I need to declare a dummy absolute address in the code of a self-modifying program. This pointer works similar to a relocation for a linker - it only reserves appropriate space in the instruction and is updated with a valid address later on at runtime. This has worked fine for me on x86-32:
movups xmm0, [0xDEADBEEF]
This assembles and works as expected at runtime. However, when I try to do this in x86-64 code:
movups xmm0, [0xDEADC0DEDEADBEEF]
It assembles with the following warning:
warning: dword data exceeds bounds
And promptly crashes at runtime because the next instruction is overwritten with the rest of the address, which happens to be garbage instruction-wise.
Any address longer than 32 bits fails to assemble without a warning, even a minimally longer one than 32 bits:
movups xmm0, [0xADEADBEEF] ; 36-bit address
How should I go about declaring a constant, absolute 64-bit pointer? Or is there just no way around it and I need to drop a RIP-relative, 32-bit pointer in there?
I may be wrong because I haven't done NASM in a long time, but I don't think you can use a 64 bit immediate value with any register other than AL, AX, EAX, RAX
. Your 64 bit address has to be declared as a QWORD
.
Solution:
mov rax , 0xDEADCODEDEADBEEF
movups xmm0, [rax]
See comments below for explanation.
This reference: NASM Manual
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