程式語言 - MASM32 - x64 - Hello, world!



參考資訊:
https://www.masm32.com/

Microsoft規定:
1. 保留給API呼叫使用的記憶體稱為Shadow Storage
2. Shadow Storage必須由呼叫者建立跟刪除
3. Shadow Storage = (參數數量 * 8 bytes),最少必須是32 bytes(即使參數不足四個)
4. Stack必須要16 bytes記憶體對齊
5. 前四個參數放在RCX, RDX, R8, R9
6. 第五個參數才開始放在Stack

main.asm

    option casemap:none
 
include c:\masm64\include64\masm64rt.inc
 
    .const
szCaption BYTE " ",0
szContent BYTE "Hello, world!",0
    
    .code
start proc
    invoke MessageBox, NULL, addr szContent, addr szCaption, MB_OK
    invoke ExitProcess, 0
start endp
end

Makefile

TARGET=main

all:
	myx86 "c:\masm64\bin\ml64.exe" /c ${TARGET}.asm
	myx86 "c:\masm64\bin\link.exe" /subsystem:windows /entry:start ${TARGET}.obj

run:
	myx64 ${TARGET}.exe

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

編譯、執行

$ make
$ make run