summaryrefslogtreecommitdiff
path: root/ascii_array_subdivision.mas
blob: f31f57e1cf2a5861145710c147cb93bcdae5f345 (plain) (blame)
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/ "size: "
load s
output
load i
output
load z
output
load e
output
load colon
output
load space
output

/ input for size of array
input
output
store size
store counter
load newline
output

/ "In char "
accept_character, load I
  output
  load n
  output
  load space
  output
  load c
  output
  load h
  output
  load a
  output
  load r
  output
  load space
  output
  
  / character (s) to fill array
  input
  output
  storei arrai
  load newline
  output
  load arrai
  add one
  store arrai
  load counter
  subt one
  store counter
  skipcond 400
  jump accept_character
  
  / store half size for line splitting
  load size
  store divide_top_to_remainder
  jns divide
  load divide_result
  store half_size
  
  / reset array cursor
  load base
  store arrai
  
  load half_size
  add half_size
  store full_size

print_half, load half_size
  / prime half_size to print half of array
  store counter
_print_half, load counter
  / decrement counter which tracks half array left to prent
  subt one
  store counter
  
  / decrement full_size which tracks characters left to print
  load full_size
  subt one
  store full_size
  
  / print the array character
  loadi arrai
  output
  
  / print a seperator space
  load space
  output
  
  / increment array cursor for next print iteration (if left)
  load arrai
  add one
  store arrai
  
  / print the rest of the characters for the line, if any
  load counter
  skipcond 400
  jump _print_half
  
  / output a new line seperator for next subdivision
  load newline
  output
  
  / if further array exists, print that subdivision
  load full_size
  skipcond 400
  jump print_half

  halt

divide, hex 0
_divide, load divide_result
  / result += 1
  add one
  store divide_result
  
  / remainder -= divisor
  load divide_top_to_remainder
  subt divide_bottom
  store divide_top_to_remainder
  
  / if (AC < 0) { goto _divide; }
  skipcond 000
  jump _divide
  
  / result -= 1
  load divide_result
  subt one
  store divide_result
  
  / remainder += divisor
  load divide_top_to_remainder
  add divide_bottom
  store divide_top_to_remainder
  
  jumpi divide

/ mutable user dependents
arrai, hex 0a0
base, hex 0a0
size, dec 0
half_size, dec 0
full_size, dec 0
counter, dec 0

/ constants and characters
one, dec 1
newline, hex a
space, hex 20
colon, hex 3a
I, hex 49
n, hex 6e
c, hex 63
h, hex 68
a, hex 61
r, hex 72
s, hex 73
i, hex 69
z, hex 7a
e, hex 65

/ division related variables
divide_bottom, dec 2
divide_result, dec 0
divide_top_to_remainder, dec 0