.include "m328def.inc"; include library for the AVR ATmega328 microcontroller
.org 0x0000
RJMP begin; jump to 'begin'
.org 0x0034; sets initial program address at 0x0034
begin: CLI; disables interrupt bit
LDI R16,low(RAMEND); loads the low value of RAMEND into a register
OUT SPL,R16; sets stack pointer SPL
LDI R16,high(RAMEND); loads the high value of RAMEND into a register
OUT SPH, R16; sets stack pointer SPH
LDI R16,0xFF
OUT DDRD, R16; sets DDRD as 0xFF to set all pins of PORTD to output
looper: LDI R16,0xFF; defines the starting of an infinite loop
OUT PORTD, R16; sets all pins of PORTD to high
RCALL Delay; calls a subroutine starting at 'Delay' to create a delay of a
second while the LED is on
LDI R16,0x00
OUT PORTD, R16; sets all pins of PORTD to low
RCALL Delay; calls a subroutine starting at 'Delay' to create a delay of a
second while the LED is on
RJMP looper; jumps back to 'looper' to the next iteration of the loop
Delay: LDI R17, 0x99; defines the starting of the subroutine loop with the looping
variable at 0x99 (=153)
loop: RCALL Delay2; calls a nested subroutine 'Delay2'
DEC R17; decreases the looping value stored in the register
BRNE loop; if value at R17 is not zero, jumps back to 'loop' else continues
RET; returns to address where subroutine was called from
Delay2: LDI R18, 0xFF; defines the starting of the subroutine loop with the looping
variable at 0xFF (=255)
loop2: RCALL Delay3; calls a nested subroutine 'Delay3'
DEC R18; decreases the looping value stored in the register
BRNE loop2; if value at R18 is not zero, jumps back to 'loop2' else continues
RET; returns to address where subroutine was called from
Delay3: LDI R19, 0xFF; defines the starting of the subroutine loop with the looping
variable at 0xFF (=255)
loop3: DEC R19; decreases the looping value stored in the register
BRNE loop3; if value at R19 is not zero, jumps back to 'loop3' else continues
RET; returns to address where subroutine was called from