在8086年将数字转换为ascii

时间:2014-05-04 01:12:26

标签: assembly ascii x86-16 tasm dosbox

在8086(tasm)我试图将数字打印到屏幕上。以下代码适用于大多数但是15876失败。我的问题是如何反复划分16876并将其数字作为提醒?还是有更好的打印15876?

谢谢。

    lea si,answerst         ;holds output
    add si,5                ;max length of ans

    ;add a $ at the end
    mov bh,24h      
    mov [si],bh
    dec si        ;decrements si 

    mov bx,15876  ;the number to print
    mov ax,bx     ;put it in ax because div uses ax
    mov cx,10     ;10 is the dividend

spctostring:
    cmp al,0      ;if the quotient is zero you have reached the end of the num          
    je stringme   ;if you have reached the end of the num print it out

    div cl        ;divide by 10     
    mov bh,ah     ;put the reminder in bh
    mov ah,0      ;resets ah

    add bh,30h    ;add 30 hex to get ascii value
    mov [si],bh   ;place the char in the output string
    dec si        ;decrements si

    jmp spctostring

stringme:
;---------------Output-------------------
    mov ah,09h      ;print string cmd 
    lea dx,numone   ;string to print
    int 21h         ;print interrupt

0 个答案:

没有答案