What does this section of assembly code means?

Posted on 2004-09-13
Medium Priority
Last Modified: 2013-12-13

I got this section of assembly code:

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

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,

Question by:rfr1tz
1 Comment
LVL 11

Accepted Solution

dimitry earned 1000 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.

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

587 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