Introduction to LC3

LC-3

“Little Computer 3”

Very simple “architecture”

ISA

“ISA” – Instruction Set Architecture

Definition of the set of instructions which a specific computer recognizes.

“…data types, instructions, registers, addressing modes, memory architecture, interrupt and exception handling, and external I/O. An ISA includes a specification of the set of opcodes (machine language), and the native commands implemented by a particular processor.” Wikipedia ISA

Seems unclear now, but we’ll learn more!

WORD

16 bits

15

14

13

12

11

10

9

8

7

6

5

4

3

2

1

0

Types (Interpretations)

·         Unsigned binary number

·         Two’s Complement binary number

·         Two ASCII characters

·         Absolute Address in Memory

·         Address Offset in Memory

·         LC-3 Assembly Instruction

LC-3 Memory

ROM with 16 address bits and 16 data bits (1 word). (16 data in, 16 data out).

Matrix with 16 columns and 216 = 65,376 rows!

Each row index is an “address” in memory… a pointer to a 16 bit word.

We typically write an address as a 4 digit hexadecimal number, e.g. 0x203A -> 16 bit word at row 8250.

By convention, we draw memory w/ low addresses at the top, high addresses at the bottom…

0x0000

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

0x0001

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

0x0002

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

0x0003

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

0x0004

0

0

0

1

1

0

1

1

1

0

1

0

1

0

0

0

1

0x0005

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

0xFFFD

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

0xFFFE

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

0xFFFF

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Value @ 0x0004 = 0b0011 0111 0101 0001 = 0x3751 = 14,161

Or 0x0004 -> 0x3751

We also write memory in hexadecimal, like…

0x0000

 

 

 

 

0x0001

 

 

 

 

0x0002

 

 

 

 

0x0003

 

 

 

 

0x0004

3

7

5

1

0x0005

 

 

 

 

 

 

 

 

 

 

 

 

 

0xFFFD

 

 

 

 

0xFFFE

 

 

 

 

0xFFFF

 

 

 

 

 

In LC-3, addresses 0x0000 – 0x2FFF are often used already, leaving us 0x3000 – 0xFFFF!

Reading and Writing Memory is SLOW – and needs to be avoided when possible.

REGISTERS

Small Local Memory – FAST

General Purpose Memory

In LC3 - R0, R1, R2, R3, R4, R5, R6, R7 – each 16 bits (1 word) wide

R0

0000

0101

1000

1101

R1

 

 

 

 

R2

 

 

 

 

R3

 

 

 

 

R4

 

 

 

 

R5

 

 

 

 

R6

 

 

 

 

R7

 

 

 

 

Program Counter

Single 16 bit (1 word) register labeled “PC” (Program Counter)

Holds the address of the next instruction to execute

PC

0000

0011

0000

0000

And…

More we’ll learn about later (instruction register, condition codes, resolved addresses, memory fetch results, …)

Von Neumann Architecture

File:JohnvonNeumann-LosAlamos.gif John Von Neumann

Hungarian born Mathematician, Physicist, Computer Scientist

Princeton – Institute for Advanced Studies (w/ Einstein, etc. etc.)

Manhattan Project (A-Bomb)

EDVAC – First US Digital Computer

http://www.uni-obuda.hu/files/image/978.jpg

Organized as:

·         Processing Unit

o   Arithmetic/Logical Unit

o   Registers

·         Control Unit

o   Program Counter

o   Instruction Register

·         Memory for both Data and Instructions!

·         Input/Output Devices

o   Punch Card Reader

o   Lights

o   Mass Storage Device (e.g. Disk)

o   Printer

Instructions

The smallest thing a computer can do – Atomic

Two Versions…

1.      Machine Readable Instructions

a.       “Object” code

b.      In LC3 – 16 bits

                                                              i.      First 4 bits (15-12)  – “Operation Code” (op-code)

                                                            ii.      Last 12 bits (11-0) – “Operands” – stuff to work on (Format depends on op-code)

2.      Man Readable Instructions

a.       “Assembly” Language

b.      In LC3 – One line of text

                                                              i.      Optional “Label” – name associated with this instruction

                                                            ii.      Op-Code – 2 or 3 letter “instruction name” (all caps)

                                                          iii.      Operands – Stuff to work on (Format depends on op-code)

                                                          iv.      Comment – Semi-colon, followed by information to help us figure out what is going on

For example…

start      ADD R3,R4,R2  ;Add the value in R4 to R2, and store the result in R3

0001 011 100 0 00 010

0x1702

5890

While executing, kept in a 16 bit (1-word) Instruction Register

IR

0x1702

 

Instruction Processing Loop

Fetch Instruction

·         Copy memory at PC value into instruction register

·         Add 1 (Increment) PC!!!!

For example…

PC

0x3000

IR

0x____

PC

0x3001

IR

0x1702

 

 

 

Decode

·         Figure out how to read the instruction  See TextBook Appendix A

For example…

1.      0x1702 = 0b0001 0111 0000 0010

2.      Opcode = 0b0001 = ADD

3.      0b0001 011 100 0 00 010

4.      ADD DR=3,SR1=4,SR2=2

5.      Get the value of R4 and the value of R2 – add them together, store the result in R3.

Evaluate Addresses

·         More on this later… not used for ADD.

Fetch Operands

·         Get values from Registers or Memory

Get the value of R4 and R2

Execute

·         Perform the required ALU (Arithmetic/Logic Unit) Function

Add the two operands

Store Results

·         Move the ALU output to Register or Memory

Put R4+R2 value into R3