L12 [Input Output] - Skyline-9/CS2110-Notes GitHub Wiki

L12 [Input/Output]

IO Basics

Asynchronous

  • Electronic, mechanical, and human speed
  • Speed mismatch
  • Handshaking: ready bit

Synchronous

  • Processor operation
  • Certain kinds of high speed I/O

Two methods of doing I/O

Special I/O instructions

  • Need an opcode
  • Need to be general enough to work with devices that haven't been invented yet

Memory-mapped I/O

  • Steal part of the address space for device registers
  • Operations done by reading/writing bits in the device register
  • (We're going to concentrate on this method)

Device Registers

Data registers: Used for the actual transfer of data i.e. character code

Status registers: Information the device is telling us

Control registers: Allows us to set changeable device characteristics

Device registers are often part of the i/o device itself

Memory Mapped vs Special I/O Instructions

  • If device registers are located at valid memory addresses, how can we access them?
  • How can they be located at valid memory addresses?

Interrupt-Driven vs Polling

  1. Polling

Has a character been typed? Has a character been typed? Has a character been typed? Has a character been typed? Has a character been typed? Has a character been typed? Has a character been typed?

  1. Interrupt

Excuse me, but I've just given you a character

Our First Attempts at I/O

We'll be working with asynchronous I/O instead of synchronous. We're going to use memory mapped I/O instead of special I/O instructions. We're going to use polling instead of interrupts.

Keyboard Input

  • KBSR (xFE00)
    • Only uses one 1 bit
    • Bit 15 is set when a character is available
  • KbDr (xFE02)
    • Really only need 8 bits but 16 easier
    • This location is read-only
    • Reading clears KBSR

Memory Mapped Input

.orig x3000
LD      R4, term
LEA     R2, buffer      ; Initialize buffer pointer

START
LDI     R1, kbsrA       ; See if a char is there
BRzp    START

LDI     R0, kbdrA       ; get the character
STR     R0, R2, 0       ; Store it in the buffer

NOT     R0, R0          ; Subtract R4 - R0
ADD     R0, R0, 1       
ADD     R0, R0, R4
BRz     QUIT

ADD     R2, R2, 1       ; Increment buffer pointer
BR      START           ; Do it again

QUIT    halt

term    .fill   x001A   ; CTRL/Z
kbsrA   .fill   xFE00
kdbrA   .fill   xFE02
buffer  .blkw   x0100
        .end

Monitor Output

  • DSR (xFE04)
    • Transferring a character to DDR clears DSR
    • When monitor is finished processing a character it sets DSR bit 15
    • "Please sir, may I have another?"
  • DDR (xFE06)
    • Transfer character to this address to print it on the monitor
.orig x3000
LEA     R2, buffer      ; Initialize buffer pointer

START
LDR     R0, R2, 0       ; Get char into r0
BRz     QUIT            ; Terminate on null

WAIT
LDI     R3, dsrA        ; Are we ready?
BRzp    WAIT
STI     R0, ddrA        ; Send R0 to monitor
ADD     R2, R2, 1       ; Move buffer ptr over 1
BR      START

QUIT    halt

dsrA    .fill   xFE04
ddrA    .fill   xFE06
buffer  .stringz "Hello, World!"
        .end