我正在尝试为我的真实模式操作系统编写一个函数,该函数将转储内存。我希望字节0x0a显示为“0A”,0xf3显示为“F3”,依此类推。我编写的代码使用由“0123456789ABCDEF”组成的表,并使用单个半字节作为偏移量来查找正确的字符。首先,它保存值
al
。下一步它会移动
铝
向右移动4,移除较低的半字节并向下移动较高的半字节。然后将表加载到
di
,并清零
ah
。接下来,它添加了
ax
到
二
以查找偏移。然后将值移动到
二
然后,它遵循相同的步骤,只是使用低半字节而不是高半字节。然而,当我运行它时,它只重复打印“33”,而不是实际的十六进制数。这是我的代码:
memdump:
mov si, 0x7000 ;load si
loop:
mov al, [si] ;put the value at si into al
call printhex ;call the hex printer
inc si ;increment si
cmp si, 0x7CFF ;are we done?
je done ;yes, return
jmp loop ;loop
printhex:
mov al, bl ;save al
shr al, 4 ;remove the lower nibble and move the higher nibble down
mov di,hexbuffer ;put the hexadecimal buffer in di
xor ah, ah ;remove everything from ah
add di, ax ;add the address to the buffer
mov al, [di] ;move the ascii char into al
mov ah, 0x0E ;teletype printing for int 0x10
int 0x10 ;print the character
mov bl, al ;reload al
shl al, 4 ;remove the high nibble
shr al, 4 ;move the new high nibble down
mov di, hexbuffer ;reload the buffer
xor ah, ah ;zero out ah
add di, ax ;add the offset
mov al, [di] ;transfer the ascii char
mov ah, 0x0E ;teletype printing for int 0x10
int 0x10 ;print the char
mov al, ' ' ;now print a space
int 0x10 ;print the space
ret ;return
done:
ret ;return to kernel
hexbuffer db '0123456789ABCDEF'
它有什么问题?提前谢谢。