Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

gcc assembly help in converting windows assembly code to linux gcc.

Avatar of SimonHowald
SimonHowald asked on
LinuxCAssembly
10 Comments1 Solution1014 ViewsLast Modified:
64-bit counter increment/decrement on 32-bit system.

atomically in_value is incremented and updated value is returned.
Pseudo code...
__int64* increment(__Int64 *in_value)
{
__int64 *temp = NULL;
 
__asm  {
               mov edi, in_value
                mov eax, [edi]
                mov edx, [edi+4]
           retry:
                mov ecx, edx
                mov ebx, eax
                add ebx, 1
                adc ecx, 0
                lock cmpxchg8b [edi]
                jnz retry
                mov eax, temp
                xor edx, edx
                mov [eax+edx*4], ebx
                mov [eax+edx*4+4], ecx
     }
return *temp;
}
 
It works great. I want it be converted into gcc assembly.
 
I unsuccessfully converted it in to gcc assembly. But its wrong, i dont know how to pass in_value  (hi and low) in one ready.
 
#define low(x)       *(((unsigned int*)&(x))+0)
#define high(x)      *(((unsigned int*)&(x))+1)
 
asm volatile (  "mov   %0,  %%edi \n"
                "mov   %1,  %%eax  \n"
                "mov   %2,  %%edx \n"
                "1: \n"
                "mov   %%edx,  %%ecx\n"
             "mov   %%eax, %%ebx \n"
              "add   $1, %%ebx \n"
            "adc   $0, %%ecx \n"
            "lock;  cmpxchg8b %0\n"
            "jnz   1b \n"
                "mov   %%edx, %%edx \n"
                "mov   %3, %%ebx \n"     //Error
                "mov   %3, %%ecx \n"     //Error
               : "=m" (*in_value)
   : "m" (low(*in_value)), "m" (high(*in_value)), "m" (*in_value)
               : "memory", "ebx", "ecx", "eax", "edi");
 
in_value should not re-read for one cycle to preserve the atomicity.
thank you
ASKER CERTIFIED SOLUTION
Avatar of ravenpl
Commented:
This problem has been solved!
Unlock 1 Answer and 10 Comments.
See Answers