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

时间:2015-01-04 11:56:34

标签: assembly x86 tasm

在TASM中制作的程序的目的是将两位数字相乘并将结果写在屏幕上。它实际上是多少,但结果显示为ascii符号(我使用此网站http://chexed.com/ComputerTips/asciicodes.php检查,结果是正确的)。我不能把它显示为整数,特别是当结果是两位数时。

.model small
.stack 

.data

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, "$"

.code

MOV AX, @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

1 个答案:

答案 0 :(得分:1)

您必须将整数结果转换为字符串,然后您可以使用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