So from my understanding of how the stack works. Nothing ever gets removed explicitly from the stack(data is replaced instead). Think of it like this. The pointer starts from the top. To push an item, you move the pointer down before adding the item to the stack, and then when pulling(getting data from the stack), you simply decrease the pointer by one. Note: since you moved up, the next push will ignore that there was some data down there and replace it.
What are stack registers? Link - https://en.wikipedia.org/wiki/Stack_register
Stack Register Representation problem: when we stack, do we accumulate after an operation or leave the items in the stack? Won’t this also affect successive operations that would require items from the stack register?
Imagine you have to run this operation under an ALU: X = (A + B) * (C + D)
The stack register representation of the instructions would look similar to this. (a reference to the image)
We approach the left set of operands and push to stack and add the results but as the question states, do we keep the values in the same stack or is there a special place for it to be kept?
In the case we keep the result from the addition to the stack, when we continue with the remaining set, we would have to add the new things pushed to the stack to the addition results which would defeat the evaluation we want to make from the expression given.
what do you think happens? Share your thoughts.