题
我有点羞于问这个问题,但是我如何在汇编器中输出一个字节的值?假设 AL 寄存器中有数字 62。我的目标是8086。似乎只有输出它的 ascii 值的中断可用。
编辑: 谢谢尼克 D,这就是我一直在寻找的。为了回答几个问题,我实际上使用的是模拟器,emu8086。该代码将用于使用过时设备的工厂中的小型应用程序(即这是一个秘密)。
使用 Nick D 的想法,解决方案看起来有点像这样:
compare number, 99 jump if greater to over99Label compare number, 9 jump if greater to between9and99Label ;if jumps failed, number has one digit printdigit(number) between9and99Label: divide the number by 10 printascii(quotient) printascii(modulus) jump to the end over99Label: divide the number by 100 printascii(quotient) store the modulus in the place that between9and99Label sees as input jump to between9and99Label the end: return
对于无符号字节它工作得很好:)
解决方案
// pseudocode for values < 100
printAscii (AL div 10) + 48
printAscii (AL mod 10) + 48
将值转换为字符串表示并打印。
其他提示
我目前无法访问汇编器来检查它,而且语法会根据您使用的汇编器而有所不同,但这仍然应该传达这个想法。
FOUR_BITS: .db '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' ; If ebx need to be preserved do so push ebx ; Get the top four bits of al mov bl, al shl bl, 4 ; Convert that into the ASCII hex representation mov bl, [FOUR_BITS + bl] ; Use that value as a parameter to your printing routine push bl call printAscii pop bl ; Get the bottom four bits of al mov bl, al and bl, 0xF ; Convert that into the ASCII hex representation mov bl, [FOUR_BITS + bl] ; Use that value as a parameter to your printing routine push bl call printAscii pop bl
不隶属于 StackOverflow