Solved

What does this section of assembly code means?

Posted on 2004-09-13
3
879 Views
Last Modified: 2013-12-13
Hi,

I got this section of assembly code:

#ifdef WIN32
inline int CPP_Spinlock::TestAndSet (int* pTargetAddress, int nValue)
{
    __asm
    {
        mov edx, dword ptr [pTargetAddress]
        mov eax, nValue
        lock xchg eax, dwrod ptr[edx]
    }
}
#endif

I tried to understand what this section of code really does? However, took the course on assembly code over 10 years ago and I don't remember much now. Please give some help.

Thanks a lot,

Rfr1tz
0
Comment
Question by:rfr1tz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 11

Accepted Solution

by:
dimitry earned 250 total points
ID: 12060979
This code is doing the next:
  *pTargetAddress = nValue;

However, it does it with special command that is used for spinlocks (it is not interruptable): lock xchg
It means that *pTargetAddress = nValue is non-interruptable operation.
If you will do this in C, its assembler implementation will be different and interruptable.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to concatenate fields in zpl, and how to use conditional statement? 3 119
Math Equation 23 149
What does != "" mean in programming 8 190
C qsort compare function issue 6 70
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question