Debian Codegraph @

Source/DSPSpy/tests/loop_counter_test.ds

raw
1 ; This test checks how LOOP and BLOOP handle their arguments by running loops with the count
2 ; ranging from 0 to 0xffff. The current counter is shown via mail at the top of the screen.
3 ; This test gets slower as the counter gets larger (it runs in O(n^2)).
4 incdir "tests"
5 include "dsp_base.inc"
6
7 test_main:
8 CLR $acc0
9 LRI $ar0, #0
10 LRI $ix0, #0
11 LRI $ar1, #0
12 LRI $ix1, #0
13
14 main_loop:
15 CLR $acc1
16 ; Incrementing $acc1 $ac0.l times sets $acc1 to 1 * $ac0.l, which is just $ac0.l
17 LOOP $ac0.l
18 INC $acc1
19 ; We are now done looping. Check that the results match what we want...
20 CMP
21 JZ check_bloop
22 ; Did not match.
23 IAR $ar0
24 LRI $ix0, #1
25 CALL send_back
26
27 check_bloop:
28 CLR $acc1
29 ; Same deal as above. Here we only have one instruction that is repeated via BLOOP.
30 BLOOP $ac0.l, last_bloop_ins
31 ; TODO: This NOP is needed for things to behave properly; if the last_bloop_ins label
32 ; is immediately after the BLOOP instruction things break on real hardware.
33 ; There's no reason to do this normally though since the LOOP instruction does the same thing
34 ; without needing to provide a label. But it's worth checking eventually (along with how these
35 ; instructions behave when a 2-word long instruction is at the end).
36 NOP
37 last_bloop_ins:
38 INC $acc1
39 ; We are now done looping. Check that the results match what we want...
40 CMP
41 JZ advance_main_loop
42 ; Did not match.
43 IAR $ar1
44 LRI $ix1, #1
45 CALL send_back
46
47 advance_main_loop:
48 ; Report progress as mail
49 SI @DMBH, #0
50 SR @DMBL, $ac0.l
51 SI @DIRQ, #0x0001
52
53 ; Move on to the next value.
54 ; CMPIS (and CMPI) check the middle of the accumulator, so CMPIS $acc0, #1
55 ; checks if the full accumulator is 0x10000 - which is our end point.
56 INC $acc0
57 CMPIS $ac0.m, #1
58 JNZ main_loop
59
60 ; Done with the test. $ar0, $ix0, $ar1, and $ix1 should all be 0.
61 CALL send_back
62
63 ; We're done, DO NOT DELETE THIS LINE
64 JMP end_of_test