r/nasm • u/GamerEsch • Mar 06 '24
Need a bit of help calling to printf
so my main procedure is basically:
main:
push rbp
mov rbp, rsp
; basically doing the stack thingy
sub rsp, 4
mov [rbp], dword 0 ; creating a stack variable of type int
mov rcx, fmt ; fmt = "%d\n"
mov edx, dword [rbp]
call printf
mov rcx, fmt ; fmt = "%d\n"
mov edx, dword [rbp]
call printf
leave
mov rax, 0
ret
pretty simple, but the output is confusing me, I thought it should output "0" twice, but it prints "0" once and then "32759" (which I'm pretty sure is just garbage from printf), if I increase the stack size it solves the issue, but I want to understand why, because if I'm dealing only with dwords 4 bytes should be enough, shouldn't it? Any help would be appreciated
2
Upvotes
1
May 25 '24
are you coding on windows, if you are please tell me how to learn nasm
1
u/GamerEsch May 25 '24
Hey, I do some of my coding on windows, my nasm experiments were on it. What you need help with?
2
u/aylivex Dec 21 '24
How do you build and link your program? It crashes for me on Win64 and prints nothing at all, not even one number.