I've been having the strangest problem. In x86 assembly, the 32 bit registers (eax, ebx, etc.) have been overflowing at 256, suggesting that they're actually 8 bit, for some reason. For example:
test.s:
section .data
section .text
global _start
_start:
mov eax, 1
mov ebx, 256
int 80h
If I then compile this code with nasm -felf32 -g test.s && ld -m elf_i386 -s -o test test.s
, and run the resulting executable, it returns 0. This same problem happens for eax, ecx, edx, etc.
Why would the 32 bit registers act like 8 bit ones, in ANY situation?
It's not the register wrapping around, it's the
exit
system call, which only uses the lower eight bits ofebx
for the return code.From the
exit
man-page:That
0377
is the octal equivalent of0xff
(binary1111 1111
), meaning that only the lower eight bits are used. The other bits in what you get back fromwait()
(in the parent) are used for things such as whether the child process was terminated, what signal was used if so, whether a core dump occurred, and so on.