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.
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 usePCoffset9) this is defined as:effectiveAddress=PC1 +SEXT(PCoffset9)and for LEA then,
DR=effectiveAddresswhere the LEA instruction has the format:
LEADR:3 is the 3-bit number of the target registerPCoffset:9 as a 9-bit immediate number1The incremented PC.
From location 0x3000, the incremented PC is 0x3001, while
SEXT(31)is 31, so 0x3001 + 31 is the value computed intoR1.