Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8200993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:38:54+00:00 2026-06-07T06:38:54+00:00

Visual Studio produces the following machine code when _InterlockedIncrement is used: ; 40 :

  • 0

Visual Studio produces the following machine code when _InterlockedIncrement is used:

; 40   :        _InterlockedIncrement(&framecounter);

  00078 b8 00 00 00 00   mov     eax, OFFSET ?framecounter@@3JA ; framecounter
  0007d b9 01 00 00 00   mov     ecx, 1
  00082 f0 0f c1 08  lock     xadd   DWORD PTR [eax], ecx

If I would be writing this i would use just lock inc DWORD PTR [eax] instead of mov and xadd

Is there a valid reason why Microsoft preferred xadd and using 2 instructions instead of 1?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T06:38:56+00:00Added an answer on June 7, 2026 at 6:38 am

    Because _InterlockedIncrement also returns the new value.

    You can’t do that with lock inc DWORD PTR [eax], because now neither the old nor the new value are anywhere to be found. Except in memory, but if you do an other read, clearly it won’t be atomic (the increment itself would be, but you could get a value back that has nothing to do with what happened at the time of the increment).

    Returning the value makes _InterlockedIncrement more useful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code will not compile against the Async CTP in Visual Studio 2010:
Visual Studio 2010 C# code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using
Visual studio seems intent that my javascript code is bad, mostly because it has
When my Visual Studio 2008 C++ command-line application crashes, it sometimes produces this dialog.
I have seen and used a rename feature in Visual Studio 2010. However when
I'm trying to build System.Data.SQLite in Visual Studio using the source code downloaded from
I am wondering why the following contrived example code works perfectly fine in Visual
The following code: ref class A { private: int% referenceToAnInt; }; produces the following
For the following code: (assuming x has been defined) scanf(%d\n, &x); printf(foo); I expect
I'm using Visual Studio 2008 (C++) and would like to produce a list of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.