Solved

What does this section of assembly code means?

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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 …
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…

785 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