@nataliapc/mcp-openmsx 1.1.5 → 1.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -2
- package/dist/openmsx.js +9 -0
- package/dist/server.js +502 -327
- package/dist/utils.js +17 -0
- package/package.json +4 -1
- package/resources/audio/toc.json +31 -0
- package/resources/bios/Calling_BIOS_from_MSX-DOS.md +75 -0
- package/resources/bios/MSX2_SUBROM_BIOS_calls.md +734 -0
- package/resources/bios/MSX_BIOS_calls.md +1046 -0
- package/resources/bios/toc.json +24 -0
- package/resources/book--msx2-technical-handbook/Appendix1__BIOS_Listing.md +1464 -0
- package/resources/book--msx2-technical-handbook/Appendix2__Math-Pack.md +427 -0
- package/resources/book--msx2-technical-handbook/Appendix3__Bit_Block_Transfer.md +182 -0
- package/resources/book--msx2-technical-handbook/Appendix4__Work_Area_Listing.md +1637 -0
- package/resources/book--msx2-technical-handbook/Appendix5__VRAM_Map.md +145 -0
- package/resources/book--msx2-technical-handbook/Appendix6__IO_Map.md +128 -0
- package/resources/book--msx2-technical-handbook/Appendix8_10__Control_Codes_and_Escape_Sequences.md +76 -0
- package/resources/book--msx2-technical-handbook/Chapter1__MSX_System_Overview.md +402 -0
- package/resources/book--msx2-technical-handbook/Chapter2__BASIC.md +2148 -0
- package/resources/book--msx2-technical-handbook/Chapter3__MSX-DOS.md +2577 -0
- package/resources/book--msx2-technical-handbook/Chapter4a__VDP_and_Display_Screen.md +2052 -0
- package/resources/book--msx2-technical-handbook/Chapter4b__VDP_and_Display_Screen.md +3311 -0
- package/resources/book--msx2-technical-handbook/Chapter5a__Access_to_Peripherals_through_BIOS.md +2714 -0
- package/resources/book--msx2-technical-handbook/Chapter5b__Access_to_Peripherals_through_BIOS.md +1263 -0
- package/resources/book--msx2-technical-handbook/MSX_Kun_BASIC_Compiler.md +220 -0
- package/resources/book--msx2-technical-handbook/toc.json +82 -0
- package/resources/book--the-msx-red-book/the_msx_red_book.md +10349 -0
- package/resources/book--the-msx-red-book/toc.json +12 -0
- package/resources/msx-dos/MSX-DOS_2_Function_Specifications.md +1366 -0
- package/resources/msx-dos/MSX-DOS_2_Program_Interface_Specification.md +963 -0
- package/resources/msx-dos/toc.json +18 -0
- package/resources/msx-unapi/Ethernet_UNAPI_specification_1.1.md +369 -0
- package/resources/msx-unapi/Introduction_to_MSX-UNAPI.md +132 -0
- package/resources/msx-unapi/MSX_UNAPI_specification_1.1.md +679 -0
- package/resources/msx-unapi/TCP-IP_UNAPI_specification.md +2361 -0
- package/resources/msx-unapi/toc.json +27 -0
- package/resources/others/toc.json +11 -0
- package/resources/processors/Z80_R800_instruction_set.md +482 -0
- package/resources/processors/toc.json +24 -0
- package/resources/processors/z80-undocumented.tex +5617 -0
- package/resources/processors/z80_detailed_instruction_set.md +2025 -0
- package/resources/programming/toc.json +121 -0
- package/resources/system/MSX_IO_ports_overview.md +554 -0
- package/resources/system/toc.json +18 -0
- package/resources/video/V9938_Technical_Data_Book.md +3623 -0
- package/resources/video/V9958_Technical_Data_Book.md +417 -0
- package/resources/video/V9990_Programmers_Manual_Banzai.html +1582 -0
- package/resources/video/VDP_TMS9918A.txt +709 -0
- package/resources/video/toc.json +28 -0
|
@@ -0,0 +1,2025 @@
|
|
|
1
|
+
# Z80 detailed instruction set
|
|
2
|
+
|
|
3
|
+
Source: [Z80 Heaven](http://z80-heaven.wikidot.com/instructions-set)
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
## ADC
|
|
7
|
+
The sum of the two operands plus the carry flag (0 or 1) is calculated, and the result is written back into the first operand.
|
|
8
|
+
|
|
9
|
+
### Syntax
|
|
10
|
+
adc a,op8 ;8 bit
|
|
11
|
+
adc hl,op16 ;16 bit
|
|
12
|
+
|
|
13
|
+
#### Allowed instructions
|
|
14
|
+
adc a,a
|
|
15
|
+
adc a,b
|
|
16
|
+
adc a,c
|
|
17
|
+
adc a,d
|
|
18
|
+
adc a,e
|
|
19
|
+
adc a,h
|
|
20
|
+
adc a,l
|
|
21
|
+
adc a,ixh
|
|
22
|
+
adc a,ixl
|
|
23
|
+
adc a,iyh
|
|
24
|
+
adc a,iyl
|
|
25
|
+
adc a,(hl)
|
|
26
|
+
adc a,(ix+n)
|
|
27
|
+
adc a,(iy+n)
|
|
28
|
+
adc a,n ;(8-bit number)
|
|
29
|
+
|
|
30
|
+
adc hl,bc
|
|
31
|
+
adc hl,de
|
|
32
|
+
adc hl,hl
|
|
33
|
+
adc hl,sp
|
|
34
|
+
|
|
35
|
+
### Effects
|
|
36
|
+
The `N` flag is reset, `P/V` is interpreted as overflow. The rest of the flags is modified by definition. In the case of 16-bit addition the `H` flag is undefined.
|
|
37
|
+
|
|
38
|
+
### Uses
|
|
39
|
+
Multiple precision adding
|
|
40
|
+
|
|
41
|
+
### T-States
|
|
42
|
+
`r` denotes 8-bit register.
|
|
43
|
+
`rr` represents a two byte register pair: `BC`, `DE`, `HL`, `SP`
|
|
44
|
+
|
|
45
|
+
a, r 4
|
|
46
|
+
a, X 7
|
|
47
|
+
a, (hl) 7
|
|
48
|
+
a, (ix+X) 19
|
|
49
|
+
a, (iy+X) 19
|
|
50
|
+
hl, rr 15
|
|
51
|
+
|
|
52
|
+
### See also
|
|
53
|
+
[ADD](#add), [DAA](#daa), [DEC](#dec), [INC](#inc), [SBC](#sbc), [SUB](#sub)
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
## ADD
|
|
57
|
+
The values of the two operands are added together, and the result is written back to the first one.
|
|
58
|
+
|
|
59
|
+
### Syntax
|
|
60
|
+
add a,op8 ;8 bits
|
|
61
|
+
add op16,op16 ;16 bits
|
|
62
|
+
|
|
63
|
+
#### Allowed instructions
|
|
64
|
+
add a,a
|
|
65
|
+
add a,b
|
|
66
|
+
add a,c
|
|
67
|
+
add a,d
|
|
68
|
+
add a,e
|
|
69
|
+
add a,h
|
|
70
|
+
add a,l
|
|
71
|
+
add a,ixh
|
|
72
|
+
add a,ixl
|
|
73
|
+
add a,iyh
|
|
74
|
+
add a,ixl
|
|
75
|
+
add a,(hl)
|
|
76
|
+
add a,(ix+n)
|
|
77
|
+
add a,(iy+n)
|
|
78
|
+
add a,n ;8-bit constant
|
|
79
|
+
|
|
80
|
+
add hl,bc
|
|
81
|
+
add hl,de
|
|
82
|
+
add hl,hl
|
|
83
|
+
add hl,sp
|
|
84
|
+
|
|
85
|
+
add ix,bc
|
|
86
|
+
add ix,de
|
|
87
|
+
add ix,ix
|
|
88
|
+
add ix,sp
|
|
89
|
+
|
|
90
|
+
add iy,bc
|
|
91
|
+
add iy,de
|
|
92
|
+
add iy,iy
|
|
93
|
+
add iy,sp
|
|
94
|
+
|
|
95
|
+
### Effects
|
|
96
|
+
#### 8-bit arithmetic
|
|
97
|
+
`N` flag is reset, `P/V` is interpreted as overflow.
|
|
98
|
+
Rest of flags modified by definition.
|
|
99
|
+
|
|
100
|
+
#### 16-bit arithmetic
|
|
101
|
+
preserves the `S`, `Z` and `P/V` flags, and `H` is undefined.
|
|
102
|
+
Rest of flags modified by definition.
|
|
103
|
+
|
|
104
|
+
### Uses
|
|
105
|
+
Obviously used to add two numbers together. However, you can add 16-bit numbers to sp, giving you control of where the stack pointer is pointing to.
|
|
106
|
+
|
|
107
|
+
### T-States
|
|
108
|
+
`r` denotes 8-bit register.
|
|
109
|
+
`rr` represents a two byte register pair: BC, DE, HL, SP
|
|
110
|
+
|
|
111
|
+
r 4
|
|
112
|
+
X 7
|
|
113
|
+
(hl) 7
|
|
114
|
+
(ix+X) 19
|
|
115
|
+
(iy+X) 19
|
|
116
|
+
hl, rr 11
|
|
117
|
+
ix, rr 15
|
|
118
|
+
iy, rr 15
|
|
119
|
+
|
|
120
|
+
### See Also
|
|
121
|
+
[ADC](#adc), [DAA](#daa), [DEC](#dec), [INC](#inc), [SBC](#sbc), [SUB](#sub)
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
## AND
|
|
125
|
+
`AND` is an instruction that takes an 8-bit input an compares it with the accumulator. It checks to see if both are set. If either one is reset, the resulting bit in the accumulator is zero.
|
|
126
|
+
|
|
127
|
+
0 and 0 result: 0
|
|
128
|
+
0 and 1 result: 0
|
|
129
|
+
1 and 0 result: 0
|
|
130
|
+
1 and 1 result: 1
|
|
131
|
+
|
|
132
|
+
### Syntax
|
|
133
|
+
and op8
|
|
134
|
+
|
|
135
|
+
#### Allowed Instructions
|
|
136
|
+
and a
|
|
137
|
+
and b
|
|
138
|
+
and c
|
|
139
|
+
and d
|
|
140
|
+
and e
|
|
141
|
+
and h
|
|
142
|
+
and l
|
|
143
|
+
and ixh
|
|
144
|
+
and ixl
|
|
145
|
+
and iyh
|
|
146
|
+
and iyl
|
|
147
|
+
and (hl)
|
|
148
|
+
and (ix+n)
|
|
149
|
+
and (iy+n)
|
|
150
|
+
and n ;8 bit constant
|
|
151
|
+
|
|
152
|
+
### Effects
|
|
153
|
+
`C` and `N` flags cleared, `P/V` is parity, rest are altered by definition.
|
|
154
|
+
|
|
155
|
+
### Uses
|
|
156
|
+
The most important use of `AND` is in bit-masking. For more information on bit-masking, see here.
|
|
157
|
+
|
|
158
|
+
### T-States
|
|
159
|
+
`r` denotes 8-bit register.
|
|
160
|
+
|
|
161
|
+
r 4
|
|
162
|
+
X 7
|
|
163
|
+
(l) 7
|
|
164
|
+
(x+X) 19
|
|
165
|
+
(y+X) 19
|
|
166
|
+
|
|
167
|
+
### See Also
|
|
168
|
+
[BIT](#bit), [CCF](#ccf), [CPL](#cpl), [OR](#or), [RES](#res), [SCF](#scf), [SET](#set) ,[XOR](#xor)
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
## BIT
|
|
172
|
+
Tests if the specified bit is set.
|
|
173
|
+
|
|
174
|
+
### Syntax
|
|
175
|
+
bit n,op8
|
|
176
|
+
|
|
177
|
+
#### Allowed Instructions
|
|
178
|
+
`n` can be any integer from [0,7]. It must be defined on compile time.
|
|
179
|
+
|
|
180
|
+
bit n,a
|
|
181
|
+
bit n,b
|
|
182
|
+
bit n,c
|
|
183
|
+
bit n,d
|
|
184
|
+
bit n,e
|
|
185
|
+
bit n,h
|
|
186
|
+
bit n,l
|
|
187
|
+
bit n,(hl)
|
|
188
|
+
bit n,(ix+n)
|
|
189
|
+
bit n,(iy+n)
|
|
190
|
+
|
|
191
|
+
### Effects
|
|
192
|
+
Opposite of the n<sup>th</sup> bit is written into the `Z` flag. `C` is preserved, `N` is reset, `H` is set, and `S` and `P/V` are undefined.
|
|
193
|
+
|
|
194
|
+
ld a,%00000001
|
|
195
|
+
bit 0,a ;would reset Z
|
|
196
|
+
bit 1,a ;would set Z
|
|
197
|
+
|
|
198
|
+
### T-States
|
|
199
|
+
`r` denotes 8-bit register.
|
|
200
|
+
|
|
201
|
+
r 8
|
|
202
|
+
(hl) 12
|
|
203
|
+
(ix+X) 20
|
|
204
|
+
(iy+X) 20
|
|
205
|
+
|
|
206
|
+
### See Also
|
|
207
|
+
[AND](#and), [CCF](#ccf), [CP](#cp), [CPD](#cpd), [CPDR](#cpdr), [CPI](#cpi), [CPIR](#cpir), [CPL](#cpl), [OR](#or), [RES](#res), [SCF](#scf), [SET](#set), [XOR](#xor)
|
|
208
|
+
|
|
209
|
+
---
|
|
210
|
+
## CALL
|
|
211
|
+
Pushes the address after the `CALL` instruction (`PC`+3) onto the stack and jumps to the label. Can also take conditions.
|
|
212
|
+
|
|
213
|
+
### Syntax
|
|
214
|
+
call label ;unconditional call
|
|
215
|
+
call cond.,label ;conditional call
|
|
216
|
+
|
|
217
|
+
#### Allowed Instructions
|
|
218
|
+
call label ;always calls
|
|
219
|
+
|
|
220
|
+
call c,label ;calls if C flag is set
|
|
221
|
+
call nc,label ;calls if C flag is reset
|
|
222
|
+
|
|
223
|
+
call z,label ;calls if Z flag is set
|
|
224
|
+
call nz,label ;calls if Z flag is reset
|
|
225
|
+
|
|
226
|
+
call m,label ;calls if S flag is set
|
|
227
|
+
call p,label ;calls if S flag is reset
|
|
228
|
+
|
|
229
|
+
call pe,label ;calls if P/V is set
|
|
230
|
+
call po,label ;calls if P/V is reset
|
|
231
|
+
|
|
232
|
+
### Effects
|
|
233
|
+
Flags are preserved.
|
|
234
|
+
|
|
235
|
+
### Uses
|
|
236
|
+
The most common use of `CALL` is to create routines that can be used multiple times.
|
|
237
|
+
|
|
238
|
+
### T-States
|
|
239
|
+
`cc` is condition: `NZ`, `Z`, `NC`, `C`, `PO`, `PE`, `P`, `M`
|
|
240
|
+
|
|
241
|
+
XX 17
|
|
242
|
+
condition-true condition-false
|
|
243
|
+
cc,XX 17 10
|
|
244
|
+
|
|
245
|
+
### See Also
|
|
246
|
+
[BIT](#bit), [CP](#cp), [CPD](#cpd), [CPDR](#cpdr), [CPI](#cpi), [CPIR](#cpir), [DJNZ](#djnz), [JP](#jp), [JR](#jr), [RET](#ret)
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
## CCF
|
|
250
|
+
Inverts the carry flag.
|
|
251
|
+
|
|
252
|
+
### Syntax
|
|
253
|
+
ccf
|
|
254
|
+
|
|
255
|
+
### Effects
|
|
256
|
+
Carry flag inverted. Also inverts `H` and clears `N`. Rest of the flags are preserved.
|
|
257
|
+
|
|
258
|
+
### T-States
|
|
259
|
+
4 t-states
|
|
260
|
+
|
|
261
|
+
### See Also
|
|
262
|
+
[SCF](#scf)
|
|
263
|
+
|
|
264
|
+
---
|
|
265
|
+
## CP
|
|
266
|
+
CP is a subtraction from A that doesn't update A, only the flags it would have set/reset if it really was subtracted.
|
|
267
|
+
|
|
268
|
+
### Syntax
|
|
269
|
+
cp op8
|
|
270
|
+
|
|
271
|
+
`op8` is any one of the allowed inputs.
|
|
272
|
+
|
|
273
|
+
#### Allowed instructions
|
|
274
|
+
cp a
|
|
275
|
+
cp b
|
|
276
|
+
cp c
|
|
277
|
+
cp d
|
|
278
|
+
cp e
|
|
279
|
+
cp h
|
|
280
|
+
cp l
|
|
281
|
+
cp ixh
|
|
282
|
+
cp ixl
|
|
283
|
+
cp iyh
|
|
284
|
+
cp iyl
|
|
285
|
+
cp (hl)
|
|
286
|
+
cp (ix+n)
|
|
287
|
+
cp (iy+n)
|
|
288
|
+
cp n ;8 bit constant
|
|
289
|
+
|
|
290
|
+
### Effects
|
|
291
|
+
`C`, `S`, and `Z` flags modified by definition
|
|
292
|
+
`P/V` detects overflow
|
|
293
|
+
|
|
294
|
+
### Uses
|
|
295
|
+
Here are some general rules on using `CP`:
|
|
296
|
+
|
|
297
|
+
#### Unsigned
|
|
298
|
+
If A == N, then `Z` flag is set.
|
|
299
|
+
If A != N, then `Z` flag is reset.
|
|
300
|
+
If A < N, then `C` flag is set.
|
|
301
|
+
If A >= N, then `C` flag is reset.
|
|
302
|
+
|
|
303
|
+
#### Signed
|
|
304
|
+
If A == N, then `Z` flag is set.
|
|
305
|
+
If A != N, then `Z` flag is reset.
|
|
306
|
+
If A < N, then `S` and `P/V` are different.
|
|
307
|
+
If A >= N, then `S` and `P/V` are the same.
|
|
308
|
+
|
|
309
|
+
### T-States
|
|
310
|
+
`r` denotes 8-bit register.
|
|
311
|
+
|
|
312
|
+
r 4
|
|
313
|
+
X 7
|
|
314
|
+
(hl) 7
|
|
315
|
+
(ix+X) 19
|
|
316
|
+
(iy+X) 19
|
|
317
|
+
|
|
318
|
+
### See also
|
|
319
|
+
[BIT](#bit), [CALL](#call), [CPD](#cpd), [CPDR](#cpdr), [CPI](#cpi), [CPIR](#cpir), [JP](#jp), [JR](#jr), [RET](#ret)
|
|
320
|
+
|
|
321
|
+
---
|
|
322
|
+
## CPD
|
|
323
|
+
Multiple instructions combined into one. `CPD` does these things in this order:
|
|
324
|
+
|
|
325
|
+
CP (HL)
|
|
326
|
+
DEC HL
|
|
327
|
+
DEC BC
|
|
328
|
+
|
|
329
|
+
### Syntax
|
|
330
|
+
No operands.
|
|
331
|
+
|
|
332
|
+
cpd
|
|
333
|
+
|
|
334
|
+
### Effects
|
|
335
|
+
The carry is preserved, `N` is set and all the other flags are affected as defined. `P/V` denotes the overflowing of `BC`, while the `Z` flag is set if `A`=`(HL)` before `HL` is decreased.
|
|
336
|
+
|
|
337
|
+
### Uses
|
|
338
|
+
See [`CPDR`](#cpdr) for potential uses.
|
|
339
|
+
|
|
340
|
+
### See Also
|
|
341
|
+
[BIT](#bit), [CALL](#call), [CP](#cp), [CPDR](#cpdr), [CPI](#cpi), [CPIR](#cpir), [JP](#jp), [JR](#jr)
|
|
342
|
+
|
|
343
|
+
---
|
|
344
|
+
## CPDR
|
|
345
|
+
Repeats `CPD` until either:
|
|
346
|
+
|
|
347
|
+
BC=0
|
|
348
|
+
A=(HL)
|
|
349
|
+
|
|
350
|
+
### Syntax
|
|
351
|
+
No operands.
|
|
352
|
+
|
|
353
|
+
cpdr
|
|
354
|
+
|
|
355
|
+
### Effects
|
|
356
|
+
The carry is preserved, `N` is set and all the other flags are affected as defined. `P/V` denotes the overflowing of `BC`, while the `Z` flag is set if `A`=`(HL)` before `HL` is decreased.
|
|
357
|
+
|
|
358
|
+
### Uses
|
|
359
|
+
Say you want to find the last occurrence of 124 in the valid memory space:
|
|
360
|
+
|
|
361
|
+
LD HL,0000h
|
|
362
|
+
LD BC,0000h
|
|
363
|
+
LD A,124
|
|
364
|
+
CPDR
|
|
365
|
+
|
|
366
|
+
_Note: if you used CPIR it would find the first occurrence of 124 in the valid memory space._
|
|
367
|
+
|
|
368
|
+
### T-States
|
|
369
|
+
BC ≠ 0 and A ≠ (HL) 21
|
|
370
|
+
BC = 0 or A = (HL) 16
|
|
371
|
+
|
|
372
|
+
### See Also
|
|
373
|
+
[BIT](#bit), [CALL](#call), [CP](#cp), [CPD](#cpd), [CPI](#cpi), [CPIR](#cpir), [JP](#jp), [JR](#jr)
|
|
374
|
+
|
|
375
|
+
---
|
|
376
|
+
## CPI
|
|
377
|
+
Multiple instructions combined into one. `CPI` does these things in this order:
|
|
378
|
+
|
|
379
|
+
CP (HL)
|
|
380
|
+
INC HL
|
|
381
|
+
DEC BC
|
|
382
|
+
|
|
383
|
+
### Syntax
|
|
384
|
+
No operands.
|
|
385
|
+
|
|
386
|
+
cpi
|
|
387
|
+
|
|
388
|
+
### Effects
|
|
389
|
+
The carry is preserved, `N` is set and all the other flags are affected as defined. `P/V` denotes the overflowing of `BC`, while the `Z` flag is set if `A`=`(HL)` before `HL` is decreased.
|
|
390
|
+
|
|
391
|
+
### Uses
|
|
392
|
+
See [`CPIR`](#cpir) for one example use.
|
|
393
|
+
|
|
394
|
+
### T-States
|
|
395
|
+
16 t-states
|
|
396
|
+
|
|
397
|
+
### See Also
|
|
398
|
+
[BIT](#bit), [CALL](#call), [CP](#cp), [CPD](#cpd), [CPDR](#cpdr), [CPIR](#cpir), [JP](#jp), [JR](#jr)
|
|
399
|
+
|
|
400
|
+
---
|
|
401
|
+
## CPIR
|
|
402
|
+
Repeats `CPI` until either:
|
|
403
|
+
|
|
404
|
+
BC=0
|
|
405
|
+
A=(HL)
|
|
406
|
+
|
|
407
|
+
### Syntax
|
|
408
|
+
No operands.
|
|
409
|
+
|
|
410
|
+
cpir
|
|
411
|
+
|
|
412
|
+
### Effects
|
|
413
|
+
The carry is preserved, `N` is set and all the other flags are affected as defined. `P/V` denotes the overflowing of `BC`, while the `Z` flag is set if `A`=`(HL)` before `HL` is decreased.
|
|
414
|
+
|
|
415
|
+
### Uses
|
|
416
|
+
If you want to find the first occurrence of 124 in the valid memory space:
|
|
417
|
+
|
|
418
|
+
LD HL,0000h
|
|
419
|
+
LD BC,0000h
|
|
420
|
+
LD A,124
|
|
421
|
+
CPIR
|
|
422
|
+
|
|
423
|
+
_Note: if you used CPDR it would find the last occurrence of 124 in the valid memory space._
|
|
424
|
+
|
|
425
|
+
### T-States
|
|
426
|
+
BC ≠ 0 and A ≠ (HL) 21
|
|
427
|
+
BC = 0 or A = (HL) 16
|
|
428
|
+
|
|
429
|
+
### See Also
|
|
430
|
+
[BIT](#bit), [CALL](#call), [CP](#cp), [CPD](#cpd), [CPDR](#cpdr), [CPI](#cpi), [JP](#jp), [JR](#jr)
|
|
431
|
+
|
|
432
|
+
---
|
|
433
|
+
## CPL
|
|
434
|
+
CPL inverts all bits of A.
|
|
435
|
+
|
|
436
|
+
### Syntax
|
|
437
|
+
cpl
|
|
438
|
+
|
|
439
|
+
### Effects
|
|
440
|
+
Sets `H` and `N`, other flags are unmodified.
|
|
441
|
+
|
|
442
|
+
### Uses
|
|
443
|
+
This instruction returns the same value as XORing A with $FF or subtracting A from $FF.
|
|
444
|
+
Also, `CPL` \ `INC A` returns the same value that `NEG` does.
|
|
445
|
+
|
|
446
|
+
### T-States
|
|
447
|
+
4 t-states
|
|
448
|
+
|
|
449
|
+
### See Also
|
|
450
|
+
[NEG](#neg), [XOR](#xor)
|
|
451
|
+
|
|
452
|
+
---
|
|
453
|
+
## DAA
|
|
454
|
+
When this instruction is executed, the `A` register is BCD corrected using the contents of the flags. The exact process is the following: if the least significant four bits of `A` contain a non-BCD digit (i. e. it is greater than 9) or the `H` flag is set, then $06 is added to the register. Then the four most significant bits are checked. If this more significant digit also happens to be greater than 9 or the `C` flag is set, then $60 is added.
|
|
455
|
+
|
|
456
|
+
### Syntax
|
|
457
|
+
dda
|
|
458
|
+
|
|
459
|
+
### Effects
|
|
460
|
+
If the second addition was needed, the `C` flag is set after execution, otherwise it is reset. The `N` flag is preserved, `P/V` is parity and the others are altered by definition.
|
|
461
|
+
|
|
462
|
+
### T-States
|
|
463
|
+
4 t-states
|
|
464
|
+
|
|
465
|
+
### See Also
|
|
466
|
+
[ADC](#adc), [ADD](#add), [DEC](#dec), [INC](#inc), [SBC](#sbc), [SUB](#sub)
|
|
467
|
+
|
|
468
|
+
---
|
|
469
|
+
## DEC
|
|
470
|
+
Decreases operand by one.
|
|
471
|
+
|
|
472
|
+
### Syntax
|
|
473
|
+
dec op8 ;8 bits
|
|
474
|
+
dec op16 ;16 bits
|
|
475
|
+
|
|
476
|
+
#### Allowed Instructions
|
|
477
|
+
dec a
|
|
478
|
+
dec b
|
|
479
|
+
dec c
|
|
480
|
+
dec d
|
|
481
|
+
dec e
|
|
482
|
+
dec h
|
|
483
|
+
dec l
|
|
484
|
+
dec ixh
|
|
485
|
+
dec ixl
|
|
486
|
+
dec iyh
|
|
487
|
+
dec iyl
|
|
488
|
+
dec (hl)
|
|
489
|
+
dec (ix+n)
|
|
490
|
+
dec (iy+n)
|
|
491
|
+
|
|
492
|
+
dec bc
|
|
493
|
+
dec de
|
|
494
|
+
dec hl
|
|
495
|
+
dec ix
|
|
496
|
+
dec iy
|
|
497
|
+
dec sp
|
|
498
|
+
|
|
499
|
+
### Effects
|
|
500
|
+
#### 8 Bits
|
|
501
|
+
`C` flag preserved, `P/V` detects overflow and rest modified by definition.
|
|
502
|
+
|
|
503
|
+
#### 16 Bits
|
|
504
|
+
No flags altered.
|
|
505
|
+
|
|
506
|
+
### T-States
|
|
507
|
+
`r` denotes 8-bit register.
|
|
508
|
+
`rr` represents a two byte register pair: `BC`, `DE`, `HL`, `SP`
|
|
509
|
+
|
|
510
|
+
r 4
|
|
511
|
+
(hl) 11
|
|
512
|
+
(ix+X) 23
|
|
513
|
+
(iy+X) 23
|
|
514
|
+
rr 6
|
|
515
|
+
ix 10
|
|
516
|
+
iy 10
|
|
517
|
+
|
|
518
|
+
### See Also
|
|
519
|
+
[ADC](#adc), [ADD](#add), [DAA](#daa), [INC](#inc), [SBC](#sbc), [SUB](#sub)
|
|
520
|
+
|
|
521
|
+
---
|
|
522
|
+
## DI
|
|
523
|
+
Disables the interrupts (both mode 1 and mode 2).
|
|
524
|
+
|
|
525
|
+
### Syntax
|
|
526
|
+
di
|
|
527
|
+
|
|
528
|
+
### Effects
|
|
529
|
+
Flags preserved.
|
|
530
|
+
|
|
531
|
+
### Uses
|
|
532
|
+
Useful if you want to use the `IY` register or shadow registers, which are modified by the OS's interrupts. Be sure to reset `IY` to flags before returning to the OS.
|
|
533
|
+
|
|
534
|
+
ld iy,flags
|
|
535
|
+
|
|
536
|
+
### T-States
|
|
537
|
+
4 t-states
|
|
538
|
+
|
|
539
|
+
### See Also
|
|
540
|
+
[EI](#ei), [HALT](#halt), [IM](#im), [RETI](#reti), [RETN](#retn), [RST](#rst)
|
|
541
|
+
|
|
542
|
+
---
|
|
543
|
+
## DJNZ
|
|
544
|
+
Decreases `B` and jumps to a label if not zero. Note that `DJNZ` does a relative jump, so it can only jump between 128 bytes back/ahead.
|
|
545
|
+
|
|
546
|
+
### Syntax
|
|
547
|
+
djnz label
|
|
548
|
+
|
|
549
|
+
### Effects
|
|
550
|
+
Preserves all flags.
|
|
551
|
+
|
|
552
|
+
### Uses
|
|
553
|
+
`DJNZ` is a very useful instruction when it comes to creating loops. See Control Structures to find out more about loops.
|
|
554
|
+
|
|
555
|
+
### T-States
|
|
556
|
+
B ≠ 0 13
|
|
557
|
+
B = 0 8
|
|
558
|
+
|
|
559
|
+
### See Also
|
|
560
|
+
[CALL](#call), [JP](#jp), [JR](#jr)
|
|
561
|
+
|
|
562
|
+
---
|
|
563
|
+
## EI
|
|
564
|
+
Enables the interrupts.
|
|
565
|
+
|
|
566
|
+
### Syntax
|
|
567
|
+
ei
|
|
568
|
+
|
|
569
|
+
### Effects
|
|
570
|
+
Flags preserved.
|
|
571
|
+
|
|
572
|
+
### Uses
|
|
573
|
+
Can either be set to interrupt mode 1 (OS interrupts) or interrupt mode 2 using `IM`. Be sure to re-enable interrupt mode 1 before returning to the OS.
|
|
574
|
+
|
|
575
|
+
### T-States
|
|
576
|
+
4 t-states
|
|
577
|
+
|
|
578
|
+
### See Also
|
|
579
|
+
[DI](#di), [HALT](#halt), [IM](#im), [RETI](#reti), [RETN](#retn), [RST](#rst)
|
|
580
|
+
|
|
581
|
+
---
|
|
582
|
+
## EX
|
|
583
|
+
## EX
|
|
584
|
+
Exchanges two 16-bit values.
|
|
585
|
+
|
|
586
|
+
### Syntax
|
|
587
|
+
ex op16,op16
|
|
588
|
+
|
|
589
|
+
#### Allowed Instructions
|
|
590
|
+
ex af,af'
|
|
591
|
+
ex de,hl
|
|
592
|
+
ex (sp),hl
|
|
593
|
+
ex (sp),ix
|
|
594
|
+
ex (sp),iy
|
|
595
|
+
|
|
596
|
+
### Effects
|
|
597
|
+
Flags are preserved.
|
|
598
|
+
|
|
599
|
+
### Uses
|
|
600
|
+
`EX DE,HL` exchanges `HL` with `DE`. Note that `IX` and `IY` do not work with this command.
|
|
601
|
+
`EX (SP),HL` exchanges `HL` with the last pushed value on the stack.
|
|
602
|
+
`EX AF,AF'` exchanges `AF` with its shadow register. This is mostly used as an alternative to pushing `AF` to the stack during interrupts. Note that the flags will most likely not be the same after this command.
|
|
603
|
+
|
|
604
|
+
### T-States
|
|
605
|
+
de, hl 4
|
|
606
|
+
af, af' 4
|
|
607
|
+
(sp),hl 19
|
|
608
|
+
(sp),ix 19
|
|
609
|
+
(sp),iy 19
|
|
610
|
+
|
|
611
|
+
### See Also
|
|
612
|
+
[EXX](#exx)
|
|
613
|
+
|
|
614
|
+
---
|
|
615
|
+
## EXX
|
|
616
|
+
Exchanges `BC`, `DE`, and `HL` with shadow registers `BC'`, `DE'`, and `HL'`.
|
|
617
|
+
|
|
618
|
+
### Syntax
|
|
619
|
+
exx
|
|
620
|
+
|
|
621
|
+
### Effects
|
|
622
|
+
All flags preserved.
|
|
623
|
+
|
|
624
|
+
### Uses
|
|
625
|
+
Most useful in interrupts as an alternative to saving those registers on the stack. If you want to use this command outside an interrupt, make sure interrupts are disabled first.
|
|
626
|
+
|
|
627
|
+
### T-States
|
|
628
|
+
4 t-states
|
|
629
|
+
|
|
630
|
+
### See Also
|
|
631
|
+
[DI](#di), [EI](#ei), [EX](#ex), [HALT](#halt), [IM](#im), [RETI](#reti), [RETN](#retn)
|
|
632
|
+
|
|
633
|
+
---
|
|
634
|
+
## HALT
|
|
635
|
+
Suspends all actions until the next interrupt.
|
|
636
|
+
|
|
637
|
+
_Note: Since halt does wait for the next interrupt, if you disable interrupts halt will run forever, resulting in a crash. Make sure that you always either know the interrupts will be on, or turn it on right before you use the halt instruction._
|
|
638
|
+
|
|
639
|
+
### Syntax
|
|
640
|
+
halt
|
|
641
|
+
|
|
642
|
+
### Effects
|
|
643
|
+
All flags preserved.
|
|
644
|
+
|
|
645
|
+
### Uses
|
|
646
|
+
Exactly what it says: if you need a delay, halt will provide a split second delay. You can chain halts
|
|
647
|
+
|
|
648
|
+
### T-States
|
|
649
|
+
4 t-states
|
|
650
|
+
|
|
651
|
+
### See Also
|
|
652
|
+
[DI](#di), [EI](#ei), [NOP](#nop)
|
|
653
|
+
|
|
654
|
+
---
|
|
655
|
+
## IM
|
|
656
|
+
Sets the interrupt mode.
|
|
657
|
+
|
|
658
|
+
### Modes
|
|
659
|
+
#### Mode 0
|
|
660
|
+
Not used by TI calculators, but means that an external device plugged into a z80 device generates the interrupt.
|
|
661
|
+
|
|
662
|
+
#### Mode 1
|
|
663
|
+
Interrupts are generated by the internal circuitry of the processor (aka the OS). The frequency of these interrupts is 200 per second on a ZX Spectrum, and 50(PAL)/60(NTSC) on a MSX, but it depends on the state of the batteries in the case of TI calculators (probably varies between 100 and 150). Every time an interrupt is encountered, the OS performs an RST $28.
|
|
664
|
+
|
|
665
|
+
#### Mode 2
|
|
666
|
+
Allows user to determine when an interrupt happens, and what the interrupt does. For more information on interrupts, see this page.
|
|
667
|
+
|
|
668
|
+
### Syntax
|
|
669
|
+
im 0 ;will compile, but could result in a crash
|
|
670
|
+
im 1
|
|
671
|
+
im 2
|
|
672
|
+
|
|
673
|
+
### Effects
|
|
674
|
+
All flags are preserved.
|
|
675
|
+
|
|
676
|
+
### Uses
|
|
677
|
+
The most important use of `IM` is to allow for the programmer to create their own interrupts that can do whatever they want them to, when they want the interrupts to occur. For more information on how interrupts work, see this page.
|
|
678
|
+
|
|
679
|
+
### T-States
|
|
680
|
+
8 t-states for each mode
|
|
681
|
+
|
|
682
|
+
### See Also
|
|
683
|
+
[DI](#di), [EI](#ei), [RETI](#reti), [RETN](#retn), [RST](#rst)
|
|
684
|
+
|
|
685
|
+
---
|
|
686
|
+
## IN
|
|
687
|
+
Reads a value from a hardware port.
|
|
688
|
+
|
|
689
|
+
### Syntax
|
|
690
|
+
in op8,(op8)
|
|
691
|
+
|
|
692
|
+
#### Allowed Instructions
|
|
693
|
+
in a,(n) ;8-bit constant
|
|
694
|
+
in a,(c)
|
|
695
|
+
in b,(c)
|
|
696
|
+
in c,(c)
|
|
697
|
+
in d,(c)
|
|
698
|
+
in e,(c)
|
|
699
|
+
in h,(c)
|
|
700
|
+
in l,(c)
|
|
701
|
+
in (c) ;undocumented command
|
|
702
|
+
|
|
703
|
+
### Effects
|
|
704
|
+
#### IN A,(N)
|
|
705
|
+
This command alters no flags.
|
|
706
|
+
|
|
707
|
+
#### Others
|
|
708
|
+
`N` flag reset, `P/V` represents parity, `C` flag preserved, all other flags affected by definition.
|
|
709
|
+
|
|
710
|
+
### Uses
|
|
711
|
+
This command, along with `OUT`, is used for hardware interfacing.
|
|
712
|
+
The undocumented command `IN (C)` reads from the port and affects flags, but does not store the value to a register.
|
|
713
|
+
|
|
714
|
+
### T-States
|
|
715
|
+
`r` denotes 8-bit register.
|
|
716
|
+
|
|
717
|
+
A, X 11
|
|
718
|
+
r, (C) 12
|
|
719
|
+
|
|
720
|
+
### See Also
|
|
721
|
+
[IND](#ind), [INDR](#indr), [INI](#ini), [INIR](#inir), [OUT](#out), [OUTD](#outd), [OTDR](#otdr), [OUTI](#outi), [OTIR](#otir)
|
|
722
|
+
|
|
723
|
+
---
|
|
724
|
+
## INC
|
|
725
|
+
Increases operand by 1.
|
|
726
|
+
|
|
727
|
+
### Syntax
|
|
728
|
+
inc op8 ;8 bits
|
|
729
|
+
inc op16 ;16 bits
|
|
730
|
+
|
|
731
|
+
#### Allowed Instructions
|
|
732
|
+
inc a
|
|
733
|
+
inc b
|
|
734
|
+
inc c
|
|
735
|
+
inc d
|
|
736
|
+
inc e
|
|
737
|
+
inc h
|
|
738
|
+
inc l
|
|
739
|
+
inc ixh
|
|
740
|
+
inc ixl
|
|
741
|
+
inc iyh
|
|
742
|
+
inc iyl
|
|
743
|
+
inc (hl)
|
|
744
|
+
inc (ix+n)
|
|
745
|
+
inc (iy+n)
|
|
746
|
+
|
|
747
|
+
inc bc
|
|
748
|
+
inc de
|
|
749
|
+
inc hl
|
|
750
|
+
inc ix
|
|
751
|
+
inc iy
|
|
752
|
+
inc sp
|
|
753
|
+
|
|
754
|
+
### Effects
|
|
755
|
+
#### 8 Bits
|
|
756
|
+
Preserves `C` flag, `N` flag is reset, `P/V` detects overflow and rest are modified by definition.
|
|
757
|
+
|
|
758
|
+
#### 16 Bits
|
|
759
|
+
No flags altered.
|
|
760
|
+
|
|
761
|
+
### T-States
|
|
762
|
+
`r` denotes 8-bit register.
|
|
763
|
+
`rr` represents a two byte register pair: `BC`, `DE`, `HL`, `SP`
|
|
764
|
+
|
|
765
|
+
r 4
|
|
766
|
+
(hl) 11
|
|
767
|
+
(ix+X) 23
|
|
768
|
+
(iy+X) 23
|
|
769
|
+
rr 6
|
|
770
|
+
ix 10
|
|
771
|
+
iy 10
|
|
772
|
+
|
|
773
|
+
### See Also
|
|
774
|
+
[ADC](#adc), [ADD](#add), [DAA](#daa), [DEC](#dec), [SBC](#sbc), [SUB](#sub)
|
|
775
|
+
|
|
776
|
+
---
|
|
777
|
+
## IND
|
|
778
|
+
Reads the `(C)` port and writes the result to `(HL)`, then decrements `HL` and decrements `B`.
|
|
779
|
+
|
|
780
|
+
### Syntax
|
|
781
|
+
ind
|
|
782
|
+
|
|
783
|
+
### Effects
|
|
784
|
+
`C` is preserved, the `N` flag is set. `S`, `H` and `P/V` are undefined. `Z` is set if `B` becomes zero after decrementing, otherwise it is reset.
|
|
785
|
+
|
|
786
|
+
### T-States
|
|
787
|
+
16 t-states
|
|
788
|
+
|
|
789
|
+
### See Also
|
|
790
|
+
[IN](#in), [INI](#ini), [INDR](#indr), [INIR](#inir), [OTDR](#otdr), [OTIR](#otir), [OUT](#out), [OUTD](#outd), [OUTI](#outi)
|
|
791
|
+
|
|
792
|
+
---
|
|
793
|
+
## INDR
|
|
794
|
+
Reads the `(C)` port and writes the result to `(HL)`. `HL` and `B` are decremented. Repeats until `B` = 0.
|
|
795
|
+
|
|
796
|
+
### Syntax
|
|
797
|
+
indr
|
|
798
|
+
|
|
799
|
+
### Effects
|
|
800
|
+
`Z` is set, carry is preserved, `N` is set, `S`, `H`, and `P/V` are undefined.
|
|
801
|
+
|
|
802
|
+
### Uses
|
|
803
|
+
|
|
804
|
+
### T-States
|
|
805
|
+
B = 0 16
|
|
806
|
+
B ≠ 0 21
|
|
807
|
+
|
|
808
|
+
### See Also
|
|
809
|
+
[IN](#in), [IND](#ind), [INI](#ini), [INIR](#inir), [OUT](#out), [OUTD](#outd), [OTDR](#otdr), [OUTI](#outi), [OTIR](#otir)
|
|
810
|
+
|
|
811
|
+
---
|
|
812
|
+
## INI
|
|
813
|
+
Reads the `(C)` port and writes the result to `(HL)`, then increments `HL` and decrements `B`.
|
|
814
|
+
|
|
815
|
+
### Syntax
|
|
816
|
+
ini
|
|
817
|
+
|
|
818
|
+
### Effects
|
|
819
|
+
`C` is preserved, the `N` flag is reset. `S`, `H` and `P/V` are undefined. `Z` is set if `B` becomes zero after decrementing, otherwise it is reset.
|
|
820
|
+
|
|
821
|
+
### T-States
|
|
822
|
+
16 t-states
|
|
823
|
+
|
|
824
|
+
### See Also
|
|
825
|
+
[IN](#in), [IND](#ind), [INDR](#indr), [INIR](#inir), [OTDR](#otdr), [OTIR](#otir), [OUT](#out), [OUTD](#outd), [OUTI](#outi)
|
|
826
|
+
|
|
827
|
+
---
|
|
828
|
+
## INIR
|
|
829
|
+
Reads from the `(C)` port, then writes to `(HL)`. `HL` is incremented and `B` is decremented. Repeats until `B` = 0.
|
|
830
|
+
|
|
831
|
+
### Syntax
|
|
832
|
+
inir
|
|
833
|
+
|
|
834
|
+
### Effects
|
|
835
|
+
`Z` is set, `C` is reset, `N` is reset, `S`, `H`, and `P/V` are undefined.
|
|
836
|
+
|
|
837
|
+
### T-States
|
|
838
|
+
B = 0 16
|
|
839
|
+
B ≠ 0 21
|
|
840
|
+
|
|
841
|
+
### See Also
|
|
842
|
+
[IN](#in), [IND](#ind), [INDR](#indr), [INI](#ini), [OUT](#out), [OUTD](#outd), [OTDR](#otdr), [OUTI](#outi), [OTIR](#otir)
|
|
843
|
+
|
|
844
|
+
---
|
|
845
|
+
## JP
|
|
846
|
+
Absolute jumps to the address. Can be conditional or unconditional. `JP` takes one more byte than `JR`, but is also slightly faster, so decide whether speed or size is more important before choosing `JP` or `JR`. `JP (HL)`, `JP (IX)`, and `JP (IY)` are unconditional and are the fastest jumps, and do not take more bytes than other jumps.
|
|
847
|
+
|
|
848
|
+
### Syntax
|
|
849
|
+
jp nn ;unconditional jump
|
|
850
|
+
jp cond.,nn ;conditional jump
|
|
851
|
+
jp (reg16) ;HL, IX and IY only
|
|
852
|
+
|
|
853
|
+
#### Allowed Instructions
|
|
854
|
+
;Constants
|
|
855
|
+
jp nn ;no condition
|
|
856
|
+
jp c,nn ;jumps if C is set
|
|
857
|
+
jp nc,nn ;jumps if C is reset
|
|
858
|
+
jp z,nn ;jumps if Z is set
|
|
859
|
+
jp nz,nn ;jumps if Z is reset
|
|
860
|
+
jp m,nn ;jumps if S is set
|
|
861
|
+
jp p,nn ;jumps if S is reset
|
|
862
|
+
jp pe,nn ;jumps if P/V is set
|
|
863
|
+
jp po,nn ;jumps if P/V is reset
|
|
864
|
+
|
|
865
|
+
;HL points to address
|
|
866
|
+
jp (hl)
|
|
867
|
+
|
|
868
|
+
;IX points to address
|
|
869
|
+
jp (ix)
|
|
870
|
+
|
|
871
|
+
;IY points to address
|
|
872
|
+
jp (iy)
|
|
873
|
+
|
|
874
|
+
### Effects
|
|
875
|
+
All flags preserved.
|
|
876
|
+
|
|
877
|
+
### T-States
|
|
878
|
+
`cc` is condition: `NZ`, `Z`, `NC`, `C`, `PO`, `PE`, `P`, `M`
|
|
879
|
+
|
|
880
|
+
XX 10
|
|
881
|
+
cc,XX 10
|
|
882
|
+
(hl) 4
|
|
883
|
+
(ix) 8
|
|
884
|
+
(iy) 8
|
|
885
|
+
|
|
886
|
+
### See Also
|
|
887
|
+
[BIT](#bit), [CALL](#call), [CP](#cp), [CPD](#cpd), [CPDR](#cpdr), [CPI](#cpi), [CPIR](#cpir), [DJNZ](#djnz), [JR](#jr)
|
|
888
|
+
|
|
889
|
+
---
|
|
890
|
+
## JR
|
|
891
|
+
Relative jumps to the address. This means that it can only jump between 128 bytes ahead or behind. Can be conditional or unconditional. `JR` takes up one less byte than `JP`, but is also slower. Weigh the needs of the code at the time before choosing one over the other (speed vs. size).
|
|
892
|
+
|
|
893
|
+
### Syntax
|
|
894
|
+
jr nn ;unconditional jump
|
|
895
|
+
jr cond.,nn ;conditional jump
|
|
896
|
+
|
|
897
|
+
#### Allowed Instructions
|
|
898
|
+
;Constants
|
|
899
|
+
jr nn ;no condition
|
|
900
|
+
jr c,nn ;jumps if C is set
|
|
901
|
+
jr nc,nn ;jumps if C is reset
|
|
902
|
+
jr z,nn ;jumps if Z is set
|
|
903
|
+
jr nz,nn ;jumps if Z is reset
|
|
904
|
+
|
|
905
|
+
### Effects
|
|
906
|
+
All flags preserved.
|
|
907
|
+
|
|
908
|
+
### T-States
|
|
909
|
+
`cc` is condition: `NZ`, `Z`, `NC`, `C`
|
|
910
|
+
|
|
911
|
+
XX 12
|
|
912
|
+
condition-true condition-false
|
|
913
|
+
cc,XX 12 7
|
|
914
|
+
|
|
915
|
+
### See Also
|
|
916
|
+
[BIT](#bit), [CALL](#call), [CP](#cp), [CPD](#cpd), [CPDR](#cpdr), [CPI](#cpi), [CPIR](#cpir), [DJNZ](#djnz), [JP](#jp)
|
|
917
|
+
|
|
918
|
+
---
|
|
919
|
+
## LD
|
|
920
|
+
The `LD` instruction is used to put the value from one place into another place.
|
|
921
|
+
|
|
922
|
+
### Syntax
|
|
923
|
+
ld N,M
|
|
924
|
+
|
|
925
|
+
puts `M` into `N`.
|
|
926
|
+
|
|
927
|
+
#### Allowed instructions
|
|
928
|
+
(across: `M` Down: `N`)
|
|
929
|
+
|
|
930
|
+
If x, it means allowed. If empty, it means not allowed.
|
|
931
|
+
|
|
932
|
+
| | A | B | C | D | E | H | L | I | R | IXH | IXL | IYH | IYL | BC | DE | HL | SP | IX | IY | (BC) | (DE) | (HL) | (IX+N) | (IY+N) | N | NN | (NN) |
|
|
933
|
+
|-------|---|---|---|---|---|---|---|---|---|-----|-----|-----|-----|----|----|----|----|----|----|------|------|------|--------|--------|---|----|----- |
|
|
934
|
+
| A | x | x | x | x | x | x | x | x | x | x | x | x | x | | | | | | | x | x | x | x | x | x | | x |
|
|
935
|
+
| B | x | x | x | x | x | x | x | | | x | x | x | x | | | | | | | | | x | x | x | x | | |
|
|
936
|
+
| C | x | x | x | x | x | x | x | | | x | x | x | x | | | | | | | | | x | x | x | x | | |
|
|
937
|
+
| D | x | x | x | x | x | x | x | | | x | x | x | x | | | | | | | | | x | x | x | x | | |
|
|
938
|
+
| E | x | x | x | x | x | x | x | | | x | x | x | x | | | | | | | | | x | x | x | x | | |
|
|
939
|
+
| H | x | x | x | x | x | x | x | | | | | | | | | | | | | | | x | x | x | x | | |
|
|
940
|
+
| L | x | x | x | x | x | x | x | | | | | | | | | | | | | | | x | x | x | x | | |
|
|
941
|
+
| I | x | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
|
942
|
+
| R | x | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
|
943
|
+
| IXH | x | x | x | x | x | | | | | x | x | | | | | | | | | | | | | | x | | |
|
|
944
|
+
| IXL | x | x | x | x | x | | | | | x | x | | | | | | | | | | | | | | x | | |
|
|
945
|
+
| IYH | x | x | x | x | x | | | | | | | x | x | | | | | | | | | | | | x | | |
|
|
946
|
+
| IYL | x | x | x | x | x | | | | | | | x | x | | | | | | | | | | | | x | | |
|
|
947
|
+
| BC | | | | | | | | | | | | | | | | | | | | | | | | | | x | x |
|
|
948
|
+
| DE | | | | | | | | | | | | | | | | | | | | | | | | | | x | x |
|
|
949
|
+
| HL | | | | | | | | | | | | | | | | | | | | | | | | | | x | x |
|
|
950
|
+
| SP | | | | | | | | | | | | | | | | x | | x | x | | | | | | | x | x |
|
|
951
|
+
| IX | | | | | | | | | | | | | | | | | | | | | | | | | | x | x |
|
|
952
|
+
| IY | | | | | | | | | | | | | | | | | | | | | | | | | | x | x |
|
|
953
|
+
| (BC) | x | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
|
954
|
+
| (DE) | x | | | | | | | | | | | | | | | | | | | | | | | | | | |
|
|
955
|
+
| (HL) | x | x | x | x | x | x | x | | | | | | | | | | | | | | | | | | x | | |
|
|
956
|
+
| (IX+N)| x | x | x | x | x | x | x | | | | | | | | | | | | | | | | | | x | | |
|
|
957
|
+
| (IY+N)| x | x | x | x | x | x | x | | | | | | | | | | | | | | | | | | x | | |
|
|
958
|
+
| (NN) | x | | | | | | | | | | | | | x | x | x | x | x | x | | | | | | | | |
|
|
959
|
+
|
|
960
|
+
### Effects
|
|
961
|
+
No flags are altered except in the cases of the `I` or `R` registers.
|
|
962
|
+
|
|
963
|
+
In those cases, `C` is preserved, `H` and `N` are reset, and alters `Z` and `S`. `P/V` is set if interrupts are enabled, reset otherwise.
|
|
964
|
+
|
|
965
|
+
### Uses
|
|
966
|
+
Use to load numbers into operands. They can either be numbers used in the code (usually 8-bits), or labels (usually 16-bits).
|
|
967
|
+
|
|
968
|
+
ld b,$05 ;Counter
|
|
969
|
+
|
|
970
|
+
ld hl,var ;Variable label
|
|
971
|
+
ld a,(var) ;Write data to var
|
|
972
|
+
|
|
973
|
+
### T-States
|
|
974
|
+
`r` denotes 8-bit register.
|
|
975
|
+
`rr` represents a two byte register pair: `BC`, `DE`, `HL`, `SP`
|
|
976
|
+
|
|
977
|
+
r, r' 4
|
|
978
|
+
r,X 7
|
|
979
|
+
r,(hl) 7
|
|
980
|
+
r,(ix+X) 19
|
|
981
|
+
r,(iy+X) 19
|
|
982
|
+
a, (bc) 7
|
|
983
|
+
a, (de) 7
|
|
984
|
+
a, (XX) 13
|
|
985
|
+
(bc),a 7
|
|
986
|
+
(de),a 7
|
|
987
|
+
(XX),a 13
|
|
988
|
+
a, i 9
|
|
989
|
+
a, r 9
|
|
990
|
+
i, a 9
|
|
991
|
+
r, a 9
|
|
992
|
+
a, (BC) 7
|
|
993
|
+
(XX), a 13
|
|
994
|
+
rr,XX 10
|
|
995
|
+
ix, XX 14
|
|
996
|
+
iy, XX 14
|
|
997
|
+
hl, (XX) 20
|
|
998
|
+
ix, (XX) 20
|
|
999
|
+
iy, (XX) 20
|
|
1000
|
+
(XX), hl 20
|
|
1001
|
+
(XX), rr 20
|
|
1002
|
+
(XX), ix 20
|
|
1003
|
+
(XX), iy 20
|
|
1004
|
+
sp, hl 6
|
|
1005
|
+
sp, ix 10
|
|
1006
|
+
sp, iy 10
|
|
1007
|
+
|
|
1008
|
+
### See Also
|
|
1009
|
+
[LDD](#ldd), [LDDR](#lddr), [LDI](#ldi), [LDIR](#ldir)
|
|
1010
|
+
|
|
1011
|
+
---
|
|
1012
|
+
## LDD
|
|
1013
|
+
Does a sort of `LD (DE),(HL)`, then decrements `DE`, `HL`, and `BC`.
|
|
1014
|
+
|
|
1015
|
+
### Syntax
|
|
1016
|
+
ldd
|
|
1017
|
+
|
|
1018
|
+
### Effects
|
|
1019
|
+
`P/V` is reset in case of overflow (if `BC`=0 after calling `LDD`).
|
|
1020
|
+
|
|
1021
|
+
### Uses
|
|
1022
|
+
Used when you want to copy over the data pointed to by `HL` to the location pointed to by `DE`.
|
|
1023
|
+
|
|
1024
|
+
### T-States
|
|
1025
|
+
16 t-states
|
|
1026
|
+
|
|
1027
|
+
### See Also
|
|
1028
|
+
[LD](#ld), [LDDR](#lddr), [LDI](#ldi), [LDIR](#ldir)
|
|
1029
|
+
|
|
1030
|
+
## LDDR
|
|
1031
|
+
Repeats the instruction `LDD` (Does a `LD (DE),(HL)` and decrements each of `DE`, `HL`, and `BC`) until `BC`=0. Note that if `BC`=0 before the start of the routine, it will try loop around until `BC`=0 again.
|
|
1032
|
+
|
|
1033
|
+
### Syntax
|
|
1034
|
+
lddr
|
|
1035
|
+
|
|
1036
|
+
### Effects
|
|
1037
|
+
`P/V` is reset.
|
|
1038
|
+
|
|
1039
|
+
### Uses
|
|
1040
|
+
Copying over sections of data.
|
|
1041
|
+
|
|
1042
|
+
### T-States
|
|
1043
|
+
BC ≠ 0 21
|
|
1044
|
+
BC = 0 16
|
|
1045
|
+
|
|
1046
|
+
### See Also
|
|
1047
|
+
[LD](#ld), [LDD](#ldd), [LDI](#ldi), [LDIR](#ldir)
|
|
1048
|
+
|
|
1049
|
+
---
|
|
1050
|
+
## LDI
|
|
1051
|
+
Performs a `LD (DE),(HL)`, then increments `DE` and `HL`, and decrements `BC`.
|
|
1052
|
+
|
|
1053
|
+
### Syntax
|
|
1054
|
+
ldi
|
|
1055
|
+
|
|
1056
|
+
### Effects
|
|
1057
|
+
`P/V` is reset in case of overflow (if `BC`=0 after calling `LDI`).
|
|
1058
|
+
|
|
1059
|
+
### Uses
|
|
1060
|
+
Copying data.
|
|
1061
|
+
|
|
1062
|
+
### T-States
|
|
1063
|
+
16 t-states
|
|
1064
|
+
|
|
1065
|
+
### See Also
|
|
1066
|
+
[LD](#ld), [LDD](#ldd), [LDDR](#lddr), [LDIR](#ldir)
|
|
1067
|
+
|
|
1068
|
+
---
|
|
1069
|
+
## LDIR
|
|
1070
|
+
Repeats `LDI` (`LD (DE),(HL)`, then increments `DE`, `HL`, and decrements `BC`) until `BC`=0. Note that if `BC`=0 before this instruction is called, it will loop around until `BC`=0 again.
|
|
1071
|
+
|
|
1072
|
+
### Syntax
|
|
1073
|
+
ldir
|
|
1074
|
+
|
|
1075
|
+
### Effects
|
|
1076
|
+
`P/V` is reset.
|
|
1077
|
+
|
|
1078
|
+
### Uses
|
|
1079
|
+
Copying sections of data.
|
|
1080
|
+
|
|
1081
|
+
### T-States
|
|
1082
|
+
BC ≠ 0 21
|
|
1083
|
+
BC = 0 16
|
|
1084
|
+
|
|
1085
|
+
### See Also
|
|
1086
|
+
[LD](#ld), [LDD](#ldd), [LDDR](#lddr), [LDI](#ldi)
|
|
1087
|
+
|
|
1088
|
+
---
|
|
1089
|
+
## NEG
|
|
1090
|
+
`NEG` negates the accumulator.
|
|
1091
|
+
|
|
1092
|
+
### Syntax
|
|
1093
|
+
neg
|
|
1094
|
+
|
|
1095
|
+
### Effects
|
|
1096
|
+
`N` flag is set, all other flags modified by definition.
|
|
1097
|
+
|
|
1098
|
+
### Uses
|
|
1099
|
+
This command literally subtracts `A` from 0. This explains what "modified by definition" means in the _Effects_ section above.
|
|
1100
|
+
|
|
1101
|
+
### T-States
|
|
1102
|
+
8 t-states
|
|
1103
|
+
|
|
1104
|
+
### See Also
|
|
1105
|
+
[CPL](#cpl), [SUB](#sub)
|
|
1106
|
+
|
|
1107
|
+
---
|
|
1108
|
+
## NOP
|
|
1109
|
+
`NOP` does nothing for 4 clock cycles.
|
|
1110
|
+
|
|
1111
|
+
### Syntax
|
|
1112
|
+
nop
|
|
1113
|
+
|
|
1114
|
+
### Effects
|
|
1115
|
+
All flags preserved.
|
|
1116
|
+
|
|
1117
|
+
### Uses
|
|
1118
|
+
Useful for a short time waster (for example, it's common to put clock cycles between output and input ports).
|
|
1119
|
+
|
|
1120
|
+
### T-States
|
|
1121
|
+
4 t-states
|
|
1122
|
+
|
|
1123
|
+
### See Also
|
|
1124
|
+
[HALT](#halt)
|
|
1125
|
+
|
|
1126
|
+
---
|
|
1127
|
+
## OR
|
|
1128
|
+
`OR` is an instruction that takes an 8-bit input an compare sit with the accumulator. It checks to see if anything is set, and if neither are set, it results in a zero.
|
|
1129
|
+
|
|
1130
|
+
0 or 0 result: 0
|
|
1131
|
+
0 or 1 result: 1
|
|
1132
|
+
1 or 0 result: 1
|
|
1133
|
+
1 or 1 result: 1
|
|
1134
|
+
|
|
1135
|
+
### Syntax
|
|
1136
|
+
or op8
|
|
1137
|
+
|
|
1138
|
+
#### Allowed Instructions
|
|
1139
|
+
or a
|
|
1140
|
+
or b
|
|
1141
|
+
or c
|
|
1142
|
+
or d
|
|
1143
|
+
or e
|
|
1144
|
+
or h
|
|
1145
|
+
or l
|
|
1146
|
+
or ixh
|
|
1147
|
+
or ixl
|
|
1148
|
+
or iyh
|
|
1149
|
+
or iyl
|
|
1150
|
+
or (hl)
|
|
1151
|
+
or (ix+n)
|
|
1152
|
+
or (iy+n)
|
|
1153
|
+
or n ;8 bit constant
|
|
1154
|
+
|
|
1155
|
+
### Effects
|
|
1156
|
+
`C` and `N` flags cleared, `P/V` detects parity, and rest are modified by definition.
|
|
1157
|
+
|
|
1158
|
+
### Uses
|
|
1159
|
+
Used in bit-masking. For more information see here.
|
|
1160
|
+
|
|
1161
|
+
### T-States
|
|
1162
|
+
`r` denotes 8-bit register.
|
|
1163
|
+
|
|
1164
|
+
r 4
|
|
1165
|
+
X 7
|
|
1166
|
+
(hl) 7
|
|
1167
|
+
(ix+X) 19
|
|
1168
|
+
(iy+X) 19
|
|
1169
|
+
|
|
1170
|
+
### See Also
|
|
1171
|
+
[AND](#and), [BIT](#bit), [CCF](#ccf), [CPL](#cpl), [RES](#res), [SCF](#scf), [SET](#set), [XOR](#xor)
|
|
1172
|
+
|
|
1173
|
+
---
|
|
1174
|
+
## OTDR
|
|
1175
|
+
Reads from `(HL)` and writes to the `(C)` port. `HL` and `B` are then decremented. Repeats until `B` = 0.
|
|
1176
|
+
|
|
1177
|
+
### Syntax
|
|
1178
|
+
otdr
|
|
1179
|
+
|
|
1180
|
+
### Effects
|
|
1181
|
+
`C` is preserved, `Z` is set, `N` is set, `S`, `H`, and `P/V` are undefined.
|
|
1182
|
+
|
|
1183
|
+
### T-States
|
|
1184
|
+
B = 0 16
|
|
1185
|
+
B ≠ 0 21
|
|
1186
|
+
|
|
1187
|
+
### See Also
|
|
1188
|
+
[IN](#in), [IND](#ind), [INDR](#indr), [INI](#ini), [INIR](#inir), [OUT](#out), [OUTD](#outd), [OUTI](#outi), [OTIR](#otir)
|
|
1189
|
+
|
|
1190
|
+
---
|
|
1191
|
+
## OTIR
|
|
1192
|
+
Reads from `(HL)` and writes to the `(C)` port. `HL` is incremented and `B` is decremented. Repeats until `B` = 0.
|
|
1193
|
+
|
|
1194
|
+
### Syntax
|
|
1195
|
+
otir
|
|
1196
|
+
|
|
1197
|
+
### Effects
|
|
1198
|
+
`Z` is set, `C` is preserved, `N` is reset, `H`, `S`, and `P/V` are undefined.
|
|
1199
|
+
|
|
1200
|
+
### T-States
|
|
1201
|
+
B = 0 16
|
|
1202
|
+
B ≠ 0 21
|
|
1203
|
+
|
|
1204
|
+
### See Also
|
|
1205
|
+
[IN](#in), [IND](#ind), [INDR](#indr), [INI](#ini), [INIR](#inir), [OUT](#out), [OUTD](#outd), [OTDR](#otdr), [OUTI](#outi)
|
|
1206
|
+
|
|
1207
|
+
---
|
|
1208
|
+
## OUT
|
|
1209
|
+
Writes the value of the second operand into the port given by the first operand.
|
|
1210
|
+
|
|
1211
|
+
### Syntax
|
|
1212
|
+
out (imm8),a
|
|
1213
|
+
out (c),reg8
|
|
1214
|
+
|
|
1215
|
+
#### Allowed Instructions
|
|
1216
|
+
out (imm8),a
|
|
1217
|
+
out (c),a
|
|
1218
|
+
out (c),b
|
|
1219
|
+
out (c),c
|
|
1220
|
+
out (c),d
|
|
1221
|
+
out (c),e
|
|
1222
|
+
out (c),h
|
|
1223
|
+
out (c),l
|
|
1224
|
+
|
|
1225
|
+
out (c),0 ;Zero. Note: Undocumented
|
|
1226
|
+
|
|
1227
|
+
### Effects
|
|
1228
|
+
All flags preserved
|
|
1229
|
+
|
|
1230
|
+
### T-States
|
|
1231
|
+
`r` denotes 8-bit register.
|
|
1232
|
+
|
|
1233
|
+
A, X 11
|
|
1234
|
+
r, (C) 12
|
|
1235
|
+
|
|
1236
|
+
### See Also
|
|
1237
|
+
[IN](#in), [IND](#ind), [INDR](#indr), [INI](#ini), [INIR](#inir), [OUTD](#outd), [OTDR](#otdr), [OUTI](#outi), [OTIR](#otir)
|
|
1238
|
+
|
|
1239
|
+
---
|
|
1240
|
+
## OUTD
|
|
1241
|
+
Writes the value from `(HL)` to the `(C)` port, then decrements `B` and `HL`.
|
|
1242
|
+
|
|
1243
|
+
### Syntax
|
|
1244
|
+
outd
|
|
1245
|
+
|
|
1246
|
+
### Effects
|
|
1247
|
+
`C` is preserved, `N` is set, `H`, `S`, and `P/V` are undefined. `Z` is set only if `B` becomes zero after decrement, otherwise it is reset.
|
|
1248
|
+
|
|
1249
|
+
### T-States
|
|
1250
|
+
16 t-states
|
|
1251
|
+
|
|
1252
|
+
### See Also
|
|
1253
|
+
[IN](#in), [IND](#ind), [INDR](#indr), [INI](#ini), [INIR](#inir), [OUT](#out), [OTDR](#otdr), [OUTI](#outi), [OTIR](#otir)
|
|
1254
|
+
|
|
1255
|
+
---
|
|
1256
|
+
## OUTI
|
|
1257
|
+
Reads from `(HL)` and writes to the `(C)` port. `HL` is then incremented, and `B` is decremented.
|
|
1258
|
+
|
|
1259
|
+
### Syntax
|
|
1260
|
+
outi
|
|
1261
|
+
|
|
1262
|
+
### Effects
|
|
1263
|
+
`C` is preserved, `N` is reset, `H`, `S`, and `P/V` are undefined. `Z` is set only if `B` becomes zero after decrement, otherwise it's reset.
|
|
1264
|
+
|
|
1265
|
+
### Uses
|
|
1266
|
+
|
|
1267
|
+
### T-States
|
|
1268
|
+
16 t-states
|
|
1269
|
+
|
|
1270
|
+
### See Also
|
|
1271
|
+
[IN](#in), [IND](#ind), [INDR](#indr), [INI](#ini), [INIR](#inir), [OUT](#out), [OUTD](#outd), [OTDR](#otdr), [OTIR](#otir)
|
|
1272
|
+
|
|
1273
|
+
---
|
|
1274
|
+
## POP
|
|
1275
|
+
Copies the two bytes from `(SP)` into the operand, then increases `SP` by 2.
|
|
1276
|
+
|
|
1277
|
+
### Syntax
|
|
1278
|
+
pop reg16
|
|
1279
|
+
|
|
1280
|
+
#### Allowed Instructions
|
|
1281
|
+
pop af
|
|
1282
|
+
pop bc
|
|
1283
|
+
pop de
|
|
1284
|
+
pop hl
|
|
1285
|
+
pop ix
|
|
1286
|
+
pop iy
|
|
1287
|
+
|
|
1288
|
+
### Effects
|
|
1289
|
+
Flags are unaffected except when popping `AF`.
|
|
1290
|
+
|
|
1291
|
+
### Uses
|
|
1292
|
+
Used for retrieving values saved on the stack. Also used when you want to load a 16-bit register into another 16-bit register (the `LD` instruction won't work for this).
|
|
1293
|
+
|
|
1294
|
+
### T-States
|
|
1295
|
+
`rr` represents a two byte register pair: `BC`, `DE`, `HL`, `SP`
|
|
1296
|
+
|
|
1297
|
+
rr 10
|
|
1298
|
+
ix 14
|
|
1299
|
+
iy 14
|
|
1300
|
+
|
|
1301
|
+
### See Also
|
|
1302
|
+
[PUSH](#push)
|
|
1303
|
+
|
|
1304
|
+
---
|
|
1305
|
+
## PUSH
|
|
1306
|
+
Copies the operand into `(SP)`, then decrements `SP` by 2.
|
|
1307
|
+
|
|
1308
|
+
### Syntax
|
|
1309
|
+
push reg16
|
|
1310
|
+
|
|
1311
|
+
#### Allowed Instructions
|
|
1312
|
+
push af
|
|
1313
|
+
push bc
|
|
1314
|
+
push de
|
|
1315
|
+
push hl
|
|
1316
|
+
push ix
|
|
1317
|
+
push iy
|
|
1318
|
+
|
|
1319
|
+
### Effects
|
|
1320
|
+
Flags are unaffected.
|
|
1321
|
+
|
|
1322
|
+
### Uses
|
|
1323
|
+
Used for saving register values onto the stack. Also used when you want to load a 16-bit register into another 16-bit register (the `LD` instruction won't work for this).
|
|
1324
|
+
|
|
1325
|
+
### T-States
|
|
1326
|
+
`rr` represents a two byte register pair: `BC`, `DE`, `HL`, `SP`
|
|
1327
|
+
|
|
1328
|
+
rr 11
|
|
1329
|
+
ix 15
|
|
1330
|
+
iy 15
|
|
1331
|
+
|
|
1332
|
+
### See Also
|
|
1333
|
+
[POP](#pop)
|
|
1334
|
+
|
|
1335
|
+
---
|
|
1336
|
+
## RES
|
|
1337
|
+
Resets the specified bit to zero.
|
|
1338
|
+
|
|
1339
|
+
### Syntax
|
|
1340
|
+
res n,op8
|
|
1341
|
+
|
|
1342
|
+
#### Allowed Instructions
|
|
1343
|
+
`n` can be any integer from [0,7]. It must be defined on compile time.
|
|
1344
|
+
|
|
1345
|
+
res n,a
|
|
1346
|
+
res n,b
|
|
1347
|
+
res n,c
|
|
1348
|
+
res n,d
|
|
1349
|
+
res n,e
|
|
1350
|
+
res n,h
|
|
1351
|
+
res n,l
|
|
1352
|
+
res n,(hl)
|
|
1353
|
+
res n,(ix+n)
|
|
1354
|
+
res n,(iy+n)
|
|
1355
|
+
|
|
1356
|
+
### Effects
|
|
1357
|
+
Flags are preserved.
|
|
1358
|
+
|
|
1359
|
+
### T-States
|
|
1360
|
+
`r` denotes 8-bit register.
|
|
1361
|
+
|
|
1362
|
+
r 8
|
|
1363
|
+
(hl) 15
|
|
1364
|
+
(ix+X) 23
|
|
1365
|
+
(iy+X) 23
|
|
1366
|
+
|
|
1367
|
+
### See Also
|
|
1368
|
+
[AND](#and), [BIT](#bit), [CCF](#ccf), [CPL](#cpl), [OR](#or), [SCF](#scf), [SET](#set), [XOR](#xor)
|
|
1369
|
+
|
|
1370
|
+
---
|
|
1371
|
+
## RET
|
|
1372
|
+
Pops the top of the stack into the program counter. Note that `RET` can be either conditional or unconditional.
|
|
1373
|
+
|
|
1374
|
+
### Syntax
|
|
1375
|
+
ret ;no conditions
|
|
1376
|
+
ret cond. ;conditional
|
|
1377
|
+
|
|
1378
|
+
#### Allowed Instructions
|
|
1379
|
+
ret z ; Z flag is set
|
|
1380
|
+
ret nz ; Z flag is reset
|
|
1381
|
+
ret c ; Carry flag is set
|
|
1382
|
+
ret nc ; Carry flag is reset
|
|
1383
|
+
ret m ; S flag is set
|
|
1384
|
+
ret p ; S flag is reset
|
|
1385
|
+
ret pe ; P/V is set
|
|
1386
|
+
ret po ; P/V is reset
|
|
1387
|
+
|
|
1388
|
+
### Effects
|
|
1389
|
+
Preserves all flags.
|
|
1390
|
+
|
|
1391
|
+
### Uses
|
|
1392
|
+
`RET` is used mostly for exiting an assembly program or returning from a routine.
|
|
1393
|
+
|
|
1394
|
+
### T-States
|
|
1395
|
+
`cc` is condition: `NZ`, `Z`, `NC`, `C`, `PO`, `PE`, `P`, `M`
|
|
1396
|
+
|
|
1397
|
+
ret 10
|
|
1398
|
+
condition-true condition-false
|
|
1399
|
+
ret cc 11 5
|
|
1400
|
+
|
|
1401
|
+
### See Also
|
|
1402
|
+
[BIT](#bit), [CALL](#call), [CP](#cp), [CPD](#cpd), [CPDR](#cpdr), [CPI](#cpi), [CPIR](#cpir), [RETI](#reti), [RETN](#retn)
|
|
1403
|
+
|
|
1404
|
+
---
|
|
1405
|
+
## RETI
|
|
1406
|
+
Returns from an interrupt routine. Note: `RETI` cannot use return conditions.
|
|
1407
|
+
|
|
1408
|
+
### Syntax
|
|
1409
|
+
reti
|
|
1410
|
+
|
|
1411
|
+
### Effects
|
|
1412
|
+
All flags unaffected.
|
|
1413
|
+
|
|
1414
|
+
### T-States
|
|
1415
|
+
14 t-states
|
|
1416
|
+
|
|
1417
|
+
### See Also
|
|
1418
|
+
[DI](#di), [EI](#ei), [IM](#im), [RET](#ret), [RETN](#retn), [RST](#rst)
|
|
1419
|
+
|
|
1420
|
+
---
|
|
1421
|
+
## RETN
|
|
1422
|
+
Returns from the non-maskable interrupt (NMI). Cannot take return conditions.
|
|
1423
|
+
|
|
1424
|
+
### Syntax
|
|
1425
|
+
retn
|
|
1426
|
+
|
|
1427
|
+
### Effects
|
|
1428
|
+
All flags unaffected.
|
|
1429
|
+
|
|
1430
|
+
### T-States
|
|
1431
|
+
14 t-states
|
|
1432
|
+
|
|
1433
|
+
### See Also
|
|
1434
|
+
[DI](#di), [EI](#ei), [IM](#im), [RET](#ret), [RETI](#reti), [RST](#rst)
|
|
1435
|
+
|
|
1436
|
+
---
|
|
1437
|
+
## RL
|
|
1438
|
+
9-bit rotation to the left. The register's bits are shifted left. The carry value is put into 0<sup>th</sup> bit of the register, and the leaving 7th bit is put into the carry.
|
|
1439
|
+
|
|
1440
|
+
### Syntax
|
|
1441
|
+
rl op8
|
|
1442
|
+
|
|
1443
|
+
#### Allowed Instructions
|
|
1444
|
+
rl a
|
|
1445
|
+
rl b
|
|
1446
|
+
rl c
|
|
1447
|
+
rl d
|
|
1448
|
+
rl e
|
|
1449
|
+
rl h
|
|
1450
|
+
rl l
|
|
1451
|
+
rl (hl)
|
|
1452
|
+
rl (ix+n)
|
|
1453
|
+
rl (iy+n)
|
|
1454
|
+
|
|
1455
|
+
### Effects
|
|
1456
|
+
`C` is changed to the leaving 7th bit, `H` and `N` are reset, `P/V` is parity, `S` and `Z` are modified by definition.
|
|
1457
|
+
|
|
1458
|
+
### T-States
|
|
1459
|
+
`r` denotes 8-bit register.
|
|
1460
|
+
|
|
1461
|
+
r 8
|
|
1462
|
+
(hl) 15
|
|
1463
|
+
(ix+X) 23
|
|
1464
|
+
(iy+X) 23
|
|
1465
|
+
|
|
1466
|
+
### See Also
|
|
1467
|
+
[RLA](#rla), [RLC](#rlc), [RLCA](#rlca), [RLD](#rld), [RR](#rr), [RRA](#rra), [RRC](#rrc), [RRCA](#rrca), [RRD](#rrd), [SLA](#sla), [SLL/SL1](#sllsl1), [SRA](#sra), [SRL](#srl)
|
|
1468
|
+
|
|
1469
|
+
---
|
|
1470
|
+
## RLA
|
|
1471
|
+
Performs an `RL A`, but is much faster and `S`, `Z`, and `P/V` flags are preserved.
|
|
1472
|
+
|
|
1473
|
+
### Syntax
|
|
1474
|
+
rla
|
|
1475
|
+
|
|
1476
|
+
### Effects
|
|
1477
|
+
`C` is changed to the leaving 7th bit, `H` and `N` are reset, `P/V`, `S` and `Z` are preserved.
|
|
1478
|
+
|
|
1479
|
+
### T-States
|
|
1480
|
+
4 t-states
|
|
1481
|
+
|
|
1482
|
+
### See Also
|
|
1483
|
+
[RL](#rl), [RLC](#rlc), [RLCA](#rlca), [RLD](#rld), [RR](#rr), [RRA](#rra), [RRC](#rrc), [RRCA](#rrca), [RRD](#rrd), [SLA](#sla), [SLL/SL1](#sllsl1), [SRA](#sra), [SRL](#srl)
|
|
1484
|
+
|
|
1485
|
+
---
|
|
1486
|
+
## RLC
|
|
1487
|
+
8-bit rotation to the left. The bit leaving on the left is copied into the carry, and to bit 0.
|
|
1488
|
+
|
|
1489
|
+
### Syntax
|
|
1490
|
+
rlc op8
|
|
1491
|
+
|
|
1492
|
+
#### Allowed Instructions
|
|
1493
|
+
rlc a
|
|
1494
|
+
rlc b
|
|
1495
|
+
rlc c
|
|
1496
|
+
rlc d
|
|
1497
|
+
rlc e
|
|
1498
|
+
rlc h
|
|
1499
|
+
rlc l
|
|
1500
|
+
rlc (hl)
|
|
1501
|
+
rlc (ix+n)
|
|
1502
|
+
rlc (iy+n)
|
|
1503
|
+
|
|
1504
|
+
### Effects
|
|
1505
|
+
`H` and `N` flags are reset, `P/V` is parity, `S` and `Z` are modified by definition.
|
|
1506
|
+
|
|
1507
|
+
### T-States
|
|
1508
|
+
`r` denotes 8-bit register.
|
|
1509
|
+
|
|
1510
|
+
r 8
|
|
1511
|
+
(hl) 15
|
|
1512
|
+
(ix+X) 23
|
|
1513
|
+
(iy+X) 23
|
|
1514
|
+
|
|
1515
|
+
### See Also
|
|
1516
|
+
[RL](#rl), [RLA](#rla), [RLCA](#rlca), [RLD](#rld), [RR](#rr), [RRA](#rra), [RRC](#rrc), [RRCA](#rrca), [RRD](#rrd), [SLA](#sla), [SLL/SL1](#sllsl1), [SRA](#sra), [SRL](#srl)
|
|
1517
|
+
|
|
1518
|
+
---
|
|
1519
|
+
## RLCA
|
|
1520
|
+
Performs `RLC A` much quicker, and modifies the flags differently.
|
|
1521
|
+
|
|
1522
|
+
### Syntax
|
|
1523
|
+
rlca
|
|
1524
|
+
|
|
1525
|
+
### Effects
|
|
1526
|
+
`S`, `Z`, and `P/V` are preserved, `H` and `N` flags are reset.
|
|
1527
|
+
|
|
1528
|
+
### T-States
|
|
1529
|
+
4 t-states
|
|
1530
|
+
|
|
1531
|
+
### See Also
|
|
1532
|
+
[RL](#rl), [RLA](#rla), [RLC](#rlc), [RLD](#rld), [RR](#rr), [RRA](#rra), [RRC](#rrc), [RRCA](#rrca), [RRD](#rrd), [SLA](#sla), [SLL/SL1](#sllsl1), [SRA](#sra), [SRL](#srl)
|
|
1533
|
+
|
|
1534
|
+
---
|
|
1535
|
+
## RLD
|
|
1536
|
+
Performs a 4-bit leftward rotation of the 12-bit number whose 4 most significant bits are the 4 least significant bits of A, and its 8 least significant bits are in (HL).
|
|
1537
|
+
|
|
1538
|
+
; assume W,X,Y,Z are the set of all possible hex values 0-F
|
|
1539
|
+
ld a,$WX
|
|
1540
|
+
ld (hl),$YZ
|
|
1541
|
+
rld
|
|
1542
|
+
; A = $WY
|
|
1543
|
+
; (HL) = $ZX
|
|
1544
|
+
|
|
1545
|
+
### Syntax
|
|
1546
|
+
rld
|
|
1547
|
+
|
|
1548
|
+
### Effects
|
|
1549
|
+
The `H` and `N` flags are reset, `P/V` is parity, `C` is preserved, and `S` and `Z` are modified by definition.
|
|
1550
|
+
|
|
1551
|
+
### T-States
|
|
1552
|
+
18 t-states
|
|
1553
|
+
|
|
1554
|
+
### See Also
|
|
1555
|
+
[RL](#rl), [RLA](#rla), [RLC](#rlc), [RLCA](#rlca), [RR](#rr), [RRA](#rra), [RRC](#rrc), [RRCA](#rrca), [RRD](#rrd), [SLA](#sla), [SLL/SL1](#sllsl1), [SRA](#sra), [SRL](#srl)
|
|
1556
|
+
|
|
1557
|
+
---
|
|
1558
|
+
## RR
|
|
1559
|
+
9-bit rotation to the right. The carry is copied into bit 7, and the bit leaving on the right is copied into the carry.
|
|
1560
|
+
|
|
1561
|
+
### Syntax
|
|
1562
|
+
rr op8
|
|
1563
|
+
|
|
1564
|
+
#### Allowed Instructions
|
|
1565
|
+
rr a
|
|
1566
|
+
rr b
|
|
1567
|
+
rr c
|
|
1568
|
+
rr d
|
|
1569
|
+
rr e
|
|
1570
|
+
rr h
|
|
1571
|
+
rr l
|
|
1572
|
+
rr (hl)
|
|
1573
|
+
rr (ix+n)
|
|
1574
|
+
rr (iy+n)
|
|
1575
|
+
|
|
1576
|
+
### Effects
|
|
1577
|
+
Carry becomes the bit leaving on the right, `H` and `N` flags are reset, `P/V` is parity, `S` and `Z` are modified by definition.
|
|
1578
|
+
|
|
1579
|
+
### T-States
|
|
1580
|
+
`r` denotes 8-bit register.
|
|
1581
|
+
|
|
1582
|
+
r 8
|
|
1583
|
+
(hl) 15
|
|
1584
|
+
(ix+X) 23
|
|
1585
|
+
(iy+X) 23
|
|
1586
|
+
|
|
1587
|
+
### See Also
|
|
1588
|
+
[RL](#rl), [RLA](#rla), [RLC](#rlc), [RLCA](#rlca), [RLD](#rld), [RRA](#rra), [RRC](#rrc), [RRCA](#rrca), [RRD](#rrd), [SLA](#sla), [SLL/SL1](#sllsl1), [SRA](#sra), [SRL](#srl)
|
|
1589
|
+
|
|
1590
|
+
---
|
|
1591
|
+
## RRA
|
|
1592
|
+
Performs an `RR A`, but is much faster and `P/V`, `S`, and `Z` flags are preserved.
|
|
1593
|
+
|
|
1594
|
+
### Syntax
|
|
1595
|
+
rra
|
|
1596
|
+
|
|
1597
|
+
### Effects
|
|
1598
|
+
The carry becomes the bit leaving on the right, `H` and `N` flags are reset, `P/V`, `S`, and `Z` are preserved.
|
|
1599
|
+
|
|
1600
|
+
### T-States
|
|
1601
|
+
4 t-states
|
|
1602
|
+
|
|
1603
|
+
### See Also
|
|
1604
|
+
[RL](#rl), [RLA](#rla), [RLC](#rlc), [RLCA](#rlca), [RLD](#rld), [RR](#rr), [RRC](#rrc), [RRCA](#rrca), [RRD](#rrd), [SLA](#sla), [SLL/SL1](#sllsl1), [SRA](#sra), [SRL](#srl)
|
|
1605
|
+
|
|
1606
|
+
---
|
|
1607
|
+
## RRC
|
|
1608
|
+
8-bit rotation to the right. The bit leaving on the right is copied into the carry, and into bit 7.
|
|
1609
|
+
|
|
1610
|
+
### Syntax
|
|
1611
|
+
rrc op8
|
|
1612
|
+
|
|
1613
|
+
#### Allowed Instructions
|
|
1614
|
+
rrc a
|
|
1615
|
+
rrc b
|
|
1616
|
+
rrc c
|
|
1617
|
+
rrc d
|
|
1618
|
+
rrc e
|
|
1619
|
+
rrc h
|
|
1620
|
+
rrc l
|
|
1621
|
+
rrc (hl)
|
|
1622
|
+
rrc (ix+n)
|
|
1623
|
+
rrc (iy+n)
|
|
1624
|
+
|
|
1625
|
+
### Effects
|
|
1626
|
+
The carry becomes the value leaving on the right, `H` and `N` are reset, `P/V` is parity, and `S` and `Z` are modified by definition.
|
|
1627
|
+
|
|
1628
|
+
### T-States
|
|
1629
|
+
`r` denotes 8-bit register.
|
|
1630
|
+
|
|
1631
|
+
r 8
|
|
1632
|
+
(hl) 15
|
|
1633
|
+
(ix+X) 23
|
|
1634
|
+
(iy+X) 23
|
|
1635
|
+
|
|
1636
|
+
### See Also
|
|
1637
|
+
[RL](#rl), [RLA](#rla), [RLC](#rlc), [RLCA](#rlca), [RLD](#rld), [RR](#rr), [RRA](#rra), [RRCA](#rrca), [RRD](#rrd), [SLA](#sla), [SLL/SL1](#sllsl1), [SRA](#sra), [SRL](#srl)
|
|
1638
|
+
|
|
1639
|
+
## RRCA
|
|
1640
|
+
Performs `RRC A` faster and modifies the flags differently.
|
|
1641
|
+
|
|
1642
|
+
### Syntax
|
|
1643
|
+
rrca
|
|
1644
|
+
|
|
1645
|
+
### Effects
|
|
1646
|
+
The carry becomes the value leaving on the right, `H` and `N` are reset, `P/V`, `S`, and `Z` are preserved.
|
|
1647
|
+
|
|
1648
|
+
### Uses
|
|
1649
|
+
|
|
1650
|
+
### T-States
|
|
1651
|
+
4 t-states
|
|
1652
|
+
|
|
1653
|
+
### See Also
|
|
1654
|
+
[RL](#rl), [RLA](#rla), [RLC](#rlc), [RLCA](#rlca), [RLD](#rld), [RR](#rr), [RRA](#rra), [RRC](#rrc), [RRD](#rrd), [SLA](#sla), [SLL/SL1](#sllsl1), [SRA](#sra), [SRL](#srl)
|
|
1655
|
+
|
|
1656
|
+
---
|
|
1657
|
+
## RRD
|
|
1658
|
+
Performs a 4-bit rightward rotation of the 12-bit number whose 4 most significant bits are the 4 least significant bits of `A`, and its 8 least significant bits are in `(HL)`.
|
|
1659
|
+
|
|
1660
|
+
; assume W,X,Y,Z are the set of all possible hex values 0-F
|
|
1661
|
+
ld a,$WX
|
|
1662
|
+
ld (hl),$YZ
|
|
1663
|
+
rrd
|
|
1664
|
+
; A = $WZ
|
|
1665
|
+
; (HL) = $XY
|
|
1666
|
+
|
|
1667
|
+
### Syntax
|
|
1668
|
+
rrd
|
|
1669
|
+
|
|
1670
|
+
### Effects
|
|
1671
|
+
The `H` and `N` flags are reset, `P/V` is parity, `C` is preserved, and `S` and `Z` are modified by definition.
|
|
1672
|
+
|
|
1673
|
+
### T-States
|
|
1674
|
+
18 t-states
|
|
1675
|
+
|
|
1676
|
+
### See Also
|
|
1677
|
+
[RL](#rl), [RLA](#rla), [RLC](#rlc), [RLCA](#rlca), [RLD](#rld), [RR](#rr), [RRA](#rra), [RRC](#rrc), [RRCA](#rrca), [SLA](#sla), [SLL/SL1](#sllsl1), [SRA](#sra), [SRL](#srl)
|
|
1678
|
+
|
|
1679
|
+
---
|
|
1680
|
+
## RST
|
|
1681
|
+
The current `PC` value plus three is pushed onto the stack. The MSB is loaded with $00 and the LSB is loaded with `imm8`.
|
|
1682
|
+
|
|
1683
|
+
### Syntax
|
|
1684
|
+
rst imm8
|
|
1685
|
+
|
|
1686
|
+
#### Allowed Instructions
|
|
1687
|
+
rst $00
|
|
1688
|
+
rst $08
|
|
1689
|
+
rst $10
|
|
1690
|
+
rst $18
|
|
1691
|
+
rst $20
|
|
1692
|
+
rst $28
|
|
1693
|
+
rst $30
|
|
1694
|
+
rst $38
|
|
1695
|
+
|
|
1696
|
+
### Effects
|
|
1697
|
+
All flags unaffected.
|
|
1698
|
+
|
|
1699
|
+
### T-States
|
|
1700
|
+
11 t-states
|
|
1701
|
+
|
|
1702
|
+
### See Also
|
|
1703
|
+
[DI](#di), [EI](#ei), [IM](#im), [RET](#ret), [RETI](#reti), [RETN](#retn)
|
|
1704
|
+
|
|
1705
|
+
---
|
|
1706
|
+
## SBC
|
|
1707
|
+
Sum of second operand and carry flag is subtracted from the first operand. Results are written into the first operand.
|
|
1708
|
+
|
|
1709
|
+
### Syntax
|
|
1710
|
+
sbc a,op8 ;8 bits
|
|
1711
|
+
sbc hl,op16 ;16 bits
|
|
1712
|
+
|
|
1713
|
+
#### Allowed Instructions
|
|
1714
|
+
sbc a,a
|
|
1715
|
+
sbc a,b
|
|
1716
|
+
sbc a,c
|
|
1717
|
+
sbc a,d
|
|
1718
|
+
sbc a,e
|
|
1719
|
+
sbc a,h
|
|
1720
|
+
sbc a,l
|
|
1721
|
+
sbc a,ixh
|
|
1722
|
+
sbc a,ixl
|
|
1723
|
+
sbc a,iyh
|
|
1724
|
+
sbc a,iyl
|
|
1725
|
+
sbc a,(hl)
|
|
1726
|
+
sbc a,(ix+n)
|
|
1727
|
+
sbc a,(iy+n)
|
|
1728
|
+
sbc a,n ;8 bits
|
|
1729
|
+
|
|
1730
|
+
sbc hl,bc
|
|
1731
|
+
sbc hl,de
|
|
1732
|
+
sbc hl,hl
|
|
1733
|
+
sbc hl,sp
|
|
1734
|
+
|
|
1735
|
+
### Effects
|
|
1736
|
+
`N` flag is set, `P/V` detects overflow, rest modified by definition.
|
|
1737
|
+
In the case of 16-bit registers, `H` flag is undefined.
|
|
1738
|
+
|
|
1739
|
+
### Uses
|
|
1740
|
+
Multiple precision subtraction
|
|
1741
|
+
|
|
1742
|
+
### T-States
|
|
1743
|
+
`r` denotes 8-bit register.
|
|
1744
|
+
`rr` represents a two byte register pair: `BC`, `DE`, `HL`, `SP`
|
|
1745
|
+
|
|
1746
|
+
r 4
|
|
1747
|
+
X 7
|
|
1748
|
+
(hl) 7
|
|
1749
|
+
(ix+X) 19
|
|
1750
|
+
(iy+X) 19
|
|
1751
|
+
hl, rr 15
|
|
1752
|
+
|
|
1753
|
+
### See Also
|
|
1754
|
+
[ADC](#adc), [ADD](#add), [DAA](#daa), [DEC](#dec), [INC](#inc), [SUB](#sub)
|
|
1755
|
+
|
|
1756
|
+
---
|
|
1757
|
+
## SCF
|
|
1758
|
+
Sets carry flag.
|
|
1759
|
+
|
|
1760
|
+
### Syntax
|
|
1761
|
+
scf
|
|
1762
|
+
|
|
1763
|
+
### Effects
|
|
1764
|
+
Carry flag set, `H` and `N` cleared, rest are preserved.
|
|
1765
|
+
|
|
1766
|
+
### T-States
|
|
1767
|
+
4 t-states
|
|
1768
|
+
|
|
1769
|
+
### See Also
|
|
1770
|
+
[CCF](#ccf)
|
|
1771
|
+
|
|
1772
|
+
---
|
|
1773
|
+
## SET
|
|
1774
|
+
Sets the specified bit.
|
|
1775
|
+
|
|
1776
|
+
### Syntax
|
|
1777
|
+
set n,op8
|
|
1778
|
+
|
|
1779
|
+
#### Allowed Instructions
|
|
1780
|
+
`n` can be any integer from [0,7]. It must be defined on compile time.
|
|
1781
|
+
|
|
1782
|
+
set n,a
|
|
1783
|
+
set n,b
|
|
1784
|
+
set n,c
|
|
1785
|
+
set n,d
|
|
1786
|
+
set n,e
|
|
1787
|
+
set n,h
|
|
1788
|
+
set n,l
|
|
1789
|
+
set n,(hl)
|
|
1790
|
+
set n,(ix+n)
|
|
1791
|
+
set n,(iy+n)
|
|
1792
|
+
|
|
1793
|
+
### Effects
|
|
1794
|
+
All flags preserved.
|
|
1795
|
+
|
|
1796
|
+
### T-States
|
|
1797
|
+
`r` denotes 8-bit register.
|
|
1798
|
+
|
|
1799
|
+
r 8
|
|
1800
|
+
(hl) 15
|
|
1801
|
+
(ix+X) 23
|
|
1802
|
+
(iy+X) 23
|
|
1803
|
+
|
|
1804
|
+
### See Also
|
|
1805
|
+
[AND](#and), [BIT](#bit), [CCF](#ccf), [CPL](#cpl), [OR](#or), [RES](#res), [SCF](#scf), [XOR](#xor)
|
|
1806
|
+
|
|
1807
|
+
---
|
|
1808
|
+
## SLA
|
|
1809
|
+
An arithmetic shift left 1 bit position is performed on the contents of register `r`. The contents of bit 7 are copied to the carry flag. Bit 0 is the least-significant bit.
|
|
1810
|
+
|
|
1811
|
+
### Syntax
|
|
1812
|
+
sla op8
|
|
1813
|
+
|
|
1814
|
+
#### Allowed Instructions
|
|
1815
|
+
sla a
|
|
1816
|
+
sla b
|
|
1817
|
+
sla c
|
|
1818
|
+
sla d
|
|
1819
|
+
sla e
|
|
1820
|
+
sla h
|
|
1821
|
+
sla l
|
|
1822
|
+
sla (hl)
|
|
1823
|
+
sla (ix+n)
|
|
1824
|
+
sla (iy+n)
|
|
1825
|
+
|
|
1826
|
+
### Effects
|
|
1827
|
+
`S` and `Z` by definition, `H` and `N` reset, `C` from bit 7, `P/V` set if result is even.
|
|
1828
|
+
|
|
1829
|
+
### T-States
|
|
1830
|
+
`r` denotes 8-bit register.
|
|
1831
|
+
|
|
1832
|
+
r 8
|
|
1833
|
+
(hl) 15
|
|
1834
|
+
(ix+X) 23
|
|
1835
|
+
(iy+X) 23
|
|
1836
|
+
|
|
1837
|
+
### See Also
|
|
1838
|
+
[RL](#rl), [RLA](#rla), [RLC](#rlc), [RLCA](#rlca), [RLD](#rld), [RR](#rr), [RRA](#rra), [RRC](#rrc), [RRCA](#rrca), [RRD](#rrd), [SLL/SL1](#sllsl1), [SRA](#sra), [SRL](#srl)
|
|
1839
|
+
|
|
1840
|
+
---
|
|
1841
|
+
## SLL/SL1
|
|
1842
|
+
An "undocumented" instruction. Functions like `SLA`, except a 1 is inserted into the low bit.
|
|
1843
|
+
|
|
1844
|
+
### Syntax
|
|
1845
|
+
sll op8
|
|
1846
|
+
|
|
1847
|
+
#### Allowed Instructions
|
|
1848
|
+
sll a
|
|
1849
|
+
sll b
|
|
1850
|
+
sll c
|
|
1851
|
+
sll d
|
|
1852
|
+
sll e
|
|
1853
|
+
sll h
|
|
1854
|
+
sll l
|
|
1855
|
+
sll (hl)
|
|
1856
|
+
sll (ix+n)
|
|
1857
|
+
sll (iy+n)
|
|
1858
|
+
|
|
1859
|
+
### Effects
|
|
1860
|
+
`S` and `Z` by definition, `H` and `N` reset, `C` from bit 7, `P/V` set if result is even.
|
|
1861
|
+
|
|
1862
|
+
### T-States
|
|
1863
|
+
`r` denotes 8-bit register. `IX` and `IY` values assumed from `SLA`. Needs confirmation.
|
|
1864
|
+
|
|
1865
|
+
r 8
|
|
1866
|
+
(hl) 15
|
|
1867
|
+
(ix+X) 23
|
|
1868
|
+
(iy+X) 23
|
|
1869
|
+
|
|
1870
|
+
### See Also
|
|
1871
|
+
[RL](#rl), [RLA](#rla), [RLC](#rlc), [RLCA](#rlca), [RLD](#rld), [RR](#rr), [RRA](#rra), [RRC](#rrc), [RRCA](#rrca), [RRD](#rrd), [SLA](#sla), [SRA](#sra), [SRL](#srl)
|
|
1872
|
+
|
|
1873
|
+
---
|
|
1874
|
+
## SRA
|
|
1875
|
+
Arithmetic shift right 1 bit, bit 0 goes to carry flag, bit 7 remains unchanged.
|
|
1876
|
+
|
|
1877
|
+
### Syntax
|
|
1878
|
+
sra op8
|
|
1879
|
+
|
|
1880
|
+
#### Allowed Instructions
|
|
1881
|
+
sra a
|
|
1882
|
+
sra b
|
|
1883
|
+
sra c
|
|
1884
|
+
sra d
|
|
1885
|
+
sra e
|
|
1886
|
+
sra h
|
|
1887
|
+
sra l
|
|
1888
|
+
sra (hl)
|
|
1889
|
+
sra (ix+n)
|
|
1890
|
+
sra (iy+n)
|
|
1891
|
+
|
|
1892
|
+
### Effects
|
|
1893
|
+
`S` and `Z` set according to definition, `H` and `N` reset, `C` from bit 0, `P/V` if parity is 0.
|
|
1894
|
+
|
|
1895
|
+
### T-States
|
|
1896
|
+
`r` denotes 8-bit register.
|
|
1897
|
+
|
|
1898
|
+
r 8
|
|
1899
|
+
(hl) 15
|
|
1900
|
+
(ix+X) 23
|
|
1901
|
+
(iy+X) 23
|
|
1902
|
+
|
|
1903
|
+
### See Also
|
|
1904
|
+
[RL](#rl), [RLA](#rla), [RLC](#rlc), [RLCA](#rlca), [RLD](#rld), [RR](#rr), [RRA](#rra), [RRC](#rrc), [RRCA](#rrca), [RRD](#rrd), [SLA](#sla), [SLL/SL1](#sllsl1), [SRL](#srl)
|
|
1905
|
+
|
|
1906
|
+
---
|
|
1907
|
+
## SRL
|
|
1908
|
+
Like `SRA`, except a 0 is put into bit 7. The bits are all shifted right, with bit 0 put into the carry flag.
|
|
1909
|
+
|
|
1910
|
+
### Syntax
|
|
1911
|
+
srl op8
|
|
1912
|
+
|
|
1913
|
+
#### Allowed Instructions
|
|
1914
|
+
srl a
|
|
1915
|
+
srl b
|
|
1916
|
+
srl c
|
|
1917
|
+
srl d
|
|
1918
|
+
srl e
|
|
1919
|
+
srl h
|
|
1920
|
+
srl l
|
|
1921
|
+
srl (hl)
|
|
1922
|
+
srl (ix+n)
|
|
1923
|
+
srl (iy+n)
|
|
1924
|
+
|
|
1925
|
+
### Effects
|
|
1926
|
+
`S`, `H`, and `N` flags reset, `Z` if result is zero, `P/V` set if parity is even, `C` from bit 0.
|
|
1927
|
+
|
|
1928
|
+
### T-States
|
|
1929
|
+
`r` denotes 8-bit register.
|
|
1930
|
+
|
|
1931
|
+
r 8
|
|
1932
|
+
(hl) 15
|
|
1933
|
+
(ix+X) 23
|
|
1934
|
+
(iy+X) 23
|
|
1935
|
+
|
|
1936
|
+
### See Also
|
|
1937
|
+
[RL](#rl), [RLA](#rla), [RLC](#rlc), [RLCA](#rlca), [RLD](#rld), [RR](#rr), [RRA](#rra), [RRC](#rrc), [RRCA](#rrca), [RRD](#rrd), [SLA](#sla), [SLL/SL1](#sllsl1), [SRA](#sra)
|
|
1938
|
+
|
|
1939
|
+
---
|
|
1940
|
+
## SUB
|
|
1941
|
+
`SUB` stands for subtract but only takes one input. It subtracts the input from the accumulator and writes back to it.
|
|
1942
|
+
|
|
1943
|
+
### Syntax
|
|
1944
|
+
sub op8 ;8 bit
|
|
1945
|
+
|
|
1946
|
+
#### Allowed Instructions
|
|
1947
|
+
sub a
|
|
1948
|
+
sub b
|
|
1949
|
+
sub c
|
|
1950
|
+
sub d
|
|
1951
|
+
sub e
|
|
1952
|
+
sub h
|
|
1953
|
+
sub l
|
|
1954
|
+
sub n ;8 bit constant
|
|
1955
|
+
|
|
1956
|
+
sub (hl)
|
|
1957
|
+
sub (ix+n)
|
|
1958
|
+
sub (iy+n)
|
|
1959
|
+
|
|
1960
|
+
### Effects
|
|
1961
|
+
`N` flag set, `P/V` is overflow, rest modified by definition.
|
|
1962
|
+
|
|
1963
|
+
### Uses
|
|
1964
|
+
Allows you to subtract two 8 bit integers. Useful in if you have an offset and want to eliminate certain items.
|
|
1965
|
+
|
|
1966
|
+
### T-States
|
|
1967
|
+
`r` denotes 8-bit register.
|
|
1968
|
+
|
|
1969
|
+
r 4
|
|
1970
|
+
X 7
|
|
1971
|
+
(hl) 7
|
|
1972
|
+
(ix+X) 19
|
|
1973
|
+
(iy+X) 19
|
|
1974
|
+
|
|
1975
|
+
### See Also
|
|
1976
|
+
[ADC](#adc), [ADD](#add), [DAA](#daa), [DEC](#dec), [INC](#inc), [SBC](#sbc)
|
|
1977
|
+
|
|
1978
|
+
---
|
|
1979
|
+
## XOR
|
|
1980
|
+
`XOR` is an instruction that takes one 8-bit input and compares it with the accumulator. `XOR` is similar to `OR`, except for one thing: only 1 of the 2 test bits can be set or else it will result in a zero. The final answer is stored to the accumulator.
|
|
1981
|
+
|
|
1982
|
+
0 and 0 result: 0
|
|
1983
|
+
0 and 1 result: 1
|
|
1984
|
+
1 and 0 result: 1
|
|
1985
|
+
1 and 1 result: 0
|
|
1986
|
+
|
|
1987
|
+
### Syntax
|
|
1988
|
+
xor op8
|
|
1989
|
+
|
|
1990
|
+
#### Allowed Instructions
|
|
1991
|
+
xor a
|
|
1992
|
+
xor b
|
|
1993
|
+
xor c
|
|
1994
|
+
xor d
|
|
1995
|
+
xor e
|
|
1996
|
+
xor h
|
|
1997
|
+
xor l
|
|
1998
|
+
xor ixh
|
|
1999
|
+
xor ixl
|
|
2000
|
+
xor iyh
|
|
2001
|
+
xor iyl
|
|
2002
|
+
xor (hl)
|
|
2003
|
+
xor (ix+n)
|
|
2004
|
+
xor (iy+n)
|
|
2005
|
+
xor n ;8 bit constant
|
|
2006
|
+
|
|
2007
|
+
### Effects
|
|
2008
|
+
`C` and `N` flags cleared. `P/V` is parity, and rest are modified by definition.
|
|
2009
|
+
|
|
2010
|
+
### Uses
|
|
2011
|
+
XORing numbers is used a lot to invert sprites and such. It is also very useful in bit-masking. See here for more information about bit-masking.
|
|
2012
|
+
|
|
2013
|
+
### T-States
|
|
2014
|
+
`r` denotes 8-bit register.
|
|
2015
|
+
|
|
2016
|
+
r 4
|
|
2017
|
+
X 7
|
|
2018
|
+
(hl) 7
|
|
2019
|
+
(ix+X) 19
|
|
2020
|
+
(iy+X) 19
|
|
2021
|
+
|
|
2022
|
+
### See Also
|
|
2023
|
+
[AND](#and), [BIT](#bit), [CCF](#ccf), [CPL](#cpl), [OR](#or), [RES](#res), [SCF](#scf), [SET](#set)
|
|
2024
|
+
|
|
2025
|
+
---
|