stage1_assembler-0.hex0 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 0
  17. E0002D2B0001 # LOADUI R11 1 ; Our toggle
  18. # ;; R15 is storing our nybble
  19. # ;; Prep TAPE_01
  20. E0002D201100 # LOADUI R0 0x1100
  21. 42100000 # FOPEN_READ
  22. # ;; Prep TAPE_02
  23. E0002D201101 # LOADUI R0 0x1101
  24. 42100001 # FOPEN_WRITE
  25. E0002D211100 # LOADUI R1 0x1100 ; Read from tape_01
  26. # ;; Main program loop
  27. # ;; Halts when done
  28. # :loop 20
  29. 42100100 # FGETC ; Read a Char
  30. # ;; Check for EOF
  31. E0002CC000b8 # JUMP.NP R0 @finish
  32. 3C000044 # JUMP @hex ; Convert it
  33. # :loop_1 2e
  34. E0002CC0ffec # JUMP.NP R0 @loop ; Don't use nonhex chars
  35. E0002C9B000e # JUMP.Z R11 @loop_2 ; Jump if toggled
  36. # ;; Process first byte of pair
  37. E100B0F0000f # ANDI R15 R0 0xF ; Store First nibble
  38. 0D00002B # FALSE R11 ; Flip the toggle
  39. 3C00ffd8 # JUMP @loop
  40. # :loop_2 48
  41. E0002D5F0004 # SL0I R15 4 ; Shift our first nibble
  42. E100B000000f # ANDI R0 R0 0xF ; Mask out top
  43. 0500000F # ADD R0 R0 R15 ; Combine nibbles
  44. E0002D1B0001 # LOADI R11 1 ; Flip the toggle
  45. E0002D211101 # LOADUI R1 0x1101 ; Write the combined byte
  46. 42100200 # FPUTC ; To TAPE_02
  47. E0002D211100 # LOADUI R1 0x1100 ; Read from tape_01
  48. 3C00ffae # JUMP @loop ; Try to get more bytes
  49. # ;; Hex function
  50. # ;; Converts Ascii chars to their hex values
  51. # ;; Or -1 if not a hex char
  52. # ;; Returns to whatever called it
  53. # :hex 72
  54. # ;; Deal with line comments starting with #
  55. E000A0300023 # CMPSKIPI.NE R0 35
  56. 3C000050 # JUMP @ascii_comment
  57. # ;; Deal with line comments starting with ;
  58. E000A030003b # CMPSKIPI.NE R0 59
  59. 3C000046 # JUMP @ascii_comment
  60. # ;; Deal with all ascii less than '0'
  61. E000A0100030 # CMPSKIPI.GE R0 48
  62. 3C00004a # JUMP @ascii_other
  63. # ;; Deal with '0'-'9'
  64. E000A0000039 # CMPSKIPI.G R0 57
  65. 3C00001e # JUMP @ascii_num
  66. # ;; Unset high bit to set everything into uppercase
  67. E100B00000df # ANDI R0 R0 0xDF
  68. # ;; Deal with all ascii less than 'A'
  69. E000A0100041 # CMPSKIPI.GE R0 65
  70. 3C000030 # JUMP @ascii_other
  71. # ;; Deal with 'A'-'F'
  72. E000A0000046 # CMPSKIPI.G R0 70
  73. 3C00000e # JUMP @ascii_high
  74. # ;; Ignore the rest
  75. 3C000022 # JUMP @ascii_other
  76. # :ascii_num b8
  77. E10011000030 # SUBUI R0 R0 48
  78. 3C00ff6c # JUMP @loop_1
  79. # :ascii_high c2
  80. E10011000037 # SUBUI R0 R0 55
  81. 3C00ff62 # JUMP @loop_1
  82. # :ascii_comment cc
  83. 42100100 # FGETC ; Read another char
  84. E000A020000a # CMPSKIPI.E R0 10 ; Stop at the end of line
  85. 3C00fff2 # JUMP @ascii_comment ; Otherwise keep looping
  86. # :ascii_other da
  87. 0D000030 # TRUE R0
  88. 3C00ff4c # JUMP @loop_1
  89. # ;; Finish function
  90. # ;; Cleans up at the end of the program
  91. # ;; Performs the HALT
  92. # :finish e2
  93. E0002D201100 # LOADUI R0 0x1100 ; Close TAPE_01
  94. 42100002 # FCLOSE
  95. E0002D201101 # LOADUI R0 0x1101 ; Close TAPE_02
  96. 42100002 # FCLOSE
  97. FFFFFFFF # HALT