-
Notifications
You must be signed in to change notification settings - Fork 0
/
FIND_WHICH.s
114 lines (90 loc) · 1.72 KB
/
FIND_WHICH.s
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
AREA find_which_, READONLY, CODE
THUMB
EXTERN OutChar
EXTERN DELAY100
EXPORT find_which
find_which PROC
;uses existing r1 and r4 values
PUSH {R0, R1, R2, R3, R4, R5,LR}
MOV R2, #0xE0 ; first row
STR R2, [R1]
BL delay50
LDR R0, [R1]
AND R0, #0x0F
CMP R0, #0x0F
MOV R4, #0 ;R4 will keep the offset for ID
BCC found
MOV R2, #0xD0 ;second row
MOV R4, #4
STR R2, [R1]
BL delay50
LDR R0, [R1]
AND R0, #0x0F
CMP R0, #0x0F
BCC found
MOV R2, #0xB0 ;third row
STR R2, [R1]
BL delay50
LDR R0, [R1]
AND R0, #0x0F
CMP R0, #0x0F
MOV R4, #8
BCC found
MOV R2, #0x70 ;fourth row
STR R2, [R1]
BL delay50
LDR R0, [R1]
AND R0, #0x0F
CMP R0, #0x0F
MOV R4, #12
BCC found
BHS not_found
found CMP R0, #0x0E
MOVEQ R5, #0
BEQ id
CMP R0, #0x0D
MOVEQ R5, #1
BEQ id
CMP R0, #0x0B
MOVEQ R5, #2
BEQ id
CMP R0, #0x07
MOVEQ R5, #3
BEQ id
id ADD R5,R5,R4
NotReleased LDR R0, [R1]
AND R0, #0x0F
CMP R0, #0x0F
BNE NotReleased
BL DELAY100
LDR R0, [R1]
AND R0, #0x0F
CMP R0, #0x0F
BNE NotReleased
;convert to ascii
CMP R5,#10
MOV R6, R5
BCC decimal
BHS hex
decimal
ADD R5,R5,#0x30
B the_end
hex ADD R5, R5, #55
the_end BL OutChar ;ptint the key ID
MOV R5, #44 ; coma
BL OutChar ; print the coma
not_found POP {R0, R1, R2, R3, R4, R5,LR}
BX LR
ENDP
delay50 PROC
PUSH {R0, LR}
LDR R0, =0x100 ;Frequency assumed to be 12MHz
loop SUBS R0,#1
NOP
NOP
BNE loop
POP {R0, LR}
BX LR
ENDP
ALIGN
END