stage1_assembler-0.hex0 3.5 KB

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