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

AssemblyCLinux

Avatar of undefined
Last Comment
SimonHowald
Avatar of DefreeComan
DefreeComan

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

Avatar of SimonHowald
SimonHowald

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

ASKER CERTIFIED SOLUTION
Avatar of DefreeComan
DefreeComan

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of SimonHowald
SimonHowald

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.
Avatar of SimonHowald
SimonHowald

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.

#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

Avatar of SimonHowald
SimonHowald

ASKER

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

Linux is a UNIX-like open source operating system with hundreds of distinct distributions, including: Fedora, openSUSE, Ubuntu, Debian, Slackware, Gentoo, CentOS, and Arch Linux. Linux is generally associated with web and database servers, but has become popular in many niche industries and applications.

71K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo