flat assembler
Message board for the users of flat assembler.

Index > Main > dword mov with x86-64?

Author
Thread Post new topic Reply to topic
fonolite



Joined: 14 Dec 2005
Posts: 32
fonolite 19 Jan 2006, 12:06
mov rax, 123456789ABCDEF0h

mov rdx, 0FFFFFFFFh



mov al, dl => rax=123456789ABCDEFFh

mov ax, dx => rax=123456789ABCFFFFh

but,

mov eax, edx => rax=00000000FFFFFFFFh


How strange for DWORD transfer.

Upper 32bit of general 64bit register goes away when DWORD transfer.

Is it a sort of bug for x86-64 CPU?

I tested Intel's EM64T in long mode with fasm 1.65.5 and 1.64.

I have no AMD64.
Post 19 Jan 2006, 12:06
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 19 Jan 2006, 12:11
It's not a bug, it's a feature. Wink
It was documented from the very first version of published x86-64 specification. The operations on 32-bit register zero the high 32 bits of target register. This is mainly to let you use the shorter form (without REX prefix) of instruction for some cases like "sub eax,eax" to zero RAX register (instead of "sub rax,rax", which has one byte longer opcode), or "mov eax,1" instead of "mov rax,1".
Post 19 Jan 2006, 12:11
View user's profile Send private message Visit poster's website Reply with quote
fonolite



Joined: 14 Dec 2005
Posts: 32
fonolite 19 Jan 2006, 12:35
Oh, thanks for your quick detailed answer.

x86-64 looks strange to me...


Anyway, how can I expand 32bit to 64bit register?

i.e. (upper 0, lower eax) => (eax, eax)=rax

Simple question or not?
Post 19 Jan 2006, 12:35
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 19 Jan 2006, 12:46
Can you rephrase?
Post 19 Jan 2006, 12:46
View user's profile Send private message Visit poster's website Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 19 Jan 2006, 12:55
I think he meant:
Code:
mov eax,4C63EF53h
mov rdx,rax
shl rdx,32
add rdx,rax
    


-Or-

Code:
mov eax,19283746h
imul 100000001h ; *(2^32+1)
    


so that rax=eax shl 32 + eax
Post 19 Jan 2006, 12:55
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
fonolite



Joined: 14 Dec 2005
Posts: 32
fonolite 19 Jan 2006, 13:23
Madis731 is right. Smile

I got used my code like below.


Code:
mov rdx,rax 
shl rdx,32 
or rdx,rax    


similar answer to Madis731.


This DWORD restriction bothers me. Sad


Anyway, Thank you all...,
Post 19 Jan 2006, 13:23
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.