我需要制作一个将内存地址转换为字节串的例程。然后该字符串将成为打印以空字符结尾的字符串(我已经能够制作)的函数的输入。例如,如果我有一个地址 0x1bf9,我需要将文本“1bf9”打印到屏幕上。这本书还没有进入 32 位模式,但它暗示我们也需要它。这是我到目前为止所拥有的:
TABLE:
db "0123456789ABCDEF", 0
STRING:
db 0
hex_to_char:
lea bx, TABLE
mov ax, dx
mov ah, al ;make al and ah equal so we can isolate each half of the byte
shr ah, 4 ;ah now has the high nibble
and al, 0x0F ;al now has the low nibble
xlat ;lookup al's contents in our table
xchg ah, al ;flip around the bytes so now we can get the higher nibble
xlat ;look up what we just flipped
inc STRING
mov [STRING], ah ;append the new character to a string of bytes
inc STRING
mov [STRING], al ;append the new character to the string of bytes
ret