0

Very simple Hello world with nasm. I successful assembly it with nasm.exe main.asm -f win32 -o main.obj and linking it with gcc.exe -fno-use-linker-plugin -o main.obj output.exe
It runs ok, it prints on the screen and then the program crashes (output.exe has stopped working). It seems I made some stuff on the stack but I can't find the error. Is it ok if I pass parameters on the stack (stdcall)? It should, because it prints ok but..

Here's the code

section .data
    msg db "Hello, world!", 0

section .text
    global _main
    extern _printf
_main:

    push msg
    call _printf

    xor eax, eax
    ret

Platfor: win8.1 x64, Intel CPU, NASM 2.11, GCC latest version

1 Answer 1

1

printf being a C function, it isn't stdcall, it is cdecl. As such, the caller (you) needs to free the argument after the call. Use add esp, 4.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks :) Do I need to free the call for any cdecl calling function?
Yes, applies to all cdecl functions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.