Reputation: 723
I'm currently trying to learn some basic x86 assembly and running into some difficulties running it on Windows. All I'm trying to do is set the exit status. I'm aware of how to do this if I was on Linux:
global _start
_start:
mov eax,1
mov ebx, 52
int 0x80
Obviously this will give exit status 52. How do I do this on Windows? I looked all over but couldn't find a clear answer.
Upvotes: 1
Views: 2166
Reputation: 1572
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 $?
Upvotes: 1