8085 program to access and exchange the content of Flag register with register B
Problem – Write an assembly language program in 8085 microprocessor to access Flag register and exchange the content of flag register F with register B.
Example –

Assumptions – Initial values of flag register, register B and stack pointer are is 00, 3F, and 3FFF respectively.
PSW stands for PROGRAM STATUS WORD. PSW combines accumulator A and flag register F.
Algorithm –
- Push the value of PSW in memory stack by help of PUSH instruction
- Pop the value of Flag register and store it in register H by help of POP instruction
- Move the value of register H in register C
- Move the value of register B in register H
- Move the value of register C in register B
- Push the value of register H in memory stack by help of PUSH instruction
- Pop the value of PSW from memory stack using POP instruction
Program –
| MEMORY ADDRESS | MNEMONICS | COMMENT |
|---|---|---|
| 2000 | PUSH PSW | Push value of accumulator and flag in stack |
| 2001 | POP H | Pop value from TOP of memory stack in H |
| 2002 | MOV C, H | C <- H |
| 2003 | MOV H, B | H <- B |
| 2004 | MOV B, C | B <- C |
| 2005 | PUSH H | Push the value of register H |
| 2006 | POP PSW | Pop value of flag register and Accumulator |
| 2007 | HLT | END |
Explanation – Registers used A, B, C, H, F
- PUSH PSW instruction performs the following task:
SP <- SP - 1 M[SP] <- A SP <- SP - 1 M[SP] <- F - POP H instruction performs the following task:
H <- M[SP] SP <- SP + 1 - MOV C, H – moves the value of H in register C
- MOV H, B – moves the value of B in register H, hence H is updated
- MOV B, C – moves the value of C in register B, hence B is updated
- PUSH H performs the following task:
SP <- SP - 1 M[SP] <- H - POP PSW performs the following task:
F <- M[SP] SP <- SP + 1 A <- M[SP] SP <- SP + 1 - HLT – stops executing the program and halts any further execution
Recommended Posts:
- 8085 program to exchange content of HL register pair with DE register pair
- 8085 program to find 2's complement of the contents of Flag Register
- Flag register in 8085 microprocessor
- Register content and Flag status after Instructions
- 8085 program to count the number of ones in contents of register B
- Flag register of 8086 microprocessor
- 8085 program to exchange a block of bytes in memory
- Register Allocations in Code Generation
- Introduction of General Register based CPU Organization
- Difference between Memory based and Register based Addressing Modes
- Subtract content of two ports by interfacing 8255 with 8085 microprocessor
- Difference between Random Access Memory (RAM) and Content Addressable Memory (CAM)
- 8085 program to add two 16 bit numbers
- 8085 program to add 2-BCD numbers
- 8085 program to add two 8 bit numbers
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



