- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
8085 program to find the sum of series of even numbers
In this program we will see how to find the sum of all even numbers.
Problem Statement
Write 8085 Assembly language program to find sum of all even numbers stored in an array. The size of the array is stored at location F100; the numbers are stored from memory location F101 onwards. The result will be stored at F150.
Discussion
To check whether a number is odd or even, we can to AND operation. If a number is odd, then it will contain 1 as LSb, for even LSb will be 0. So after AND operation if the result is 0, then it is even. By using loop, we are adding the numbers only when it is even.
Input
Address | Data |
---|---|
. . . | . . . |
F100 | 08 |
F101 | 0C |
F102 | 0F |
F103 | 0A |
F104 | 0B |
F105 | 02 |
F106 | 03 |
F107 | 05 |
F108 | 08 |
. . . | . . . |
Flow Diagram
Program
Address | HEX Codes | Labels | Mnemonics | Comments |
---|---|---|---|---|
F000 | 3A, 00, F1 | | LDA F100 | Load number of elements into A |
F003 | 4F | | MOV C,A | Load counter |
F004 | 06, 00 | | MVI B,00 | Clear B to store Sum |
F006 | 21, 01, F1 | | LXI H,F101 | Initialize pointer to take numbers |
F009 | 7E | LOOP | MOV A,M | Take number from memory |
F00A | E6, 01 | | ANI 01 | Mask bits to check even or not |
F00C | C2, 12, F0 | | JNZ SKIP | If it is not zero, skip it |
F00F | 78 | | MOV A,B | Load B to A |
F010 | 86 | | ADD M | Add A and memory element |
F011 | 47 | | MOV B,A | Store A to B |
F012 | 23 | SKIP | INX H | Point to next location |
F013 | 0D | | DCR C | Decrease Counter |
F014 | C2, 09, F0 | | JNZ LOOP | Until Z = 1, jump to LOOP |
F017 | 32, 50, F1 | | STA F150 | Store result |
F020 | 76 | | HLT | Terminate program |
Output
Address | Data |
---|---|
. . . | . . . |
F150 | 20 |
. . . | . . . |
Advertisements