more.s 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. ; Copyright (C) 2016 Jeremiah Orians
  2. ; This file is part of stage0.
  3. ;
  4. ; stage0 is free software: you can redistribute it and/or modify
  5. ; it under the terms of the GNU General Public License as published by
  6. ; the Free Software Foundation, either version 3 of the License, or
  7. ; (at your option) any later version.
  8. ;
  9. ; stage0 is distributed in the hope that it will be useful,
  10. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ; GNU General Public License for more details.
  13. ;
  14. ; You should have received a copy of the GNU General Public License
  15. ; along with stage0. If not, see <http://www.gnu.org/licenses/>.
  16. :start
  17. LOADUI R2 10 ; We will be using R2 for our counter
  18. ;; Prep TAPE_01
  19. LOADUI R0 0x1100
  20. FOPEN_READ
  21. ;; Main loop of more functionality
  22. ;; Modifies R0, R1 and R2
  23. ;; Does not utilize stack or heap
  24. :main
  25. ;; Read a byte
  26. LOADUI R1 0x1100
  27. FGETC
  28. ;; Check for EOF
  29. CMPSKIPI.GE R0 0
  30. JUMP @main_1
  31. ;; Write the Byte
  32. FALSE R1
  33. FPUTC
  34. ;; Check for LF
  35. CMPSKIPI.NE R0 10 ; Skip if not line feed
  36. SUBI R2 R2 1 ; Decrement on line feed
  37. ;; Loop if not Zero
  38. CMPSKIPI.E R2 0 ; Skip if counter is zero
  39. JUMP @main
  40. ;; Otherwise provide main loop functionality
  41. FGETC ; Wait for key press
  42. LOADUI R2 10 ; Reset counter
  43. JUMP @main ; And loop
  44. :main_1
  45. ;; Close up as we are done
  46. LOADUI R0 0x1100 ; Close TAPE_01
  47. FCLOSE
  48. HALT