Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
IN P U T O U TP U T
K e yb o a rd M o n ito r
M ouse P R O C E S S IN G U N IT P rin te r
Scanner LED
D is k ALU TE M P D is k
C O N T R O L U N IT
PC IR
IN P U T OUTPU T
Each device has its own interface, K e yb o a rd M o n ito r
M ouse P rin te r
usually a set of registers like the Scanner LED
D is k D is k
memory’s MAR and MDR
LC-2 supports keyboard (input) and console (output)
keyboard: data register (KBDR) and status register (KBSR)
console: data register (CRTDR) and status register (CRTSR)
Some devices provide both input and output
disk, network
Program that controls access to a device is
usually called a driver.
Introduction to Computing Systems and Programming Fall 1384, 8
Control Unit
Orchestrates execution of the program
C O N T R O L U N IT
PC IR
Control unit:
reads an instruction from memory
the instruction’s address is in the PC
interprets the instruction, generating signals
that tell the other components what to do
an instruction may take many machine cycles to complete
Decode instruction
Evaluate address
Execute operation
Store result
such as 16 or 32 bits.
Control unit interprets instruction:
other registers
not directly addressable, but used by (and affected by) instructions
PC (program counter), condition codes
Introduction to Computing Systems and Programming Fall 1384, 14
LC-2 Overview: Instruction Set
Opcodes
16 opcodes
Operate instructions: ADD, AND, NOT
Data movement instructions: LD, LDI, LDR, LEA, ST, STR, STI
Control instructions: BR, JSR, JSRR, RET, RTI, TRAP
some opcodes set/clear condition codes, based on result:
N = negative, Z = zero, P = positive (> 0)
Data Types
16-bit 2’s complement integer
Addressing Modes
How is the location of an operand specified?
non-memory addresses: immediate, register
memory addresses: direct, indirect, base+offset
Introduction to Computing Systems and Programming Fall 1384, 15
Example: LC-2 ADD Instruction
LC-2 has 16-bit instructions.
Each instruction has a four-bit opcode, bits [15:12].
LC-2 has eight registers (R0-R7) for temporary
storage.
Sources and destination of ADD are registers.
Examples: OP
add offset to base register (as in LDR)
EX
add offset to PC (or to part of PC)
add offset to zero S
Examples: OP
load data from memory (LDR)
EX
read data from register file (ADD)
S
Examples: EA
send operands to ALU and assert ADD
OP
signal
do nothing (e.g., for loads and stores) EX
S
Introduction to Computing Systems and Programming Fall 1384, 22
Instruction Processing: STORE
Write results to destination. F
(register or memory)
D
Examples: EA
result of ADD is placed in destination register
result of memory load is placed in destination OP
register
for store instruction, data is stored to memory EX
write address to MAR, data to MDR
assert WRITE signal to memory
S
Introduction to Computing Systems and Programming Fall 1384, 23
Changing the Sequence of Instructions
In the FETCH phase,we incremented the Program
Counter by 1.
What if we don’t want to always execute the instruction
that follows this one?
examples: loop, if-then, function call