-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelay_usec.s
More file actions
59 lines (53 loc) · 1.08 KB
/
Copy pathdelay_usec.s
File metadata and controls
59 lines (53 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* delay_usec.s
*
* Created: 1/22/2017 2:58:59 PM
* Author: Carter W, Drake Stillman
*/
.section .text
.global delay_usec
delay_usec: ;4 cycles of RCALL
;2 cycles for parameter => parameter is in r24 and r25
ldi r18, 0x01 ;set to one
eor r19, r19 ;zero out high bits
cp r18, r24
cpc r19, r25 ;Check if parameter is 1
brne testzero ;two cycles if true, one if false
ret ;If one, branch fails
testzero: ;at 12 cycles
eor r18, r18 ;zero low bits
cp r18, r24
cpc r19, r25
breq zero ;at 16 cycles if fail, 17 if parameter is zero
loop: ;16 cycles have passed, parameter needs to be parameter-1
sbiw r24, 0x01 ;2 cycles, parameter-1
nop
nop
nop
ldi r18, 0x01 ;set to one
eor r19, r19 ;zero out high bits
cp r18, r24
cpc r19, r25
breq one ;if one => 2 cycles, if greater than => 1 cycle
nop
nop
nop
nop
rjmp loop
one:
ret ;5 cycles
zero: ;17 cycles, need to burn 15, then jump to loop with MAX-1
ldi r24, 0xFF
ldi r25, 0xFF ;sets parameter to 65536-1
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
rjmp loop ;2 cycles