SQUARE OF A NUMBER USING LOOK UP TABLE

To find the square of the number from 0 to 9 using a Table of Square.

ALGORITHM:
1. Initialize HL pair to point Look up table
2. Get the data .
3. Check whether the given input is less than 9.

4. If yes go to next step else halt the program
5. Add the desired address with the accumulator content
6. Store the result

PROGRAM:
LXI H,4125 Initialsie Look up table address
LDA 4150 Get the data
CPI 0A Check input > 9
JC AFTER if yes error
MVI A,FF Error Indication
STA 4151
HLT
AFTER: MOV C,A Add the desired Address
MVI B,00
DAD B
MOV A,M
STA 4151 Store the result
HLT Terminate the program

LOOKUP TABLE:
4125 01
4126 04
4127 09
4128 16
4129 25
4130 36
4131 49
4132 64
4133 81

OBSERVATION:
Input: 4150: 05
Output: 4151 25 (Square)
Input : 4150: 11
Output: 4151: FF (Error Indication)
SQUARE OF A NUMBER USING LOOK UP TABLE SQUARE OF A NUMBER USING LOOK UP TABLE Reviewed by enakta13 on August 20, 2012 Rating: 5

Search your question

Powered by Blogger.