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:
- Initialize H-L pair to point Look up
- Get the data.
- Check whether the given input is less than 9.
- If yes go to next step else halt the program.
- Add the desired address with the contents of accumulator.
- 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
Related posts:
- Terminology Used in Microprocessor and Microcontroller
- CISC and RISC Processor Architecture
- Von Neumann and Harvard Architecture
- Basics of Microprocessor and Microcontroller
- Introduction to Microprocessor 8085
- Architecture of 8085 Microprocessor
- Pin Diagram of 8085 Microprocessor and Pin Description
- Addressing Modes in 8085 Microprocessor
- Data Transfer Instructions in 8085 Microprocessor
- Arithmetic Instructions in 8085 Microprocessor
- Logical Instructions in 8085 Microprocessor
- Branching instructions in 8085 Microprocessor
- Machine Control Instructions in 8085 Microprocessor
- Timing Diagram of 8085 Instructions
- Stack and Subroutine in 8085 Microprocessor
- Interrupts in 8085 Microprocessor
- Assembler Directives of 8085 Microprocessor
- Simple Data Transfer Program in 8085 Microprocessor
- Microprocessor 8085 Addition and Subtraction Programs
- Programs on Logical Instructions in 8085 Microprocessor
- Multiplication Programs in 8085 Microprocessor
- Division Programs in 8085 Microprocessor
- Introduction to Assembly Language Programming
- 8085 Program to Find the Largest Number in an Array of Data
- 8085 Program to Count Negative Numbers | ALP to Count Negative Numbers
- 8085 Program to Find the Smallest Number in An Array of Data
- 8085 Program to Arrange an Array of Data in Ascending Order
- 8085 Program to Arrange an Array of Data in Descending Order