Exercise 3: Why "ADD Directly to Memory" Isn't Valid LC-3 — Possible Solution ==================================================================== WHY ADD R1, VALUE, #1 IS INVALID ------------------------------ Per the chapter's own Load/Store Architecture section, LC-3's ALU instructions (ADD, AND, NOT) are only ever allowed to operate on values already sitting in REGISTERS -- never directly on a value stored in memory. VALUE is a memory location (a label), not a register, so it can't legally appear as an operand to ADD at all. There is no LC-3 instruction that reaches into memory, modifies a value there, and writes it back in one single step -- that capability was deliberately left out of the design. THE CORRECT TWO-INSTRUCTION SEQUENCE ------------------------------ LD R1, VALUE ; load the value at VALUE into a register first ADD R1, R1, #1 ; now perform the addition on the register ST R1, VALUE ; (if the result needs to be saved back to memory) The chapter's own wording describes exactly this: "If you want to add something to a value stored in memory, you have to explicitly LD it into a register first, operate on it there, and ST it back out if you need the result saved." The first LD gets VALUE's contents into R1; the ADD then legally operates on R1 (a register, not memory); the final ST is only needed if the incremented value has to persist back in memory rather than just being used from R1 going forward. WHY THIS WORKS AS AN ANSWER ------------------------------ It identifies specifically why VALUE can't be an ADD operand (it's a memory location, and ALU instructions are restricted to registers only), and supplies the correct load-operate-(optionally store) sequence the chapter itself describes, rather than just asserting that the one-line version "doesn't exist."