Introduction to AVR Assembly Language Programming II: Stack Operations

“Those who are last now will be first then, and those who are first will be last.” -Matthew 20:16

READING

The AVR Microcontroller and Embedded Systems using Assembly and C
by Muhammad Ali Mazidi, Sarmad Naimi, and Sepehr Naimi

Section: 3.2

AVRBeginners.Net
Jumps, Calls and the Stack

Table of Contents

WORKING WITH STACKS

  • Stacks
    FIFO and LIFO
    SP
    Initialization
  • LIFO Stack Operations (Push and Pop)
    Explicit push and pop

    Figure 1: Register Transfer Language

    Implicit rcall, call, icall, ret, reti

  • Working with the Stack (3 questions and answers)
    Word Size: 1 byte
    Points At: Empty Byte
    Direction: Decrements stack by 2 for implicit (call) and by 1 for explicit (push) stack operations
  • The Program Counter byte ordering on the SRAM stack is Big Endian.

STACK OPERATION ON A CALL INSTRUCTION

Figure 2: Pointer Counter in Flash Program Memory

AMAZING LAB DESIGN EXAMPLE

Figure 3: Address of Instructions in Flash Program Memory

CALL INSTRUCTION ENCODING

  • All control transfer addressing modes modify the program counter.
  • The Program Counter byte ordering on the SRAM stack is Big Endian.

Figure 4: JMP & CALL Machine Code Stored in Flash Program Memory

RCALL INSTRUCTION ENCODING

Figure 5: RJMP & RCALL Machine Code Stored in Flash Program Memory

RET INSTRUCTION ENCODING

Figure 6: RET Machine Code used to Move Pointer Counter