Richard JP Le Guen
Richard JP Le Guen

Reputation: 28753

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?

Upvotes: 3

Views: 3311

Answers (4)

Scott Wisniewski
Scott Wisniewski

Reputation: 25051

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

  1. ebx
  2. ecx
  3. edx
  4. esi
  5. 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

Upvotes: 1

J.K
J.K

Reputation: 1

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.

Upvotes: 0

karlphillip
karlphillip

Reputation: 93468

%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.

Upvotes: 3

Erik
Erik

Reputation: 91300

It's the exit code of the process - your snippet is more or less exit(0)

See this link for a (somewhat dated) list.

Upvotes: 7

Related Questions