Write a program in assembly language to reverse a given number – IGNOU MCA Assignment 2017 – 18

By | December 9, 2017

MASTER OF COMPUTER APPLICATIONS

Course Code : MCSL-017
Course Title : C and Assembly Language Programming (Lab Course)
Assignment Number : MCA(1)/L-017/Assignment/17-18
Maximum Marks : 50
Weightage : 25%

Write a program in assembly language to reverse a given number – IGNOU MCA Assignment 2017 – 18

Code:-

DATA SEGMENT
NUM1 DW 12345
NUM2 DW ?
ARRY DB 10 DUP (0)
TEMP DW ?
MSG1 DB 10,13,’STORED NUMBER IN MEMORY IS : $’
MSG2 DB 10,13,’REVERSE NUMBER IS : $’
RES DB 10 DUP (‘$’)
DATA ENDS

DISPLAY MACRO MSG
MOV AH,9
LEA DX,MSG
INT 21H
ENDM
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX

DISPLAY MSG1

MOV AX,NUM1

LEA SI,RES
CALL HEX2DEC

LEA DX,RES
MOV AH,9
INT 21H

LEA SI,ARRY
MOV AX,NUM1

REVE:
MOV DX,0
MOV BX,10
DIV BX
MOV ARRY[SI],DL
MOV TEMP,AX
MOV AX,DX

INC SI
MOV AX,TEMP
CMP TEMP,0
JG REVE

LEA DI,ARRY
LAST:
INC DI
CMP ARRY[DI],0
JG LAST

DEC DI
MOV AL,ARRY[DI]
MOV AH,0
MOV NUM2,AX
MOV CX,10
CONV:
DEC DI
MOV AL,ARRY[DI]
MOV AH,0
MUL CX
ADD NUM2,AX

MOV AX,CX
MOV BX,10
MUL BX
MOV CX,AX

CMP ARRY[DI],0
JG CONV

DISPLAY MSG2

MOV AX,NUM2

LEA SI,RES
CALL HEX2DEC

LEA DX,RES
MOV AH,9
INT 21H

MOV AH,4CH
INT 21H
CODE ENDS

HEX2DEC PROC NEAR
MOV CX,0
MOV BX,10

LOOP1: MOV DX,0
DIV BX
ADD DL,30H
PUSH DX
INC CX
CMP AX,9
JG LOOP1

ADD AL,30H
MOV [SI],AL

LOOP2: POP AX
INC SI
MOV [SI],AL
LOOP LOOP2
RET
HEX2DEC ENDP

END START

DATA SEGMENT
NUM1 DW 12345
NUM2 DW ?
ARRY DB 10 DUP (0)
TEMP DW ?
MSG1 DB 10,13,'STORED NUMBER IN MEMORY IS : $'
MSG2 DB 10,13,'REVERSE NUMBER IS : $'
RES DB 10 DUP ('$')
DATA ENDS
DISPLAY MACRO MSG
MOV AH,9
LEA DX,MSG
INT 21H
ENDM
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
DISPLAY MSG1
MOV AX,NUM1
LEA SI,RES
CALL HEX2DEC
LEA DX,RES
MOV AH,9
INT 21H
LEA SI,ARRY
MOV AX,NUM1
REVE:
MOV DX,0
MOV BX,10
DIV BX
MOV ARRY[SI],DL
MOV TEMP,AX
MOV AX,DX
INC SI
MOV AX,TEMP
CMP TEMP,0
JG REVE
LEA DI,ARRY
LAST:
INC DI
CMP ARRY[DI],0
JG LAST
DEC DI
MOV AL,ARRY[DI]
MOV AH,0
MOV NUM2,AX
MOV CX,10
CONV:
DEC DI
MOV AL,ARRY[DI]
MOV AH,0
MUL CX
ADD NUM2,AX
MOV AX,CX
MOV BX,10
MUL BX
MOV CX,AX
CMP ARRY[DI],0
JG CONV
DISPLAY MSG2
MOV AX,NUM2
LEA SI,RES
CALL HEX2DEC
LEA DX,RES
MOV AH,9
INT 21H
MOV AH,4CH
INT 21H
CODE ENDS
HEX2DEC PROC NEAR
MOV CX,0
MOV BX,10
LOOP1: MOV DX,0
DIV BX
ADD DL,30H
PUSH DX
INC CX
CMP AX,9
JG LOOP1
ADD AL,30H
MOV [SI],AL
LOOP2: POP AX
INC SI
MOV [SI],AL
LOOP LOOP2
RET
HEX2DEC ENDP
END START

Screen Shots :-

Asm_program_Reverse_Number

After Execution :-

Asm_program_Reverse_Number_Output

Note :- To see the variable and its value you have to click vars button in the emulator.