gpt4 book ai didi

linux - 这个程序集如何不崩溃?

转载 作者:可可西里 更新时间:2023-11-01 11:50:38 25 4
gpt4 key购买 nike

我这里有这个不会崩溃的 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 指令在返回后将错误数量的值从堆栈中弹出。但是,您接下来要做的事情并不假设堆栈上有任何使用值。例如,exit 函数不会在意堆栈是否已废弃,并且仍会退出您的进程。

关于linux - 这个程序集如何不崩溃?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6475385/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com