Path: Home => AVR-Overview => Software => JUMP-command    (Diese Seite in Deutsch: Flag DE) Logo

; Calls a subroutine via the stack

;
; This subroutine call is not implemented via the RCALL command
; but by using the processor stack. The sequence is: first the
; return adress is pushed onto the stack, then the adress of
; the subroutine to be called. The jump to the subroutine and
; back to the main program is done by executing the RET-
; command (popping the adress from the stack and jump to
; this adress).
; This adressing mode is a very unusual opportunity, e.g. to write
; multiple jump adresses to a table and calculate the target adress.
; It is not meant for the beginner.
;
.NOLIST
.INCLUDE "8515def.inc"
.LIST
;
.DEF   mpr=R16 ; As always, a multi purpose working register
;

; Reset-/Interrupt-Vector table

;
   RJMP   main
;
main:   LDI   mpr,HIGH(RAMEND) ; Stack init
   OUT   SPH,mpr
   LDI   mpr,LOW(RAMEND)
   OUT   SPL,mpr

   LDI   mpr,LOW(retret)
; Push return adress to the stack
   PUSH   mpr
   LDI   mpr,HIGH(retret)
   PUSH   mpr

   LDI   mpr,LOW(testup)
; Push subroutine adress to the stack
   PUSH   mpr
   LDI   mpr,HIGH(testup)
   PUSH   mpr

   RET
; Jump to the subroutine!
;

; The called subroutine swiches all LEDs on

;
retret:   LDI   mpr,0x00 ; If successful, switch all LEDs on
   OUT   PORTB,mpr
loop:   RJMP   loop ; Halt
;
;   

; Test program to be called

;
testup:   LDI   mpr,0xFF ; All LED drivers on
   OUT   DDRB,mpr
   RET
; Return to adress on the stack


Back to the software-page

©2002 by http://www.avr-asm-tutorial.net