Assembly language program to find the Square of a number – IGNOU MCA Assignment 2015 – 16

By | August 16, 2015

Q. Write a program in assembly language to find the Square of a given number. 

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%

Solution : 

DATA SEGMENT
NUM DB ?
RES DB 10 DUP (‘$’)
MSG1 DB “ENTER NUMBER : $”
MSG2 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 NUM,AL
MOV AH,0

MUL NUM

LEA SI,RES
CALL HEX2DEC

LEA DX,MSG2
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. NUM DB ?
  3. RES DB 10 DUP ('$')
  4. MSG1 DB "ENTER NUMBER : $"
  5. MSG2 DB 10,13,"SQUARE OF NUMBER IS : $"
  6. DATA ENDS
  7. CODE SEGMENT
  8. ASSUME DS:DATA,CS:CODE
  9. START:
  10. MOV AX,DATA
  11. MOV DS,AX
  12. LEA DX,MSG1
  13. MOV AH,9
  14. INT 21H
  15. MOV AH,1
  16. INT 21H
  17. SUB AL,30H
  18. MOV NUM,AL
  19. MOV AH,0
  20. MUL NUM
  21. LEA SI,RES
  22. CALL HEX2DEC
  23. LEA DX,MSG2
  24. MOV AH,9
  25. INT 21H
  26. LEA DX,RES
  27. MOV AH,9
  28. INT 21H
  29. MOV AH,4CH
  30. INT 21H
  31. CODE ENDS
  32. HEX2DEC PROC NEAR
  33. MOV CX,0
  34. MOV BX,10
  35. LOOP1: MOV DX,0
  36. DIV BX
  37. ADD DL,30H
  38. PUSH DX
  39. INC CX
  40. CMP AX,9
  41. JG LOOP1
  42. ADD AL,30H
  43. MOV [SI],AL
  44. LOOP2: POP AX
  45. INC SI
  46. MOV [SI],AL
  47. LOOP LOOP2
  48. RET
  49. HEX2DEC ENDP
  50. END START

Screen shots :-

Asm_program_Find_Square

After Execution :

Asm_program_Find_Square_Output