Chap 4 & 5 LC-3 Computer LC-3 Instructions Chap 4 Homework – due Monday October 27 Chap 5 Homework – due Wednesday October 29 Project 2 Designs (Working Schematics) – due Wednesday October 29 Project 2 Reports – due Wednesday November 5 Note: Alt PrintScreen is a good way to get a 1 page schematic with timing traces Project 1 Feedback – I would like to see more clarification/discussion of what you did and observed, especially linking the timing traces to the circuits.
LC-3 Memory Map (64K of 16 bit words) 256 words 23.5 K words 39.5 K words 512 words
The LC-3 Computer a von Neumann machine Memory PSW (Program Status Word): Bits: | S| |Priority| | N| Z| P| PSW The Instruction Cycle Fetch: Next Instruction from Memory (PC) (points to) next instruction PC (PC) + 1 Decode: Fetched Instruction Evaluate: Instr & Address (es) (find where the data is) Fetch: Operand (s) (get data as specified) Execute: Operation Store: Result (if specified)
Computer Machine Instruction Formats What is IN an instruction? Operation code – what to do Input Operand(s) – where to get input operands (memory, registers) Output Operand(s) – Where to put results (memory, registers) What are the major instruction types? Data Movement (load, store, etc.) Operate (add, sub, mult, OR, AND, etc.) Control (branch, jump to subroutine, etc.)
LC-3 Instructions (Fig 5.3 – Appendix a) Addressing Modes Register (Operand is in one of the 8 registers) PC-relative (Operand is “offset” from where the PC points) Base + Offset (Base relative) (Operand is “offset” from the contents of a register) Immediate (Operand is in the instruction) Indirect (The “Operand” points to the real address of Operand – rather than being the operand)
TRAP Instruction Calls a service routine, identified by 8-bit “trap vector.” When service routine is done, PC is set to the instruction following TRAP (using RET instruction). vectorService routine x23input a character from the keyboard x21output a character to the monitor x25halt the program
TRAPS See page 543.
Example LC-3 Program Write a program to add 12 integers and store the result in a Register.
Compute the Sum of 12 Integers Program Program begins at location x3000. Integers begin at location x3100. R1 x3100 R3 0 (Sum) R2 12(count) R2=0? R4 M[R1] R3 R3+R4 R1 R1+1 R2 R2-1 NO YES R1: “Array” index pointer (Begin with location 3100) R3: Accumulator for the sum of integers R2: Loop counter (Count down from 12) R4: Temporary register to store next integer
Sum integers from x3100 – x310B AddressInstructionComments x R1 x3100 x R3 0 x R2 0 x R2 12 x If Z, goto x300A x Load next value to R4 x Add to R3 x Increment R1 (pointer) X Decrement R2 (counter) x Goto x3004 R1: “Array” index pointer (Begin with location 3100) R3: Accumulator for the sum of integers R2: Loop counter (Count down from 12) R4: Temporary register to store next integer
The Sum program in “binary” ;start x3000 x ;R1=x3100 x ;R3=0 x ;R2=0 x ;R2=R2+12 x ;If z goto x300A x ;Load next value into R4 x ;R3=R3+R4 x ;R1=R1+1 x ;R2=R2-1 x ;goto x3004 x300A ;halt
The Sum program in “hex” 3000 ;start x3000 x3000 E2FF ;R1=x3100 x E0 ;R3=0 x A0 ;R2=0 x AC ;R2=R2+12 x ;If z goto x300A x ;Load next value into R4 x C4 ;R3=R3+R4 x ;R1=R1+1 x BF ;R2=R2-1 x3009 0FFA ;goto x3004 x300A F025 ;halt
The Sum program Data in “hex” 3100 ; Begin data at x3100 x ; Loc x3100 x x x x3104 FFFF x3105 1C10 x B1 x x3108 0F07 x x310A 0A00 x310B 400F ; Loc x310B
LC3 Edit Enter (or Load) the program into LC3 Edit - Store it as prog.bin for a binary file, or Store it as prog.hex for a hex file - Create a prog.obj file with the Editor Enter (or Load) the data into LC3 Edit - Store it as data.bin for a binary file, or Store it as data.hex for a hex file - Create a data.obj file with the Editor
LC-3 Simulator Open LC-3 Simulator - Load prog.obj - Load data.obj - Set breakpoint(s) - Step through program
Simulator Screen
LC3 Edit