I'm working on my first program that does some calculations and the result store in AL register. I have a problem with my converting from HEX to ASCII subroutine to print it to screen. So, If the value in AL between 0 and 9, it print the ASCII value with no problems. The problem is if the value in AL bigger than 9, I got 3 zeros printed. Please, any comment might help. This is my code:
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