Administrator
|
I think you probably meant the right thing, but that's not what you wrote.
You wrote: (Memory(RAM[1]) + 7)
If RAM[1] has the value 270 in it, then this reduces to
(Memory(270) + 7)
(I'm using different arbitrary numbers because I can't see my earlier post while I'm writing this.)
Since Memory(270) and RAM[270] are identical ways of saying the same thing, let's stick to the RAM[] notation.
If RAM[270] has 4038 in it, then this ultimately reduces to 4045.
What you WANT is first recognize that
RAM[1] is the address of the start of the LCL segment.
If you want local 7, then it is 7 places beyond the start of the local segment, so the address of local 7 is
RAM[1] + 7
If we want the value stored in local 7, that's
RAM[RAM[1] + 7]
or, using your earlier notation
Memory(RAM[1] + 7)
Do you see the distinction between this and
(Memory(RAM[1]) + 7)
|