-
June 24th, 2012, 02:42 PM
#1
please explain me this multi-digit print program
Please consider this code:
.model small
.stack 100h
.code
.startup
mov AX,235
; in 16 bit DIV
; dividend = AX
; divisor = any register, bx in this case
; quotient = AX
; remainder = DX
mov cx,0
mov bx,10
Next:
mov dx,0
div bx
push dx
inc cx
cmp ax,0
ja Next
show:
pop dx
mov dh,0
add dl,48
mov ah,02
int 21h
loop show
mov ah,4ch ; terminate to DOS successfuly
int 21h
end
I know the logic is "divide the number repeatedly, pushing remainders in stack, and then display one by one poping back from stack" My confusion is this;
ax = 235
after 1st div: remainder = dx = 5, and quotient = ax = 23
after 2nd div:remainder = dx = 3, and quotient = ax = 2
after 3rd div: remainder = dix = 0, and quotient = ax = 0.2
poping should yield:035 but it gives 235 correctly. I wonder what happens with last div that is gives 2 correctly. Please help me.
Best Regards
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|