繁体   English   中英

如何在汇编中将普通字节转换为ASCII?

[英]How to convert normal bytes to ascii in assembly?

我正在尝试为我的实模式操作系统编写一个函数,该函数将转储内存。 我希望字节0x0a显示为'0A',0xf3显示为'F3',依此类推。 我编写的代码使用的表由'0123456789ABCDEF'组成,并使用单个半字节作为偏移量来查找正确的字符。 首先,它保存值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; save al mov al, bl; save almov bl, al ; reload al mov bl, al ; reload al所有操作数。

如果您已经在编写所谓的操作系统,则应该熟悉调试器,以便自己解决错误。

请查看我在此页面上的示例,该示例将EAX中的32位值转换为8个十六进制ASCII字节: 以汇编语言打印数字?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM