0% found this document useful (0 votes)
48 views9 pages

Computer Architecture and Assembly Language: Practical Session 11

The document discusses input/output (I/O) architecture and methods for computer systems. It describes how I/O devices connect to the CPU through an I/O module and controller. It explains programmed I/O, interrupt-driven I/O, and direct memory access (DMA) for transferring data between devices and memory. It also covers I/O ports for communicating with controllers through input and output instructions. An example shows writing a simple keyboard driver that reads key presses through polling an I/O port register.

Uploaded by

Ameer Ameen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views9 pages

Computer Architecture and Assembly Language: Practical Session 11

The document discusses input/output (I/O) architecture and methods for computer systems. It describes how I/O devices connect to the CPU through an I/O module and controller. It explains programmed I/O, interrupt-driven I/O, and direct memory access (DMA) for transferring data between devices and memory. It also covers I/O ports for communicating with controllers through input and output instructions. An example shows writing a simple keyboard driver that reads key presses through polling an I/O port register.

Uploaded by

Ameer Ameen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Computer Architecture and

Assembly Language

Practical Session 11
Input &Output (I/O)
CPU-Memory-I/O Architecture
Input / Output (I/O) devices are used to interact with “outside world”
• mouse, screen, disks, printer …

CPU

I/O module / Operating system


I/O driver

I/O controller

I/O device
I/O Controller
• Typically I/O Controller has 3 internal registers:
– Data register
– Status register
– Command register
Data in

Data out

Example: character output


• Check status register of I/O controller
• e.g. busy, idle, offline
• Put data into data in register
• Put command into command register
• e.g. “send the character in data register to printer”
Programmed I/O
• Software controls I/O operations
– slow 
– busy CPU wait 
– simple 
Interrupt-driven I/O
• Device includes a signal to interrupt CPU (interrupt is produced by hardware)
• When an interrupt occurs (and is accepted), a special routine
executes to service the interrupt
– no CPU busy wait 

Direct memory access (DMA) I/O DMA Controller

• CPU transfer information to DMA controller (DMAC)


• location of data on device
• location of data in memory
• size of block to transfer
• direction of transfer
• When device is ready, DMAC takes control of the system buses
I/O controller I/O controller to
to DMA
DMA module

controller controller

controller controller

5
I/O Ports
• I/O port is the address of I/O controller register
• Two kinds of mapping: Two address spaces

Isolated I/O
– separate address spaces
– special commands for I/O

• in instruction is used to read data from I/O port:


in register, port address (direct address)
x86 provides 64 I/O ports is not
in register, DX (indirect address) KB of isolated I/O physical memory, it is
• out instruction is used to write data to I/O port: address space virtual mapping of I/O
controllers’ registers
out port address, register (direct address) and to their addresses
out DX, register (indirect address)
• register must be AL, AX, or EAX
I/O ports mapping table

address I/O controller


RAM
Example: 0x60 Screen device
data out
‘a’ … … I/O controller register
mov byte [0x60], ‘a’ 0x60

mov AL, ‘a’ ‘a’


0x60
out 0x60, AL
I/O Ports
• I/O port is the address of I/O controller register
• Two kinds of mapping:
Memory mapped I/O
– no special commands for I/O
– use regular memory read/write commands

Example: I/O ports mapping table

address I/O controller


mov byte [0x60], ‘a’
0x60 Screen device
mov byte [0x80], ‘b’ … …

Screen device
RAM I/O controller
data out register

0x60 ‘a’
0x60

‘b’
0x80
Example – How to Write a Simple Keyboard Driver

• Use PA input port register at address 60h


– PA7 = 0 if a key is pressed
– PA7 = 1 if a key is released PA7 PA6 PA5 PA4 PA3 PA2 PA1 PA0

– PA0–PA6 = key scan code

• Use busy wait loop


– wait until a key is pressed (i.e. until PA7 = 0)
– read scan code of the key
– wait until a key is released (i.e. until PA7 = 1)

• Pressing ESC key terminates the program


Example – How to Write a Simple Keyboard Driver
section .data
ESC_KEY EQU 0x1B ; ASCII code for ESC key TEST instruction performs a
KB_DATA EQU 0x60 ; port PA bitwise AND on two operands. The
flags SF, ZF, PF are modified while the
section .text result of AND is discarded.
global _start
_start:

key_down_loop: ; loop until a key is pressed i.e., until PA7 = 0


in AL, KB_DATA ; read keyboard status & scan code
test AL, 0x80 ; PA7 = 0? (0x80=10000000b)
jnz key_down_loop ; if not, loop back

and AL,0x7F ; (0x7F=01111111b) – isolate scan code


..translate scan code to ASCII code in AL..

cmp AL, ESC_KEY ; ESC key - terminate program


je done

key_up_loop: ; loop until a key is released i.e., until PA7 = 1


in AL, KB_DATA ; read keyboard status & scan code
test AL, 0x80 ; PA7 = 1? (0x80=10000000b)
jz key_up_loop ; if not, loop back (busy wait)

jmp key_down_loop

done:
..exit program..

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy