1 / 19

Practical Session No. 12

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).

eve-vinson
Télécharger la présentation

Practical Session No. 12

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. 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). • Are mostly used to communicate with the outside world, and to store data.

  3. Controller • I/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.

  4. Reasons for using an I/O controller • Different 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

  5. Reasons for using an I/O controller • The amount of electrical power used to send signals on the system bus is very low Controllers typically contain driver hardware to send current over long cables

  6. I/O Controller • Typically has 3 internal registers: • Data register • Command register • Status register • Processor interacts with an I/O device via the associated I/O controller

  7. I/O device interface to the system

  8. Communication (character 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).

  9. Communication (character 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.

  10. I/O Ports • An 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.

  11. I/O Ports • Pentium 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.

  12. Register I/O Instructions • The 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.

  13. 8255 Programmable Peripheral Interface (PPI) 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

  14. 8255 Programmable Peripheral Interface (PPI) Chip • Keyboard 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

  15. Register Bit Map of 8255 • Keyboard 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 = 1 • PB7 — selects source for PA input • 0— keyboard scan code • 1— configuration switch 1 • Also, 1 is used as keyboard acknowledge

  16. Keyboard Driver • Uses 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

  17. Keyboard Driver section .data ESC_KEY EQU 1BH ; ASCII code for ESC key KB_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

  18. Keyboard Driver and AL,7FH ; isolate the scan code ..Translate scan code to ASCII code in AL.. cmp AL,0 ; ASCII code of 0 => uninterested key je key_down_loop cmp AL,ESC_KEY ; ESC key---terminate program je done display_ch: ; char is now in AL ..Print character AL to screen..

  19. Keyboard Driver key_down_loop: in AL,KB_DATA test AL, 80H ; PA7 = 1? jz key_down_loop ; if not, loop back mov AX,0C00H ; clear keyboard buffer int 21H ; (System interrupt) jmp key_up_loop Done: mov AX,0C00H ; clear keyboard buffer int 21H ..Exit Program..

More Related