
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Add Two Multi-Byte BCD Numbers in 8085
Now let us see a program of Intel 8085 Microprocessor. This program is mainly for adding multi-digit BCD (Binary Coded Decimal) numbers.
Problem Statement
Write 8085 Assembly language program to add two multi-byte BCD (Binary Coded Decimal) numbers.
Discussion
We are using 4-byte BCD numbers. The numbers are stored into the memory at location 8501H and8505H. One additional information is stored at location 8500H. In this place, we are storing the byte count. The result is stored at location 85F0H.
The HL pair is storing the address of first operand bytes, the DE is storing the address of second operand bytes. C is holding the byte count. We are using the stack to store the intermediate bytes of the result. After completion of the addition operation, we are popping from the stack and storing into the destination.
Input
Address |
Data |
---|---|
. . . |
. . . |
8500 |
04 |
8501 |
19 |
8502 |
68 |
8503 |
12 |
8504 |
85 |
8505 |
88 |
8506 |
25 |
8507 |
17 |
8508 |
20 |
. . . |
. . . |
Flow Diagram
Program
Address |
HEX Codes |
Labels |
Mnemonics |
Comments |
|
---|---|---|---|---|---|
F000 |
31,00, 20 |
|
LXI SP, 2000H |
Initialize Stack Pointer |
|
F003 |
21,00, 85 |
|
LXI H,8500H |
load memory address to get byte count |
|
F006 |
4E |
|
MOV C,M |
load memory content into C register |
|
F007 |
06,00 |
|
MVI B,00H |
clear B register |
|
F009 |
21,01, 85 |
|
LXI H, 8501H |
load first argument address |
|
F00C |
11,05, 85 |
|
LXI D, 8505H |
load second argument address |
|
F00F |
1A |
LOOP |
LDAX D |
load DE with second operand address |
|
F010 |
8E |
|
ADC M |
Add memory content and carry with Acc |
|
F011 |
27 |
|
DAA |
Decimal adjust the acc content |
|
F012 |
F5 |
|
PUSH PSW |
Store the accumulator content into the stack |
|
F013 |
4 |
|
INR B |
increase b after pushing into a stack |
|
F014 |
23 |
|
INX H |
Increase HL pair to point next address |
|
F015 |
13 |
|
INX D |
Increase DE pair to point next address |
|
F016 |
0D |
|
DCR C |
Decrease c to while all bytes are not exhausted |
|
F017 |
C2,0F, F0 |
|
JNZ LOOP |
When bytes are not considered, loop again |
|
F01A |
D2,21, F0 |
|
JNC SKIP |
when carry = 0, jump to store |
|
F01D |
3E,01 |
|
MVIA, 01H |
when carry = 1, push it into stack |
|
F01F |
F5 |
|
PUSH PSW |
Store the accumulator content into the stack |
|
F020 |
04 |
|
INR B |
increase b after pushing into the stack |
|
F021 |
21,F0, 85 |
SKIP |
LXIH, 85F0H |
load the destination pointer |
|
F024 |
F1 |
L1 |
POP PSW |
pop AF to get back bytes from the stack |
|
F025 |
77 |
|
MOV M, A |
store Acc data at the memory location pointed by HL |
|
F026 |
23 |
|
INX H |
Increase HL pair to point next address |
|
F027 |
05 |
|
DCR B |
Decrease B |
|
F028 |
C2,24, F0 |
|
JNZ L1 |
Goto L1 to store stack contents |
|
F02B |
76 |
|
HLT |
Terminate the program |
Output
Address |
Data |
---|---|
. . . |
. . . |
85F0 |
01 |
85F1 |
05 |
85F2 |
29 |
85F3 |
94 |
85F4 |
07 |
. . . |
. . . |