8085 Program to Find the Square of a Number from 0 to 9 Using a Table of Square

Problem:

Write a microprocessor 8085 program to find the square of a number from 0 to 9 using a table of squares.  The number is at memory location 4150H and store the result at 4151H.

Assume that the square of numbers is stored in the lookup table starting form 4125H.

Algorithm:

  1. Initialize H-L pair to point Look up
  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 contents of accumulator.
  6. Store the result.

Program:

           LXI H, 4125H ; Initialize Look up table address

           LDA 4150H      ; Get the data

           CPI 0AH           ; Check input > 9

           JC Lookup       ; if yes error else jump to Lookup

           MVI A, EEH      ; Error Indication

           STA 4151H      ; Display error message

           HLT                  ; Terminate the program                   

 

Lookup: MOV C, A     ; Add the 0-9 value in C register

           MVI B, 00H      ; Initialize B=00H       

           DAD B              ; HL (memory address) + B-C (a number)

           MOV A, M       ; Copy the contents of memory to accumulator       

           STA 4151H      ; Store the result

               HLT                       ; Terminate the program

Lookup Table:

4125

00

4126

01

4127

04

4128

09

4129

16

4130

25

4131

36

4132

49

4133

64

4134

81

Sample Example:

Input:                   4150H:                08

Output:                4151H:                 64

 

Input:                   4150H:                 14

Output:                4151H:                 EE (Error Indication)

Recent posts

Leave a Comment

Your email address will not be published. Required fields are marked *