; Tests subroutine calls via 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 "C:\avrtools\appnotes\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 setup out SPH,mpr ldi mpr,LOW(RAMEND) out SPL,mpr ldi mpr,LOW(retret) ; Push return adress onto stack push mpr ldi mpr,HIGH(retret) push mpr ldi mpr,LOW(testup) ; Push subroutine adress onto stack push mpr ldi mpr,HIGH(testup) push mpr ret ; Jump to subroutine ; ; The return routine switches all lamps on to signal correct execution ; retret: ldi mpr,0x00 ; Switch all LEDs on, if correct out PORTB,mpr loop: rjmp loop ; stop execution ; ; ; Test subroutine to be jumped to ; testup: ldi mpr,0xFF ; All lamp drivers tov output out DDRB,mpr ret ; Jump back to call adress on the stack