On x64, loading from a 64-bit absolute address (that is, dereferencing a 64-bit immediate) can be done by
movabs addr64, %rax
However, when the destination register is any other than rax
the assembler gives an error message saying operand size mismatch for movabs
. What am I missing?
rax is the 64-bit, "long" size register. It was added in 2003 during the transition to 64-bit processors. eax is the 32-bit, "int" size register. It was added in 1985 during the transition to 32-bit processors with the 80386 CPU.
The RAX register is used for return values in functions regardless of whether you're working with Objective-C or Swift.
In AT&T syntax, the instruction: mov (%rax), %eax # AT&T syntax. or, equivalently in Intel syntax: mov eax, DWORD PTR [rax] ; Intel syntax. dereferences the memory address stored in rax , reads a 32-bit value from that memory address, and stores it in the eax register.
From the MOV instruction document you can see that you can move a 64-bit immediate to any registers, but loads/stores involving a 64-bit immediate absolute address can only work with Areg
Opcode | Instruction | Description |
---|---|---|
A0 | MOV AL,moffs8* | Move byte at (seg:offset) to AL. |
REX.W + A0 | MOV AL,moffs8* | Move byte at (offset) to AL. |
A1 | MOV AX,moffs16* | Move word at (seg:offset) to AX. |
A1 | MOV EAX,moffs32* | Move doubleword at (seg:offset) to EAX. |
REX.W + A1 | MOV RAX,moffs64* | Move quadword at (offset) to RAX. |
A2 | MOV moffs8,AL | Move AL to (seg:offset). |
REX.W + A2 | MOV moffs8***,AL | Move AL to (offset). |
A3 | MOV moffs16*,AX | Move AX to (seg:offset). |
A3 | MOV moffs32*,EAX | Move EAX to (seg:offset). |
REX.W + A3 | MOV moffs64*,RAX | Move RAX to (offset). |
As you can see there's no ModR/M byte to encode the register number. Since this is less commonly used than moving a 64-bit immediate to a register it won't be a problem. If really needed it can be done in 2 instructions
MOVABS
is the GAS opcode name for theMOV
opcode formsMOV Areg, [Offs64]
andMOV [Offs64], Areg
. In Yasm's NASM syntax mode, you can get this form by sayingMOV AX, [qword xxx]
. Yasm's GAS syntax mode acceptsMOVABS
(for GAS compatibility). Note this form is only valid with Areg (AL/AX/EAX/RAX) as the source/destination register.http://cvs.tortall.net/pipermail/yasm-devel/2006-March/000579.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With