Relative program addressing, rjmp and rcall, Constant addressing using the lpm instruction, Subroutine and interrupt hardware stack – Rainbow Electronics ATtiny12 User Manual

Page 12: Attiny11/12

Advertising
background image

12

ATtiny11/12

1006C–09/01

Relative Program Addressing,
RJMP and RCALL

Figure 12. Relative Program Memory Addressing

Program execution continues at address PC + k + 1. The relative address k is -2048 to
2047.

Constant Addressing Using
the LPM Instruction

Figure 13. Code Memory Constant Addressing

Constant byte address is specified by the Z-register contents. The 15 MSBs select word
address (0 - 511), the LSB selects low byte if cleared (LSB = 0) or high byte if set
(LSB = 1).

Subroutine and Interrupt
Hardware Stack

The ATtiny11/12 uses a 3-level-deep hardware stack for subroutines and interrupts. The
hardware stack is 9 bits wide and stores the program counter (PC) return address while
subroutines and interrupts are executed.

RCALL instructions and interrupts push the PC return address onto stack level 0, and
the data in the other stack levels 1-2 are pushed one level deeper in the stack. When a
RET or RETI instruction is executed the returning PC is fetched from stack level 0, and
the data in the other stack levels 1-2 are popped one level in the stack.

If more than three subsequent subroutine calls or interrupts are executed, the first val-
ues written to the stack are overwritten. Pushing four return addresses A1, A2, A3, and
A4, followed by four subroutine or interrupt returns, will pop A4, A3, A2, and once more
A2 from the hardware stack.

+1

$1FF

$000

PROGRAM MEMORY

15

1 0

Z-REGISTER

Advertising