Professional Documents
Culture Documents
In addition to memory, 80x86 microprocessors are able to access I/O ports. Ports are
accessed either to bring data from the port into the CPU (inputting) or to send data from the
CPU to the port (outputting).
In format (1) above, port# is the address of the port, and can be from 00 to FFH. This 8-bit
address allows 256 input ports and 256 output ports. No segment register is involved in
computing the address, in contrast to the data accessed from memory.
In format (2) , port# is the address of the port, and can be from 0000 to FFFFH. This 16-bit
address allows 65,536 input ports and 65,536 output ports. No segment register (DS) is
involved.
Ex: Write a sequence of instructions that will output FFH to a byte-wide output port at the
address ABH of the I/O address space?
MOV AL,FFH
OUT ABH,AL
Ex: Write a sequence of instructions that will output FFH to an output port at the address
B000H of the I/O address space?
MOV DX,B000H ;Note that 16-bit address must be in DX
MOV AL,FFH
OUT DX,AL
Ex: Assume that the port address 22H is an input port for monitoring the temperature. Write
Assembly language instructions to monitor the port continuously for the temperature of 100
degrees. If it reaches 100, then BH should contain ‘Y’.
1
Case 2: 16-bit data ports
Inputting Data Outputting Data
Format IN dest,source OUT dest,source
(1) IN AX,port# OUT port#,AX
(2) MOV DX,port# MOV DX,port#
IN AX,DX OUT DX,AX
Ex: Assume that AX=98F6H and the output port address is 47H, then
OUT 47H,AX
¾ In the above case F6H, the content of AL, goes to port address 47H and 98H, the content of
AH goes into the port address 48H.
¾ In other words the low byte goes to the low port address, and the high byte goes to the high
byte address.
2
Detailed Block Diagram of 8255 (a), and the Pin layout (b)
• PA0-PA7 (Port A) : This 8-bit port can be programmed all as input or all as output or
all bits as bi-directional input/output.
• PB0-PB7 (Port B) : This 8-bit port can be programmed all as input or all as output or
all bits as bi-directional port.
• PC0-PC7 (Port C) : This 8-bit port can be all input or all output. It can also be split into
two parts:
CU (Upper 4 bits PC4-PC7) and
CL (Lower 4 bits PC0-PC3).
Each can be used for input or output.
• RD and WR : These two active low signals are inputs to the 8255. If the 8255 is using
isolated I/O design, IOR or IOW of the system bus are connected to these two pins. If
the port uses memory-mapped I/O, MEMR and MEMW activate them.
• RESET: This is an active high signal input to the 8255 used to clear the control register.
When RESET is activated, all ports are initialized as input ports.
• A0, A1, and CS: While CS selects the entire chip, it is A0 and A1 that select the
specific port. A0 and A1 are used to access ports A, B, C, or the control register
according to the table below.
3
A1 A0 Selects:
0 0 Port A
0 1 Port B Table 1:
1 0 Port C
1 1 Control Register
The Control Register; is used to configure the individual ports as to be in input or output
mode.
The Control Register in Mode 0
D7 D6 D5 D4 D3 D2 D1 D0
1=Mode 0 Mode selection Port A Port C Mode Port B Port C
I/O Mode 00 = Mode 0 1=input (PC7-PC4) Selection 1=input (PC3-PC0)
01 = Mode 1 0=output 1=input 0=Mode 0 0=output 1=input
1X = Mode 2 0=output 1=Mode 1 0=output
Ex: Configure 8255 as follows: port A as input, B as output, and all the bits in C as output.
Determine the content of the Control Register and,
Program the ports to input data from A and send it to both B and C.
(Assume the standard port addresses of 8255 given above)
1 0 0 1 0 0 0 0 = 90H
4
Ex: Configure the ports of 8255 as follows: port A=input, B=output/ PC0 –PC3=input, and PC4-
PC7=output.
Determine the content of the Control Register and,
Program the 8255 to get data from port A and send it to port B. In addition, input data from
PCL and send out to PCU.
1 0 0 1 0 0 0 1 = 91H