0

If the pointer to the next location in the stack is raved in Ram[SP]/[0], How do I instruct the computer in hack to open the location? I have tried

@0
D=M
@D

but it isn't opening the address in stored in Ram[0] How do I make it access the ram address stored in Ram[0] Thank you

Michael
  • 57,169
  • 9
  • 80
  • 125
  • 1
    What does _"opening the address"_ mean? Also, what will you be using the value of `Ram[0]` _for_ (store it somewhere else in RAM? perform a conditional jump? ...) – Michael Aug 23 '16 at 10:31

1 Answers1

1

You indirect through a ram location using the A/M register.

@SP  // loads the A register with the value SP (SP predefined to 0)
A=M  // loads the A register with the contents of MEM[0] (the stack pointer)
D=M  // loads D with the contents of MEM[Stack]

@D would load the A register with the contents of the symbolic location D, which will get automatically assigned by the assembler. @D (address) and D (register) are not the same thing, and for that reason, using @D is not a good idea.

MadOverlord
  • 1,034
  • 6
  • 11