Path: Home => AVR-Overview => Software => Macro example 2
; *****************************************************
; * Jump labels within a macro: the answer is "yes" *
; * Demonstrates the use of macros with the ATMEL *
; * assembler, just a test program for use with the *
; * ATMEL STK200 board, (C) 2000 Gerhard Schmidt *
; * Report bugs to info!at!avr-asm-tutorial.net *
; *****************************************************
;
.NOLIST
.INCLUDE "8515def.inc"
.LIST
;
; Used registers
;
.DEF mpr=R16 ; a multi purpose register
;
; The following is the macro which includes a label
; within that macro (mjmp) and a jump to a label
; outside that macro. Both jumps are translated
; correctly.
;
.MACRO TestMacro
   Inc   mpr ; INC the register mpr
   BRNE   mjmp ; If no overflow skip the next
   RJMP   ovf ; Jump if overflow occurs
mjmp:
.ENDMACRO
;
.LISTMAC
;
; Start of main program
;
   LDI   mpr,0xFF ; Set PortB (LEDs) to be output
   OUT   DDRB,mpr ; to Data Direction Register
;
   LDI   mpr,0xFE ; Set the register to 254
   TestMacro ; Insert the macro here (one INC)
   TestMacro ; Insert it once again here (another INC)
; As there should have been an overflow during the last INC
; the following code should not be reached. If executed,
; it would result in all LEDs on.
;
outp:   OUT   PORTB,mpr
loop:   RJMP   loop ; and end the program in a loop
;
; The overflow should occur and this code will be executed
;
ovf:   LDI   mpr,0xFF ; Blank all LEDs
   OUT   PORTB,mpr ; at Port B
   RJMP   loop ; Jump to indefinite loop
;
; After execution all the LEDs PB.0 to PB.7 should be off.


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