loop_counter_test.ds 1.8 KB

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