I think the basic outline should be something like:
@SP //Find out where the top of the stack is
A=M //Go to the top of the stack
D=M //Save the value into register M
??? // Set the A register to where segment[index] is mapped in RAM
M=D //Write the top of stack into segment[index]
The only problem is that I can't think of any way to implement the "???" without clobbering the D register, which is how I'm saving the value at the top of the stack.
Oh yeah, I forgot that SP points to an empty space. Okay, so I only need to decrement the value at SP first. I can't see how saving the value in R13 will help. After I set the A register to segment[index], I'll need to set M= value@R13. But if I try to load the value of R13, I'll end up overwriting the A register which I am using to point to segment[index]! An elaboration would be greatly appreciated. Thanks for your help.
I'm not sure if it's analogous but reading this reminds me of this well known puzzle.
A, D and e.g R13 are all you need, it's just a matter of figuring out how to move stuff between them.