Open In App

Interface 8255 with 8085 microprocessor for 1’s and 2’s complement of a number

Last Updated : 27 Sep, 2025
Comments
Improve
Suggest changes
3 Likes
Like
Report

Introduction :

The 8255 is a programmable peripheral interface chip that can be interfaced with the 8085 microprocessor to perform various input/output operations. One of the operations that can be performed using the 8255 and the 8085 microprocessor is finding the 1's and 2's complement of a number.

The 1's complement of a binary number is obtained by changing all the 0s to 1s and all the 1s to 0s. For example, the 1's complement of 1010 is 0101.

The 2's complement of a binary number is obtained by taking the 1's complement of the number and adding 1 to the result. For example, the 2's complement of 1010 is 0110 (1's complement is 0101, add 1 to get 0110).

To interface the 8255 with the 8085 microprocessor to find the 1's and 2's complement of a number, you can follow these steps:

  1. Initialize the 8255 in mode 0 to enable simple input/output operations.
  2. Assign a port to input the binary number.
  3. Load the binary number into the accumulator of the 8085 microprocessor.
  4. Find the 1's complement of the binary number using the CPL instruction of the 8085 microprocessor.
  5. Store the result in a second port.
  6. Find the 2's complement of the binary number using the ADD instruction of the 8085 microprocessor.
  7. Store the result in a third port.

Here is a step-by-step guide to implementing these steps in code:

1. Initialise the 8255 in mode 0: The 8255 has three control registers: Control Register A (CRA), Control Register B (CRB), and Control Register C (CRC). To initialize the 8255 in mode 0, you need to set the appropriate bits in Control Register A.

MOV A, 00H ; Initialize control register A for mode 0
OUT 00H, A ; Send the initialization value to the 8255

 2. Assign a port to input the binary number: You need to assign a port for the input binary number. In this example, we will use Port A for the input value.

MOV A, 00H ; Port A
OUT 01H, A ; Assign Port A to the 8255

3. Load the binary number into the accumulator: You need to load the binary number from Port A into the accumulator of the 8085 microprocessor.

IN A, 01H ; Load data from Port A into accumulator

4. Find the 1's complement of the binary number: Use the CPL instruction of the 8085 microprocessor to find the 1's complement of the binary number.

CPL ; Find the 1's complement of the binary number

5. Store the result in a second port: Store the result of the 1's complement in Port B.

OUT 02H, A ; Store the 1's complement in Port B

6. Find the 2's complement of the binary number: Use the ADD instruction of the 8085 microprocessor to find the 2's complement of the binary number.

ADD A, #01H ; Find the 2's complement of the binary number

7. Store the result in a third port: Store the result of the 2's complement in Port C.

OUT 03H, A ; Store the 2's complement in Port C

Problem - Interface 8255 with 8085 microprocessor and write an assembly language program to display 99 in Port A, 1’s complement of 99 in Port B, and 2’s complement of 99 in Port C. If Port addresses are 30H, 32H, and 33H resp. Example -

D7D6D5D4D3D2D1D0
10000000

Algorithm -

  1. Construct the control word register.
  2. Input value of accumulator A.
  3. Display value of A in Port A.
  4. Now 1’s complement of A is calculated and result is displayed in Port B.
  5. Now 2’s complement of A is calculated by adding 1 to 1’s complement of A. The result is displayed in Port C.

Program -

MnemonicsComments
MVI A, 80A<--80
OUT 33Control Register<--A
MVI A, 99A<--99
OUT 30Port A<--A
CMA1's complement of A
OUT 31Port B<--A
INR AA<--A+1
OUT 32Port C<--A
RETReturn

Explanation -

  1. .MVI A, 80: Value of control register is 80.
  2. OUT 33: Putting the value of A in 33H which is port number of port control register.
  3. .MVI A, 99: Value of A is equals to 99.
  4. OUT 30: Displaying the value of A in 30H which is port number of Port A.
  5. CMA: Calculates 1’s complement of A.
  6. OUT 31: Displaying 1’s complement of A in 31H which is port number of Port B.
  7. INR A: 1’s complement of A is incremented by 1 i.e. 2’s complement of A is calculated.
  8. OUT 32: Displaying 2’s complement of A in 32 H which is port number of Port C.
  9. RET: Return.
Suggested Quiz
5 Questions

Which instruction in 8085 is used to compute 1’s complement ?

  • A

    ADD A, #01H

  • B

    INR A

  • C

    CMA

  • D

    CPL

Explanation:

CMA = Complement Accumulator → performs 1’s complement.

To compute 2’s complement, after CMA, what instruction is used ?

  • A

    DCR A

  • B

    INR A

  • C

    SUB A

  • D

    MOV A, B

Explanation:

INR A adds 1 to 1’s complement → gives 2’s complement.

What is the 2’s complement of 99H in hexadecimal ?

  • A

    66H

  • B

    67H

  • C

    99H

  • D

    00H

Explanation:

1’s complement = 66H → +1 → 67H

Which signal is NOT directly connected in 8255 interfacing ?

  • A

    RD’

  • B

    WR’

  • C

    CS’

  • D

    CLK

Explanation:

8255 is asynchronous — no clock required.

The RESET pin of 8255 does what when asserted ?

  • A

    Clears all ports

  • B

    Sets all ports as input in Mode 0

  • C

    Enables BSR mode

  • D

    Disables chip

Explanation:

Standard reset behavior.

Quiz Completed Successfully
Your Score :   2/5
Accuracy :  0%
Login to View Explanation
1/5 1/5 < Previous Next >

Explore