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

发布于 2024-11-17 03:20:03 字数 864 浏览 4 评论 0原文

我这里有这个不会崩溃的 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

I have this linux nasm code here that doesn't crash. With the ret 80 instruction at the end of printString shouldn't this program crash?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

つ可否回来 2024-11-24 03:20:03

用汇编语言做事不正确决不能保证你会崩溃。

ret 60 指令返回后从堆栈中弹出错误数量的值。但是,您接下来要做的事情不会假设堆栈上有任何使用值。例如,exit 函数不会关心堆栈是否被丢弃,并且仍然会退出您的进程。

Doing things incorrectly in assembly language by no means assures that you'll get a crash.

The ret 60 instruction pops the wrong number of values off the stack after returning. However, the next things you do don't assume that there are any values of use on the stack. For instance, the exit function won't care that the stack is trashed, and will still exit your process.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文