I'm confused in push/pop constent x

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

I'm confused in push/pop constent x

liangke
hi:
I'm confused in push/pop constent x.
example: push constent 2
it mean what ?
push 2 to where?
pop constent 2 .
it operate 2  to where?
Reply | Threaded
Open this post in threaded view
|

Re: I'm confused in push/pop constent x

cadet1620
Administrator
liangke wrote
hi:
I'm confused in push/pop constent x.
example: push constent 2
it mean what ?
push 2 to where?
pop constent 2 .
it operate 2  to where?
VM push commands all push something onto the stack; the parameters say what to push. In the case of push constant 2, the value 2 is pushed onto the stack.

VM command pop constant 2 is not allowed. That would be like trying to write "let 2 = x".

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: I'm confused in push/pop constent x

liangke
thank you!
push 2 means :
RAM[SP] = 2
is right?
Reply | Threaded
Open this post in threaded view
|

Re: I'm confused in push/pop constent x

ivant
liangke wrote
thank you!
push 2 means :
RAM[SP] = 2
is right?
Almost there. We also have to move the stack pointer to the next cell, so that consequent pushes won't overwrite this value (SP = SP + 1).