# 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
PUSH DX
INC CX
CMP AX,9
JG LOOP1

MOV [SI],AL

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

END START

Program Code :

 Source code
`DATA SEGMENTNUM DB ?RES DB 10 DUP ('\$')MSG1 DB "ENTER NUMBER : \$"MSG2 DB 10,13,"SQUARE OF NUMBER IS : \$"DATA ENDSCODE SEGMENTASSUME DS:DATA,CS:CODESTART:MOV AX,DATAMOV DS,AXLEA DX,MSG1MOV AH,9INT 21HMOV AH,1INT 21HSUB AL,30HMOV NUM,ALMOV AH,0MUL NUMLEA SI,RESCALL HEX2DECLEA DX,MSG2MOV AH,9INT 21HLEA DX,RESMOV AH,9INT 21HMOV AH,4CHINT 21HCODE ENDSHEX2DEC PROC NEARMOV CX,0MOV BX,10LOOP1: MOV DX,0DIV BXADD DL,30HPUSH DXINC CXCMP AX,9JG LOOP1ADD AL,30HMOV [SI],ALLOOP2: POP AXINC SIMOV [SI],ALLOOP LOOP2RETHEX2DEC ENDPEND START`

Screen shots :-

After Execution :