- Related Questions & Answers
- Average numbers in array in C Programming
- C Program for Tower of Hanoi
- C++ Program for Dijkstra’s shortest path algorithm?
- C/C++ Program for nth Catalan Number?
- C Program to Multiply two Floating Point Numbers?
- C program to find the length of a string?
- C Program to Check if all digits of a number divide it
- C Program to Check if a Given String is a Palindrome?
- Write a program to Delete a Tree in C programming
- Write a C program to print “ Tutorials Point ” without using a semicolon
- Sum of the numbers up to N that are divisible by 2 or 5 in c programming
- Sum of the nodes of a Singly Linked List in C Program
- Sum of first n natural numbers in C Program
- C Program for simple interest?
- Area of a n-sided regular polygon with given Radius in C Program?

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Here we will see one 8085 program. This program will perform different operations on BCD numbers based on choice.

**Problem Statement **−

Write an 8085 Assembly language program to perform some operations on two 8-bit BCD numbers base on our 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.

**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 |

… | … |

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 |

** **

**First output**

Address | Data |
---|---|

… | … |

8050 | 85 |

8051 | 01 |

… | … |

**Second output**

Address | Data |
---|---|

… | … |

8050 | 09 |

8051 | 00 |

… | … |

**Third output**

Address | Data |
---|---|

… | … |

8050 | 20 |

8051 | 00 |

… | … |

Advertisements