0

I started to learn assembly and I have met with problems related to absolute address 32-bit. I have read recently post about this similar problem Why is there problems with absolute addressing?. Can you prompt why if I specify without writing default rel I get error related with that executable base address in mac os starts 4GB.

mov qword[test], ‘hello’

To summarize all, problem is why is mov qword[test], ‘hello’ a 32-bit addressing? And if I specify before mov qword[test], ‘hello’ this REX.W it doesn’t help me to solve 32-bit addressing problem?

Thank you

Jester
  • 56,577
  • 4
  • 81
  • 125
Ruslan
  • 51
  • 5
  • 2
    it is 32 bit because the instruction encoding only supports 32 bits for the address. Relative addressing uses `rip+offset` (also 32 bit). You can tell nasm with the `rel` keyword or `default rel` if you want relative. Note that `qword [test]` refers to the operation size, not the address size. – Jester Jun 20 '21 at 12:34
  • So as I understand if I wanna refer to address which is located above 32 bit address I can do only that through offset from RIP? – Ruslan Jun 20 '21 at 12:40
  • Yes, or indirectly. – Jester Jun 20 '21 at 12:41
  • 1
    Because the only ways to encode that are `[disp32]` or `[rip+rel32]`. See [Referencing the contents of a memory location. (x86 addressing modes)](https://stackoverflow.com/q/34058101). My answer on [Why are global variables in x86-64 accessed relative to the instruction pointer?](https://stackoverflow.com/q/56262889) includes an explanation of how RIP-relative works in machine code. – Peter Cordes Jun 20 '21 at 13:05
  • 1
    Why is there a problem? Because MacOS maps executables outside the low 4GiB of address space. (Perhaps as a way to make sure that truncating pointers to 32-bit always faults, not accesses some other memory.) – Peter Cordes Jun 20 '21 at 13:20

0 Answers0