An assembly language program to reverse the given number and check if the number is palindrome – IGNOU MCA Assignment 2015 – 16

By | August 16, 2015

MASTER OF COMPUTER APPLICATIONS

Course Code : MCS-017
Course Title : C and Assembly Language Programming(Lab Course)
Assignment Number : MCA(I)/L-017/Assignment/15-16
Maximum Marks : 100
Weightage : 25%

 

Develop and execute an assembly language program to reverse the given number and check if the number is palindrome. 

 

DATA SEGMENT
NUM1 DW 12321
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 : $’
MSG3 DB 10,13,’NUMBER IS A PALINDROME $’
MSG4 DB 10,13,’NUMBER IS NOT A PALINDROME $’
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 AX,NUM1
CMP NUM2,AX
JE PALIN

DISPLAY MSG4
JMP FINISH
PALIN:
DISPLAY MSG3

FINISH: 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

Program Code :

  1. DATA SEGMENT
  2. NUM1 DW 12321
  3. NUM2 DW ?
  4. ARRY DB 10 DUP (0)
  5. TEMP DW ?
  6. MSG1 DB 10,13,'STORED NUMBER IN MEMORY IS : $'
  7. MSG2 DB 10,13,'REVERSE NUMBER IS : $'
  8. MSG3 DB 10,13,'NUMBER IS A PALINDROME $'
  9. MSG4 DB 10,13,'NUMBER IS NOT A PALINDROME $'
  10. RES DB 10 DUP ('$')
  11. DATA ENDS
  12. DISPLAY MACRO MSG
  13. MOV AH,9
  14. LEA DX,MSG
  15. INT 21H
  16. ENDM
  17. CODE SEGMENT
  18. ASSUME CS:CODE,DS:DATA
  19. START:
  20. MOV AX,DATA
  21. MOV DS,AX
  22. DISPLAY MSG1
  23. MOV AX,NUM1
  24. LEA SI,RES
  25. CALL HEX2DEC
  26. LEA DX,RES
  27. MOV AH,9
  28. INT 21H
  29. LEA SI,ARRY
  30. MOV AX,NUM1
  31. REVE:
  32. MOV DX,0
  33. MOV BX,10
  34. DIV BX
  35. MOV ARRY[SI],DL
  36. MOV TEMP,AX
  37. MOV AX,DX
  38. INC SI
  39. MOV AX,TEMP
  40. CMP TEMP,0
  41. JG REVE
  42. LEA DI,ARRY
  43. LAST:
  44. INC DI
  45. CMP ARRY[DI],0
  46. JG LAST
  47. DEC DI
  48. MOV AL,ARRY[DI]
  49. MOV AH,0
  50. MOV NUM2,AX
  51. MOV CX,10
  52. CONV:
  53. DEC DI
  54. MOV AL,ARRY[DI]
  55. MOV AH,0
  56. MUL CX
  57. ADD NUM2,AX
  58. MOV AX,CX
  59. MOV BX,10
  60. MUL BX
  61. MOV CX,AX
  62. CMP ARRY[DI],0
  63. JG CONV
  64. DISPLAY MSG2
  65. MOV AX,NUM2
  66. LEA SI,RES
  67. CALL HEX2DEC
  68. LEA DX,RES
  69. MOV AH,9
  70. INT 21H
  71. MOV AX,NUM1
  72. CMP NUM2,AX
  73. JE PALIN
  74. DISPLAY MSG4
  75. JMP FINISH
  76. PALIN:
  77. DISPLAY MSG3
  78. FINISH: MOV AH,4CH
  79. INT 21H
  80. CODE ENDS
  81. HEX2DEC PROC NEAR
  82. MOV CX,0
  83. MOV BX,10
  84. LOOP1: MOV DX,0
  85. DIV BX
  86. ADD DL,30H
  87. PUSH DX
  88. INC CX
  89. CMP AX,9
  90. JG LOOP1
  91. ADD AL,30H
  92. MOV [SI],AL
  93. LOOP2: POP AX
  94. INC SI
  95. MOV [SI],AL
  96. LOOP LOOP2
  97. RET
  98. HEX2DEC ENDP
  99. END START

Screen shots :-

Asm_program_Reverse_Number_Palindrome

After Execution :

Asm_program_Reverse_Number_Palindrome_Output