2015-01-04 21 views
0

该程序在TASM中制作的目的是将两个单位数字相乘并将结果写入屏幕。它实际上是乘以,但结果显示为ascii符号(我检查了这个网站http://chexed.com/ComputerTips/asciicodes.php和结果是正确的)。我不能让它显示结果为整数,特别是当结果是两位数字时。TASM将乘法结果作为ASCII符号输出,如何转换为整数

 
.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

你必须整数结果转换为字符串,其然后您可以使用int 21h/ah = 9进行打印。

做转换的简单方法如下(我会让你做翻译TASM语法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 
+0

我确实有点不同,但它的作品般的魅力。我发现那个结果保存在al和ah中,所以我改变了它输出这两个的代码,感谢帮助:) – w0jt1 2015-01-04 13:31:18

相关问题