Motherboard Forums


Reply
Thread Tools Display Modes

My understanding of stack, is it right?

 
 
Everett M. Greene
Guest
Posts: n/a
 
      08-15-2005, 05:37 PM
Jim Granville <> writes:
> Bruce Sam wrote:
> > If there are two register A and B in microcontroller, I use PUSH
> > A, PUSH B and then use POP A, POP B, what will happen? I thinked the
> > content of B will give to A, and the content of A will give to B.Is it
> > right?Another thing, if SP is the stack pointer, it can point to the
> > middle of the stack not the top of it. and then use POP instruction
> > will get the content of SP that point to.
> > What I understanding is right or wrong? My operation may be
> > something crazy, but I just want to know the stack deeply.

>
> If you only PUSH and POP, ( or converse) for stack access, this is
> correct for all uC.
> There is a subtle detail that can matter with more complex stack
> usage : Some uC Pre INC/DEC, and some Post INC.DEC


Or you can do like the ARM and have both flavors as a
programmer option. A good mind-boggling combination
is an upward growing stack with post-increment for
pushing and pre-decrement for popping.

> You can change the SP anytime ( at your peril, of course
>
> If you load the SP into an index register [to get a MOV @SP ]
> then the pre/post inc/dec detail matters.


Except on the Moto 680X family where the TSX/TXS instructions
make the adjustment for you.

> ie is the SP pointing to the last PUSH, or the Next PUSH ?

 
Reply With Quote
 
 
 
 
Steve at fivetrees
Guest
Posts: n/a
 
      08-15-2005, 11:56 PM
"Coos Haak" <> wrote in message
news:ioogn445u1oh$....
> Op 14 Aug 2005 21:53:53 -0700 schreef :
>
>> Are there really processors that point to the next location? If that
>> were true the top of stack contents would not easily be accesible and
>> the stack pointer allways points to garbage. Maybe you could post an
>> example.

>
> Cosmac 1802.


Blimey - that brings back memories. I had an eval board (hex keypad, hex
display) for the 1802 circa '80 or so.... usual
moonlander-in-hex-programming shenanigans...

<sigh>

Steve
http://www.fivetrees.com


 
Reply With Quote
 
Coos Haak
Guest
Posts: n/a
 
      08-16-2005, 11:19 PM
Op Tue, 16 Aug 2005 00:56:40 +0100 schreef Steve at fivetrees:

> "Coos Haak" <> wrote in message
> news:ioogn445u1oh$....
>> Op 14 Aug 2005 21:53:53 -0700 schreef :
>>
>>> Are there really processors that point to the next location? If that
>>> were true the top of stack contents would not easily be accesible and
>>> the stack pointer allways points to garbage. Maybe you could post an
>>> example.

>>
>> Cosmac 1802.

>
> Blimey - that brings back memories. I had an eval board (hex keypad, hex
> display) for the 1802 circa '80 or so.... usual
> moonlander-in-hex-programming shenanigans...
>
> <sigh>
>
> Steve
> http://www.fivetrees.com


I haven't fired it up since I bought my ZX Spectrum in 1984. It was my
first computer and soon ran Forth on it, hence my knowledge of stacks ;-)

The push (STXD) was postdecrement and pointed to a free space on the
X-stack, handy if you wanted to do arithmetic while in a subroutine. The
pop (LDA) was postincrement and pointed afterwards to a previous value. You
had to use INC and DEC everytime. Sloppy of RCA, but the SCAL and SRET of
the 1806 cured that. But this one was as my memory goes not available at
that time.

Coos
--
CHForth, 16 bit DOS applications
http://home.hccnet.nl/j.j.haak/forth.html
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT. The time now is 05:38 PM.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44