I've come across some nasm assembly examples. This is a classic Hello World program:
; ----------------------------------------------------------------------------
; helloworld.asm
;
; This is a Win32 console program that writes "Hello, World" on one line and
; then exits. It needs to be linked with a C library.
; ----------------------------------------------------------------------------
global _main
extern _printf
section .text
_main:
push message
call _printf
add esp, 4
ret
message:
db 'Hello, World', 10, 0
One thing I do not understand is why is only four added to esp
after printf is executed?
It's supposed to flush out the message var from the stack if I understand right. The whole db variable is pushed onto stack, and obviously it takes more than 4 bytes. (I've referred to the accepted answer to this question: what is the syntax to define a string constant in assembly?)
I'm sure this is an extremely stupid question for an experienced assembly programmer.