	.func spin
	.global spin
	.global __delay_10us
spin:
	call	sub_delay_10
	dec		R24
	brne	spin
	ret
	.endfunc


sub_delay_10:
	push	R17			; save R17 [2]
	push	R18			; save R18 [2]

	ldi		R18, 10		; init outer [1]
delay_10:
	ldi		R17, 199	; init counter [1]

delay_1:
	dec 	R17			; [1]
	nop					; [1]
	nop					; [1]
	brne	delay_1		; [2] total [5] x 216
	
	dec		R18			; [1]
	brne	delay_10	; [2] total [4] x 10 = [40]

	pop		R18			; [2]
	pop		R17			; [2] restore R17
	ret					; [5] [19] + [40]

; caller is [6]
__delay_10us:
	DEC		R24			; [1]
delay_us_l:
	SBIW	R24, 1		; [2]
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP					; [6] for nops
	BRNE	delay_us_l	; [2] or [1] 3 * num uS
	RET					; [4] 
	
