Input and output
Download
1 / 19

Input and Output - PowerPoint PPT Presentation


  • 102 Views
  • Uploaded on

Input and Output. Computer Organization and Assembly Language: Module 9. Motivation. Input and output devices (I/O devices) allow computers to perceive and effect their environment

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Input and Output' - ehren


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Input and output

Input and Output

Computer Organization and Assembly Language: Module 9


Motivation
Motivation

  • Input and output devices (I/O devices) allow computers to perceive and effect their environment

  • Input devices are often much slower than the computer: the computer can process data faster than the device can provide data

  • Some output devices have are also slow relative to the speed of memory access or CPU computation; they cannot accept data at the rate provided


General categories of i o
General Categories of I/O

  • User interface devices

    • Input devices: mouse, keyboard

    • Output devices: terminal display, printer

  • Mass storage devices

    • Disks, tape drives

  • Gateways and networks


Hardware i o instructions
Hardware: I/O instructions

  • The hardware implements special instructions to read from/write to I/O devices.

    • Perhaps lwio (load word I/O) and swio

  • The devices have a separate address space from memory

    • lwio $s0, 16 and lw $s0, 16 access different data

      • lwio $s0, 16 reads the next word from device 16

      • lw $s0, 16 reads the word stored in memory location 16.

  • MIPS does NOT use special I/O instructions


Hardware memory mapped i o
Hardware: Memory-Mapped I/O

  • The hardware can be designed in such a way that some memory addresses are not really memory at all but a collection of communication channels to I/O devices.

  • In memory-mapped I/O, load and store from/to the communication channels provide a means of performing I/O, i.e., load and store instructions with an I/O address are treated as I/O operations.

    lw $a0, KeyboardData

    sw $t0, DisplayData

communication

channels


Hardware memory mapped i o1
Hardware: Memory-Mapped I/O

  • MIPS RISC architecture uses memory-mapped I/O.

  • I/O devices, unlike memory, may be unavailable. If a device is not ready to accept or transmit data then it is busy.

    • The system must provide a mechanism for allowing a program to detect if a device is ready or busy

  • The processor communicates with an I/O device using two addresses: one for data exchange and the other to obtain the status of the I/O device.


Memory mapped addresses in spim
Memory mapped addresses in SPIM

keyboard_control = 0xffff0000 display_control = 0xffff0008

keyboard_data = 0xffff0004 display_data = 0xffff000c

Data

7 6 5 4 3 2 1 0

Control

1 0

Interrupt enable (1 = enabled)

Device busy/ready (1 = ready)


Memory mapped addresses in spim1
Memory mapped addresses in SPIM

  • Define the memory mapped constants like this:

    .data 0xffff0000

    keyboard_control: .space 4

    keyboard_data: .space 4

    display_control: .space 4

    display_data: .space 4


Software managing i o
Software: Managing I/O

  • Programmed I/O (Polling)

  • Interrupt driven I/O


Software programmed i o
Software: Programmed I/O

In programmed I/O, the CPU stays in a loop until

the I/O unit indicates that is ready for data transfer or

if the CPU has issued a command to the I/O module

it must wait until the operation is complete.

wait: lw $s0,keyboard_control

and $s0, $s0, 1

beq $s0, 0, wait

lw $v0,keyboard_data

wait: lw $s0,display_control

and $s0, $s0, 1

beq $s0, 0, wait

sw $v0,display_data

1 = ready

0 = busy

least significant bit


Software interrupt driven i o
Software: Interrupt Driven I/O

  • Instead of spin-waiting or doing a regular check whether an I/O device is ready, the I/O device can just inform the CPU that it is ready to receive or transmit data. The I/O device sends an interrupt signal to the system.

  • In this mechanism, control is transferred to the exception handler (part of the operating system) which saves the current state of the interrupted program. The requests are then serviced and control is given back to the interrupted program. This mechanism is called an exception.


Software interrupt driven i o1
Software: Interrupt Driven I/O

  • Exceptions come in two varieties

    • Interrupts are generated by hardware

      • I/O device

      • Clock

      • Power down

    • Traps are generated by code execution

      • Division by zero

      • Illegal memory address

      • System call


How interrupt driven i o works
How interrupt driven I/O works

User code/data

Kernel data

Display

.text

.

la $a0, A

li $v0, 4

syscall

.

.

.data

A:

.asciiz “cat”

Output buffer


How interrupt driven i o works1
How interrupt driven I/O works

User code/data

Kernel data

Display

.text

.

la $a0, A

li $v0, 4

syscall

.

.

.data

A:

.asciiz “cat”

Output buffer

c a t


How interrupt driven i o works2
How interrupt driven I/O works

User code/data

Kernel data

Display

.text

.

la $a0, A

li $v0, 4

syscall

.

.

.data

A:

.asciiz “cat”

Output buffer

c

c a t


How interrupt driven i o works3
How interrupt driven I/O works

User code/data

Kernel data

Display

.text

.

la $a0, A

li $v0, 4

syscall

.

.

.data

A:

.asciiz “cat”

Output buffer

ca

c a t


How interrupt driven i o works4
How interrupt driven I/O works

User code/data

Kernel data

Display

.text

.

la $a0, A

li $v0, 4

syscall

.

.

.data

A:

.asciiz “cat”

Output buffer

cat

c a t


Exception mechanism
Exception Mechanism

  • The exception handler determines which event has caused the exception and decides what should be done based on it.

  • Since an exception handler can be invoked anytime, an exception handler can not have parameters nor it can return values.

  • It must also save register values being used by the interrupted program and restore them before returning control to the interrupted program.


Role of the operating system
Role of the Operating System

  • The operating system is a program that allocates and controls the use of all system resources: the processor, memory, and I/O devices.

  • Since there are many processes that can run concurrently, the operating system uses interrupt to allocate the processor to different processes periodically -- allowing processes to share processing time with each other.

  • The exception handler plus other codes used to decide what process should be executed next is called the kernel.


ad