- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 do an operation on two BCD numbers based on the contents of X
Now let us see a program of Intel 8085 Microprocessor. In this program we will see how to do different operations on BCD numbers based on choice.
Problem Statement:
Write 8085 Assembly language program to perform some operations on two 8-bit BCD numbers base on choice.
Discussion:
In this program we are taking a choice. The choice value is stored at memory location 8000H (named as X). And the BCD numbers are stored at location 8001H and 8002H. We are storing the result at location 8050H and 8051H.
Here if the choice is 00H, then it will perform addition, for 01H, it will perform subtraction, and for 02H, it will do the multiplication operation.
Input:
First input
Address | Data |
---|---|
. . . | . . . |
8000 | 00 |
8001 | 97 |
8002 | 88 |
. . . | . . . |
Second input
Address | Data |
---|---|
. . . | . . . |
8000 | 01 |
8001 | 97 |
8002 | 88 |
. . . | . . . |
Third input
Address | Data |
---|---|
. . . | . . . |
8000 | 02 |
8001 | 05 |
8002 | 04 |
. . . | . . . |
Flow Diagram:
Program:
Address | HEX Codes | Labels | Mnemonics | Comments |
---|---|---|---|---|
F000 | 21, 00, 80 | LXI H,8000H | Point to get the choice | |
F003 | 7E | MOV A,M | Load choice into A | |
F004 | FE, 00 | CPI 00H | Compare for ADD | |
F006 | CA,14, F0 | JZ ADD | Jump to do Addition | |
F009 | FE, 01 | CPI 01H | Compare for SUB | |
F00B | CA,27, F0 | JZ SUB | Jump to do Subtraction | |
F00E | FE, 02 | CPI 02H | Compare for MUL | |
F010 | CA, 3F, F0 | JZ MUL | Jump to do Multiplication | |
F013 | 76 | HLT | Terminate the program | |
F014 | 23 | ADD | INX H | Point to first operand |
F015 | 7E | MOV A,M | Load operand to A | |
F016 | 23 | INX H | Point to next operand | |
F017 | 86 | ADD M | Add M with A | |
F018 | 27 | DAA | Decimal adjust | |
F019 | 6F | MOV L,A | Store A to L | |
F01A | D2, 22, F0 | JNC SKP1 | If CY = 0, jump to SKP1 | |
F01D | 26, 01 | MVI H,01H | Load H with 01H | |
F01F | C3, 62, F0 | JMP STORE | Store result | |
F022 | 26, 00 | SKP1 | MVI H,00H | Clear HL |
F024 | C3, 62, F0 | JMP STORE | Store HL as result | |
F027 | 23 | SUB | INX H | Point to first operand |
F028 | 46 | MOV B,M | Load operand to B | |
F029 | 3E, 99 | MVI A,99H | Load A with 99H | |
F02B | 23 | INX H | Point to next operand | |
F02C | 96 | SUB M | Subtract M from A | |
F02D | C6, 01 | ADI 01H | Add 01H to get 10's complement | |
F02F | 80 | ADD B | Add B with A | |
F030 | 27 | DAA | Adjust decimal | |
F031 | 6F | MOV L,A | Store A to L | |
F032 | DA, 3A, F0 | JC SKP2 | If CY = 1, jump to SKP2 | |
F035 | 26, FF | MVI H,FFH | Load H with FFH | |
F037 | C3, 62, F0 | JMP STORE | Store result | |
F03A | 26, 00 | SKP2 | MVI H,00H | Clear HL |
F03C | C3, 62, F0 | JMP STORE | Store HL as result | |
F03F | 23 | MUL | INX H | Point to first operand |
F040 | 46 | MOV B,M | Load operand to B | |
F041 | 23 | INX H | Point to next operand | |
F042 | 4E | MOV C,M | Load the second operand | |
F043 | 26, 00 | MVI H,00H | Clear H register | |
F045 | AF | XRA A | Clear A register | |
F046 | B9 | CMP C | Compare C with A | |
F047 | CA, 5E, F0 | JZ DONE | Jump to Done if Z = 1 | |
F04A | 80 | LOOP | ADD B | Add B with A |
F04B | 27 | DAA | Adjust decimal | |
F04C | 57 | MOV D,A | Move A to D | |
F04D | D2, 55, F0 | JNC NINC | if CY = 0, not increment H | |
F050 | 7C | MOV A,H | Load H to A | |
F051 | C6, 01 | ADI 01H | Increase A | |
F053 | 27 | DAA | Adjust decimal | |
F054 | 67 | MOV H,A | Get back to H | |
F055 | 79 | NINC | MOV A,C | Load A to C |
F056 | C6, 99 | ADI 99H | Add A and 99H | |
F058 | 27 | DAA | Adjust Decimal | |
F059 | 4F | MOV C,A | Load A to C again | |
F05A | 7A | MOV A,D | Get back the data from D to A | |
F05B | C2, 4A, F0 | JNZ LOOP | Jump to Loop if Z = 0 | |
F05E | 6F | DONE | MOV L,A | Take A to L |
F05F | C3, 62, F0 | JMP STORE | Store HL as result | |
F062 | 22, 50, 80 | STORE | SHLD 8050H | Store result from HL |
F065 | 76 | HLT | Terminate the program |
Output:
First output
Address | Data |
---|---|
. . . | . . . |
8050 | 85 |
8051 | 01 |
. . . | . . . |
Second output
Address | Data |
---|---|
. . . | . . . |
8050 | 09 |
8051 | 00 |
. . . | . . . |
Third output
Address | Data |
---|---|
. . . | . . . |
8050 | 20 |
8051 | 00 |
. . . | . . . |
- Related Articles
- Program to do an operation on two BCD numbers based on the contents of X in 8085 Microprocessor
- 8085 Program to do an operation on two numbers based on the contents of X
- 8085 program to subtract two BCD numbers
- 8085 Program to Add two multi-byte BCD numbers
- 8085 Program to multiply two 2-digit BCD numbers
- 8085 program to add 2-BCD numbers
- Program to multiply two 2-digit BCD numbers in 8085 Microprocessor
- 8085 Program for subtraction of multi-Byte BCD numbers
- a 8085 Program to perform bubble sort based on choice
- 8085 Program to convert a two-digit BCD to binary
- BCD numbers in 8085 Microprocessor
- 8085 program with a subroutine to add ten packed BCD numbers.
- Program for subtraction of multi-byte BCD numbers in 8085 Microprocessor
- Program to perform bubble sort based on choice in 8085 Microprocessor
- 8085 Program to convert an 8-bit binary to BCD
