0

I am given a few lines of code and told to write the corresponding LC3 instructions. I am having trouble determining the offset value.

For example:

x3100    1110001000100000

So 1110 is the opcode for LEA. 001 signifies R1. The rest confuses me. I am left with 000100000. Looking at the LC-3 Instruction List, the syntax for LEA is as follows

LEA-->  |1110|DR|PCoffset9|

How do I figure out what PCoffset9 is from my code? 000100000 is the number 32, so is it:

LEA R1, #32    ;is this right?

That doesn't seem right. I thought I recalled seeing these numbers represented as memory locations? So 000100000 would be x020? I am so confused on how to figure out the offset.

GenericUser01
  • 337
  • 3
  • 11
  • 27

1 Answers1

2

You're right with the breakdown of this instruction. The offset 000100000 that remains is indeed 32 in decimal or x0020 in hex.

This offset must be taken from the end of the current instruction. Since the current instruction is at x3100 the end of it is at x3101. Now you add 32 to this number and you get the memory address that this LEAis referring to. x3101 + 32 == x3121

Most probably in a normal program there would be a label defined at this address x3121. Thus the instruction encoding 1110001000100000 could have originated from a source line like:

LEA R1, MYLABEL
Fifoernik
  • 9,779
  • 1
  • 21
  • 27