因爲DX所做的計劃將無法正常工作NOT指向「str1」的地址。
首先,將str1的地址壓入SP指向的堆棧中。這是沒有問題的。
但是,在調用函數「show_str」來打印str1後,SP將不再指向str1,因爲原始IP的值將被壓入堆棧中,SP指向該堆棧。
你沒有意識到SP的改變,仍然試圖將SP的值傳遞給DX,DX應該存儲要打印的字符串的地址。
我的建議是,您應該使用「正常」風格來編寫程序,因爲除非您正在探索語言本身的祕密,否則這會讓我們的生活更輕鬆。
這是我的程序。
;file: showmsg.asm (.COM)
;nasm -fbin showmsg.asm -o showmsg.com
org 0x100
mov ax, cs
mov ds, ax
mov ax, str1 ;Transmit parameter to show_msg through AX
call show_msg
mov ax, 4c00h
int 21h
show_msg: ;the address offset of the string is stored in ax
mov dx, ax ;DS:DX=string address
mov ax, 0900h ;AH=09
int 21h
ret
str1: db "Hello, world!$"
在哪臺機器和操作系統應該正常工作? – ShinTakezou
在16位DOS上... – user1091856