-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgb-instructions.txt
524 lines (299 loc) · 11 KB
/
gb-instructions.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
GameBoy Assembly Language Commands, 27-Mar-98
---------------------------------------------
Since books on the Z80 are getting harder & harder to find,
hopefully the information here might be helpful to those
trying to understand assembly language specific to GameBoy.
If 'Flags affected' is not given for a command then none
are affected.
From: https://raw.githubusercontent.com/gb-archive/salvage/master/txt-files/gb-instructions.txt
Commands
--------
ADC A,n - Add n + Carry flag to A.
n = A,B,C,D,E,H,L,(HL),#
Flags affected:
Z - Set if result is zero.
N - Reset.
H - Set if carry from bit 3.
C - Set if carry from bit 7.
ADD A,n - Add n to A.
n = A,B,C,D,E,H,L,(HL),#
Flags affected:
Z - Set if result is zero.
N - Reset.
H - Set if carry from bit 3.
C - Set if carry from bit 7.
ADD HL,n - Add n to HL.
n = BC,DE,HL
Flags affected:
Z - Not affected.
N - Reset.
H - Set if carry from bit 11.
C - Set if carry from bit 15.
ADD SP,n - Add n to Stack Pointer (SP).
n = one byte signed immediate value.
Flags affected:
Z - Reset.
N - Reset.
H - Set or reset according to operation.
C - Set or reset according to operation.
AND n - Logically AND n with A, result in A.
n = A,B,C,D,E,H,L,(HL),#
Flags affected:
Z - Set if result is zero.
N - Reset.
H - Set.
C - Reset.
BIT b,r - Test bit b in register r.
b = 0 - 7, r = A,B,C,D,E,H,L,(HL)
Flags affected:
Z - Set if bit b of register r is 0.
N - Reset.
H - Set.
C - Not affected.
CALL n - Push address of next instruction onto
stack and then jump to address n.
CALL cc,n - Call address n if following condition
is true:
cc = NZ, Call if Z flag is reset.
cc = Z, Call if Z flag is set.
cc = NC, Call if C flag is reset.
cc = C, Call if C flag is set.
CCF - Complement carry flag.
If C flag is set, then reset it.
If C flag is reset, then set it.
Flags affected:
Z - Not affected.
N - Reset.
H - Reset.
C - Complemented.
CP n - Compare A with n.
This is basically an A - n subtraction
instruction but the results are thrown away.
n = A,B,C,D,E,H,L,(HL),#
Flags affected:
Z - Set if result is zero. (Set if A = n.)
N - Set.
H - Set if no borrow from bit 4.
C - Set for no borrow. (Set if A < n.)
CPL - Complement A register. (Flip all bits.)
Flags affected:
Z - Not affected.
N - Set.
H - Set.
C - Not affected.
DAA - Decimal adjust register A.
This instruction adjusts register A so that the
correct representation of Binary Coded Decimal
(BCD) is obtained.
Flags affected:
Z - Set if register A is zero.
N - Not affected.
H - Reset.
C - Set or reset according to operation.
DEC n - Decrement register n.
n = A,B,C,D,E,H,L,(HL)
Flags affected:
Z - Set if reselt is zero.
N - Set.
H - Set if no borrow from bit 4.
C - Not affected.
DEC nn - Decrement register nn.
nn = BC,DE,HL,SP
Flags affected:
None
DI - Disable interrupts.
Flags affected:
None.
EI - Enable interrupts.
This intruction enables interrupts but not immediately.
Interrupts are enabled after instruction after EI is
executed.
Flags affected:
None.
INC n - Increment register n.
n = A,B,C,D,E,H,L,(HL)
Flags affected:
Z - Set if result is zero.
N - Reset.
H - Set if carry from bit 3.
C - Not affected.
INC nn - Increment register nn.
nn = BC,DE,HL,SP
Flags affected:
None.
JP n - Jump to address n.
n = two byte immediate value. (LS byte first.)
JP cc,n - Jump to address n if following condition
is true:
n = two byte immediate value. (LS byte first.)
cc = NZ, Jump if Z flag is reset.
cc = Z, Jump if Z flag is set.
cc = NC, Jump if C flag is reset.
cc = C, Jump if C flag is set.
JP (HL) - Jump to address contained in HL.
JR n - Add n to current address and jump to it.
n = one byte signed immediate value
JR cc,n - If following condition is true then
add n to current address and jump to it:
n = one byte signed immediate value
cc = NZ, Jump if Z flag is reset.
cc = Z, Jump if Z flag is set.
cc = NC, Jump if C flag is reset.
cc = C, Jump if C flag is set.
HALT - Power down CPU until an interrupt occurs.
LD A,n - Put value n into A.
n = A,B,C,D,E,H,L,(BC),(DE),(HL),(nnnn),#
LD n,A - Put value A into n.
n = A,B,C,D,E,H,L,(BC),(DE),(HL),(nnnn)
LD A,(C) - Put value at address $FF00 + register C into A.
LD A,(HL+) - Same as LD A,(HLI).
LD A,(HL-) - Same as LD A,(HLD).
LD A,(HLI) - Put value at address HL into A. Increment HL.
LD A,(HLD) - Put value at address HL into A. Decrement HL.
LD (C),A - Put A into address $FF00 + register C.
LD (HL+),A - Same as LD (HLI),A.
LD (HL-),A - Same as LD (HLD),A.
LD (HLI),A - Put A into memory address HL. Increment HL.
LD (HLD),A - Put A into memory address HL. Decrement HL.
LD r1,r2 - Put value r2 into r1.
r1,r2 = A,B,C,D,E,H,L,(HL)
LD n,nn - Put value nn into n.
n = BC,DE,HL,SP
nn = 16 bit immediate value
LD HL,(SP+n) - Same as LDHL SP,n.
LD SP,HL - Put HL into Stack Pointer (SP).
LD (n),SP - Put Stack Pointer (SP) at address n.
n = two byte immediate address.
LDD A,(HL) - Same as LD A,(HLD).
LDD (HL),A - Same as LD (HLD),A.
LDH (n),A - Put A into memory address $FF00+n.
n = one byte immediate value.
LDH A,(n) - Put memory address $FF00+n into A.
n = one byte immediate value.
LDHL SP,n - Put SP + n into HL.
n = one byte signed immediate value.
Flags affected:
Z - Reset.
N - Reset.
H - Set or reset according to operation.
C - Set or reset according to operation.
LDI A,(HL) - Same as LD A,(HLI).
LDI (HL),A - Same as LD (HLI),A.
NOP - No operation.
OR n - Logical OR n with register A, result in A.
n = A,B,C,D,E,H,L,(HL),#
Flags affected:
Z - Set if result is zero.
N - Reset.
H - Reset.
C - Reset.
POP nn - Pop two bytes off stack into register pair nn.
Increment Stack Pointer (SP) twice.
nn = AF,BC,DE,HL
PUSH nn - Push register pair nn onto stack.
Decrement Stack Pointer (SP) twice.
nn = AF,BC,DE,HL
RES b,r - Reset bit b in register r.
b = 0 - 7, r = A,B,C,D,E,H,L,(HL)
Flags affected:
None.
RET - Pop two bytes from stack & jump to that address.
RET cc - Return if following condition is true:
cc = NZ, Return if Z flag is reset.
cc = Z, Return if Z flag is set.
cc = NC, Return if C flag is reset.
cc = C, Return if C flag is set.
RETI - Pop two bytes from stack & jump to that address
then enable interrupts.
RL n - Rotate n left through Carry flag.
n = A,B,C,D,E,H,L,(HL)
Flags affected:
Z - Set if result is zero.
N - Reset.
H - Reset.
C - Contains old bit 7 data.
RLC n - Rotate n left. Old bit 7 to Carry flag.
n = A,B,C,D,E,H,L,(HL)
Flags affected:
Z - Set if result is zero.
N - Reset.
H - Reset.
C - Contains old bit 7 data.
RR n - Rotate n right through Carry flag.
n = A,B,C,D,E,H,L,(HL)
Flags affected:
Z - Set if result is zero.
N - Reset.
H - Reset.
C - Contains old bit 0 data.
RRC n - Rotate n right. Old bit 0 to Carry flag.
n = A,B,C,D,E,H,L,(HL)
Flags affected:
Z - Set if result is zero.
N - Reset.
H - Reset.
C - Contains old bit 0 data.
RST n - Push present address onto stack.
Jump to address $0000 + n.
n = $00,$08,$10,$18,$20,$28,$30,$38
SBC A,n - Subtract n + Carry flag from A.
n = A,B,C,D,E,H,L,(HL),#
Flags affected:
Z - Set if result is zero.
N - Set.
H - Set if no borrow from bit 4.
C - Set if no borrow.
SCF - Set Carry flag.
Flags affected:
Z - Not affected.
N - Reset.
H - Reset.
C - Set.
SET b,r - Set bit b in register r.
b = 0 - 7, r = A,B,C,D,E,H,L,(HL)
Flags affected:
None.
SLA n - Shift n left into Carry. LSB of n set to 0.
n = A,B,C,D,E,H,L,(HL)
Flags affected:
Z - Set if result is zero.
N - Reset.
H - Reset.
C - Contains old bit 7 data.
SRA n - Shift n right into Carry. MSB doesn't change.
n = A,B,C,D,E,H,L,(HL)
Flags affected:
Z - Set if result is zero.
N - Reset.
H - Reset.
C - Contains old bit 0 data.
SRL n - Shift n right into Carry. MSB set to 0.
n = A,B,C,D,E,H,L,(HL)
Flags affected:
Z - Set if result is zero.
N - Reset.
H - Reset.
C - Contains old bit 0 data.
STOP - ???
SUB n - Subtract n from A.
n = A,B,C,D,E,H,L,(HL),#
Flags affected:
Z - Set if result is zero.
N - Set.
H - Set if no borrow from bit 4.
C - Set if no borrow.
SWAP n - Swap upper & lower bits of n.
n = A,B,C,D,E,H,L,(HL)
Flags affected:
Z - Set if result is zero.
N - Reset.
H - Reset.
C - Reset.
XOR n - Logical exclusive OR n with
register A, result in A.
n = A,B,C,D,E,H,L,(HL),#
Flags affected:
Z - Set if result is zero.
N - Reset.
H - Reset.
C - Reset.