Click here to Skip to main content
15,889,931 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone!

I Am New In Assembly Language, and during Practice i got one problem in Number Division. i make Program Which Take 4 Digit In Input and store in DW Array . but on Output Time Program Give Me Wrong output .

For Example.

If I Enter 1234 The output of the Program is "4321" But i want "1234" in output Result .

Please See the Code and tell me if any one know about this.

ASM
.model small
.stack 100h
.data
arr dw 0,0
ten db 10

.code
main proc
mov ax,@data
mov ds,ax

mov ah,1
int 21h
sub al,48
mov al,al
mul ten
mov arr,ax

mov ah,1
int 21h
sub al,48
mov ah,0
add arr,ax
mov ax,arr
mov al,al
mul ten
mov arr,ax

mov ah,1
int 21h
sub al,48
mov ah,0
add arr,ax
mov ax,arr
mov al,al
mul ten
mov arr,ax

mov ah,1
int 21h
sub al,48
mov ah,0
add arr,ax

;Strat Division from Here

mov ax,arr
div ten
mov ch,ah
mov cl,al
mov ah,2
mov dl,ch
add dl,48
int 21h
mov ah,0
mov al,cl
div ten

mov ch,ah
mov cl,al
mov ah,2
mov dl,ch
add dl,48
int 21h
mov ah,0
mov al,cl
div ten
mov ch,ah
mov cl,al
mov ah,2
mov dl,ch
add dl,48
int 21h



mov dl,cl
add dl,48
int 21h

mov ah,4ch
int 21h
main endp
end main
Posted

1 solution

You are using the divide operation to get the remainder of number / 10, and you then print the remainder value. So the first value you print will be 4, then 3 etc. You need to build an array in memory of these digits and then print them in reverse order. You could also improve this considerably by using index values and loops.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900