Difference between revisions of "Extended Z80 instruction set"

From SpecNext official Wiki
Jump to: navigation, search
(added note about implementing BSRF in C, implicit variable type promotion gotcha)
 
(84 intermediate revisions by 13 users not shown)
Line 1: Line 1:
  
This is a general list of Z80 instructions with descriptions. For summaries, you can view the [[Z80 Instruction Table]].
+
This is a general list of Z80 instructions with descriptions. For summaries, you can view the [[Z80 Instruction Table]]. You can also [[Special:RunQuery/OpcodeQuery|search for opcodes]].
  
<div style="float:right;"> {{Special:RunQuery/OpcodeQuery}} </div>
+
=== Erratum ===
 +
2021-09-16: figuring out the hard way, the three Z80N instructions `ADD HL/DE/BC,A` actually do NOT preserve carry flag, but change it to undefined value (verified with core 3.1.5). There's also strong suspicion (but not verified yet), that LDIX/LDDX/LDIRX/LDDRX/LDPIRX do affects flags the same way as LDI/LDIR - to be verified.
 +
 
 +
2022-01-11: it's [http://www.z80.info/zip/z80-documented.pdf documented] for several years that regular Z80 INI/IND/INIR/INDR/OUTI/OUTD/OTIR/OTDR instructions do modify carry flag (contrary to the official Z80 documentation and many Internet resources describing Z80 instructions, including previous version of this page, unfortunately).
  
 
=== Term references ===
 
=== Term references ===
 
* ''Any 8-bit register'' means A, B, C, D, E, H, and L. F, I and R do not count even though they are technically 8 bit registers. Also, the high and low bytes of IX and IY (IXH, IXL, IYH, IYL) can be used as 8-bit registers although this behavior was undocumented on the original Z80.
 
* ''Any 8-bit register'' means A, B, C, D, E, H, and L. F, I and R do not count even though they are technically 8 bit registers. Also, the high and low bytes of IX and IY (IXH, IXL, IYH, IYL) can be used as 8-bit registers although this behavior was undocumented on the original Z80.
 
* IXY means IX or IY.
 
* IXY means IX or IY.
* Details of ACC32, which appears to be a Next extension, are unknown at present.
 
 
* For the status field:
 
* For the status field:
 
** S means Standard. It's in the Z80 manual. Everything should support it.
 
** S means Standard. It's in the Z80 manual. Everything should support it.
Line 18: Line 20:
 
** ! means the instruction has an unusual effect on the flag which is documented in the description.
 
** ! means the instruction has an unusual effect on the flag which is documented in the description.
 
** S means the effect on the flag is "standard". C is set if a carry/borrow occurred beyond the MSB; Z is set if the result of the operation is zero; H is set if a carry/borrow occurred beyond bit 3.
 
** S means the effect on the flag is "standard". C is set if a carry/borrow occurred beyond the MSB; Z is set if the result of the operation is zero; H is set if a carry/borrow occurred beyond bit 3.
** P, V, and L are used for the P/V flag which has several standard effects. P means it's parity. V means it's overflow. L means it detects the end of a loop (BC reaching 0) as it does for some of the block copy and search instructions.
+
** P, V, and L are used for the P/V flag which has several standard effects. P means it's parity. V means it's overflow. L means it checks BC as loop counter for some of the block copy and search instructions: P/V = (BC != 0)
 +
 
 +
 
  
 
=== Register and Data manipulation ===
 
=== Register and Data manipulation ===
Line 35: Line 39:
 
  |s=-
 
  |s=-
 
  |tstates=4
 
  |tstates=4
 +
|shortfx=r := r'
 
}}
 
}}
  
Line 48: Line 53:
 
  |s=-
 
  |s=-
 
  |tstates=7
 
  |tstates=7
 +
|shortfx=r := n
 
}}
 
}}
  
Line 61: Line 67:
 
  |s=-
 
  |s=-
 
  |tstates=7
 
  |tstates=7
 +
|shortfx=r := HL*
 
}}
 
}}
  
Line 74: Line 81:
 
  |s=-
 
  |s=-
 
  |tstates=19
 
  |tstates=19
 +
|shortfx=r := (IXY+d)*
 
}}
 
}}
  
Line 87: Line 95:
 
  |s=-
 
  |s=-
 
  |tstates=7
 
  |tstates=7
 +
|shortfx=HL* := r
 
}}
 
}}
  
Line 100: Line 109:
 
  |s=-
 
  |s=-
 
  |tstates=19
 
  |tstates=19
 +
|shortfx=(IXY+D)* := r
 
}}
 
}}
  
Line 113: Line 123:
 
  |s=-
 
  |s=-
 
  |tstates=10
 
  |tstates=10
 +
|shortfx=HL* := n
 
}}
 
}}
  
Line 126: Line 137:
 
  |s=-
 
  |s=-
 
  |tstates=19
 
  |tstates=19
 +
|shortfx=(IXY+d)* := n
 
}}
 
}}
  
Line 139: Line 151:
 
  |s=-
 
  |s=-
 
  |tstates=7
 
  |tstates=7
 +
|shortfx=A := rr*
 
}}
 
}}
  
Line 152: Line 165:
 
  |s=-
 
  |s=-
 
  |tstates=13
 
  |tstates=13
 +
|shortfx=A := (nn)*
 
}}
 
}}
  
Line 165: Line 179:
 
  |s=-
 
  |s=-
 
  |tstates=7
 
  |tstates=7
 +
|shortfx=rr* := A
 
}}
 
}}
  
Line 179: Line 194:
 
  |s=-
 
  |s=-
 
  |tstates=13
 
  |tstates=13
 +
|shortfx=(nn)* := A
 
}}
 
}}
  
Line 192: Line 208:
 
  |s=S
 
  |s=S
 
  |tstates=9
 
  |tstates=9
 +
|shortfx=A := I; P/V:=IFF2
 
}}
 
}}
  
Line 205: Line 222:
 
  |s=S
 
  |s=S
 
  |tstates=9
 
  |tstates=9
 +
|shortfx=A := R; P/V:=IFF2
 
}}
 
}}
  
Line 218: Line 236:
 
  |s=-
 
  |s=-
 
  |tstates=9
 
  |tstates=9
 +
|shortfx=I := A
 
}}
 
}}
  
Line 232: Line 251:
 
  |s=-
 
  |s=-
 
  |tstates=9
 
  |tstates=9
 +
|shortfx=R := A
 
}}
 
}}
  
Line 245: Line 265:
 
  |s=-
 
  |s=-
 
  |tstates=10
 
  |tstates=10
 +
|shortfx=rr := nn
 
}}
 
}}
  
Line 259: Line 280:
 
  |s=-
 
  |s=-
 
  |tstates=14
 
  |tstates=14
 +
|shortfx=rr := nn
 
}}
 
}}
  
Line 273: Line 295:
 
  |s=-
 
  |s=-
 
  |tstates=16
 
  |tstates=16
 +
|shortfx=HL := (nn)*
 
}}
 
}}
  
Line 287: Line 310:
 
  |s=-
 
  |s=-
 
  |tstates=20
 
  |tstates=20
 +
|shortfx=rr := (nn)*
 
}}
 
}}
  
Line 301: Line 325:
 
  |s=-
 
  |s=-
 
  |tstates=16
 
  |tstates=16
}}
+
|shortfx=(nn)* := HL
 
 
{{Opcode|opdesc=LD (nn), HL
 
|ad1=Address
 
|ad2=Register
 
|status=S
 
|c=-
 
|n=-
 
|pv=-
 
|h=-
 
|z=-
 
|s=-
 
|tstates=16
 
 
}}
 
}}
  
Line 327: Line 339:
 
  |s=-
 
  |s=-
 
  |tstates=20
 
  |tstates=20
 +
|shortfx=(nn)* := rr
 
}}
 
}}
  
Line 340: Line 353:
 
  |s=-
 
  |s=-
 
  |tstates=6
 
  |tstates=6
}}
+
|shortfx=SP := HL
 
 
{{Opcode|opdesc=LD HL, SP
 
|ad1=Register
 
|ad2=Register
 
|status=E
 
|c=?
 
|n=?
 
|pv=?
 
|h=?
 
|z=?
 
|s=?
 
|tstates=?
 
 
}}
 
}}
  
Line 366: Line 367:
 
  |s=-
 
  |s=-
 
  |tstates=10
 
  |tstates=10
 +
|shortfx=SP := IXY
 
}}
 
}}
  
{{Opcode|opdesc=LD ACC32, DEHL
+
|}
|ad1=Register
+
:The basic data load/transfer instruction. Transfers data from the location specified by the second argument, to the location specified by the first. Available combinations are as follows:
|ad2=Register
+
:* Any 8-bit register can be:
|status=E
+
:** loaded with an immediate value;
|c=?
+
:** loaded with the contents of any other 8-bit register except I and R;
|n=?
 
|pv=?
 
|h=?
 
|z=?
 
|s=?
 
|tstates=?
 
}}
 
 
 
{{Opcode|opdesc=LD DEHL, ACC32
 
|ad1=Register
 
|ad2=Register
 
|status=E
 
|c=?
 
|n=?
 
|pv=?
 
|h=?
 
|z=?
 
|s=?
 
|tstates=?
 
}}
 
 
 
 
 
|}
 
:The basic data load/transfer instruction. Transfers data from the location specified by the second argument, to the location specified by the first. Available combinations are as follows:
 
:* Any 8-bit register can be:
 
:** loaded with an immediate value;
 
:** loaded with the contents of any other 8-bit register except I and R;
 
 
:** loaded with the contents of, or stored in, memory pointed to by HL;
 
:** loaded with the contents of, or stored in, memory pointed to by HL;
 
:** loaded with the contents of, or stored in, memory offset-indexed by IX or IY.
 
:** loaded with the contents of, or stored in, memory offset-indexed by IX or IY.
Line 411: Line 386:
 
:* Additionally, SP (only) can be:
 
:* Additionally, SP (only) can be:
 
:** loaded with the contents of HL, IX, or IY.
 
