32位寄存器充当8位寄存器 [英] 32 bit registers act as 8 bit ones
问题描述
我一直遇到最奇怪的问题.在x86汇编中,由于某些原因,32位寄存器(eax,ebx等)在256处溢出,表明它们实际上是8位.例如:
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
如果随后我用nasm -felf32 -g test.s && ld -m elf_i386 -s -o test test.s
编译此代码并运行生成的可执行文件,则它返回0.eax,ecx,edx等也会发生相同的问题.
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.
在任何情况下,为什么32位寄存器都像8位寄存器一样起作用?
Why would the 32 bit registers act like 8 bit ones, in ANY situation?
推荐答案
这不是 register ,而是exit
系统调用,它仅使用ebx
的低八位返回代码.
It's not the register wrapping around, it's the exit
system call, which only uses the lower eight bits of ebx
for the return code.
在exit
手册页中:
exit()
函数导致正常的进程终止,并且status & 0377
的值返回给父级(请参见wait(2)
).
The
exit()
function causes normal process termination and the value ofstatus & 0377
is returned to the parent (seewait(2)
).
0377
是0xff
的八进制等效项(二进制1111 1111
),这意味着仅使用低八位.从wait()
返回的其他位(在父级中)用于诸如是否终止子进程,使用了什么信号(如果终止),是否发生核心转储之类的事情.
That 0377
is the octal equivalent of 0xff
(binary 1111 1111
), meaning that only the lower eight bits are used. The other bits in what you get back from wait()
(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.
这篇关于32位寄存器充当8位寄存器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!