19
Practical Session No. Practical Session No. 12 12 Input &Output (I/O) 1

Practical Session No. 12

Embed Size (px)

DESCRIPTION

Practical Session No. 12. Input &Output (I/O). I/O Devices. Input/output (I/O) devices provide the means to interact with the “outside world”. An I/O device can be purely input, purely output, or both an input and output device (e.g. mouse, screen, disks). - PowerPoint PPT Presentation

Citation preview

Page 1: Practical Session No. 12

Practical Session No. 12Practical Session No. 12Input &Output (I/O)

1

Page 2: Practical Session No. 12

I/O DevicesI/O DevicesInput/output (I/O) devices provide

the means to interact with the “outside world”.

An I/O device can be purely input, purely output, or both an input and output device (e.g. mouse, screen, disks).

Are mostly used to communicate with the outside world, and to store data.

1.2

Page 3: Practical Session No. 12

ControllerControllerI/O devices are not

directly connected to the system bus. Instead, there is usually an I/O controller that acts as an interface between the system and the I/O device.

1.3

Page 4: Practical Session No. 12

Reasons for using an I/O Reasons for using an I/O controllercontrollerDifferent devices exhibit different

characteristics. The processor would spend a lot of time for interaction.

Controller could provide the necessary low-level commands and data for proper operation

1.4

Page 5: Practical Session No. 12

Reasons for using an I/O Reasons for using an I/O controllercontrollerThe amount of electrical power

used to send signals on the system bus is very low

Controllers typically contain driverhardware to send current over long cables

1.5

Page 6: Practical Session No. 12

I/O ControllerI/O ControllerTypically has 3 internal registers:

◦Data register◦Command register◦Status register

Processor interacts with an I/O device via the associated I/O controller

1.6

Page 7: Practical Session No. 12

I/O device interface to the I/O device interface to the systemsystem

1.7

Page 8: Practical Session No. 12

Communication (character Communication (character output)output)Before the processor sends output

character, it has to first check the status register of the associated controller (e.g. busy, idle, offline).

The data register holds the character (e.g. to be printed).

The command register determines the operation requested by the processor (e.g. send the character in the data register to the printer).

1.8

Page 9: Practical Session No. 12

Communication (character Communication (character output)output)Sequence of operations:

◦Wait for the controller to finish the last command;

◦Place a character to be printed in the data register;

◦Set the command register to initiate the transfer.

1.9

Page 10: Practical Session No. 12

I/O PortsI/O PortsAn I/O port is the address of a register

associated with an I/O controller.Two kinds of mapping:

◦memory-mapped I/O: writing to an I/O port is similar to writing to a memory address.

◦ I/O address space: separated from the memory address space.

Special I/O instructions are needed for I/O address space map. Pentium provides two instructions: in and out, to access I/O ports.

1.10

Page 11: Practical Session No. 12

I/O PortsI/O PortsPentium provides 64 KB of I/O address

space. This address space can be used for 8-bit,16-bit, and 32-bit I/O ports.

A combination cannot be more than the I/O address space.

For example, we can have 64-K 8-bit ports, 32-K 16-bit ports, 16-K 32-bit ports, or a combination of these that fits the 64-K address space.

1.11

Page 12: Practical Session No. 12

Register I/O InstructionsThe in instruction is used to read data

from an I/O port:◦ in accumulator, port8 (direct address)◦ in accumulator, DX (indirect address)

The out instruction to write data to an I/O port:◦out port8, accumulator (direct address)◦out DX, accumulator (indirect address)

accumulator must be AL, AX, or EAX.port8 - access the first 256 ports

0..FFH.1.1

2

Page 13: Practical Session No. 12

8255 Programmable 8255 Programmable Peripheral Interface (PPI) Peripheral Interface (PPI) Chip Chip Provides three 8-bit registers to

interface with I/O devices:

Register Port address◦PA (input port) 60H◦PB (output port) 61H ◦PC (input port) 62H◦Command register 63H

1.13

Page 14: Practical Session No. 12

8255 Programmable 8255 Programmable Peripheral Interface (PPI) Peripheral Interface (PPI) ChipChipKeyboard interface is provided by

port PA and PB7.Keyboard sends an interrupt (to other

interrupt controller) whenever a change occurs (e.g, key is pressed).

A scan code of the key whose state has changed is written in PA.

Keyboard waits for an acknowledge signalfrom CPU in PB7

1.14

Page 15: Practical Session No. 12

Register Bit Map of 8255Register Bit Map of 8255Keyboard scan code if PB7 = 0

◦PA7 = 0 if a key is depressed◦PA7 = 1 if a key is released◦PA0–PA6 = key scan code

Configuration switch 1 if PB7 = 1PB7 — selects source for PA input

◦0— keyboard scan code◦1— configuration switch 1◦Also, 1 is used as keyboard

acknowledge1.1

5

Page 16: Practical Session No. 12

Keyboard DriverKeyboard DriverUses busy wait loop.Pressing the esc key terminates

the program.Waits for the PA7 bit to go low to

indicate that a key is depressed.Scan code is read from PA6 to

PA0

1.16

Page 17: Practical Session No. 12

Keyboard DriverKeyboard Driver

1.17

section .dataESC_KEY EQU 1BH ; ASCII code for ESC keyKB_DATA EQU 60H ; 8255 port PA

section .text global _start_start: key_up_loop: ;Loops until a key is pressed i.e., until PA7 = 0. ; PA7 = 1 if a key is up. in AL, KB_DATA ; read keyboard status & scan code test AL, 80H ; PA7 = 0? jnz key_up_loop ; if not, loop back

Page 18: Practical Session No. 12

Keyboard DriverKeyboard Driver

1.18

and AL,7FH ; isolate the scan code

..Translate scan code to ASCII code in AL..

cmp AL,0 ; ASCII code of 0 => uninterested keyje key_down_loop

cmp AL,ESC_KEY ; ESC key---terminate programje done

display_ch: ; char is now in AL..Print character AL to screen..

Page 19: Practical Session No. 12

Keyboard DriverKeyboard Driver

1.19

key_down_loop:in AL,KB_DATAtest AL, 80H ; PA7 = 1?jz key_down_loop ; if not, loop back

mov AX,0C00H ; clear keyboard bufferint 21H ; (System interrupt)

jmp key_up_loopDone:

mov AX,0C00H ; clear keyboard bufferint 21H

..Exit Program..