-
Notifications
You must be signed in to change notification settings - Fork 0
/
alu.asm
276 lines (228 loc) · 3.23 KB
/
alu.asm
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
; ALU tests
org 0x00
arg1 skip 1
arg2 skip 1
count skip 1
org 0x10
st #-8, count
loop
; Test condition flags
; Testing Zero
clr arg1
jeq arg1, next
halt
next jne arg1, hal
inc arg1
jne arg1, next1
halt
hal halt
hal1 halt
hal2 halt
hal3 halt
hal4 halt
hal5 halt
hal6 halt
hal7 halt
next1 jeq arg1, hal1
; Testing carry
stc
jcs next2
halt
next2 stc
jcc hal2
clc
jcs hal3
stc
jcs next3
halt
next3 clc
jcc next4
halt
; Test negative
next4
st #0x80, arg1
jmi arg1, next5
halt
next5 jpl arg1, hal4
st #0x7F, arg1
jmi arg1, hal5
jpl arg1, next6
halt
; Test even / odd
next6 st #1, arg1
je arg1, hal6
jo arg1, next7
halt
next7 st #0xFE, arg1
jo arg1, hal7
je arg1, next8
halt
hal8 halt
hal9 halt
hal10 halt
hal11 halt
hal12 halt
hal13 halt
hal14 halt
hal15 halt
hal16 halt
hal17 halt
hal18 halt
hal19 halt
hal20 halt
hal21 halt
hal22 halt
hal23 halt
hal24 halt
hal25 halt
hal26 halt
hal27 halt
hal28 halt
hal29 halt
hal30 halt
hal31 halt
hal32 halt
hal33 halt
hal34 halt
hal35 halt
hal36 halt
hal37 halt
hal38 halt
hal39 halt
hal40 halt
hal41 halt
hal42 halt
hal43 halt
hal44 halt
hal45 halt
; Test AND
next8 st #0x55, arg1
andto #0x55, arg1
rsbto #0x55, arg1
jne arg1, hal8
st #0xAA, arg1
andto #0x55, arg1
jne arg1, hal9
st #0xAA, arg1
andto #0xAA, arg1
rsbto #0xAA, arg1
jne arg1, hal10
st #0x55, arg1
andto #0xAA, arg1
jne arg1, hal11
; Test ROR
st #0x55, arg1
stc
ror arg1
rsbto #0xAA, arg1
jne arg1, hal12
st #0xAA, arg1
clc
ror arg1
rsbto #0x55, arg1
jne arg1, hal13
clr arg1
lsro arg1
rsbto #0x80, arg1
jne arg1, hal14
st #0xFF, arg1
lsr arg1
rsbto #0x7F, arg1
jne arg1, hal15
; Test adder
st #0xAA, arg1
addto #0x55, arg1
rsbto #0xFF, arg1
jne arg1, hal16
st #0x55, arg1
addto #0xAA, arg1
rsbto #0xFF, arg1
jne arg1, hal17
st #0x55, arg1
clc
adcto #0x55, arg1
jcs hal18
rsbto #0xAA, arg1
jne arg1, hal19
st #0xAA, arg1
stc
adcto #0xAA, arg1
jcc hal20
rsbto #0x55, arg1
jne arg1, hal21
st #0x00, arg1
stc
adcto #0x01, arg1
rsbto #0x02, arg1
jne arg1, hal22
st #0x01, arg1
stc
adcto #0x00, arg1
rsbto #0x02, arg1
jne arg1, hal23
st #0x01, arg1
addto #0x03, arg1
rsbto #0x04, arg1
jne arg1, hal24
st #0x03, arg1
addto #0x01, arg1
rsbto #0x04, arg1
jne arg1, hal25
st #0x03, arg1
addto #0x07, arg1
rsbto #0x0A, arg1
jne arg1, hal26
st #0x07, arg1
addto #0x03, arg1
rsbto #0x0A, arg1
jne arg1, hal27
st #0x07, arg1
addto #0x0F, arg1
rsbto #0x16, arg1
jne arg1, hal28
st #0x0f, arg1
addto #0x07, arg1
rsbto #0x16, arg1
jne arg1, hal29
st #0x0f, arg1
addto #0x1f, arg1
rsbto #0x2e, arg1
jne arg1, hal30
st #0x1f, arg1
addto #0x0f, arg1
rsbto #0x2e, arg1
jne arg1, hal31
st #0x1f, arg1
addto #0x3f, arg1
rsbto #0x5e, arg1
jne arg1, hal32
st #0x3f, arg1
addto #0x1f, arg1
rsbto #0x5e, arg1
jne arg1, hal33
st #0x3f, arg1
addto #0x7f, arg1
rsbto #0xbe, arg1
jne arg1, hal34
st #0x7f, arg1
addto #0x3f, arg1
rsbto #0xbe, arg1
jne arg1, hal35
st #0x7f, arg1
addto #0xff, arg1
jcc hal36
rsbto #0x7e, arg1
jne arg1, hal37
st #0xff, arg1
addto #0x7f, arg1
jcc hal38
rsbto #0x7e, arg1
jne arg1, hal39
st #0xff, arg1
addto #0xff, arg1
jcc hal40
rsbto #0xfe, arg1
jne arg1, hal41
incjne count, loop
outc #0x50
halt