tags:

views:

1448

answers:

5

Can someone explain what the following assembly code does?

 int 0x80
+10  A: 

It passes control to interrupt vector 0x80

See http://en.wikipedia.org/wiki/Interrupt%5Fvector

On Linux, have a look at this: it was used to handle system_call. Of course on another OS this could mean something totally different.

jldupont
Note that int 0x80 is the older way to do a syscall, but there is also the SYSENTER instruction. Some links of interest: http://tinyurl.com/y9vuc27 http://kerneltrap.org/node/531
asveikau
@asveikau: thanks for your links!
jldupont
+4  A: 

int 0x80 is the assembly language instruction that is used to invoke system calls in Linux on x86 (i.e., Intel-compatible) processors.

http://www.linfo.org/int_0x80.html

Tom
A: 

It tells the kernel to activate interrupt vector 0x80, which on Linux OSes is the system-call interrupt, used to invoke system functions like open() for files, et cetera.

Amber
Strictly speaking, it doesn't tell the kernel... It tells the CPU, which looks up the handler in the IDT, which ends up being a pointer to some kernel code.
asveikau
True. I suppose the better phrasing would be it tells the CPU to activate the vector, and the vector (as part of the kernel) invokes the function.
Amber
Down for "tells the kernel".
Andy
+1  A: 

As mentioned, it causes control to jump to interrupt vector 0x80. In practice what this means (at least under Linux) is that a system call is invoked; the exact system call and arguments are defined by the contents of the registers. For example, exit() can be invoked by setting %eax to 1 followed by 'int 0x80'.

Steve Smith
+1  A: 

int means interrupt, and the number 0x80 is the interrupt number. An interrupt transfers the program flow to whomever is handling that interrupt, which is interrupt 0x80 in this case. In Linux, 0x80 interrupt handler is the kernel, and is used to make system calls to the kernel by other programs.

The kernel is notified about which system call the program wants to make, by examining the value in the register %eax (gas syntax, and EAX in Intel syntax). Each system call have different requirements about the use of the other registers. For example, a value of 1 in %eax means a system call of exit(), and the value in %ebx holds the value of the status code for exit().

Polat Tuzla