是的,就是你will最有可能得到一个奇怪的字符,因为 int 21/ah=02 要求打印的字符位于dl
注册,并且您还没有填充dl
与任何东西。
您可能想通过以下方式转移值:
mov ax, 10
add ax, 5
push ax ; these are the two new lines.
pop dx
mov ah, 02h
但是,请记住,即使您do转移价值al
to dl
,第 15 个字符可能不是您所期望的。 15 是 ASCII 控制字符之一,我不确定 DOS 中断将为它们输出什么。
如果你想打印出数字15
, 你会需要two来电,一dl = 31h
第二个是dl = 35h
(这两个 ASCII 代码1
and 5
人物)。
如果你想知道如何在寄存器中取出一个数字并输出digits对于可读形式的该数字,有一些伪代码我之前的一个回答 https://stackoverflow.com/questions/7884143/how-to-print-numbers-greater-then-10-in-arm200-assembly-language/7884259#7884259.
从这个答案中,你可以得到伪代码:
val = 247
units = val
tens = 0
hundreds = 0
loop1:
if units < 100 goto loop2
units = units - 100
hundreds = hundreds + 1
goto loop1
loop2:
if units < 10 goto done
units = units - 10
tens = tens + 1
goto loop2
done:
if hundreds > 0: # Don't print leading zeroes.
output hundreds
if hundreds > 0 or tens > 0:
output tens
output units
;; hundreds = 2, tens = 4, units = 7.
现在您需要将其转换为 x86 程序集。让我们从所需的值开始ax
:
mov ax, 247 ; or whatever (must be < 1000)
push ax ; save it
push dx ; save dx since we use it
mov dx, 0 ; count of hundreds
loop1:
cmp ax, 100 ; loop until no more hundreds
jl fin1a
inc dx
sub ax, 100
jmp loop1
fin1a:
add dx, 30h ; convert to character in dl
push ax ; save
mov ah, 2
int 21h ; print character
pop ax ; restore value
; now do tens and units the same way.
pop dx ; restore registers
pop ax
现在,代码段(尽管由于我进行汇编已经有一段时间了而出现任何错误)应该打印出百位数字,并只留下 ax 的十位和个位数字。
将功能重复两次以获得十位和个位应该是一件简单的事情。