Path: Home =>
AVR-Overview =>
Software => Macro
example 3
; *****************************************************
; * 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!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
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.
©2002 by http://www.avr-asm-tutorial.net