Commit | Line | Data |
---|---|---|
cb6a7127 AC |
1 | ; Test program to tic80 alu operations |
2 | ; compile with tic80-coff-gcc -nostartfiles -nostdlib | |
3 | ||
4 | .macro write string | |
5 | .section .const | |
6 | 1: .ascii "\string\n" | |
7 | 2: | |
8 | .section .text | |
9 | addu 1,r0,r2 ; filedes | |
10 | addu 1b,r0,r4 ; string | |
11 | addu 2b-1b,r0,r6 ; length | |
12 | addu 4,r0,r15 ; write system call # | |
13 | trap 72 | |
14 | .endm | |
15 | ||
16 | .macro expect reg, value, string | |
17 | xor \value,\reg,r19 ; produces r19 == 0 if matches expected value | |
18 | bcnd.a 3f,r19,eq0.w | |
19 | .section .const | |
20 | 1: .ascii "Expected \value for \string\n" | |
21 | 2: | |
22 | .section .text | |
23 | addu 1,r0,r2 ; filedes | |
24 | addu 1b,r0,r4 ; string | |
25 | addu 2b-1b,r0,r6 ; length | |
26 | addu 4,r0,r15 ; write system call # | |
27 | trap 72 | |
28 | ||
29 | ld _errors(r0),r19 | |
30 | addu 1,r19,r19 | |
31 | st _errors(r0),r19 | |
32 | 3: | |
33 | .endm | |
34 | ||
35 | .globl __start | |
36 | .globl _errors | |
37 | .data | |
38 | _errors: | |
39 | .long 0 | |
40 | ||
41 | .text | |
42 | ||
43 | __start: | |
44 | write "Test add" | |
45 | addu 0x12345678,r0,r7 | |
46 | addu 0x12345678,r0,r8 | |
47 | add r7,r8,r9 | |
48 | expect r9,0x2468acf0,"add #1" | |
49 | ||
50 | addu 0x54545478,r0,r8 | |
51 | add 0x0001,r8,r9 | |
52 | expect r9,0x54545479,"add #2" | |
53 | ||
54 | addu 0x12345678,r0,r8 | |
55 | add 0x12345678,r8,r9 | |
56 | expect r9,0x2468acf0,"add #3" | |
57 | ||
58 | ; This will cause overflow | |
59 | ; add 0x789abcde,r8,r9 | |
60 | ; expect r9,0x8acf1356,"add #4" | |
61 | ||
62 | write "Test addu" | |
63 | addu 0x12345678,r0,r7 | |
64 | addu 0x12345678,r0,r8 | |
65 | addu r7,r8,r9 | |
66 | expect r9,0x2468acf0,"addu #1" | |
67 | ||
68 | addu 0x54545478,r0,r8 | |
69 | addu 0x0001,r8,r9 | |
70 | expect r9,0x54545479,"addu #2" | |
71 | ||
72 | addu 0x12345678,r0,r8 | |
73 | addu 0x12345678,r8,r9 | |
74 | expect r9,0x2468acf0,"addu #3" | |
75 | ||
76 | addu 0x789abcde,r8,r9 | |
77 | expect r9,0x8acf1356,"addu #4" | |
78 | ||
79 | write "Test and" | |
80 | addu 0xf,r0,r7 | |
81 | addu 0x12345678,r0,r8 | |
82 | and r7,r8,r9 | |
83 | expect r9,0x8,"and #1" | |
84 | ||
85 | and 0x7fff,r8,r9 | |
86 | expect r9,0x5678,"add #2" | |
87 | ||
88 | and 0xff0000ff,r8,r9 | |
89 | expect r9,0x12000078,"add #3" | |
90 | ||
91 | write "Test and.tt" | |
92 | addu 0xf,r0,r7 | |
93 | addu 0x12345678,r0,r8 | |
94 | and.tt r7,r8,r9 | |
95 | expect r9,0x8,"and.tt #1" | |
96 | ||
97 | and.tt 0x7fff,r8,r9 | |
98 | expect r9,0x5678,"add.tt #2" | |
99 | ||
100 | and.tt 0xff0000ff,r8,r9 | |
101 | expect r9,0x12000078,"add.tt #3" | |
102 | ||
103 | write "Test and.ff" | |
104 | addu 0xf,r0,r7 | |
105 | addu 0x12345678,r0,r8 | |
106 | and.ff r7,r8,r9 | |
107 | expect r9,0xedcba980,"and.ff #1" | |
108 | ||
109 | and.ff 0x7fff,r8,r9 | |
110 | expect r9,0xedcb8000,"add.ff #2" | |
111 | ||
112 | and.ff 0xff0000ff,r8,r9 | |
113 | expect r9,0x00cba900,"add.ff #3" | |
114 | ||
115 | write "Test and.ft" | |
116 | addu 0xf,r0,r7 | |
117 | addu 0x12345678,r0,r8 | |
118 | and.ft r7,r8,r9 | |
119 | expect r9,0x12345670,"and.ft #1" | |
120 | ||
121 | and.ft 0x7fff,r8,r9 | |
122 | expect r9,0x12340000,"add.ft #2" | |
123 | ||
124 | and.ft 0xff0000ff,r8,r9 | |
125 | expect r9,0x00345600,"add.ft #3" | |
126 | ||
127 | write "Test and.tf" | |
128 | addu 0xf,r0,r7 | |
129 | addu 0x12345678,r0,r8 | |
130 | and.tf r7,r8,r9 | |
131 | expect r9,0x7,"and.tf #1" | |
132 | ||
133 | and.tf 0x7fff,r8,r9 | |
134 | expect r9,0x2987,"add.tf #2" | |
135 | ||
136 | and.tf 0xff0000ff,r8,r9 | |
137 | expect r9,0xed000087,"add.tf #3" | |
138 | ||
139 | write "Test cmp" | |
140 | addu 0x12345678,r0,r7 | |
141 | addu 0x54545478,r0,r8 | |
142 | cmp r7,r8,r9 | |
143 | expect r9,0x19a99aa9,"cmp #1" | |
144 | ||
145 | cmp 0xd3c4,r8,r9 | |
146 | expect r9,0x19a96a5a,"cmp #2" | |
147 | ||
148 | cmp 0x54545478,r7,r9 | |
149 | expect r9,0x26666aa9,"cmp #3" | |
150 | ||
151 | cmp 0x13c4,r8,r9 | |
152 | expect r9,0x19a66a5a,"cmp #4" | |
153 | ||
154 | write "Test exts" | |
155 | addu 5,r0,r4 | |
156 | addu 8,r0,r5 | |
157 | addu 0x10203040,r0,r7 | |
158 | exts 5,8,r7,r9 | |
159 | expect r9,0xffffff82,"exts #1" | |
160 | ||
161 | exts r4,8,r7,r9 | |
162 | expect r9,0xffffff82,"exts #2" | |
163 | ||
164 | addu 0x0f0e0d0c,r0,r9 | |
165 | exts 5,8,r9,r7 | |
166 | expect r7,0x00000068,"exts #3" | |
167 | ||
168 | exts r4,8,r9,r7 | |
169 | expect r7,0x00000068,"exts #4" | |
170 | ||
171 | write "Test extu" | |
172 | addu 5,r0,r4 | |
173 | addu 8,r0,r5 | |
174 | addu 0x10203040,r0,r7 | |
175 | extu 5,8,r7,r9 | |
176 | expect r9,0x00000082,"extu #1" | |
177 | ||
178 | extu r4,8,r7,r9 | |
179 | expect r9,0x00000082,"extu #2" | |
180 | ||
181 | addu 0x0f0e0d0c,r0,r9 | |
182 | extu 5,8,r9,r7 | |
183 | expect r7,0x00000068,"extu #3" | |
184 | ||
185 | extu r4,8,r9,r7 | |
186 | expect r7,0x00000068,"extu #4" | |
187 | ||
188 | write "Test ins" | |
189 | addu 4,r0,r4 | |
190 | addu 0x1234567,r0,r7 | |
191 | addu 0xfedcba98,r0,r9 | |
192 | ins 4,11,r7,r9 | |
193 | expect r9,0xfedcbe78,"ins #1" | |
194 | ||
195 | addu 0xfedcba98,r0,r9 | |
196 | ins r4,11,r7,r9 | |
197 | expect r9,0xfedcbe78,"ins #2" | |
198 | ||
199 | addu 0xfedcba98,r0,r9 | |
200 | ins 4,11,r9,r7 | |
201 | expect r7,0x01234187,"ins #3" | |
202 | ||
203 | addu 0x1234567,r0,r7 | |
204 | addu 0xfedcba98,r0,r9 | |
205 | ins r4,11,r9,r7 | |
206 | expect r7,0x01234187,"ins #4" | |
207 | ||
208 | write "Test lmo" | |
209 | addu 0x0089abc,r0,r7 | |
210 | lmo r7,r9 | |
211 | expect r9,0xc,"lmo #1" | |
212 | ||
213 | lmo r0,r9 | |
214 | expect r9,32,"lmo #2" | |
215 | ||
216 | write "Test nop" | |
217 | nop | |
218 | ||
219 | write "Test or" | |
220 | addu 0x0000000f,r0,r7 | |
221 | addu 0x12345678,r0,r8 | |
222 | or r7,r8,r9 | |
223 | expect r9,0x1234567f,"or #1" | |
224 | ||
225 | or 0x7fff,r8,r9 | |
226 | expect r9,0x12347fff,"or #2" | |
227 | ||
228 | or 0xff0000ff,r8,r9 | |
229 | expect r9,0xff3456ff,"or #3" | |
230 | ||
231 | write "Test or.tt" | |
232 | addu 0x0000000f,r0,r7 | |
233 | addu 0x12345678,r0,r8 | |
234 | or.tt r7,r8,r9 | |
235 | expect r9,0x1234567f,"or.tt #1" | |
236 | ||
237 | or.tt 0x7fff,r8,r9 | |
238 | expect r9,0x12347fff,"or.tt #2" | |
239 | ||
240 | or.tt 0xff0000ff,r8,r9 | |
241 | expect r9,0xff3456ff,"or.tt #3" | |
242 | ||
243 | write "Test or.ff" | |
244 | addu 0x0000000f,r0,r7 | |
245 | addu 0x12345678,r0,r8 | |
246 | or.ff r7,r8,r9 | |
247 | expect r9,0xfffffff7,"or.ff #1" | |
248 | ||
249 | or.ff 0x7fff,r8,r9 | |
250 | expect r9,0xffffa987,"or.ff #2" | |
251 | ||
252 | or.ff 0xff0000ff,r8,r9 | |
253 | expect r9,0xedffff87,"or.ff #3" | |
254 | ||
255 | write "Test or.ft" | |
256 | addu 0x0000000f,r0,r7 | |
257 | addu 0x12345678,r0,r8 | |
258 | or.ft r7,r8,r9 | |
259 | expect r9,0xfffffff8,"or.ft #1" | |
260 | ||
261 | or.ft 0x7fff,r8,r9 | |
262 | expect r9,0xffffd678,"or.ft #2" | |
263 | ||
264 | or.ft 0xff0000ff,r8,r9 | |
265 | expect r9,0x12ffff78,"or.ft #3" | |
266 | ||
267 | write "Test or.tf" | |
268 | addu 0x0000000f,r0,r7 | |
269 | addu 0x12345678,r0,r8 | |
270 | or.tf r7,r8,r9 | |
271 | expect r9,0xedcba98f,"or.tf #1" | |
272 | ||
273 | or.tf 0x7fff,r8,r9 | |
274 | expect r9,0xedcbffff,"or.tf #2" | |
275 | ||
276 | or.tf 0xff0000ff,r8,r9 | |
277 | expect r9,0xffcba9ff,"or.tf #3" | |
278 | ||
279 | write "Test rmo" | |
280 | addu 0xdcba9800,r0,r7 | |
281 | rmo r7,r9 | |
282 | expect r9,0x14,"rmo #1" | |
283 | ||
284 | rmo r0,r9 | |
285 | expect r9,32,"rmo #2" | |
286 | ||
287 | write "Test rotl" | |
288 | addu 27,r0,r4 | |
289 | addu 0x1234567,r0,r7 | |
290 | rotl 27,32,r7,r9 | |
291 | expect r9,0x38091a2b,"rotl #1" | |
292 | ||
293 | rotl r4,32,r7,r9 | |
294 | expect r9,0x38091a2b,"rotl #2" | |
295 | ||
296 | write "Test rotr" | |
297 | addu 5,r0,r4 | |
298 | addu 0x1234567,r0,r7 | |
299 | rotr 5,32,r7,r9 | |
300 | expect r9,0x38091a2b,"rotr #1" | |
301 | ||
302 | rotr r4,32,r7,r9 | |
303 | expect r9,0x38091a2b,"rotr #2" | |
304 | ||
305 | write "Test shl" | |
306 | addu 5,r0,r4 | |
307 | addu 0x1234567,r0,r7 | |
308 | shl 5,32,r7,r9 | |
309 | expect r9,0x2468ace0,"shl #1" | |
310 | ||
311 | shl r4,32,r7,r9 | |
312 | expect r9,0x2468ace0,"shl #2" | |
313 | ||
314 | write "Test sl" | |
315 | addu 4,r0,r4 | |
316 | addu 0x1234567,r0,r7 | |
317 | addu 0xfedcba98,r0,r9 | |
318 | sl.im 4,11,r7,r9 | |
319 | expect r9,0xfedcbe78,"sl #1" | |
320 | ||
321 | addu 0xfedcba98,r0,r9 | |
322 | sl.im r4,11,r7,r9 | |
323 | expect r9,0xfedcbe78,"sl #2" | |
324 | ||
325 | addu 0xfedcba98,r0,r9 | |
326 | sl.im 4,11,r9,r7 | |
327 | expect r7,0x01234187,"sl #3" | |
328 | ||
329 | addu 0x1234567,r0,r7 | |
330 | addu 0xfedcba98,r0,r9 | |
331 | sl.im r4,11,r9,r7 | |
332 | expect r7,0x01234187,"sl #4" | |
333 | ||
334 | addu 27,r0,r4 | |
335 | addu 0x1234567,r0,r7 | |
336 | sl.dz 27,32,r7,r9 | |
337 | expect r9,0x38091a2b,"sl #5" | |
338 | ||
339 | sl.dz r4,32,r7,r9 | |
340 | expect r9,0x38091a2b,"sl #6" | |
341 | ||
342 | addu 5,r0,r4 | |
343 | addu 0x1234567,r0,r7 | |
344 | sl.iz 5,32,r7,r9 | |
345 | expect r9,0x2468ace0,"sl #7" | |
346 | ||
347 | sl.iz r4,32,r7,r9 | |
348 | expect r9,0x2468ace0,"sl #8" | |
349 | ||
350 | write "Test sli" | |
351 | addu 4,r0,r4 | |
352 | addu 0x1234567,r0,r7 | |
353 | addu 0xfedcba98,r0,r9 | |
354 | sli.im 4,11,r7,r9 | |
355 | expect r9,0x12345298,"sli #1" | |
356 | ||
357 | addu 0xfedcba98,r0,r9 | |
358 | sli.im r4,11,r7,r9 | |
359 | expect r9,0x12345298,"sli #2" | |
360 | ||
361 | addu 0xfedcba98,r0,r9 | |
362 | sli.im 4,11,r9,r7 | |
363 | expect r7,0xedcbad67,"sli #3" | |
364 | ||
365 | addu 0x1234567,r0,r7 | |
366 | sli.im r4,11,r9,r7 | |
367 | expect r7,0xedcbad67,"sli #4" | |
368 | ||
369 | write "Test sr" | |
370 | addu 5,r0,r4 | |
371 | addu 0x1234567,r0,r7 | |
372 | sr.dz 5,32,r7,r9 | |
373 | expect r9,0x38091a2b,"sr #1" | |
374 | ||
375 | sr.dz r4,32,r7,r9 | |
376 | expect r9,0x38091a2b,"sr #2" | |
377 | ||
378 | addu 5,r0,r4 | |
379 | addu 0x1234567,r0,r7 | |
380 | addu 0xfedcba98,r0,r9 | |
381 | sr.es 5,32,r7,r9 | |
382 | expect r9,0x00091a2b,"sr #3" | |
383 | ||
384 | sr.es r4,32,r7,r9 | |
385 | expect r9,0x00091a2b,"sr #4" | |
386 | ||
387 | addu 0xfedcba98,r0,r9 | |
388 | sr.es 5,32,r9,r7 | |
389 | expect r7,0xfff6e5d4,"sr #5" | |
390 | ||
391 | addu 0x1234567,r0,r7 | |
392 | sr.es r4,32,r9,r7 | |
393 | expect r7,0xfff6e5d4,"sr #6" | |
394 | ||
395 | addu 5,r0,r4 | |
396 | addu 0x1234567,r0,r7 | |
397 | addu 0xfedcba98,r0,r9 | |
398 | sr.ez 5,32,r7,r9 | |
399 | expect r9,0x00091a2b,"sr #7" | |
400 | ||
401 | sr.ez r4,32,r7,r9 | |
402 | expect r9,0x00091a2b,"sr #8" | |
403 | ||
404 | addu 0xfedcba98,r0,r9 | |
405 | sr.ez 5,32,r9,r7 | |
406 | expect r7,0x07f6e5d4,"sr #9" | |
407 | ||
408 | addu 0x1234567,r0,r7 | |
409 | sr.ez r4,32,r9,r7 | |
410 | expect r7,0x07f6e5d4,"sr #10" | |
411 | ||
412 | addu 5,r0,r4 | |
413 | addu 8,r0,r5 | |
414 | addu 0x10203040,r0,r7 | |
415 | sr.ds 5,8,r7,r9 | |
416 | expect r9,0xffffff82,"sr #11" | |
417 | ||
418 | sr.ds r4,8,r7,r9 | |
419 | expect r9,0xffffff82,"sr #12" | |
420 | ||
421 | addu 0x0f0e0d0c,r0,r9 | |
422 | sr.ds 5,8,r9,r7 | |
423 | expect r7,0x00000068,"sr #13" | |
424 | ||
425 | sr.ds r4,8,r9,r7 | |
426 | expect r7,0x00000068,"sr #14" | |
427 | ||
428 | addu 5,r0,r4 | |
429 | addu 8,r0,r5 | |
430 | addu 0x10203040,r0,r7 | |
431 | sr.dz 5,8,r7,r9 | |
432 | expect r9,0x00000082,"sr #15" | |
433 | ||
434 | sr.dz r4,8,r7,r9 | |
435 | expect r9,0x00000082,"sr #16" | |
436 | ||
437 | addu 0x0f0e0d0c,r0,r9 | |
438 | sr.dz 5,8,r9,r7 | |
439 | expect r7,0x00000068,"sr #17" | |
440 | ||
441 | sr.dz r4,8,r9,r7 | |
442 | expect r7,0x00000068,"sr #18" | |
443 | ||
444 | write "Test sra" | |
445 | addu 5,r0,r4 | |
446 | addu 0x1234567,r0,r7 | |
447 | addu 0xfedcba98,r0,r9 | |
448 | sra 5,32,r7,r9 | |
449 | expect r9,0x00091a2b,"sra #1" | |
450 | ||
451 | sra r4,32,r7,r9 | |
452 | expect r9,0x00091a2b,"sra #2" | |
453 | ||
454 | addu 0xfedcba98,r0,r9 | |
455 | sra 5,32,r9,r7 | |
456 | expect r7,0xfff6e5d4,"sra #3" | |
457 | ||
458 | addu 0x1234567,r0,r7 | |
459 | sra r4,32,r9,r7 | |
460 | expect r7,0xfff6e5d4,"sra #4" | |
461 | ||
462 | addu 0xaabbccdd, r0, r4 | |
463 | sra 0,0,r4,r2 | |
464 | expect r2, 0xaabbccdd, "sra #5" | |
465 | ||
466 | write "Test sri" | |
467 | addu 5,r0,r4 | |
468 | addu 0x1234567,r0,r7 | |
469 | addu 0xfedcba98,r0,r9 | |
470 | sri.em 5,11,r7,r9 | |
471 | expect r9,0xf8091a98,"sri #1" | |
472 | ||
473 | sri.em r4,11,r7,r9 | |
474 | expect r9,0xf8091a98,"sri #2" | |
475 | ||
476 | write "Test srl" | |
477 | addu 5,r0,r4 | |
478 | addu 0x1234567,r0,r7 | |
479 | addu 0xfedcba98,r0,r9 | |
480 | srl 5,32,r7,r9 | |
481 | expect r9,0x00091a2b,"srl #1" | |
482 | ||
483 | srl r4,32,r7,r9 | |
484 | expect r9,0x00091a2b,"srl #2" | |
485 | ||
486 | addu 0xfedcba98,r0,r9 | |
487 | srl 5,32,r9,r7 | |
488 | expect r7,0x07f6e5d4,"srl #3" | |
489 | ||
490 | addu 0x1234567,r0,r7 | |
491 | srl r4,32,r9,r7 | |
492 | expect r7,0x07f6e5d4,"srl #4" | |
493 | ||
494 | write "Test sub" | |
495 | addu 0x12345678,r0,r7 | |
496 | addu 0x12345677,r0,r8 | |
497 | sub r7,r8,r9 | |
498 | expect r9,1,"sub #1" | |
499 | ||
500 | addu 1,r0,r8 | |
501 | sub 2,r8,r9 | |
502 | expect r9,1,"sub #2" | |
503 | ||
504 | addu 0x12345677,r0,r8 | |
505 | sub 0x12345678,r8,r9 | |
506 | expect r9,1,"sub #3" | |
507 | ||
508 | ; This overflows | |
509 | ; addu 0,r0,r7 | |
510 | ; addu 0x80000000,r0,r8 | |
511 | ; sub r7,r8,r9 | |
512 | ; expect r9,0x80000000,"sub #4" | |
513 | ||
514 | write "Test subu" | |
515 | addu 0x12345678,r0,r7 | |
516 | addu 0x12345677,r0,r8 | |
517 | subu r7,r8,r9 | |
518 | expect r9,1,"subu #1" | |
519 | ||
520 | addu 1,r0,r8 | |
521 | subu 2,r8,r9 | |
522 | expect r9,1,"subu #2" | |
523 | ||
524 | addu 0x12345677,r0,r8 | |
525 | subu 0x12345678,r8,r9 | |
526 | expect r9,1,"subu #3" | |
527 | ||
528 | addu 0,r0,r7 | |
529 | addu 0x80000000,r0,r8 | |
530 | subu r7,r8,r9 | |
531 | expect r9,0x80000000,"subu #4" | |
532 | ||
533 | write "Test xnor" | |
534 | addu 0xf,r0,r7 | |
535 | addu 0x12345678,r0,r8 | |
536 | xnor r7,r8,r9 | |
537 | expect r9,0xedcba988,"xnor #1" | |
538 | ||
539 | xnor 0x7fff,r8,r9 | |
540 | expect r9,0xedcbd678,"xnor #2" | |
541 | ||
542 | xnor 0xff0000ff,r8,r9 | |
543 | expect r9,0x12cba978,"xnor #3" | |
544 | ||
545 | write "Test xor" | |
546 | addu 0xf,r0,r7 | |
547 | addu 0x12345678,r0,r8 | |
548 | xor r7,r8,r9 | |
549 | expect r9,0x12345677,"xor #1" | |
550 | ||
551 | xor 0x7fff,r8,r9 | |
552 | expect r9,0x12342987,"xor #2" | |
553 | ||
554 | xor 0xff0000ff,r8,r9 | |
555 | expect r9,0xed345687,"xor #3" | |
556 | ||
557 | write "Done" | |
558 | ld _errors(r0),r2 ; # of errors | |
559 | addu 1,r0,r15 ; exit system call number | |
560 | trap 72 | |
561 | ||
562 |