I’m using SDL with FASM, and have code that’s minimally like the following:
format ELF
extrn _SDL_Init
extrn _SDL_SetVideoMode
extrn _SDL_Quit
extrn _exit
SDL_INIT_VIDEO equ 0x00000020
section '.text'
public _SDL_main
_SDL_main:
ccall _SDL_Init, SDL_INIT_VIDEO
ccall _SDL_SetVideoMode, 640, 480, 32, 0
ccall _SDL_Quit
ccall _exit, 0 ; Success, or
ret ; failure.
With the following quick-and-dirty makefile:
SOURCES = main.asm
OBJECTS = main.o
TARGET = SDLASM.exe
FASM = C:\fasm\fasm.exe
release : $(OBJECTS)
ld $(OBJECTS) -LC:/SDL/lib/ -lSDLmain -lSDL -LC:/MinGW/lib/ -lmingw32 -lcrtdll -o $(TARGET) --subsystem windows
cleanrelease :
del $(OBJECTS)
%.o : %.asm
$(FASM) $< $@
Using exit() (or Windows’ ExitProcess()) seems to be the only way to get this program to exit cleanly, even though I feel like I should be able to use retn/retf. When I just ret without calling exit(), the application does not terminate and needs to be killed. Could anyone shed some light on this? It only happens when I make the call to SDL_SetVideoMode().
I noticed that
retworks to end the program, but as far as I know that’s not guaranteed anywhere by Microsoft.The official way to end a program is to call
exit()orExitProcess().(In C, the compiler has to arrange the code so that it is equivalent to calling
exit().Also, I suspect that a lot of existing programs use
retinstead, of it seems unlikely that Microsoft would change that behavior.)About your problem, SDL does some black magic before your program is called: http://www.libsdl.org/faq.php?action=listentries&category=4#48.
I would suggest that you use a
main()entry point, as suggested in the FAQ.