; ***************************************************** ; * To pass a parameter to a macro is easy to program * ; * 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@avr-asm-tutorial.net * ; ***************************************************** ; .NOLIST .INCLUDE "C:\avrtools\appnotes\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 the value for the ; register is handed over with the first parameter ; referenced by @0. ; .MACRO TestMacro ldi mpr,@0 ; Set mpr-value to first parameter inc mpr ; Add one 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 ; Here comes the macro: 0xFF is passed to it, then INCed ; and, as it is zero, jumps to the label ovf ; testmacro(0xff) ; Insert the macro here ; ; 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.