From AVR Instruction set manual:
-- START --
PUSH - Push Register on Stack Description: This instruction stores the contents of register Rr on the STACK. The stack pointer is post-decremented by 1 after the PUSH.
Operation: STACK ← Rr
Syntax: Operands: Program Counter: Stack: PUSH Rr 0 ≤ r ≤ 31 PC ← PC + 1 SP ← SP - 1
-- END --
Correct me if i am wrong, From my understanding it will move whatever is in register Rr to stack. So now because the stack is credentialing (SP ← SP - 1), does it mean that it is growing downwards?
Also, as the current Program counter (before increment) had the instruction to Push. Which is carried out so we want to go to next instruction, so we increase the Program counter (PC ← PC + 1 ). Am i correct?
Thanks
If you want to use a more technical terminology you can say the stack is empty descending.
Descending means the stack pointer is decremented, empty means the stack pointer points to the next location on the stack (hence an empty location).
Making stacks grow downwards let us put them at the far end of the data region.
While AVR is empty descending, x86 is full descending and ARM has all four combinations but is usually used as full descending.
The program counter note is useful because of instructions like cpse
(ComPare Skip if Equal) or sbis
/sbrc
/sbrs
that increments the program counter by more than 1 (based on a condition).
All instructions of the general AVR chip but call
, jmp
, eicall
, eijmp
, icall
, ijmp
, ret
, reti
increments the program counter (rcall
and rjmp
also add a constant to it that may result in a lower final value).
Note that while the AVR data-memory-words are 8-bit, the instruction-memory-words are 16-bit and the program counter addresses words.
This is not unusual for microcontrollers, for example some variants of PIC have 14-bit instructions words.