In this program, we will write an 8085 Program to Calculate the sum of a series of even numbers in the 8085 microprocessor with a program flow chart and explanation of the program.
8085 Program to Calculate the sum of a series of even numbers
Program Statement
Write a program in the ALP of 8085 to calculate the sum of a series of even numbers. Assume that the length of the series is stored at memory location D000H and the series itself begins at memory location D001H. Store the result in memory location E000H.
Explanation of Program
- Initialize the sum to zero. Load the count of numbers in register C. Initialize the pointer to start the series.
- To check whether the number is even we will AND the number with 01 H. If the result of ANDing is zero it indicates that the number is even. We will add this even number to the initialized sum.
- Decrement count. Increment source pointer to next location. Continue the process till the sum of all even numbers is found. Store the sum at memory location E000 Н.
Flow Chart of Program
Assembly Language Program
Label | Instruction | Comment |
---|---|---|
LDA D000H | ||
MOV C, A | Initialize counter | |
MVI B, 00H | Sum = 0 | |
LXI H, D001H | Initialize pointer | |
BACK: | MOV A, M | Get the number |
ANI 01 H | Mask bit-1 to bit-7 | |
JNZ SKIP | Don’t add if the number is ODD | |
MOV A, B | Get the sum | |
ADD M | Sum = sum + data | |
MOV B, A | Store the result in B register | |
SKIP: | INX H | Increment pointer |
DCR C | Decrement counter | |
JNZ BACK | If counter ≠ 0 , repeat | |
STA E000H | Store the sum (result) | |
HLT | Terminate program execution |