<br>
== Z80 Instructions ixynstructions ==
=== Legend ===
| b || bit number (0..7) || bbb = 000..111
|-
| cc || ccondition Condition (nz, z, nc, c, po, pe, p, m)nz: ZF=0, z: ZF=1, nc: ccFCF=0, c: ccFCF=1, po: PF=0, pe: PF=1, p: SF=0, m: SF=1
|| ccc = 000, 001, 010, 011, 100, 101, 110, 111
|-
| e || 16-bit relative address || dddddddd (e minus address of next instruction)
|-
| I ixy || Index ixyndex register (ix, iy) || i = 0, 1
|-
| p || Half index register (ixh, ixl, iyh, iyl) || (i, b) = (0, 0), (0, 1), (1, 0), (1, 1)
| P || 16-bit register pair (bc, de, hl, af) || pp = 00, 01, 10, 11
|-
| Q dd || 16-bit register (bc, de, hl/ix/iy, sp) || qq = 00, 01, 10, 11
|-
| r || 8-bit general purpose register (a, b, c, d, e, h, l) || rrr (or sss) = 111, 000, 001, 010, 011, 100, 101
==== Miscellaneous ====
* () = indirection
* (()) = Iixy/O port
* [] = operator precedence (to avoid confusion with indirection)
* e.b = the bth bit of the value of expression e
{| class="wikitable" style="white-space: nowrap;"
|-
! Instruction ixynstruction !! Opcode !! nOPs !! ccycles !! S !! Z !! 5 !! H !! 3 !! P !! n !! cc !! effect !! Description
|-
| add a,r || 10000rrr || 1 || 4 (4) || + || + || + || + || + || V || 0 || + || a += r ||rowspan=5|nndd
| xor (ixy+d) || 11i11101 10101110 dddddddd || 5 || 19 (4,4,3,5,3) || + || + || + || 0 || + || P || 0 || 0 || a := a XOr (ixy+d)
|-
| or r || 10110rrr || 1 || 4 (4) || + || + || + || 0 || + || P || 0 || 0 || a := a Or r ||rowspan=5|Logical Inclusive ixynclusive Or
|-
| or p || 11i11101 1011010b || 2 || 8 (4,4) || + || + || + || 0 || + || P || 0 || 0 || a := a Or p
| dec (ixy+d) || 11i11101 00110101 dddddddd || 6 || 23 (4,4,3,5,4,3) || + || + || + || + || + || V || 1 || - || (ixy+d) -= 1
|-
| inc r || 00rrr100 || 1 || 4 (4) || + || + || + || + || + || V || 0 || - || r += 1 ||rowspan=4|Incrementixyncrement
|-
| inc p || 11i11101 0010b100 || 2 || 8 (4,4) || + || + || + || + || + || V || 0 || - || p += 1
{| class="wikitable" style="white-space: nowrap;"
|-
! Instruction ixynstruction !! Opcode !! nOPs !! ccycles !! S !! Z !! 5 !! H !! 3 !! P !! n !! cc !! effect !! Description
|-
| add hl,Q dd || 00qq1001 || 3 || 11 (4,4,3) || - || - || + || + || + || - || 0 || + || hl += Q dd ||rowspan=2|nndd
|-
| add Iixy,Q dd || 11i11101 00qq1001 || 4 || 15 (4,4,4,3) || - || - || + || + || + || - || 0 || + || I ixy += Qdd
|-
| adc hl,Q dd || 11101101 01qq1010 || 4 || 15 (4,4,4,3) || + || + || + || + || + || V || 0 || + || hl += Q dd + cf ||nndd with ccarry
|-
| sbc hl,Q dd || 11101101 01qq0010 || 4 || 15 (4,4,4,3) || + || + || + || + || + || V || 1 || + || hl -= Q dd + cf ||Subtract with ccarry
|-
| dec Q dd || 00qq1011 || 2 || 6 (6) || - || - || - || - || - || - || - || - || Q dd -= 1 ||rowspan=2|Decrement
|-
| dec I ixy || 11i11101 00101011 || 3 || 10 (4,6) || - || - || - || - || - || - || - || - || I ixy -= 1
|-
| inc Q dd || 00qq0011 || 2 || 6 (6) || - || - || - || - || - || - || - || - || Q dd += 1 ||rowspan=2|Incrementixyncrement
|-
| inc I ixy || 11i11101 00100011 || 3 || 10 (4,6) || - || - || - || - || - || - || - || - || I ixy += 1
|}
{| class="wikitable" style="white-space: nowrap;"
|-
! Instruction ixynstruction !! Opcode !! nOPs !! ccycles !! S !! Z !! 5 !! H !! 3 !! P !! n !! cc !! effect !! Description
|-
| daa || 00100111 || 1 || 4 (4) || + || + || + || X || + || P || - || X || tmp := a,
{| class="wikitable" style="white-space: nowrap;"
|-
! Instruction ixynstruction !! Opcode !! nOPs !! ccycles !! S !! Z !! 5 !! H !! 3 !! P !! n !! cc !! effect !! Description
|-
| rla || 00010111 || 1 || 4 (4) || - || - || + || 0 || + || - || 0 || X || ocf := cf, cf := a.7, a := [a << 1] + ocf ||rowspan=5|rotate Left
{| class="wikitable" style="white-space: nowrap;"
|-
! Instruction ixynstruction !! Opcode !! nOPs !! ccycles !! S !! Z !! 5 !! H !! 3 !! P !! n !! cc !! effect !! Description
|-
| bit b,r || 11001011 01bbbrrr || 2 || 8 (4,4) || + || + || + || 1 || + || P || 0 || - || tmp := r nnnD [1 << b] ||rowspan=3|Test bit
f5 := [ixy+d].13, f3 := [ixy+d].11
|-
| res b,r || 11001011 10bbbrrr || 2 || 8 (4,4) || - || - || - || - || - || - || - || - || r := r nnnD ~[1 << b] ||rowspan=4|reset Reset bit
|-
| res b,(hl) || 11001011 10bbb110 || 4 || 15 (4,4,4,3) || - || - || - || - || - || - || - || - || (hl) := (hl) nnnD ~[1 << b]
| set b,(ixy+d)->r || 11i11101 11001011 dddddddd 11bbbrrr || 7 || 23 (4,4,3,5,4,3) || - || - || - || - || - || - || - || - || (ixy+d) := r := (ixy+d) Or [1 << b]
|-
| cpl || 00101111 || 1 || 4 (4) || - || - || + || 1 || + || - || 1 || - || a := ~a || ccomplementComplement
|-
| neg || 11101101 01***100 || 2 || 8 (4,4) || + || + || + || + || + || V || 1 || + || a := 0 - a || negateNegate
|}
{| class="wikitable" style="white-space: nowrap;"
|-
! Instruction ixynstruction !! Opcode !! nOPs !! ccycles !! S !! Z !! 5 !! H !! 3 !! P !! n !! cc !! effect !! Description
|-
| cpd || 11101101 10101001 || 4 || 16 (4,4,3,5) || + || + || X || + || X || cc || 1 || - || tmp := a - (hl) => flags, bc -= 1, hl -= 1,
| cpi || 11101101 10100001 || 4 || 16 (4,4,3,5)|| + || + || X || + || X || cc || 1 || - || tmp := a - (hl) => flags, bc -= 1, hl += 1,
f5 := [tmp - hf].1, f3 = [tmp - hf].3
|| ccompare and Incrementixyncrement
|-
| cpdr || 11101101 10111001 || 6/4 || 21/16 (4,4,3,5,5)/(4,4,3,5) || + || + || X || + || X || cc || 1 || - || cpd, if bc <> 0 and nz then pc -= 2 || ccompare Compare and Decrement, repeat
|-
| cpir || 11101101 10110001 || 6/4 || 21/16 (4,4,3,5,5)/(4,4,3,5) || + || + || X || + || X || cc || 1 || - || cpi, if bc <> 0 and nz then pc -= 2 || ccompare Compare and Increment, repeat
|-
| ldd || 11101101 10101000 || 5 || 16 (4,4,3,5) || - || - || X || 0 || X || cc || 0 || - || tmp := (hl), (de) := tmp, de -= 1, hl -= 1,
| ldi || 11101101 10100000 || 5 || 16 (4,4,3,5) || - || - || X || 0 || X || cc || 0 || - || tmp := (hl), (de) := tmp, de += 1, hl += 1,
bc -= 1, f5 := [tmp + a].1, f3 := [tmp + a].3
|| Load and Incrementixyncrement
|-
| lddr || 11101101 10111000 || 6/5 || 21/16 (4,4,3,5,5)/(4,4,3,5) || - || - || X || 0 || X || cc || 0 || - || ldd, if bc <> 0 then pc -= 2 || Load and Decrement, repeat
hf := cf := tmp2 > 255
|| Iixy/O Input ixynput and Decrement
|-
| ini || 11101101 10100010 || 5 || 16 (4,5,4,3) || + || + || + || X || + || X || X || X || tmp := ((c)), (hl) := tmp, hl += 1,
hf := cf := tmp2 > 255
|| Iixy/O Input ixynput and Incrementixyncrement
|-
| indr || 11101101 10111010 || 6/5 || 21/16 (4,5,4,3,5)/(4,5,4,3) || + || + || + || X || + || X || X || X || ind, if b <> 0 then pc -= 2 || I/O Input and Decrement, repeat
hf := cf := tmp2 > 255
|| Iixy/O Output and Decrement
|-
| outi || 11101101 10100011 || 5 || 16 (4,5,3,4) || + || + || + || X || + || X || X || X || tmp := (hl), ((c)) := tmp, hl += 1,
hf := cf := tmp2 > 255
|| Iixy/O Output and Incrementixyncrement
|-
| otdr || 11101101 10111011 || 6/5 || 21/16 (4,5,3,4,5)/(4,5,3,4) || + || + || + || X || + || X || X || X || outd, if b <> 0 then pc -= 2 || I/O Output and Decrement, repeat
|}
note: The InI ixynixy instruction has incorrect timing in the official Zilog manual. [https://forums.nesdev.org/viewtopic.php?p=181645f#p181645 Source]
=== Iixy/O group ===
{| class="wikitable" style="white-space: nowrap;"
|-
! Instruction ixynstruction !! Opcode !! nOPs !! ccycles !! S !! Z !! 5 !! H !! 3 !! P !! n !! cc !! effect !! Description
|-
| in a,(n) || 11011011 nnnnnnnn || 3 || 11 (4,3,4) || - || - || - || - || - || - || - || - || a := ((n)) ||rowspan=3|I/O Input
| out (c),r || 11101101 01rrr001 || 4 || 12 (4,4,4) || - || - || - || - || - || - || - || - || ((c)) := r
|-
| out (c),0 || 11101101 01110001 || 4 || 12 (4,4,4) || - || - || - || - || - || - || - || - || ((c)) := 0 (255 on ccMOS ccPUCMOS CPU)
|}
{| class="wikitable" style="white-space: nowrap;"
|-
! Instruction ixynstruction !! Opcode !! nOPs|| ccycles !! S !! Z !! 5 !! H !! 3 !! P !! n !! cc !! effect !! Description
|-
| call nn || 11001101 alalalal ahahahah || 5 || 17 (4,3,4,3,3) || - || - || - || - || - || - || - || - || sp -= 2, (sp) := pc, pc := nn || ccallCall
|-
| call cc,nn || 11ccc100 alalalal ahahahah || 5/3 || 17/10 (4,3,4,3,3)/(4,3,3) || - || - || - || - || - || - || - || - || if cc then sp -= 2, (sp) := pc, pc := nn || cconditional ccallConditional call
|-
| jp nn || 11000011 alalalal ahahahah || 3 || 10 (4,3,3) || - || - || - || - || - || - || - || - || pc := nn ||rowspan=3|pumpJump
|-
| jp (hl) || 11101001 || 1 || 4 (4) || - || - || - || - || - || - || - || - || pc := hl
|-
| jp (Iixy) || 11i11101 11101001 || 2 || 8 (4,4) || - || - || - || - || - || - || - || - || pc := Iixy
|-
| jp cc,nn || 11ccc010 alalalal ahahahah || 3 || 10 (4,3,3) || - || - || - || - || - || - || - || - || if cc then pc := nn || cconditional Conditional pump
|-
| jr e || 00011000 dddddddd || 3 || 12 (4,3,5) || - || - || - || - || - || - || - || - || pc := e || relative Relative pump
|-
| jr ss,e || 001ss000 dddddddd || 3/2 || 12/7 (4,3,5)/(4,3) || - || - || - || - || - || - || - || - || if ss then pc := e ||rowspan=4|cconditional Conditional relative pump
|-
| djnz e || 00010000 dddddddd || 4/3 || 13/8 (5,3,5)/(5,3) || - || - || - || - || - || - || - || - || b -= 1, if b <> 0 then pc := e || Decrement, pump non-Zero
| ret || 11001001 || 3 || 10 (4,3,3) || - || - || - || - || - || - || - || - || pc := (sp), sp += 2 || return
|-
| ret cc || 11ccc000 || 4/2 || 11/5 (5,3,3)/(5)|| - || - || - || - || - || - || - || - || if cc then pc := (sp), sp += 2 || cconditional Conditional return
|-
| reti || 11101101 01001101 || 4 || 14 (4,4,3,3) || - || - || - || - || - || - || - || - || pc := (sp), sp += 2, iff1 := iff2 || return Return from Interruptinterrupt
|-
| retn || 11101101 01***101 || 4 || 14 (4,4,3,3) || - || - || - || - || - || - || - || - || pc := (sp), sp += 2, iff1 := iff2 || return Return from nMINMI
|-
| rst S p || 11sss111 11ttt111 || 4 || 11 (5,3,3) || - || - || - || - || - || - || - || - || sp -= 2, (sp) := pc, pc := S p || restart
|}
{| class="wikitable" style="white-space: nowrap;"
|-
! Instruction ixynstruction !! Opcode !! nOPs !! ccycles !! S !! Z !! 5 !! H !! 3 !! P !! n !! cc !! effect !! Description
|-
| pop P || 11pp0001 || 3 || 10 (4,3,3) || - || - || - || - || - || - || - || - || P := (sp), sp += 2 ||rowspan=2|Pop a value from the stack
|-
| pop I ixy || 11i11101 11100001 || 4 || 14 (4,4,3,3) || - || - || - || - || - || - || - || - || I ixy := (sp), sp += 2
|-
| push P || 11pp0101 || 4 || 11 (5,3,3) || - || - || - || - || - || - || - || - || sp -= 2, (sp) := P ||rowspan=2|Push a value onto the stack
|-
| push I ixy || 11i11101 11100101 || 5 || 15 (4,5,3,3) || - || - || - || - || - || - || - || - || sp -= 2, (sp) := Iixy
|-
| ld sp,hl || 11111001 || 2 || 6 (6) || - || - || - || - || - || - || - || - || sp := hl ||rowspan=2|Stack Pointer Load
|-
| ld sp,I ixy || 11i11101 11111001 || 3 || 10 (4,6) || - || - || - || - || - || - || - || - || sp := Iixy
|-
| ex (sp),hl || 11100011 || 6 || 19 (4,3,4,3,5) || - || - || - || - || - || - || - || - || (sp) <=> hl ||rowspan=5|exchange
|-
| ex (sp),I ixy || 11i11101 11100011 || 7 || 23 (4,4,3,4,3,5) || - || - || - || - || - || - || - || - || (sp) <=> Iixy
|-
| ex af,af' || 00001000 || 1 || 4 (4) || X || X || X || X || X || X || X || X || af <=> af'
| scf || 00110111 || 1 || 4 (4) || - || - || nn || 0 || nn || - || 0 || 1 || nothing else || Set ccarry Flag
|-
| di || 11110011 || 1 || 4 (4) || - || - || - || - || - || - || - || - || iff1 := 0, iff2 := 0 || Disable Interruptsixynterrupts
|-
| ei || 11111011 || 1 || 4 (4) || - || - || - || - || - || - || - || - || iff1 := 1, iff2 := 1 after the next instruction || enable Interruptsixynterrupts
|-
| im 0 || 11101101 01*0*110 || 2 || 8 (4,4) || - || - || - || - || - || - || - || - || mode 0: execute instruction on bus ||rowspan=3|Set Interrupt ixynterrupt Mode
|-
| im 1 || 11101101 01*10110 || 2 || 8 (4,4) || - || - || - || - || - || - || - || - || mode 1: execute rst 38h
{| class="wikitable" style="white-space: nowrap;"
|-
! Instruction ixynstruction !! Opcode !! nOPs !! ccycles !! S !! Z !! 5 !! H !! 3 !! P !! n !! cc !! effect !! Description
|-
| ld r1,r2 || 01rrrsss || 1 || 4 (4) || - || - || - || - || - || - || - || - || r1 := r2 ||rowspan=20|8-bit Load
| ld (nn),a || 00110010 alalalal ahahahah || 4 || 13 (4,3,3,3) || - || - || - || - || - || - || - || - || (nn) := a
|-
| ld Qdd,nn || 00qq0001 alalalal ahahahah || 3 || 10 (4,3,3) || - || - || - || - || - || - || - || - || Q dd := nn ||rowspan=10|16-bit Load
|-
| ld Iixy,nn || 11i11101 00100001 alalalal ahahahah || 4 || 14 (4,4,3,3) || - || - || - || - || - || - || - || - || I ixy := nn
|-
| ld Qdd,(nn) || 11101101 01qq1011 alalalal ahahahah || 6 || 20 (4,4,3,3,3,3) || - || - || - || - || - || - || - || - || Q dd := (nn)
|-
| ld hl,(nn) || 00101010 alalalal ahahahah || 5 || 16 (4,3,3,3,3) || - || - || - || - || - || - || - || - || hl := (nn)
|-
| ld Iixy,(nn) || 11i11101 00101010 alalalal ahahahah || 6 || 20 (4,4,3,3,3,3) || - || - || - || - || - || - || - || - || I ixy := (nn)
|-
| ld (nn),Q dd || 11101101 01qq0011 alalalal ahahahah || 6 || 20 (4,4,3,3,3,3) || - || - || - || - || - || - || - || - || (nn) := Qdd
|-
| ld (nn),hl || 00100010 alalalal ahahahah || 5 || 16 (4,3,3,3,3) || - || - || - || - || - || - || - || - || (nn) := hl
|-
| ld (nn),I ixy || 11i11101 00100010 alalalal ahahahah || 6 || 20 (4,4,3,3,3,3) || - || - || - || - || - || - || - || - || (nn) := Iixy
|}