- Trending Categories
- 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 access and exchange the content of Flag register with register B
In this program we will see how to exchange the content of Flat register with register B.
Problem Statement
Write 8085 Assembly language program to swap the content of flag register and the register B.
Discussion
As we cannot access the flag register content directly, we have to take the help of stack. By using stack, we can push the content of PSW (Accumulator and Flag). Then we can get it back and store into some other registers. Similarly, from other register, we have to push them into stack, then pop it to PSW.
Here if we want to exchange the value of B and F, then at first we have to make a copy of B to C. When we will push the PSW into stack, then pop to BC, the Acc content will be loaded to B, and Flag register content will be loaded to C.
Input
Here we are not providing any additional inputs. We are directly storing a value to B, then swapping it to flag register. In the program the B is containing 45H, after executing the program, 45H will be loaded to Flag register.
Flow Diagram
Program
Address | HEX Codes | Mnemonics | Comments |
---|---|---|---|
F000 | 31, 00, 90 | LXI SP,9000 | Initialize stack pointer |
F003 | 06, 45 | MVI B,45H | Load B with 45H |
F005 | 48 | MOV C,B | Save B into C |
F006 | F5 | PUSH PSW | Store AF into stack |
F007 | C5 | PUSH B | Store BC into stack |
F008 | F1 | POP PSW | Pop and store to AF |
F009 | C1 | POP B | Pop and store to BC |
F00A | 41 | MOV B, C | Move C to B |
F00B | 76 | HLT | Terminate the program |
Output
Flag register will be loaded with 45H.