:** loaded with the contents of HL, IX, or IY.
:** (as a Next extended opcode) stored in HL.
+
:** The planned '''ld hl, sp''' didn't make it to Next yet, one possible workaround is: '''ld hl,0'''; '''add hl,sp''';
 
:* Memory referred to by HL or through IX can be assigned immediate values.
 
:* Memory referred to by HL or through IX can be assigned immediate values.
:* Details of the ACC32 register are unknown at present.
 
 
:Although 16-bit register pairs cannot be directly moved between each other, they can be moved by moving the two 8-bit registers. (SP gets a special case because it can't be addressed via 8-bit registers.) Some assemblers will provide built-in macro instructions allowing, for example, '''ld bc, de'''.
 
:Although 16-bit register pairs cannot be directly moved between each other, they can be moved by moving the two 8-bit registers. (SP gets a special case because it can't be addressed via 8-bit registers.) Some assemblers will provide built-in macro instructions allowing, for example, '''ld bc, de'''.
 
:LD instructions do not alter any flags unless I or R are loaded into A.
 
:LD instructions do not alter any flags unless I or R are loaded into A.
Line 431: Line 405:
 
  |s=-
 
  |s=-
 
  |tstates=4
 
  |tstates=4
 +
|shortfx=swap(DE,HL)
 
}}
 
}}
 
{{Opcode|opdesc=EX AF, AF'
 
{{Opcode|opdesc=EX AF, AF'
Line 443: Line 418:
 
  |s=!
 
  |s=!
 
  |tstates=4
 
  |tstates=4
 +
|shortfx=swap(AF,AF')
 
}}
 
}}
 
{{Opcode|opdesc=EX (SP), HL
 
{{Opcode|opdesc=EX (SP), HL
Line 455: Line 431:
 
  |s=-
 
  |s=-
 
  |tstates=19
 
  |tstates=19
 +
|shortfx=swap(SP*,HL)
 
}}
 
}}
 
{{Opcode|opdesc=EX (SP), IXY
 
{{Opcode|opdesc=EX (SP), IXY
Line 467: Line 444:
 
  |s=-
 
  |s=-
 
  |tstates=23
 
  |tstates=23
}}
+
|shortfx=swap(SP*,IXY)
{{Opcode|opdesc=EX ACC32, DEHL
 
|ad1=Register
 
|ad2=Register
 
|status=E
 
|c=?
 
|n=?
 
|pv=?
 
|h=?
 
|z=?
 
|s=?
 
|tstates=?
 
 
}}
 
}}
  
Line 501: Line 467:
 
  |s=-
 
  |s=-
 
  |tstates=4
 
  |tstates=4
 +
|shortfx=swap(BC,BC');swap(DE,DE');swap(HL,HL')
 
}}
 
}}
 
|}
 
|}
Line 520: Line 487:
 
  |s=-
 
  |s=-
 
  |tstates=11
 
  |tstates=11
 +
|shortfx=SP-=2; SP*:=rr
 
}}
 
}}
 
{{Opcode|opdesc=PUSH IXY
 
{{Opcode|opdesc=PUSH IXY
Line 532: Line 500:
 
  |s=-
 
  |s=-
 
  |tstates=15
 
  |tstates=15
 +
|shortfx=SP-=2; SP*:=rr
 
}}
 
}}
{{Opcode|opdesc=PUSH nnnn
+
{{Opcode|opdesc=PUSH nn
 
  |ad1=Immediate
 
  |ad1=Immediate
 
  |ad2=-
 
  |ad2=-
 
  |status=E
 
  |status=E
  |c=?
+
  |c=-
  |n=?
+
  |n=-
  |pv=?
+
  |pv=-
  |h=?
+
  |h=-
  |z=?
+
  |z=-
  |s=?
+
  |s=-
  |tstates=?
+
  |tstates=23
 +
|shortfx=SP-=2; SP*:=nn
 
}}
 
}}
  
Line 553: Line 523:
 
;POP
 
;POP
 
:{{Opcodelisttop}}
 
:{{Opcodelisttop}}
{{Opcode|opdesc=POP BC/DE/HL/AF
+
{{Opcode|opdesc=POP BC/DE/HL
 
  |ad1=Register
 
  |ad1=Register
 
  |ad2=-
 
  |ad2=-
Line 564: Line 534:
 
  |s=-
 
  |s=-
 
  |tstates=10
 
  |tstates=10
 +
|shortfx=rr:=SP*; SP+=2
 +
}}
 +
{{Opcode|opdesc=POP AF
 +
|ad1=Register
 +
|ad2=-
 +
|status=S
 +
|c=!
 +
|n=!
 +
|pv=!
 +
|h=!
 +
|z=!
 +
|s=!
 +
|tstates=10
 +
|shortfx=rr:=SP*; SP+=2
 
}}
 
}}
 
{{Opcode|opdesc=POP IXY
 
{{Opcode|opdesc=POP IXY
Line 576: Line 560:
 
  |s=-
 
  |s=-
 
  |tstates=14
 
  |tstates=14
 +
|shortfx=rr:=SP*; SP+=2
 
}}
 
}}
{{Opcode|opdesc=POPX
+
|}
|ad1=-
+
:Pops the given argument from the stack. This can be any 16-bit register pair except SP. The current value at SP is copied to the register pair and then SP is raised by 2.
|ad2=-
+
:Popping into AF does set value of flag register F directly to low 8 bits of value from stack.
|status=E
+
 
|c=?
 
|n=?
 
|pv=?
 
|h=?
 
|z=?
 
|s=?
 
|tstates=?
 
}}
 
  
|}
 
:Pops the given argument from the stack. This can be any 16-bit register pair except SP. The current value at SP is copied to the register pair and then SP is raised by 2. POPX, an extension opcode, pops the argument and throws it away and is thus equivalent to directly adding 2 to SP.
 
  
 
=== Block Copy ===
 
=== Block Copy ===
Line 607: Line 582:
 
  |s=-
 
  |s=-
 
  |tstates=16
 
  |tstates=16
 +
|shortfx=DE*:=HL*; DE++; HL++; BC--
 
}}
 
}}
 
|}
 
|}
:Copies the byte pointed to by HL to the address pointed to by DE, then adds 1 to DE and HL and subtracts 1 from BC. If BC did not reach 0, P/V is reset, otherwise it is set.  
+
:Copies the byte pointed to by HL to the address pointed to by DE, then adds 1 to DE and HL and subtracts 1 from BC. P/V is set to (BC!=0), i.e. set when non zero.
  
  
Line 625: Line 601:
 
  |s=-
 
  |s=-
 
  |tstates=21x+16
 
  |tstates=21x+16
 +
|shortfx=do LDI while(BC>0)
 
}}
 
}}
 
|}
 
|}
:Automatically loops LDI until BC reaches zero. Note that no loop occurs with BC=0. Flag effects are the same as LDI except that P/V will always be set, because BC by definition reaches 0 before this instruction ends.
+
:Automatically loops LDI until BC reaches zero. Note the last iteration starts when BC=1 and ends with BC=0 (starting the LDIR with BC=0 will start 64kiB transfer, most likely overwriting vital parts of system memory and/or code itself).
 +
:Flag effects are the same as LDI except that P/V will always be reset, because BC by definition reaches 0 before this instruction ends (normally - unless something overwrites LDIR opcode while BC>0).
 +
:Interrupts may interrupt LDIR instruction while looping (after each single LDI sub-part finished) and LDIR will resume after and finish loop properly.
  
  
Line 644: Line 623:
 
  |s=-
 
  |s=-
 
  |tstates=16
 
  |tstates=16
 +
|shortfx=DE*:=HL*; DE--; HL--; BC--
 
}}
 
}}
 
|}
 
|}
Line 662: Line 642:
 
  |z=-
 
  |z=-
 
  |s=-
 
  |s=-
  |tstates=21
+
  |tstates=21x+16
 +
|shortfx=do LDD while(BC>0)
 
}}
 
}}
 
|}
 
|}
 
:Same as LDIR but loops LDD instead of LDI.
 
:Same as LDIR but loops LDD instead of LDI.
 +
 +
 +
;LDWS
 +
:{{Opcodelisttop}}
 +
{{Opcode|opdesc=LDWS
 +
|ad1=-
 +
|ad2=-
 +
|status=E
 +
|c=-
 +
|n=0
 +
|pv=!
 +
|h=S
 +
|z=S
 +
|s=S
 +
|tstates=14
 +
|shortfx=DE*:=HL*; INC L; INC D;
 +
}}
 +
|}
 +
:Next-only extended opcode. Copies the byte pointed to by HL to the address pointed to by DE and increments only L and D. This is used for vertically copying bytes to the Layer 2 display.
 +
:The flags are identical to what the '''INC D''' instruction would produce.
 +
:Note the source data are read only from single 256B (aligned) block of memory, because only L is incremented, not HL.
  
  
Line 675: Line 677:
 
  |ad2=-
 
  |ad2=-
 
  |status=E
 
  |status=E
  |c=?
+
  |c=-
  |n=?
+
  |n=-
  |pv=?
+
  |pv=-
  |h=?
+
  |h=-
  |z=?
+
  |z=-
  |s=?
+
  |s=-
  |tstates=?
+
  |tstates=16
 +
|shortfx={if HL*!=A DE*:=HL*;} DE++; HL++; BC--
 
}}
 
}}
 
{{Opcode|opdesc=LDIRX
 
{{Opcode|opdesc=LDIRX
Line 687: Line 690:
 
  |ad2=-
 
  |ad2=-
 
  |status=E
 
  |status=E
  |c=?
+
  |c=-
  |n=?
+
  |n=-
  |pv=?
+
  |pv=-
  |h=?
+
  |h=-
  |z=?
+
  |z=-
  |s=?
+
  |s=-
  |tstates=?
+
  |tstates=21/16
 +
|shortfx=do LDIX while(BC>0)
 
}}
 
}}
 
{{Opcode|opdesc=LDDX
 
{{Opcode|opdesc=LDDX
Line 699: Line 703:
 
  |ad2=-
 
  |ad2=-
 
  |status=E
 
  |status=E
  |c=?
+
  |c=-
  |n=?
+
  |n=-
  |pv=?
+
  |pv=-
  |h=?
+
  |h=-
  |z=?
+
  |z=-
  |s=?
+
  |s=-
  |tstates=?
+
  |tstates=16
 +
|shortfx={if HL*!=A DE*:=HL*;} DE++; HL--; BC--
 
}}
 
}}
 
{{Opcode|opdesc=LDDRX
 
{{Opcode|opdesc=LDDRX
Line 711: Line 716:
 
  |ad2=-
 
  |ad2=-
 
  |status=E
 
  |status=E
  |c=?
+
  |c=-
  |n=?
+
  |n=-
  |pv=?
+
  |pv=-
  |h=?
+
  |h=-
  |z=?
+
  |z=-
  |s=?
+
  |s=-
  |tstates=?
+
  |tstates=21/16
 +
|shortfx=do LDDX while(BC>0)
 
}}
 
}}
 
|}
 
|}
:Next-only extended opcodes. Behave the same as their non-X equivalents except the byte is not copied if it is equal to A.
+
:Next-only extended opcodes. Behave similarly as their non-X equivalents except the byte is not copied if it is equal to A and LDDX/LDDRX advance DE by incrementing it (like LDI), while HL is decremented (like LDD).
 +
:Second difference to non-X instructions (as usual with next-only opcodes due to implementation), the extended ones don't modify any flags.
  
  
  
=== Block Search ===
+
;LDPIRX
;CPI (ComPare and Increment)
 
 
:{{Opcodelisttop}}
 
:{{Opcodelisttop}}
{{Opcode|opdesc=CPI
+
{{Opcode|opdesc=LDPIRX
 
  |ad1=-
 
  |ad1=-
 
  |ad2=-
 
  |ad2=-
  |status=S
+
  |status=E
 
  |c=-
 
  |c=-
  |n=1
+
|n=-
 +
|pv=-
 +
|h=-
 +
|z=-
 +
|s=-
 +
|tstates=21/16
 +
|shortfx=do{t:=(HL&$FFF8+E&7)*; {if t!=A DE*:=t;} DE++; BC--}while(BC>0)
 +
}}
 +
|}
 +
:Similar to LDIRX except the source byte address is not just HL, but is obtained by using the top 13 bits of HL and the lower 3 bits of DE and HL does not increment during whole loop (HL works as base address of aligned 8 byte lookup table, DE works as destination and also wrapping index 0..7 into table). This is intended for "pattern fill" functionality.
 +
 
 +
=== Block Search ===
 +
;CPI (ComPare and Increment)
 +
:{{Opcodelisttop}}
 +
{{Opcode|opdesc=CPI
 +
|ad1=-
 +
|ad2=-
 +
|status=S
 +
|c=-
 +
  |n=1
 
  |pv=L
 
  |pv=L
 
  |h=S
 
  |h=S
Line 738: Line 763:
 
  |s=S
 
  |s=S
 
  |tstates=16
 
  |tstates=16
 +
|shortfx=HL*==A?; HL++; BC--
 
}}
 
}}
 
|}
 
|}
:Compares the byte pointed to by HL with the contents of A and sets Z if it matches or S if the comparison goes negative. Then adds 1 to HL and subtracts 1 from BC. Sets P/V if BC did not reach 0 or resets it if it did.  
+
:Compares the byte pointed to by HL with the contents of A and sets Z if it matches or S if the comparison goes negative. Then adds 1 to HL and subtracts 1 from BC. P/V is set to (BC!=0), i.e. set when non zero.
  
  
Line 757: Line 783:
 
  |s=S
 
  |s=S
 
  |tstates=21x+16
 
  |tstates=21x+16
 +
|shortfx=do CPI while (!Z && BC>0)
 
}}
 
}}
 
|}
 
|}
:Automatically loops CPI until either Z is set (A is found in the byte pointed to by HL) or P/V is reset (BC reached 0). Flag effects are the same as CPI except that one of the two terminating flag conditions will always be true.
+
:Automatically loops CPI until either Z is set (A is found in the byte pointed to by HL) or P/V is reset (BC reached 0).
 +
:Flag effects are the same as CPI except that one of the two terminating flag conditions will always be true.
  
  
Line 776: Line 804:
 
  |s=S
 
  |s=S
 
  |tstates=16
 
  |tstates=16
 +
|shortfx=HL*==A?; HL--; BC--
 
}}
 
}}
 
|}
 
|}
Line 795: Line 824:
 
  |s=S
 
  |s=S
 
  |tstates=21x+16
 
  |tstates=21x+16
 +
|shortfx=do CPD while (!Z && BC>0)
 
}}
 
}}
 
|}
 
|}
Line 800: Line 830:
  
  
=== Block Fill ===
 
;FILLDE (FILL DE bytes)
 
:{{Opcodelisttop}}
 
{{Opcode|opdesc=FILLDE
 
|ad1=-
 
|ad2=-
 
|status=E
 
|c=?
 
|n=?
 
|pv=?
 
|h=?
 
|z=?
 
|s=?
 
|tstates=?
 
}}
 
|}
 
:Fills BC bytes with the value of A, starting at DE.
 
  
 
=== Arithmetic ===
 
=== Arithmetic ===
Line 832: Line 845:
 
  |s=S
 
  |s=S
 
  |tstates=4
 
  |tstates=4
 +
|shortfx=A+=r
 
}}
 
}}
 
{{Opcode|opdesc=ADD A, n
 
{{Opcode|opdesc=ADD A, n
Line 844: Line 858:
 
  |s=S
 
  |s=S
 
  |tstates=7
 
  |tstates=7
 +
|shortfx=A+=n
 
}}
 
}}
 
{{Opcode|opdesc=ADD A, (HL)
 
{{Opcode|opdesc=ADD A, (HL)
Line 856: Line 871:
 
  |s=S
 
  |s=S
 
  |tstates=7
 
  |tstates=7
 +
|shortfx=A+=HL*
 
}}
 
}}
 
{{Opcode|opdesc=ADD A, (IXY+d)
 
{{Opcode|opdesc=ADD A, (IXY+d)
Line 868: Line 884:
 
  |s=S
 
  |s=S
 
  |tstates=19
 
  |tstates=19
 +
|shortfx=A+=(IXY+d)*
 
}}
 
}}
 
{{Opcode|opdesc=ADD HL, BC/DE/HL/SP
 
{{Opcode|opdesc=ADD HL, BC/DE/HL/SP
Line 880: Line 897:
 
  |s=-
 
  |s=-
 
  |tstates=11
 
  |tstates=11
 +
|shortfx=HL+=rr
 
}}
 
}}
 
{{Opcode|opdesc=ADD IXY, BC/DE/IXY/SP
 
{{Opcode|opdesc=ADD IXY, BC/DE/IXY/SP
Line 892: Line 910:
 
  |s=-
 
  |s=-
 
  |tstates=15
 
  |tstates=15
 +
|shortfx=IXY+=rr
 
}}
 
}}
 
{{Opcode|opdesc=ADD HL/DE/BC, A
 
{{Opcode|opdesc=ADD HL/DE/BC, A
Line 898: Line 917:
 
  |status=E
 
  |status=E
 
  |c=?
 
  |c=?
  |n=?
+
  |n=-
  |pv=?
+
  |pv=-
  |h=?
+
  |h=-
  |z=?
+
  |z=-
  |s=?
+
  |s=-
  |tstates=?
+
  |tstates=8
 +
|shortfx=rr+=unsigned A
 
}}
 
}}
{{Opcode|opdesc=ADD HL/DE/BC, nnnn
+
{{Opcode|opdesc=ADD HL/DE/BC, nn
 
  |ad1=Register
 
  |ad1=Register
 
  |ad2=Immediate
 
  |ad2=Immediate
 
  |status=E
 
  |status=E
  |c=?
+
  |c=-
  |n=?
+
  |n=-
  |pv=?
+
  |pv=-
  |h=?
+
  |h=-
  |z=?
+
  |z=-
  |s=?
+
  |s=-
  |tstates=?
+
  |tstates=16
 +
|shortfx=rr+=nn
 
}}
 
}}
{{Opcode|opdesc=ADD DEHL, A
+
|}
|ad1=Register
+
:Adds values together. Legal combinations are:
|ad2=Accumulator
+
:* When adding 8-bit values the first parameter must be A and the second may be:
|status=E
+
:** The contents of an 8-bit register;
|c=?
+
:** An immediate value;
|n=?
+
:** The contents of memory pointed to by HL or by indexing based on IX or IY.
|pv=?
+
:* When adding 16-bit values the first parameter must be HL, IX or IY and the second must be another 16-bit register pair. If the first parameter is IX or IY, the second cannot be HL or the other index register.  
|h=?
+
:* For 16 bit additions (regular Z80), H is set if a carry occurred in bit 11 (ie, a half carry in the high byte)
|z=?
+
:* On the Spectrum Next the extended opcodes also allow the first parameter to be HL, DE, or BC and the second to be A (A will be zero extended to 16 bits) or an 16bit immediate value.
|s=?
+
 
|tstates=?
+
 
}}
+
;ADC (ADd with Carry)
{{Opcode|opdesc=ADD DEHL, BC
 
|ad1=Register
 
|ad2=Register
 
|status=E
 
|c=?
 
|n=?
 
|pv=?
 
|h=?
 
|z=?
 
|s=?
 
|tstates=?
 
}}
 
{{Opcode|opdesc=ADD DEHL, nnnn
 
|ad1=Register
 
|ad2=Immediate
 
|status=E
 
|c=?
 
|n=?
 
|pv=?
 
|h=?
 
|z=?
 
|s=?
 
|tstates=?
 
}}
 
|}
 
:Adds values together. Legal combinations are:
 
:* When adding 8-bit values the first parameter must be A and the second may be:
 
:** The contents of an 8-bit register;
 
:** An immediate value;
 
:** The contents of memory pointed to by HL or by indexing based on IX or IY.
 
:* When adding 16-bit values the first parameter must be HL, IX or IY and the second must be another 16-bit register pair. If the first parameter is IX or IY, the second cannot be HL or the other index register.  
 
:* On the Spectrum Next the extended opcodes also allow the first parameter to be HL, DE, or BC and the second to be A or an immediate value.
 
:For 16 bit additions, H is set if a carry occurred in bit 11 (ie, a half carry in the high byte)
 
 
 
 
 
;ADC (ADd with Carry)
 
 
:{{Opcodelisttop}}
 
:{{Opcodelisttop}}
 
{{Opcode|opdesc=ADC A, r
 
{{Opcode|opdesc=ADC A, r
Line 977: Line 962:
 
  |s=S
 
  |s=S
 
  |tstates=4
 
  |tstates=4
 +
|shortfx=A+=r+(CF?1:0)
 
}}
 
}}
 
{{Opcode|opdesc=ADC A, n
 
{{Opcode|opdesc=ADC A, n
Line 989: Line 975:
 
  |s=S
 
  |s=S
 
  |tstates=7
 
  |tstates=7
 +
|shortfx=A+=n+(CF?1:0)
 
}}
 
}}
 
{{Opcode|opdesc=ADC A, (HL)
 
{{Opcode|opdesc=ADC A, (HL)
Line 1,001: Line 988:
 
  |s=S
 
  |s=S
 
  |tstates=7
 
  |tstates=7
 +
|shortfx=A+=HL*+(CF?1:0)
 
}}
 
}}
 
{{Opcode|opdesc=ADC A, (IXY+d)
 
{{Opcode|opdesc=ADC A, (IXY+d)
Line 1,013: Line 1,001:
 
  |s=S
 
  |s=S
 
  |tstates=19
 
  |tstates=19
 +
|shortfx=A+=(IXY+d)*+(CF?1:0)
 
}}
 
}}
 
{{Opcode|opdesc=ADC HL, BC/DE/HL/SP
 
{{Opcode|opdesc=ADC HL, BC/DE/HL/SP
Line 1,020: Line 1,009:
 
  |c=S
 
  |c=S
 
  |n=0
 
  |n=0
  |pv=-
+
  |pv=V
 
  |h=!
 
  |h=!
  |z=-
+
  |z=S
  |s=-
+
  |s=S
 
  |tstates=15
 
  |tstates=15
 +
|shortfx=HL+=rr+(CF?1:0)
 
}}
 
}}
 
|}
 
|}
:Adds values together, adding an additional 1 if Carry is set. Legal combinations are the same as for ADD, although there are no extended opcode versions of ADC and in 16-bit values the first parameter can only be HL.  
+
:Adds values together, adding an additional 1 if Carry is set. Legal combinations are the same as for ADD, although there are no extended opcode versions of ADC and in 16-bit values the first parameter can only be HL. For 16-bit values the H flag is set if carry from bit 11; otherwise, it is reset.
  
 
   
 
   
Line 1,038: Line 1,028:
 
  |status=S
 
  |status=S
 
  |c=S
 
  |c=S
  |n=0
+
  |n=1
 
  |pv=V
 
  |pv=V
 
  |h=S
 
  |h=S
Line 1,044: Line 1,034:
 
  |s=S
 
  |s=S
 
  |tstates=4
 
  |tstates=4
 +
|shortfx=A -= r
 
}}
 
}}
 
{{Opcode|opdesc=SUB n
 
{{Opcode|opdesc=SUB n
Line 1,050: Line 1,041:
 
  |status=S
 
  |status=S
 
  |c=S
 
  |c=S
  |n=0
+
  |n=1
 
  |pv=V
 
  |pv=V
 
  |h=S
 
  |h=S
Line 1,056: Line 1,047:
 
  |s=S
 
  |s=S
 
  |tstates=7
 
  |tstates=7
 +
|shortfx=A -= n
 
}}
 
}}
 
{{Opcode|opdesc=SUB (HL)
 
{{Opcode|opdesc=SUB (HL)
Line 1,062: Line 1,054:
 
  |status=S
 
  |status=S
 
  |c=S
 
  |c=S
  |n=0
+
  |n=1
 
  |pv=V
 
  |pv=V
 
  |h=S
 
  |h=S
Line 1,068: Line 1,060:
 
  |s=S
 
  |s=S
 
  |tstates=7
 
  |tstates=7
 +
|shortfx=A -= HL*
 
}}
 
}}
 
{{Opcode|opdesc=SUB (IXY+d)
 
{{Opcode|opdesc=SUB (IXY+d)
Line 1,074: Line 1,067:
 
  |status=S
 
  |status=S
 
  |c=S
 
  |c=S
  |n=0
+
  |n=1
 
  |pv=V
 
  |pv=V
 
  |h=S
 
  |h=S
Line 1,080: Line 1,073:
 
  |s=S
 
  |s=S
 
  |tstates=19
 
  |tstates=19
 +
|shortfx=A -= (IXY+d)*
 
}}
 
}}
{{Opcode|opdesc=SUB DEHL, A
 
|ad1=Register
 
|ad2=Accumulator
 
|status=E
 
|c=?
 
|n=?
 
|pv=?
 
|h=?
 
|z=?
 
|s=?
 
|tstates=?
 
}}
 
{{Opcode|opdesc=SUB DEHL, BC
 
|ad1=Register
 
|ad2=Register
 
|status=E
 
|c=?
 
|n=?
 
|pv=?
 
|h=?
 
|z=?
 
|s=?
 
|tstates=?
 
}}
 
 
 
|}
 
|}
 
:Subtracts a value from A. Legal combinations are the same as for ADD for 8-bit, except that A does not need to be specified as the first parameter because subtraction can only be done from A. SUB cannot be used for 16-bit numbers.  
 
:Subtracts a value from A. Legal combinations are the same as for ADD for 8-bit, except that A does not need to be specified as the first parameter because subtraction can only be done from A. SUB cannot be used for 16-bit numbers.  
Line 1,118: Line 1,087:
 
  |status=S
 
  |status=S
 
  |c=S
 
  |c=S
  |n=0
+
  |n=1
 
  |pv=V
 
  |pv=V
 
  |h=S
 
  |h=S
Line 1,124: Line 1,093:
 
  |s=S
 
  |s=S
 
  |tstates=4
 
  |tstates=4
 +
|shortfx=A-=(r+(CF?1:0))
 
}}
 
}}
 
{{Opcode|opdesc=SBC A, n
 
{{Opcode|opdesc=SBC A, n
Line 1,130: Line 1,100:
 
  |status=S
 
  |status=S
 
  |c=S
 
  |c=S
  |n=0
+
  |n=1
 
  |pv=V
 
  |pv=V
 
  |h=S
 
  |h=S
Line 1,136: Line 1,106:
 
  |s=S
 
  |s=S
 
  |tstates=7
 
  |tstates=7
 +
|shortfx=A-=(n+(CF?1:0))
 
}}
 
}}
 
{{Opcode|opdesc=SBC A, (HL)
 
{{Opcode|opdesc=SBC A, (HL)
Line 1,142: Line 1,113:
 
  |status=S
 
  |status=S
 
  |c=S
 
  |c=S
  |n=0
+
  |n=1
 
  |pv=V
 
  |pv=V
 
  |h=S
 
  |h=S
Line 1,148: Line 1,119:
 
  |s=S
 
  |s=S
 
  |tstates=7
 
  |tstates=7
 +
|shortfx=A-=(HL*+(CF?1:0))
 
}}
 
}}
 
{{Opcode|opdesc=SBC A, (IXY+d)
 
{{Opcode|opdesc=SBC A, (IXY+d)
Line 1,154: Line 1,126:
 
  |status=S
 
  |status=S
 
  |c=S
 
  |c=S
  |n=0
+
  |n=1
 
  |pv=V
 
  |pv=V
 
  |h=S
 
  |h=S
Line 1,160: Line 1,132:
 
  |s=S
 
  |s=S
 
  |tstates=19
 
  |tstates=19
 +
|shortfx=A-=((IXY+d)+(CF?1:0))
 
}}
 
}}
 
{{Opcode|opdesc=SBC HL, BC/DE/HL/SP
 
{{Opcode|opdesc=SBC HL, BC/DE/HL/SP
Line 1,166: Line 1,139:
 
  |status=S
 
  |status=S
 
  |c=S
 
  |c=S
  |n=0
+
  |n=1
  |pv=-
+
  |pv=V
 
  |h=!
 
  |h=!
  |z=-
+
  |z=S
  |s=-
+
  |s=S
 
  |tstates=15
 
  |tstates=15
 +
|shortfx=HL-=(rr+(CF?1:0))
 
}}
 
}}
 
|}
 
|}
:Subtracts values, subtracting an additional 1 if Carry is set. Legal combinations are the same as for ADD, although there are no extended opcode versions of SBC and in 16-bit values the first parameter can only be HL.  
+
:Subtracts values, subtracting an additional 1 if Carry is set. Legal combinations are the same as for ADD, although there are no extended opcode versions of SBC and in 16-bit values the first parameter can only be HL. For 16-bit values the H flag is set if borrow from bit 12; otherwise, it is reset.
  
  
Line 1,186: Line 1,160:
 
  |c=0
 
  |c=0
 
  |n=0
 
  |n=0
  |pv=V
+
  |pv=P
 
  |h=1
 
  |h=1
 
  |z=S
 
  |z=S
 
  |s=S
 
  |s=S
 
  |tstates=4
 
  |tstates=4
 +
|shortfx=A := A & r
 
}}
 
}}
 
{{Opcode|opdesc=AND n
 
{{Opcode|opdesc=AND n
Line 1,198: Line 1,173:
 
  |c=0
 
  |c=0
 
  |n=0
 
  |n=0
  |pv=V
+
  |pv=P
 
  |h=1
 
  |h=1
 
  |z=S
 
  |z=S
 
  |s=S
 
  |s=S
 
  |tstates=7
 
  |tstates=7
 +
|shortfx=A := A & n
 
}}
 
}}
 
{{Opcode|opdesc=AND (HL)
 
{{Opcode|opdesc=AND (HL)
Line 1,210: Line 1,186:
 
  |c=0
 
  |c=0
 
  |n=0
 
  |n=0
  |pv=V
+
  |pv=P
 
  |h=1
 
  |h=1
 
  |z=S
 
  |z=S
 
  |s=S
 
  |s=S
 
  |tstates=7
 
  |tstates=7
 +
|shortfx=A := A & HL*
 
}}
 
}}
 
{{Opcode|opdesc=AND (IXY+d)
 
{{Opcode|opdesc=AND (IXY+d)
Line 1,222: Line 1,199:
 
  |c=0
 
  |c=0
 
  |n=0
 
  |n=0
  |pv=V
+
  |pv=P
 
  |h=1
 
  |h=1
 
  |z=S
 
  |z=S
 
  |s=S
 
  |s=S
 
  |tstates=19
 
  |tstates=19
 +
|shortfx=A := A & (IXY+d)*
 
}}
 
}}
 
{{Opcode|opdesc=OR r
 
{{Opcode|opdesc=OR r
Line 1,234: Line 1,212:
 
  |c=0
 
  |c=0
 
  |n=0
 
  |n=0
  |pv=V
+
  |pv=P
 
  |h=0
 
  |h=0
 
  |z=S
 
  |z=S
 
  |s=S
 
  |s=S
 
  |tstates=4
 
  |tstates=4
 +
|shortfx=A := A OR r
 
}}
 
}}
 
{{Opcode|opdesc=OR n
 
{{Opcode|opdesc=OR n
Line 1,246: Line 1,225:
 
  |c=0
 
  |c=0
 
  |n=0
 
  |n=0
  |pv=V
+
  |pv=P
 
  |h=0
 
  |h=0
 
  |z=S
 
  |z=S
 
  |s=S
 
  |s=S
 
  |tstates=7
 
  |tstates=7
 +
|shortfx=A := A OR n
 
}}
 
}}
 
{{Opcode|opdesc=OR (HL)
 
{{Opcode|opdesc=OR (HL)
Line 1,258: Line 1,238:
 
  |c=0
 
  |c=0
 
  |n=0
 
  |n=0
  |pv=V
+
  |pv=P
 
  |h=0
 
  |h=0
 
  |z=S
 
  |z=S
 
  |s=S
 
  |s=S
 
  |tstates=7
 
  |tstates=7
 +
|shortfx=A := A OR HL*
 
}}
 
}}
 
{{Opcode|opdesc=OR (IXY+d)
 
{{Opcode|opdesc=OR (IXY+d)
Line 1,270: Line 1,251:
 
  |c=0
 
  |c=0
 
  |n=0
 
  |n=0
  |pv=V
+
  |pv=P
 
  |h=0
 
  |h=0
 
  |z=S
 
  |z=S
 
  |s=S
 
  |s=S
 
  |tstates=19
 
  |tstates=19
 +
|shortfx=A := A OR (IXY+d)*
 
}}
 
}}
 
{{Opcode|opdesc=XOR r
 
{{Opcode|opdesc=XOR r
Line 1,287: Line 1,269:
 
  |s=S
 
  |s=S
 
  |tstates=4
 
  |tstates=4
 +
|shortfx=A := A ^ r
 
}}
 
}}
 
{{Opcode|opdesc=XOR n
 
{{Opcode|opdesc=XOR n
Line 1,299: Line 1,282:
 
  |s=S
 
  |s=S
 
  |tstates=7
 
  |tstates=7
 +
|shortfx=A := A ^ n
 
}}
 
}}
 
{{Opcode|opdesc=XOR (HL)
 
{{Opcode|opdesc=XOR (HL)
Line 1,311: Line 1,295:
 
  |s=S
 
  |s=S
 
  |tstates=7
 
  |tstates=7
 +
|shortfx=A := A ^ HL*
 
}}
 
}}
 
{{Opcode|opdesc=XOR (IXY+d)
 
{{Opcode|opdesc=XOR (IXY+d)
Line 1,323: Line 1,308:
 
  |s=S
 
  |s=S
 
  |tstates=19
 
  |tstates=19
 +
|shortfx=A := A ^ (IXY+d)*
 
}}
 
}}
 
|}
 
|}
 
:Performs the appropriate bitwise operator on A. Legal combinations are the same as SUB.  
 
:Performs the appropriate bitwise operator on A. Legal combinations are the same as SUB.  
  
 
+
:XOR A is faster and shorter than LD A,0
  
 
;MIRROR
 
;MIRROR
Line 1,335: Line 1,321:
 
  |ad2=-
 
  |ad2=-
 
  |status=E
 
  |status=E
  |c=?
+
  |c=-
  |n=?
+
  |n=-
  |pv=?
+
  |pv=-
  |h=?
+
  |h=-
  |z=?
+
  |z=-
  |s=?
+
  |s=-
  |tstates=?
+
  |tstates=8
}}
+
  |shortfx=A[76543210]:=A[01234567]
{{Opcode|opdesc=MIRROR DE
 
|ad1=Register
 
|ad2=-
 
|status=E
 
|c=?
 
|n=?
 
|pv=?
 
|h=?
 
  |z=?
 
|s=?
 
|tstates=?
 
 
}}
 
}}
 
|}
 
|}
:Next extended opcode. Mirrors (reverses the order) of bits in the specified register.
+
:Next extended opcode. Mirrors (reverses the order) of bits in the accumulator. Older core versions supported MIRROR DE, but this was removed.
  
  
Line 1,373: Line 1,348:
 
  |s=S
 
  |s=S
 
  |tstates=4
 
  |tstates=4
 +
|shortfx=A-=r?
 
}}
 
}}
 
{{Opcode|opdesc=CP n
 
{{Opcode|opdesc=CP n
Line 1,385: Line 1,361:
 
  |s=S
 
  |s=S
 
  |tstates=7
 
  |tstates=7
 +
|shortfx=A-=n?
 
}}
 
}}
 
{{Opcode|opdesc=CP (HL)
 
{{Opcode|opdesc=CP (HL)
Line 1,397: Line 1,374:
 
  |s=S
 
  |s=S
 
  |tstates=7
 
  |tstates=7
 +
|shortfx=A-=HL*?
 
}}
 
}}
 
{{Opcode|opdesc=CP (IXY+d)
 
{{Opcode|opdesc=CP (IXY+d)
Line 1,409: Line 1,387:
 
  |s=S
 
  |s=S
 
  |tstates=19
 
  |tstates=19
 +
|shortfx=A-=(IXY+d)?
 
}}
 
}}
 
|}
 
|}
Line 1,423: Line 1,402:
 
  |c=S
 
  |c=S
 
  |n=?
 
  |n=?
  |pv=V
+
  |pv=P
 
  |h=S
 
  |h=S
 
  |z=S
 
  |z=S
 
  |s=S
 
  |s=S
  |tstates=?
+
  |tstates=11
 +
|shortfx=A&n?
 
}}
 
}}
 
|}
 
|}
Line 1,447: Line 1,427:
 
  |s=S
 
  |s=S
 
  |tstates=4
 
  |tstates=4
 +
|shortfx=r++
 
}}
 
}}
 
{{Opcode|opdesc=INC (HL)
 
{{Opcode|opdesc=INC (HL)
Line 1,459: Line 1,440:
 
  |s=S
 
  |s=S
 
  |tstates=11
 
  |tstates=11
 +
|shortfx=HL*++
 
}}
 
}}
 
{{Opcode|opdesc=INC (IXY+d)
 
{{Opcode|opdesc=INC (IXY+d)
Line 1,471: Line 1,453:
 
  |s=S
 
  |s=S
 
  |tstates=23
 
  |tstates=23
 +
|shortfx=(IXY+d)*++
 
}}
 
}}
 
{{Opcode|opdesc=INC BC/DE/HL/SP
 
{{Opcode|opdesc=INC BC/DE/HL/SP
Line 1,483: Line 1,466:
 
  |s=-
 
  |s=-
 
  |tstates=6
 
  |tstates=6
 +
|shortfx=rr++
 
}}
 
}}
 
{{Opcode|opdesc=INC IXY
 
{{Opcode|opdesc=INC IXY
Line 1,495: Line 1,479:
 
  |s=-
 
  |s=-
 
  |tstates=10
 
  |tstates=10
}}
+
  |shortfx=rr++
{{Opcode|opdesc=INC DEHL
 
|ad1=Register
 
|ad2=-
 
|status=E
 
|c=?
 
|n=?
 
|pv=?
 
|h=?
 
|z=?
 
|s=?
 
  |tstates=?
 
 
}}
 
}}
 
|}
 
|}
Line 1,513: Line 1,486:
  
  
;DEC
+
;DEC (DECrement)
 
:{{Opcodelisttop}}
 
:{{Opcodelisttop}}
 
{{Opcode|opdesc=DEC r
 
{{Opcode|opdesc=DEC r
Line 1,526: Line 1,499:
 
  |s=S
 
  |s=S
 
  |tstates=4
 
  |tstates=4
 +
|shortfx=r--
 
}}
 
}}
 
{{Opcode|opdesc=DEC (HL)
 
{{Opcode|opdesc=DEC (HL)
Line 1,538: Line 1,512:
 
  |s=S
 
  |s=S
 
  |tstates=11
 
  |tstates=11
 +
|shortfx=HL*--
 
}}
 
}}
 
{{Opcode|opdesc=DEC (IXY+d)
 
{{Opcode|opdesc=DEC (IXY+d)
Line 1,550: Line 1,525:
 
  |s=S
 
  |s=S
 
  |tstates=23
 
  |tstates=23
 +
|shortfx=(IXY+D)*--
 
}}
 
}}
 
{{Opcode|opdesc=DEC BC/DE/HL/SP
 
{{Opcode|opdesc=DEC BC/DE/HL/SP
Line 1,562: Line 1,538:
 
  |s=-
 
  |s=-
 
  |tstates=6
 
  |tstates=6
 +
|shortfx=rr--
 
}}
 
}}
 
{{Opcode|opdesc=DEC IXY
 
{{Opcode|opdesc=DEC IXY
Line 1,574: Line 1,551:
 
  |s=-
 
  |s=-
 
  |tstates=10
 
  |tstates=10
}}
+
  |shortfx=rr--
{{Opcode|opdesc=DEC DEHL
 
  |ad1=Register
 
|ad2=-
 
|status=E
 
|c=?
 
|n=?
 
|pv=?
 
|h=?
 
|z=?
 
|s=?
 
|tstates=?
 
 
}}
 
}}
 
|}
 
|}
Line 1,592: Line 1,558:
  
  
;RLC (Rotate Left and Copy)
+
;RLC (Rotate Left Circular)
 
:{{Opcodelisttop}}
 
:{{Opcodelisttop}}
 
{{Opcode|opdesc=RLC r
 
{{Opcode|opdesc=RLC r
Line 1,605: Line 1,571:
 
  |s=S
 
  |s=S
 
  |tstates=8
 
  |tstates=8
 +
|shortfx=x:=r[7]; r:=r<<1; r[0]:=x; CF:=x
 
}}
 
}}
 
{{Opcode|opdesc=RLC (HL)
 
{{Opcode|opdesc=RLC (HL)
Line 1,617: Line 1,584:
 
  |s=S
 
  |s=S
 
  |tstates=15
 
  |tstates=15
 +
|shortfx=x:=HL*[7]; HL*:=HL*<<1; HL*[0]:=x; CF:=x
 
}}
 
}}
 
{{Opcode|opdesc=RLC (IXY+d)
 
{{Opcode|opdesc=RLC (IXY+d)
Line 1,629: Line 1,597:
 
  |s=S
 
  |s=S
 
  |tstates=23
 
  |tstates=23
 +
|shortfx=x:=(IXY+d)*[7]; (IXY+d)*:=(IXY+d)*<<1; (IXY+d)*[0]:=x; CF:=x
 
}}
 
}}
 
{{Opcode|opdesc=RLC r,(IX+d)
 
{{Opcode|opdesc=RLC r,(IX+d)
Line 1,640: Line 1,609:
 
  |z=S
 
  |z=S
 
  |s=S
 
  |s=S
  |tstates=?
+
  |tstates=23
 +
|shortfx=x:=(IX+d)*[7]; (IX+d)*:=(IX+d)*<<1; (IX+d)*[0]:=x; CF:=x; r:=(IX+d)*
 
}}
 
}}
 
|}
 
|}
Line 1,660: Line 1,630:
 
  |s=S
 
  |s=S
 
  |tstates=8
 
  |tstates=8
 +
|shortfx=x:=r[7]; r:=r<<1; r[0]:=CF; CF:=x
 
}}
 
}}
 
{{Opcode|opdesc=RL (HL)
 
{{Opcode|opdesc=RL (HL)
Line 1,672: Line 1,643:
 
  |s=S
 
  |s=S
 
  |tstates=15
 
  |tstates=15
 +
|shortfx=x:=HL*[7]; HL*:=HL*<<1; HL*[0]:=CF; CF:=x
 
}}
 
}}
 
{{Opcode|opdesc=RL (IXY+d)
 
{{Opcode|opdesc=RL (IXY+d)
Line 1,684: Line 1,656:
 
  |s=S
 
  |s=S
 
  |tstates=23
 
  |tstates=23
 +
|shortfx=x:=(IXY+d)*[7]; (IXY+d)*:=(IXY+d)*<<1; (IXY+d)*[0]:=CF; CF:=x
 
}}
 
}}
 
{{Opcode|opdesc=RL r,(IX+d)
 
{{Opcode|opdesc=RL r,(IX+d)
Line 1,695: Line 1,668:
 
  |z=S
 
  |z=S
 
  |s=S
 
  |s=S
  |tstates=?
+
  |tstates=23
 +
|shortfx=x:=(IX+d)*[7]; (IX+d)*:=(IX+d)*<<1; (IX+d)*[0]:=CF; CF:=x; r:=(IX+d)*
 
}}
 
}}
  
Line 1,703: Line 1,677:
  
  
;RRC, RR (Rotate Right and Copy, Rotate Right)
+
;RRC, RR (Rotate Right Circular, Rotate Right)
 
:{{Opcodelisttop}}
 
:{{Opcodelisttop}}
 
{{Opcode|opdesc=RRC r
 
{{Opcode|opdesc=RRC r
Line 1,716: Line 1,690:
 
  |s=S
 
  |s=S
 
  |tstates=8
 
  |tstates=8
 +
|shortfx=x:=r[0]; r:=r>>1; r[7]:=x; CF:=x
 
}}
 
}}
 
{{Opcode|opdesc=RRC (HL)
 
{{Opcode|opdesc=RRC (HL)
Line 1,728: Line 1,703:
 
  |s=S
 
  |s=S
 
  |tstates=15
 
  |tstates=15
 +
|shortfx=x:=HL*[0]; HL*:=HL*>>1; HL*[7]:=x; CF:=x
 
}}
 
}}
 
{{Opcode|opdesc=RRC (IXY+d)
 
{{Opcode|opdesc=RRC (IXY+d)
Line 1,740: Line 1,716:
 
  |s=S
 
  |s=S
 
  |tstates=23
 
  |tstates=23
 +
|shortfx=x:=(IXY+d)*[0]; (IXY+d)*:=(IXY+d)*>>1; (IXY+d)*[7]:=x; CF:=x
 +
 
}}
 
}}
 
{{Opcode|opdesc=RRC r,(IX+d)
 
{{Opcode|opdesc=RRC r,(IX+d)
Line 1,751: Line 1,729:
 
  |z=S
 
  |z=S
 
  |s=S
 
  |s=S
  |tstates=?
+
  |tstates=23
 +
|shortfx=x:=(IX+d)*[0]; (IX+d)*:=(IX+d)*>>1; (IX+d)*[7]:=x; CF:=x; r:=(IX+d)*
 
}}
 
}}
 
{{Opcode|opdesc=RR r
 
{{Opcode|opdesc=RR r
Line 1,764: Line 1,743:
 
  |s=S
 
  |s=S
 
  |tstates=8
 
  |tstates=8
 +
|shortfx=x:=r[0]; r:=r>>1; r[7]:=CF; CF:=x
 
}}
 
}}
 
{{Opcode|opdesc=RR (HL)
 
{{Opcode|opdesc=RR (HL)
Line 1,776: Line 1,756:
 
  |s=S
 
  |s=S
 
  |tstates=15
 
  |tstates=15
 +
|shortfx=x:=HL*[0]; HL*:=HL*>>1; HL*[7]:=CF; CF:=x
 
}}
 
}}
 
{{Opcode|opdesc=RR (IXY+d)
 
{{Opcode|opdesc=RR (IXY+d)
Line 1,788: Line 1,769:
 
  |s=S
 
  |s=S
 
  |tstates=23
 
  |tstates=23
 +
|shortfx=x:=(IXY+d)*[0]; (IXY+d)*:=(IXY+d)*>>1; (IXY+d)*[7]:=CF; CF:=x
 
}}
 
}}
 
{{Opcode|opdesc=RR r,(IX+d)
 
{{Opcode|opdesc=RR r,(IX+d)
Line 1,799: Line 1,781:
 
  |z=S
 
  |z=S
 
  |s=S
 
  |s=S
  |tstates=?
+
  |tstates=23
 +
|shortfx=x:=(IX+d)*[0]; (IX+d)*:=(IX+d)*>>1; (IX+d)*[7]:=CF; CF:=x; r=(IX+d)*
 
}}
 
}}
 
|}
 
|}
Line 1,819: Line 1,802:
 
  |s=S
 
  |s=S
 
  |tstates=8
 
  |tstates=8
 +
|shortfx=r:=r<<1
 
}}
 
}}
 
{{Opcode|opdesc=SLA (HL)
 
{{Opcode|opdesc=SLA (HL)
Line 1,831: Line 1,815:
 
  |s=S
 
  |s=S
 
  |tstates=15
 
  |tstates=15
 +
|shortfx=HL*:=HL*<<1
 
}}
 
}}
 
{{Opcode|opdesc=SLA (IXY+d)
 
{{Opcode|opdesc=SLA (IXY+d)
Line 1,843: Line 1,828:
 
  |s=S
 
  |s=S
 
  |tstates=23
 
  |tstates=23
 +
|shortfx=(IXY+d)*:=(IXY+d)*<<1
 
}}
 
}}
 
{{Opcode|opdesc=SLA r,(IX+d)
 
{{Opcode|opdesc=SLA r,(IX+d)
Line 1,854: Line 1,840:
 
  |z=S
 
  |z=S
 
  |s=S
 
  |s=S
  |tstates=?
+
  |tstates=23
 +
|shortfx=(IX+d)*:=(IX+d)*<<1; r=(IX+d)*
 
}}
 
}}
 
|}
 
|}
Line 1,874: Line 1,861:
 
  |s=S
 
  |s=S
 
  |tstates=8
 
  |tstates=8
 +
|shortfx=r:=r>>1 OR r[7]
 
}}
 
}}
 
{{Opcode|opdesc=SRA (HL)
 
{{Opcode|opdesc=SRA (HL)
Line 1,886: Line 1,874:
 
  |s=S
 
  |s=S
 
  |tstates=15
 
  |tstates=15
 +
|shortfx=HL*:=HL*>>1 OR HL*[7]
 
}}
 
}}
 
{{Opcode|opdesc=SRA (IXY+d)
 
{{Opcode|opdesc=SRA (IXY+d)
Line 1,898: Line 1,887:
 
  |s=S
 
  |s=S
 
  |tstates=23
 
  |tstates=23
 +
|shortfx=(IXY+d)*:=(IXY+d)*>>1 OR (IXY+d)*[7]
 
}}
 
}}
 
{{Opcode|opdesc=SRA r,(IX+d)
 
{{Opcode|opdesc=SRA r,(IX+d)
Line 1,909: Line 1,899:
 
  |z=S
 
  |z=S
 
  |s=S
 
  |s=S
  |tstates=?
+
  |tstates=23
 +
|shortfx=(IX+d)*:=(IX+d)*>>1 OR (IX+d)*[7]; r:=(IX+d)*
 
}}
 
}}
 
|}
 
|}
Line 1,929: Line 1,920:
 
  |s=0
 
  |s=0
 
  |tstates=8
 
  |tstates=8
 +
|shortfx=r:=unsigned(r)>>1
 
}}
 
}}
 
{{Opcode|opdesc=SRL (HL)
 
{{Opcode|opdesc=SRL (HL)
Line 1,941: Line 1,933:
 
  |s=0
 
  |s=0
 
  |tstates=15
 
  |tstates=15
 +
|shortfx=HL*:=unsigned(HL*)>>1
 
}}
 
}}
 
{{Opcode|opdesc=SRL (IXY+d)
 
{{Opcode|opdesc=SRL (IXY+d)
Line 1,953: Line 1,946:
 
  |s=0
 
  |s=0
 
  |tstates=23
 
  |tstates=23
 +
|shortfx=(IXY+d)*:=unsigned((IXY+d)*)>>1
 
}}
 
}}
{{Opcode|opdesc=SRL r,(IX+d)
+
{{Opcode|opdesc=SRL r,(IXY+d)
 
  |ad1=Register
 
  |ad1=Register
 
  |ad2=Indexed
 
  |ad2=Indexed
Line 1,964: Line 1,958:
 
  |z=S
 
  |z=S
 
  |s=0
 
  |s=0
  |tstates=?
+
  |tstates=23
 +
|shortfx=(IXY+d)*:=unsigned((IXY+d)*)>>1; r:=(IXY+d)*
 
}}
 
}}
 
|}
 
|}
Line 1,984: Line 1,979:
 
  |s=-
 
  |s=-
 
  |tstates=4
 
  |tstates=4
 +
|shortfx=x:=A[7]; A:=A<<1; A[0]:=x; CF:=x
 
}}
 
}}
 
{{Opcode|opdesc=RLA
 
{{Opcode|opdesc=RLA
Line 1,996: Line 1,992:
 
  |s=-
 
  |s=-
 
  |tstates=4
 
  |tstates=4
 +
|shortfx=x:=A[7]; A:=A<<1; A[0]:=CF; CF:=x
 
}}
 
}}
 
{{Opcode|opdesc=RRCA
 
{{Opcode|opdesc=RRCA
Line 2,008: Line 2,005:
 
  |s=-
 
  |s=-
 
  |tstates=4
 
  |tstates=4
 +
|shortfx=x:=A[0]; A:=A>>1; A[7]:=x; CF:=x
 
}}
 
}}
 
{{Opcode|opdesc=RRA
 
{{Opcode|opdesc=RRA
Line 2,020: Line 2,018:
 
  |s=-
 
  |s=-
 
  |tstates=4
 
  |tstates=4
 +
|shortfx=x:=A[0]; A:=A>>1; A[7]:=CF; CF:=x
 
}}
 
}}
 
|}
 
|}
Line 2,031: Line 2,030:
  
  
;SL1 (Shift Left and Add 1)
+
;SL1 or SLI (Shift Left and Add 1) or (Shift Left and Increment)
 
:{{Opcodelisttop}}
 
:{{Opcodelisttop}}
 
{{Opcode|opdesc=SL1 r
 
{{Opcode|opdesc=SL1 r
Line 2,044: Line 2,043:
 
  |s=S
 
  |s=S
 
  |tstates=8
 
  |tstates=8
 +
|shortfx=r:=(r<<1)+1
 
}}
 
}}
 
{{Opcode|opdesc=SL1 (HL)
 
{{Opcode|opdesc=SL1 (HL)
Line 2,056: Line 2,056:
 
  |s=S
 
  |s=S
 
  |tstates=15
 
  |tstates=15
 +
|shortfx=HL*:=(HL*<<1)+1
 
}}
 
}}
 
{{Opcode|opdesc=SL1 (IXY+d)
 
{{Opcode|opdesc=SL1 (IXY+d)
Line 2,068: Line 2,069:
 
  |s=S
 
  |s=S
 
  |tstates=23
 
  |tstates=23
 +
|shortfx=(IXY+d)*:=((IXY+d)*<<1)+1
 
}}
 
}}
{{Opcode|opdesc=SL1 r,(IX+d)
+
{{Opcode|opdesc=SL1 r,(IXY+d)
 
  |ad1=Register
 
  |ad1=Register
 
  |ad2=Indexed
 
  |ad2=Indexed
Line 2,079: Line 2,081:
 
  |z=S
 
  |z=S
 
  |s=S
 
  |s=S
  |tstates=?
+
  |tstates=23
 +
|shortfx=(IXY+d)*:=((IXY+d)*<<1)+1; r=(IXY+d)*
 
}}
 
}}
 
|}
 
|}
Line 2,086: Line 2,089:
  
  
;RLD
+
;RLD (Rotate Left bcd Digit)
 
:{{Opcodelisttop}}
 
:{{Opcodelisttop}}
 
{{Opcode|opdesc=RLD
 
{{Opcode|opdesc=RLD
Line 2,099: Line 2,102:
 
  |s=S
 
  |s=S
 
  |tstates=18
 
  |tstates=18
 +
|shortfx=x=HL*; HL*[0123]:=A[0123]; HL*[7654]:=x[0123]; A[0123]:=x[7654] 
 
}}
 
}}
 
|}
 
|}
Line 2,105: Line 2,109:
  
  
;RRD
+
;RRD (Rotate Right bcd Digit)
 
:{{Opcodelisttop}}
 
:{{Opcodelisttop}}
 
{{Opcode|opdesc=RRD
 
{{Opcode|opdesc=RRD
Line 2,118: Line 2,122:
 
  |s=S
 
  |s=S
 
  |tstates=18
 
  |tstates=18
 +
|shortfx=x=HL*; HL*[7654]:=A[0123]; HL*[0123]:=x[7654]; A[0123]:=x[0123]
 
}}
 
}}
 
|}
 
|}
Line 2,123: Line 2,128:
  
  
 
+
;Barrel (variable amount) shift and rotate (cores v2+ only)
;CPL (ComPLement)
 
 
:{{Opcodelisttop}}
 
:{{Opcodelisttop}}
{{Opcode|opdesc=CPL
+
{{Opcode|opdesc=BSLA DE,B
 
  |ad1=-
 
  |ad1=-
 
  |ad2=-
 
  |ad2=-
  |status=S
+
  |status=E
 
  |c=-
 
  |c=-
  |n=1
+
  |n=-
 
  |pv=-
 
  |pv=-
  |h=1
+
  |h=-
 
  |z=-
 
  |z=-
 
  |s=-
 
  |s=-
  |tstates=4
+
|shortfx=DE:=DE<<(B&31)
 +
  |tstates=8
 
}}
 
}}
|}
+
{{Opcode|opdesc=BSRA DE,B
:Inverts the contents of the accumulator.
 
 
 
 
 
 
 
;NEG (NEGate)
 
:{{Opcodelisttop}}
 
{{Opcode|opdesc=NEG
 
 
  |ad1=-
 
  |ad1=-
 
  |ad2=-
 
  |ad2=-
  |status=S
+
  |status=E
  |c=!
+
  |c=-
  |n=1
+
  |n=-
  |pv=!
+
  |pv=-
  |h=S
+
  |h=-
  |z=S
+
  |z=-
  |s=S
+
  |s=-
 +
|shortfx=DE:=signed(DE)>>(B&31)
 
  |tstates=8
 
  |tstates=8
 
}}
 
}}
|}
+
{{Opcode|opdesc=BSRL DE,B
:Subtracts the contents of the accumulator from zero, making it negative for the purpose of two's complement. P/V is set if A previously held $80. C is set if accumulator did not previously hold $00.
 
 
 
 
 
 
 
;CCF (Craunch Carry Flag)
 
:{{Opcodelisttop}}
 
{{Opcode|opdesc=CCF
 
 
  |ad1=-
 
  |ad1=-
 
  |ad2=-
 
  |ad2=-
  |status=S
+
  |status=E
  |c=!
+
  |c=-
  |n=0
+
  |n=-
 
  |pv=-
 
  |pv=-
  |h=!
+
  |h=-
 
  |z=-
 
  |z=-
 
  |s=-
 
  |s=-
  |tstates=4
+
|shortfx=DE:=unsigned(DE)>>(B&31)
 +
  |tstates=8
 
}}
 
}}
|}
+
{{Opcode|opdesc=BSRF DE,B
:Inverts the carry flag. (Does not, as might be assumed, clear it!) Also sets H to the previous value of the carry flag.
 
 
 
 
 
 
 
;SCF (Set Carry Flag)
 
:{{Opcodelisttop}}
 
{{Opcode|opdesc=CCF
 
 
  |ad1=-
 
  |ad1=-
 
  |ad2=-
 
  |ad2=-
  |status=S
+
  |status=E
  |c=1
+
  |c=-
  |n=0
+
  |n=-
 +
|pv=-
 +
|h=-
 +
|z=-
 +
|s=-
 +
|shortfx=DE:=~(unsigned(~DE)>>(B&31))
 +
|tstates=8
 +
}}
 +
{{Opcode|opdesc=BRLC DE,B
 +
|ad1=-
 +
|ad2=-
 +
|status=E
 +
|c=-
 +
|n=-
 
  |pv=-
 
  |pv=-
  |h=0
+
  |h=-
 
  |z=-
 
  |z=-
 
  |s=-
 
  |s=-
  |tstates=4
+
|shortfx=DE:=DE<<(B&15) OR DE>>(16-B&15)
 +
  |tstates=8
 
}}
 
}}
 
|}
 
|}
:Sets the carry flag.
+
:Shift instructions use only bits 4..0 of B, BSLA shifts DE left, BSRA/BSRL/BSRF shifts DE right in arithmetic/logical/fill-one way. BRLC rotates DE left by B places, uses only bits 3..0 of B (to rotate right, use B=16-places).
  
 +
If you are implementing BSRF in C (or similar), be careful with implicit variable type promotion. You will need to do something like this: DE:=~((uint16_t)~DE>>(B&31))
  
  
;BIT
+
;CPL (ComPLement)
 
:{{Opcodelisttop}}
 
:{{Opcodelisttop}}
{{Opcode|opdesc=BIT b,r
+
{{Opcode|opdesc=CPL
  |ad1=Immediate
+
  |ad1=-
  |ad2=Register
+
  |ad2=-
 
  |status=S
 
  |status=S
 
  |c=-
 
  |c=-
  |n=0
+
  |n=1
  |pv=!
+
  |pv=-
 
  |h=1
 
  |h=1
  |z=!
+
  |z=-
  |s=!
+
  |s=-
  |tstates=8
+
  |tstates=4
 +
|shortfx=A:=~A
 
}}
 
}}
{{Opcode|opdesc=BIT b,(HL)
+
|}
|ad1=Immediate
+
:Inverts the contents of the accumulator.
|ad2=Indirect
 
|status=S
 
|c=-
 
|n=0
 
|pv=!
 
|h=1
 
|z=!
 
|s=!
 
|tstates=12
 
}}
 
{{Opcode|opdesc=BIT b,(IXY+d)
 
|ad1=Immediate
 
|ad2=Indexed
 
|status=S
 
|c=-
 
|n=0
 
|pv=!
 
|h=1
 
|z=!
 
|s=!
 
|tstates=12
 
}}
 
|}
 
:Tests if a bit is set on target value. The first parameter states which bit. The second can be any 8-bit register, or the location in memory pointed to by HL or indexed by IX or IY. Sets Z if specified bit was 0. S and P/V are destroyed.
 
  
  
  
;SET
+
;NEG (NEGate)
 
:{{Opcodelisttop}}
 
:{{Opcodelisttop}}
{{Opcode|opdesc=SET b,r
+
{{Opcode|opdesc=NEG
  |ad1=Immediate
+
  |ad1=-
  |ad2=Register
+
  |ad2=-
 
  |status=S
 
  |status=S
  |c=-
+
  |c=!
  |n=-
+
  |n=1
  |pv=-
+
  |pv=!
  |h=-
+
  |h=S
  |z=-
+
  |z=S
  |s=-
+
  |s=S
 
  |tstates=8
 
  |tstates=8
 +
|shortfx=A:=0-A
 
}}
 
}}
{{Opcode|opdesc=SET b,(HL)
+
|}
  |ad1=Immediate
+
:Subtracts the contents of the accumulator from zero, making it negative for the purpose of two's complement. P/V is set if A previously held $80. C is set if accumulator did not previously hold $00.
  |ad2=Register
+
 
 +
 
 +
 
 +
;CCF (Complement Carry Flag)
 +
:{{Opcodelisttop}}
 +
{{Opcode|opdesc=CCF
 +
  |ad1=-
 +
  |ad2=-
 
  |status=S
 
  |status=S
  |c=-
+
  |c=!
  |n=-
+
  |n=0
 
  |pv=-
 
  |pv=-
  |h=-
+
  |h=!
  |z=!
+
  |z=-
  |s=!
+
  |s=-
  |tstates=15
+
  |tstates=4
 +
|shortfx=CF:=!CF
 
}}
 
}}
{{Opcode|opdesc=SET b,(IXY+d)
+
|}
  |ad1=Immediate
+
:Inverts the carry flag. (Does not, as might be assumed, clear it!) Also sets H to the previous value of the carry flag.
  |ad2=Indexed
+
 
 +
 
 +
 
 +
;SCF (Set Carry Flag)
 +
:{{Opcodelisttop}}
 +
{{Opcode|opdesc=SCF
 +
  |ad1=-
 +
  |ad2=-
 
  |status=S
 
  |status=S
  |c=-
+
  |c=1
  |n=-
+
  |n=0
 
  |pv=-
 
  |pv=-
  |h=-
+
  |h=0
 
  |z=-
 
  |z=-
 
  |s=-
 
  |s=-
  |tstates=23
+
  |tstates=4
 +
|shortfx=CF:=1
 
}}
 
}}
{{Opcode|opdesc=SET r,b,(IX+d)
+
|}
 +
:Sets the carry flag.
 +
 
 +
 
 +
 
 +
;BIT (test BIT)
 +
:{{Opcodelisttop}}
 +
{{Opcode|opdesc=BIT b,r
 
  |ad1=Immediate
 
  |ad1=Immediate
  |ad2=Indexed
+
  |ad2=Register
  |status=U
+
  |status=S
 
  |c=-
 
  |c=-
  |n=-
+
  |n=0
  |pv=-
+
|pv=?
  |h=-
+
|h=1
  |z=-
+
|z=!
  |s=-
+
|s=?
  |tstates=?
+
|tstates=8
 +
|shortfx=r[b]==1?
 +
}}
 +
{{Opcode|opdesc=BIT b,(HL)
 +
|ad1=Immediate
 +
|ad2=Indirect
 +
|status=S
 +
|c=-
 +
|n=0
 +
  |pv=?
 +
  |h=1
 +
  |z=!
 +
  |s=?
 +
  |tstates=12
 +
|shortfx=HL*[b]==1?
 
}}
 
}}
{{Opcode|opdesc=SETAE
+
{{Opcode|opdesc=BIT b,(IXY+d)
  |ad1=-
+
  |ad1=Immediate
  |ad2=-
+
  |ad2=Indexed
  |status=E
+
  |status=S
  |c=?
+
  |c=-
  |n=?
+
  |n=0
 
  |pv=?
 
  |pv=?
  |h=?
+
  |h=1
  |z=?
+
  |z=!
 
  |s=?
 
  |s=?
  |tstates=?
+
  |tstates=20
 +
|shortfx=(IXY+d)*[b]==1?
 
}}
 
}}
 
|}
 
|}
:Sets the numbered bit on target value. The possible targets are the same as BIT. The three parameter variant is undocumented and stores the result in a register as well as performing the SET. SETAE is a Next extended opcode which takes the bit number to set from e (only the lower 3 bits) and sets that bit on the accumulator.
+
:Tests if a bit is set on target value. The first parameter states which bit. The second can be any 8-bit register, or the location in memory pointed to by HL or indexed by IX or IY. Sets Z if specified bit was 0. S and P/V are destroyed.
  
  
  
;RES (RESet)
+
;SET (SET bit)
 
:{{Opcodelisttop}}
 
:{{Opcodelisttop}}
{{Opcode|opdesc=RES b,r
+
{{Opcode|opdesc=SET b,r
 
  |ad1=Immediate
 
  |ad1=Immediate
 
  |ad2=Register
 
  |ad2=Register
Line 2,323: Line 2,340:
 
  |s=-
 
  |s=-
 
  |tstates=8
 
  |tstates=8
 +
|shortfx=r:=r OR (1<<b)
 
}}
 
}}
{{Opcode|opdesc=RES b,(HL)
+
{{Opcode|opdesc=SET b,(HL)
 
  |ad1=Immediate
 
  |ad1=Immediate
 
  |ad2=Register
 
  |ad2=Register
Line 2,332: Line 2,350:
 
  |pv=-
 
  |pv=-
 
  |h=-
 
  |h=-
  |z=!
+
  |z=-
  |s=!
+
  |s=-
 
  |tstates=15
 
  |tstates=15
 +
|shortfx=HL*:=HL* OR (1<<b)
 
}}
 
}}
{{Opcode|opdesc=RES b,(IXY+d)
+
{{Opcode|opdesc=SET b,(IXY+d)
 
  |ad1=Immediate
 
  |ad1=Immediate
 
  |ad2=Indexed
 
  |ad2=Indexed
Line 2,347: Line 2,366:
 
  |s=-
 
  |s=-
 
  |tstates=23
 
  |tstates=23
 +
|shortfx=(IXY+d)*:=(IXY+d)* OR (1<<b)
 
}}
 
}}
{{Opcode|opdesc=RES r,b,(IX+d)
+
{{Opcode|opdesc=SET r,b,(IX+d)
 
  |ad1=Immediate
 
  |ad1=Immediate
 
  |ad2=Indexed
 
  |ad2=Indexed
Line 2,358: Line 2,378:
 
  |z=-
 
  |z=-
 
  |s=-
 
  |s=-
  |tstates=?
+
  |tstates=23
 +
|shortfx=(IX+d)*:=(IX+d)* OR (1<<b); r:=(IX+d)*
 
}}
 
}}
|}
+
{{Opcode|opdesc=SETAE
:Resets the numbered bit on target value. The possible targets are the same as BIT.
 
 
 
 
 
 
 
;DAA (Decimal Adjust Accumulator)
 
:{{Opcodelisttop}}
 
{{Opcode|opdesc=DAA
 
 
  |ad1=-
 
  |ad1=-
 
  |ad2=-
 
  |ad2=-
  |status=S
+
  |status=E
  |c=!
+
  |c=-
 
  |n=-
 
  |n=-
  |pv=P
+
  |pv=-
  |h=!
+
  |h=-
  |z=S
+
  |z=-
  |s=S
+
  |s=-
 
  |tstates=8
 
  |tstates=8
 +
|shortfx=A:=unsigned($80)>>(E&7)
 
}}
 
}}
 
|}
 
|}
:Modifies the contents of the accumulator based on the flags and the previous operation to correct for binary coded decimal.
+
:Sets the numbered bit on target value. The possible targets are the same as BIT. The three parameter variant is undocumented and stores the result in a register as well as performing the SET.
 +
:SETAE is a Next extended opcode which takes the bit number to set from E (only the low 3 bits) and sets whole A to value of that bit, but counted from top to bottom (E=0 will produce A:=$80, E=7 will produce A:=$01). This works as pixel mask for ULA bitmap modes, when E is 0..255 x-coordinate.
  
  
  
;MUL
+
;RES (RESet bit)
 
:{{Opcodelisttop}}
 
:{{Opcodelisttop}}
{{Opcode|opdesc=MUL
+
{{Opcode|opdesc=RES b,r
  |ad1=-
+
  |ad1=Immediate
  |ad2=-
+
  |ad2=Register
  |status=E
+
  |status=S
 
  |c=-
 
  |c=-
 
  |n=-
 
  |n=-
Line 2,396: Line 2,412:
 
  |z=-
 
  |z=-
 
  |s=-
 
  |s=-
  |tstates=?
+
  |tstates=8
 +
|shortfx=r:=r & (~(1<<b))
 
}}
 
}}
|}
+
{{Opcode|opdesc=RES b,(HL)
:Next extended opcode. Multiplies HL by DE, leaving the high word of the result in DE and the low word in HL. Does not alter any flags.
+
  |ad1=Immediate
 
+
  |ad2=Register
 
+
  |status=S
 
 
;SWAPNIB
 
:{{Opcodelisttop}}
 
{{Opcode|opdesc=SWAPNIB
 
  |ad1=-
 
  |ad2=-
 
  |status=E
 
 
  |c=-
 
  |c=-
 
  |n=-
 
  |n=-
Line 2,415: Line 2,425:
 
  |z=-
 
  |z=-
 
  |s=-
 
  |s=-
  |tstates=?
+
  |tstates=15
 +
|shortfx=HL*:=HL* & (~(1<<b))
 
}}
 
}}
|}
+
{{Opcode|opdesc=RES b,(IXY+d)
:Next extended opcode. Swaps the high and low nibbles of the accumulator.
+
|ad1=Immediate
 
+
|ad2=Indexed
 
+
|status=S
;PIXELAD
+
|c=-
:{{Opcodelisttop}}
+
|n=-
{{Opcode|opdesc=PIXELAD
+
|pv=-
  |ad1=-
+
|h=-
  |ad2=-
+
|z=-
  |status=E
+
|s=-
  |c=?
+
|tstates=23
  |n=?
+
|shortfx=(IXY+d)*:=(IXY+d)* & (~(1<<b))
  |pv=?
+
}}
  |h=?
+
{{Opcode|opdesc=RES r,b,(IX+d)
  |z=?
+
  |ad1=Immediate
  |s=?
+
  |ad2=Indexed
  |tstates=?
+
  |status=U
 +
  |c=-
 +
  |n=-
 +
  |pv=-
 +
  |h=-
 +
  |z=-
 +
  |s=-
 +
  |tstates=23
 +
|shortfx=(IX+d)*:=(IX+d)* & (~(1<<b)); r:=(IX+d)*
 
}}
 
}}
 
|}
 
|}
:Next extended opcode. Takes E and D as the X,Y coordinate of a point and calculates the address of the byte containing this pixel in the pixel area of standard ULA screen 0, storing it in HL.
+
:Resets the numbered bit on target value. The possible targets are the same as BIT.
  
  
  
;PIXELDN
+
;DAA (Decimal Adjust Accumulator)
 
:{{Opcodelisttop}}
 
:{{Opcodelisttop}}
{{Opcode|opdesc=PIXELDN
+
{{Opcode|opdesc=DAA
 
  |ad1=-
 
  |ad1=-
 
  |ad2=-
 
  |ad2=-
  |status=E
+
  |status=S
  |c=?
+
  |c=!
  |n=?
+
  |n=-
  |pv=?
+
  |pv=P
  |h=?
+
  |h=!
  |z=?
+
  |z=S
  |s=?
+
  |s=S
  |tstates=?
+
  |tstates=8
 +
|shortfx=if(A&$0F>$09 or HF) A±=$06; if(A&$F0>$90 or CF) A±=$60 (± depends on NF)
 
}}
 
}}
 
|}
 
|}
:Updates the address in HL to move down by one line of pixels.
+
:Modifies the contents of the accumulator based on the flags left by previous operation to correct for binary coded decimal (BCD).
  
  
  
=== Control Flow ===
+
;MUL (MULtiply)
;JP (JumP)
 
 
:{{Opcodelisttop}}
 
:{{Opcodelisttop}}
{{Opcode|opdesc=JP nn
+
{{Opcode|opdesc=MUL d,e
  |ad1=Address
+
  |ad1=-
 
  |ad2=-
 
  |ad2=-
  |status=S
+
  |status=E
 
  |c=-
 
  |c=-
 
  |n=-
 
  |n=-
Line 2,472: Line 2,491:
 
  |z=-
 
  |z=-
 
  |s=-
 
  |s=-
  |tstates=10
+
  |tstates=8
 +
|shortfx=DE:=D*E
 
}}
 
}}
{{Opcode|opdesc=JP (HL)
+
|}
  |ad1=Register
+
:Next extended opcode. Multiplies D by E, storing 16 bit result into DE. Does not alter any flags (the opcode is not compatible with any of the R800/Z180/eZ80/... variants of MUL, it is solely Next specific).
 +
 
 +
 
 +
 
 +
;SWAPNIB (SWAP NIBbles)
 +
:{{Opcodelisttop}}
 +
{{Opcode|opdesc=SWAPNIB
 +
  |ad1=-
 
  |ad2=-
 
  |ad2=-
  |status=S
+
  |status=E
 
  |c=-
 
  |c=-
 
  |n=-
 
  |n=-
Line 2,484: Line 2,511:
 
  |z=-
 
  |z=-
 
  |s=-
 
  |s=-
  |tstates=4
+
  |tstates=8
 +
|shortfx=A:=A[3210]<<4 OR A[7654]>>4
 
}}
 
}}
{{Opcode|opdesc=JP (IXY)
+
|}
  |ad1=Register
+
:Next extended opcode. Swaps the high and low nibbles of the accumulator.
 +
 
 +
 
 +
;PIXELAD (PIXEL ADdress)
 +
:{{Opcodelisttop}}
 +
{{Opcode|opdesc=PIXELAD
 +
  |ad1=-
 
  |ad2=-
 
  |ad2=-
  |status=S
+
  |status=E
 
  |c=-
 
  |c=-
 
  |n=-
 
  |n=-
Line 2,497: Line 2,531:
 
  |s=-
 
  |s=-
 
  |tstates=8
 
  |tstates=8
 +
|shortfx=HL:=$4000+((D&$C0)<<5)+((D&$07)<<8)+((D&$38)<<2)+(E>>3)
 
}}
 
}}
 
|}
 
|}
:Jumps (sets the PC) to the given address. The address can be given immediately or read from HL, IX, or IY. Note that although the variants that use register pairs ''look'' like they are using indirect addressing, JP (HL) jumps to the address stored in the register HL, not the address stored at the address HL points to.
+
:Next extended opcode. Takes E and D as the X,Y coordinate of a point and calculates the address of the byte containing this pixel in the pixel area of standard ULA screen 0, storing it in HL.
  
  
  
;JP cc
+
;PIXELDN (PIXEL DowN)
 
:{{Opcodelisttop}}
 
:{{Opcodelisttop}}
{{Opcode|opdesc=JP Z/NZ/NC/C/PO/PE/P/M, nn
+
{{Opcode|opdesc=PIXELDN
  |ad1=Address
+
  |ad1=-
 
  |ad2=-
 
  |ad2=-
  |status=S
+
  |status=E
 
  |c=-
 
  |c=-
 
  |n=-
 
  |n=-
Line 2,515: Line 2,550:
 
  |z=-
 
  |z=-
 
  |s=-
 
  |s=-
  |tstates=10
+
  |tstates=8
 +
|shortfx=if(HL&$0700!=$0700) HL+=256;<br>
 +
else if(HL&$e0!=$e0) HL:=HL&$F8FF+$20;<br>
 +
else HL:=HL&$F81F+$0800
 
}}
 
}}
 
|}
 
|}
:Conditionally jumps (sets the PC) to the given address. The condition is set in terms of the flags: Zero (Z, NZ), Carry (C, NC), Parity (PO, PE), and Sign (P/M). The address can only be given immediately for a conditional jump.
+
:Updates the address in HL to move down by one line of pixels.
 
  
 
+
=== Control Flow ===
;JR (Jump Relative)
+
;JP (JumP)
 
:{{Opcodelisttop}}
 
:{{Opcodelisttop}}
{{Opcode|opdesc=JR nn
+
{{Opcode|opdesc=JP nn
  |ad1=Immediate
+
  |ad1=Address
 
  |ad2=-
 
  |ad2=-
 
  |status=S
 
  |status=S
Line 2,534: Line 2,571:
 
  |z=-
 
  |z=-
 
  |s=-
 
  |s=-
  |tstates=12
+
  |tstates=10
 +
|shortfx=PC:=nn
 
}}
 
}}
{{Opcode|opdesc=JR C/NC/Z/NZ, nn
+
{{Opcode|opdesc=JP (HL)
  |ad1=Immediate
+
  |ad1=Register
 
  |ad2=-
 
  |ad2=-
 
  |status=S
 
  |status=S
Line 2,546: Line 2,584:
 
  |z=-
 
  |z=-
 
  |s=-
 
  |s=-
  |tstates=12
+
  |tstates=4
 +
|shortfx=PC:=HL (not PC:=HL*)
 
}}
 
}}
|}
+
{{Opcode|opdesc=JP (IXY)
:Jumps to an alternate address by ''adding'' the parameter to the PC - in other words the parameter is an adjustment, not an absolute address. When used in an assembler with labels the syntax should be the same as JP. The JR address can only be given immediately. Conditions are legal, but only those based on carry and zero.
+
  |ad1=Register
 
+
  |ad2=-
 
 
 
 
;DJNZ (Decrement and Jump if Not Zero)
 
:{{Opcodelisttop}}
 
{{Opcode|opdesc=DJNZ n
 
  |ad1=Immediate
 
  |ad2=-
 
 
  |status=S
 
  |status=S
 
  |c=-
 
  |c=-
Line 2,565: Line 2,597:
 
  |z=-
 
  |z=-
 
  |s=-
 
  |s=-
 +
|tstates=8
 +
|shortfx=PC:=IXY (not PC:=IXY*)
 +
}}
 +
{{Opcode|opdesc=JP (C)
 +
|ad1=Register
 +
|ad2=-
 +
|status=E
 +
|c=?
 +
|n=?
 +
|pv=?
 +
|h=?
 +
|z=?
 +
|s=?
 
  |tstates=13
 
  |tstates=13
 +
|shortfx=PC:=PC&$C000+IN(C)<<6
 
}}
 
}}
 
|}
 
|}
:Decrements B then performs JR NZ.. to the given address. Used for encapsulating loops.
+
:Jumps (sets the PC) to the given address. The address can be given immediately or read from HL, IX, or IY. Note that although the variants that use register pairs ''look'' like they are using indirect addressing, JP (HL) jumps to the address stored in the register HL, not the address stored at the address HL points to. The JP (C) sets bottom 14 bits of current PC<sup>*</sup> to value read from I/O port: PC[13:0] = (IN (C) << 6) (can be used to execute code block read from a disk stream) * "current PC" is address of next instruction after JP (C), as the PC is advanced by fetching op code from memory and is already advanced when execution happens - if the JP instruction resides at the very end of 16k memory block (..FE or ..FF address), then newly composed PC value will land into following 16k block.
  
  
  
;CALL
+
;JP cc (JumP conditionally)
 
:{{Opcodelisttop}}
 
:{{Opcodelisttop}}
{{Opcode|opdesc=CALL nn
+
{{Opcode|opdesc=JP Z/NZ/NC/C/PO/PE/P/M, nn
 
  |ad1=Address
 
  |ad1=Address
 
  |ad2=-
 
  |ad2=-
Line 2,584: Line 2,630:
 
  |z=-
 
  |z=-
 
  |s=-
 
  |s=-
  |tstates=17
+
  |tstates=10
 +
|shortfx=if cc PC:=nn
 
}}
 
}}
{{Opcode|opdesc=CALL Z/NZ/C/NC/PO/PE/P/M, n
+
|}
  |ad1=Address
+
:Conditionally jumps (sets the PC) to the given address. The condition is set in terms of the flags: Zero (Z, NZ), Carry (C, NC), Parity (PO, PE), and Sign (P/M). The address can only be given immediately for a conditional jump.
 +
 +
 
 +
 
 +
;JR (Jump Relative)
 +
:{{Opcodelisttop}}
 +
{{Opcode|opdesc=JR nn
 +
  |ad1=Immediate
 
  |ad2=-
 
  |ad2=-
 
  |status=S
 
  |status=S
Line 2,596: Line 2,650:
 
  |z=-
 
  |z=-
 
  |s=-
 
  |s=-
  |tstates=17
+
  |tstates=12
 +
|shortfx=PC+=nn
 
}}
 
}}
|}
+
{{Opcode|opdesc=JR C/NC/Z/NZ, nn
:Like JP (including the ability to have conditions), but PUSHes the PC before jumping. Used for subroutine calls.
+
  |ad1=Immediate
:* If a subroutine ends with a CALL to another subroutine immediately before the RET, it is more efficient to JP to the other subroutine and allow its RET to return from the whole combination. This might make high-level programmers queasy but your compiler already does it (tail call optimization)
 
 
 
 
 
 
 
;RET
 
:{{Opcodelisttop}}
 
{{Opcode|opdesc=RET
 
  |ad1=-
 
 
  |ad2=-
 
  |ad2=-
 
  |status=S
 
  |status=S
Line 2,616: Line 2,663:
 
  |z=-
 
  |z=-
 
  |s=-
 
  |s=-
  |tstates=10
+
  |tstates=12 ;  7 if not cc
 +
|shortfx=if cc PC+=nn
 
}}
 
}}
{{Opcode|opdesc=RET Z/NZ/C/NC/PO/PE/P/M
+
|}
  |ad1=-
+
:Jumps to an alternate address by ''adding'' the parameter to the PC - in other words the parameter is an adjustment, not an absolute address. When used in an assembler with labels the syntax should be the same as JP. The JR address can only be given immediately. Conditions are legal, but only those based on carry and zero.
 +
 
 +
 
 +
 
 +
;DJNZ (Decrement reg. b and Jump if Not Zero)
 +
:{{Opcodelisttop}}
 +
{{Opcode|opdesc=DJNZ n
 +
  |ad1=Immediate
 
  |ad2=-
 
  |ad2=-
 
  |status=S
 
  |status=S
Line 2,628: Line 2,683:
 
  |z=-
 
  |z=-
 
  |s=-
 
  |s=-
  |tstates=11
+
  |tstates=13
 +
|shortfx=B--; if B!=0 PC+=nn
 
}}
 
}}
 
|}
 
|}
:POPs the PC from the stack, returning from a previous CALL. This can also accept the same conditions as JP.
+
:Decrements B then performs JR NZ.. to the given address. Used for encapsulating loops.
  
  
  
;RETI
+
;CALL
 
:{{Opcodelisttop}}
 
:{{Opcodelisttop}}
{{Opcode|opdesc=RETI
+
{{Opcode|opdesc=CALL nn
  |ad1=-
+
  |ad1=Address
 
  |ad2=-
 
  |ad2=-
 
  |status=S
 
  |status=S
Line 2,647: Line 2,703:
 
  |z=-
 
  |z=-
 
  |s=-
 
  |s=-
  |tstates=14
+
  |tstates=17
 +
|shortfx=SP-=2; SP*:=PC; PC:=nn
 
}}
 
}}
|}
+
{{Opcode|opdesc=CALL Z/NZ/C/NC/PO/PE/P/M, nn
:Returns from an interrupt service routine.
+
  |ad1=Address
 
+
  |ad2=-
 
 
 
 
;RETN
 
:{{Opcodelisttop}}
 
{{Opcode|opdesc=RETN
 
  |ad1=-
 
  |ad2=-
 
 
  |status=S
 
  |status=S
 
  |c=-
 
  |c=-
Line 2,666: Line 2,716:
 
  |z=-
 
  |z=-
 
  |s=-
 
  |s=-
  |tstates=14
+
  |tstates=17 ;  10 if not cc
 +
|shortfx=if cc {SP-=2; SP*:=PC; PC:=nn}
 
}}
 
}}
 
|}
 
|}
:Returns from a non-maskable interrupt service routine.
+
:Like JP (including the ability to have conditions), but PUSHes the PC before jumping. Used for subroutine calls.
 +
:* If a subroutine ends with a CALL to another subroutine immediately before the RET, it is more efficient to JP to the other subroutine and allow its RET to return from the whole combination. This might make high-level programmers queasy but your compiler already does it (tail call optimization)
  
  
  
;RST (ReSTart)
+
;RET (RETurn)
 
:{{Opcodelisttop}}
 
:{{Opcodelisttop}}
{{Opcode|opdesc=RST n
+
{{Opcode|opdesc=RET
|ad1=Immediate
 
|ad2=-
 
|status=S
 
|c=?
 
|n=?
 
|pv=?
 
|h=?
 
|z=?
 
|s=?
 
|tstates=11
 
}}
 
|}
 
 
 
:Performs a CALL to a routine located at one of eight fixed locations in the zero page. This is located in ROM, and on the Spectrum only a limited number of values are useful to call built-in ROM routines.
 
 
 
 
 
 
 
;NOP (No OPeration)
 
:{{Opcodelisttop}}
 
{{Opcode|opdesc=NOP
 
 
  |ad1=-
 
  |ad1=-
 
  |ad2=-
 
  |ad2=-
Line 2,705: Line 2,737:
 
  |z=-
 
  |z=-
 
  |s=-
 
  |s=-
  |tstates=4
+
  |tstates=10
 +
|shortfx=PC:=SP*; SP+=2
 
}}
 
}}
|}
+
{{Opcode|opdesc=RET Z/NZ/C/NC/PO/PE/P/M
:Does nothing.
 
 
 
 
 
 
 
;HALT
 
:{{Opcodelisttop}}
 
{{Opcode|opdesc=HALT
 
 
  |ad1=-
 
  |ad1=-
 
  |ad2=-
 
  |ad2=-
Line 2,724: Line 2,750:
 
  |z=-
 
  |z=-
 
  |s=-
 
  |s=-
  |tstates=4
+
  |tstates=11 ;  5 if not cc
 +
|shortfx=if cc {PC:=SP*; SP+=2}
 
}}
 
}}
 
|}
 
|}
:Suspends the CPU until an interrupt is received.
+
:POPs the PC from the stack, returning from a previous CALL. This can also accept the same conditions as JP.
  
  
  
;DI (Disable Interrupts)
+
;RETI (RETurn from Interrupt)
 
:{{Opcodelisttop}}
 
:{{Opcodelisttop}}
{{Opcode|opdesc=DI
+
{{Opcode|opdesc=RETI
 
  |ad1=-
 
  |ad1=-
 
  |ad2=-
 
  |ad2=-
Line 2,743: Line 2,770:
 
  |z=-
 
  |z=-
 
  |s=-
 
  |s=-
  |tstates=4
+
  |tstates=14
 +
|shortfx=PC:=SP*; SP+=2
 
}}
 
}}
 
|}
 
|}
:Disables maskable interrupts.
+
:Returns from an interrupt service routine (same as RET instruction, but also does signal to I/O device that the interrupt routine is completed).
  
  
  
;EI (Enable Interrupts)
+
;RETN (RETurn from Non-maskable interrupt)
 
:{{Opcodelisttop}}
 
:{{Opcodelisttop}}
 
{{Opcode|opdesc=RETN
 
{{Opcode|opdesc=RETN
Line 2,763: Line 2,791:
 
  |s=-
 
  |s=-
 
  |tstates=14
 
  |tstates=14
 +
|shortfx=IFF1:=IFF2; PC:=SP*; SP+=2
 
}}
 
}}
 
|}
 
|}
:Enables maskable interrupts.
+
:Returns from a non-maskable interrupt service routine.
  
  
  
;IM (Interrupt Mode)
+
;RST (ReSTart)
 
:{{Opcodelisttop}}
 
:{{Opcodelisttop}}
{{Opcode|opdesc=IM n
+
{{Opcode|opdesc=RST n
 
  |ad1=Immediate
 
  |ad1=Immediate
 
  |ad2=-
 
  |ad2=-
Line 2,781: Line 2,810:
 
  |z=-
 
  |z=-
 
  |s=-
 
  |s=-
  |tstates=8
+
  |tstates=11
 +
|shortfx=CALL n
 
}}
 
}}
 
|}
 
|}
:Sets interrupt handling mode. The default for Next is 1. 2 is used for user defined interrupt service routines. IM 0 is useless on Next (and pretty much everything else, to be honest)
+
:Performs a CALL to a routine located at one of eight fixed locations ($00, $08, ..., $38) in the zero page. This is located in ROM, and on the Spectrum only a limited number of values are useful to call built-in ROM routines.
  
  
  
=== Input and Output ===
+
;NOP (No OPeration)
;IN r, (c); OUT (c), r
 
 
:{{Opcodelisttop}}
 
:{{Opcodelisttop}}
{{Opcode|opdesc=IN r, (c)
+
{{Opcode|opdesc=NOP
  |ad1=Register
+
  |ad1=-
  |ad2=Register
+
  |ad2=-
 
  |status=S
 
  |status=S
 
  |c=-
 
  |c=-
|n=0
+
  |n=-
|pv=P
+
  |pv=-
|h=0
 
|z=S
 
|s=S
 
|tstates=12
 
}}
 
{{Opcode|opdesc=OUT (c),r
 
|ad1=Register
 
|ad2=Register
 
|status=S
 
|c=-
 
  |n=-
 
  |pv=-
 
 
  |h=-
 
  |h=-
 
  |z=-
 
  |z=-
 
  |s=-
 
  |s=-
  |tstates=12
+
  |tstates=4
 +
|shortfx=PC+=1
 
}}
 
}}
 
|}
 
|}
 +
:Does "nothing" (just usual housekeeping like refreshing memory and advancing program counter to next instruction).
  
:Inputs or outputs a byte value from the 16-bit port number given in BC. R can be any 8-bit register. Note that the port number is given in BC even though the instruction refers only to C. Some assemblers will allow the instruction to be written with "(bc)" instead of "(c)" as a reminder.
 
  
  
 
+
;HALT
;IN (c); OUT (c), 0
 
 
:{{Opcodelisttop}}
 
:{{Opcodelisttop}}
{{Opcode|opdesc=IN (c)
+
{{Opcode|opdesc=HALT
  |ad1=Register
+
  |ad1=-
 
  |ad2=-
 
  |ad2=-
  |status=U
+
  |status=S
|c=-
 
|n=0
 
|pv=P
 
|h=0
 
|z=S
 
|s=S
 
|tstates=?
 
}}
 
{{Opcode|opdesc=OUT (c),0
 
|ad1=Register
 
|ad2=Immediate
 
|status=U
 
 
  |c=-
 
  |c=-
 
  |n=-
 
  |n=-
Line 2,845: Line 2,850:
 
  |z=-
 
  |z=-
 
  |s=-
 
  |s=-
  |tstates=?
+
  |tstates=4
 +
|shortfx=waits for interrupt
 
}}
 
}}
 
|}
 
|}
:Undocumented opcodes. The IN variation performs an input, but does not store the result, only setting the flags. The OUT variation outputs 0 on the port. This is the only number that can be output to a port in immediate mode.
+
:Suspends the CPU until an interrupt is received (maskable interrupts must be enabled to break the wait). While CPU is waiting for interrupt, the fake NOP instruction is being executed, to keep memory refresh going on.
  
  
  
;IN a, (n); OUT (n), a
+
;DI (Disable Interrupts)
 
:{{Opcodelisttop}}
 
:{{Opcodelisttop}}
{{Opcode|opdesc=IN A, (n)
+
{{Opcode|opdesc=DI
  |ad1=Accumulator
+
  |ad1=-
  |ad2=Immediate
+
  |ad2=-
 
  |status=S
 
  |status=S
 
  |c=-
 
  |c=-
Line 2,864: Line 2,870:
 
  |z=-
 
  |z=-
 
  |s=-
 
  |s=-
  |tstates=11
+
  |tstates=4
 +
|shortfx=IFF1:=0; IFF2:=0
 
}}
 
}}
{{Opcode|opdesc=OUT (n),A
+
|}
  |ad1=Immediate
+
:Disables maskable interrupts.
  |ad2=Accumulator
+
 
 +
 
 +
 
 +
;EI (Enable Interrupts)
 +
:{{Opcodelisttop}}
 +
{{Opcode|opdesc=EI
 +
  |ad1=-
 +
  |ad2=-
 
  |status=S
 
  |status=S
 
  |c=-
 
  |c=-
Line 2,876: Line 2,890:
 
  |z=-
 
  |z=-
 
  |s=-
 
  |s=-
  |tstates=11
+
  |tstates=4
 +
|shortfx=IFF1:=1; IFF2:=1
 
}}
 
}}
 
|}
 
|}
:Inputs or outputs the byte value in A from a 16-bit port number where the lower byte is N and the upper byte is A. This is only likely to be useful in cases where the upper byte of the port number is not relevant.
+
:Enables maskable interrupts (after next instruction, i.e. for example "EI RET" - the interrupt may happen only after RET instruction is finished (or "EI DI" pair of instructions will not allow any maskable interrupt to happen).
  
  
  
;INI (INput and Increment)
+
;IM (Interrupt Mode)
 
:{{Opcodelisttop}}
 
:{{Opcodelisttop}}
{{Opcode|opdesc=INI
+
{{Opcode|opdesc=IM n
  |ad1=-
+
  |ad1=Immediate
 
  |ad2=-
 
  |ad2=-
 
  |status=S
 
  |status=S
 
  |c=-
 
  |c=-
  |n=1
+
  |n=-
  |pv=!
+
  |pv=-
  |h=!
+
  |h=-
  |z=!
+
  |z=-
  |s=!
+
  |s=-
  |tstates=16
+
  |tstates=8
 +
|shortfx=Interrupt mode:=n
 
}}
 
}}
 
|}
 
|}
:Inputs a value from port BC into memory at the address stored in HL, then increments HL and decrements B. Because B is decremented and is part of the port number, the port number for future INI instructions will change unless it is reset. Z is set if B reached 0; S, H, and P/V are destroyed.
+
:Sets interrupt handling mode. The default for Next is 1. 2 is used for user defined interrupt service routines. IM 0 is useless on Next (and pretty much everything else, to be honest)
  
 
+
=== Input and Output ===
 
+
;IN r, (c); OUT (c), r
;INIR (INput and Increment Repeated)
 
 
:{{Opcodelisttop}}
 
:{{Opcodelisttop}}
{{Opcode|opdesc=INIR
+
{{Opcode|opdesc=IN r, (c)
  |ad1=-
+
  |ad1=Register
  |ad2=-
+
  |ad2=Register
 
  |status=S
 
  |status=S
 
  |c=-
 
  |c=-
  |n=1
+
  |n=0
  |pv=!
+
  |pv=P
  |h=!
+
  |h=0
  |z=1
+
  |z=S
  |s=!
+
  |s=S
  |tstates=21x+16
+
  |tstates=12
 +
|shortfx=r := in(BC)
 
}}
 
}}
|}
+
{{Opcode|opdesc=OUT (c),r
:Loops INIR until B reaches 0. Because B is decremented during this process and is part of the port number, this is unlikely to be useful except when the upper byte of the port number is not relevant.
+
  |ad1=Register
 
+
  |ad2=Register
 
 
 
 
;IND, INDR (INput and Decrement, INput and Decrement Repeated)
 
:{{Opcodelisttop}}
 
{{Opcode|opdesc=IND
 
  |ad1=-
 
  |ad2=-
 
 
  |status=S
 
  |status=S
 
  |c=-
 
  |c=-
  |n=1
+
  |n=-
  |pv=!
+
  |pv=-
  |h=!
+
  |h=-
  |z=!
+
  |z=-
  |s=!
+
  |s=-
  |tstates=16
+
  |tstates=12
}}
+
  |shortfx=out(BC,r)
{{Opcode|opdesc=INDR
 
  |ad1=-
 
|ad2=-
 
|status=S
 
|c=-
 
|n=1
 
|pv=!
 
|h=!
 
|z=1
 
|s=!
 
|tstates=21x+16
 
 
}}
 
}}
 
|}
 
|}
:Behave like INI and INIR except that HL is decremented instead of incremented.
+
:Inputs or outputs a byte value from the 16-bit port number given in BC. R can be any 8-bit register. Note that the port number is given in BC even though the instruction refers only to C. Some assemblers will allow the instruction to be written with "(bc)" instead of "(c)" as a reminder.
  
  
  
;OUTI (Out and Increment), OTIR (Out and Increment Repeated), OUTD (Out and Decrement), OTDR (Out and Decrement Repeated)
+
;IN (c); OUT (c), 0
 
:{{Opcodelisttop}}
 
:{{Opcodelisttop}}
{{Opcode|opdesc=OUTI
+
{{Opcode|opdesc=IN (c)
  |ad1=-
+
  |ad1=Register
 
  |ad2=-
 
  |ad2=-
  |status=S
+
  |status=U
 
  |c=-
 
  |c=-
  |n=1
+
  |n=0
  |pv=!
+
  |pv=P
  |h=!
+
  |h=0
  |z=!
+
  |z=S
  |s=!
+
  |s=S
  |tstates=16
+
  |tstates=12
 +
|shortfx=in(BC)?
 
}}
 
}}
{{Opcode|opdesc=OTIR
+
{{Opcode|opdesc=OUT (c),0
  |ad1=-
+
  |ad1=Register
  |ad2=-
+
  |ad2=Immediate
  |status=S
+
  |status=U
 
  |c=-
 
  |c=-
  |n=1
+
  |n=-
  |pv=!
+
  |pv=-
  |h=!
+
  |h=-
  |z=1
+
  |z=-
  |s=!
+
  |s=-
|tstates=21x+16
+
  |tstates=12
}}
+
  |shortfx=out(BC,0)
{{Opcode|opdesc=OUTD
 
|ad1=-
 
|ad2=-
 
|status=S
 
|c=-
 
|n=1
 
|pv=!
 
|h=!
 
|z=!
 
|s=!
 
  |tstates=16
 
}}
 
{{Opcode|opdesc=OTDR
 
|ad1=-
 
|ad2=-
 
  |status=S
 
|c=-
 
|n=1
 
|pv=!
 
|h=!
 
|z=1
 
|s=!
 
|tstates=21x+16
 
 
}}
 
}}
 
|}
 
|}
:Behave like INI, INIR, IND, INDR except that they output instead of input and B is decremented '''before''' the output instead of after.
+
:Undocumented opcodes. The IN variation performs an input, but does not store the result, only setting the flags. The OUT variation outputs 0 on the port. This is the only number that can be output to a port in immediate mode. The Next FPGA does output zero, but some Z80 chips manufactured differently from early batches output different value like 255, so it is not recommended to use OUT (C),0 if you want to reuse your code also on classic ZX Spectrum or publish it as example.
  
  
  
;OUTINB (Out and Increment with No B)
+
;IN a, (n); OUT (n), a
 
:{{Opcodelisttop}}
 
:{{Opcodelisttop}}
{{Opcode|opdesc=OUTINB
+
{{Opcode|opdesc=IN A, (n)
 +
|ad1=Accumulator
 +
|ad2=Immediate
 +
|status=S
 +
|c=-
 +
|n=-
 +
|pv=-
 +
|h=-
 +
|z=-
 +
|s=-
 +
|tstates=11
 +
|shortfx=A := in(An)
 +
}}
 +
{{Opcode|opdesc=OUT (n),A
 +
|ad1=Immediate
 +
|ad2=Accumulator
 +
|status=S
 +
|c=-
 +
|n=-
 +
|pv=-
 +
|h=-
 +
|z=-
 +
|s=-
 +
|tstates=11
 +
|shortfx=out(An,A)
 +
}}
 +
|}
 +
:Inputs or outputs the byte value in A from a 16-bit port number where the lower byte is N and the upper byte is A. This is only likely to be useful in cases where the upper byte of the port number is not relevant.
 +
 
 +
 
 +
 
 +
;INI (INput and Increment)
 +
:{{Opcodelisttop}}
 +
{{Opcode|opdesc=INI
 
  |ad1=-
 
  |ad1=-
 
  |ad2=-
 
  |ad2=-
  |status=E
+
  |status=S
 
  |c=?
 
  |c=?
  |n=?
+
  |n=1
 
  |pv=?
 
  |pv=?
 
  |h=?
 
  |h=?
  |z=?
+
  |z=!
 
  |s=?
 
  |s=?
  |tstates=?
+
  |tstates=16
 +
|shortfx=HL*:=in(BC); HL++; B--
 
}}
 
}}
 
|}
 
|}
:Next extended opcode. Behaves like OUTI, but doesn't decrement B.
+
:Inputs a value from port BC into memory at the address stored in HL, then increments HL and decrements B. Because B is decremented and is part of the port number, the port number for future INI instructions will change unless it is reset. Z is set if B reached 0; C, S, H, and P/V are destroyed.
 +
 
  
  
;NEXTREG
+
;INIR (INput and Increment Repeated)
 
:{{Opcodelisttop}}
 
:{{Opcodelisttop}}
{{Opcode|opdesc=NEXTREG nn, nn
+
{{Opcode|opdesc=INIR
  |ad1=Immediate
+
  |ad1=-
  |ad2=Immediate
+
  |ad2=-
  |status=E
+
  |status=S
 
  |c=?
 
  |c=?
  |n=?
+
  |n=1
 
  |pv=?
 
  |pv=?
 
  |h=?
 
  |h=?
  |z=?
+
  |z=1
 
  |s=?
 
  |s=?
  |tstates=?
+
  |tstates=21x+16
 +
|shortfx=do INI while(B>0)
 
}}
 
}}
{{Opcode|opdesc=NEXTREG nn, A
+
|}
  |ad1=Immediate
+
:Loops INIR until B reaches 0, so that if INIR starts with B=0 it loops 256 times. Because B is decremented during this process and is part of the port number, this is unlikely to be useful except when the upper byte of the port number is not relevant. Interrupts are recognized during execution.
  |ad2=Accumulator
+
 
  |status=E
+
 
 +
 
 +
;IND, INDR (INput and Decrement, INput and Decrement Repeated)
 +
:{{Opcodelisttop}}
 +
{{Opcode|opdesc=IND
 +
  |ad1=-
 +
  |ad2=-
 +
  |status=S
 
  |c=?
 
  |c=?
  |n=?
+
  |n=1
 
  |pv=?
 
  |pv=?
 
  |h=?
 
  |h=?
  |z=?
+
  |z=!
 
  |s=?
 
  |s=?
  |tstates=?
+
  |tstates=16
 +
|shortfx=HL*:=in(BC); HL--; B--
 +
}}
 +
{{Opcode|opdesc=INDR
 +
|ad1=-
 +
|ad2=-
 +
|status=S
 +
|c=?
 +
|n=1
 +
|pv=?
 +
|h=?
 +
|z=1
 +
|s=?
 +
|tstates=21x+16
 +
|shortfx=do IND while(B>0)
 
}}
 
}}
 
|}
 
|}
:Next extended opcode. Directly sets the [[Board feature control|Next Feature Control Registers]] without going through ports {{PortNo|$243B}} and {{PortNo|253B}}.
+
:Behave like INI and INIR except that HL is decremented instead of incremented.
 +
 
 +
 
 +
 
 +
;OUTI (Out and Increment), OTIR (Out and Increment Repeated), OUTD (Out and Decrement), OTDR (Out and Decrement Repeated)
 +
:{{Opcodelisttop}}
 +
{{Opcode|opdesc=OUTI
 +
|ad1=-
 +
|ad2=-
 +
|status=S
 +
|c=?
 +
|n=1
 +
|pv=?
 +
|h=?
 +
|z=!
 +
|s=?
 +
|tstates=16
 +
|shortfx=B--; out(BC,HL*); HL++
 +
}}
 +
{{Opcode|opdesc=OTIR
 +
|ad1=-
 +
|ad2=-
 +
|status=S
 +
|c=?
 +
|n=1
 +
|pv=?
 +
|h=?
 +
|z=1
 +
|s=?
 +
|tstates=21x+16
 +
|shortfx=do OUTI while (B>0)
 +
}}
 +
{{Opcode|opdesc=OUTD
 +
|ad1=-
 +
|ad2=-
 +
|status=S
 +
|c=?
 +
|n=1
 +
|pv=?
 +
|h=?
 +
|z=!
 +
|s=?
 +
|tstates=16
 +
|shortfx=B--; out(BC,HL*); HL--
 +
}}
 +
{{Opcode|opdesc=OTDR
 +
|ad1=-
 +
|ad2=-
 +
|status=S
 +
|c=?
 +
|n=1
 +
|pv=?
 +
|h=?
 +
|z=1
 +
|s=?
 +
|tstates=21x+16
 +
|shortfx=do OUTD while (B>0)
 +
}}
 +
|}
 +
:Behave like INI, INIR, IND, INDR except that they output instead of input and B is decremented '''before''' the output instead of after. Condition check on B is performed '''after''', so that if OTIR starts with B=0 it loops 256 times.
 +
 
 +
 
 +
 
 +
;OUTINB (Out and Increment with No B)
 +
:{{Opcodelisttop}}
 +
{{Opcode|opdesc=OUTINB
 +
|ad1=-
 +
|ad2=-
 +
|status=E
 +
|c=?
 +
|n=?
 +
|pv=?
 +
|h=?
 +
|z=?
 +
|s=?
 +
|tstates=16
 +
|shortfx=out(BC,HL*); HL++
 +
}}
 +
|}
 +
:Next extended opcode. Behaves like OUTI, but doesn't decrement B.
 +
 
 +
 
 +
 
 +
;NEXTREG
 +
:{{Opcodelisttop}}
 +
{{Opcode|opdesc=NEXTREG n,n'
 +
|ad1=Immediate
 +
|ad2=Immediate
 +
|status=E
 +
|c=-
 +
|n=-
 +
|pv=-
 +
|h=-
 +
|z=-
 +
|s=-
 +
|tstates=20
 +
|shortfx=HwNextReg_n:=n'
 +
}}
 +
{{Opcode|opdesc=NEXTREG n, A
 +
|ad1=Immediate
 +
|ad2=Accumulator
 +
|status=E
 +
|c=-
 +
|n=-
 +
|pv=-
 +
|h=-
 +
|z=-
 +
|s=-
 +
|tstates=17
 +
|shortfx=HwNextReg_n:=A
 +
}}
 +
|}
 +
:Next extended opcode. Directly sets the [[Board feature control|Next Feature Control Registers]] without going through ports {{PortNo|$243B}} and {{PortNo|$253B}}.
 +
 
 +
=== Z80N instructions opcodes ===
 +
 
 +
The Z80 on the Next has extra instructions that are unique to it.  Below is a table of the opcode bytes that are required to select
 +
those instructions.  The timings are based on some partial testing.  These may not be accurate.
 +
 
 +
Also there's initiative led by Matt Davies (author of Odin assembler/editor/debugger tool for ZX Next) to have 4-letter aliases for all new instructions using long mnemonics, the abbreviations suggested are in the last column of the table.
 +
 
 +
{| class="wikitable sortable"
 +
|-
 +
! Instruction !! Byte 1 !! Byte 2 !! Byte 3 !! Byte 4 !! T-States !! 4 letter
 +
|-
 +
| LDIX || ED || A4 || || || 16
 +
|-
 +
| LDWS || ED || A5 || || || 14
 +
|-
 +
| LDIRX || ED || B4 || || || 21/16 || LIRX
 +
|-
 +
| LDDX || ED || AC || || || 16
 +
|-
 +
| LDDRX || ED || BC || || || 21/16 || LDRX
 +
|-
 +
| LDPIRX || ED  || B7 || || || 21/16 || LPRX
 +
|-
 +
| OUTINB || ED  || 90 || || || 16 || OTIB
 +
|-
 +
| MUL D,E || ED || 30 || || || 8
 +
|-
 +
| ADD HL,A || ED || 31 || || || 8
 +
|-
 +
| ADD DE,A || ED || 32 || || || 8
 +
|-
 +
| ADD BC,A || ED || 33 || || || 8
 +
|-
 +
| ADD HL,$im16 || ED || 34 || low || high || 16
 +
|-
 +
| ADD DE,$im16 || ED || 35 || low || high || 16
 +
|-
 +
| ADD BC,$im16 || ED  || 36|| low || high || 16
 +
|-
 +
| SWAPNIB || ED || 23 || || || 8 || SWAP
 +
|-
 +
| MIRROR A || ED || 24 || || || 8 || MIRR
 +
|-
 +
| PUSH $im16 || ED || 8A || high || low || 23
 +
|-
 +
| NEXTREG $im8,$im8 || ED || 91 || register || value || 20 || NREG
 +
|-
 +
| NEXTREG $im8,A || ED  || 92 || register || || 17 || NREG
 +
|-
 +
| PIXELDN || ED || 93 || || || 8 || PXDN
 +
|-
 +
| PIXELAD || ED || 94 || || || 8 || PXAD
 +
|-
 +
| SETAE || ED  || 95 ||  || || 8 || STAE
 +
|-
 +
| TEST $im8 || ED || 27 || value || || 11
 +
|-
 +
| BSLA DE,B || ED || 28 || || || 8
 +
|-
 +
| BSRA DE,B || ED || 29 || || || 8
 +
|-
 +
| BSRL DE,B || ED || 2A || || || 8
 +
|-
 +
| BSRF DE,B || ED || 2B || || || 8
 +
|-
 +
| BRLC DE,B || ED || 2C || || || 8
 +
|-
 +
| JP (C) || ED || 98 || || || 13
 +
|}
 +
 
 +
Note that the "PUSH $im16" instruction is not a mistake.  The operand is encoded in big-endian.

Latest revision as of 13:01, 25 June 2024

This is a general list of Z80 instructions with descriptions. For summaries, you can view the Z80 Instruction Table. You can also search for opcodes.

Erratum

2021-09-16: figuring out the hard way, the three Z80N instructions `ADD HL/DE/BC,A` actually do NOT preserve carry flag, but change it to undefined value (verified with core 3.1.5). There's also strong suspicion (but not verified yet), that LDIX/LDDX/LDIRX/LDDRX/LDPIRX do affects flags the same way as LDI/LDIR - to be verified.

2022-01-11: it's documented for several years that regular Z80 INI/IND/INIR/INDR/OUTI/OUTD/OTIR/OTDR instructions do modify carry flag (contrary to the official Z80 documentation and many Internet resources describing Z80 instructions, including previous version of this page, unfortunately).

Term references

  • Any 8-bit register means A, B, C, D, E, H, and L. F, I and R do not count even though they are technically 8 bit registers. Also, the high and low bytes of IX and IY (IXH, IXL, IYH, IYL) can be used as 8-bit registers although this behavior was undocumented on the original Z80.
  • IXY means IX or IY.
  • For the status field:
    • S means Standard. It's in the Z80 manual. Everything should support it.
    • U means Undocumented. It works on Z80 chips, but it's not in the manual. These have been known for years and were acknowledged by Zilog, so they should work on everything, but some assemblers may vary the syntax.
    • E means Extension. It only works on the Z80 core on the Next. It'll probably only be accepted by assemblers that have been updated specifically for the Next.
  • Each of the flag effects is documented as follows:
    • - means the flag is unchanged.
    • 1 or 0 mean the flag is set or reset as appropriate.
    •  ? means we don't know what effect the instruction has on the flag.
    •  ! means the instruction has an unusual effect on the flag which is documented in the description.
    • S means the effect on the flag is "standard". C is set if a carry/borrow occurred beyond the MSB; Z is set if the result of the operation is zero; H is set if a carry/borrow occurred beyond bit 3.
    • P, V, and L are used for the P/V flag which has several standard effects. P means it's parity. V means it's overflow. L means it checks BC as loop counter for some of the block copy and search instructions: P/V = (BC != 0)


Register and Data manipulation

LD (LoaD)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
LD r, r' Register Register S - - - - - - 4 r := r'
LD r,n Register Immediate S - - - - - - 7 r := n
LD r, (HL) Register Indirect S - - - - - - 7 r := HL*
LD r, (IXY+d) Register Indexed S - - - - - - 19 r := (IXY+d)*
LD (HL),r Indirect Register S - - - - - - 7 HL* := r
LD (IXY+d),r Indexed Register S - - - - - - 19 (IXY+D)* := r
LD (HL), n Indirect Immediate S - - - - - - 10 HL* := n
LD (IXY+d), n Indexed Immediate S - - - - - - 19 (IXY+d)* := n
LD A, (BC/DE) Accumulator Indirect S - - - - - - 7 A := rr*
LD A, (nn) Accumulator Address S - - - - - - 13 A := (nn)*
LD (BC/DE), A Indirect Accumulator S - - - - - - 7 rr* := A
LD (nn), A Address Accumulator S - - - - - - 13 (nn)* := A
LD A, I Accumulator Register S - 0 ! 0 S S 9 A := I; P/V:=IFF2
LD A, R Accumulator Register S - 0 ! 0 S S 9 A := R; P/V:=IFF2
LD I, A Register Accumulator S - - - - - - 9 I := A
LD R, A Register Accumulator S - - - - - - 9 R := A
LD BC/DE/HL/SP, nn Register Immediate S - - - - - - 10 rr := nn
LD IXY, nn Register Immediate S - - - - - - 14 rr := nn
LD HL, (nn) Register Address S - - - - - - 16 HL := (nn)*
LD BC/DE/SP/IXY, (nn) Register Address S - - - - - - 20 rr := (nn)*
LD (nn), HL Address Register S - - - - - - 16 (nn)* := HL
LD (nn), BC/DE/SP/IXY Address Register S - - - - - - 20 (nn)* := rr
LD SP, HL Register Register S - - - - - - 6 SP := HL
LD SP, IXY Register Register S - - - - - - 10 SP := IXY
The basic data load/transfer instruction. Transfers data from the location specified by the second argument, to the location specified by the first. Available combinations are as follows:
  • Any 8-bit register can be:
    • loaded with an immediate value;
    • loaded with the contents of any other 8-bit register except I and R;
    • loaded with the contents of, or stored in, memory pointed to by HL;
    • loaded with the contents of, or stored in, memory offset-indexed by IX or IY.
  • Additionally, the accumulator A (only) can be:
    • loaded with the contents of, or stored in, memory pointed to by BC or DE;
    • loaded with the contents of, or stored in, memory pointed to by an immediate address;
    • loaded with the contents of I or R.
  • Any 16-bit register pair can be:
    • loaded with an immediate value;
    • loaded with the contents of, or stored in, memory pointed to by an immediate address.
  • Additionally, SP (only) can be:
    • loaded with the contents of HL, IX, or IY.
    • The planned ld hl, sp didn't make it to Next yet, one possible workaround is: ld hl,0; add hl,sp;
  • Memory referred to by HL or through IX can be assigned immediate values.
Although 16-bit register pairs cannot be directly moved between each other, they can be moved by moving the two 8-bit registers. (SP gets a special case because it can't be addressed via 8-bit registers.) Some assemblers will provide built-in macro instructions allowing, for example, ld bc, de.
LD instructions do not alter any flags unless I or R are loaded into A.


EX (EXchange)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
EX DE, HL Register Register S - - - - - - 4 swap(DE,HL)
EX AF, AF' Register Register S ! ! ! ! ! ! 4 swap(AF,AF')
EX (SP), HL Indirect Register S - - - - - - 19 swap(SP*,HL)
EX (SP), IXY Indirect Register S - - - - - - 23 swap(SP*,IXY)
Exchanges the contents of two sources. The only permitted combinations are
  • Exchanging DE and HL;
  • Exchanging AF and AF';
  • Exchanging HL, IX, or IY with the contents of memory pointed to by SP.


EXX (EXchange all)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
EXX - - S - - - - - - 4 swap(BC,BC');swap(DE,DE');swap(HL,HL')
Exchanges BC, DE, and HL with their shadow registers. AF and AF' are not exchanged.


PUSH
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
PUSH BC/DE/HL/AF Register - S - - - - - - 11 SP-=2; SP*:=rr
PUSH IXY Register - S - - - - - - 15 SP-=2; SP*:=rr
PUSH nn Immediate - E - - - - - - 23 SP-=2; SP*:=nn
Pushes the given argument on the stack. This can be any 16-bit register pair except SP. SP is reduced by 2 and then the argument is written to the new location SP points to.


POP
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
POP BC/DE/HL Register - S - - - - - - 10 rr:=SP*; SP+=2
POP AF Register - S ! ! ! ! ! ! 10 rr:=SP*; SP+=2
POP IXY Register - S - - - - - - 14 rr:=SP*; SP+=2
Pops the given argument from the stack. This can be any 16-bit register pair except SP. The current value at SP is copied to the register pair and then SP is raised by 2.
Popping into AF does set value of flag register F directly to low 8 bits of value from stack.


Block Copy

LDI (LoaD and Increment)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
LDI - - S - 0 L 0 - - 16 DE*:=HL*; DE++; HL++; BC--
Copies the byte pointed to by HL to the address pointed to by DE, then adds 1 to DE and HL and subtracts 1 from BC. P/V is set to (BC!=0), i.e. set when non zero.


LDIR (LoaD and Increment Repeated)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
LDIR - - S - 0 L 0 - - 21x+16 do LDI while(BC>0)
Automatically loops LDI until BC reaches zero. Note the last iteration starts when BC=1 and ends with BC=0 (starting the LDIR with BC=0 will start 64kiB transfer, most likely overwriting vital parts of system memory and/or code itself).
Flag effects are the same as LDI except that P/V will always be reset, because BC by definition reaches 0 before this instruction ends (normally - unless something overwrites LDIR opcode while BC>0).
Interrupts may interrupt LDIR instruction while looping (after each single LDI sub-part finished) and LDIR will resume after and finish loop properly.


LDD (LoaD and Decrement)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
LDD - - S - 0 L 0 - - 16 DE*:=HL*; DE--; HL--; BC--
Same as LDI, but subtracts 1 from DE and HL instead of adding.


LDDR (LoaD and Decrement Repeated)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
LDDR - - S - 0 0 0 - - 21x+16 do LDD while(BC>0)
Same as LDIR but loops LDD instead of LDI.


LDWS
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
LDWS - - E - 0 ! S S S 14 DE*:=HL*; INC L; INC D;
Next-only extended opcode. Copies the byte pointed to by HL to the address pointed to by DE and increments only L and D. This is used for vertically copying bytes to the Layer 2 display.
The flags are identical to what the INC D instruction would produce.
Note the source data are read only from single 256B (aligned) block of memory, because only L is incremented, not HL.


LDIX, LDIRX, LDDX, LDDRX
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
LDIX - - E - - - - - - 16 {if HL*!=A DE*:=HL*;} DE++; HL++; BC--
LDIRX - - E - - - - - - 21/16 do LDIX while(BC>0)
LDDX - - E - - - - - - 16 {if HL*!=A DE*:=HL*;} DE++; HL--; BC--
LDDRX - - E - - - - - - 21/16 do LDDX while(BC>0)
Next-only extended opcodes. Behave similarly as their non-X equivalents except the byte is not copied if it is equal to A and LDDX/LDDRX advance DE by incrementing it (like LDI), while HL is decremented (like LDD).
Second difference to non-X instructions (as usual with next-only opcodes due to implementation), the extended ones don't modify any flags.


LDPIRX
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
LDPIRX - - E - - - - - - 21/16 do{t:=(HL&$FFF8+E&7)*; {if t!=A DE*:=t;} DE++; BC--}while(BC>0)
Similar to LDIRX except the source byte address is not just HL, but is obtained by using the top 13 bits of HL and the lower 3 bits of DE and HL does not increment during whole loop (HL works as base address of aligned 8 byte lookup table, DE works as destination and also wrapping index 0..7 into table). This is intended for "pattern fill" functionality.

Block Search

CPI (ComPare and Increment)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
CPI - - S - 1 L S ! S 16 HL*==A?; HL++; BC--
Compares the byte pointed to by HL with the contents of A and sets Z if it matches or S if the comparison goes negative. Then adds 1 to HL and subtracts 1 from BC. P/V is set to (BC!=0), i.e. set when non zero.


CPIR (ComPare and Increment Repeated)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
CPIR - - S - 1 L S ! S 21x+16 do CPI while (!Z && BC>0)
Automatically loops CPI until either Z is set (A is found in the byte pointed to by HL) or P/V is reset (BC reached 0).
Flag effects are the same as CPI except that one of the two terminating flag conditions will always be true.


CPD (ComPare and Decrement)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
CPD - - S - 1 L S ! S 16 HL*==A?; HL--; BC--
Same as CPI, but subtracts 1 from HL instead of adding it.


CPDR (ComPare and Decrement Repeated)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
CPDR - - S - 1 L S ! S 21x+16 do CPD while (!Z && BC>0)
Same as CPIR but loops CPD instead of CPI.


Arithmetic

ADD
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
ADD A, r Accumulator Register S S 0 V S S S 4 A+=r
ADD A, n Accumulator Immediate S S 0 V S S S 7 A+=n
ADD A, (HL) Accumulator Indirect S S 0 V S S S 7 A+=HL*
ADD A, (IXY+d) Accumulator Indexed S S 0 V S S S 19 A+=(IXY+d)*
ADD HL, BC/DE/HL/SP Register Register S S 0 - ! - - 11 HL+=rr
ADD IXY, BC/DE/IXY/SP Register Register S S 0 - ! - - 15 IXY+=rr
ADD HL/DE/BC, A Register Register E ? - - - - - 8 rr+=unsigned A
ADD HL/DE/BC, nn Register Immediate E - - - - - - 16 rr+=nn
Adds values together. Legal combinations are:
  • When adding 8-bit values the first parameter must be A and the second may be:
    • The contents of an 8-bit register;
    • An immediate value;
    • The contents of memory pointed to by HL or by indexing based on IX or IY.
  • When adding 16-bit values the first parameter must be HL, IX or IY and the second must be another 16-bit register pair. If the first parameter is IX or IY, the second cannot be HL or the other index register.
  • For 16 bit additions (regular Z80), H is set if a carry occurred in bit 11 (ie, a half carry in the high byte)
  • On the Spectrum Next the extended opcodes also allow the first parameter to be HL, DE, or BC and the second to be A (A will be zero extended to 16 bits) or an 16bit immediate value.


ADC (ADd with Carry)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
ADC A, r Accumulator Register S S 0 V S S S 4 A+=r+(CF?1:0)
ADC A, n Accumulator Immediate S S 0 V S S S 7 A+=n+(CF?1:0)
ADC A, (HL) Accumulator Indirect S S 0 V S S S 7 A+=HL*+(CF?1:0)
ADC A, (IXY+d) Accumulator Indexed S S 0 V S S S 19 A+=(IXY+d)*+(CF?1:0)
ADC HL, BC/DE/HL/SP Register Register S S 0 V ! S S 15 HL+=rr+(CF?1:0)
Adds values together, adding an additional 1 if Carry is set. Legal combinations are the same as for ADD, although there are no extended opcode versions of ADC and in 16-bit values the first parameter can only be HL. For 16-bit values the H flag is set if carry from bit 11; otherwise, it is reset.


SUB
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
SUB r Register - S S 1 V S S S 4 A -= r
SUB n Immediate - S S 1 V S S S 7 A -= n
SUB (HL) Indirect - S S 1 V S S S 7 A -= HL*
SUB (IXY+d) Indexed - S S 1 V S S S 19 A -= (IXY+d)*
Subtracts a value from A. Legal combinations are the same as for ADD for 8-bit, except that A does not need to be specified as the first parameter because subtraction can only be done from A. SUB cannot be used for 16-bit numbers.


SBC (SuBtract with Carry, er, borrow)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
SBC A, r Accumulator Register S S 1 V S S S 4 A-=(r+(CF?1:0))
SBC A, n Accumulator Immediate S S 1 V S S S 7 A-=(n+(CF?1:0))
SBC A, (HL) Accumulator Indirect S S 1 V S S S 7 A-=(HL*+(CF?1:0))
SBC A, (IXY+d) Accumulator Indexed S S 1 V S S S 19 A-=((IXY+d)+(CF?1:0))
SBC HL, BC/DE/HL/SP Register Register S S 1 V ! S S 15 HL-=(rr+(CF?1:0))
Subtracts values, subtracting an additional 1 if Carry is set. Legal combinations are the same as for ADD, although there are no extended opcode versions of SBC and in 16-bit values the first parameter can only be HL. For 16-bit values the H flag is set if borrow from bit 12; otherwise, it is reset.


AND, OR, XOR
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
AND r Register - S 0 0 P 1 S S 4 A := A & r
AND n Immediate - S 0 0 P 1 S S 7 A := A & n
AND (HL) Indirect - S 0 0 P 1 S S 7 A := A & HL*
AND (IXY+d) Indexed - S 0 0 P 1 S S 19 A := A & (IXY+d)*
OR r Register - S 0 0 P 0 S S 4 A := A OR r
OR n Immediate - S 0 0 P 0 S S 7 A := A OR n
OR (HL) Indirect - S 0 0 P 0 S S 7 A := A OR HL*
OR (IXY+d) Indexed - S 0 0 P 0 S S 19 A := A OR (IXY+d)*
XOR r Register - S 0 0 P 0 S S 4 A := A ^ r
XOR n Immediate - S 0 0 P 0 S S 7 A := A ^ n
XOR (HL) Indirect - S 0 0 P 0 S S 7 A := A ^ HL*
XOR (IXY+d) Indexed - S 0 0 P 0 S S 19 A := A ^ (IXY+d)*
Performs the appropriate bitwise operator on A. Legal combinations are the same as SUB.
XOR A is faster and shorter than LD A,0
MIRROR
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
MIRROR A Register - E - - - - - - 8 A[76543210]:=A[01234567]
Next extended opcode. Mirrors (reverses the order) of bits in the accumulator. Older core versions supported MIRROR DE, but this was removed.


CP (ComPare)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
CP r Register - S S 1 V S S S 4 A-=r?
CP n Immediate - S S 1 V S S S 7 A-=n?
CP (HL) Indirect - S S 1 V S S S 7 A-=HL*?
CP (IXY+d) Indexed - S S 1 V S S S 19 A-=(IXY+d)?
Sets the flags as if a SUB was performed but does not perform it. Legal combinations are the same as SUB. This is commonly used to set the flags to perform an equality or greater/less test.
  • CP is not equivalent to "if" in high level languages. Flag based jumps can follow any instruction that sets the flags, not just CP.


TEST
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
TEST n Immediate - E S ? P S S S 11 A&n?
Next extended opcode. Similar to CP, but performs an AND instead of a subtraction.


INC (INCrement)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
INC r Register - S - 0 ! S S S 4 r++
INC (HL) Indirect - S - 0 ! S S S 11 HL*++
INC (IXY+d) Indexed - S - 0 ! S S S 23 (IXY+d)*++
INC BC/DE/HL/SP Register - S - - - - - - 6 rr++
INC IXY Register - S - - - - - - 10 rr++
Increments the target by one. The argument can be any 8-bit register, any 16-bit register pair, or the address pointed to by HL or indexed via IX or IY. P/V is set if the target held $7F. N is reset.
  • INC A is faster than ADD 1.


DEC (DECrement)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
DEC r Register - S - 1 ! S S S 4 r--
DEC (HL) Indirect - S - 1 ! S S S 11 HL*--
DEC (IXY+d) Indexed - S - 1 ! S S S 23 (IXY+D)*--
DEC BC/DE/HL/SP Register - S - - - - - - 6 rr--
DEC IXY Register - S - - - - - - 10 rr--
Decrements the target by one. Allowed arguments are the same as INC. Flag effects are the same as INC except H refers to borrow, not carry; and P/V is set if the target held $80.
  • DEC A is faster than SUB 1.


RLC (Rotate Left Circular)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
RLC r Register - S ! 0 P 0 S S 8 x:=r[7]; r:=r<<1; r[0]:=x; CF:=x
RLC (HL) Indirect - S ! 0 P 0 S S 15 x:=HL*[7]; HL*:=HL*<<1; HL*[0]:=x; CF:=x
RLC (IXY+d) Indexed - S ! 0 P 0 S S 23 x:=(IXY+d)*[7]; (IXY+d)*:=(IXY+d)*<<1; (IXY+d)*[0]:=x; CF:=x
RLC r,(IX+d) Register Indexed U ! 0 P 0 S S 23 x:=(IX+d)*[7]; (IX+d)*:=(IX+d)*<<1; (IX+d)*[0]:=x; CF:=x; r:=(IX+d)*
Rotates the target bitwise left by one position. The MSB is copied to bit 0, and also to Carry. Can be applied to any 8-bit register or to a location in memory pointed to by HL or indexed via IX or IY. The final alternative is undocumented, and stores the result in a register as well as performing the operation.


RL (Rotate Left)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
RL r Register - S ! 0 P 0 S S 8 x:=r[7]; r:=r<<1; r[0]:=CF; CF:=x
RL (HL) Indirect - S ! 0 P 0 S S 15 x:=HL*[7]; HL*:=HL*<<1; HL*[0]:=CF; CF:=x
RL (IXY+d) Indexed - S ! 0 P 0 S S 23 x:=(IXY+d)*[7]; (IXY+d)*:=(IXY+d)*<<1; (IXY+d)*[0]:=CF; CF:=x
RL r,(IX+d) Register Indexed U ! 0 P 0 S S 23 x:=(IX+d)*[7]; (IX+d)*:=(IX+d)*<<1; (IX+d)*[0]:=CF; CF:=x; r:=(IX+d)*
Same as RLC, except the MSB is copied to Carry only, and the previous contents of Carry are copied to bit 0.


RRC, RR (Rotate Right Circular, Rotate Right)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
RRC r Register - S ! 0 P 0 S S 8 x:=r[0]; r:=r>>1; r[7]:=x; CF:=x
RRC (HL) Indirect - S ! 0 P 0 S S 15 x:=HL*[0]; HL*:=HL*>>1; HL*[7]:=x; CF:=x
RRC (IXY+d) Indexed - S ! 0 P 0 S S 23 x:=(IXY+d)*[0]; (IXY+d)*:=(IXY+d)*>>1; (IXY+d)*[7]:=x; CF:=x
RRC r,(IX+d) Register Indexed U ! 0 P 0 S S 23 x:=(IX+d)*[0]; (IX+d)*:=(IX+d)*>>1; (IX+d)*[7]:=x; CF:=x; r:=(IX+d)*
RR r Register - S ! 0 P 0 S S 8 x:=r[0]; r:=r>>1; r[7]:=CF; CF:=x
RR (HL) Indirect - S ! 0 P 0 S S 15 x:=HL*[0]; HL*:=HL*>>1; HL*[7]:=CF; CF:=x
RR (IXY+d) Indexed - S ! 0 P 0 S S 23 x:=(IXY+d)*[0]; (IXY+d)*:=(IXY+d)*>>1; (IXY+d)*[7]:=CF; CF:=x
RR r,(IX+d) Register Indexed U ! 0 P 0 S S 23 x:=(IX+d)*[0]; (IX+d)*:=(IX+d)*>>1; (IX+d)*[7]:=CF; CF:=x; r=(IX+d)*
Same as RLC and RL except they rotate right instead of left.


SLA (Shift Left Arithmetic)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
SLA r Register - S ! 0 P 0 S S 8 r:=r<<1
SLA (HL) Indirect - S ! 0 P 0 S S 15 HL*:=HL*<<1
SLA (IXY+d) Indexed - S ! 0 P 0 S S 23 (IXY+d)*:=(IXY+d)*<<1
SLA r,(IX+d) Register Indexed U ! 0 P 0 S S 23 (IX+d)*:=(IX+d)*<<1; r=(IX+d)*
Same as RL except bit 0 is set to zero, not the previous contents of Carry.


SRA (Shift Right Arithmetic)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
SRA r Register - S ! 0 P 0 S S 8 r:=r>>1 OR r[7]
SRA (HL) Indirect - S ! 0 P 0 S S 15 HL*:=HL*>>1 OR HL*[7]
SRA (IXY+d) Indexed - S ! 0 P 0 S S 23 (IXY+d)*:=(IXY+d)*>>1 OR (IXY+d)*[7]
SRA r,(IX+d) Register Indexed U ! 0 P 0 S S 23 (IX+d)*:=(IX+d)*>>1 OR (IX+d)*[7]; r:=(IX+d)*
Same as RR except the MSB is left unchanged (on the assumption that it's the sign bit), not replaced with the previous contents of Carry.


SRL (Shift Right Logical)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
SRL r Register - S ! 0 P 0 S 0 8 r:=unsigned(r)>>1
SRL (HL) Indirect - S ! 0 P 0 S 0 15 HL*:=unsigned(HL*)>>1
SRL (IXY+d) Indexed - S ! 0 P 0 S 0 23 (IXY+d)*:=unsigned((IXY+d)*)>>1
SRL r,(IXY+d) Register Indexed U ! 0 P 0 S 0 23 (IXY+d)*:=unsigned((IXY+d)*)>>1; r:=(IXY+d)*
Same as SLA except it shifts right instead of left.


RLCA, RLA, RRCA, RRA
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
RLCA - - S ! 0 - 0 - - 4 x:=A[7]; A:=A<<1; A[0]:=x; CF:=x
RLA - - S ! 0 - 0 - - 4 x:=A[7]; A:=A<<1; A[0]:=CF; CF:=x
RRCA - - S ! 0 - 0 - - 4 x:=A[0]; A:=A>>1; A[7]:=x; CF:=x
RRA - - S ! 0 - 0 - - 4 x:=A[0]; A:=A>>1; A[7]:=CF; CF:=x
Same as their matching instruction except they work only on A, are faster, and do not alter S, Z or P/V.


SLL (Shift Left Logical)
This mnemonic has no associated opcode. There is no difference between a logical and arithmetic shift left, so both can use SLA, but some assemblers will allow SLL as an equivalent. Unfortunately, some will also assemble it as SL1. So it's probably worth just avoiding.


SL1 or SLI (Shift Left and Add 1) or (Shift Left and Increment)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
SL1 r Register - U ! 0 P 0 S S 8 r:=(r<<1)+1
SL1 (HL) Indirect - U ! 0 P 0 S S 15 HL*:=(HL*<<1)+1
SL1 (IXY+d) Indexed - U ! 0 P 0 S S 23 (IXY+d)*:=((IXY+d)*<<1)+1
SL1 r,(IXY+d) Register Indexed U ! 0 P 0 S S 23 (IXY+d)*:=((IXY+d)*<<1)+1; r=(IXY+d)*
Undocumented opcodes that behave like SLA, but set bit 0 to 1 instead of 0.


RLD (Rotate Left bcd Digit)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
RLD - - S - 0 P 0 S S 18 x=HL*; HL*[0123]:=A[0123]; HL*[7654]:=x[0123]; A[0123]:=x[7654]
Rotates the lower nibble of the byte pointed to by HL, the upper nibble of that byte, and the lower nibble of A, in that order.


RRD (Rotate Right bcd Digit)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
RRD - - S - 0 P 0 S S 18 x=HL*; HL*[7654]:=A[0123]; HL*[0123]:=x[7654]; A[0123]:=x[0123]
Same as RLD, but the order is: the lower nibble pointed to by HL, the lower nibble of the A, and the upper nibble of the byte.


Barrel (variable amount) shift and rotate (cores v2+ only)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
BSLA DE,B - - E - - - - - - 8 DE:=DE<<(B&31)
BSRA DE,B - - E - - - - - - 8 DE:=signed(DE)>>(B&31)
BSRL DE,B - - E - - - - - - 8 DE:=unsigned(DE)>>(B&31)
BSRF DE,B - - E - - - - - - 8 DE:=~(unsigned(~DE)>>(B&31))
BRLC DE,B - - E - - - - - - 8 DE:=DE<<(B&15) OR DE>>(16-B&15)
Shift instructions use only bits 4..0 of B, BSLA shifts DE left, BSRA/BSRL/BSRF shifts DE right in arithmetic/logical/fill-one way. BRLC rotates DE left by B places, uses only bits 3..0 of B (to rotate right, use B=16-places).

If you are implementing BSRF in C (or similar), be careful with implicit variable type promotion. You will need to do something like this: DE:=~((uint16_t)~DE>>(B&31))


CPL (ComPLement)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
CPL - - S - 1 - 1 - - 4 A:=~A
Inverts the contents of the accumulator.


NEG (NEGate)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
NEG - - S ! 1 ! S S S 8 A:=0-A
Subtracts the contents of the accumulator from zero, making it negative for the purpose of two's complement. P/V is set if A previously held $80. C is set if accumulator did not previously hold $00.


CCF (Complement Carry Flag)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
CCF - - S ! 0 - ! - - 4 CF:=!CF
Inverts the carry flag. (Does not, as might be assumed, clear it!) Also sets H to the previous value of the carry flag.


SCF (Set Carry Flag)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
SCF - - S 1 0 - 0 - - 4 CF:=1
Sets the carry flag.


BIT (test BIT)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
BIT b,r Immediate Register S - 0 ? 1 ! ? 8 r[b]==1?
BIT b,(HL) Immediate Indirect S - 0 ? 1 ! ? 12 HL*[b]==1?
BIT b,(IXY+d) Immediate Indexed S - 0 ? 1 ! ? 20 (IXY+d)*[b]==1?
Tests if a bit is set on target value. The first parameter states which bit. The second can be any 8-bit register, or the location in memory pointed to by HL or indexed by IX or IY. Sets Z if specified bit was 0. S and P/V are destroyed.


SET (SET bit)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
SET b,r Immediate Register S - - - - - - 8 r:=r OR (1<<b)
SET b,(HL) Immediate Register S - - - - - - 15 HL*:=HL* OR (1<<b)
SET b,(IXY+d) Immediate Indexed S - - - - - - 23 (IXY+d)*:=(IXY+d)* OR (1<<b)
SET r,b,(IX+d) Immediate Indexed U - - - - - - 23 (IX+d)*:=(IX+d)* OR (1<<b); r:=(IX+d)*
SETAE - - E - - - - - - 8 A:=unsigned($80)>>(E&7)
Sets the numbered bit on target value. The possible targets are the same as BIT. The three parameter variant is undocumented and stores the result in a register as well as performing the SET.
SETAE is a Next extended opcode which takes the bit number to set from E (only the low 3 bits) and sets whole A to value of that bit, but counted from top to bottom (E=0 will produce A:=$80, E=7 will produce A:=$01). This works as pixel mask for ULA bitmap modes, when E is 0..255 x-coordinate.


RES (RESet bit)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
RES b,r Immediate Register S - - - - - - 8 r:=r & (~(1<<b))
RES b,(HL) Immediate Register S - - - - - - 15 HL*:=HL* & (~(1<<b))
RES b,(IXY+d) Immediate Indexed S - - - - - - 23 (IXY+d)*:=(IXY+d)* & (~(1<<b))
RES r,b,(IX+d) Immediate Indexed U - - - - - - 23 (IX+d)*:=(IX+d)* & (~(1<<b)); r:=(IX+d)*
Resets the numbered bit on target value. The possible targets are the same as BIT.


DAA (Decimal Adjust Accumulator)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
DAA - - S ! - P ! S S 8 if(A&$0F>$09 or HF) A±=$06; if(A&$F0>$90 or CF) A±=$60 (± depends on NF)
Modifies the contents of the accumulator based on the flags left by previous operation to correct for binary coded decimal (BCD).


MUL (MULtiply)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
MUL d,e - - E - - - - - - 8 DE:=D*E
Next extended opcode. Multiplies D by E, storing 16 bit result into DE. Does not alter any flags (the opcode is not compatible with any of the R800/Z180/eZ80/... variants of MUL, it is solely Next specific).


SWAPNIB (SWAP NIBbles)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
SWAPNIB - - E - - - - - - 8 A:=A[3210]<<4 OR A[7654]>>4
Next extended opcode. Swaps the high and low nibbles of the accumulator.


PIXELAD (PIXEL ADdress)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
PIXELAD - - E - - - - - - 8 HL:=$4000+((D&$C0)<<5)+((D&$07)<<8)+((D&$38)<<2)+(E>>3)
Next extended opcode. Takes E and D as the X,Y coordinate of a point and calculates the address of the byte containing this pixel in the pixel area of standard ULA screen 0, storing it in HL.


PIXELDN (PIXEL DowN)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
PIXELDN - - E - - - - - - 8 if(HL&$0700!=$0700) HL+=256;

else if(HL&$e0!=$e0) HL:=HL&$F8FF+$20;
else HL:=HL&$F81F+$0800

Updates the address in HL to move down by one line of pixels.

Control Flow

JP (JumP)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
JP nn Address - S - - - - - - 10 PC:=nn
JP (HL) Register - S - - - - - - 4 PC:=HL (not PC:=HL*)
JP (IXY) Register - S - - - - - - 8 PC:=IXY (not PC:=IXY*)
JP (C) Register - E ? ? ? ? ? ? 13 PC:=PC&$C000+IN(C)<<6
Jumps (sets the PC) to the given address. The address can be given immediately or read from HL, IX, or IY. Note that although the variants that use register pairs look like they are using indirect addressing, JP (HL) jumps to the address stored in the register HL, not the address stored at the address HL points to. The JP (C) sets bottom 14 bits of current PC* to value read from I/O port: PC[13:0] = (IN (C) << 6) (can be used to execute code block read from a disk stream) * "current PC" is address of next instruction after JP (C), as the PC is advanced by fetching op code from memory and is already advanced when execution happens - if the JP instruction resides at the very end of 16k memory block (..FE or ..FF address), then newly composed PC value will land into following 16k block.


JP cc (JumP conditionally)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
JP Z/NZ/NC/C/PO/PE/P/M, nn Address - S - - - - - - 10 if cc PC:=nn
Conditionally jumps (sets the PC) to the given address. The condition is set in terms of the flags: Zero (Z, NZ), Carry (C, NC), Parity (PO, PE), and Sign (P/M). The address can only be given immediately for a conditional jump.


JR (Jump Relative)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
JR nn Immediate - S - - - - - - 12 PC+=nn
JR C/NC/Z/NZ, nn Immediate - S - - - - - - 12 ; 7 if not cc if cc PC+=nn
Jumps to an alternate address by adding the parameter to the PC - in other words the parameter is an adjustment, not an absolute address. When used in an assembler with labels the syntax should be the same as JP. The JR address can only be given immediately. Conditions are legal, but only those based on carry and zero.


DJNZ (Decrement reg. b and Jump if Not Zero)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
DJNZ n Immediate - S - - - - - - 13 B--; if B!=0 PC+=nn
Decrements B then performs JR NZ.. to the given address. Used for encapsulating loops.


CALL
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
CALL nn Address - S - - - - - - 17 SP-=2; SP*:=PC; PC:=nn
CALL Z/NZ/C/NC/PO/PE/P/M, nn Address - S - - - - - - 17 ; 10 if not cc if cc {SP-=2; SP*:=PC; PC:=nn}
Like JP (including the ability to have conditions), but PUSHes the PC before jumping. Used for subroutine calls.
  • If a subroutine ends with a CALL to another subroutine immediately before the RET, it is more efficient to JP to the other subroutine and allow its RET to return from the whole combination. This might make high-level programmers queasy but your compiler already does it (tail call optimization)


RET (RETurn)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
RET - - S - - - - - - 10 PC:=SP*; SP+=2
RET Z/NZ/C/NC/PO/PE/P/M - - S - - - - - - 11 ; 5 if not cc if cc {PC:=SP*; SP+=2}
POPs the PC from the stack, returning from a previous CALL. This can also accept the same conditions as JP.


RETI (RETurn from Interrupt)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
RETI - - S - - - - - - 14 PC:=SP*; SP+=2
Returns from an interrupt service routine (same as RET instruction, but also does signal to I/O device that the interrupt routine is completed).


RETN (RETurn from Non-maskable interrupt)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
RETN - - S - - - - - - 14 IFF1:=IFF2; PC:=SP*; SP+=2
Returns from a non-maskable interrupt service routine.


RST (ReSTart)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
RST n Immediate - S - - - - - - 11 CALL n
Performs a CALL to a routine located at one of eight fixed locations ($00, $08, ..., $38) in the zero page. This is located in ROM, and on the Spectrum only a limited number of values are useful to call built-in ROM routines.


NOP (No OPeration)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
NOP - - S - - - - - - 4 PC+=1
Does "nothing" (just usual housekeeping like refreshing memory and advancing program counter to next instruction).


HALT
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
HALT - - S - - - - - - 4 waits for interrupt
Suspends the CPU until an interrupt is received (maskable interrupts must be enabled to break the wait). While CPU is waiting for interrupt, the fake NOP instruction is being executed, to keep memory refresh going on.


DI (Disable Interrupts)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
DI - - S - - - - - - 4 IFF1:=0; IFF2:=0
Disables maskable interrupts.


EI (Enable Interrupts)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
EI - - S - - - - - - 4 IFF1:=1; IFF2:=1
Enables maskable interrupts (after next instruction, i.e. for example "EI RET" - the interrupt may happen only after RET instruction is finished (or "EI DI" pair of instructions will not allow any maskable interrupt to happen).


IM (Interrupt Mode)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
IM n Immediate - S - - - - - - 8 Interrupt mode:=n
Sets interrupt handling mode. The default for Next is 1. 2 is used for user defined interrupt service routines. IM 0 is useless on Next (and pretty much everything else, to be honest)

Input and Output

IN r, (c); OUT (c), r
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
IN r, (c) Register Register S - 0 P 0 S S 12 r := in(BC)
OUT (c),r Register Register S - - - - - - 12 out(BC,r)
Inputs or outputs a byte value from the 16-bit port number given in BC. R can be any 8-bit register. Note that the port number is given in BC even though the instruction refers only to C. Some assemblers will allow the instruction to be written with "(bc)" instead of "(c)" as a reminder.


IN (c); OUT (c), 0
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
IN (c) Register - U - 0 P 0 S S 12 in(BC)?
OUT (c),0 Register Immediate U - - - - - - 12 out(BC,0)
Undocumented opcodes. The IN variation performs an input, but does not store the result, only setting the flags. The OUT variation outputs 0 on the port. This is the only number that can be output to a port in immediate mode. The Next FPGA does output zero, but some Z80 chips manufactured differently from early batches output different value like 255, so it is not recommended to use OUT (C),0 if you want to reuse your code also on classic ZX Spectrum or publish it as example.


IN a, (n); OUT (n), a
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
IN A, (n) Accumulator Immediate S - - - - - - 11 A := in(An)
OUT (n),A Immediate Accumulator S - - - - - - 11 out(An,A)
Inputs or outputs the byte value in A from a 16-bit port number where the lower byte is N and the upper byte is A. This is only likely to be useful in cases where the upper byte of the port number is not relevant.


INI (INput and Increment)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
INI - - S ? 1 ? ? ! ? 16 HL*:=in(BC); HL++; B--
Inputs a value from port BC into memory at the address stored in HL, then increments HL and decrements B. Because B is decremented and is part of the port number, the port number for future INI instructions will change unless it is reset. Z is set if B reached 0; C, S, H, and P/V are destroyed.


INIR (INput and Increment Repeated)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
INIR - - S ? 1 ? ? 1 ? 21x+16 do INI while(B>0)
Loops INIR until B reaches 0, so that if INIR starts with B=0 it loops 256 times. Because B is decremented during this process and is part of the port number, this is unlikely to be useful except when the upper byte of the port number is not relevant. Interrupts are recognized during execution.


IND, INDR (INput and Decrement, INput and Decrement Repeated)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
IND - - S ? 1 ? ? ! ? 16 HL*:=in(BC); HL--; B--
INDR - - S ? 1 ? ? 1 ? 21x+16 do IND while(B>0)
Behave like INI and INIR except that HL is decremented instead of incremented.


OUTI (Out and Increment), OTIR (Out and Increment Repeated), OUTD (Out and Decrement), OTDR (Out and Decrement Repeated)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
OUTI - - S ? 1 ? ? ! ? 16 B--; out(BC,HL*); HL++
OTIR - - S ? 1 ? ? 1 ? 21x+16 do OUTI while (B>0)
OUTD - - S ? 1 ? ? ! ? 16 B--; out(BC,HL*); HL--
OTDR - - S ? 1 ? ? 1 ? 21x+16 do OUTD while (B>0)
Behave like INI, INIR, IND, INDR except that they output instead of input and B is decremented before the output instead of after. Condition check on B is performed after, so that if OTIR starts with B=0 it loops 256 times.


OUTINB (Out and Increment with No B)
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
OUTINB - - E ? ? ? ? ? ? 16 out(BC,HL*); HL++
Next extended opcode. Behaves like OUTI, but doesn't decrement B.


NEXTREG
Mnemonic Addressing mode 1 Addressing mode 2 Status C N PV H Z S Tstates shortfx
NEXTREG n,n' Immediate Immediate E - - - - - - 20 HwNextReg_n:=n'
NEXTREG n, A Immediate Accumulator E - - - - - - 17 HwNextReg_n:=A
Next extended opcode. Directly sets the Next Feature Control Registers without going through ports TBBlue Register Select ($243B / 9275) and TBBlue Register Access ($253B / 9531).

Z80N instructions opcodes

The Z80 on the Next has extra instructions that are unique to it. Below is a table of the opcode bytes that are required to select those instructions. The timings are based on some partial testing. These may not be accurate.

Also there's initiative led by Matt Davies (author of Odin assembler/editor/debugger tool for ZX Next) to have 4-letter aliases for all new instructions using long mnemonics, the abbreviations suggested are in the last column of the table.

Instruction Byte 1 Byte 2 Byte 3 Byte 4 T-States 4 letter
LDIX ED A4 16
LDWS ED A5 14
LDIRX ED B4 21/16 LIRX
LDDX ED AC 16
LDDRX ED BC 21/16 LDRX
LDPIRX ED B7 21/16 LPRX
OUTINB ED 90 16 OTIB
MUL D,E ED 30 8
ADD HL,A ED 31 8
ADD DE,A ED 32 8
ADD BC,A ED 33 8
ADD HL,$im16 ED 34 low high 16
ADD DE,$im16 ED 35 low high 16
ADD BC,$im16 ED 36 low high 16
SWAPNIB ED 23 8 SWAP
MIRROR A ED 24 8 MIRR
PUSH $im16 ED 8A high low 23
NEXTREG $im8,$im8 ED 91 register value 20 NREG
NEXTREG $im8,A ED 92 register 17 NREG
PIXELDN ED 93 8 PXDN
PIXELAD ED 94 8 PXAD
SETAE ED 95 8 STAE
TEST $im8 ED 27 value 11
BSLA DE,B ED 28 8
BSRA DE,B ED 29 8
BSRL DE,B ED 2A 8
BSRF DE,B ED 2B 8
BRLC DE,B ED 2C 8
JP (C) ED 98 13

Note that the "PUSH $im16" instruction is not a mistake. The operand is encoded in big-endian.