与AX和AL寄存器混淆

问题描述

因此,我正在通过编写打印十六进制数字的函数来弄清楚Assembly。 函数的工作方式:在循环中,它获取数字的最后一位数字,将其转换为char,然后在HEX_OUT字符串(HEX_OUT: DB "0x0000",0处替换char,因此该函数将把每个char重写为输入相应的数字),然后重复该操作,直到该数字将映射到HEX_OUT字符串,然后将其打印出来。

但是我不了解的寄存器存在问题。 问题是,当我将一些值放入ax寄存器(例如6)中,然后将ax的值放入bx寄存器(mov [bx],ax ),最后一天我在屏幕上打印了0x1,但是如果我将指令更改为mov [bx],al,则会得到0x1fb6(假定要打印的数字是0x1fb6 ,这是正确的结果。)

据我所知,由于我将6放在ax中,al寄存器应该等于ax的值。

请用问题所在的[HERE]查看注释行。

; HEX_OUT ("0x0000") is stored in bx
; hexadecimal number to be printed (0x1fb6) is stored in dx

print_hex:
    pusha
    mov cx,0                   ; cx = counter

loop1:
    cmp cx,4                   ; if counter < 4
    jl print                    ; jump to print
    jmp end                     ; else jump to end

print:
    mov ax,dx                  ; ax = 0x1fb6
    and ax,0x000f              ; ax = 6
    cmp ax,9                   ; if ax > 9
    jg num_to_abc               ; make a letter out of char (because hexadecimal)
    jmp next                    ; jump to next

num_to_abc:
    add ax,39
    jmp next

next:
    add ax,'0'                 ; make a char out of num
    mov bx,HEX_OUT + 5         ; bx now points to last char of string
    sub bx,cx                  ; bx = bx - counter
    mov [bx],al                ; [HERE] al is currently 54 (6 + '0'). But why al works properly,but ax doesn't?
    ror dx,4                   ; put last digit at the beginning (before: 0x1fb6,after: 0x61fb)
    inc cx                      ; counter++
    jmp loop1                   ; jump back to loop

end:
    mov bx,HEX_OUT             ; some code
    call print_string
    popa
    ret

print_string函数(我认为它没有任何问题):

print_string:       
pusha               
mov ah,0x0e        
loop:               
    mov al,[bx]    
    cmp al,0       
    je return       
    jmp put_char    
put_char:           
    int 0x10        
    inc bx          
    jmp loop        
return:             
    popa            
    ret             

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...