Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NASM programming - `int0x80` versus `int 0x80`

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...
like image 820
Richard JP Le Guen Avatar asked Mar 25 '11 02:03

Richard JP Le Guen


People also ask

What does int 0x80 mean?

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.

What does call kernel mean?

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.


1 Answers

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
like image 91
Martin Avatar answered Sep 29 '22 11:09

Martin