Assembly 用汇编语言打印十进制数?

Assembly 用汇编语言打印十进制数?,assembly,x86,output,decimal,Assembly,X86,Output,Decimal,我试图得到十进制形式的输出。请告诉我,我可以做什么来获得相同的十进制变量,而不是ASCII .model small .stack 100h .data msg_1 db 'Number Is = $' var_1 db 12 .code add_1 proc mov ax, @data mov ds, ax mov ah, 09 lea dx, msg_1 int 21h mov ah, 02 mov dl, va

我试图得到十进制形式的输出。请告诉我,我可以做什么来获得相同的十进制变量,而不是ASCII

.model small
.stack 100h

.data

msg_1   db   'Number Is = $'
var_1   db   12

.code

add_1 proc
    mov ax, @data
    mov ds, ax
    mov ah, 09
    lea dx, msg_1
    int 21h
    mov ah, 02
    mov dl, var_1
    int 21h
    mov ah, 4ch
    int 21h
add_1 endp

end add_1

你写的这三行:

打印由var_1变量中的ASCII码表示的字符

要打印十进制数,需要进行转换。
var_1变量的值足够小(12),因此可以使用精心编制的代码来处理0到99之间的数字。该代码用于简单地除以10。
addax,3030h
将实际转换为字符。它之所以有效,是因为“0”的ASCII码是48(十六进制为30h),而且所有其他数字都使用下一个更高的ASCII码:“1”是49,“2”是50

mov al, var_1      ; Your example (12)
aam                ; -> AH is quotient (1) , AL is remainder (2)
add ax, 3030h      ; -> AH is "1", AL is "2"
push ax            ; (1)
mov dl, ah         ; First we print the tens
mov ah, 02h        ; DOS.PrintChar
int 21h
pop dx             ; (1) Secondly we print the ones (moved from AL to DL via those PUSH AX and POP DX instructions
mov ah, 02h        ; DOS.PrintChar
int 21h
如果您对打印大于99的数字感兴趣,那么 看看我发布的一般解决方案

除以10,在余数中为每个数字加上“0”,然后按相反顺序打印。对于负数,请打印“-”
mov al, var_1      ; Your example (12)
aam                ; -> AH is quotient (1) , AL is remainder (2)
add ax, 3030h      ; -> AH is "1", AL is "2"
push ax            ; (1)
mov dl, ah         ; First we print the tens
mov ah, 02h        ; DOS.PrintChar
int 21h
pop dx             ; (1) Secondly we print the ones (moved from AL to DL via those PUSH AX and POP DX instructions
mov ah, 02h        ; DOS.PrintChar
int 21h