I am working with a simple example in x86 GNU GAS on MacOSX whereby an integer value of 300
is moved into the eax
register. As expected, only 300 mod 256
(the value 44
), is actually stored in %eax
, as echo$?
reveals from Mac terminal:
.globl _main
_main:
pushq %rbp
movq %rsp, %rbp
subq $16, %rsp
movl $300, %eax;
leave
ret
However, I was under the impression that there is an overflow/wrap-around flag to denote that a wraparound occurred or a register storing the result of the integer division of 300
and 256
, the result being 1
. I have been unable to find any information detailing this process (if it exists) for x86 GNU. Does anyone know how the wraparound value or an overflow flag can be accessed?
There are a couple of misconceptions in your question.
First, eax can hold values from 0 to 4294967295, so mov $300, %eax
does in fact store 300 into eax.
Second, a mov instruction cannot overflow or wrap around; the size of the source and the size of the destination are the same. The overflow flag is used for arithmetic operations.
The reason echo $?
prints 44 is that the operating system reports the low byte of the exit status of the process to the shell.