Wrong order of execution in NASM Assembly

Viewed 43

I am learning NASM Assembly and I am writing a program to receive input and printout the input.

global main
extern read
extern printf

section .data
    request: db "Enter a string (len <= 32): ", 0
    response: db "You have typed: '%s'", 0x0a, 0
    format: db "%s", 0

section .bss
    val: resb 32

section .text
main:
    push ebp
    mov ebp, esp

    push request 
    call printf
    add esp, 4 

    push 32
    push val
    push 1
    call read
    add esp, 12

    mov eax, val

    push eax
    push response
    call printf
    add esp, 8

    mov esp, ebp
    pop ebp
    mov eax, 0
    ret

A weird thing is when I execute the code, the read() function seems to be executed before the first printf(). I am not quite sure why this happens.

screenshot

Thank you very much for your support.

0 Answers
Related