问题描述
|
我在这里没有崩溃的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!!!!\",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
解决方法
用汇编语言错误地做事绝不能确保您会崩溃。
返回后,“ 1”指令会从堆栈中弹出错误数量的值。但是,接下来要做的事情并不假定堆栈上有任何使用价值。例如,
exit
函数将不会在意堆栈是否被废弃,并且仍会退出您的进程。