How do I determine the PC offset of a LC-3 machine

132 Views Asked by At

In a homework assignment we are trying to trace the code of a LC-3 machine The first line of code is 0x3000 1110 001 000011111 which is a LEA to destination of R1. I am lost by the PC offset. If I read it right it is 31 in decimal or 1F in hex. But the range we are given to get info from is 0x3020 through 0x3025. Am I doing something wrong?

I tried reading our book and going over lecture notes, but the instructor just gives us an answer without explaining how he gets it.

1

There are 1 best solutions below

0
Erik Eidt On

You already have the PC offset — it is 31.

What you're looking for is the effective address (aka memory location) that is referred to by a PC offset of 31 from an instruction located at 0x3000.

For LEA (and the others that use PCoffset9) this is defined as:

effectiveAddress = PC1 + SEXT(PCoffset9)

and for LEA then, DR = effectiveAddress

where the LEA instruction has the format:

1110:4 DR:3 PCoffset:9
  • 1110:4 is the 4-bit opcode for LEA
  • DR:3 is the 3-bit number of the target register
  • PCoffset:9 as a 9-bit immediate number

1The incremented PC.

From location 0x3000, the incremented PC is 0x3001, while SEXT(31) is 31, so 0x3001 + 31 is the value computed into R1.