Professional Documents
Culture Documents
The lc-2 ch5
The lc-2 ch5
The LC-2
Instruction Set Architecture
ISA = All of the programmer-visible
components and operations of the computer
memory organization
address space -- how may locations can be addressed?
addressibility -- how many bits per location?
register set
how many? what size? how are they used?
instruction set
opcodes
data types
addressing modes
ISA provides all information needed for someone that wants to write a
program in machine language
(or translate from a high-level language to machine language).
Introduction to Computing Systems and Programming Fall 1383, 2
LC-2 Overview: Memory and Registers
Memory
address space: 216 locations (16-bit addresses)
addressibility: 16 bits
Registers
temporary storage, accessed in a single machine cycle
accessing memory generally takes longer than a single cycle
eight general-purpose registers: R0 - R7
each 16 bits wide
how many bits to uniquely identify a register?
other registers
not directly addressable, but used by (and affected by) instructions
PC (program counter), condition codes
Introduction to Computing Systems and Programming Fall 1383, 3
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 1383, 4
Operate Instructions
Only three operations: ADD, AND, NOT
How do we OR?
x0200
x3B24
Page x01 0011101100100100
x0400 Page number (7 bits): x1D
Page x02
Page offset (9 bits): x124
x3A00
512 words Page x1D
Direct mode addressing
x3C00 gets page number from PC[15:9]
Page x1E
and page offset from IR[8:0].
xFE00
Page x7F
Introduction to Computing Systems and Programming Fall 1383, 12
Practice
What is the page number and page offset
for each of these addresses?
Page
Address Page Offset
Number
x3102
x3002
x4321
xF3FE
TRAP
changes PC to the first instruction in an OS “service routine”
when routine is done, will execute next instruction
Introduction to Computing Systems and Programming Fall 1383, 25
Condition Codes
LC-2 has three condition code registers:
N -- negative
Z -- zero
P -- positive (greater than zero)
R4 ← M[R1]
R3 ← R3+R4
R2=0?
NO R1 ← R1+1
R2 ← R2-1
YES
Base + Offset
Address is register plus unsigned offset (IR[5:0]).
Allows any target address.
HALT
Incr Count (TRAP x25)
Introduction…
to Computing Systems and Programming Fall 1383, 43