Open In App

Subtract content of two ports by interfacing 8255 with 8085 microprocessor

Introduction :

The 8255 is a programmable peripheral interface chip that can be interfaced with the 8085 microprocessor to provide additional I/O capabilities. One of the operations that can be performed using the 8255 is to subtract the contents of two ports.

To perform this operation, the following steps can be followed:

  1. Configure the 8255 in mode 1 to enable bidirectional data transfer.
  2. Assign the two ports that will be used for the subtraction operation.
  3. Load the data from the two ports into the accumulator of the 8085 microprocessor.
  4. Subtract the contents of one port from the other using the SUB instruction of the 8085 microprocessor.
  5. Store the result in a third port.

Here is an example code that illustrates how to subtract the contents of Port A from Port B and store the result in Port C:




; Initialize the 8255 in mode 1
MOV A, 80H   ; Initialize control register A
OUT 80H, A
 
; Assign the ports
MOV A, 00H   ; Port A
OUT 81H, A
MOV A, 01H   ; Port B
OUT 82H, A
MOV A, 02H   ; Port C
OUT 83H, A
 
; Load data from Port A and Port B into accumulator
IN A, 81H
MOV B, A
IN A, 82H
 
; Subtract the contents of Port A from Port B
SUB B
 
; Store the result in Port C
OUT 83H, A

This code initializes the 8255 in mode 1 and assigns ports A, B, and C. It then loads the contents of Port A and Port B into the accumulator and subtracts the contents of Port A from Port B. The result is stored in Port C.

Note that the specific port addresses used in the code may vary depending on the system configuration.

How to Subtract content of two ports by interfacing 8255 with 8085 microprocessor :



To subtract the contents of two ports using the 8255 with the 8085 microprocessor, you can follow these steps:

  1. Initialize the 8255 in mode 1 to enable bidirectional data transfer.
  2. Assign the two ports that will be used for the subtraction operation.
  3. Load the data from the two ports into the accumulator of the 8085 microprocessor.
  4. Subtract the contents of one port from the other using the SUB instruction of the 8085 microprocessor.
  5. Store the result in a third port.

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

  1. Initialize the 8255 in mode 1: 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 1, you need to set the appropriate bits in Control Register A.
  2. Assign the ports: You need to assign two ports for the subtraction operation. In this example, we will use Port A and Port B for the input values, and Port C for the output result.
  3. Load the data into the accumulator: You need to load the data from the two input ports (Port A and Port B) into the accumulator of the 8085 microprocessor.
  4. Subtract the contents of one port from the other: Subtract the contents of Port A from Port B using the SUB instruction.
  5. Store the result in a third port:  Finally, store the result of the subtraction in Port C.

Here is the complete code:




; Initialize the 8255 in mode 1
MOV A, 80H   ; Initialize control register A
OUT 00H, A   ; Send the initialization value to the 8255
 
; Assign the ports
MOV A, 00H   ; Port A
OUT 01H, A   ; Assign Port A to the 8255
MOV A, 01H   ; Port B
OUT 02H, A   ; Assign Port B to the 8255
MOV A, 02H   ; Port C
OUT 03H, A   ; Assign Port C to the 8255
 
; Load data into accumulator
IN A, 01H   ; Load data from Port A into accumulator
MOV B, A    ; Move the data to register B for later use
IN A, 02H   ; Load data from Port B into accumulator
 
; Subtract the contents of Port A from Port B
SUB B
 
; Store the result in Port C
OUT 03H, A   ; Store the result in Port C

Problem – Write an assembly program which determine the subtraction of contents of port B from port A and store the result in port C by interfacing 8255 with 8085 microprocessor. Example – Algorithm –

  1. Construct the control word register
  2. Input the data from port A and port B
  3. Subtract the contents of port A and port B
  4. Display the result in port C
  5. Halt the program

Program –

MNEMONICS COMMENTS
MVI A, 92 A <- 92
OUT 83 Control Register <- A
IN 81 A <- Port B
MOV B, A B <- A
IN 80 A <- Port A
SUB B A <- A – B
OUT 82 Port C <- A
RET Return

Explanation –

  1. MVI A, 92: means that the value of control register is 92.
D7=1         I/O mode
D6=0 & D5=0  Port A is in mode 0
D4=1         Port A is taking input
D3=0 & D0=0  Port C is not taking part
D2=0         Port B is in mode 0
D1=1         Port B is taking input
  1. OUT 83: putting the value of A in 83H which is the port number of port control register.
  2. IN 81: take input from 81H which is the port number of port B.
  3. MOV B, A: copies the content of A register to B register.
  4. IN 80: taking input from 80H which is the port number of port A.
  5. SUB B: subtract the contents of A register and B register.
  6. OUT 82: display the result in 81H which is the port number of port C.
  7. RET: return

Article Tags :