问题
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