How do I do this on Windows? I looked all over but couldn't find a clear answer.
That is the issue here: There is no clear answer. Windoze is a mess. Use Linux and be happy. :−)
As it’s already been mentioned, there is no universal method to interface with the OS.
On WinD0S, for instance, it would’ve been int 21h
:
segment code
start:
mov ah, 0x4C ; function `exit – terminate with return code`
mov al, 52 ; return code
int 0x21 ; DOS kernel interrupt
What you probably wanna do is, as David Wohlferd already pointed out, use ExitProcess
:
global start
extern _ExitProcess@4
section .text
start:
push 52
call _ExitProcess@4
On a GNU/Linux Debian(-like) system with a wine(1)
installation the steps look like:
nasm -f win32 -o exitdemo.obj exitdemo.asm
i686-w64-mingw32-ld exitdemo.obj -lkernel32 -o exitdemo.exe
wine ./exitdemo.exe; echo $?