Path: Home => AVR-Overview => Software => Macro example 1    (Diese Seite in Deutsch: Flag DE) Logo
; *****************************************************
; * 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, a piece of code that
; will be inserted into your program whenever you
; need it there. Whenever you need the same sequences
; all over again and you don't want to call a subroutine
; you should write a macro and insert this sequence by
; calling that macro.
;
.MACRO TestMacro
   Inc   mpr
   Inc   mpr
   Inc   mpr
.ENDMACRO
;
;
; Start of main program
;
   LDI   mpr,0xFF ; Set PortB (LEDs) to be output
   OUT   DDRB,mpr ; to Data Direction Register
   CLR   mpr ; Clear the register
   TestMacro ; Insert the macro here (three INCs)
   TestMacro ; Insert it once again here (another 3)
   COM   mpr ; Invert the result to display it
   OUT   PORTB,mpr ; and write it to the LEDs
loop:   RJMP   loop ; and end the program in a loop
;
; Assembling this code should result in a 11 word long
; binary, because the two TestMacro-macros blow up to
; six INCs during the assembly process.
;
; After execution the LEDs PB.1 and PB.2 should be on,
; all others should be off to display the result (6 dec
; = 0000.0110 binary)!
;


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