Linux NASM: What is the value in ebx when you invoke sys_exit?
In a Linux environment, if I write some NASM code as follows:
mov eax, 1 ; system call 1 - sys_exit
mov ebx, 0
int 0x80
... what is the value in ebx开发者_如何转开发?
It's the exit code of the process - your snippet is more or less exit(0)
See this link for a (somewhat dated) list.
%ebx is the status code for the exit system call
This means that whatever is stored in %ebx will be returned to the Operating System. Therefore, after executing your application on a terminal, issuing this command:
echo $?
will print the return code of your app.
Pages 20,21,22 of Programming from the Ground Up explains this very well.
In general the Linux x86 system call interface uses eax to store the system call number and then the following registers for function arguments from to right
- ebx
- ecx
- edx
- esi
- edi
There's a very nice system call table here that outlines most of the Linux system calls:
http://bluemaster.iu.hio.no/edu/dark/lin-asm/syscalls.html
mov eax, 1 ;
is the sys_exit code
mov ebx, 0 ;
the value of ebx could be either 0 or 1, 0 means normal exit, 1 means error.
精彩评论