我有一个单词数组,有 4 个单元格
RESULT DW 4 DUP(0)
它将包含二进制数,例如
MOV RESULT, 0H
MOV RESULT+2, 0H
MOV RESULT+4, 35A4H
MOV RESULT+6, E900H
现在结果包含 0000000035A4E900H
,这意味着十进制的 900000000。
不是我想在显示器上打印 900000000。
我该怎么办?
最佳答案
不管你用什么语言转十进制打印十进制都是一样的过程。那么两个过程之一。您可以从任一端开始。假设您有一个 16 位数字 12345 (0x3039)。
第一种方式是
divide by 10000 result is 1 remainder 2345 save or print the 1
divide by 1000 result is 2 remainder 345 save or print the 2
divide by 100 result is 3 remainder 45 save or print the 3
divide by 10 result is 4 remainder 5 save or print the 4 and 5
第二种方式
divide by 10 result is 1234 remainder 5 save the remainder use the result
divide by 10 result is 123 remainder 4 save the remainder use the result
divide by 10 result is 12 remainder 3 save the remainder use the result
divide by 10 result is 1 remainder 2 save both the remainder and result
print the results in the right order
现在,如果您的问题是如何使用我的指令集将 64 位数字除以这些 10 的幂,那么有时您可以,有时您不能,有时您必须使用其他数学规则。除以 10 与除以 2*5 相同,因此您可以除以 2(移位)然后除以 5。
0x3039 (12345) 除以 10000 与右移 4 然后除以 5 的 4 次方 (625) 相同。 0x303 = 771, 771/625 = 1。如果你的除法不是那么大,你的乘法可能也不是那么大 1 * 625 = 0x271, 0x271
您可能需要除以中间的一个数字,假设您有一个 32 位数字(最大 4,294,967,296),并且您的硬件可以将 32 位数字除以 16 位结果和 16 位余数。您可以使用上述方法敲掉几个数字,比如留下 94,967,295 然后除以 10000 得到 9496 余数 7295 然后使用硬件独立处理这四位数字。
如果您没有除法硬件而是乘法硬件(是的,我知道您指定了 8086),您可以这样做:
http://www.divms.uiowa.edu/~jones/bcd/divide.html
如果您还记得小学时如何用铅笔和纸做乘法:
1234
x1010
=====
0000
1234
0000
+1234
========
1246340
二进制使这变得非常简单,正如您从我选择的数字中所想象的那样
abcd
x efgh
======
如果你想将四位 abcd 乘以四位 efgh 那么:
result = 0;
if(h) result+=abcd << 0;
if(g) result+=abcd << 1;
if(f) result+=abcd << 2;
if(e) result+=abcd << 3;
对于大多数指令集,您可以将这个倍数级联到您有内存的宽度,想要将 100 万位乘以 100 万位。没问题,500,000 字节加上多一点或几个寄存器(以及很多时钟周期)。
https://stackoverflow.com/questions/9079379/