flat assembler
Message board for the users of flat assembler.

flat assembler > Main > Exit program without libraries

Author
Thread Post new topic Reply to topic
Mino



Joined: 14 Jan 2018
Posts: 156
Good morning,
I'm looking for a way to end the program without using
Code:
 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:

Code:
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:

Image

Some ideas Very Happy ?

Thank you very much in advance.

_________________
The best way to predict the future is to invent it.
Post 09 May 2018, 22:02
View user's profile Send private message Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 1227
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:
Code:
ret    



EDIT: Because the wiki example for 32-bit Linux is in GAS, here's translation to FASM:
Code:
_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    
Their 64-bit example is in FASM:
Code:
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    
Post 09 May 2018, 23:40
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2018, Tomasz Grysztar.

Powered by rwasa.