乘法错误没有得到正确的结果?

Multiplication error not getting proper result?

我想做什么?

我从用户那里获取两个整数并尝试使用 mul 指令将它们相乘。

问题是什么?

每次我尝试乘以 2 个整数并尝试显示结果时,我得到字母表 T 作为输出。

data segment 

    msg1 db "Enter first number:$" 
    msg2 db 10, 13,"Enter second number:$" 
    msg3 db 10, 13,"The product is:$"
    n1 db ? 
    n2 db ?
    pkey db "press any key...$" 

ends

stack segment

    dw 128 dup(0) 

ends

code segment 
start: ; set segment registers: mov ax, data mov ds, ax mov es, ax

; add your code here

mov ax, @data 
mov ds, ax

mov dx, offset msg1 
mov ah,09h 
int 21h

mov ah, 01h 
int 21h

sub al, 48 
mov n1, al

mov dx, offset msg2 
mov ah, 09h 
int 21h

mov ah, 01h 
int 21h

sub al, 48 
mov n2, al

mul n1

mov bl, al

mov dx, offset msg3 
mov ah, 09h 
int 21h  

add bl, 48 
mov dl, bl 
mov ah, 02h 
int 21h

mov ah, 4ch 
int 21h

lea dx, pkey 
mov ah, 9 
int 21h ; output string at ds:dx

; wait for any key....
mov ah, 1 
int 21h

mov ax, 4c00h ; exit to operating system. int 21h
ends

end start ; set entry point and stop the assembler.

为什么输出字母表 T

这些指令:

mov dx, offset msg3 
mov ah, 09h 
int 21h

导致 AL 的值被更改为 24 (它实际上是 INT 21h 指令将 AL 的值更改为 24)和指令 mov ah, 09hAH 的内容设置为 09。然后下一条指令

add ax, 48 

48 添加到 AX 的内容中,在 AL 中给出 84(十六进制的 54),这是 T 的 ASCII 值,然后显示内容AL 个,代码如下:

mov dl, al 
mov ah, 02h 
int 21h

显示字母 T

要修复它,请执行以下操作:

mul 指令后添加:

mov bl, al     ; save the content of AL to BL

显示后 msg3 像这样将 al 的出现更改为 bl:

add bl, 48   
mov dl, bl 
mov ah, 02h 
int 21h