main 末尾的跳转未使用 int 0x80 执行
jump at the end of main is not execute with int 0x80
所以我有了这个基本的 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
跳跃有效。为什么它不适用于第一种情况?
最后的 int 0x80
是一个系统调用,要求 (Linux?) 内核终止进程。
在 C 中它会是 like:
exit(0);
goto somewhere; // Never executed because the process no longer exists
所以我有了这个基本的 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
跳跃有效。为什么它不适用于第一种情况?
最后的 int 0x80
是一个系统调用,要求 (Linux?) 内核终止进程。
在 C 中它会是 like:
exit(0);
goto somewhere; // Never executed because the process no longer exists