Debian Codegraph @

tests/languages/armasm/instruction_feature.test

raw
1 AREA subrout, CODE, READONLY ; Name this block of code
2 ENTRY ; Mark first instruction to execute
3 start MOV r0, #10 ; Set up parameters
4 MOV r1, #3
5 BL doadd ; Call subroutine
6 stop MOV r0, #0x18 ; angel_SWIreason_ReportException
7 LDR r1, =0x20026 ; ADP_Stopped_ApplicationExit
8 SVC #0x123456 ; ARM semihosting (formerly SWI)
9 doadd ADD r0, r0, r1 ; Subroutine code
10 BX lr ; Return from subroutine
11 END ; Mark end of file
12
13
14 MACRO
15 $Lab DivMod $Div,$Top,$Bot,$Temp
16 ASSERT $Top <> $Bot ; Produce an error message if the
17 ASSERT $Top <> $Temp ; registers supplied are
18 ASSERT $Bot <> $Temp ; not all different
19 IF "$Div" <> ""
20 ASSERT $Div <> $Top ; These three only matter if $Div
21 ASSERT $Div <> $Bot ; is not null ("")
22 ASSERT $Div <> $Temp ;
23 ENDIF
24 $Lab
25 MOV $Temp, $Bot ; Put divisor in $Temp
26 CMP $Temp, $Top, LSR #1 ; double it until
27 90 MOVLS $Temp, $Temp, LSL #1 ; 2 * $Temp > $Top
28 CMP $Temp, $Top, LSR #1
29 BLS %b90 ; The b means search backwards
30 IF "$Div" <> "" ; Omit next instruction if $Div is null
31 MOV $Div, #0 ; Initialize quotient
32 ENDIF
33 91 CMP $Top, $Temp ; Can we subtract $Temp?
34 SUBCS $Top, $Top,$Temp ; If we can, do so
35 IF "$Div" <> "" ; Omit next instruction if $Div is null
36 ADC $Div, $Div, $Div ; Double $Div
37 ENDIF
38 MOV $Temp, $Temp, LSR #1 ; Halve $Temp,
39 CMP $Temp, $Bot ; and loop until
40 BHS %b91 ; less than divisor
41 MEND
42
43 ----------------------------------------------------
44
45 [
46 ["directive", "AREA"],
47 " subrout",
48 ["punctuation", ","],
49 ["directive", "CODE"],
50 ["punctuation", ","],
51 ["directive", "READONLY"],
52 ["comment", "; Name this block of code"],
53
54 ["directive", "ENTRY"],
55 ["comment", "; Mark first instruction to execute"],
56
57 "\r\nstart ",
58 ["instruction", "MOV"],
59 ["register", "r0"],
60 ["punctuation", ","],
61 ["operator", "#"],
62 ["number", "10"],
63 ["comment", "; Set up parameters"],
64
65 ["instruction", "MOV"],
66 ["register", "r1"],
67 ["punctuation", ","],
68 ["operator", "#"],
69 ["number", "3"],
70
71 ["instruction", "BL"],
72 " doadd ",
73 ["comment", "; Call subroutine"],
74
75 "\r\nstop ",
76 ["instruction", "MOV"],
77 ["register", "r0"],
78 ["punctuation", ","],
79 ["operator", "#"],
80 ["number", "0x18"],
81 ["comment", "; angel_SWIreason_ReportException"],
82
83 ["instruction", "LDR"],
84 ["register", "r1"],
85 ["punctuation", ","],
86 ["operator", "="],
87 ["number", "0x20026"],
88 ["comment", "; ADP_Stopped_ApplicationExit"],
89
90 ["instruction", "SVC"],
91 ["operator", "#"],
92 ["number", "0x123456"],
93 ["comment", "; ARM semihosting (formerly SWI)"],
94
95 "\r\ndoadd ",
96 ["instruction", "ADD"],
97 ["register", "r0"],
98 ["punctuation", ","],
99 ["register", "r0"],
100 ["punctuation", ","],
101 ["register", "r1"],
102 ["comment", "; Subroutine code"],
103
104 ["instruction", "BX"],
105 ["register", "lr"],
106 ["comment", "; Return from subroutine"],
107
108 ["directive", "END"],
109 ["comment", "; Mark end of file"],
110
111 ["directive", "MACRO"],
112
113 ["variable", "$Lab"],
114 " DivMod ",
115 ["variable", "$Div"],
116 ["punctuation", ","],
117 ["variable", "$Top"],
118 ["punctuation", ","],
119 ["variable", "$Bot"],
120 ["punctuation", ","],
121 ["variable", "$Temp"],
122
123 ["directive", "ASSERT"],
124 ["variable", "$Top"],
125 ["operator", "<>"],
126 ["variable", "$Bot"],
127 ["comment", "; Produce an error message if the"],
128
129 ["directive", "ASSERT"],
130 ["variable", "$Top"],
131 ["operator", "<>"],
132 ["variable", "$Temp"],
133 ["comment", "; registers supplied are"],
134
135 ["directive", "ASSERT"],
136 ["variable", "$Bot"],
137 ["operator", "<>"],
138 ["variable", "$Temp"],
139 ["comment", "; not all different"],
140
141 ["directive", "IF"],
142 ["string", [
143 "\"",
144 ["variable", "$Div"],
145 "\""
146 ]],
147 ["operator", "<>"],
148 ["string", ["\"\""]],
149
150 ["directive", "ASSERT"],
151 ["variable", "$Div"],
152 ["operator", "<>"],
153 ["variable", "$Top"],
154 ["comment", "; These three only matter if $Div"],
155
156 ["directive", "ASSERT"],
157 ["variable", "$Div"],
158 ["operator", "<>"],
159 ["variable", "$Bot"],
160 ["comment", "; is not null (\"\")"],
161
162 ["directive", "ASSERT"],
163 ["variable", "$Div"],
164 ["operator", "<>"],
165 ["variable", "$Temp"],
166 ["comment", ";"],
167
168 ["directive", "ENDIF"],
169
170 ["variable", "$Lab"],
171
172 ["instruction", "MOV"],
173 ["variable", "$Temp"],
174 ["punctuation", ","],
175 ["variable", "$Bot"],
176 ["comment", "; Put divisor in $Temp"],
177
178 ["instruction", "CMP"],
179 ["variable", "$Temp"],
180 ["punctuation", ","],
181 ["variable", "$Top"],
182 ["punctuation", ","],
183 " LSR ",
184 ["operator", "#"],
185 ["number", "1"],
186 ["comment", "; double it until"],
187
188 ["number", "90"],
189 ["instruction", "MOVLS"],
190 ["variable", "$Temp"],
191 ["punctuation", ","],
192 ["variable", "$Temp"],
193 ["punctuation", ","],
194 " LSL ",
195 ["operator", "#"],
196 ["number", "1"],
197 ["comment", "; 2 * $Temp > $Top"],
198
199 ["instruction", "CMP"],
200 ["variable", "$Temp"],
201 ["punctuation", ","],
202 ["variable", "$Top"],
203 ["punctuation", ","],
204 " LSR ",
205 ["operator", "#"],
206 ["number", "1"],
207
208 ["instruction", "BLS"],
209 ["operator", "%"],
210 "b90 ",
211 ["comment", "; The b means search backwards"],
212
213 ["directive", "IF"],
214 ["string", [
215 "\"",
216 ["variable", "$Div"],
217 "\""
218 ]],
219 ["operator", "<>"],
220 ["string", ["\"\""]],
221 ["comment", "; Omit next instruction if $Div is null"],
222
223 ["instruction", "MOV"],
224 ["variable", "$Div"],
225 ["punctuation", ","],
226 ["operator", "#"],
227 ["number", "0"],
228 ["comment", "; Initialize quotient"],
229
230 ["directive", "ENDIF"],
231
232 ["number", "91"],
233 ["instruction", "CMP"],
234 ["variable", "$Top"],
235 ["punctuation", ","],
236 ["variable", "$Temp"],
237 ["comment", "; Can we subtract $Temp?"],
238
239 ["instruction", "SUBCS"],
240 ["variable", "$Top"],
241 ["punctuation", ","],
242 ["variable", "$Top"],
243 ["punctuation", ","],
244 ["variable", "$Temp"],
245 ["comment", "; If we can, do so"],
246
247 ["directive", "IF"],
248 ["string", [
249 "\"",
250 ["variable", "$Div"],
251 "\""
252 ]],
253 ["operator", "<>"],
254 ["string", ["\"\""]],
255 ["comment", "; Omit next instruction if $Div is null"],
256
257 ["instruction", "ADC"],
258 ["variable", "$Div"],
259 ["punctuation", ","],
260 ["variable", "$Div"],
261 ["punctuation", ","],
262 ["variable", "$Div"],
263 ["comment", "; Double $Div"],
264
265 ["directive", "ENDIF"],
266
267 ["instruction", "MOV"],
268 ["variable", "$Temp"],
269 ["punctuation", ","],
270 ["variable", "$Temp"],
271 ["punctuation", ","],
272 " LSR ",
273 ["operator", "#"],
274 ["number", "1"],
275 ["comment", "; Halve $Temp,"],
276
277 ["instruction", "CMP"],
278 ["variable", "$Temp"],
279 ["punctuation", ","],
280 ["variable", "$Bot"],
281 ["comment", "; and loop until"],
282
283 ["instruction", "BHS"],
284 ["operator", "%"],
285 "b91 ",
286 ["comment", "; less than divisor"],
287
288 ["directive", "MEND"]
289 ]