我这里有这个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
解决方法:
在汇编语言中不正确地做事并不能确保你会崩溃.
ret 60指令在返回后从堆栈中弹出错误数量的值.但是,接下来的事情并不是假设堆栈上有任何使用值.例如,退出函数不关心堆栈是否已被删除,并且仍将退出您的进程.