8085 Program to find Square of a number using look up table

Microprocessor8085

Now let us see a program of Intel 8085 Microprocessor. This program is mainly for finding a square of a number.

Problem Statement

Write 8085 Assembly language program to find the square of a number using Look-Up Table. 

Discussion

In this example, we are using Look-Up table to find the square of a number. The main limitation of this program is that it can find a square in range 0-F. When the input is above F, it will fail. We are storing the square result into the memory. When the number is greater than F, we are storing FFH into memory to indicate an ERROR.

We are taking the number from location 8000H, and the lookup table is stored at the 9000H location.

The Look Up Table looks like this.

NumberSquared Value
0000
0101
02
04
03
09
04
10
05
19
06
24
07
31
08
40
09
51
0A
64
0B
79
0C
90
0D
A9
0E
C4
0F
E1

Input

first input

Address
Data
.
.
.
.
.
.
8000
06
.
.
.
.
.
.

second input

Address
Data
.
.
.
.
.
.
8000
0C
.
.
.
.
.
.

third input

Address
Data
.
.
.
.
.
.
8000
25
.
.
.
.
.
.

Flow Diagram

Program

Address
HEXCodes
Labels
Mnemonics
Comments
F000
21,00, 90

LXIH, 9000H
Point to the lookup table address
F003
3A,00, 80

LDA 8000H
Get the data
F006
FE,0F

CPI 0FH
Checkinput > 15D
F008
DA,13, F0

JC AFTER
The check the number greater than 0A or not
F00B
3E, FF

MVIA, FFH
Load FFH into A
F00D
32,50, 80

STA 8050H
Store FFH for numbers > 15D
F010
C3,1B, F0

JMP DONE
End the program
F013
4F
AFTER
MOVC, A
Add the desired Address
F014
06,00

MVIB,00H
Clear register B
F016
09

DAD B
ADD BC with HL pair
F017
7E

MOVA, M
Take the result from Look-up table
F018
32,50, 80

STA 8050H
Store the result
F01B
76
DONE
HLT
Terminate the program

Output

first output

Address
Data
.
.
.
.
.
.
8050
24
.
.
.
.
.
.

second output

Address
Data
.
.
.
.
.
.
8050
90
.
.
.
.
.
.

third output

Address
Data
.
.
.
.
.
.
8050
FF
.
.
.
.
.
.
raja
Published on 07-Jan-2019 07:48:12
Advertisements