Can't figure out how to pop stack

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Can't figure out how to pop stack

Mark
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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Can't figure out how to pop stack

Uli Kastlunger
Hello,

two hints:

1) If you pop an element from the stack, this element is at *SP - 1, and not at *SP.

2) You need a temp. variable (you can use R13 - R15) for the popping task

I hope this helps you, if not I can elaborate it in more detail.

best regards,
uli
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Can't figure out how to pop stack

Mark
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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Can't figure out how to pop stack

culchie
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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Can't figure out how to pop stack

Mark
Ah yes, I think I've got it. Thanks!
Loading...