summaryrefslogtreecommitdiff
path: root/stage1/stage1_assembler-0.hex0
blob: 227795af92772276b55feabbb805a631dc777682 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
## Copyright (C) 2016 Jeremiah Orians
## This file is part of stage0.
##
## stage0 is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## stage0 is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with stage0.  If not, see <http://www.gnu.org/licenses/>.

# :start 0
E0002D2B0001    # LOADUI R11 1 ; Our toggle
# ;; R15 is storing our nybble

# ;; Prep TAPE_01
E0002D201100    # LOADUI R0 0x1100
42100000        # FOPEN_READ

# ;; Prep TAPE_02
E0002D201101    # LOADUI R0 0x1101
42100001        # FOPEN_WRITE

E0002D211100    # LOADUI R1 0x1100 ; Read from tape_01

# ;; Main program loop
# ;; Halts when done
# :loop 20
42100100        # FGETC ; Read a Char

# ;; Check for EOF
E0002CC000b8    # JUMP.NP R0 @finish
3C000044        # JUMP @hex ; Convert it

# :loop_1 2e
E0002CC0ffec    # JUMP.NP R0 @loop ; Don't use nonhex chars
E0002C9B000e    # JUMP.Z R11 @loop_2 ; Jump if toggled

# ;; Process first byte of pair
E100B0F0000f    # ANDI R15 R0 0xF ; Store First nibble
0D00002B        # FALSE R11 ; Flip the toggle
3C00ffd8        # JUMP @loop

# :loop_2 48
E0002D5F0004    # SL0I R15 4 ; Shift our first nibble
E100B000000f    # ANDI R0 R0 0xF ; Mask out top
0500000F        # ADD R0 R0 R15 ; Combine nibbles
E0002D1B0001    # LOADI R11 1 ; Flip the toggle
E0002D211101    # LOADUI R1 0x1101 ; Write the combined byte
42100200        # FPUTC ; To TAPE_02
E0002D211100    # LOADUI R1 0x1100 ; Read from tape_01
3C00ffae        # JUMP @loop ; Try to get more bytes

# ;; Hex function
# ;; Converts Ascii chars to their hex values
# ;; Or -1 if not a hex char
# ;; Returns to whatever called it
# :hex 72
# ;; Deal with line comments starting with #
E000A0300023    # CMPSKIPI.NE R0 35
3C000050        # JUMP @ascii_comment
# ;; Deal with line comments starting with ;
E000A030003b    # CMPSKIPI.NE R0 59
3C000046        # JUMP @ascii_comment
# ;; Deal with all ascii less than '0'
E000A0100030    # CMPSKIPI.GE R0 48
3C00004a        # JUMP @ascii_other
# ;; Deal with '0'-'9'
E000A0000039    # CMPSKIPI.G R0 57
3C00001e        # JUMP @ascii_num
# ;; Unset high bit to set everything into uppercase
E100B00000df    # ANDI R0 R0 0xDF
# ;; Deal with all ascii less than 'A'
E000A0100041    # CMPSKIPI.GE R0 65
3C000030        # JUMP @ascii_other
# ;; Deal with 'A'-'F'
E000A0000046    # CMPSKIPI.G R0 70
3C00000e        # JUMP @ascii_high
# ;; Ignore the rest
3C000022        # JUMP @ascii_other

# :ascii_num b8
E10011000030    # SUBUI R0 R0 48
3C00ff6c        # JUMP @loop_1
# :ascii_high c2
E10011000037    # SUBUI R0 R0 55
3C00ff62        # JUMP @loop_1
# :ascii_comment cc
42100100        # FGETC ; Read another char
E000A020000a    # CMPSKIPI.E R0 10 ; Stop at the end of line
3C00fff2        # JUMP @ascii_comment ; Otherwise keep looping
# :ascii_other da
0D000030        # TRUE R0
3C00ff4c        # JUMP @loop_1

# ;; Finish function
# ;; Cleans up at the end of the program
# ;; Performs the HALT
# :finish e2
E0002D201100    # LOADUI R0 0x1100 ; Close TAPE_01
42100002        # FCLOSE
E0002D201101    # LOADUI R0 0x1101 ; Close TAPE_02
42100002        # FCLOSE
FFFFFFFF        # HALT