- 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 subtract two BCD numbers
Here we will see how to perform BCD subtractions using 8085.
Problem Statement
Write 8085 Assembly language program to perform BCD subtractions of tow numbers stored at location 8001 and 8002. The result will be stored at 8050 and 8051.
Discussion
To subtract two BCD numbers, we are going to use the 10s complement method. Taking the first number and storing into B, Load 99 into A then subtract the number to get the 9’s complement. After that add 1 with the result to get 10’s complement. We cannot increase using INR instruction. This does not effect on CY flag. So we have to use ADI 01. Then DAA instruction will be used to adjust the decimal. Then if the result is negative we are storing FF as upper byte, otherwise 00 as upper byte.
Input
Address | Data |
---|---|
. . . | . . . |
8000 | 01 |
8001 | 97 |
8002 | 88 |
. . . | . . . |
Flow Diagram
Program
Address | HEX Codes | Labels | Mnemonics | Comments |
---|---|---|---|---|
F000 | 21, 01, 80 | | LXI H,8001H | Point to get the choice |
F003 | 46 | | MOV B,M | Load operand to B |
F004 | 3E, 99 | | MVI A,99H | Load A with 99H |
F006 | 23 | | INX H | Point to next operand |
F007 | 96 | | SUB M | Subtract M from A |
F008 | C6, 01 | | ADI 01H | Add 01H to get 10's complement |
F00A | 80 | | ADD B | Add B with A |
F00B | 27 | | DAA | Adjust decimal |
F00C | 6F | | MOV L,A | Store A to L |
F00D | DA, 3A, F0 | | JC SKP2 | If CY = 1, jump to SKP2 |
F010 | 26, FF | | MVI H,FFH | Load H with FFH |
F012 | C3, 62, F0 | | JMP STORE | Store result |
F015 | 26, 00 | SKP2 | MVI H,00H | Clear HL |
F017 | 22, 50, 80 | STORE | SHLD 8050H | Store result from HL |
F01A | 76 | | HLT | Terminate the program |
Output
Address | Data |
---|---|
. . . | . . . |
8050 | 09 |
8051 | 00 |
. . . | . . . |
Advertisements