Tutorial - The LC-3 Exercises • Exercise 1: Addressing modes o (a) What is an addressing mode? o (b) Name three places an instruction's operands might be located. (c) List the five addressing modes of the LC-3. o (d) For each of the addressing mode, state where the operand is located. o Answer: (a) It is a way to specify where to get and evaluate the data to be operated or moved. (b) The three places are memory, register, and instruction itself. (c) The five addressing modes are: Register, Immediate, PC-relative, Base plus offset, indirect. (d) Register mode: the operand is in the register(s). Immediate mode: the operand is coded in the instruction itself. PC-relative mode: the operand is PC plus the data coded in the instruction itself. Base + offset mode: the operand is in register plus the data coded in the instruction itself. Indirect mode: the operand is eventually found in memory. • Exercise 2: For each of the following instruction, identify whether the instructions are operate instructions, data movement instructions, or control instruction. Also list the addressing modes that can be used with each instruction. o (a) ADD o (b) JMP o (c) LEA (d) NOT o Answer: (a) Operate; register and immediate addressing modes (b) Branch; register addressing mode (c) Data movement; immediate mode (d) Operate; register addressing mode • Exercise 3: If we use the PC-relative addressing mode, and want to allow control transfer between instructions 256 locations away, how many bits of a branch instruction are needed to specify the PC-relative offset? Answer: 9 bits • Exercise 4: What is the largest positive number we can represent literally within an LC-3 ADD instruction (Immediate mode)? Answer: 15 • Exercise 5: The LC-3 does not have an opcode for the logical function OR. However, we can write a sequence of instructions to implement the OR operation. Write the four instruction sequence that performs the OR of the contents of register 1 and register 2 and puts the result in register 3. Represent your answer in 4 lines of binary format of instruction. Answer: 1001 001 001 111111 1001 010 010 111111 0101 011 001 0 00 010 1001 011 011 111111 • Exercise 6: The LC-3 has no subtract instruction. How could one perform the following operation using only three LC-3 instructions: R1 <- R2 - R3. Represent your answer in 3 lines of binary format of instruction. Answer: 1001 011 011 111111 0001 011 011 1 00001 0001 001 010 0 00 011 • Exercise 7: LC-3 Instructions o (a) Write an LC-3 instruction that clears the contents of R1. o (b) Write an LC-3 instruction that moves the value in R2 into R3. o (c) Using only one LC-3 instruction and without changing the contents of any register, how might one set the condition codes based on the value that resides in R1? Answer: (a) 0101 001 001 1 00000 (b) 0001 011 010 1 11111 (c) 0101 001 001 1 11111