I have a simple NASM program which only invokes sys_exit
:
segment .text
global _start
_start:
mov eax, 1 ; 1 is the system identifier for sys_exit
mov ebx, 0 ; exit code
int 0x80 ; interrupt to invoke the system call
When I first wrote it, I made a mistake and forgot the space between int
and 0x80
:
int0x80
... but the program still compiled without problem!
[prompt]> nasm -f elf MyProgram.asm
[prompt]> ld -o MyProgram MyProgram.o
It just gave me a segmentation error when I ran it!
[prompt]> ./MyProgram
Segmentation fault
So what does this program - the original one I wrote, with the missing space - do? What does int0x80
(with no space) mean in NASM?
segment .text
global _start
_start:
mov eax, 1
mov ebx, 0
int0x80 ; no space...
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.
A kernel is the core component of an operating system. Using interprocess communication and system calls, it acts as a bridge between applications and the data processing performed at the hardware level.
NASM is giving me this warning:
warning: label alone on a line without a colon might be in error
Apparently the typo gets treated as a label and you can reference the new int0x80
label in your program as usual:
segment .text
global _start
_start:
mov eax, 1 ; 1 is the system identifier for sys_exit
mov ebx, 0 ; exit code
int0x80 ; interrupt to invoke the system call
jmp int0x80 ; jump to typo indefinitely
NASM supports labels without colon, I often use that for data declarations:
error_msg db "Ooops", 0
flag db 0x80
nullpointer dd 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With