I want to understand what why we use int 80h
and what happens after calling it in assembly code. Like here:
int 80h
mov eax,1
int 80h
How does it know that I want to call the system exit, not just saving decimal number in eax?
I want to understand what why we use int 80h
and what happens after calling it in assembly code. Like here:
int 80h
mov eax,1
int 80h
How does it know that I want to call the system exit, not just saving decimal number in eax?
INT
is the assembly mnemonic for "interrupt". The code after it specifies the interrupt code. (80h/0x80 or 128 in decimal is the Unix System Call interrupt) When running in Real Mode (16-bit on a 32-bit chip), interrupts are handled by the BIOS. When running on top of an Operating System, interrupts are handled by the OS through an Interrupt Descriptor Table (IDT) loaded at boot time.
If the CPU encounters an INT
instruction, it will either lookup the interrupt in the BIOS's IVT or the OS's IDT and find the attached handler for that specific interrupt code. It will then jump to that piece of code specified by the IDT/IVT, start executing, and jump back to the code that called the INT
when it reaches the special instruction IRET
in the handler, denoting that the system is finished with executing the interrupt.
Some interrupt handlers use registers to know more information, sort of like passing arguments to a function in a higher-level language. Therefore, when you write 1
to EAX
, the handler which receives your interrupt will see that EAX
is set to 1
and know something about what you want, for example the system resource which you want to use.