程式語言 - Netwide Assembler (NASM) - Win32 API - Hello, world!



參考資訊:
https://masm32.com/board/index.php
https://www.nasm.us/xdoc/2.13rc9/html/nasmdoc0.html

經典的Hello, world!程式框架總是能夠讓人細心品味一款程式語言的美好,司徒就使用一個簡單的Message對話盒來展現Hello, world!框架

main.asm

    %include "/opt/wadk/nasm/inc/windows.inc"

    section .data
szCaption DB "",0
szContent DB "Hello, world!",0
 
    section .text
_start:
    push MB_OK
    push szCaption
    push szContent
    push NULL
    call MessageBox
 
    push 0
    call ExitProcess

Makefile

TARGET   = main
CFLAGS  += -f win32
CFLAGS  += -l ${TARGET}.lst
LDFLAGS += -e _start@0
LDFLAGS += -L/opt/wadk/masm32/lib
LDFLAGS += -lkernel32
LDFLAGS += -luser32
LDFLAGS += -ladvapi32
LDFLAGS += -lgdi32
LDFLAGS += -lopengl32

all:
	nasm ${CFLAGS} ${TARGET}.asm
	i686-w64-mingw32-ld ${TARGET}.obj -o ${TARGET}.exe ${LDFLAGS}

run:
	myx86 ${TARGET}.exe

clean:
	rm -rf ${TARGET}.exe ${TARGET}.obj ${TARGET}.lst

編譯、執行

$ make
$ make run