Assembly 不使用int 0x80执行main末尾的跳转
我有一个基本的hello world代码Assembly 不使用int 0x80执行main末尾的跳转,assembly,nasm,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=
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
当我把跳转a放在主线末端时,它不起作用,但如果我把它放在最后一行之前,
这样:
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
跳跃是有效的。为什么它不能在第一种情况下工作?最后的
int0x80
是一个系统调用,它要求(Linux?)内核终止进程
在C语言中,它就像:
最后一个
int0x80
是一个系统调用,它要求(Linux?)内核终止进程
在C语言中,它就像:
exit(0);
goto somewhere; // Never executed because the process no longer exists