In this program, we will write an 8085 Program to Find the Number of Negative Numbers in Array in the 8085 microprocessor with a program flow chart and explanation of the program.
8085 Program to Find the Number of Negative Numbers in Array
Program Statement
Given an array of N numbers. Write a program in the Assembly language program of 8084 to find the number of negative numbers in the array. Assume the array begins at memory location D001H and memory location D000H consists size of the array. Store the result at memory location E000H.
Explanation of Program
- We have an array of N numbers. For e.g., we initialize the count with 5.
- Also, we initialize a pointer to point the elements in the array.
- We will check for the MSB. If the MSB of the number is 1, the number is negative.
- Increment count for counting the negative numbers.
- Increment the pointer to point to the next element. Check if MSB is 1. Repeat the process till all the numbers are scanned.
- Store the count of negative numbers.
Flow Chart of Program
Assembly Language Program
Label | Instruction | Comment | Operation |
---|---|---|---|
LDA D000H | Load count in the accumulator | A = 05 H | |
MOV C, A | Initialize count | C = 05 H | |
MVI B, 00 | Initialize the negative number count = 0 | B = 00 H | |
LXI H, D001H | Initialize pointer to array | H = D0H, L = 01H | |
BACK: | MOV A, M | Get the number | A ← (HL) |
ANI 80H | check for MSB | ANDing with 80H | |
JZ SKIP | Check if MSB = 1 | if MSB = 1, the number is negative | |
INR B | Increment negative number count | B = B + 1 | |
SKIP: | INX H | Increment memory pointer | HL = HL + 1 |
DCR C | decrement count | C = C – 1 | |
JNZ BACK | if the count is 0 repeat | ||
MOV A, B | Load negative count in A | A = B | |
STA E000H | Store the result | E000H = No. of negative numbers | |
HLT | Terminate program execution | Stop |