在main的末尾跳转不使用int 0x80执行

时间:2019-05-09 19:55:10

标签: assembly nasm

所以我有这个基本的hello world代码

SECTION .data       ; data section
msg:    db "Hello World",10 ; the string to print, 10=cr
len:    equ $-msg       ; "$" means "here"
                ; len is a value, not an address
msg2:    db "test" ; the string to print, 10=cr
len2:    equ $-msg2       ; "$" means "here"
                ; len is a value, not an address                

SECTION .text       ; code section
        global main     ; make label available to linker 
main:               ; standard  gcc  entry point
    mov edx,len     ; arg3, length of string to print
    mov ecx, msg   ; arg2, pointer to string
    mov ebx,1       ; arg1, where to write, screen
    mov eax,4       ; write sysout command to int 80 hex
    int 0x80        ; interrupt 80 hex, call kernel
    mov ebx,0       ; exit code, 0=normal
    mov eax,1       ; exit command to kernel
    int 0x80        ; interrupt 80 hex, call kernel
    JMP l2



l2:
    mov edx,len2     ; arg3, length of string to print
    mov ecx,msg2     ; arg2, pointer to string
    mov ebx,1       ; arg1, where to write, screen
    mov eax,4       ; write sysout command to int 80 hex
    int 0x80        ; interrupt 80 hex, call kernel

    mov ebx,0       ; exit code, 0=normal
    mov eax,1       ; exit command to kernel
    int 0x80        ; interrupt 80 hex, call kernel

当我将跳线放在主线末端时,它不起作用,但是如果我将其放在最后一行之前,  这样:

main:               ; standard  gcc  entry point
    mov edx,len     ; arg3, length of string to print
    mov ecx, msg   ; arg2, pointer to string
    mov ebx,1       ; arg1, where to write, screen
    mov eax,4       ; write sysout command to int 80 hex
    int 0x80        ; interrupt 80 hex, call kernel
    mov ebx,0       ; exit code, 0=normal
    mov eax,1       ; exit command to kernel
    JMP l2
    int 0x80        ; interrupt 80 hex, call kernel

跳跃有效。为什么在第一种情况下不起作用?

1 个答案:

答案 0 :(得分:2)

最后一个int 0x80是一个系统调用,要求(Linux?)内核终止该进程。

在C语言中,它会像

     exit(0);
     goto somewhere;   // Never executed because the process no longer exists