Updated markdown in Instruction Reference to display as separate paragraphs.
[ned1] / docs / instruction_reference.md
... / ...
CommitLineData
1NED - Instruction Reference
2===========================
3
4Overview
5--------
6
7Version: 2
8
9Format A - Word
10---------------
11
12 +----------+----+-------+
13 | | 31 | 30..0 |
14 +----------+----+-------+
15 | WORD_x | 1 | x..x |
16 +----------+----+-------+
17
18Operation: TOS = x
19
20Indicators: None
21
22Description: Pushes bits 30-0 on to TOS after left shift by one position and
23 padding with zero bit.
24
25Format C - Syllables
26--------------------
27
28 +----------+---+---+---+---+---+---+
29 | | 5 | 4 | 3 | 2 | 1 | 0 |
30 +----------+---+---+---+---+---+---+
31 | IM_x | 1 | x | x | x | x | x |
32 +----------+---+---+---+---+---+---+
33
34Operation: TOS = x
35
36Indicators: None
37
38Description: Pushes bits 4-0 on to TOS while padding bits 31-5 with zeroes.
39
40--------------------------------------------------------------------------------
41
42 +----------+---+---+---+---+---+---+
43 | | 5 | 4 | 3 | 2 | 1 | 0 |
44 +----------+---+---+---+---+---+---+
45 | LDSP+x | 0 | 1 | 1 | x | x | x |
46 +----------+---+---+---+---+---+---+
47
48Operation: TOS = TOS[x]
49
50Indicators: Sets PSW_N and PSW_Z flags.
51
52Description: Pushes a copy of the x'th entry on the stack to the TOS. Indexing
53 begins at 0. Thus, LDSP+0 duplicates the top stack entry and
54 LDSP+1 pushes a copy of the NOS to the TOS.
55
56--------------------------------------------------------------------------------
57
58 +----------+---+---+---+---+---+---+
59 | | 5 | 4 | 3 | 2 | 1 | 0 |
60 +----------+---+---+---+---+---+---+
61 | STSP+x | 0 | 1 | 0 | x | x | x |
62 +----------+---+---+---+---+---+---+
63
64Operation: TOS[x] = TOS
65
66Indicators: None
67
68Description: Pops TOS and stores it x positions deep, overwriting the
69 pre-existing stack entry. Indexing begins at 0 and is counted
70 after popping the TOS. Thus, STSP+0 deletes the NOS, equivalent
71 to SWAP, DROP if such instructions existed.
72
73--------------------------------------------------------------------------------
74
75 +----------+---+---+---+---+---+---+
76 | | 5 | 4 | 3 | 2 | 1 | 0 |
77 +----------+---+---+---+---+---+---+
78 | AND | 0 | 0 | 1 | 0 | 0 | 0 |
79 +----------+---+---+---+---+---+---+
80
81Operation: TOS = TOS ^ NOS
82
83Indicators: Sets PSW_N and PSW_Z flags.
84
85Description: Pops TOS and NOS, performs bitwise Boolean AND and pushes result
86 to TOS.
87
88--------------------------------------------------------------------------------
89
90 +----------+---+---+---+---+---+---+
91 | | 5 | 4 | 3 | 2 | 1 | 0 |
92 +----------+---+---+---+---+---+---+
93 | OR | 0 | 0 | 1 | 0 | 0 | 1 |
94 +----------+---+---+---+---+---+---+
95
96Operation: TOS = TOS V NOS
97
98Indicators: Sets PSW_N and PSW_Z flags.
99
100Description: Pops TOS and NOS, performs bitwise Boolean OR and pushes result
101 to TOS.
102
103--------------------------------------------------------------------------------
104
105 +----------+---+---+---+---+---+---+
106 | | 5 | 4 | 3 | 2 | 1 | 0 |
107 +----------+---+---+---+---+---+---+
108 | NOT | 0 | 0 | 1 | 0 | 1 | 0 |
109 +----------+---+---+---+---+---+---+
110
111Operation: TOS = ~TOS
112
113Indicators: Sets PSW_N and PSW_Z flags.
114
115Description: Pops TOS, performs bitwise Boolean NOT and pushes result to TOS.
116
117--------------------------------------------------------------------------------
118
119 +----------+---+---+---+---+---+---+
120 | | 5 | 4 | 3 | 2 | 1 | 0 |
121 +----------+---+---+---+---+---+---+
122 | XOR | 0 | 0 | 1 | 0 | 1 | 1 |
123 +----------+---+---+---+---+---+---+
124
125Operation: TOS = TOS >< NOS
126
127Indicators: Sets PSW_N and PSW_Z flags.
128
129Description: Pops TOS and NOS, performs bitwise Boolean XOR and pushes result
130 to TOS.
131
132--------------------------------------------------------------------------------
133
134 +----------+---+---+---+---+---+---+
135 | | 5 | 4 | 3 | 2 | 1 | 0 |
136 +----------+---+---+---+---+---+---+
137 | ADD | 0 | 0 | 1 | 1 | 0 | 0 |
138 +----------+---+---+---+---+---+---+
139
140Operation: TOS = TOS + NOS
141
142Indicators: Sets PSW_N and PSW_Z flags.
143
144Description: Pops TOS and NOS, performs signed, twos-complement addition and
145 pushes result to TOS.
146
147--------------------------------------------------------------------------------
148
149 +----------+---+---+---+---+---+---+
150 | | 5 | 4 | 3 | 2 | 1 | 0 |
151 +----------+---+---+---+---+---+---+
152 | SWAP | 0 | 0 | 1 | 1 | 0 | 1 |
153 +----------+---+---+---+---+---+---+
154
155Operation: TOS = NOS; NOS = TOS
156
157Indicators: Sets PSW_N and PSW_Z flags.
158
159Description: Swaps the TOS and NOS entries on the stack. Sets PSW flags based
160 on new TOS entry.
161
162--------------------------------------------------------------------------------
163
164 +----------+---+---+---+---+---+---+
165 | | 5 | 4 | 3 | 2 | 1 | 0 |
166 +----------+---+---+---+---+---+---+
167 | JMP | 0 | 0 | 1 | 1 | 1 | 0 |
168 +----------+---+---+---+---+---+---+
169
170Operation: PC = TOS
171
172Indicators: None
173
174Description: Pops TOS and loads value in to PC, overwriting existing PC. Resets
175 SC to zero.
176
177--------------------------------------------------------------------------------
178
179 +----------+---+---+---+---+---+---+
180 | | 5 | 4 | 3 | 2 | 1 | 0 |
181 +----------+---+---+---+---+---+---+
182 | MVSTCK | 0 | 0 | 1 | 1 | 1 | 1 |
183 +----------+---+---+---+---+---+---+
184
185Operation: SID = TOS
186
187Indicators: None
188
189Description: Pops TOS and loads value in to SID, overwriting existing SID.
190
191--------------------------------------------------------------------------------
192
193 +----------+---+---+---+---+---+---+
194 | | 5 | 4 | 3 | 2 | 1 | 0 |
195 +----------+---+---+---+---+---+---+
196 | SHIFT | 0 | 0 | 0 | 1 | 0 | 0 |
197 +----------+---+---+---+---+---+---+
198
199Operation: TOS = NOS (<< or >>) TOS
200
201Indicators: Sets PSW_N and PSW_Z flags.
202
203Description: Pops TOS and NOS, shifts NOS according to TOS and pushes back to
204 TOS. Direction of shift is left if bit 31 of TOS is set, otherwise
205 shift is right. Magnitude of shift is controlled by bits 30-0 of
206 TOS. Note that this is sign-magnitude, not twos-complement.
207
208--------------------------------------------------------------------------------
209
210 +----------+---+---+---+---+---+---+
211 | | 5 | 4 | 3 | 2 | 1 | 0 |
212 +----------+---+---+---+---+---+---+
213 | CMPSWP | 0 | 0 | 0 | 1 | 0 | 1 |
214 +----------+---+---+---+---+---+---+
215
216Operation:
217
218Indicators:
219
220Description: Not yet implemented.
221
222--------------------------------------------------------------------------------
223
224 +----------+---+---+---+---+---+---+
225 | | 5 | 4 | 3 | 2 | 1 | 0 |
226 +----------+---+---+---+---+---+---+
227 | TEST | 0 | 0 | 0 | 1 | 1 | 0 |
228 +----------+---+---+---+---+---+---+
229
230Operation: None
231
232Indicators: Sets PSW_N and PSW_Z flags.
233
234Description: Pops TOS and sets PSW flags accordingly.
235
236--------------------------------------------------------------------------------
237
238 +----------+---+---+---+---+---+---+
239 | | 5 | 4 | 3 | 2 | 1 | 0 |
240 +----------+---+---+---+---+---+---+
241 | BRZ | 0 | 0 | 0 | 1 | 1 | 1 |
242 +----------+---+---+---+---+---+---+
243
244Operation: PC = TOS if NOS = 0
245
246Indicators: None
247
248Description: Pops TOS and NOS. If NOS = 0, loads TOS value in to PC.
249
250--------------------------------------------------------------------------------
251
252 +----------+---+---+---+---+---+---+
253 | | 5 | 4 | 3 | 2 | 1 | 0 |
254 +----------+---+---+---+---+---+---+
255 | LOAD | 0 | 0 | 0 | 0 | 1 | 0 |
256 +----------+---+---+---+---+---+---+
257
258Operation: TOS = (TOS)
259
260Indicators: Sets PSW_N and PSW_Z flags.
261
262Description: Pops TOS, treating it as a pointer in to RAM and pushing the
263 corresponding value from RAM on to TOS.
264
265--------------------------------------------------------------------------------
266
267 +----------+---+---+---+---+---+---+
268 | | 5 | 4 | 3 | 2 | 1 | 0 |
269 +----------+---+---+---+---+---+---+
270 | STORE | 0 | 0 | 0 | 0 | 1 | 1 |
271 +----------+---+---+---+---+---+---+
272
273Operation: (TOS) = NOS
274
275Indicators: None
276
277Description: Pops TOS and NOS, treating TOS as a pointer in to RAM and storing
278 NOS at that address.
279
280--------------------------------------------------------------------------------
281
282 +----------+---+---+---+---+---+---+
283 | | 5 | 4 | 3 | 2 | 1 | 0 |
284 +----------+---+---+---+---+---+---+
285 | NOP | 0 | 0 | 0 | 0 | 0 | 1 |
286 +----------+---+---+---+---+---+---+
287
288Operation: None
289
290Indicators: None
291
292Description: Does nothing for one CPU cycle.
293
294--------------------------------------------------------------------------------
295
296 +----------+---+---+---+---+---+---+
297 | | 5 | 4 | 3 | 2 | 1 | 0 |
298 +----------+---+---+---+---+---+---+
299 | HALT | 0 | 0 | 0 | 0 | 0 | 0 |
300 +----------+---+---+---+---+---+---+
301
302Operation: None
303
304Indicators: None
305
306Description: Halts the CPU.