nasm和masm使用上有一定的語法區別,而windows環境的nasm教程有較少,經過自己研究,寫下這個教程
org 0100h ;PSP前綴,程序從0100h開始運行
mov ax, cs ;初始化 ds和dx寄存器,爲調用9號程序(顯示字符串)做準備
mov ds, ax
mov dx, string ;取偏移地址,等價於MASM的 lea dx, string 或 mov dx, offset string
mov ah, 9
int 21h
MOV AH,4CH ;回到操作系統
INT 21H
string db "Hello, OS world!$"
編譯方法如下:
nasm hello.asm -o hello.com
需要使用doxbox運行,相關軟件下載地址如下: