微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

这个汇编过程如何不崩溃?

如何解决这个汇编过程如何不崩溃?

| 我在这里没有崩溃的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
函数将不会在意堆栈是否被废弃,并且仍会退出您的进程。     

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。