我正在研究我的第一个程序,它执行一些计算并将结果存储在AL寄存器中。我有一个问题,我从HEX转换为ASCII子程序,将其打印到屏幕。因此,如果AL中的值介于0和9之间,则打印ASCII值没有问题。问题是如果AL中的值大于9,我打印了3个零。请,任何评论可能会有所帮助。这是我的代码:
FNUM DB 20 Dup ?
B2A8:
LEA DI, FNUM ;point DI to ASCII save
MOV W[DI], 3030H ;preload ASCII buffer with number bias
MOV B[DI+2], 30H
B2A1:
SUB AL, 100 ;subtract 100's placeholder value
JC B2A2 ;if negative, we subtracted too much
INC B[DI] ;if positive, add 1 to ASCII byte
JMP B2A1 ;continue counting place values until minus
B2A2:
ADD AL, 100 ;restore AL to previous value over subtracted
B2A3:
SUB AL, 10 ;subtract 10's placeholder value
JC B2A4 ;if negative, we subtracted too much
INC B[DI+1] ;if positive, add 1 to ASCII byte
JMP B2A3 ;continue counting place values until minus
B2A4:
ADD AX, 10 ;restore AL to previous value over subtracted
ADD [DI+2], AL ;create units character
MOV B[DI+3], '$' ;mark end of the text
RET