0

In NASM, when using dwords, I can write mov dword [rbp-16], 2147483647 instead of mov eax, 2147483647 followed by mov dword [rbp-16], eax.
But with qwords, this is not the case. If I wrote mov qword [rbp-16], 2147483648 instead of mov rax, 2147483648 followed by mov qword [rbp-16], rax, it gives me this warning:

disass.asm:35: warning: signed dword immediate exceeds bounds [-w+number-overflow]
disass.asm:35: warning: dword data exceeds bounds [-w+number-overflow]

Why is so?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Sourav Kannantha B
  • 2,860
  • 1
  • 11
  • 35
  • 2
    Because `+2147483648` can't be represented as a 2's complement 32-bit integer immediate (which will be sign-extended to qword). You can do that with `2147483647` (`0x000000007fffffff`) though, so `mov qword [mem], 0x000000007fffffff` is fine. – Peter Cordes Mar 11 '21 at 05:42
  • 3
    There is no encoding of `mov` with a generic (ModR/M or SIB) memory destination and full 64-bit immediate source. – ecm Mar 11 '21 at 05:53
  • 4
    Not sure if any existing questions directly address the fact that a value can fit in a 32-bit immediate (which won't be extended and can thus be considered unsigned), but *not* in a 32-bit immediate that has to sign-extend to the right value in the high bits. That's what's going on here, and is hopefully clear enough from the duplicates, but if anyone disagrees we can tidy up this question and reopen. – Peter Cordes Mar 11 '21 at 05:57

0 Answers0