Message board for the users of flat assembler.
> Main > Exit program without libraries
Mino 09 May 2018, 22:02
I'm looking for a way to end the program without using
invoke ExitProcess, 0
And without any libraries, but what I could find on the Internet was talking about DOS instruction (and I would like it to work on Windows first, as well as on a UNIX/Linux system).
Here is an example of a code that does not close after execution:
format PE entry main section '.code' code executable main: push ebp mov ebp, esp mov DWORD [ebp-4], edi mov DWORD [ebp-16], esi mov DWORD eax, 21 sub eax, 7 mov edi, eax call square mov esp, ebp pop ebp square: push ebp mov ebp, esp mov DWORD [ebp-4], edi ; n -> DWORD (4 bits) ; ... pop ebp ret
(by the way, this is the code that my compiler generates for the moment, what could I improve in it?)
There is also always on Windows the shield icon for the administrator mode:
Some ideas ?
Thank you very much in advance.
The best way to predict the future is to invent it.
|09 May 2018, 22:02||
Furs 09 May 2018, 23:40
Wikipedia has some examples for Linux: https://en.wikipedia.org/wiki/Exit_%28system_call%29
There is no stable way to do it in Windows, because the system calls vary between Windows versions. That's why Microsoft want you to use their libraries (e.g. kernel32.dll) since those are stable.
I guess you could just:
EDIT: Because the wiki example for 32-bit Linux is in GAS, here's translation to FASM:
Their 64-bit example is in FASM:
_start: mov eax, 1 ; System call number 1: exit() mov ebx, 0 ; Exits with exit status 0 int 0x80 ; Passes control to interrupt vector ; invokes system call—in this case system call ; number 1 with argument 0
format ELF64 executable 3 entry start segment readable executable start: ; STUFF ; exiting mov eax, 60 ; sys_exit syscall number: 60 xor edi, edi ; set exit status to 0 (`xor edi, edi` is equal to `mov edi, 0` ) syscall ; call it
|09 May 2018, 23:40||
< Last Thread | Next Thread >
Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.