Solved

What does this section of assembly code means?

Posted on 2004-09-13
3
871 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
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
seriesUp challenge 7 107
wordsWithout 49 79
C Programming - If Statement 8 50
Please explain: Aspect Oriented Programming 2 54
This is an explanation of a simple data model to help parse a JSON feed
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.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now