Exercise 2: Computing the Offset After Inserting a New Instruction — Possible Solution ==================================================================== THE NEW LAYOUT ------------------------------ Inserting ST R1, N immediately after the existing LD R1, N (which stays at x3001) shifts every address from that point on down by exactly one, since Pass 1's location counter simply advances one extra step to account for the new instruction: x3000 AND R2, R2, #0 x3001 LD R1, N x3002 ST R1, N <- new instruction x3003 LOOP: ADD R2, R2, R1 (was x3002, now x3003) x3004 ADD R1, R1, #-1 (was x3003, now x3004) x3005 BRp LOOP (was x3004, now x3005) x3006 ST R2, SUM (was x3005, now x3006) x3007 TRAP x25 (was x3006, now x3007) x3008 N .FILL #5 (was x3007, now x3008) x3009 SUM .FILL #0 (was x3008, now x3009) REBUILT SYMBOL TABLE (relevant entries) ------------------------------ N -> x3008 (shifted by 1 from the original x3007) LOOP -> x3003 (shifted by 1 from the original x3002) COMPUTING THE NEW INSTRUCTION'S OFFSET ------------------------------ Per the chapter's own offset formula: offset = target address - (this instruction's address + 1) The new ST R1, N sits at x3002, referencing N, which (per the rebuilt symbol table above) now lives at x3008: offset = x3008 - (x3002 + 1) = x3008 - x3003 = 5 RESULT ------------------------------ The new ST R1, N instruction's PC-relative offset is +5. WHY THIS WORKS AS AN ANSWER ------------------------------ It correctly recognizes that inserting one instruction shifts every subsequent address by exactly one (re-deriving N's new address as x3008, not reusing the original x3007), then applies the chapter's own offset formula using the NEW addresses for both the instruction and its target, rather than mixing old and new addresses together.