TheFuzz
TheFuzz

Reputation: 2623

how does this assembly proc not crash?

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

Upvotes: 3

Views: 167

Answers (1)

Greg Hewgill
Greg Hewgill

Reputation: 992757

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.

Upvotes: 5

Related Questions