Changed BRZ behavior to chomp a test word from stack instead of checking PSW_Z bit.
[ned1] / docs / instruction_reference.md
CommitLineData
bc5b63cf
AT
1NED - Instruction Reference
2===========================
3
4Overview
5--------
6
418f3fc7 7Version: 2
bc5b63cf
AT
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
418f3fc7 214Operation: PC = TOS if NOS = 0
bc5b63cf 215Indicators: None
418f3fc7 216Description: Pops TOS and NOS. If NOS = 0, loads TOS value in to PC.
bc5b63cf
AT
217
218--------------------------------------------------------------------------------
219
220 +----------+---+---+---+---+---+---+
221 | | 5 | 4 | 3 | 2 | 1 | 0 |
222 +----------+---+---+---+---+---+---+
223 | LOAD | 0 | 0 | 0 | 0 | 1 | 0 |
224 +----------+---+---+---+---+---+---+
225
226Operation: TOS = (TOS)
227Indicators: Sets PSW_N and PSW_Z flags.
228Description: Pops TOS, treating it as a pointer in to RAM and pushing the
229 corresponding value from RAM on to TOS.
230
231--------------------------------------------------------------------------------
232
233 +----------+---+---+---+---+---+---+
234 | | 5 | 4 | 3 | 2 | 1 | 0 |
235 +----------+---+---+---+---+---+---+
236 | STORE | 0 | 0 | 0 | 0 | 1 | 1 |
237 +----------+---+---+---+---+---+---+
238
239Operation: (TOS) = NOS
240Indicators: None
241Description: Pops TOS and NOS, treating TOS as a pointer in to RAM and storing
242 NOS at that address.
243
244--------------------------------------------------------------------------------
245
246 +----------+---+---+---+---+---+---+
247 | | 5 | 4 | 3 | 2 | 1 | 0 |
248 +----------+---+---+---+---+---+---+
249 | NOP | 0 | 0 | 0 | 0 | 0 | 1 |
250 +----------+---+---+---+---+---+---+
251
252Operation: None
253Indicators: None
254Description: Does nothing for one CPU cycle.
255
256--------------------------------------------------------------------------------
257
258 +----------+---+---+---+---+---+---+
259 | | 5 | 4 | 3 | 2 | 1 | 0 |
260 +----------+---+---+---+---+---+---+
261 | HALT | 0 | 0 | 0 | 0 | 0 | 0 |
262 +----------+---+---+---+---+---+---+
263
264Operation: None
265Indicators: None
266Description: Halts the CPU.