In this program, we are going to write an assembly language program to Find the 2’s complement of a Number in 8085 microprocessor with a program flow chart and explanation of the program.
2’s complement of a Number in 8085
Program Statement
Find the 2’s complement of a Number in 8085 stored at memory location C200H and store the complemented number at memory location C3ooH.
Explanation of Program
- 2’s complement means adding 1 to 1’s complement of that number.
- We will load the number in the accumulator. Then using CMA instruction we will complement the accumulator. This is 1’s complement of that number.
- Now we will add 1 to this complemented number to get 2’s complement of that number.
- Store the result at memory location C300H.
- Let A = 44 H
- i.e. A = 0100 0100 (44 H)
- 1’s complement of A: 1011 1011 ( BB H)
- Now add + 1 to A
- 2’s complement of A: 1011 1100 (BC H)
- The 2’s complement of the number BC H. We will store this result in memory location C300H.
Assembly Language Program
Instruction | Comments | Operation |
---|---|---|
LDA C200H | Load the number in the accumulator store at the memory location C200H. | A = 44 H |
CMA | Complement the number | A = BB H |
ADI 01H | Add 1 to the complemented number i.e. 2’s complement of the number. | A = BC H |
STA C300H | Store the result | C300 : BC H Result |
HLT | Terminate program execution | Stop |