TASM 将乘法结果输出为 ascii 符号,如何转换为整数

TASM outputs result of multiplication as ascii symbol, how to convert to integer

在 TASM 中制作的这个程序的目的是将两个单数相乘并将结果写在屏幕上。它的作用实际上是相乘,但结果显示为 ascii 符号(我检查了这个网站 http://chexed.com/ComputerTips/asciicodes.php,结果是正确的)。我无法将结果显示为整数,尤其是当结果是两位数时。

.型号小
.stack 

.数据

msgA DB "Input 1st number: $"
msgB DB 10, 13, "Input 2nd number $"
msgC DB 10, 13, 10, 13, "Result: $"
msgD DB 10, 13, 10, 13, "Error, retry", 10, 13, 10, 13, "$"

.代码

MOV 斧头,@DATA MOV DS, AX

jmp start num1 DB ? num2 DB ? result Dw ? start: mov ah, 09 mov dx, offset msgA int 21h mov ah, 01 int 21h mov num1, al mov ah, 09 mov dx, offset msgB int 21h mov ah, 01 int 21h mov num2, al mov al,num1 sub al,'0' mov bl,num2 sub bl,'0' mul bl add ax,'0' mov result, ax sub result, 48 mov ah, 09 mov dx, offset msgC int 21h mov ah, 02 mov dx, result int 21h mov ax, 4c00h int 21h end

您必须将整数结果转换为字符串,然后您可以使用 int 21h / ah = 9.

进行打印

进行转换的简单方法如下(我会让您将其转换为 TASM-syntax x86 程序集):

ax = the value to convert
si = &buffer[9];     // buffer is an array of at least 10 bytes
buffer[9] = '$';     // DOS string terminator
do {
    ax /= 10;
    si--;            // the buffer is filled from right to left
    *si = dl + '0';  // place the remainder + '0' in the buffer
} while (ax != 0);
dx = si;             // dx now points to the first character of the string