开发者

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

I have a simple NASM program which only invokes sys_开发者_StackOverflowexit:

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...


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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