Overview The Operate Instructions - ADD, AND, NOT The Data Movement Instructions - Load, Load Address, Store Example Using Operate & Data Movement The Control instructions - BR, JMP, TRAP
Example AddressInstructionComments x30F R1 PC – 3 = x30F4 x30F R2 R = x3102 x30F M[PC - 5] R2 M[x30F4] x3102 x30F R2 0 x30FA R2 R2 + 5 = 5 x30FB M[R1+14] R2 M[x3102] 5 x30FC R3 M[M[x30F4]] R3 M[x3102] R3 5 Opcode
Branch Instruction BR [0000 nzp PCoffset9] Branch specifies one or more condition codes If the set bit is specified, the branch is taken: –PC is set to the address specified in the instruction –Target address is made by adding SEXT(IR[8:0]) to the PC If the branch is not taken: - the next sequential instruction (PC) is executed.
BR ///////////// /////+ SEXT
Jump Instruction JMP BaseR [ BaseR ] Jump is an unconditional branch -- always taken. Base –Address is contents of the register –Allows any target address.
TRAP Calls a service routine, identified by 8-bit “trap vector.” When routine is done, PC is set to the instruction following TRAP. vectorroutine x23input a character from the keyboard x21output a character to the monitor x25halt the program
LC-3 Memory Map
TRAPS
Using Branch Instructions Compute sum of 12 integers. Numbers start at location x3100. Program starts at location x3000. R1 x3100 R3 0 R2 12 R2=0? R4 M[R1] R3 R3+R4 R1 R1+1 R2 R2-1 NO YES
Sample Program AddressInstructionComments x R1 x3100 (PC+0xFF) x R3 0 x R2 0 x R2 12 x If Z, goto x300A (PC+5) x Load next value to R4 x Add to R3 x Increment R1 (pointer) X Decrement R2 (counter) x Goto x3004 (PC-6)
Example 1: Multiply This program multiplies two unsigned integers in R4 and R5. x x x x x clear R2 add R4 to R2 decrement R5 R5 = 0? HALT No Yes R2 <- 0 R2 <- R2 + R4 R5 <- R5 – 1 BRzp x3201 HALT