I'm using nasm to compile the following assembly. However the code crashes in the console under Windows.
C:\>nasm -f win32 test.asm -o test.o
C:\>ld test.o -o test.exe
section .data
msg db 'Hello world!', 0AH
len equ $-msg
section .text
global _WinMain@16
_WinMain@16:
mov edx, len
mov ecx, msg
mov ebx, 1
mov eax, 4
int 80h
mov ebx, 0
mov eax, 1
int 80h
According to this post. The main
function is not available under Windows and must be replaced by WinMain
.
So if your entry point is _start
or main
, it should be changed to _WinMain@16
and change the ret
at the end of the procedure to ret 16
:
My working example:
section .text
global _WinMain@16
_WinMain@16:
mov eax, 0
ret 16