[Coco] Assembly language question: The stack

Luis Fernández luis46coco at hotmail.com
Wed Oct 24 22:26:03 EDT 2018


According to what I remember, first the stack is decremented and then the value is placed in the new position indicated by the stack, in fact the SP always reports the last used value, so if we indicate $ 4000, it means that in $ 4000 there is a value necessary and used as the last value of the stack.



Certainly the first time we use the stack it must point to the last byte of memory used for other purposes, since when doing PUSH it will decrement first and then place the BYTE.



Enviado desde Correo<https://go.microsoft.com/fwlink/?LinkId=550986> para Windows 10



________________________________
De: Coco <coco-bounces at maltedmedia.com> en nombre de Salvador Garcia via Coco <coco at maltedmedia.com>
Enviado: Wednesday, October 24, 2018 9:34:17 PM
Para: CoCoList for Color Computer Enthusiasts
Cc: Salvador Garcia
Asunto: [Coco] Assembly language question: The stack

Hi all,

I am studying assembly language for the 6809 and have a question about the stack.

>From what I have been reading, I deduced the following:

When I push a byte the stack pointer decrements and then the byte is stored at that location

When I pull a byte, the byte is recovered from the current pointer location and then the pointer is incremented.

I'll pause here in case any of the above needs correction.

This means that the stack pointer points to the top of the stack where the last pushed byte is located. If I initialize the stack pointer to, say $4000, for example and I do the first push, what happens to location $4000. If I am correct in how the stack works, the first byte of the stack is always wasted because the push causes the pointer to decrement before the value is stored.

Am I correct about this?

Also, I assume it is the developer's responsibility to manage the stack, that is, there is no way to know if the stack gets too big or if I do too many pulls and end up pulling from an empty stack. Is that right?

Thanks all, especially to those who are on CoCoTalk answering questions about Steve Bjork's assembly course :-)

Salvador


--
Coco mailing list
Coco at maltedmedia.com
https://pairlist5.pair.net/mailman/listinfo/coco


More information about the Coco mailing list