Assembly 如何在汇编中将普通字节转换为ascii?
我正在尝试为我的实模式操作系统编写一个函数,该函数将转储内存。我希望字节0x0a显示为“0A”,0xf3显示为“F3”,依此类推。我编写的代码使用一个由“0123456789ABCDEF”组成的表,并使用单个半字节作为偏移量来查找正确的字符。首先,它保存Assembly 如何在汇编中将普通字节转换为ascii?,assembly,x86,hex,ascii,real-mode,Assembly,X86,Hex,Ascii,Real Mode,我正在尝试为我的实模式操作系统编写一个函数,该函数将转储内存。我希望字节0x0a显示为“0A”,0xf3显示为“F3”,依此类推。我编写的代码使用一个由“0123456789ABCDEF”组成的表,并使用单个半字节作为偏移量来查找正确的字符。首先,它保存al中的值。接下来,它将al向右移动4,移除较低的半字节并向下移动较高的半字节。然后将表加载到di,并将ah归零。接下来,它将ax添加到di以查找偏移量。然后,它将di处的值移动到al中,并将其打印出来。然后,它遵循相同的步骤,只是随后使用低半字
al
中的值。接下来,它将al
向右移动4,移除较低的半字节并向下移动较高的半字节。然后将表加载到di
,并将ah
归零。接下来,它将ax
添加到di
以查找偏移量。然后,它将di
处的值移动到al中,并将其打印出来。然后,它遵循相同的步骤,只是随后使用低半字节而不是高半字节。然而,当我运行它时,它只重复打印出'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'
有什么问题吗?提前谢谢。一个问题是
mov al,bl;保存al
和mov bl,al;重载al
使操作数反转
如果您已经在编写所谓的操作系统,您应该熟悉调试器,这样您就可以修复自己的错误。请看我在本页上的示例,将EAX中的32位值转换为8个十六进制ASCII字节:
这么简单的错误!愚蠢的我!我可能应该有调试器,我从没想过。我想我的操作系统有点业余爱好。可能是