linux nasm move a value in AL up to AX

十年热恋 提交于 2019-12-22 10:45:30

问题


I am working on a way to print multiple digit integers by dividing the integer by 10 repeatedly and collecting the remainders, then printing them. Here is a code segment that has the problem:

Divide:

    ; initial division
    mov ax, 111   ; number we want to print
    mov ch, 10    ; we divide by ten to siphon digits
    div ch        ; divide our number by 10

    ; al now has 11, ah has 1
    mov dh, ah ; save the remainder in dh
  1 mov bx, al ; these lines refill ax with the number to 
    mov ax, bx ; divide
    mov ch, 10 ; refill ch with the divisor
    div ch     ; al now has 1, ah now has 1

The line marked with 1 has the problem. I need to move a value in 8 bit register AL to a 16 bit register AX. How can I get that value there so I can divide it?


回答1:


Just clear the ah register instead. The ax register consists of it's high and low part - ah:al

The same applies to bx (bh,bl) cx (ch,cl) and dx (dh,dl) registers



来源:https://stackoverflow.com/questions/12879740/linux-nasm-move-a-value-in-al-up-to-ax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!