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