Avatar of SimonHowald
SimonHowald asked on

aggregate two 32 bit registers in to one local 64 bit variable

i have two 32-bit registers ebx and ecx which are used to store a 64 bit value.
i want to reconstruct 64 bit integer from register b (lower 32 bits) and register c (higher 32 bits) and store in in to 64-bit
How do I do?
int64 value;      

int64 value;	
asm {
   mov     ecx, edx
   mov     ebx, eax
   add     ebx, 1
   adc     ecx, 0  
here I need to store b and c in to 64 bit varriable value.

Open in new window


Avatar of undefined
Last Comment

8/22/2022 - Mon

It could look like the following
mov    eax, value             ; move the address of value into eax
xor    edx, edx               ; prepare edx to serve as index offset register
mov    [eax+edx*4], ecx       ; move ecx into the high 4 bytes of value
mov    [eax+edx*4+4], ebx     ; move ebx into the low 4 bytes of value

Open in new window


Thank you very much. I am getting error compilng on windows.
 error C2443: operand size conflict

increment(__int64* in_value)
__int64* ret_value

    mov     edi, in_value
    mov     eax, [edi]    
    mov     edx, [edi+4]  
    mov     ecx, edx
    mov     ebx, eax
    add     ebx, 1  
    adc     ecx, 0
    lock    cmpxchg8b [edi]      
    jnz     again
    mov     eax, ret_value  
    xor     edx, edx  
    mov     [eax+edx*4], ecx    
    mov     [eax+edx*4+4], ebx

retrun ret_value;

How do I correct this problem? Thank you very much


Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

Thanks it worked for me. ebc and ebx need to interchanged.
I have question why edx is required there?
Line 15 i.e.
__asm xor edx, edx
will reset all bits to 0. 16 and 17 will be like this in every case
    __asm mov [eax], ecx
    __asm mov [eax+4], ebx
I appreciate your help. Thank you so much.
Your help has saved me hundreds of hours of internet surfing.

Above worked for me under windows. I need the same to be converted to be used under linux.
I am attaching what I did.  I have following
[edi]  and [edi+4]  does not work under gcc.
Function should automically increment the value and return the updated value.
Thank you.

#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");
if not this then alternative code snip will also work for me.

Open in new window


Thank you so much. You answered what is asked. But I have new question related to this. Please help me there. Thank you.