1 / 21

Practical Session 12

Practical Session 12. Input &Output (I/O). I/O Device. Input / Output (I/O) devices provide the means to interact with the “outside world”. mouse, screen, disks, printer, etc. CPU-Memory-I/O Architecture. Memory. CPU. I/O module. I/O controller. I/O device. “CPU bus” or “System bus”.

clydez
Download Presentation

Practical Session 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 12 Input &Output (I/O)

  2. I/O Device • Input / Output (I/O) devices provide the means to interact with the “outside world”. • mouse, screen, disks, printer, etc.

  3. CPU-Memory-I/O Architecture Memory CPU I/O module I/O controller I/O device “CPU bus” or “System bus” “Bus interface” “I/O bus”

  4. Types of I/O • Programmed I/O • Interrupt-driven I/O • Direct memory access (DMA)

  5. Programmed I/O • I/O operations are under direct control of software (program) • Software initiates the I/O operation • Disadvantage: • Slow • Uses a lot of CPU resources • Advantage: • Simple

  6. Types of I/O • Programmed I/O • Interrupt-driven I/O • Direct memory access (DMA)

  7. Interrupt-driven I/O • I/O operations are initiated by the device • The device, or its I/O module, includes a signal to interrupt the CPU • When an interrupt occurs (and is accepted), a special routine executes to service the interrupt

  8. Types of I/O • Programmed I/O • Interrupt-driven I/O • Direct memory access (DMA)

  9. Direct memory access (DMA) • Used for high-speed block transfers between a device and memory • During the transfer, the CPU is not involved • The CPU “prepares” the DMA operation by transferring information to a DMA controller (DMAC): • Location of the data on the device • Location of the data in memory • Size of the block to transfer • Direction of the transfer • When the device is ready to transfer data, the DMAC takes control of the system buses

  10. I/O controller to DMA module controller controller

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

  12. Operating system

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

  14. I/O device interface to the system

  15. Communication example – character output • Check the status register of I/O controller • e.g. busy, idle, offline • Put data into data register • Put command into command register • e.g. “send the character in the data register to the printer”

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

  17. I/O Mapping • Memory mapped I/O • Devices and memory share an address space • I/O looks just like memory read/write • No special commands for I/O • Large selection of memory access commands available • Isolated I/O • Separate address spaces • Need I/O or memory select lines • Special commands for I/O • Limited set

  18. I/O Ports and Instructions • x86 provides 64 KB of isolated I/O address space • x86 provides two instructions to access I/O ports • in instruction is used to read data from an I/O port: in register, port address (direct address) in register, DX (indirect address) • out instruction is used to write data to an I/O port: out port address, register (direct address) out DX, register (indirect address) • register must be AL, AX, or EAX

  19. Example – Keyboard Driver • Use PA input port register at address 60H • PA7 = 0 if a key is depressed • PA7 = 1 if a key is released • PA0–PA6 = key scan code • Use busy wait loop • Waits until a key is pressed i.e., until PA7 = 0. • Scan code is read from PA6 to PA0 • Pressing the ESC key terminates the program

  20. Example – 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: ;loop until a key is pressed i.e., until PA7 = 0 in AL, KB_DATA ; read keyboard status & scan code test AL, 80H ; PA7 = 0? (80H=10000000b) jnz key_up_loop ; if not, loop back (busy wait)

  21. Example – Keyboard Driver and AL,7FH ; isolate the scan code ..Translate scan code to ASCII code in AL.. cmp AL,0 ; ASCII code of 0 => non-interesting key je key_down_loop cmp AL,ESC_KEY ; ESC key---terminate program je done ..Print character in AL to screen.. key_down_loop: in AL,KB_DATA test AL, 80H ; PA7 = 1? jz key_down_loop ; if not, loop back jmp key_up_loop done: ..Exit Program..

More Related