user3409988
user3409988

Reputation: 467

jump at the end of main is not execute with int 0x80

So I have this basic hello world code

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

When I put the jump a the end of the main it doesn't work but if I put it before the last line, this way:

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

The jumps works. Why it does not work on the first case?

Upvotes: 0

Views: 133

Answers (1)

Brendan
Brendan

Reputation: 37262

The final int 0x80 is a system call that asks the (Linux?) kernel to terminate the process.

In C it'd be like:

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

Upvotes: 2

Related Questions