Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
25 Views

Behaviour of instructions on 32bit operands in 64 bit mode

Jump to solution

what happens to the upper bits of rax in the following instruction.

mov eax, 1;

what about reading from memory?

mov eax, [0x12345678].

is it possible to say something like

mov rax, ecx # sign extend the values of ecx. or pad it with zeros

i am writting a compiler with uses 64 bit pointers but 32 bit integers and i need to interconvert between 32 and 64 bits because its not a statically typed language. any special instructions which can be helpful.

0 Kudos

Accepted Solutions
Highlighted
New Contributor II
25 Views
3.4.1 is volume 1
"When in 64-bit mode, operand size determines the number of valid bits in the destination
general-purpose register:
64-bit operands generate a 64-bit result in the destination general-purpose
register.
32-bit operands generate a 32-bit result, zero-extended to a 64-bit result in the
destination general-purpose register.
8-bit and 16-bit operands generate an 8-bit or 16-bit result. The upper 56 bits or
48 bits (respectively) of the destination general-purpose register are not be
modified by the operation. If the result of an 8-bit or 16-bit operation is intended
for 64-bit address calculation, explicitly sign-extend the register to the full
64-bits."

View solution in original post

0 Kudos
4 Replies
Highlighted
New Contributor II
25 Views
Upper 32 bits of the dst register are zeroed if you use 32 bit variant of the instruction (REX.W = 0 or no REX), mov eax,-1 willcause rax to hold 0x00000000ffffffff.

if you need sign extending 32->64, use movsxd
0 Kudos
Highlighted
Beginner
25 Views
Quoting - neni
Upper 32 bits of the dst register are zeroed if you use 32 bit variant of the instruction (REX.W = 0 or no REX), mov eax,-1 willcause rax to hold 0x00000000ffffffff.

if you need sign extending 32->64, use movsxd
Hi Neni,
where can I find this type of information ?
I couldn't find such a definition for MOV and 64 bit register in the Software Developer Manual.
0 Kudos
Highlighted
New Contributor II
26 Views
3.4.1 is volume 1
"When in 64-bit mode, operand size determines the number of valid bits in the destination
general-purpose register:
64-bit operands generate a 64-bit result in the destination general-purpose
register.
32-bit operands generate a 32-bit result, zero-extended to a 64-bit result in the
destination general-purpose register.
8-bit and 16-bit operands generate an 8-bit or 16-bit result. The upper 56 bits or
48 bits (respectively) of the destination general-purpose register are not be
modified by the operation. If the result of an 8-bit or 16-bit operation is intended
for 64-bit address calculation, explicitly sign-extend the register to the full
64-bits."

View solution in original post

0 Kudos
Highlighted
Beginner
25 Views
Thanks, this is what I was looking for !
0 Kudos