1GBZ80(7)             BSD Miscellaneous Information Manual             GBZ80(7)
2

NAME

4     gbz80 — CPU opcode reference
5

DESCRIPTION

7     This is the list of opcodes supported by rgbasm(1), including a short de‐
8     scription, the number of bytes needed to encode them and the number of
9     CPU cycles at 1MHz (or 2MHz in GBC dual speed mode) needed to complete
10     them.
11
12     Note: All arithmetic/logic operations that use register A as destination
13     can omit the destination as it is assumed to be register A by default.
14     The following two lines have the same effect:
15
16           OR A,B
17           OR B
18

LEGEND

20     List of abbreviations used in this document.
21
22     r8      Any of the 8-bit registers (A, B, C, D, E, H, L).
23
24     r16     Any of the general-purpose 16-bit registers (BC, DE, HL).
25
26     n8      8-bit integer constant.
27
28     n16     16-bit integer constant.
29
30     e8      8-bit offset (-128 to 127).
31
32     u3      3-bit unsigned integer constant (0 to 7).
33
34     cc      Condition codes:
35             Z       Execute if Z is set.
36             NZ      Execute if Z is not set.
37             C       Execute if C is set.
38             NC      Execute if C is not set.
39             ! cc    Negates a condition code.
40
41     vec     One of the RST vectors (0x00, 0x08, 0x10, 0x18, 0x20, 0x28, 0x30,
42             and 0x38).
43

INSTRUCTION OVERVIEW

45   8-bit Arithmetic and Logic Instructions
46     ADC A,r8
47     ADC A,[HL]
48     ADC A,n8
49     ADD A,r8
50     ADD A,[HL]
51     ADD A,n8
52     AND A,r8
53     AND A,[HL]
54     AND A,n8
55     CP A,r8
56     CP A,[HL]
57     CP A,n8
58     DEC r8
59     DEC [HL]
60     INC r8
61     INC [HL]
62     OR A,r8
63     OR A,[HL]
64     OR A,n8
65     SBC A,r8
66     SBC A,[HL]
67     SBC A,n8
68     SUB A,r8
69     SUB A,[HL]
70     SUB A,n8
71     XOR A,r8
72     XOR A,[HL]
73     XOR A,n8
74
75   16-bit Arithmetic Instructions
76     ADD HL,r16
77     DEC r16
78     INC r16
79
80   Bit Operations Instructions
81     BIT u3,r8
82     BIT u3,[HL]
83     RES u3,r8
84     RES u3,[HL]
85     SET u3,r8
86     SET u3,[HL]
87     SWAP r8
88     SWAP [HL]
89
90   Bit Shift Instructions
91     RL r8
92     RL [HL]
93     RLA
94     RLC r8
95     RLC [HL]
96     RLCA
97     RR r8
98     RR [HL]
99     RRA
100     RRC r8
101     RRC [HL]
102     RRCA
103     SLA r8
104     SLA [HL]
105     SRA r8
106     SRA [HL]
107     SRL r8
108     SRL [HL]
109
110   Load Instructions
111     LD r8,r8
112     LD r8,n8
113     LD r16,n16
114     LD [HL],r8
115     LD [HL],n8
116     LD r8,[HL]
117     LD [r16],A
118     LD [n16],A
119     LDH [n16],A
120     LDH [C],A
121     LD A,[r16]
122     LD A,[n16]
123     LDH A,[n16]
124     LDH A,[C]
125     LD [HLI],A
126     LD [HLD],A
127     LD A,[HLI]
128     LD A,[HLD]
129
130   Jumps and Subroutines
131     CALL n16
132     CALL cc,n16
133     JP HL
134     JP n16
135     JP cc,n16
136     JR e8
137     JR cc,e8
138     RET cc
139     RET
140     RETI
141     RST vec
142
143   Stack Operations Instructions
144     ADD HL,SP
145     ADD SP,e8
146     DEC SP
147     INC SP
148     LD SP,n16
149     LD [n16],SP
150     LD HL,SP+e8
151     LD SP,HL
152     POP AF
153     POP r16
154     PUSH AF
155     PUSH r16
156
157   Miscellaneous Instructions
158     CCF
159     CPL
160     DAA
161     DI
162     EI
163     HALT
164     NOP
165     SCF
166     STOP
167

INSTRUCTION REFERENCE

169   ADC A,r8
170     Add the value in r8 plus the carry flag to A.
171
172     Cycles: 1
173
174     Bytes: 1
175
176     Flags:
177     Z       Set if result is 0.
178     N       0
179     H       Set if overflow from bit 3.
180     C       Set if overflow from bit 7.
181
182   ADC A,[HL]
183     Add the byte pointed to by HL plus the carry flag to A.
184
185     Cycles: 2
186
187     Bytes: 1
188
189     Flags: See ADC A,r8
190
191   ADC A,n8
192     Add the value n8 plus the carry flag to A.
193
194     Cycles: 2
195
196     Bytes: 2
197
198     Flags: See ADC A,r8
199
200   ADD A,r8
201     Add the value in r8 to A.
202
203     Cycles: 1
204
205     Bytes: 1
206
207     Flags:
208     Z       Set if result is 0.
209     N       0
210     H       Set if overflow from bit 3.
211     C       Set if overflow from bit 7.
212
213   ADD A,[HL]
214     Add the byte pointed to by HL to A.
215
216     Cycles: 2
217
218     Bytes: 1
219
220     Flags: See ADD A,r8
221
222   ADD A,n8
223     Add the value n8 to A.
224
225     Cycles: 2
226
227     Bytes: 2
228
229     Flags: See ADD A,r8
230
231   ADD HL,r16
232     Add the value in r16 to HL.
233
234     Cycles: 2
235
236     Bytes: 1
237
238     Flags:
239     N       0
240     H       Set if overflow from bit 11.
241     C       Set if overflow from bit 15.
242
243   ADD HL,SP
244     Add the value in SP to HL.
245
246     Cycles: 2
247
248     Bytes: 1
249
250     Flags: See ADD HL,r16
251
252   ADD SP,e8
253     Add the signed value e8 to SP.
254
255     Cycles: 4
256
257     Bytes: 2
258
259     Flags:
260     Z       0
261     N       0
262     H       Set if overflow from bit 3.
263     C       Set if overflow from bit 7.
264
265   AND A,r8
266     Bitwise AND between the value in r8 and A.
267
268     Cycles: 1
269
270     Bytes: 1
271
272     Flags:
273     Z       Set if result is 0.
274     N       0
275     H       1
276     C       0
277
278   AND A,[HL]
279     Bitwise AND between the byte pointed to by HL and A.
280
281     Cycles: 2
282
283     Bytes: 1
284
285     Flags: See AND A,r8
286
287   AND A,n8
288     Bitwise AND between the value in n8 and A.
289
290     Cycles: 2
291
292     Bytes: 2
293
294     Flags: See AND A,r8
295
296   BIT u3,r8
297     Test bit u3 in register r8, set the zero flag if bit not set.
298
299     Cycles: 2
300
301     Bytes: 2
302
303     Flags:
304     Z       Set if the selected bit is 0.
305     N       0
306     H       1
307
308   BIT u3,[HL]
309     Test bit u3 in the byte pointed by HL, set the zero flag if bit not set.
310
311     Cycles: 3
312
313     Bytes: 2
314
315     Flags: See BIT u3,r8
316
317   CALL n16
318     Call address n16.  This pushes the address of the instruction after the
319     CALL on the stack, such that RET can pop it later; then, it executes an
320     implicit JP n16.
321
322     Cycles: 6
323
324     Bytes: 3
325
326     Flags: None affected.
327
328   CALL cc,n16
329     Call address n16 if condition cc is met.
330
331     Cycles: 6 taken / 3 untaken
332
333     Bytes: 3
334
335     Flags: None affected.
336
337   CCF
338     Complement Carry Flag.
339
340     Cycles: 1
341
342     Bytes: 1
343
344     Flags:
345     N       0
346     H       0
347     C       Inverted.
348
349   CP A,r8
350     Subtract the value in r8 from A and set flags accordingly, but don't
351     store the result.  This is useful for ComParing values.
352
353     Cycles: 1
354
355     Bytes: 1
356
357     Flags:
358     Z       Set if result is 0.
359     N       1
360     H       Set if borrow from bit 4.
361     C       Set if borrow (i.e. if r8 > A).
362
363   CP A,[HL]
364     Subtract the byte pointed to by HL from A and set flags accordingly, but
365     don't store the result.
366
367     Cycles: 2
368
369     Bytes: 1
370
371     Flags: See CP A,r8
372
373   CP A,n8
374     Subtract the value n8 from A and set flags accordingly, but don't store
375     the result.
376
377     Cycles: 2
378
379     Bytes: 2
380
381     Flags: See CP A,r8
382
383   CPL
384     ComPLement accumulator (A = ~A).
385
386     Cycles: 1
387
388     Bytes: 1
389
390     Flags:
391     N       1
392     H       1
393
394   DAA
395     Decimal Adjust Accumulator to get a correct BCD representation after an
396     arithmetic instruction.
397
398     Cycles: 1
399
400     Bytes: 1
401
402     Flags:
403     Z       Set if result is 0.
404     H       0
405     C       Set or reset depending on the operation.
406
407   DEC r8
408     Decrement value in register r8 by 1.
409
410     Cycles: 1
411
412     Bytes: 1
413
414     Flags:
415     Z       Set if result is 0.
416     N       1
417     H       Set if borrow from bit 4.
418
419   DEC [HL]
420     Decrement the byte pointed to by HL by 1.
421
422     Cycles: 3
423
424     Bytes: 1
425
426     Flags: See DEC r8
427
428   DEC r16
429     Decrement value in register r16 by 1.
430
431     Cycles: 2
432
433     Bytes: 1
434
435     Flags: None affected.
436
437   DEC SP
438     Decrement value in register SP by 1.
439
440     Cycles: 2
441
442     Bytes: 1
443
444     Flags: None affected.
445
446   DI
447     Disable Interrupts by clearing the IME flag.
448
449     Cycles: 1
450
451     Bytes: 1
452
453     Flags: None affected.
454
455   EI
456     Enable Interrupts by setting the IME flag.  The flag is only set after
457     the instruction following EI.
458
459     Cycles: 1
460
461     Bytes: 1
462
463     Flags: None affected.
464
465   HALT
466     Enter CPU low-power consumption mode until an interrupt occurs.  The ex‐
467     act behavior of this instruction depends on the state of the IME flag.
468
469     IME set
470             The CPU enters low-power mode until after an interrupt is about
471             to be serviced.  The handler is executed normally, and the CPU
472             resumes execution after the HALT when that returns.
473
474     IME not set
475             The behavior depends on whether an interrupt is pending (i.e.
476             ‘[IE] & [IF]’ is non-zero).
477
478             None pending
479                     As soon as an interrupt becomes pending, the CPU resumes
480                     execution.  This is like the above, except that the han‐
481                     dler is not called.
482
483             Some pending
484                     The CPU continues execution after the HALT, but the byte
485                     after it is read twice in a row (PC is not incremented,
486                     due to a hardware bug).
487
488     Cycles: -
489
490     Bytes: 1
491
492     Flags: None affected.
493
494   INC r8
495     Increment value in register r8 by 1.
496
497     Cycles: 1
498
499     Bytes: 1
500
501     Flags:
502     Z       Set if result is 0.
503     N       0
504     H       Set if overflow from bit 3.
505
506   INC [HL]
507     Increment the byte pointed to by HL by 1.
508
509     Cycles: 3
510
511     Bytes: 1
512
513     Flags: See INC r8
514
515   INC r16
516     Increment value in register r16 by 1.
517
518     Cycles: 2
519
520     Bytes: 1
521
522     Flags: None affected.
523
524   INC SP
525     Increment value in register SP by 1.
526
527     Cycles: 2
528
529     Bytes: 1
530
531     Flags: None affected.
532
533   JP n16
534     Jump to address n16; effectively, store n16 into PC.
535
536     Cycles: 4
537
538     Bytes: 3
539
540     Flags: None affected.
541
542   JP cc,n16
543     Jump to address n16 if condition cc is met.
544
545     Cycles: 4 taken / 3 untaken
546
547     Bytes: 3
548
549     Flags: None affected.
550
551   JP HL
552     Jump to address in HL; effectively, load PC with value in register HL.
553
554     Cycles: 1
555
556     Bytes: 1
557
558     Flags: None affected.
559
560   JR e8
561     Relative Jump by adding e8 to the address of the instruction following
562     the JR.  To clarify, an operand of 0 is equivalent to no jumping.
563
564     Cycles: 3
565
566     Bytes: 2
567
568     Flags: None affected.
569
570   JR cc,e8
571     Relative Jump by adding e8 to the current address if condition cc is met.
572
573     Cycles: 3 taken / 2 untaken
574
575     Bytes: 2
576
577     Flags: None affected.
578
579   LD r8,r8
580     Load (copy) value in register on the right into register on the left.
581
582     Cycles: 1
583
584     Bytes: 1
585
586     Flags: None affected.
587
588   LD r8,n8
589     Load value n8 into register r8.
590
591     Cycles: 2
592
593     Bytes: 2
594
595     Flags: None affected.
596
597   LD r16,n16
598     Load value n16 into register r16.
599
600     Cycles: 3
601
602     Bytes: 3
603
604     Flags: None affected.
605
606   LD [HL],r8
607     Store value in register r8 into the byte pointed to by register HL.
608
609     Cycles: 2
610
611     Bytes: 1
612
613     Flags: None affected.
614
615   LD [HL],n8
616     Store value n8 into the byte pointed to by register HL.
617
618     Cycles: 3
619
620     Bytes: 2
621
622     Flags: None affected.
623
624   LD r8,[HL]
625     Load value into register r8 from the byte pointed to by register HL.
626
627     Cycles: 2
628
629     Bytes: 1
630
631     Flags: None affected.
632
633   LD [r16],A
634     Store value in register A into the byte pointed to by register r16.
635
636     Cycles: 2
637
638     Bytes: 1
639
640     Flags: None affected.
641
642   LD [n16],A
643     Store value in register A into the byte at address n16.
644
645     Cycles: 4
646
647     Bytes: 3
648
649     Flags: None affected.
650
651   LDH [n16],A
652     Store value in register A into the byte at address n16, provided the ad‐
653     dress is between $FF00 and $FFFF.
654
655     Cycles: 3
656
657     Bytes: 2
658
659     Flags: None affected.
660
661     This is sometimes written as ‘LDIO [n16],A’, or ‘LD [$FF00+n8],A’.
662
663   LDH [C],A
664     Store value in register A into the byte at address $FF00+C.
665
666     Cycles: 2
667
668     Bytes: 1
669
670     Flags: None affected.
671
672     This is sometimes written as ‘LDIO [C],A’, or ‘LD [$FF00+C],A’.
673
674   LD A,[r16]
675     Load value in register A from the byte pointed to by register r16.
676
677     Cycles: 2
678
679     Bytes: 1
680
681     Flags: None affected.
682
683   LD A,[n16]
684     Load value in register A from the byte at address n16.
685
686     Cycles: 4
687
688     Bytes: 3
689
690     Flags: None affected.
691
692   LDH A,[n16]
693     Load value in register A from the byte at address n16, provided the ad‐
694     dress is between $FF00 and $FFFF.
695
696     Cycles: 3
697
698     Bytes: 2
699
700     Flags: None affected.
701
702     This is sometimes written as ‘LDIO A,[n16]’, or ‘LD A,[$FF00+n8]’.
703
704   LDH A,[C]
705     Load value in register A from the byte at address $FF00+c.
706
707     Cycles: 2
708
709     Bytes: 1
710
711     Flags: None affected.
712
713     This is sometimes written as ‘LDIO A,[C]’, or ‘LD A,[$FF00+C]’.
714
715   LD [HLI],A
716     Store value in register A into the byte pointed by HL and increment HL
717     afterwards.
718
719     Cycles: 2
720
721     Bytes: 1
722
723     Flags: None affected.
724
725     This is sometimes written as ‘LD [HL+],A’, or ‘LDI [HL],A’.
726
727   LD [HLD],A
728     Store value in register A into the byte pointed by HL and decrement HL
729     afterwards.
730
731     Cycles: 2
732
733     Bytes: 1
734
735     Flags: None affected.
736
737     This is sometimes written as ‘LD [HL-],A’, or ‘LDD [HL],A’.
738
739   LD A,[HLD]
740     Load value into register A from the byte pointed by HL and decrement HL
741     afterwards.
742
743     Cycles: 2
744
745     Bytes: 1
746
747     Flags: None affected.
748
749     This is sometimes written as ‘LD A,[HL-]’, or ‘LDD A,[HL]’.
750
751   LD A,[HLI]
752     Load value into register A from the byte pointed by HL and increment HL
753     afterwards.
754
755     Cycles: 2
756
757     Bytes: 1
758
759     Flags: None affected.
760
761     This is sometimes written as ‘LD A,[HL+]’, or ‘LDI A,[HL]’.
762
763   LD SP,n16
764     Load value n16 into register SP.
765
766     Cycles: 3
767
768     Bytes: 3
769
770     Flags: None affected.
771
772   LD [n16],SP
773     Store SP & $FF at address n16 and SP >> 8 at address n16 + 1.
774
775     Cycles: 5
776
777     Bytes: 3
778
779     Flags: None affected.
780
781   LD HL,SP+e8
782     Add the signed value e8 to SP and store the result in HL.
783
784     Cycles: 3
785
786     Bytes: 2
787
788     Flags:
789     Z       0
790     N       0
791     H       Set if overflow from bit 3.
792     C       Set if overflow from bit 7.
793
794   LD SP,HL
795     Load register HL into register SP.
796
797     Cycles: 2
798
799     Bytes: 1
800
801     Flags: None affected.
802
803   NOP
804     No OPeration.
805
806     Cycles: 1
807
808     Bytes: 1
809
810     Flags: None affected.
811
812   OR A,r8
813     Store into A the bitwise OR of the value in r8 and A.
814
815     Cycles: 1
816
817     Bytes: 1
818
819     Flags:
820     Z       Set if result is 0.
821     N       0
822     H       0
823     C       0
824
825   OR A,[HL]
826     Store into A the bitwise OR of the byte pointed to by HL and A.
827
828     Cycles: 2
829
830     Bytes: 1
831
832     Flags: See OR A,r8
833
834   OR A,n8
835     Store into A the bitwise OR of n8 and A.
836
837     Cycles: 2
838
839     Bytes: 2
840
841     Flags: See OR A,r8
842
843   POP AF
844     Pop register AF from the stack.  This is roughly equivalent to the fol‐
845     lowing imaginary instructions:
846
847           ld f, [sp] ; See below for individual flags
848           inc sp
849           ld a, [sp]
850           inc sp
851
852     Cycles: 3
853
854     Bytes: 1
855
856     Flags:
857     Z       Set from bit 7 of the popped low byte.
858     N       Set from bit 6 of the popped low byte.
859     H       Set from bit 5 of the popped low byte.
860     C       Set from bit 4 of the popped low byte.
861
862   POP r16
863     Pop register r16 from the stack.  This is roughly equivalent to the fol‐
864     lowing imaginary instructions:
865
866           ld LOW(r16), [sp] ; C, E or L
867           inc sp
868           ld HIGH(r16), [sp] ; B, D or H
869           inc sp
870
871     Cycles: 3
872
873     Bytes: 1
874
875     Flags: None affected.
876
877   PUSH AF
878     Push register AF into the stack.  This is roughly equivalent to the fol‐
879     lowing imaginary instructions:
880
881           dec sp
882           ld [sp], a
883           dec sp
884           ld [sp], flag_Z << 7 | flag_N << 6 | flag_H << 5 | flag_C << 4
885
886     Cycles: 4
887
888     Bytes: 1
889
890     Flags: None affected.
891
892   PUSH r16
893     Push register r16 into the stack.  This is roughly equivalent to the fol‐
894     lowing imaginary instructions:
895
896           dec sp
897           ld [sp], HIGH(r16) ; B, D or H
898           dec sp
899           ld [sp], LOW(r16) ; C, E or L
900
901     Cycles: 4
902
903     Bytes: 1
904
905     Flags: None affected.
906
907   RES u3,r8
908     Set bit u3 in register r8 to 0.  Bit 0 is the rightmost one, bit 7 the
909     leftmost one.
910
911     Cycles: 2
912
913     Bytes: 2
914
915     Flags: None affected.
916
917   RES u3,[HL]
918     Set bit u3 in the byte pointed by HL to 0.  Bit 0 is the rightmost one,
919     bit 7 the leftmost one.
920
921     Cycles: 4
922
923     Bytes: 2
924
925     Flags: None affected.
926
927   RET
928     Return from subroutine.  This is basically a POP PC (if such an instruc‐
929     tion existed).  See POP r16 for an explanation of how POP works.
930
931     Cycles: 4
932
933     Bytes: 1
934
935     Flags: None affected.
936
937   RET cc
938     Return from subroutine if condition cc is met.
939
940     Cycles: 5 taken / 2 untaken
941
942     Bytes: 1
943
944     Flags: None affected.
945
946   RETI
947     Return from subroutine and enable interrupts.  This is basically equiva‐
948     lent to executing EI then RET, meaning that IME is set right after this
949     instruction.
950
951     Cycles: 4
952
953     Bytes: 1
954
955     Flags: None affected.
956
957   RL r8
958     Rotate bits in register r8 left through carry.
959
960           C <- [7 <- 0] <- C
961
962     Cycles: 2
963
964     Bytes: 2
965
966     Flags:
967     Z       Set if result is 0.
968     N       0
969     H       0
970     C       Set according to result.
971
972   RL [HL]
973     Rotate the byte pointed to by HL left through carry.
974
975           C <- [7 <- 0] <- C
976
977     Cycles: 4
978
979     Bytes: 2
980
981     Flags: See RL r8
982
983   RLA
984     Rotate register A left through carry.
985
986           C <- [7 <- 0] <- C
987
988     Cycles: 1
989
990     Bytes: 1
991
992     Flags:
993     Z       0
994     N       0
995     H       0
996     C       Set according to result.
997
998   RLC r8
999     Rotate register r8 left.
1000
1001           C <- [7 <- 0] <- [7]
1002
1003     Cycles: 2
1004
1005     Bytes: 2
1006
1007     Flags:
1008     Z       Set if result is 0.
1009     N       0
1010     H       0
1011     C       Set according to result.
1012
1013   RLC [HL]
1014     Rotate the byte pointed to by HL left.
1015
1016           C <- [7 <- 0] <- [7]
1017
1018     Cycles: 4
1019
1020     Bytes: 2
1021
1022     Flags: See RLC r8
1023
1024   RLCA
1025     Rotate register A left.
1026
1027           C <- [7 <- 0] <- [7]
1028
1029     Cycles: 1
1030
1031     Bytes: 1
1032
1033     Flags:
1034     Z       0
1035     N       0
1036     H       0
1037     C       Set according to result.
1038
1039   RR r8
1040     Rotate register r8 right through carry.
1041
1042           C -> [7 -> 0] -> C
1043
1044     Cycles: 2
1045
1046     Bytes: 2
1047
1048     Flags:
1049     Z       Set if result is 0.
1050     N       0
1051     H       0
1052     C       Set according to result.
1053
1054   RR [HL]
1055     Rotate the byte pointed to by HL right through carry.
1056
1057           C -> [7 -> 0] -> C
1058
1059     Cycles: 4
1060
1061     Bytes: 2
1062
1063     Flags: See RR r8
1064
1065   RRA
1066     Rotate register A right through carry.
1067
1068           C -> [7 -> 0] -> C
1069
1070     Cycles: 1
1071
1072     Bytes: 1
1073
1074     Flags:
1075     Z       0
1076     N       0
1077     H       0
1078     C       Set according to result.
1079
1080   RRC r8
1081     Rotate register r8 right.
1082
1083           [0] -> [7 -> 0] -> C
1084
1085     Cycles: 2
1086
1087     Bytes: 2
1088
1089     Flags:
1090     Z       Set if result is 0.
1091     N       0
1092     H       0
1093     C       Set according to result.
1094
1095   RRC [HL]
1096     Rotate the byte pointed to by HL right.
1097
1098           [0] -> [7 -> 0] -> C
1099
1100     Cycles: 4
1101
1102     Bytes: 2
1103
1104     Flags: See RRC r8
1105
1106   RRCA
1107     Rotate register A right.
1108
1109           [0] -> [7 -> 0] -> C
1110
1111     Cycles: 1
1112
1113     Bytes: 1
1114
1115     Flags:
1116     Z       0
1117     N       0
1118     H       0
1119     C       Set according to result.
1120
1121   RST vec
1122     Call address vec.  This is a shorter and faster equivalent to CALL for
1123     suitable values of vec.
1124
1125     Cycles: 4
1126
1127     Bytes: 1
1128
1129     Flags: None affected.
1130
1131   SBC A,r8
1132     Subtract the value in r8 and the carry flag from A.
1133
1134     Cycles: 1
1135
1136     Bytes: 1
1137
1138     Flags:
1139     Z       Set if result is 0.
1140     N       1
1141     H       Set if borrow from bit 4.
1142     C       Set if borrow (i.e. if (r8 + carry) > A).
1143
1144   SBC A,[HL]
1145     Subtract the byte pointed to by HL and the carry flag from A.
1146
1147     Cycles: 2
1148
1149     Bytes: 1
1150
1151     Flags: See SBC A,r8
1152
1153   SBC A,n8
1154     Subtract the value n8 and the carry flag from A.
1155
1156     Cycles: 2
1157
1158     Bytes: 2
1159
1160     Flags: See SBC A,r8
1161
1162   SCF
1163     Set Carry Flag.
1164
1165     Cycles: 1
1166
1167     Bytes: 1
1168
1169     Flags:
1170     N       0
1171     H       0
1172     C       1
1173
1174   SET u3,r8
1175     Set bit u3 in register r8 to 1.  Bit 0 is the rightmost one, bit 7 the
1176     leftmost one.
1177
1178     Cycles: 2
1179
1180     Bytes: 2
1181
1182     Flags: None affected.
1183
1184   SET u3,[HL]
1185     Set bit u3 in the byte pointed by HL to 1.  Bit 0 is the rightmost one,
1186     bit 7 the leftmost one.
1187
1188     Cycles: 4
1189
1190     Bytes: 2
1191
1192     Flags: None affected.
1193
1194   SLA r8
1195     Shift Left Arithmetically register r8.
1196
1197           C <- [7 <- 0] <- 0
1198
1199     Cycles: 2
1200
1201     Bytes: 2
1202
1203     Flags:
1204     Z       Set if result is 0.
1205     N       0
1206     H       0
1207     C       Set according to result.
1208
1209   SLA [HL]
1210     Shift Left Arithmetically the byte pointed to by HL.
1211
1212           C <- [7 <- 0] <- 0
1213
1214     Cycles: 4
1215
1216     Bytes: 2
1217
1218     Flags: See SLA r8
1219
1220   SRA r8
1221     Shift Right Arithmetically register r8.
1222
1223           [7] -> [7 -> 0] -> C
1224
1225     Cycles: 2
1226
1227     Bytes: 2
1228
1229     Flags:
1230     Z       Set if result is 0.
1231     N       0
1232     H       0
1233     C       Set according to result.
1234
1235   SRA [HL]
1236     Shift Right Arithmetically the byte pointed to by HL.
1237
1238           [7] -> [7 -> 0] -> C
1239
1240     Cycles: 4
1241
1242     Bytes: 2
1243
1244     Flags: See SRA r8
1245
1246   SRL r8
1247     Shift Right Logically register r8.
1248
1249           0 -> [7 -> 0] -> C
1250
1251     Cycles: 2
1252
1253     Bytes: 2
1254
1255     Flags:
1256     Z       Set if result is 0.
1257     N       0
1258     H       0
1259     C       Set according to result.
1260
1261   SRL [HL]
1262     Shift Right Logically the byte pointed to by HL.
1263
1264           0 -> [7 -> 0] -> C
1265
1266     Cycles: 4
1267
1268     Bytes: 2
1269
1270     Flags: See SRA r8
1271
1272   STOP
1273     Enter CPU very low power mode.  Also used to switch between double and
1274     normal speed CPU modes in GBC.
1275
1276     Cycles: -
1277
1278     Bytes: 2
1279
1280     Flags: None affected.
1281
1282   SUB A,r8
1283     Subtract the value in r8 from A.
1284
1285     Cycles: 1
1286
1287     Bytes: 1
1288
1289     Flags:
1290     Z       Set if result is 0.
1291     N       1
1292     H       Set if borrow from bit 4.
1293     C       Set if borrow (set if r8 > A).
1294
1295   SUB A,[HL]
1296     Subtract the byte pointed to by HL from A.
1297
1298     Cycles: 2
1299
1300     Bytes: 1
1301
1302     Flags: See SUB A,r8
1303
1304   SUB A,n8
1305     Subtract the value n8 from A.
1306
1307     Cycles: 2
1308
1309     Bytes: 2
1310
1311     Flags: See SUB A,r8
1312
1313   SWAP r8
1314     Swap the upper 4 bits in register r8 and the lower 4 ones.
1315
1316     Cycles: 2
1317
1318     Bytes: 2
1319
1320     Flags:
1321     Z       Set if result is 0.
1322     N       0
1323     H       0
1324     C       0
1325
1326   SWAP [HL]
1327     Swap the upper 4 bits in the byte pointed by HL and the lower 4 ones.
1328
1329     Cycles: 4
1330
1331     Bytes: 2
1332
1333     Flags: See SWAP r8
1334
1335   XOR A,r8
1336     Bitwise XOR between the value in r8 and A.
1337
1338     Cycles: 1
1339
1340     Bytes: 1
1341
1342     Flags:
1343     Z       Set if result is 0.
1344     N       0
1345     H       0
1346     C       0
1347
1348   XOR A,[HL]
1349     Bitwise XOR between the byte pointed to by HL and A.
1350
1351     Cycles: 2
1352
1353     Bytes: 1
1354
1355     Flags: See XOR A,r8
1356
1357   XOR A,n8
1358     Bitwise XOR between the value in n8 and A.
1359
1360     Cycles: 2
1361
1362     Bytes: 2
1363
1364     Flags: See XOR A,r8
1365

SEE ALSO

1367     rgbasm(1), rgbds(7)
1368

HISTORY

1370     rgbds was originally written by Carsten Sørensen as part of the ASMotor
1371     package, and was later packaged in RGBDS by Justin Lloyd.  It is now
1372     maintained by a number of contributors at https://github.com/gbdev/rgbds
1373
1374BSD                             March 28, 2021                             BSD
Impressum