Write an assembly program to REVERSE THE GIVEN DIGITS
title to reverse the given digits
dosseg
.model small
.stack 100H
.code
main proc
mov ax, @data ; initialize ds register
mov ds, ax
mov ax, value1 ; move number to ax
mov cx, 0000h ; remainder r = 0
mov bx, 0010h ; for multiplication by 10h
BACK: mov dx, 0000h ; clear upper 16-bits
div bx ; divide the number ie dx= remainder, ax = quotient
push ax ; push remainder and quotient onto the stack
push dx
mov ax, cx ; r = 0
mul bx ; r = r * 10
pop dx
add ax , dx ; r = r * 10 + n mod 10
mov cx, ax ; keep reverse digits in cx register
pop ax ; or ax, ax ie number = 0
jnz BACK
mov ax, 4C00H ; return to DOS
int 21H
main endp
.data
value1 dw 789A h
list dw 4 dup (?)
end main
Visit our download section to download free simulators/ emulators and other essential engineering softwares or join the free update newsletters now.