programming-in-emu8086___with-brief-theory

This project is maintained by MahediKamal

💜4 ) display a (multi-digit) decimal number in reverse order. Assume, the number is given in AX. Don’t have to take input. (without using stack)

Example: AX=12345; Output: 54321

Solution code:

		.model small
		.stack 100h
		.data
			n    db ?
			i    db ?
			rem db 0d
			qut db 0d
			res dw 12345d 
			lft dw 0d
			rev_res dw 0d
			ln dw 0d
			md db 0d  

		.code  
			main proc
				
				mov ax,@data
				mov ds,ax
				
				mov ax,12345d
				mov res,ax
				
				mov bx,res   
				mov lft,bx
				for_number_ln:
				mov bx,lft
				cmp bx,0
				jle break2
				
					mov ax,lft
					mov dx,0d
					
					; word division
					mov bx,10d
					div bx ; ax=dx:ax/10 , dx=dx:ax%10
					
					mov rem,dl
					mov lft,ax 
					
					
				   
					
					mov ah,2
					mov dl,rem
					add dl,48d
					int 21h
				
					inc ln
				
				loop for_number_ln
				break2:  
				
				
						  
			main endp

		end main