; FabAcademy 2020
; Ulises Gordillo Zapana
;-----------------------------------------------------------------------
; VARIABLES
.equ LED_PIN = PA3			; use PA3 as LED pin

;-----------------------------------------------------------------------
; PROGRAM
; start vector
.org 0x0000
	rjmp	main			; jump to main label

; main program
main:
	sbi		DDRA, LED_PIN	; set LED pin as output
loop:
	sbic	PINA, LED_PIN	; if bit of LED pin is clear, skip next line
 	cbi		PORTA, LED_PIN	; if 1, turn the LED off
	sbis	PINA, LED_PIN	; if bit of LED pin is set, skip next line
 	sbi		PORTA, LED_PIN	; if 0, light the LED up
delay_500ms:
	ldi		r20, 3			; set register, r20 = 3
delay3:
	ldi		r19, 128		; set register, r19 = 64
delay2:
	ldi		r18, 128		; set register, r18 = 128
delay1:
	ldi		r17, 128		; set register, r17 = 128
delay0:
	dec		r17				; decrement register, r18 = r18 - 1
	brne	delay0			; if r18 != 0, jump to label delay0
	dec		r18				; decrement register, r18 = r18 - 1
	brne	delay1			; if r18 != 0, jump to label delay0
	dec		r19				; decrement register, r19 = r19 -1
	brne	delay2			; if r19 != 0, jump to label delay1
	dec		r20				; decrement register, r20 = r20 -1
	brne	delay3			; if r20 != 0, jump to label delay2
	rjmp	loop			; if r20 == 0, jump to label loop