-
Notifications
You must be signed in to change notification settings - Fork 0
/
apricos.txt
244 lines (174 loc) · 3.82 KB
/
apricos.txt
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
====================
Apricos Architecture
====================
64KB of main address space
256 bytes of stack space (shared with main address space)
8 bit ISA, 16 possible operations.
23 registers:
$ip 16-bit instruction pointer
$mr 16-bit memory address register
$dr 8-bit memory data register
$ir 16-bit instruction register
$ia 8-bit optional instruction argument
$sp 8-bit Stack register (Or stack pointer)
$fr 8-bit CPU status flags register
$a0-15 16 8-bit accumulators
Flags register: [ . . . . O N Z P ]
O = Result overflowed
N = Negative result
Z = Zero result
P = Positive result
=====
ISA
=====
OP Code | Instruction | Description
-----------------------------------------------------------------------------------------
0000 | ADD | Add a value to the currently selected accumulator
0001 | AND | AND a value with the currently selected accumulator
0010 | OR | OR a value with the currently selected accumulator
0011 | XOR | XOR a value with the currently selected accumulator
0100 | NOT | NOT the currently selected accumulator
0101 | SHF | SHIFT the currently selected accumulator either left or right
0110 | LD | Load a value from memory into the currently selected accumulator
0111 | LDI | Load a value from memory using an immediate PC offset
1000 | ST | Store the currently selected accumulator to memory
1001 | STI | Store the currently selected accumulator to memory using an immediate PC offset
1010 | STK | Stack push/pop
1011 | LA | Store an immediate address into the MAR or the currently selected accumulator
1100 | BR | Branch
1101 | PRT | Port I/O
1110 | ASET | Set the current active accumulator
1111 | RESERVED | Reserved opcode
===================
Instruction details
===================
x = don't care
(n) = operand size
$ar = currently selected accumulator
-----
ADD
-----
0000 imm(4)
$ar += imm
-----
AND
-----
0001 imm(4)
$ar &= imm
----
OR
----
0010 imm(4)
$ar |= imm
-----
XOR
-----
0011 imm(4)
$ar ^= imm
-----
NOT
-----
0100 xxxx
$ar = !$ar
-----
SHF
-----
0101 direction(1) count(3)
if direction == 1:
$ar >> count-1
else
$ar << count-1
Note that count is offset by 1.
This means that 00 will correspond to
a shift of 1, 01 to a shift of 2, etc.
----
LD
----
0110 addressWrite(1) writeHigh(1) xx
if addressWrite == 1:
if writeHigh == 1:
$mr |= ($ar << 8)
else
$mr |= ($ar)
else
$ar = memory[$mr]
-----
LDI
-----
0111 xxxx
ipoffset(8)
$ar = memory[$ip + ipoffset]
----
ST
----
1000 addressWrite(1) writeHigh(1) xx
if addressWrite == 1:
if writeHigh == 1:
$mr |= ($ar << 8)
else
$mr |= ($ar)
else
memory[$mr] = $ar
-----
STI
-----
1001 xxxx
ipoffset(8)
memory[$ip + ipoffset] = $ar
-----
STK
-----
1010 pop(1) operation(3)
if pop == 1:
if operation == 100b:
$ar += memory[$sp]
else if operation == 101b:
$ar &= memory[$sp]
else if operation == 110b:
$ar |= memory[$sp]
else if operation == 111b:
$ar ^= memory[$sp]
else:
$ar = memory[$sp]
$sp = $sp - 1
else:
$sp = $sp + 1
memory[$sp] = $ar
-----
LA
-----
1011 loadHigh(1) destination(1) xx
address(8)
if loadHigh == 0:
if destination == 0:
$mr[0-7] = address
else:
$ar = address
else:
if destination == 0:
$mr[8-15] = address
else:
$ar = address
----
BR
----
1100 n(1) z(1) p(1) useImmAddress(1)
immAddress(8)
if (n == 1 && $fr[N] == 1) || (z == 1 && $fr[Z] == 1) || (p == 1 && $fr[P] == 1):
if (!useImmAddress):
$ip = $mr
else:
$ip[0-7] = immAddress
-----
PRT
-----
1101 direction(1) id(3)
if direction == 1
write data to port #id
else
read data from port #id
------
ASET
------
1110 aID(4)
Set the current active accumulator to accumulator #aID