我这里的linux nasm代码没有崩溃。使用printString末尾的ret 80指令不应该这个程序崩溃吗?
bits 32
section .data
hello: db 'Hello Linux assembly!!!!!!!!!!!!!!!!!!!',10,0
helloLen: equ $-hello
anotherString db "hello im another string!!!!",10,0
anotherStringlen equ $-anotherString
section .text
global _start
_start:
push hello
push helloLen
call printString
;;;; should i pop the two paramters I pushed?
;;;; does the ret instruction do it for me?
push anotherString
push anotherStringlen
call printString
call exit
printString:
push ebp
mov ebp, esp
mov eax, 4
mov ebx, 1
mov ecx, [ebp+12]
mov edx, [ebp+8]
int 80h
pop ebp
ret 60 ;;;;; How does this not make printString crash?
exit:
mov eax,1
mov ebx,0
int 80h
答案 0 :(得分:5)
在汇编语言中做错事情绝不会确保你会崩溃。
返回后,ret 60
指令从堆栈中弹出错误的值。但是,接下来的事情并不是假设堆栈上有任何使用值。例如,exit
函数不关心堆栈是否已被删除,并且仍将退出您的进程。