A program in assembly language to find the perimeter of a rectangle – 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%

 

Write a program in assembly language to find the perimeter of a rectangle. 

 

DATA SEGMENT
LEN DB ?
BRE DB ?
RES DB 10 DUP (‘$’)
MSG1 DB 10,13,”ENTER LENGTH OF RECTANGLE : $”
MSG2 DB 10,13,”ENTER BREADTH OF RECTANGLE : $”
MSG3 DB 10,13,”SQUARE OF NUMBER IS : $”

DATA ENDS

CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX

LEA DX,MSG1
MOV AH,9
INT 21H

MOV AH,1
INT 21H

SUB AL,30H
MOV AH,0
MOV BL,2
MUL BL
MOV LEN,AL

LEA DX,MSG2
MOV AH,9
INT 21H

MOV AH,1
INT 21H

SUB AL,30H
MOV AH,0
MOV BL,2
MUL BL
MOV BRE,AL

ADD AL,LEN

LEA SI,RES
CALL HEX2DEC

LEA DX,MSG3
MOV AH,9
INT 21H

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

Program Code :

  1. DATA SEGMENT
  2. LEN DB ?
  3. BRE DB ?
  4. RES DB 10 DUP ('$')
  5. MSG1 DB 10,13,"ENTER LENGTH OF RECTANGLE : $"
  6. MSG2 DB 10,13,"ENTER BREADTH OF RECTANGLE : $"
  7. MSG3 DB 10,13,"SQUARE OF NUMBER IS : $"
  8. DATA ENDS
  9. CODE SEGMENT
  10. ASSUME DS:DATA,CS:CODE
  11. START:
  12. MOV AX,DATA
  13. MOV DS,AX
  14. LEA DX,MSG1
  15. MOV AH,9
  16. INT 21H
  17. MOV AH,1
  18. INT 21H
  19. SUB AL,30H
  20. MOV AH,0
  21. MOV BL,2
  22. MUL BL
  23. MOV LEN,AL
  24. LEA DX,MSG2
  25. MOV AH,9
  26. INT 21H
  27. MOV AH,1
  28. INT 21H
  29. SUB AL,30H
  30. MOV AH,0
  31. MOV BL,2
  32. MUL BL
  33. MOV BRE,AL
  34. ADD AL,LEN
  35. LEA SI,RES
  36. CALL HEX2DEC
  37. LEA DX,MSG3
  38. MOV AH,9
  39. INT 21H
  40. LEA DX,RES
  41. MOV AH,9
  42. INT 21H
  43. MOV AH,4CH
  44. INT 21H
  45. CODE ENDS
  46. HEX2DEC PROC NEAR
  47. MOV CX,0
  48. MOV BX,10
  49. LOOP1: MOV DX,0
  50. DIV BX
  51. ADD DL,30H
  52. PUSH DX
  53. INC CX
  54. CMP AX,9
  55. JG LOOP1
  56. ADD AL,30H
  57. MOV [SI],AL
  58. LOOP2: POP AX
  59. INC SI
  60. MOV [SI],AL
  61. LOOP LOOP2
  62. RET
  63. HEX2DEC ENDP
  64. END START

Screen shots :-

Asm_program_Parameter_Rectangle

After Execution :

Asm_program_Parameter_Rectangle_Output