NASM Programming - `int0x80` vs` int 0x80`

I have a simple NASM program that only calls 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 this, I made a mistake and forgot the space between int and 0x80 :

  int0x80 

... but the program is still compiled without problems!

 [prompt]> nasm -f elf MyProgram.asm [prompt]> ld -o MyProgram MyProgram.o 

He just gave me a segmentation error when I ran it!

 [prompt]> ./MyProgram Segmentation fault 

So what does this program - the original one that I wrote, with the missing space - do? What does int0x80 (without space) mean in NASM?

 segment .text global _start _start: mov eax, 1 mov ebx, 0 int0x80 ; no space... 
+6
assembly syntax nasm interrupt
source share
2 answers

NASM gives me this warning:

warning: only a label on a line without a colon may be erroneous

Apparently, the typo is considered as a label, and you can refer to 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 colonless labels, I often use this for data declarations:

 error_msg db "Ooops", 0 flag db 0x80 nullpointer dd 0 
+6
source share

You need to put a colon at the end of this line:

 Segment .text: global _start _start: mov eax, 1 mov ebx, 0 int0x80 ; no space... 
0
source share

All Articles