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;
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.
*************
}
ASKER
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]
again:
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
error C2443: operand size conflict
increment(__int64* in_value)
{
__int64* ret_value
mov edi, in_value
mov eax, [edi]
mov edx, [edi+4]
again:
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
ASKER
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.
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.
ASKER
Thank you so much. You answered what is asked. But I have new question related to this. Please help me there. Thank you.
Open in new window