8085 program to access and exchange the content of Flag register with register B - GeeksforGeeks

17 Jan, 2022
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 with the help of PUSH instruction  Pop the value of the Flag register and store it in register H with help of POP instruction  Move the value of register L in register C  [ H -> ACCUMULATOR VALUE, L-> FLAG REGISTER VALUE] Move the value of register B in register L  Move the value of register C in register B  Push the value of register H in-memory stack with the help of PUSH instruction  Pop the value of PSW from the memory stack using POP instruction  
Push the value of PSW in-memory stack with the help of PUSH instruction  
Pop the value of the Flag register and store it in register H with help of POP instruction  
Move the value of register L in register C  [ H -> ACCUMULATOR VALUE, L-> FLAG REGISTER VALUE] 
Move the value of register B in register L  
Move the value of register C in register B  
Push the value of register H in-memory stack with the help of PUSH instruction  
Pop the value of PSW from the memory stack using POP instruction  
Program – 
MVI B , 3FH
PUSH PSW
POP H
MOV C , L
MOV L , B
MOV B , C
PUSH H
POP PSW
HLT
Explanation – Registers used A, B, C, H, F 
PUSH PSW instruction performs the following task:  
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:  
POP H instruction performs the following task:  
    H <- M[SP]
    SP <- SP + 1
MOV C, L – moves the value of L in register C as we know that H contains the accumulator value and L contains flag register value  MOV L, B – moves the value of B in register L, hence L is updated  MOV B, C – moves the value of C in register B, hence B is updated  PUSH H performs the following task:  
MOV C, L – moves the value of L in register C as we know that H contains the accumulator value and L contains flag register value  
MOV L, B – moves the value of B in register L, hence L 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:  
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  
HLT – stops executing the program and halts any further execution  
 
raihanlaskar941
microprocessor
system-programming
Computer Organization & Architecture
microprocessor
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Architecture of 8085 microprocessor
Pin diagram of 8086 microprocessor
Computer Organization and Architecture | Pipelining | Set 2 (Dependencies and Data Hazard)
Direct Access Media (DMA) Controller in Computer Architecture
Memory mapped I/O and Isolated I/O
General purpose registers in 8086 microprocessor
Registers of 8085 microprocessor
8085 program to multiply two 8 bit numbers
Introduction of Control Unit and its Design
8085 program to add two 16 bit numbers