LC3 Intro/Review

advertisement
LC3 Intro/Review
main:
LD R3, var
var:
.FILL x023F
Symbol Table:
"main" x0200
"var" x0208
Memory
----------------------------0200:
0010 011 000000111
0208:
0000 0010 0011 1111
main:
LDI R3, dataPtr
dataPtr: .FILL var
var:
.FILL x0000
Symbol table:
"main"
x0200
"dataPtr" x0210
"var:
x1234
Memory
--------------------------0200: 1010 011 000001111
0210:
0001 0010 0011 0100
1234:
0000 0000 0000 0000
main:
...
array:
LEA R3, array
.BLKW 100
Symbol Table:
"main" x0200
"array" x0210
Memory
------------------------------0200: 1110 011 000001111
...
0210: ????
0211: ????
....
PC + or - 256
main:
ADD R0, R0, 1
BRp main
Symbol Table:
"main" x0200
Memory
-----------------------0200: 0000 001 111111110
main:
next:
...
foo:
LEA R7, next
ADD R0, R1, #11
ADD R0, R1, #10
JMP R7
...
JMP R7
TRAP x05
"RET" is a
synonym for
"JMP R7"
Not supported by LC3 assembler, lc3as,
but see lcc, C compiler for LC3.
Problem
Jumping or accessing data far away requires having the distant
address available. LD can get the address into a register, then
JMP REG or LDR can reference the distant location. But then
LD must use w/ a local pointer variable.
Solution
Have a data table in memory containing memory address, and
set a Global Data Pointer, GDP/R4, to point to it. Now all
remote address are available via "LDR REG, R4, offset".
.orig x3000
ld r1, six
ld r2, number
and r3,r3,#0
again
add r3,r3,r2
add r1,r1,#-1
brp again
halt
number
six
msg
.blkw 1
.fill x0006
.string "abc"
.end
0011000000000000
0010001000000111
0010010000000101
0101011011100000
0001011011000010
0001001001100001
0000001111111101
1111000000100101
0000000000000000
0000000000000110
...
Assembler (lc3as) Directives (to control the assembly process):
.orig: puts a load address into the .obj load-object file's header.
.end: tells assembler, this is the end of source code.
.blkw: tells assembler, create n blank words (all zeroes).
.fill: tells assembler, put these bits into a word.
.string: convert text to .FILL w/ one ascii code per word, NUL terminated.
The assembler produces machine code words:
--- ONE PER LINE expressing an LC3 instruction
--- ONE PER LINE where there is a .fill directive
--- n PER LINE where there is a .blkw directive
The assembler also calculates offsets for us using symbols. Symbols stand for
memory addresses (starting for the .orig address). Offsets are calculated by
subtraction. Symbols refer to the next instruction's location.
Switch stacks?
Save and restore SP, R6?
Hardware stack operations:
push, pop
Switch stacks:
UsersSP <==> SupersSP
Supplemental Readings
(PP) Patt & Patel, Introduction to Computing Systems, 2e (revised printing). McGraw-Hill. (Also see online material in LCA3trunk/docs/ or on the Web.)
PP, Chp. 7: 7.1-7.4 (LC-3 Assembly language: instruction syntax, labels, comments, assembler directives, 2-pass assembly,
object files and linking, executable images).
PP, Chp 8: 8.1.1-8.3.3 (device registers, memory-mapped I/O, keyboard and display I/O), 8.5 (interrupts).
PP, Chp 9: 9.1.1-9.2.2 (TRAP/JSR subroutine calls, register saving).
PP, Chp 10: 10.1-10.2 (stacks, push/pop, stack under/overflow, interrupt I/O, saving/restoring program state).
PH, Chp 8: 8.1-8.5 (I/O, disks, disk structure, RAID, buses, polling vs. interrupts, interrupt priority, DMA). [Also see on the CD,
8.3 (networks).]
PP Appendices A and C (also see LC3-turnk/docs/):
LC-3 Instruction notation definitions:
App. A.2
LC-3 Instruction descriptions:
App. A.3
LC-3 TRAP routines:
App. A.3, Table A.2
LC-3 I/O device registers:
App. A.3, Table A.3
LC-3 Interrupt and exception execution: App. A.4 and C.6
LC-3 FSM state diagram:
App. C, Fig. C.2 and C.7
LC-3 Complete datapath:
App. C, Fig. C.8
LC-3 memory map:
App. A.1
Supplemental Exercises from PP
PP, Chp 6:
6.13 (shift right [NB-use assembly language])
PP, Chp 7:
7.1 (instr. assembly w/ labels [NB-show instr. bits])
7.14 (replace an opcode in assembled prog. to debug)
7.24 (debug loop control)
PP, Chp 8:
8.5 (what is KBSR[15]?)
8.11 (polling vs. intr. efficiency)
8.14 (I/O addr. decode)
8.15 (KBSR[14] and intr. handling)
PP, Chp 9:
9.2 (TRAP execution)
9.13 (debugging JSR and RET)
9.19 (complete the intr. priority service call)
PP, Chp 10:
10.10 (CCs pushed on INT)
10.11 (device registers and IVT)
10.24 (prog. and INT service interaction)
Download