logic.s
2.89 KB
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
/*
* logic.s Thu Apr 28 16:16:31 PDT 1994
*
* this is a simple RSP program that tests the permutations of
* logic ops that you might want to do...
*
* Puts 'a' in $v1, 'b' in $v2, then does:
*
* elem: a: b: = res:
* 0 0 op 0 ?
* 1 0 op 1 ?
* 2 1 op 0 ?
* 3 1 op 1 ?
*
* When finished, at memory location 0x3000 there will be:
*
* aaaaaaaa aaaaaaaa ........ ........ (vector a)
* bbbbbbbb bbbbbbbb ........ ........ (vector b)
* &&&&&&&& &&&&&&&& ........ ........ (a AND b)
* ~&&&&&&&& ~&&&&&&&& ........ ........ (a NAND b)
* |||||||| |||||||| ........ ........ (a OR b)
* ~|||||||| ~|||||||| ........ ........ (a NOR b)
* ^^^^^^^^ ^^^^^^^^ ........ ........ (a XOR b)
* ~^^^^^^^^ ~^^^^^^^^ ........ ........ (a NXOR b)
*
*/
#
# define some symbolic registers to make this clearer: (I hope)
#
.name a, $v1
.name b, $v2
.name and_res, $v3
.name nand_res, $v4
.name or_res, $v5
.name nor_res, $v6
.name xor_res, $v7
.name nxor_res, $v8
#
# fill a, fill b:
#
addi $20, $0, 0x3000 # where is data?
addi $21, $0, 0x3020 # where is answer
addi $1, $0, 1
addi $0, $0, 0
sh $1, 4($20)
sh $1, 6($20)
sh $1, 18($20)
sh $1, 22($20)
lsc2 $20, a[0]
addi $20, $20, 2
lsc2 $20, a[1]
addi $20, $20, 2
lsc2 $20, a[2]
addi $20, $20, 2
lsc2 $20, a[3]
addi $20, $20, 2
addi $20, $20, 8
lsc2 $20, b[0]
addi $20, $20, 2
lsc2 $20, b[1]
addi $20, $20, 2
lsc2 $20, b[2]
addi $20, $20, 2
lsc2 $20, b[3]
addi $20, $20, 2
addi $20, $20, 8
nop
nop
nop
nop
vand and_res, a, b
ssc2 $20, and_res[0]
addi $20, $20, 2
ssc2 $20, and_res[1]
addi $20, $20, 2
ssc2 $20, and_res[2]
addi $20, $20, 2
ssc2 $20, and_res[3]
addi $20, $20, 2
addi $20, $20, 8
nop
nop
nop
nop
vnand nand_res, a, b
ssc2 $20, nand_res[0]
addi $20, $20, 2
ssc2 $20, nand_res[1]
addi $20, $20, 2
ssc2 $20, nand_res[2]
addi $20, $20, 2
ssc2 $20, nand_res[3]
addi $20, $20, 2
addi $20, $20, 8
nop
nop
nop
nop
vor or_res, a, b
ssc2 $20, or_res[0]
addi $20, $20, 2
ssc2 $20, or_res[1]
addi $20, $20, 2
ssc2 $20, or_res[2]
addi $20, $20, 2
ssc2 $20, or_res[3]
addi $20, $20, 2
addi $20, $20, 8
nop
nop
nop
nop
vnor nor_res, a, b
ssc2 $20, nor_res[0]
addi $20, $20, 2
ssc2 $20, nor_res[1]
addi $20, $20, 2
ssc2 $20, nor_res[2]
addi $20, $20, 2
ssc2 $20, nor_res[3]
addi $20, $20, 2
addi $20, $20, 8
nop
nop
nop
nop
vxor xor_res, a, b
ssc2 $20, xor_res[0]
addi $20, $20, 2
ssc2 $20, xor_res[1]
addi $20, $20, 2
ssc2 $20, xor_res[2]
addi $20, $20, 2
ssc2 $20, xor_res[3]
addi $20, $20, 2
addi $20, $20, 8
nop
nop
nop
nop
vnxor nxor_res, a, b
ssc2 $20, nxor_res[0]
addi $20, $20, 2
ssc2 $20, nxor_res[1]
addi $20, $20, 2
ssc2 $20, nxor_res[2]
addi $20, $20, 2
ssc2 $20, nxor_res[3]
addi $20, $20, 2
addi $20, $20, 8
nop
break
nop