Integer overflow in gas

199 views Asked by At

I'm not sure if this is an assembly question or more a gas question. I've done the following to see how the assembler handles immediate values that are too large to encode in the respective register:

addb $0xFFFF,      %bl
addw $0xFFFFFF,    %bx
addl $0xFFFFFFFFF, %ebx
addq $0xFFFFFFFFF, %rbx

And running $ as file.s files me the following warnings and errors:

file.s: Assembler messages:
file.s:5: Warning: 16777215 shortened to 65535
file.s:6: Warning: 68719476735 shortened to 4294967295
file.s:7: Error: operand type mismatch for `add'

Here are a few questions related to that:

  • bl: Why isn't a warning raised for trying to add in 0xFFFF into bl? It gets shortened to FF after assembling, but there's no warning message for it.
  • bx: 65535 or 0xFF FF is the max 16 bit value so that makes sense. There is a warning for this.
  • ebx: 4294967295 or 0xFF FF FF FF is the largest 32 bit value so that makes sense. There is a warning for this.
  • rbx: here was the surprising part for me, on overflow this actually raises an error and not a warning. Why does this one error?
0

There are 0 answers