Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: [AVR-Chat] Some questions about the stack in an AVR ATmega168A

2011-11-24 by fireweaver

I made the assumption that the simulator was correct (I've read
chatter to the effect that it has problems) but it seems that I have
answered my own question about push and pop order, to wit:

On my ATmega168A,

On calls and interrupts, push low PC first, then high PC.
On returns, pop high PC, then low PC.

I'm going to guess that this is the standard pattern for all AVRs.

It seems like a trivial matter, but in any case, Atmel needs
to mention that in their datasheets, considering that this can
be useful information for those of us who work in assembler.



fireweaver

On 11/23/2011 10:31 PM, Jim Wagner wrote:
> I don't know that it does, but its a core operational detail that I would expect some care to have been applied.
>
> Jim Wagner
>
> On Nov 23, 2011, at 1:33 PM, fireweaver wrote:
>
>> Does the AVR studio simulator truly mimic the AVR hardware exactly as
>> far as push and pop order?
>> If it does, I suppose I could try that instead and do the final smoke
>> test when I get my hardware.
>>
>> On 11/23/2011 3:16 PM, wagnerj@proaxis.com wrote:
>>> The Instruction Set document tells you a little more, but not everything.
>>> PUSH and POP are single byte operations, so the order is defined by your
>>> code. Note that, for large flash memory AVRs, the return addresses will be
>>> 3 bytes, not 2!
>>>
>>> I would simply make a very small test example, assemble it, and run it in
>>> the software emulator-debugger. You can see for yourself exactly what is
>>> happening with the stack. No great mysteries.
>>>
>>> Jim Wagner
>>> Oregon Research Electronics
>>>

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.