Changes
The [[Z80|Z80]] CPU contains several undocumented opcodes, which can be quite helpful sometimes. The most useful undocumented opcodes are probably these ones, which split up the 16bit index registers IX and IY in 8bit registers called IXL,IXH,IYL and IYH.
Please note, that many Z80 successors like the Z180 are NOT able to execute some of the following opcodes properly.
This is just an overview. Parts of this article have been copied from the [http://www.robsy.net/z80undoc.pdf "The Undocumented Z80 Documented" originally by Sean Young]and currently maintained by Jan Wilmans, which is one of the most comprehensive descriptiondescriptions around.
== CB prefix ==
The following commands set the lowest bit to 1 instead to 0:<pre>CB30 SLL B
CB31 SLL C
CB32 SLL D
CB36 SLL (HL)
CB37 SLL A
</pre>== DD and FD prefixes ==
ED41 OUT (C),B ED61 OUT (C),H
ED42 SBC HL,BC ED62 SBC HL,HL
ED5F LD A,R ED7F NOP *
* = undocumented opcodes
</pre>== DDCB prefix ==
001 C
010 D
110 (none: documented opcode)
111 A
</pre> The documented DDCB0106 is RLC (IX+01h). So, clear the lower three bits (DDCB0100) and something is done to register B. The result of the RLC (which is stored in (IX+01h)) is now also stored in register B. Effectively, it does the following:<pre>LD B,(IX+01h)
RLC B
LD (IX+01h),B
</pre>So you get double value for money. The result is stored in B and (IX+01h). The most common notation is: RLC (IX+01h),B
I’ve once seen this notation:<pre>RLC (IX+01h)
LD B,(IX+01h)
</pre>That’s not correct: B contains the rotated value, even if (IX+01h) points to ROM. The DDCB SET and RES instructions do the same thing as the shift/rotate instructions:<pre>DDCB10C0 SET 0,(IX+10h),B
DDCB10C1 SET 0,(IX+10h),C
DDCB10C2 SET 0,(IX+10h),D
DDCB10C6 SET 0,(IX+10h) - documented instruction
DDCB10C7 SET 0,(IX+10h),A
</pre>So for example with the last instruction, the value of (IX+10h) with bit 0 set is also stored in register A.
DDCB d 79 BIT 7,(IX+d)
DDCB d 7A BIT 7,(IX+d)
DDCB d 7E BIT 7,(IX+d) - documented instruction
DDCB d 7F BIT 7,(IX+d)
</pre> == FDCB prefix ==
Same as for the DDCB prefix, though IY is used instead of IX.
== Web links ==
* [http://www.robsy.net/z80undoc.pdf "The Undocumented Z80 Documented" by Sean Young at Robsy's MSX Workshop]* [http://www.raww.org/index.php?name=News&file=article&sid=2226 Short information about the internal "MEMPTR" 16bit register of the Z80 and its influence on the F-Register]
[[Category:Programming]]