4
votes

I was wondering if it is possible to encode an instruction like:

add rax,[address]

where <address> is a full 64-bit address pointing to a 64-bit value. NASM seems to simply truncate the address and encode it as a 32-bit address. The only form of 64-bit addressing (with a direct address) that seems to work is:

mov rax,[qword address]

which is encoded by NASM using REX.W=1 and special opcodes of MOV with direct addressing. Using REX.W with the add instruction merely makes it interpret the target address as containing a 64-bit value, but doesn't allow for the specification of a 64-bit address. But I am curious if there is another way.

(By the way, due to this problem I am for now using the RIP-relative addressing).

Can anyone confirm that the direct 64-bit addressing form is impossible?

1
The instruction set reference can confirm that, not some stranger from the internet ;)Jester
Jester, I have looked at the instruction set reference. But it is somewhat difficult to exclude there could there is a way especially because I am not that used to reading it. The instruction set reference lists an option "[REX.W + 03 /r] ADD r64, r/m64" but based on experimentation and your anwers (and the tables concerning MOD R/M byte) I conclude this refers to adding a 64-bit value stored at a 32-bit specified memory address (with no possibility of extending the address to 64-bit outside of using more instructions).Morty
@Morty The ordinary set of addressing modes do not include a mode with a 64 bit disposition or absolute. Only certain special instructions provide such an addressing mode.fuz
"Section 2.2.1.3 Displacement The ModR/M and SIB displacement sizes do not change. They remain 8 bits or 32 bits and are sign-extended to 64 bits." and "2.2.1.4 Direct Memory-Offset MOVs In 64-bit mode, direct memory-offset forms of the MOV instruction are extended to specify a 64-bit immediate absolute address."Jester

1 Answers

4
votes

The amd64 architecture has no addressing mode with a 64 bit displacement except in some special cases. Instead, use rip relative addressing which should be fine if your binary is less than 2 GB in size.