參考資訊:
https://board.flatassembler.net/
main.asm
format PE GUI 4.0 entry start include "c:\fasm\include\win32a.inc" section ".idata" import data readable writeable library user, "user32.dll", kernel, "kernel32.dll" import user, MessageBox, "MessageBoxA" import kernel, ExitProcess, "ExitProcess" section ".data" data readable writeable szCaption db "main",0 szContent db "Hello, world!",0 section ".text" code readable executable start: invoke MessageBox, NULL, szContent, szCaption, MB_OK invoke ExitProcess, 0
Line 1:執行檔的格式
Line 2:程式的進入點
Line 4:Header檔案
Line 6:Import區段
Line 7:使用到的Library
Line 9~10:使用到的Win32 API
Line 12:初始化的資料區段
Line 13~14:初始化的Global變數,型態是byte(char)且最後一個byte是0
Line 16:程式區段
Line 17:程式的進入點
Line 18:顯示Message對話盒,invoke其實就是call + push的綜合指令
Line 19:結束Process並且釋放相關資源
Makefile
export WINEPREFIX=/home/user/.wine_x86 TARGET=main MYWINE=box86 wine FASM32=/home/user/.wine_x86/drive_c/fasm all: ${MYWINE} ${FASM32}/fasm.exe ${TARGET}.asm run: ${MYWINE} ${TARGET}.exe clean: rm -rf ${TARGET}.exe
編譯、執行
$ make $ make run