Skip to content
Related Articles

Related Articles

8085 program to find 2’s complement of the contents of Flag Register
  • Last Updated : 03 Oct, 2018
GeeksforGeeks - Summer Carnival Banner

Problem – Write an assembly language program in 8085 microprocessor to find 2’s complement of the contents of Flag Register.

Example –

Algorithm –

  1. Initialize the value of Stack Pointer (SP) to 3999
  2. Push the contents of PSW (Register pair formed by Accumulator and Flag Register) into the memory stack
  3. Pop the contents from the stack into register pair BC
  4. Move the contents of register C to A
  5. Take 1’s complement of the contents of A
  6. Increment the contents of A by 1
  7. Move the contents of A to C
  8. Push the contents of register pair BC into the stack
  9. Pop the contents of stack into PSW
  10. Stop

Program –

MEMORY ADDRESSMNEMONICSCOMMENT
2000LXI SP 3999SP <- 3999
2003PUSH PSWPUSH value of Accumulator and Flag into the stack
2004POP BPOP value from Top of stack into register pair BC2005MOV A, CA <- C2006CMAA = 1’S complement of A2007INR AA = A + 12008MOV C, AC <- A2009PUSH BPUSH value of register pair BC into stack200APOP PSWPOP value from Top of stack into Accumulator and Flag200BHLTStop

Explanation –

  1. LXI SP 3999 is used to initialize the value of Stack Pointer(SP) to 3999.
  2. PUSH PSW is used to push the contents of PSW into the memory stack.
  3. POP B is used to pop the contents from the top of stack into register pair BC.
  4. MOV A, C moves the contents of register C to A.
  5. CMA takes 1’s complement of the contents of A.
  6. INR A increments the contents of A by 1.
  7. MOV C, A moves the contents of A to C.
  8. PUSH B is used to push the contents of register pair BC into the stack.
  9. POP PSW is used to pop the contents of stack into PSW.
  10. HLT is used to end the program.

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :