Docsity

Input and Output - Lecture Slides | BME 303, Exams of Biology

Partial preview of the text

Download Input and Output - Lecture Slides | BME 303 and more Exams Biology in PDF only on Docsity!

BME303 Intro. to Computing

Chapter 8: Input/Output (I/O)Chapter 8: Input/Output (I/O)

-^ I/O Basics - Device registers– Memory-mapped I/O vs.Special I/O instructions – Asynchronous vs.Synchronous -^ Input from the KeyboardO t

t t

th

it

-^ Output to the monitor•^ Interrupt-Driven I/O

te^

upt^

e^

/O

BME303 Intro. to Computing

Input/Output (I/O) DevicesInput/Output (I/O) Devices

-^ Input: Devices for transferring information to the computer, such as -^ keyboard, mouse, scanner, card reader, disk -^ Output: Devices for transferring information from the computer, suchas -^ console, printer, LED display, disk

BME303 Intro. to Computing

Virtual Reality in Protein VisualizationsVirtual Reality in Protein Visualizations

BME303 Intro. to Computing

I/O for the LC-3 (keyboard/console)I/O for the LC 3 (keyboard/console)•^ I/O for the LC-3 could be accomplished via the TRAP instruction•^ Different types of I/O service can be requested by choosing anappropriate trapvector (TV) for this instructionTrap Vector

Name

Description (Appendix A, page 543)

x^

GETC

Reads a single character from the keyboard and stores itsZEXT ASCII code in R0 (no echo on the console).

x^

OUT^

Writes a character in R0<7:0> to the console.

x^

PUTS

Writes the string beginning at M[R0] to the console.

x^

IN^

Prints prompt on console, reads a character from thekeyboard that is echoed on the console, then stores itsZEXT ASCII code in R0.

x^

PUTSP

see Appendix A, table A.2, page 543.

x^

HALT

Prints message to console; halts execution.

BME303 Intro. to Computing

Memory-Mapped vs I/O InstructionsMemory Mapped vs. I/O Instructions•Instructions– designate opcode(s) for I/O– register and operation encoded in instruction^ •Memory-mapped (LC-3)– assign a memory address

to each device registerto each device register– use existing data movementinstructions (LD/ST)for control and data transfer for control and data transfer

KDR

BME303 Intro. to Computing

Transfer TimingTransfer Timing

I/O events generally happen much slower than

g^

y^

pp

CPU cycles.•Synchronous•Synchronous– data supplied at a fixed, predictable rate– CPU reads/writes every X cycles•Asynchronous

d t^

t^ l^

di t bl

  • data rate less predictable– CPU must

synchronize

with device,

so that it doesn’t miss data or write too quickly

BME303 Intro. to Computing

Transfer ControlTransfer Control

Who determines when the next data transfer occurs?•Polling– CPU keeps checking status register until

d^

i^

OR

d^

i^

d^ f

d

new data

arrives OR

device ready

for next data

  • “Are we there yet? Are we there yet? Are we there yet?”•Interrupts– Device sends a special signal to CPU when^ new data

arrives OR

device ready

for next data

new

data

arrives

OR

device

ready

for^

next data

  • CPU can be performing other tasks instead of pollingdevice.“W k

h^

t th^

  • “Wake me when we get there.”

BME303 Intro. to ComputingLC-3LC 3

•Memory-mapped I/O

(Table A.3)

Location

I/O Register

Function

g

xFE

Keyboard Status Reg(KBSR)

Bit [15] is one when keyboardhas received a new character.Bits [7:0] contain the last

xFE

Keyboard Data Reg (KBDR)

Bits [7:0] contain the last character typed on keyboard.

xFE

Display Status Register(DSR)

Bit [15] is one when device readyto display another char on

(DSR)

p^ y screen.

xFE

Display Data Register (DDR)

Character written to bits [7:0] will be displayed on screen.

•Asynchronous devices– synchronized through status registersP lli

d I t

t

•Polling and Interrupts– the details of interrupts will be discussed in Chapter 10

BME303 Intro. to Computing

Input from KeyboardInput from Keyboard

• What problem could occur if a programWhat problem could occur if a programdoes not check the Ready bit of the KBSRbefore reading the KBDR?before reading the KBDR?Wh t

bl^

i^ lik l

t^

if th

• What problem is likely to occur if thekeyboard hardware does not check theKBSR b f

iti^

t^ th

KBDR?

KBSR before writing to the KBDR?

BME303 Intro. to Computing

Basic Input RoutineBasic Input Routine

new

POLL

LDI

R0, KBSRPtr BRzp POLLLDI

R0, KBDRPtr

new char? NO P^ lli

LDI

R0, KBDRPtr ...

KBSRPtr

FILL xFE

YES read

Polling

KBSRPtr

.FILL xFE KBDRPtr .FILL xFE

character

BME303 Intro. to Computing

Memory-Mapped InputMemory Mapped Input

1

5

1

2

5

Address Control Logicdetermines whetherMDR is loaded from

2

Memory or from KBSR/KBDR.

3

3

4

BME303 Intro. to Computing

Output to MonitorOutput to Monitor

•When Monitor is ready to display another character:

y^

p^ y

  • the “ready bit” (DSR[15]) is set to one

DDR

15

8 7

0

output data DDR DSR

1514

0

ready bit •When data is written to Display Data Register:– DSR[15] is set to zero

- current data -^ character in DDR[7:0] is displayedcharacter

in DDR[7:0] is displayed

  • any other character data written to DDR is ignored(while DSR[15] is zero)

BME303 Intro. to Computing

Basic Output RoutineBasic Output Routine

POLL

LDI

R1, DSRPtr BRzp POLLSTI

R0, DDRPtr

screenready? NO

STI

R0, DDRPtr ... DSRPtr

FILL xFE

YES write

Polling

DSRPtr

.FILL xFE DDRPtr .FILL xFE

character

Write when the ready bit is “1”

BME303 Intro. to Computing

Memory-Mapped Output

y^

pp

p

1

5

(^23)

3

4 Sets LD.DDRor selects DSR as input.