1

I know that in x86 we can use a 32-bit address in brackets for address. For example:

lea eax, [0xCAFEBABE]

But what should I do in 64-bit mode?

The next code won't compile, because (as I understand) 64-bit constants are just banned for addresses.

lea rax, [0xCAFEBABEDEADBEEF]

How to access some constants with known constant address using this brackets?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • 1
    You never want to use LEA with an absolute addressing mode in the first place, in any mode. It's always shorter (in machine code) to use `mov`. (In 64-bit mode, use RIP-relative LEA if it's a nearby address; [How to load address of function or label into register](https://stackoverflow.com/q/57212012)) – Peter Cordes Dec 22 '21 at 23:16

1 Answers1

5

Instruction lea doesn't allow 64bit displacement in ModR/M form, use mov instead:

|00000000:48B8EFBEADDEBEBAFECA | MOV RAX, 0xCAFEBABEDEADBEEF  ; Load 64bit GPR with 64bit immediate value.
|0000000A:48A1EFBEADDEBEBAFECA | MOV RAX,[0xCAFEBABEDEADBEEF] ; Load RAX from a QWORD stored at 64bit offset.
vitsoft
  • 5,515
  • 1
  • 18
  • 31