# Tutorial - The LC-3

```Tutorial - The LC-3
Exercises
•
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
(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
o
(b) JMP
o
(c) LEA
(d) NOT
o
(a) Operate; register and immediate addressing modes
(c) Data movement; immediate 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?
•
Exercise 4: What is the largest positive number we can represent literally within an LC-3
•
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.
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 &lt;- R2 - R3. Represent your answer in 3
lines of binary format of instruction.
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?