Solved

What does this section of assembly code means?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
WMI, model #, retrieving information 10 117
recursion example 16 112
iframe detection of parent window scale 20 60
simplest php form 3 64
A short article about a problem I had getting the GPS LocationListener working.
This is an explanation of a simple data model to help parse a JSON feed
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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 …

867 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

21 Experts available now in Live!

Get 1:1 Help Now