# Experiment-5

Mar 23, 2021

## AIM: Write a program to find 2‘s complement of an 8 bit number.

### Objective:

• To understand the complement process
• To write algorithm for 1’s complement
• To develop the assembly language program to find 2’s complement
• To analyse the result and interpret errors if any

### Requirement:

• Operating System- Windos, Linux
• 8085 simulator

### Theory

2’s complement of a number is found in following ways:

• Do the 1’s complement of the given number
• Add ‘1’ to this 1’s complement

#### Example:

Find the 2’s complement of 59h

Number 59h                       =  01011001

1’s complement               = 10100110

Adding ‘1’ = 10100110 + 1 = 10100111

So, 2’s complement of 59h = A7h

### Algorithm:

• Get a number in the accumulator
• Complement using CMA
• Add ‘1’ to this to get 2’s complement
• Save the result

### Assembly language Program

 Address OP-CODE Operands Label Mnemonic Comments 4200 C3 05 042 JMP start 4203 F0 X: db  0F0h 4204 00 Y: Db 00h 4205 00 Start: NOP 4206 21 03 042 LXI H, X 4209 11 04 042 LXI D, Y 420C 7E MOV A,M 420D 2F CMA 420E C6 01 AdI 01 4210 12 STAX D 4211 76 HLT Result