Extended Z80 instruction set: Difference between revisions

From SpecNext Wiki
Jump to: navigation, search
Johnnyo (talk | contribs)
Z80N instructions opcodes: fixing the sorting per opcode
link fixes
 
(31 intermediate revisions by 3 users not shown)
Line 1: Line 1:


This is a general list of Z80 and Z80N instructions with descriptions. Just the instructions specific to Z80N have the following [[#Z80N_instructions_opcodes|encodings]].
This is a general list of Z80 and Z80N instructions with descriptions. The instructions specific to Z80N have the [[#Z80N_instructions_opcodes|encodings described first]].


For a table of summaries without additional descriptions see the [[Z80 Instruction Table]]. There's also a [[Special:RunQuery/OpcodeQuery|special search for opcodes in the same table]] and an external [https://table.specnext.dev/ Z80N opcode value matrix on specnext.dev].
For a table of summaries without additional descriptions see the [[Z80 Instruction Table]]. There's also an external [https://table.specnext.dev/ Z80N opcode value matrix on specnext.dev].


=== Z80N instructions opcodes ===
=== 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
This is a table of the instructions and the encodings of all '''Next-specific''' Z80 instructions:
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"
{| class="wikitable sortable"
|-
|-
! Instruction !!data-sort-type="text"| Byte 1 !!data-sort-type="text"| Byte 2 !! Byte 3 !! Byte 4 !! T-States !! 4 letter
! Instruction !!data-sort-type="text"| Encoding (2-4 bytes) (hex) !! T-States !! Description !! 4 letter
|-
|-
| SWAPNIB  || ED || 23  || || || 8  || SWAP
|<code> <code>SWAPNIB</code> </code>|| <code>ED 23</code> || 8 || Swap the nibbles (4-bits) of A || SWAP
|-
|-
| MIRROR A  || ED || 24  ||  || || 8  || MIRR
|<code> <code>MIRROR A</code> </code>|| <code>ED 24</code> || 8 || Mirror bits 0..7 to 7..0 of A || MIRR
|-
|-
| TEST $im8  || ED  || 27  || value  || || 11 || TEST
|<code> <code>TEST $im8</code> </code>|| <code>ED 27</code> value || 11 || Change flags as AND A but A stays unaffected ||style="color:DarkGrey;"|  TEST
|-
|-
|  BSLA DE,B  || ED  || 28 || || || 8 || BSLA
|<code> <code>BSLA DE,B</code> </code>|| <code>ED 28</code> || 8 || Shift left DE for B bits ||style="color:DarkGrey;"|  BSLA
|-
|-
|  BSRA DE,B  || ED  || 29 || || || 8 || BSRA
|<code> <code>BSRA DE,B</code> </code>|| <code>ED 29</code> || 8 || Shift right signed DE for B bits ||style="color:DarkGrey;"|  BSRA
|-
|-
|  BSRL DE,B  || ED  || 2A || || || 8 || BSRL
|<code> <code>BSRL DE,B</code> </code>|| <code>ED 2A</code> || 8 || Shift right DE for B bits ||style="color:DarkGrey;"|  BSRL
|-
|-
|  BSRF DE,B  || ED  || 2B || || || 8 || BSRF
|<code> <code>BSRF DE,B</code> </code>|| <code>ED 2B</code> || 8 || Shift right DE, filling 1 for B bits ||style="color:DarkGrey;"|  BSRF
|-
|-
|  BRLC DE,B  || ED  || 2C || || || 8 || BRLC
|<code> <code>BRLC DE,B</code> </code>|| <code>ED 2C</code> || 8 || Rotate left DE for B bits ||style="color:DarkGrey;"|  BRLC
|-
|-
|  MUL D,E  || ED  || 30 || || || 8 || MUL
|<code> <code>MUL D,E</code> </code>|| <code>ED 30</code> || 8 || Multiply D with E, result in DE ||style="color:DarkGrey;"|  MUL
|-
|-
|  ADD HL,A  || ED  || 31 || || || 8 || ADD
|<code> <code>ADD HL,A</code> </code>|| <code>ED 31</code> || 8 || Add unsigned A to HL ||style="color:DarkGrey;"|  ADD
|-
|-
|  ADD DE,A  || ED  || 32 || || || 8 || ADD
|<code> <code>ADD DE,A</code> </code>|| <code>ED 32</code> || 8 || Add unsigned A to DE ||style="color:DarkGrey;"|  ADD
|-
|-
|  ADD BC,A  || ED  || 33 || || || 8 || ADD
|<code> <code>ADD BC,A</code> </code>|| <code>ED 33</code> || 8 || Add unsigned A to BC ||style="color:DarkGrey;"|  ADD
|-
|-
|  ADD HL,$im16  || ED || 34 || low  || high  || 16 || ADD
|<code> <code>ADD HL,$im16</code> </code>|| <code>ED 34 low high</code>  || 16 || Add a constant to HL ||style="color:DarkGrey;"|  ADD
|-
|-
|  ADD DE,$im16  || ED  || 35  || low  || high  || 16 || ADD
|<code> <code>ADD DE,$im16</code> </code>|| <code>ED 35 low high</code> || 16  || Add a constant to DE ||style="color:DarkGrey;"|  ADD
|-
|-
|  ADD BC,$im16  || ED  || 36 || low  || high  || 16 || ADD
|<code> <code>ADD BC,$im16</code> </code>|| <code>ED 36 low high</code> || 16 || Add a constant to BC ||style="color:DarkGrey;"|  ADD
|-
|-
|  PUSH $im16  || ED || 8A  || high  || low || 23  || PUSH
|<code> <code>PUSH $im16</code> </code>|| <code>ED 8A  high low</code> || 23 || Push a constant ||style="color:DarkGrey;"| PUSH
|-
|-
|  OUTINB  || ED || 90  ||  || || 16  || OTIB
|<code> <code>OUTINB</code> </code>|| <code>ED 90</code> || 16 || OUTI, but don't change B || OTIB
|-
|-
|  NEXTREG $im8,$im8  || ED || 91 || register  || value || 20  || NREG
|<code> <code>NEXTREG $im8,$im8</code> </code>|| <code>ED 91 register value</code> || 20 || Write v to Next register r || NREG
|-
|-
|  NEXTREG $im8,A  || ED || 92 || register ||  || 17  || NREG
|<code> <code>NEXTREG $im8,A</code> </code>|| <code>ED 92 register</code> || 17 || Write A to Next register r || NREG
|-
|-
|  PIXELDN  || ED || 93  ||  || || 8  || PXDN
|<code> <code>PIXELDN</code> </code>|| <code>ED 93</code> || 8 || HL as a pixel address moved one line down || PXDN
|-
|-
|  PIXELAD  || ED || 94  ||  || || 8  || PXAD
|<code> <code>PIXELAD</code> </code>|| <code>ED 94</code> || 8 || HL := as ULA pixel address from D==Y E==X || PXAD
|-
|-
|  SETAE  || ED || 95  ||  || || 8  || STAE
|<code> <code>SETAE</code> </code>|| <code>ED 95</code> || 8 || Get A as a mask for ULA pixel from E || STAE
|-
|-
|  JP (C)  || ED  || 98 || || || 13 || JP
|<code> <code>JP (C)</code> </code>|| <code>ED 98</code> || 13 || IN (C) then jump to a 64 byte section ||style="color:DarkGrey;"|  JP
|-
|-
|  LDIX  || ED  || A4 || || || 16 || LDIX
|<code> <code>LDIX</code> </code>|| <code>ED A4</code> || 16 || Extended LDI byte copy ||style="color:DarkGrey;"|  LDIX
|-
|-
|  LDWS  || ED  || A5 || || || 14 || LDWS
|<code> <code>LDWS</code> </code>|| <code>ED A5</code> || 14 || Byte copy as for Layer 2 ||style="color:DarkGrey;"|  LDWS
|-
|-
|  LDDX  || ED  || AC || || || 16 || LDDX
|<code> <code>LDDX</code> </code>|| <code>ED AC</code> || 16 || Extended LDD byte copy ||style="color:DarkGrey;"|  LDDX
|-
|-
|  LDIRX  || ED || B4 ||  || || 21/16  || LIRX
|<code> <code>LDIRX</code> </code>|| <code>ED B4</code> || 21/16  || Extended LDIR || LIRX
|-
|-
|  LDPIRX  || ED || B7 ||  || || 21/16  || LPRX
|<code> <code>LDPIRX</code> </code>|| <code>ED B7</code> || 21/16  || Byte copy as for a pattern fill || LPRX
|-
|-
|  LDDRX  || ED || BC ||  || || 21/16  || LDRX
|<code> <code>LDDRX</code> </code>|| <code>ED BC</code> || 21/16  || Extended LDDR || LDRX
|}
|}


Note that the "PUSH $im16" instruction is not a mistake. The operand is encoded in big-endian.
More details and the explanations of all Z80 instructions implemented in the Next Z80 CPU follow.
 
Notes:
 
* The encoding of the operand of the <code>PUSH $im16</code> is unique: it is the only operand encoded as big-endian.
* The timings (T-States) are based on some limited testing and may not be accurate.
* The shorter aliases of the official mnemonics (the 4-letter column) are those suggested in an initiative led by Matt Davies, the author of Odin assembler, editor and debugger tool for ZX Next.
* A relevant early source for this table could be [https://github.com/z88dk/z88dk/issues/312#issuecomment-322659205 a Christmas 2018 edit of a comment in a discussion of an issue 312 of z88dk].


=== Term references ===
=== Notation ===
* ''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.
* In the descriptions ''any 8-bit register'' means A, B, C, D, E, H, and L. The registers named F, I and R aren't a part of this set even if they are technically 8 bit registers. Additionally, IXH, IXL, IYH, IYL, which are the high and low byte parts of IX and IY, can be used in some of the instructions as 8-bit registers although this wasn't documented for the original Z80.
* IXY means IX or IY.
* IXY means IX or IY.
* For the status field:
* For the status field:
Line 90: Line 94:
** 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 checks BC as loop counter for some of the block copy and search instructions: P/V = (BC != 0)
** 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 ===
;LD (LoaD)
;LD (LoaD)


:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=LD r, r'
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=Register
|-
|ad2=Register
|<code>LD r, r' </code>||Register ||Register ||S ||- ||- ||- ||- ||- ||- ||4 ||r := r'
|status=S
|-
|c=-
|<code>LD r,n </code>||Register ||Immediate ||S ||- ||- ||- ||- ||- ||- ||7 ||r := n
|n=-
|-
|pv=-
|<code>LD r, (HL) </code>||Register ||Indirect ||S ||- ||- ||- ||- ||- ||- ||7 ||r := HL*
|h=-
|-
|z=-
|<code>LD r, (IXY+d) </code>||Register ||Indexed ||S ||- ||- ||- ||- ||- ||- ||19 ||r := (IXY+d)*
|s=-
|-
|tstates=4
|<code>LD (HL),r </code>||Indirect ||Register ||S ||- ||- ||- ||- ||- ||- ||7 ||HL* := r
|shortfx=r := r'
|-
}}
|<code>LD (IXY+d),r </code>||Indexed ||Register ||S ||- ||- ||- ||- ||- ||- ||19 ||(IXY+D)* := r
 
|-
{{Opcode|opdesc=LD r,n
|<code>LD (HL), n </code>||Indirect ||Immediate ||S ||- ||- ||- ||- ||- ||- ||10 ||HL* := n
|ad1=Register
|-
|ad2=Immediate
|<code>LD (IXY+d), n </code>||Indexed ||Immediate ||S ||- ||- ||- ||- ||- ||- ||19 ||(IXY+d)* := n
|status=S
|-
|c=-
|<code>LD A, (BC/DE) </code>||Accumulator ||Indirect ||S ||- ||- ||- ||- ||- ||- ||7 ||A := rr*
|n=-
|-
|pv=-
|<code>LD A, (nn) </code>||Accumulator ||Address ||S ||- ||- ||- ||- ||- ||- ||13 ||A := (nn)*
|h=-
|-
|z=-
|<code>LD (BC/DE), A </code>||Indirect ||Accumulator ||S ||- ||- ||- ||- ||- ||- ||7 ||rr* := A
|s=-
|-
|tstates=7
|<code>LD (nn), A </code>||Address ||Accumulator ||S ||- ||- ||- ||- ||- ||- ||13 ||(nn)* := A
|shortfx=r := n
|-
}}
|<code>LD A, I </code>||Accumulator ||Register ||S ||- ||0 ||! ||0 ||S ||S ||9 ||A := I; P/V:=IFF2
 
|-
{{Opcode|opdesc=LD r, (HL)
|<code>LD A, R </code>||Accumulator ||Register ||S ||- ||0 ||! ||0 ||S ||S ||9 ||A := R; P/V:=IFF2
|ad1=Register
|-
|ad2=Indirect
|<code>LD I, A </code>||Register ||Accumulator ||S ||- ||- ||- ||- ||- ||- ||9 ||I := A
|status=S
|-
|c=-
|<code>LD R, A </code>||Register ||Accumulator ||S ||- ||- ||- ||- ||- ||- ||9 ||R := A
|n=-
|-
|pv=-
|<code>LD BC/DE/HL/SP, nn </code>||Register ||Immediate ||S ||- ||- ||- ||- ||- ||- ||10 ||rr := nn
|h=-
|-
|z=-
|<code>LD IXY, nn </code>||Register ||Immediate ||S ||- ||- ||- ||- ||- ||- ||14 ||rr := nn
|s=-
|-
|tstates=7
|<code>LD HL, (nn) </code>||Register ||Address ||S ||- ||- ||- ||- ||- ||- ||16 ||HL := (nn)*
|shortfx=r := HL*
|-
}}
|<code>LD BC/DE/SP/IXY, (nn) </code>||Register ||Address ||S ||- ||- ||- ||- ||- ||- ||20 ||rr := (nn)*
 
|-
{{Opcode|opdesc=LD r, (IXY+d)
|<code>LD (nn), HL </code>||Address ||Register ||S ||- ||- ||- ||- ||- ||- ||16 ||(nn)* := HL
|ad1=Register
|-
|ad2=Indexed
|<code>LD (nn), BC/DE/SP/IXY </code>||Address ||Register ||S ||- ||- ||- ||- ||- ||- ||20 ||(nn)* := rr
|status=S
|-
|c=-
|<code>LD SP, HL </code>||Register ||Register ||S ||- ||- ||- ||- ||- ||- ||6 ||SP := HL
|n=-
|-
|pv=-
|<code>LD SP, IXY </code>||Register ||Register ||S ||- ||- ||- ||- ||- ||- ||10 ||SP := IXY
|h=-
|z=-
|s=-
|tstates=19
|shortfx=r := (IXY+d)*
}}
 
{{Opcode|opdesc=LD (HL),r
|ad1=Indirect
|ad2=Register
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=7
|shortfx=HL* := r
}}
 
{{Opcode|opdesc=LD (IXY+d),r
|ad1=Indexed
|ad2=Register
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=19
|shortfx=(IXY+D)* := r
}}
 
{{Opcode|opdesc=LD (HL), n
|ad1=Indirect
|ad2=Immediate
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=10
|shortfx=HL* := n
}}
 
{{Opcode|opdesc=LD (IXY+d), n
|ad1=Indexed
|ad2=Immediate
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=19
|shortfx=(IXY+d)* := n
}}
 
{{Opcode|opdesc=LD A, (BC/DE)
|ad1=Accumulator
|ad2=Indirect
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=7
|shortfx=A := rr*
}}
 
{{Opcode|opdesc=LD A, (nn)
|ad1=Accumulator
|ad2=Address
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=13
|shortfx=A := (nn)*
}}
 
{{Opcode|opdesc=LD (BC/DE), A
|ad1=Indirect
|ad2=Accumulator
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=7
|shortfx=rr* := A
}}
 
 
{{Opcode|opdesc=LD (nn), A
|ad1=Address
|ad2=Accumulator
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=13
|shortfx=(nn)* := A
}}
 
{{Opcode|opdesc=LD A, I
|ad1=Accumulator
|ad2=Register
|status=S
|c=-
|n=0
|pv=!
|h=0
|z=S
|s=S
|tstates=9
|shortfx=A := I; P/V:=IFF2
}}
 
{{Opcode|opdesc=LD A, R
|ad1=Accumulator
|ad2=Register
|status=S
|c=-
|n=0
|pv=!
|h=0
|z=S
|s=S
|tstates=9
|shortfx=A := R; P/V:=IFF2
}}
 
{{Opcode|opdesc=LD I, A
|ad1=Register
|ad2=Accumulator
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=9
|shortfx=I := A
}}
 
 
{{Opcode|opdesc=LD R, A
|ad1=Register
|ad2=Accumulator
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=9
|shortfx=R := A
}}
 
{{Opcode|opdesc=LD BC/DE/HL/SP, nn
|ad1=Register
|ad2=Immediate
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=10
|shortfx=rr := nn
}}
 
 
{{Opcode|opdesc=LD IXY, nn
|ad1=Register
|ad2=Immediate
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=14
|shortfx=rr := nn
}}
 
 
{{Opcode|opdesc=LD HL, (nn)
|ad1=Register
|ad2=Address
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=16
|shortfx=HL := (nn)*
}}
 
 
{{Opcode|opdesc=LD BC/DE/SP/IXY, (nn)
|ad1=Register
|ad2=Address
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=20
|shortfx=rr := (nn)*
}}
 
 
{{Opcode|opdesc=LD (nn), HL
|ad1=Address
|ad2=Register
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=16
|shortfx=(nn)* := HL
}}
 
{{Opcode|opdesc=LD (nn), BC/DE/SP/IXY
|ad1=Address
|ad2=Register
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=20
|shortfx=(nn)* := rr
}}
 
{{Opcode|opdesc=LD SP, HL
|ad1=Register
|ad2=Register
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=6
|shortfx=SP := HL
}}
 
{{Opcode|opdesc=LD SP, IXY
|ad1=Register
|ad2=Register
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=10
|shortfx=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:
: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:
Line 462: Line 171:


;EX (EXchange)
;EX (EXchange)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=EX DE, HL
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=Register
|-
|ad2=Register
|<code>EX DE, HL </code>||Register ||Register ||S ||- ||- ||- ||- ||- ||- ||4 ||swap(DE,HL)
|status=S
|-
|c=-
|<code>EX AF, AF' </code>||Register ||Register ||S ||! ||! ||! ||! ||! ||! ||4 ||swap(AF,AF')
|n=-
|-
|pv=-
|<code>EX (SP), HL </code>||Indirect ||Register ||S ||- ||- ||- ||- ||- ||- ||19 ||swap(SP*,HL)
|h=-
|-
|z=-
|<code>EX (SP), IXY </code>||Indirect ||Register ||S ||- ||- ||- ||- ||- ||- ||23 ||swap(SP*,IXY)
|s=-
|tstates=4
|shortfx=swap(DE,HL)
}}
{{Opcode|opdesc=EX AF, AF'
|ad1=Register
|ad2=Register
|status=S
|c=!
|n=!
|pv=!
|h=!
|z=!
|s=!
|tstates=4
|shortfx=swap(AF,AF')
}}
{{Opcode|opdesc=EX (SP), HL
|ad1=Indirect
|ad2=Register
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=19
|shortfx=swap(SP*,HL)
}}
{{Opcode|opdesc=EX (SP), IXY
|ad1=Indirect
|ad2=Register
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=23
|shortfx=swap(SP*,IXY)
}}
 
|}
|}
:Exchanges the contents of two sources. The only permitted combinations are
:Exchanges the contents of two sources. The only permitted combinations are
Line 524: Line 189:


;EXX (EXchange all)
;EXX (EXchange all)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=EXX
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=-
|-
|ad2=-
|<code>EXX </code>||- ||- ||S ||- ||- ||- ||- ||- ||- ||4 ||swap(BC,BC');swap(DE,DE');swap(HL,HL')
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=4
|shortfx=swap(BC,BC');swap(DE,DE');swap(HL,HL')
}}
|}
|}
:Exchanges BC, DE, and HL with their shadow registers. AF and AF' are not exchanged.  
:Exchanges BC, DE, and HL with their shadow registers. AF and AF' are not exchanged.  
Line 544: Line 199:


;PUSH
;PUSH
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=PUSH BC/DE/HL/AF
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=Register
|-
|ad2=-
|<code>PUSH BC/DE/HL/AF </code>||Register ||- ||S ||- ||- ||- ||- ||- ||- ||11 ||SP-=2; SP*:=rr
|status=S
|-
|c=-
|<code>PUSH IXY </code>||Register ||- ||S ||- ||- ||- ||- ||- ||- ||15 ||SP-=2; SP*:=rr
|n=-
|-
|pv=-
|<code>PUSH nn </code>||Immediate ||- ||E ||- ||- ||- ||- ||- ||- ||23 ||SP-=2; SP*:=nn
|h=-
|z=-
|s=-
|tstates=11
|shortfx=SP-=2; SP*:=rr
}}
{{Opcode|opdesc=PUSH IXY
|ad1=Register
|ad2=-
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=15
|shortfx=SP-=2; SP*:=rr
}}
{{Opcode|opdesc=PUSH nn
|ad1=Immediate
|ad2=-
|status=E
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=23
|shortfx=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.
: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.
Line 591: Line 213:


;POP
;POP
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=POP BC/DE/HL
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=Register
|-
|ad2=-
|<code>POP BC/DE/HL </code>||Register ||- ||S ||- ||- ||- ||- ||- ||- ||10 ||rr:=SP*; SP+=2
|status=S
|-
|c=-
|<code>POP AF </code>||Register ||- ||S ||! ||! ||! ||! ||! ||! ||10 ||rr:=SP*; SP+=2
|n=-
|-
|pv=-
|<code>POP IXY </code>||Register ||- ||S ||- ||- ||- ||- ||- ||- ||14 ||rr:=SP*; SP+=2
|h=-
|z=-
|s=-
|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
|ad1=Register
|ad2=-
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=14
|shortfx=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.
: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.
Line 639: Line 229:
=== Block Copy ===
=== Block Copy ===
;LDI (LoaD and Increment)
;LDI (LoaD and Increment)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=LDI
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=-
|-
|ad2=-
|<code>LDI </code>||- ||- ||S ||- ||0 ||L ||0 ||- ||- ||16 ||DE*:=HL*; DE++; HL++; BC--
|status=S
|c=-
|n=0
|pv=L
|h=0
|z=-
|s=-
|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. P/V is set to (BC!=0), i.e. set when non zero.
: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 658: Line 238:


;LDIR (LoaD and Increment Repeated)
;LDIR (LoaD and Increment Repeated)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=LDIR
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=-
|-
|ad2=-
|<code>LDIR </code>||- ||- ||S ||- ||0 ||L ||0 ||- ||- ||21x+16 ||do LDI while(BC>0)
|status=S
|c=-
|n=0
|pv=L
|h=0
|z=-
|s=-
|tstates=21x+16
|shortfx=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).
: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).
Line 680: Line 250:


;LDD (LoaD and Decrement)
;LDD (LoaD and Decrement)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=LDD
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=-
|-
|ad2=-
|<code>LDD </code>||- ||- ||S ||- ||0 ||L ||0 ||- ||- ||16 ||DE*:=HL*; DE--; HL--; BC--
|status=S
|c=-
|n=0
|pv=L
|h=0
|z=-
|s=-
|tstates=16
|shortfx=DE*:=HL*; DE--; HL--; BC--
}}
|}
|}
:Same as LDI, but subtracts 1 from DE and HL instead of adding.
:Same as LDI, but subtracts 1 from DE and HL instead of adding.
Line 700: Line 260:


;LDDR (LoaD and Decrement Repeated)
;LDDR (LoaD and Decrement Repeated)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=LDDR
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=-
|-
|ad2=-
|<code>LDDR </code>||- ||- ||S ||- ||0 ||0 ||0 ||- ||- ||21x+16 ||do LDD while(BC>0)
|status=S
|c=-
|n=0
|pv=0
|h=0
|z=-
|s=-
|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.
Line 719: Line 269:


;LDWS
;LDWS
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=LDWS
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=-
|-
|ad2=-
|<code>LDWS </code>||- ||- ||E ||- ||0 ||! ||S ||S ||S ||14 ||DE*:=HL*; INC L; INC D;
|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.
: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.
Line 741: Line 281:


;LDIX, LDIRX, LDDX, LDDRX
;LDIX, LDIRX, LDDX, LDDRX
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=LDIX
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=-
|-
|ad2=-
|<code>LDIX </code>||- ||- ||E ||- ||- ||- ||- ||- ||- ||16 ||{if HL*!=A DE*:=HL*;} DE++; HL++; BC--
|status=E
|-
|c=-
|<code>LDIRX </code>||- ||- ||E ||- ||- ||- ||- ||- ||- ||21/16 ||do LDIX while(BC>0)
|n=-
|-
|pv=-
|<code>LDDX </code>||- ||- ||E ||- ||- ||- ||- ||- ||- ||16 ||{if HL*!=A DE*:=HL*;} DE++; HL--; BC--
|h=-
|-
|z=-
|<code>LDDRX </code>||- ||- ||E ||- ||- ||- ||- ||- ||- ||21/16 ||do LDDX while(BC>0)
|s=-
|tstates=16
|shortfx={if HL*!=A DE*:=HL*;} DE++; HL++; BC--
}}
{{Opcode|opdesc=LDIRX
|ad1=-
|ad2=-
|status=E
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=21/16
|shortfx=do LDIX while(BC>0)
}}
{{Opcode|opdesc=LDDX
|ad1=-
|ad2=-
|status=E
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=16
|shortfx={if HL*!=A DE*:=HL*;} DE++; HL--; BC--
}}
{{Opcode|opdesc=LDDRX
|ad1=-
|ad2=-
|status=E
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=21/16
|shortfx=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).
: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).
Line 801: Line 298:


;LDPIRX  
;LDPIRX  
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=LDPIRX
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=-
|-
|ad2=-
|<code>LDPIRX </code>||- ||- ||E ||- ||- ||- ||- ||- ||- ||21/16 ||do{t:=(HL&$FFF8+E&7)*; {if t!=A DE*:=t;} DE++; BC--}while(BC>0)
|status=E
|c=-
|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.
: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.
Line 820: Line 307:
=== Block Search ===
=== Block Search ===
;CPI (ComPare and Increment)
;CPI (ComPare and Increment)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=CPI
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=-
|-
|ad2=-
|<code>CPI </code>||- ||- ||S ||- ||1 ||L ||S ||! ||S ||16 ||HL*==A?; HL++; BC--
|status=S
|c=-
|n=1
|pv=L
|h=S
|z=!
|s=S
|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. P/V is set to (BC!=0), i.e. set when non zero.
: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 840: Line 317:


;CPIR (ComPare and Increment Repeated)
;CPIR (ComPare and Increment Repeated)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=CPIR
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=-
|-
|ad2=-
|<code>CPIR </code>||- ||- ||S ||- ||1 ||L ||S ||! ||S ||21x+16 ||do CPI while (!Z && BC>0)
|status=S
|c=-
|n=1
|pv=L
|h=S
|z=!
|s=S
|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).
: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).
Line 861: Line 328:


;CPD (ComPare and Decrement)
;CPD (ComPare and Decrement)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=CPD
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=-
|-
|ad2=-
|<code>CPD </code>||- ||- ||S ||- ||1 ||L ||S ||! ||S ||16 ||HL*==A?; HL--; BC--
|status=S
|c=-
|n=1
|pv=L
|h=S
|z=!
|s=S
|tstates=16
|shortfx=HL*==A?; HL--; BC--
}}
|}
|}
:Same as CPI, but subtracts 1 from HL instead of adding it.
:Same as CPI, but subtracts 1 from HL instead of adding it.
Line 881: Line 338:


;CPDR (ComPare and Decrement Repeated)
;CPDR (ComPare and Decrement Repeated)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=CPDR
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=-
|-
|ad2=-
|<code>CPDR </code>||- ||- ||S ||- ||1 ||L ||S ||! ||S ||21x+16 ||do CPD while (!Z && BC>0)
|status=S
|c=-
|n=1
|pv=L
|h=S
|z=!
|s=S
|tstates=21x+16
|shortfx=do CPD while (!Z && BC>0)
}}
|}
|}
:Same as CPIR but loops CPD instead of CPI.  
:Same as CPIR but loops CPD instead of CPI.  
Line 902: Line 349:
=== Arithmetic ===
=== Arithmetic ===
;ADD
;ADD
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=ADD A, r
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=Accumulator
|-
|ad2=Register
|<code>ADD A, r </code>||Accumulator ||Register ||S ||S ||0 ||V ||S ||S ||S ||4 ||A+=r
|status=S
|-
|c=S
|<code>ADD A, n </code>||Accumulator ||Immediate ||S ||S ||0 ||V ||S ||S ||S ||7 ||A+=n
|n=0
|-
|pv=V
|<code>ADD A, (HL) </code>||Accumulator ||Indirect ||S ||S ||0 ||V ||S ||S ||S ||7 ||A+=HL*
|h=S
|-
|z=S
|<code>ADD A, (IXY+d) </code>||Accumulator ||Indexed ||S ||S ||0 ||V ||S ||S ||S ||19 ||A+=(IXY+d)*
|s=S
|-
|tstates=4
|<code>ADD HL, BC/DE/HL/SP </code>||Register ||Register ||S ||S ||0 ||- ||! ||- ||- ||11 ||HL+=rr
|shortfx=A+=r
|-
}}
|<code>ADD IXY, BC/DE/IXY/SP </code>||Register ||Register ||S ||S ||0 ||- ||! ||- ||- ||15 ||IXY+=rr
{{Opcode|opdesc=ADD A, n
|-
|ad1=Accumulator
|<code>ADD HL/DE/BC, A </code>||Register ||Register ||E ||? ||- ||- ||- ||- ||- ||8 ||rr+=unsigned A
|ad2=Immediate
|-
|status=S
|<code>ADD HL/DE/BC, nn </code>||Register ||Immediate ||E ||- ||- ||- ||- ||- ||- ||16 ||rr+=nn
|c=S
|n=0
|pv=V
|h=S
|z=S
|s=S
|tstates=7
|shortfx=A+=n
}}
{{Opcode|opdesc=ADD A, (HL)
|ad1=Accumulator
|ad2=Indirect
|status=S
|c=S
|n=0
|pv=V
|h=S
|z=S
|s=S
|tstates=7
|shortfx=A+=HL*
}}
{{Opcode|opdesc=ADD A, (IXY+d)
|ad1=Accumulator
|ad2=Indexed
|status=S
|c=S
|n=0
|pv=V
|h=S
|z=S
|s=S
|tstates=19
|shortfx=A+=(IXY+d)*
}}
{{Opcode|opdesc=ADD HL, BC/DE/HL/SP
|ad1=Register
|ad2=Register
|status=S
|c=S
|n=0
|pv=-
|h=!
|z=-
|s=-
|tstates=11
|shortfx=HL+=rr
}}
{{Opcode|opdesc=ADD IXY, BC/DE/IXY/SP
|ad1=Register
|ad2=Register
|status=S
|c=S
|n=0
|pv=-
|h=!
|z=-
|s=-
|tstates=15
|shortfx=IXY+=rr
}}
{{Opcode|opdesc=ADD HL/DE/BC, A
|ad1=Register
|ad2=Register
|status=E
|c=?
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=8
|shortfx=rr+=unsigned A
}}
{{Opcode|opdesc=ADD HL/DE/BC, nn
|ad1=Register
|ad2=Immediate
|status=E
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=16
|shortfx=rr+=nn
}}
|}
|}
:Adds values together. Legal combinations are:
:Adds values together. Legal combinations are:
Line 1,019: Line 379:


;ADC (ADd with Carry)
;ADC (ADd with Carry)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=ADC A, r
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=Accumulator
|-
|ad2=Register
|<code>ADC A, r </code>||Accumulator ||Register ||S ||S ||0 ||V ||S ||S ||S ||4 ||A+=r+(CF?1:0)
|status=S
|-
|c=S
|<code>ADC A, n </code>||Accumulator ||Immediate ||S ||S ||0 ||V ||S ||S ||S ||7 ||A+=n+(CF?1:0)
|n=0
|-
|pv=V
|<code>ADC A, (HL) </code>||Accumulator ||Indirect ||S ||S ||0 ||V ||S ||S ||S ||7 ||A+=HL*+(CF?1:0)
|h=S
|-
|z=S
|<code>ADC A, (IXY+d) </code>||Accumulator ||Indexed ||S ||S ||0 ||V ||S ||S ||S ||19 ||A+=(IXY+d)*+(CF?1:0)
|s=S
|-
|tstates=4
|<code>ADC HL, BC/DE/HL/SP </code>||Register ||Register ||S ||S ||0 ||V ||! ||S ||S ||15 ||HL+=rr+(CF?1:0)
|shortfx=A+=r+(CF?1:0)
}}
{{Opcode|opdesc=ADC A, n
|ad1=Accumulator
|ad2=Immediate
|status=S
|c=S
|n=0
|pv=V
|h=S
|z=S
|s=S
|tstates=7
|shortfx=A+=n+(CF?1:0)
}}
{{Opcode|opdesc=ADC A, (HL)
|ad1=Accumulator
|ad2=Indirect
|status=S
|c=S
|n=0
|pv=V
|h=S
|z=S
|s=S
|tstates=7
|shortfx=A+=HL*+(CF?1:0)
}}
{{Opcode|opdesc=ADC A, (IXY+d)
|ad1=Accumulator
|ad2=Indexed
|status=S
|c=S
|n=0
|pv=V
|h=S
|z=S
|s=S
|tstates=19
|shortfx=A+=(IXY+d)*+(CF?1:0)
}}
{{Opcode|opdesc=ADC HL, BC/DE/HL/SP
|ad1=Register
|ad2=Register
|status=S
|c=S
|n=0
|pv=V
|h=!
|z=S
|s=S
|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. For 16-bit values the H flag is set if carry from bit 11; otherwise, it is reset.
: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,091: Line 397:


;SUB
;SUB
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=SUB r
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=Register
|-
|ad2=-
|<code>SUB r </code>||Register ||- ||S ||S ||1 ||V ||S ||S ||S ||4 ||A -= r
|status=S
|-
|c=S
|<code>SUB n </code>||Immediate ||- ||S ||S ||1 ||V ||S ||S ||S ||7 ||A -= n
|n=1
|-
|pv=V
|<code>SUB (HL) </code>||Indirect ||- ||S ||S ||1 ||V ||S ||S ||S ||7 ||A -= HL*
|h=S
|-
|z=S
|<code>SUB (IXY+d) </code>||Indexed ||- ||S ||S ||1 ||V ||S ||S ||S ||19 ||A -= (IXY+d)*
|s=S
|tstates=4
|shortfx=A -= r
}}
{{Opcode|opdesc=SUB n
|ad1=Immediate
|ad2=-
|status=S
|c=S
|n=1
|pv=V
|h=S
|z=S
|s=S
|tstates=7
|shortfx=A -= n
}}
{{Opcode|opdesc=SUB (HL)
|ad1=Indirect
|ad2=-
|status=S
|c=S
|n=1
|pv=V
|h=S
|z=S
|s=S
|tstates=7
|shortfx=A -= HL*
}}
{{Opcode|opdesc=SUB (IXY+d)
|ad1=Indexed
|ad2=-
|status=S
|c=S
|n=1
|pv=V
|h=S
|z=S
|s=S
|tstates=19
|shortfx=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.  
: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,150: Line 413:


;SBC (SuBtract with Carry, er, borrow)
;SBC (SuBtract with Carry, er, borrow)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=SBC A, r
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=Accumulator
|-
|ad2=Register
|<code>SBC A, r </code>||Accumulator ||Register ||S ||S ||1 ||V ||S ||S ||S ||4 ||A-=(r+(CF?1:0))
|status=S
|-
|c=S
|<code>SBC A, n </code>||Accumulator ||Immediate ||S ||S ||1 ||V ||S ||S ||S ||7 ||A-=(n+(CF?1:0))
|n=1
|-
|pv=V
|<code>SBC A, (HL) </code>||Accumulator ||Indirect ||S ||S ||1 ||V ||S ||S ||S ||7 ||A-=(HL*+(CF?1:0))
|h=S
|-
|z=S
|<code>SBC A, (IXY+d) </code>||Accumulator ||Indexed ||S ||S ||1 ||V ||S ||S ||S ||19 ||A-=((IXY+d)+(CF?1:0))
|s=S
|-
|tstates=4
|<code>SBC HL, BC/DE/HL/SP </code>||Register ||Register ||S ||S ||1 ||V ||! ||S ||S ||15 ||HL-=(rr+(CF?1:0))
|shortfx=A-=(r+(CF?1:0))
}}
{{Opcode|opdesc=SBC A, n
|ad1=Accumulator
|ad2=Immediate
|status=S
|c=S
|n=1
|pv=V
|h=S
|z=S
|s=S
|tstates=7
|shortfx=A-=(n+(CF?1:0))
}}
{{Opcode|opdesc=SBC A, (HL)
|ad1=Accumulator
|ad2=Indirect
|status=S
|c=S
|n=1
|pv=V
|h=S
|z=S
|s=S
|tstates=7
|shortfx=A-=(HL*+(CF?1:0))
}}
{{Opcode|opdesc=SBC A, (IXY+d)
|ad1=Accumulator
|ad2=Indexed
|status=S
|c=S
|n=1
|pv=V
|h=S
|z=S
|s=S
|tstates=19
|shortfx=A-=((IXY+d)+(CF?1:0))
}}
{{Opcode|opdesc=SBC HL, BC/DE/HL/SP
|ad1=Register
|ad2=Register
|status=S
|c=S
|n=1
|pv=V
|h=!
|z=S
|s=S
|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. For 16-bit values the H flag is set if borrow from bit 12; otherwise, it is reset.
: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,222: Line 431:


;AND, OR, XOR
;AND, OR, XOR
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=AND r
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=Register
|-
|ad2=-
|<code>AND r </code>||Register ||- ||S ||0 ||0 ||P ||1 ||S ||S ||4 ||A := A & r
|status=S
|-
|c=0
|<code>AND n </code>||Immediate ||- ||S ||0 ||0 ||P ||1 ||S ||S ||7 ||A := A & n
|n=0
|-
|pv=P
|<code>AND (HL) </code>||Indirect ||- ||S ||0 ||0 ||P ||1 ||S ||S ||7 ||A := A & HL*
|h=1
|-
|z=S
|<code>AND (IXY+d) </code>||Indexed ||- ||S ||0 ||0 ||P ||1 ||S ||S ||19 ||A := A & (IXY+d)*
|s=S
|-
|tstates=4
|<code>OR r </code>||Register ||- ||S ||0 ||0 ||P ||0 ||S ||S ||4 ||A := A OR r
|shortfx=A := A & r
|-
}}
|<code>OR n </code>||Immediate ||- ||S ||0 ||0 ||P ||0 ||S ||S ||7 ||A := A OR n
{{Opcode|opdesc=AND n
|-
|ad1=Immediate
|<code>OR (HL) </code>||Indirect ||- ||S ||0 ||0 ||P ||0 ||S ||S ||7 ||A := A OR HL*
|ad2=-
|-
|status=S
|<code>OR (IXY+d) </code>||Indexed ||- ||S ||0 ||0 ||P ||0 ||S ||S ||19 ||A := A OR (IXY+d)*
|c=0
|-
|n=0
|<code>XOR r </code>||Register ||- ||S ||0 ||0 ||P ||0 ||S ||S ||4 ||A := A ^ r
|pv=P
|-
|h=1
|<code>XOR n </code>||Immediate ||- ||S ||0 ||0 ||P ||0 ||S ||S ||7 ||A := A ^ n
|z=S
|-
|s=S
|<code>XOR (HL) </code>||Indirect ||- ||S ||0 ||0 ||P ||0 ||S ||S ||7 ||A := A ^ HL*
|tstates=7
|-
|shortfx=A := A & n
|<code>XOR (IXY+d) </code>||Indexed ||- ||S ||0 ||0 ||P ||0 ||S ||S ||19 ||A := A ^ (IXY+d)*
}}
{{Opcode|opdesc=AND (HL)
|ad1=Indirect
|ad2=-
|status=S
|c=0
|n=0
|pv=P
|h=1
|z=S
|s=S
|tstates=7
|shortfx=A := A & HL*
}}
{{Opcode|opdesc=AND (IXY+d)
|ad1=Indexed
|ad2=-
|status=S
|c=0
|n=0
|pv=P
|h=1
|z=S
|s=S
|tstates=19
|shortfx=A := A & (IXY+d)*
}}
{{Opcode|opdesc=OR r
|ad1=Register
|ad2=-
|status=S
|c=0
|n=0
|pv=P
|h=0
|z=S
|s=S
|tstates=4
|shortfx=A := A OR r
}}
{{Opcode|opdesc=OR n
|ad1=Immediate
|ad2=-
|status=S
|c=0
|n=0
|pv=P
|h=0
|z=S
|s=S
|tstates=7
|shortfx=A := A OR n
}}
{{Opcode|opdesc=OR (HL)
|ad1=Indirect
|ad2=-
|status=S
|c=0
|n=0
|pv=P
|h=0
|z=S
|s=S
|tstates=7
|shortfx=A := A OR HL*
}}
{{Opcode|opdesc=OR (IXY+d)
|ad1=Indexed
|ad2=-
|status=S
|c=0
|n=0
|pv=P
|h=0
|z=S
|s=S
|tstates=19
|shortfx=A := A OR (IXY+d)*
}}
{{Opcode|opdesc=XOR r
|ad1=Register
|ad2=-
|status=S
|c=0
|n=0
|pv=P
|h=0
|z=S
|s=S
|tstates=4
|shortfx=A := A ^ r
}}
{{Opcode|opdesc=XOR n
|ad1=Immediate
|ad2=-
|status=S
|c=0
|n=0
|pv=P
|h=0
|z=S
|s=S
|tstates=7
|shortfx=A := A ^ n
}}
{{Opcode|opdesc=XOR (HL)
|ad1=Indirect
|ad2=-
|status=S
|c=0
|n=0
|pv=P
|h=0
|z=S
|s=S
|tstates=7
|shortfx=A := A ^ HL*
}}
{{Opcode|opdesc=XOR (IXY+d)
|ad1=Indexed
|ad2=-
|status=S
|c=0
|n=0
|pv=P
|h=0
|z=S
|s=S
|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.  
Line 1,385: Line 463:


;MIRROR
;MIRROR
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=MIRROR A
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=Register
|-
|ad2=-
|<code>MIRROR A </code>||Register ||- ||E ||- ||- ||- ||- ||- ||- ||8 ||A[76543210]:=A[01234567]
|status=E
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=8
|shortfx=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.
:Next extended opcode. Mirrors (reverses the order) of bits in the accumulator. Older core versions supported MIRROR DE, but this was removed.
Line 1,405: Line 473:


;CP (ComPare)
;CP (ComPare)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=CP r
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=Register
|-
|ad2=-
|<code>CP r </code>||Register ||- ||S ||S ||1 ||V ||S ||S ||S ||4 ||A-=r?
|status=S
|-
|c=S
|<code>CP n </code>||Immediate ||- ||S ||S ||1 ||V ||S ||S ||S ||7 ||A-=n?
|n=1
|-
|pv=V
|<code>CP (HL) </code>||Indirect ||- ||S ||S ||1 ||V ||S ||S ||S ||7 ||A-=HL*?
|h=S
|-
|z=S
|<code>CP (IXY+d) </code>||Indexed ||- ||S ||S ||1 ||V ||S ||S ||S ||19 ||A-=(IXY+d)?
|s=S
|tstates=4
|shortfx=A-=r?
}}
{{Opcode|opdesc=CP n
|ad1=Immediate
|ad2=-
|status=S
|c=S
|n=1
|pv=V
|h=S
|z=S
|s=S
|tstates=7
|shortfx=A-=n?
}}
{{Opcode|opdesc=CP (HL)
|ad1=Indirect
|ad2=-
|status=S
|c=S
|n=1
|pv=V
|h=S
|z=S
|s=S
|tstates=7
|shortfx=A-=HL*?
}}
{{Opcode|opdesc=CP (IXY+d)
|ad1=Indexed
|ad2=-
|status=S
|c=S
|n=1
|pv=V
|h=S
|z=S
|s=S
|tstates=19
|shortfx=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.
: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.
Line 1,464: Line 489:


;TEST
;TEST
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=TEST n
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=Immediate
|-
|ad2=-
|<code>TEST n </code>||Immediate ||- ||E ||S ||? ||P ||S ||S ||S ||11 ||A&n?
|status=E
|c=S
|n=?
|pv=P
|h=S
|z=S
|s=S
|tstates=11
|shortfx=A&n?
}}
|}
|}
: Next extended opcode. Similar to CP, but performs an AND instead of a subtraction.  
: Next extended opcode. Similar to CP, but performs an AND instead of a subtraction.  
Line 1,484: Line 499:


;INC (INCrement)
;INC (INCrement)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=INC r
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=Register
|-
|ad2=-
|<code>INC r </code>||Register ||- ||S ||- ||0 ||! ||S ||S ||S ||4 ||r++
|status=S
|-
|c=-
|<code>INC (HL) </code>||Indirect ||- ||S ||- ||0 ||! ||S ||S ||S ||11 ||HL*++
|n=0
|-
|pv=!
|<code>INC (IXY+d) </code>||Indexed ||- ||S ||- ||0 ||! ||S ||S ||S ||23 ||(IXY+d)*++
|h=S
|-
|z=S
|<code>INC BC/DE/HL/SP </code>||Register ||- ||S ||- ||- ||- ||- ||- ||- ||6 ||rr++
|s=S
|-
|tstates=4
|<code>INC IXY </code>||Register ||- ||S ||- ||- ||- ||- ||- ||- ||10 ||rr++
|shortfx=r++
}}
{{Opcode|opdesc=INC (HL)
|ad1=Indirect
|ad2=-
|status=S
|c=-
|n=0
|pv=!
|h=S
|z=S
|s=S
|tstates=11
|shortfx=HL*++
}}
{{Opcode|opdesc=INC (IXY+d)
|ad1=Indexed
|ad2=-
|status=S
|c=-
|n=0
|pv=!
|h=S
|z=S
|s=S
|tstates=23
|shortfx=(IXY+d)*++
}}
{{Opcode|opdesc=INC BC/DE/HL/SP
|ad1=Register
|ad2=-
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=6
|shortfx=rr++
}}
{{Opcode|opdesc=INC IXY
|ad1=Register
|ad2=-
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=10
|shortfx=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.
: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.
Line 1,556: Line 517:


;DEC (DECrement)
;DEC (DECrement)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=DEC r
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=Register
|-
|ad2=-
|<code>DEC r </code>||Register ||- ||S ||- ||1 ||! ||S ||S ||S ||4 ||r--
|status=S
|-
|c=-
|<code>DEC (HL) </code>||Indirect ||- ||S ||- ||1 ||! ||S ||S ||S ||11 ||HL*--
|n=1
|-
|pv=!
|<code>DEC (IXY+d) </code>||Indexed ||- ||S ||- ||1 ||! ||S ||S ||S ||23 ||(IXY+D)*--
|h=S
|-
|z=S
|<code>DEC BC/DE/HL/SP </code>||Register ||- ||S ||- ||- ||- ||- ||- ||- ||6 ||rr--
|s=S
|-
|tstates=4
|<code>DEC IXY </code>||Register ||- ||S ||- ||- ||- ||- ||- ||- ||10 ||rr--
|shortfx=r--
}}
{{Opcode|opdesc=DEC (HL)
|ad1=Indirect
|ad2=-
|status=S
|c=-
|n=1
|pv=!
|h=S
|z=S
|s=S
|tstates=11
|shortfx=HL*--
}}
{{Opcode|opdesc=DEC (IXY+d)
|ad1=Indexed
|ad2=-
|status=S
|c=-
|n=1
|pv=!
|h=S
|z=S
|s=S
|tstates=23
|shortfx=(IXY+D)*--
}}
{{Opcode|opdesc=DEC BC/DE/HL/SP
|ad1=Register
|ad2=-
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=6
|shortfx=rr--
}}
{{Opcode|opdesc=DEC IXY
|ad1=Register
|ad2=-
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=10
|shortfx=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.
: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.
Line 1,628: Line 535:


;RLC (Rotate Left Circular)
;RLC (Rotate Left Circular)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=RLC r
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=Register
|-
|ad2=-
|<code>RLC r </code>||Register ||- ||S ||! ||0 ||P ||0 ||S ||S ||8 ||x:=r[7]; r:=r<<1; r[0]:=x; CF:=x
|status=S
|-
|c=!
|<code>RLC (HL) </code>||Indirect ||- ||S ||! ||0 ||P ||0 ||S ||S ||15 ||x:=HL*[7]; HL*:=HL*<<1; HL*[0]:=x; CF:=x
|n=0
|-
|pv=P
|<code>RLC (IXY+d) </code>||Indexed ||- ||S ||! ||0 ||P ||0 ||S ||S ||23 ||x:=(IXY+d)*[7]; (IXY+d)*:=(IXY+d)*<<1; (IXY+d)*[0]:=x; CF:=x
|h=0
|-
|z=S
|<code>RLC r,(IX+d) </code>||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)*
|s=S
|tstates=8
|shortfx=x:=r[7]; r:=r<<1; r[0]:=x; CF:=x
}}
{{Opcode|opdesc=RLC (HL)
|ad1=Indirect
|ad2=-
|status=S
|c=!
|n=0
|pv=P
|h=0
|z=S
|s=S
|tstates=15
|shortfx=x:=HL*[7]; HL*:=HL*<<1; HL*[0]:=x; CF:=x
}}
{{Opcode|opdesc=RLC (IXY+d)
|ad1=Indexed
|ad2=-
|status=S
|c=!
|n=0
|pv=P
|h=0
|z=S
|s=S
|tstates=23
|shortfx=x:=(IXY+d)*[7]; (IXY+d)*:=(IXY+d)*<<1; (IXY+d)*[0]:=x; CF:=x
}}
{{Opcode|opdesc=RLC r,(IX+d)
|ad1=Register
|ad2=Indexed
|status=U
|c=!
|n=0
|pv=P
|h=0
|z=S
|s=S
|tstates=23
|shortfx=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.  
: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.  
Line 1,687: Line 551:


;RL (Rotate Left)
;RL (Rotate Left)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=RL r
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=Register
|-
|ad2=-
|<code>RL r </code>||Register ||- ||S ||! ||0 ||P ||0 ||S ||S ||8 ||x:=r[7]; r:=r<<1; r[0]:=CF; CF:=x
|status=S
|-
|c=!
|<code>RL (HL) </code>||Indirect ||- ||S ||! ||0 ||P ||0 ||S ||S ||15 ||x:=HL*[7]; HL*:=HL*<<1; HL*[0]:=CF; CF:=x
|n=0
|-
|pv=P
|<code>RL (IXY+d) </code>||Indexed ||- ||S ||! ||0 ||P ||0 ||S ||S ||23 ||x:=(IXY+d)*[7]; (IXY+d)*:=(IXY+d)*<<1; (IXY+d)*[0]:=CF; CF:=x
|h=0
|-
|z=S
|<code>RL r,(IX+d) </code>||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)*
|s=S
|tstates=8
|shortfx=x:=r[7]; r:=r<<1; r[0]:=CF; CF:=x
}}
{{Opcode|opdesc=RL (HL)
|ad1=Indirect
|ad2=-
|status=S
|c=!
|n=0
|pv=P
|h=0
|z=S
|s=S
|tstates=15
|shortfx=x:=HL*[7]; HL*:=HL*<<1; HL*[0]:=CF; CF:=x
}}
{{Opcode|opdesc=RL (IXY+d)
|ad1=Indexed
|ad2=-
|status=S
|c=!
|n=0
|pv=P
|h=0
|z=S
|s=S
|tstates=23
|shortfx=x:=(IXY+d)*[7]; (IXY+d)*:=(IXY+d)*<<1; (IXY+d)*[0]:=CF; CF:=x
}}
{{Opcode|opdesc=RL r,(IX+d)
|ad1=Register
|ad2=Indexed
|status=U
|c=!
|n=0
|pv=P
|h=0
|z=S
|s=S
|tstates=23
|shortfx=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.
:Same as RLC, except the MSB is copied to Carry only, and the previous contents of Carry are copied to bit 0.
Line 1,747: Line 567:


;RRC, RR (Rotate Right Circular, Rotate Right)
;RRC, RR (Rotate Right Circular, Rotate Right)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=RRC r
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=Register
|-
|ad2=-
|<code>RRC r </code>||Register ||- ||S ||! ||0 ||P ||0 ||S ||S ||8 ||x:=r[0]; r:=r>>1; r[7]:=x; CF:=x
|status=S
|-
|c=!
|<code>RRC (HL) </code>||Indirect ||- ||S ||! ||0 ||P ||0 ||S ||S ||15 ||x:=HL*[0]; HL*:=HL*>>1; HL*[7]:=x; CF:=x
|n=0
|-
|pv=P
|<code>RRC (IXY+d) </code>||Indexed ||- ||S ||! ||0 ||P ||0 ||S ||S ||23 ||x:=(IXY+d)*[0]; (IXY+d)*:=(IXY+d)*>>1; (IXY+d)*[7]:=x; CF:=x
|h=0
|-
|z=S
|<code>RRC r,(IX+d) </code>||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)*
|s=S
|-
|tstates=8
|<code>RR r </code>||Register ||- ||S ||! ||0 ||P ||0 ||S ||S ||8 ||x:=r[0]; r:=r>>1; r[7]:=CF; CF:=x
|shortfx=x:=r[0]; r:=r>>1; r[7]:=x; CF:=x
|-
}}
|<code>RR (HL) </code>||Indirect ||- ||S ||! ||0 ||P ||0 ||S ||S ||15 ||x:=HL*[0]; HL*:=HL*>>1; HL*[7]:=CF; CF:=x
{{Opcode|opdesc=RRC (HL)
|-
|ad1=Indirect
|<code>RR (IXY+d) </code>||Indexed ||- ||S ||! ||0 ||P ||0 ||S ||S ||23 ||x:=(IXY+d)*[0]; (IXY+d)*:=(IXY+d)*>>1; (IXY+d)*[7]:=CF; CF:=x
|ad2=-
|-
|status=S
|<code>RR r,(IX+d) </code>||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)*
|c=!
|n=0
|pv=P
|h=0
|z=S
|s=S
|tstates=15
|shortfx=x:=HL*[0]; HL*:=HL*>>1; HL*[7]:=x; CF:=x
}}
{{Opcode|opdesc=RRC (IXY+d)
|ad1=Indexed
|ad2=-
|status=S
|c=!
|n=0
|pv=P
|h=0
|z=S
|s=S
|tstates=23
|shortfx=x:=(IXY+d)*[0]; (IXY+d)*:=(IXY+d)*>>1; (IXY+d)*[7]:=x; CF:=x
 
}}
{{Opcode|opdesc=RRC r,(IX+d)
|ad1=Register
|ad2=Indexed
|status=U
|c=!
|n=0
|pv=P
|h=0
|z=S
|s=S
|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
|ad1=Register
|ad2=-
|status=S
|c=!
|n=0
|pv=P
|h=0
|z=S
|s=S
|tstates=8
|shortfx=x:=r[0]; r:=r>>1; r[7]:=CF; CF:=x
}}
{{Opcode|opdesc=RR (HL)
|ad1=Indirect
|ad2=-
|status=S
|c=!
|n=0
|pv=P
|h=0
|z=S
|s=S
|tstates=15
|shortfx=x:=HL*[0]; HL*:=HL*>>1; HL*[7]:=CF; CF:=x
}}
{{Opcode|opdesc=RR (IXY+d)
|ad1=Indexed
|ad2=-
|status=S
|c=!
|n=0
|pv=P
|h=0
|z=S
|s=S
|tstates=23
|shortfx=x:=(IXY+d)*[0]; (IXY+d)*:=(IXY+d)*>>1; (IXY+d)*[7]:=CF; CF:=x
}}
{{Opcode|opdesc=RR r,(IX+d)
|ad1=Register
|ad2=Indexed
|status=U
|c=!
|n=0
|pv=P
|h=0
|z=S
|s=S
|tstates=23
|shortfx=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.
:Same as RLC and RL except they rotate right instead of left.
Line 1,859: Line 591:


;SLA (Shift Left Arithmetic)
;SLA (Shift Left Arithmetic)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=SLA r
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=Register
|-
|ad2=-
|<code>SLA r </code>||Register ||- ||S ||! ||0 ||P ||0 ||S ||S ||8 ||r:=r<<1
|status=S
|-
|c=!
|<code>SLA (HL) </code>||Indirect ||- ||S ||! ||0 ||P ||0 ||S ||S ||15 ||HL*:=HL*<<1
|n=0
|-
|pv=P
|<code>SLA (IXY+d) </code>||Indexed ||- ||S ||! ||0 ||P ||0 ||S ||S ||23 ||(IXY+d)*:=(IXY+d)*<<1
|h=0
|-
|z=S
|<code>SLA r,(IX+d) </code>||Register ||Indexed ||U ||! ||0 ||P ||0 ||S ||S ||23 ||(IX+d)*:=(IX+d)*<<1; r=(IX+d)*
|s=S
|tstates=8
|shortfx=r:=r<<1
}}
{{Opcode|opdesc=SLA (HL)
|ad1=Indirect
|ad2=-
|status=S
|c=!
|n=0
|pv=P
|h=0
|z=S
|s=S
|tstates=15
|shortfx=HL*:=HL*<<1
}}
{{Opcode|opdesc=SLA (IXY+d)
|ad1=Indexed
|ad2=-
|status=S
|c=!
|n=0
|pv=P
|h=0
|z=S
|s=S
|tstates=23
|shortfx=(IXY+d)*:=(IXY+d)*<<1
}}
{{Opcode|opdesc=SLA r,(IX+d)
|ad1=Register
|ad2=Indexed
|status=U
|c=!
|n=0
|pv=P
|h=0
|z=S
|s=S
|tstates=23
|shortfx=(IX+d)*:=(IX+d)*<<1; r=(IX+d)*
}}
|}
|}
:Same as RL except bit 0 is set to zero, not the previous contents of Carry.
:Same as RL except bit 0 is set to zero, not the previous contents of Carry.
Line 1,918: Line 607:


;SRA (Shift Right Arithmetic)
;SRA (Shift Right Arithmetic)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=SRA r
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=Register
|-
|ad2=-
|<code>SRA r </code>||Register ||- ||S ||! ||0 ||P ||0 ||S ||S ||8 ||r:=r>>1 OR r[7]
|status=S
|-
|c=!
|<code>SRA (HL) </code>||Indirect ||- ||S ||! ||0 ||P ||0 ||S ||S ||15 ||HL*:=HL*>>1 OR HL*[7]
|n=0
|-
|pv=P
|<code>SRA (IXY+d) </code>||Indexed ||- ||S ||! ||0 ||P ||0 ||S ||S ||23 ||(IXY+d)*:=(IXY+d)*>>1 OR (IXY+d)*[7]
|h=0
|-
|z=S
|<code>SRA r,(IX+d) </code>||Register ||Indexed ||U ||! ||0 ||P ||0 ||S ||S ||23 ||(IX+d)*:=(IX+d)*>>1 OR (IX+d)*[7]; r:=(IX+d)*
|s=S
|tstates=8
|shortfx=r:=r>>1 OR r[7]
}}
{{Opcode|opdesc=SRA (HL)
|ad1=Indirect
|ad2=-
|status=S
|c=!
|n=0
|pv=P
|h=0
|z=S
|s=S
|tstates=15
|shortfx=HL*:=HL*>>1 OR HL*[7]
}}
{{Opcode|opdesc=SRA (IXY+d)
|ad1=Indexed
|ad2=-
|status=S
|c=!
|n=0
|pv=P
|h=0
|z=S
|s=S
|tstates=23
|shortfx=(IXY+d)*:=(IXY+d)*>>1 OR (IXY+d)*[7]
}}
{{Opcode|opdesc=SRA r,(IX+d)
|ad1=Register
|ad2=Indexed
|status=U
|c=!
|n=0
|pv=P
|h=0
|z=S
|s=S
|tstates=23
|shortfx=(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.  
: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.  
Line 1,977: Line 623:


;SRL (Shift Right Logical)
;SRL (Shift Right Logical)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=SRL r
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=Register
|-
|ad2=-
|<code>SRL r </code>||Register ||- ||S ||! ||0 ||P ||0 ||S ||0 ||8 ||r:=unsigned(r)>>1
|status=S
|-
|c=!
|<code>SRL (HL) </code>||Indirect ||- ||S ||! ||0 ||P ||0 ||S ||0 ||15 ||HL*:=unsigned(HL*)>>1
|n=0
|-
|pv=P
|<code>SRL (IXY+d) </code>||Indexed ||- ||S ||! ||0 ||P ||0 ||S ||0 ||23 ||(IXY+d)*:=unsigned((IXY+d)*)>>1
|h=0
|-
|z=S
|<code>SRL r,(IXY+d) </code>||Register ||Indexed ||U ||! ||0 ||P ||0 ||S ||0 ||23 ||(IXY+d)*:=unsigned((IXY+d)*)>>1; r:=(IXY+d)*
|s=0
|tstates=8
|shortfx=r:=unsigned(r)>>1
}}
{{Opcode|opdesc=SRL (HL)
|ad1=Indirect
|ad2=-
|status=S
|c=!
|n=0
|pv=P
|h=0
|z=S
|s=0
|tstates=15
|shortfx=HL*:=unsigned(HL*)>>1
}}
{{Opcode|opdesc=SRL (IXY+d)
|ad1=Indexed
|ad2=-
|status=S
|c=!
|n=0
|pv=P
|h=0
|z=S
|s=0
|tstates=23
|shortfx=(IXY+d)*:=unsigned((IXY+d)*)>>1
}}
{{Opcode|opdesc=SRL r,(IXY+d)
|ad1=Register
|ad2=Indexed
|status=U
|c=!
|n=0
|pv=P
|h=0
|z=S
|s=0
|tstates=23
|shortfx=(IXY+d)*:=unsigned((IXY+d)*)>>1; r:=(IXY+d)*
}}
|}
|}
:Same as SLA except it shifts right instead of left.
:Same as SLA except it shifts right instead of left.
Line 2,036: Line 639:


;RLCA, RLA, RRCA, RRA
;RLCA, RLA, RRCA, RRA
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=RLCA
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=-
|-
|ad2=-
|<code>RLCA </code>||- ||- ||S ||! ||0 ||- ||0 ||- ||- ||4 ||x:=A[7]; A:=A<<1; A[0]:=x; CF:=x
|status=S
|-
|c=!
|<code>RLA </code>||- ||- ||S ||! ||0 ||- ||0 ||- ||- ||4 ||x:=A[7]; A:=A<<1; A[0]:=CF; CF:=x
|n=0
|-
|pv=-
|<code>RRCA </code>||- ||- ||S ||! ||0 ||- ||0 ||- ||- ||4 ||x:=A[0]; A:=A>>1; A[7]:=x; CF:=x
|h=0
|-
|z=-
|<code>RRA </code>||- ||- ||S ||! ||0 ||- ||0 ||- ||- ||4 ||x:=A[0]; A:=A>>1; A[7]:=CF; CF:=x
|s=-
|tstates=4
|shortfx=x:=A[7]; A:=A<<1; A[0]:=x; CF:=x
}}
{{Opcode|opdesc=RLA
|ad1=-
|ad2=-
|status=S
|c=!
|n=0
|pv=-
|h=0
|z=-
|s=-
|tstates=4
|shortfx=x:=A[7]; A:=A<<1; A[0]:=CF; CF:=x
}}
{{Opcode|opdesc=RRCA
|ad1=-
|ad2=-
|status=S
|c=!
|n=0
|pv=-
|h=0
|z=-
|s=-
|tstates=4
|shortfx=x:=A[0]; A:=A>>1; A[7]:=x; CF:=x
}}
{{Opcode|opdesc=RRA
|ad1=-
|ad2=-
|status=S
|c=!
|n=0
|pv=-
|h=0
|z=-
|s=-
|tstates=4
|shortfx=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.
:Same as their matching instruction except they work only on A, are faster, and do not alter S, Z or P/V.
Line 2,100: Line 660:


;SL1 or SLI (Shift Left and Add 1) or (Shift Left and Increment)
;SL1 or SLI (Shift Left and Add 1) or (Shift Left and Increment)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=SL1 r
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=Register
|-
|ad2=-
|<code>SL1 r </code>||Register ||- ||U ||! ||0 ||P ||0 ||S ||S ||8 ||r:=(r<<1)+1
|status=U
|-
|c=!
|<code>SL1 (HL) </code>||Indirect ||- ||U ||! ||0 ||P ||0 ||S ||S ||15 ||HL*:=(HL*<<1)+1
|n=0
|-
|pv=P
|<code>SL1 (IXY+d) </code>||Indexed ||- ||U ||! ||0 ||P ||0 ||S ||S ||23 ||(IXY+d)*:=((IXY+d)*<<1)+1
|h=0
|-
|z=S
|<code>SL1 r,(IXY+d) </code>||Register ||Indexed ||U ||! ||0 ||P ||0 ||S ||S ||23 ||(IXY+d)*:=((IXY+d)*<<1)+1; r=(IXY+d)*
|s=S
|tstates=8
|shortfx=r:=(r<<1)+1
}}
{{Opcode|opdesc=SL1 (HL)
|ad1=Indirect
|ad2=-
|status=U
|c=!
|n=0
|pv=P
|h=0
|z=S
|s=S
|tstates=15
|shortfx=HL*:=(HL*<<1)+1
}}
{{Opcode|opdesc=SL1 (IXY+d)
|ad1=Indexed
|ad2=-
|status=U
|c=!
|n=0
|pv=P
|h=0
|z=S
|s=S
|tstates=23
|shortfx=(IXY+d)*:=((IXY+d)*<<1)+1
}}
{{Opcode|opdesc=SL1 r,(IXY+d)
|ad1=Register
|ad2=Indexed
|status=U
|c=!
|n=0
|pv=P
|h=0
|z=S
|s=S
|tstates=23
|shortfx=(IXY+d)*:=((IXY+d)*<<1)+1; r=(IXY+d)*
}}
|}
|}
:Undocumented opcodes that behave like SLA, but set bit 0 to 1 instead of 0.
:Undocumented opcodes that behave like SLA, but set bit 0 to 1 instead of 0.
Line 2,159: Line 676:


;RLD (Rotate Left bcd Digit)
;RLD (Rotate Left bcd Digit)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=RLD
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=-
|-
|ad2=-
|<code>RLD </code>||- ||- ||S ||- ||0 ||P ||0 ||S ||S ||18 ||x=HL*; HL*[0123]:=A[0123]; HL*[7654]:=x[0123]; A[0123]:=x[7654]   
|status=S
|c=-
|n=0
|pv=P
|h=0
|z=S
|s=S
|tstates=18
|shortfx=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.
: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.
Line 2,179: Line 686:


;RRD (Rotate Right bcd Digit)
;RRD (Rotate Right bcd Digit)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=RRD
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=-
|-
|ad2=-
|<code>RRD </code>||- ||- ||S ||- ||0 ||P ||0 ||S ||S ||18 ||x=HL*; HL*[7654]:=A[0123]; HL*[0123]:=x[7654]; A[0123]:=x[0123]
|status=S
|c=-
|n=0
|pv=P
|h=0
|z=S
|s=S
|tstates=18
|shortfx=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.
: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.
Line 2,198: Line 695:


;Barrel (variable amount) shift and rotate (cores v2+ only)
;Barrel (variable amount) shift and rotate (cores v2+ only)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=BSLA DE,B
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=-
|-
|ad2=-
|<code>BSLA DE,B </code>||- ||- ||E ||- ||- ||- ||- ||- ||- ||DE:=DE<<(B&31) ||8
|status=E
|-
|c=-
|<code>BSRA DE,B </code>||- ||- ||E ||- ||- ||- ||- ||- ||- ||DE:=signed(DE)>>(B&31) ||8
|n=-
|-
|pv=-
|<code>BSRL DE,B </code>||- ||- ||E ||- ||- ||- ||- ||- ||- ||DE:=unsigned(DE)>>(B&31) ||8
|h=-
|-
|z=-
|<code>BSRF DE,B </code>||- ||- ||E ||- ||- ||- ||- ||- ||- ||DE:=~(unsigned(~DE)>>(B&31)) ||8
|s=-
|-
|shortfx=DE:=DE<<(B&31)
|<code>BRLC DE,B </code>||- ||- ||E ||- ||- ||- ||- ||- ||- ||DE:=DE<<(B&15) OR DE>>(16-B&15) ||8
|tstates=8
}}
{{Opcode|opdesc=BSRA DE,B
|ad1=-
|ad2=-
|status=E
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|shortfx=DE:=signed(DE)>>(B&31)
|tstates=8
}}
{{Opcode|opdesc=BSRL DE,B
|ad1=-
|ad2=-
|status=E
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|shortfx=DE:=unsigned(DE)>>(B&31)
|tstates=8
}}
{{Opcode|opdesc=BSRF DE,B
|ad1=-
|ad2=-
|status=E
|c=-
|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=-
|h=-
|z=-
|s=-
|shortfx=DE:=DE<<(B&15) OR DE>>(16-B&15)
|tstates=8
}}
|}
|}
: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).
: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).
Line 2,271: Line 714:


;CPL (ComPLement)
;CPL (ComPLement)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=CPL
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=-
|-
|ad2=-
|<code>CPL </code>||- ||- ||S ||- ||1 ||- ||1 ||- ||- ||4 ||A:=~A
|status=S
|c=-
|n=1
|pv=-
|h=1
|z=-
|s=-
|tstates=4
|shortfx=A:=~A
}}
|}
|}
:Inverts the contents of the accumulator.
:Inverts the contents of the accumulator.
Line 2,291: Line 724:


;NEG (NEGate)
;NEG (NEGate)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=NEG
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=-
|-
|ad2=-
|<code>NEG </code>||- ||- ||S ||! ||1 ||! ||S ||S ||S ||8 ||A:=0-A
|status=S
|c=!
|n=1
|pv=!
|h=S
|z=S
|s=S
|tstates=8
|shortfx=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.
: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.
Line 2,311: Line 734:


;CCF (Complement Carry Flag)
;CCF (Complement Carry Flag)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=CCF
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=-
|-
|ad2=-
|<code>CCF </code>||- ||- ||S ||! ||0 ||- ||! ||- ||- ||4 ||CF:=!CF
|status=S
|c=!
|n=0
|pv=-
|h=!
|z=-
|s=-
|tstates=4
|shortfx=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.
:Inverts the carry flag. (Does not, as might be assumed, clear it!) Also sets H to the previous value of the carry flag.
Line 2,331: Line 744:


;SCF (Set Carry Flag)
;SCF (Set Carry Flag)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=SCF
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=-
|-
|ad2=-
|<code>SCF </code>||- ||- ||S ||1 ||0 ||- ||0 ||- ||- ||4 ||CF:=1
|status=S
|c=1
|n=0
|pv=-
|h=0
|z=-
|s=-
|tstates=4
|shortfx=CF:=1
}}
|}
|}
:Sets the carry flag.
:Sets the carry flag.
Line 2,351: Line 754:


;BIT (test BIT)
;BIT (test BIT)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=BIT b,r
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=Immediate
|-
|ad2=Register
|<code>BIT b,r </code>||Immediate ||Register ||S ||- ||0 ||? ||1 ||! ||? ||8 ||r[b]==1?
|status=S
|-
|c=-
|<code>BIT b,(HL) </code>||Immediate ||Indirect ||S ||- ||0 ||? ||1 ||! ||? ||12 ||HL*[b]==1?
|n=0
|-
|pv=?
|<code>BIT b,(IXY+d) </code>||Immediate ||Indexed ||S ||- ||0 ||? ||1 ||! ||? ||20 ||(IXY+d)*[b]==1?
|h=1
|z=!
|s=?
|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=BIT b,(IXY+d)
|ad1=Immediate
|ad2=Indexed
|status=S
|c=-
|n=0
|pv=?
|h=1
|z=!
|s=?
|tstates=20
|shortfx=(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.
: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.
Line 2,397: Line 768:


;SET (SET bit)
;SET (SET bit)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=SET b,r
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=Immediate
|-
|ad2=Register
|<code>SET b,r </code>||Immediate ||Register ||S ||- ||- ||- ||- ||- ||- ||8 ||r:=r OR (1<<b)
|status=S
|-
|c=-
|<code>SET b,(HL) </code>||Immediate ||Register ||S ||- ||- ||- ||- ||- ||- ||15 ||HL*:=HL* OR (1<<b)
|n=-
|-
|pv=-
|<code>SET b,(IXY+d) </code>||Immediate ||Indexed ||S ||- ||- ||- ||- ||- ||- ||23 ||(IXY+d)*:=(IXY+d)* OR (1<<b)
|h=-
|-
|z=-
|<code>SET r,b,(IX+d) </code>||Immediate ||Indexed ||U ||- ||- ||- ||- ||- ||- ||23 ||(IX+d)*:=(IX+d)* OR (1<<b); r:=(IX+d)*
|s=-
|-
|tstates=8
|<code>SETAE </code>||- ||- ||E ||- ||- ||- ||- ||- ||- ||8 ||A:=unsigned($80)>>(E&7)
|shortfx=r:=r OR (1<<b)
}}
{{Opcode|opdesc=SET b,(HL)
|ad1=Immediate
|ad2=Register
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=15
|shortfx=HL*:=HL* OR (1<<b)
}}
{{Opcode|opdesc=SET b,(IXY+d)
|ad1=Immediate
|ad2=Indexed
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=23
|shortfx=(IXY+d)*:=(IXY+d)* OR (1<<b)
}}
{{Opcode|opdesc=SET r,b,(IX+d)
|ad1=Immediate
|ad2=Indexed
|status=U
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=23
|shortfx=(IX+d)*:=(IX+d)* OR (1<<b); r:=(IX+d)*
}}
{{Opcode|opdesc=SETAE
|ad1=-
|ad2=-
|status=E
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=8
|shortfx=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.
: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.
Line 2,470: Line 787:


;RES (RESet bit)
;RES (RESet bit)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=RES b,r
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=Immediate
|-
|ad2=Register
|<code>RES b,r </code>||Immediate ||Register ||S ||- ||- ||- ||- ||- ||- ||8 ||r:=r & (~(1<<b))
|status=S
|-
|c=-
|<code>RES b,(HL) </code>||Immediate ||Register ||S ||- ||- ||- ||- ||- ||- ||15 ||HL*:=HL* & (~(1<<b))
|n=-
|-
|pv=-
|<code>RES b,(IXY+d) </code>||Immediate ||Indexed ||S ||- ||- ||- ||- ||- ||- ||23 ||(IXY+d)*:=(IXY+d)* & (~(1<<b))
|h=-
|-
|z=-
|<code>RES r,b,(IX+d) </code>||Immediate ||Indexed ||U ||- ||- ||- ||- ||- ||- ||23 ||(IX+d)*:=(IX+d)* & (~(1<<b)); r:=(IX+d)*
|s=-
|tstates=8
|shortfx=r:=r & (~(1<<b))
}}
{{Opcode|opdesc=RES b,(HL)
|ad1=Immediate
|ad2=Register
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=15
|shortfx=HL*:=HL* & (~(1<<b))
}}
{{Opcode|opdesc=RES b,(IXY+d)
|ad1=Immediate
|ad2=Indexed
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=23
|shortfx=(IXY+d)*:=(IXY+d)* & (~(1<<b))
}}
{{Opcode|opdesc=RES r,b,(IX+d)
|ad1=Immediate
|ad2=Indexed
|status=U
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=23
|shortfx=(IX+d)*:=(IX+d)* & (~(1<<b)); r:=(IX+d)*
}}
|}
|}
:Resets the numbered bit on target value. The possible targets are the same as BIT.
:Resets the numbered bit on target value. The possible targets are the same as BIT.
Line 2,529: Line 803:


;DAA (Decimal Adjust Accumulator)
;DAA (Decimal Adjust Accumulator)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=DAA
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=-
|-
|ad2=-
|<code>DAA </code>||- ||- ||S ||! ||- ||P ||! ||S ||S ||8 ||if(A&$0F>$09 or HF) A±=$06; if(A&$F0>$90 or CF) A±=$60 (± depends on NF)
|status=S
|c=!
|n=-
|pv=P
|h=!
|z=S
|s=S
|tstates=8
|shortfx=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).
:Modifies the contents of the accumulator based on the flags left by previous operation to correct for binary coded decimal (BCD).
Line 2,549: Line 813:


;MUL (MULtiply)
;MUL (MULtiply)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=MUL d,e
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=-
|-
|ad2=-
|<code>MUL d,e </code>||- ||- ||E ||- ||- ||- ||- ||- ||- ||8 ||DE:=D*E
|status=E
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=8
|shortfx=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).
: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).
Line 2,569: Line 823:


;SWAPNIB (SWAP NIBbles)
;SWAPNIB (SWAP NIBbles)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=SWAPNIB
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=-
|-
|ad2=-
|<code>SWAPNIB </code>||- ||- ||E ||- ||- ||- ||- ||- ||- ||8 ||A:=A[3210]<<4 OR A[7654]>>4
|status=E
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=8
|shortfx=A:=A[3210]<<4 OR A[7654]>>4
}}
|}
|}
:Next extended opcode. Swaps the high and low nibbles of the accumulator.
:Next extended opcode. Swaps the high and low nibbles of the accumulator.
Line 2,588: Line 832:


;PIXELAD (PIXEL ADdress)
;PIXELAD (PIXEL ADdress)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=PIXELAD
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=-
|-
|ad2=-
|<code>PIXELAD </code>||- ||- ||E ||- ||- ||- ||- ||- ||- ||8 ||HL:=$4000+((D&$C0)<<5)+((D&$07)<<8)+((D&$38)<<2)+(E>>3)
|status=E
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=8
|shortfx=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.
: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.
Line 2,608: Line 842:


;PIXELDN (PIXEL DowN)
;PIXELDN (PIXEL DowN)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=PIXELDN
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=-
|-
|ad2=-
|<code>PIXELDN </code>||- ||- ||E ||- ||- ||- ||- ||- ||- ||8 ||if(HL&$0700!=$0700) HL+=256;<br>
|status=E
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=8
|shortfx=if(HL&$0700!=$0700) HL+=256;<br>
else if(HL&$e0!=$e0) HL:=HL&$F8FF+$20;<br>
else if(HL&$e0!=$e0) HL:=HL&$F8FF+$20;<br>
else HL:=HL&$F81F+$0800
else HL:=HL&$F81F+$0800
}}
|}
|}
:Updates the address in HL to move down by one line of pixels.
:Updates the address in HL to move down by one line of pixels.
Line 2,629: Line 853:
=== Control Flow ===
=== Control Flow ===
;JP (JumP)
;JP (JumP)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=JP nn
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=Address
|-
|ad2=-
|<code>JP nn </code>||Address ||- ||S ||- ||- ||- ||- ||- ||- ||10 ||PC:=nn
|status=S
|-
|c=-
|<code>JP (HL) </code>||Register ||- ||S ||- ||- ||- ||- ||- ||- ||4 ||PC:=HL (not PC:=HL*)
|n=-
|-
|pv=-
|<code>JP (IXY) </code>||Register ||- ||S ||- ||- ||- ||- ||- ||- ||8 ||PC:=IXY (not PC:=IXY*)
|h=-
|-
|z=-
|<code>JP (C) </code>||Register ||- ||E ||? ||? ||? ||? ||? ||? ||13 ||PC:=PC&$C000+IN(C)<<6
|s=-
|tstates=10
|shortfx=PC:=nn
}}
{{Opcode|opdesc=JP (HL)
|ad1=Register
|ad2=-
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=4
|shortfx=PC:=HL (not PC:=HL*)
}}
{{Opcode|opdesc=JP (IXY)
|ad1=Register
|ad2=-
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|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
|shortfx=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<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.
: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.
Line 2,688: Line 869:


;JP cc (JumP conditionally)
;JP cc (JumP conditionally)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=JP Z/NZ/NC/C/PO/PE/P/M, nn
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=Address
|-
|ad2=-
|<code>JP Z/NZ/NC/C/PO/PE/P/M, nn </code>||Address ||- ||S ||- ||- ||- ||- ||- ||- ||10 ||if cc PC:=nn
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=10
|shortfx=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.
: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.
Line 2,708: Line 879:


;JR (Jump Relative)
;JR (Jump Relative)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=JR nn
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=Immediate
|-
|ad2=-
|<code>JR nn </code>||Immediate ||- ||S ||- ||- ||- ||- ||- ||- ||12 ||PC+=nn
|status=S
|-
|c=-
|<code>JR C/NC/Z/NZ, nn </code>||Immediate ||- ||S ||- ||- ||- ||- ||- ||- ||12 ;  7 if not cc ||if cc PC+=nn
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=12
|shortfx=PC+=nn
}}
{{Opcode|opdesc=JR C/NC/Z/NZ, nn
|ad1=Immediate
|ad2=-
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=12 ;  7 if not cc
|shortfx=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.
: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.
Line 2,741: Line 891:


;DJNZ (Decrement reg. b and Jump if Not Zero)
;DJNZ (Decrement reg. b and Jump if Not Zero)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=DJNZ n
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=Immediate
|-
|ad2=-
|<code>DJNZ n </code>||Immediate ||- ||S ||- ||- ||- ||- ||- ||- ||13 ||B--; if B!=0 PC+=nn
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=13
|shortfx=B--; if B!=0 PC+=nn
}}
|}
|}
:Decrements B then performs JR NZ.. to the given address. Used for encapsulating loops.
:Decrements B then performs JR NZ.. to the given address. Used for encapsulating loops.
Line 2,761: Line 901:


;CALL
;CALL
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=CALL nn
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=Address
|-
|ad2=-
|<code>CALL nn </code>||Address ||- ||S ||- ||- ||- ||- ||- ||- ||17 ||SP-=2; SP*:=PC; PC:=nn
|status=S
|-
|c=-
|<code>CALL Z/NZ/C/NC/PO/PE/P/M, nn </code>||Address ||- ||S ||- ||- ||- ||- ||- ||- ||17 ;  10 if not cc ||if cc {SP-=2; SP*:=PC; PC:=nn}
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=17
|shortfx=SP-=2; SP*:=PC; PC:=nn
}}
{{Opcode|opdesc=CALL Z/NZ/C/NC/PO/PE/P/M, nn
|ad1=Address
|ad2=-
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=17 ;  10 if not cc
|shortfx=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.  
:Like JP (including the ability to have conditions), but PUSHes the PC before jumping. Used for subroutine calls.  
Line 2,795: Line 914:


;RET (RETurn)
;RET (RETurn)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=RET
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=-
|-
|ad2=-
|<code>RET </code>||- ||- ||S ||- ||- ||- ||- ||- ||- ||10 ||PC:=SP*; SP+=2
|status=S
|-
|c=-
|<code>RET Z/NZ/C/NC/PO/PE/P/M </code>||- ||- ||S ||- ||- ||- ||- ||- ||- ||11 ;  5 if not cc ||if cc {PC:=SP*; SP+=2}
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=10
|shortfx=PC:=SP*; SP+=2
}}
{{Opcode|opdesc=RET Z/NZ/C/NC/PO/PE/P/M
|ad1=-
|ad2=-
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=11 ;  5 if not cc
|shortfx=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.
:POPs the PC from the stack, returning from a previous CALL. This can also accept the same conditions as JP.
Line 2,828: Line 926:


;RETI (RETurn from Interrupt)
;RETI (RETurn from Interrupt)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=RETI
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=-
|-
|ad2=-
|<code>RETI </code>||- ||- ||S ||- ||- ||- ||- ||- ||- ||14 ||PC:=SP*; SP+=2
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=14
|shortfx=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).
:Returns from an interrupt service routine (same as RET instruction, but also does signal to I/O device that the interrupt routine is completed).
Line 2,848: Line 936:


;RETN (RETurn from Non-maskable interrupt)
;RETN (RETurn from Non-maskable interrupt)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=RETN
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=-
|-
|ad2=-
|<code>RETN </code>||- ||- ||S ||- ||- ||- ||- ||- ||- ||14 ||IFF1:=IFF2; PC:=SP*; SP+=2
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=14
|shortfx=IFF1:=IFF2; PC:=SP*; SP+=2
}}
|}
|}
:Returns from a non-maskable interrupt service routine.
:Returns from a non-maskable interrupt service routine.
Line 2,868: Line 946:


;RST (ReSTart)
;RST (ReSTart)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=RST n
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=Immediate
|-
|ad2=-
|<code>RST n </code>||Immediate ||- ||S ||- ||- ||- ||- ||- ||- ||11 ||CALL n
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=11
|shortfx=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.  
: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.  
Line 2,888: Line 956:


;NOP (No OPeration)
;NOP (No OPeration)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=NOP
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=-
|-
|ad2=-
|<code>NOP </code>||- ||- ||S ||- ||- ||- ||- ||- ||- ||4 ||PC+=1
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=4
|shortfx=PC+=1
}}
|}
|}
:Does "nothing" (just usual housekeeping like refreshing memory and advancing program counter to next instruction).
:Does "nothing" (just usual housekeeping like refreshing memory and advancing program counter to next instruction).
Line 2,908: Line 966:


;HALT
;HALT
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=HALT
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=-
|-
|ad2=-
|<code>HALT </code>||- ||- ||S ||- ||- ||- ||- ||- ||- ||4 ||waits for interrupt
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=4
|shortfx=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.
: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.
Line 2,928: Line 976:


;DI (Disable Interrupts)
;DI (Disable Interrupts)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=DI
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=-
|-
|ad2=-
|<code>DI </code>||- ||- ||S ||- ||- ||- ||- ||- ||- ||4 ||IFF1:=0; IFF2:=0
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=4
|shortfx=IFF1:=0; IFF2:=0
}}
|}
|}
:Disables maskable interrupts.
:Disables maskable interrupts.
Line 2,948: Line 986:


;EI (Enable Interrupts)
;EI (Enable Interrupts)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=EI
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=-
|-
|ad2=-
|<code>EI </code>||- ||- ||S ||- ||- ||- ||- ||- ||- ||4 ||IFF1:=1; IFF2:=1
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=4
|shortfx=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).
: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).
Line 2,968: Line 996:


;IM (Interrupt Mode)
;IM (Interrupt Mode)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=IM n
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=Immediate
|-
|ad2=-
|<code>IM n </code>||Immediate ||- ||S ||- ||- ||- ||- ||- ||- ||8 ||Interrupt mode:=n
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=8
|shortfx=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)
: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)
Line 2,987: Line 1,005:
=== Input and Output ===
=== Input and Output ===
;IN r, (c); OUT (c), r
;IN r, (c); OUT (c), r
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=IN r, (c)
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=Register
|-
|ad2=Register
|<code>IN r, (c) </code>||Register ||Register ||S ||- ||0 ||P ||0 ||S ||S ||12 ||r := in(BC)
|status=S
|-
|c=-
|<code>OUT (c),r </code>||Register ||Register ||S ||- ||- ||- ||- ||- ||- ||12 ||out(BC,r)
|n=0
|pv=P
|h=0
|z=S
|s=S
|tstates=12
|shortfx=r := in(BC)
}}
{{Opcode|opdesc=OUT (c),r
|ad1=Register
|ad2=Register
|status=S
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=12
|shortfx=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.
: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.
Line 3,020: Line 1,017:


;IN (c); OUT (c), 0
;IN (c); OUT (c), 0
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=IN (c)
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=Register
|-
|ad2=-
|<code>IN (c) </code>||Register ||- ||U ||- ||0 ||P ||0 ||S ||S ||12 ||in(BC)?
|status=U
|-
|c=-
|<code>OUT (c),0 </code>||Register ||Immediate ||U ||- ||- ||- ||- ||- ||- ||12 ||out(BC,0)
|n=0
|pv=P
|h=0
|z=S
|s=S
|tstates=12
|shortfx=in(BC)?
}}
{{Opcode|opdesc=OUT (c),0
|ad1=Register
|ad2=Immediate
|status=U
|c=-
|n=-
|pv=-
|h=-
|z=-
|s=-
|tstates=12
|shortfx=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.
: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.
Line 3,053: Line 1,029:


;IN a, (n); OUT (n), a
;IN a, (n); OUT (n), a
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=IN A, (n)
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=Accumulator
|-
|ad2=Immediate
|<code>IN A, (n) </code>||Accumulator ||Immediate ||S ||- ||- ||- ||- ||- ||- ||11 ||A := in(An)
|status=S
|-
|c=-
|<code>OUT (n),A </code>||Immediate ||Accumulator ||S ||- ||- ||- ||- ||- ||- ||11 ||out(An,A)
|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.
: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.
Line 3,086: Line 1,041:


;INI (INput and Increment)
;INI (INput and Increment)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=INI
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=-
|-
|ad2=-
|<code>INI </code>||- ||- ||S ||? ||1 ||? ||? ||! ||? ||16 ||HL*:=in(BC); HL++; B--
|status=S
|c=?
|n=1
|pv=?
|h=?
|z=!
|s=?
|tstates=16
|shortfx=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.
: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.
Line 3,106: Line 1,051:


;INIR (INput and Increment Repeated)
;INIR (INput and Increment Repeated)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=INIR
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=-
|-
|ad2=-
|<code>INIR </code>||- ||- ||S ||? ||1 ||? ||? ||1 ||? ||21x+16 ||do INI while(B>0)
|status=S
|c=?
|n=1
|pv=?
|h=?
|z=1
|s=?
|tstates=21x+16
|shortfx=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.
: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.
Line 3,126: Line 1,061:


;IND, INDR (INput and Decrement, INput and Decrement Repeated)
;IND, INDR (INput and Decrement, INput and Decrement Repeated)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=IND
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=-
|-
|ad2=-
|<code>IND </code>||- ||- ||S ||? ||1 ||? ||? ||! ||? ||16 ||HL*:=in(BC); HL--; B--
|status=S
|-
|c=?
|<code>INDR </code>||- ||- ||S ||? ||1 ||? ||? ||1 ||? ||21x+16 ||do IND while(B>0)
|n=1
|pv=?
|h=?
|z=!
|s=?
|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)
}}
|}
|}
:Behave like INI and INIR except that HL is decremented instead of incremented.
:Behave like INI and INIR except that HL is decremented instead of incremented.
Line 3,159: Line 1,073:


;OUTI (Out and Increment), OTIR (Out and Increment Repeated), OUTD (Out and Decrement), OTDR (Out and Decrement Repeated)
;OUTI (Out and Increment), OTIR (Out and Increment Repeated), OUTD (Out and Decrement), OTDR (Out and Decrement Repeated)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=OUTI
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=-
|-
|ad2=-
|<code>OUTI </code>||- ||- ||S ||? ||1 ||? ||? ||! ||? ||16 ||B--; out(BC,HL*); HL++
|status=S
|-
|c=?
|<code>OTIR </code>||- ||- ||S ||? ||1 ||? ||? ||1 ||? ||21x+16 ||do OUTI while (B>0)
|n=1
|-
|pv=?
|<code>OUTD </code>||- ||- ||S ||? ||1 ||? ||? ||! ||? ||16 ||B--; out(BC,HL*); HL--
|h=?
|-
|z=!
|<code>OTDR </code>||- ||- ||S ||? ||1 ||? ||? ||1 ||? ||21x+16 ||do OUTD while (B>0)
|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.
: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.
Line 3,218: Line 1,089:


;OUTINB (Out and Increment with No B)
;OUTINB (Out and Increment with No B)
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=OUTINB
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=-
|-
|ad2=-
|<code>OUTINB </code>||- ||- ||E ||? ||? ||? ||? ||? ||? ||16 ||out(BC,HL*); HL++
|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.
:Next extended opcode. Behaves like OUTI, but doesn't decrement B.
Line 3,238: Line 1,099:


;NEXTREG
;NEXTREG
:{{Opcodelisttop}}
{| class="wikitable"
{{Opcode|opdesc=NEXTREG n,n'
!Mnemonic || Addressing mode 1 || Addressing mode 2 || Status || C || N || PV || H || Z || S || Tstates || Shortfx
|ad1=Immediate
|-
|ad2=Immediate
|<code>NEXTREG n,n' </code>||Immediate ||Immediate ||E ||- ||- ||- ||- ||- ||- ||20 ||HwNextReg_n:=n'
|status=E
|-
|c=-
|<code>NEXTREG n, A </code>||Immediate ||Accumulator ||E ||- ||- ||- ||- ||- ||- ||17 ||HwNextReg_n:=A
|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}}.
:Next extended opcode. Directly sets the [[Board feature control|Next Feature Control Registers]] without going through ports [[TBBlue_Register_Select]] and [[TBBlue Register Access]].


=== Open Issues ===
=== A note on some Z80-N specific observations ===
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.


2021-09-16: It is still not confirmed but it seems that LDIX/LDDX/LDIRX/LDDRX/LDPIRX could affect flags the same way as LDI/LDIR - (Ped: '''TO DO'''). (Note: That behaviour could change in the following cores)
2025-01-25: Testing 3.02.x 1) <code>LDIX</code>, <code>LDDX</code>, <code>LDIRX</code>, <code>LDDRX</code> affect the flags similarly to <code>LDI</code>, <code>LDD</code>, <code>LDIR</code> and <code>LDDR</code>. 2) <code>ADD HL,A</code>, <code>ADD DE,A</code> and <code>ADD BC,A</code> most probably always reset the carry flag.


=== Errata ===
=== Errata ===
Line 3,277: Line 1,118:


2022-01-11: The previous versions of this page didn't match what was [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).
2022-01-11: The previous versions of this page didn't match what was [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).
2021-09-16: The Z80N-specific instructions <code>ADD HL,A</code>, <code>ADD DE,A</code> and <code>ADD BC,A</code> '''do not preserve carry flag''', but change it to an undefined value (confirmed by the tests by Ped on the core 3.1.5). (Note: That behaviour could change in the following cores)

Latest revision as of 14:39, 7 October 2025

This is a general list of Z80 and Z80N instructions with descriptions. The instructions specific to Z80N have the encodings described first.

For a table of summaries without additional descriptions see the Z80 Instruction Table. There's also an external Z80N opcode value matrix on specnext.dev.

Z80N instructions opcodes

This is a table of the instructions and the encodings of all Next-specific Z80 instructions:

Instruction Encoding (2-4 bytes) (hex) T-States Description 4 letter
SWAPNIB ED 23 8 Swap the nibbles (4-bits) of A SWAP
MIRROR A ED 24 8 Mirror bits 0..7 to 7..0 of A MIRR
TEST $im8 ED 27 value 11 Change flags as AND A but A stays unaffected TEST
BSLA DE,B ED 28 8 Shift left DE for B bits BSLA
BSRA DE,B ED 29 8 Shift right signed DE for B bits BSRA
BSRL DE,B ED 2A 8 Shift right DE for B bits BSRL
BSRF DE,B ED 2B 8 Shift right DE, filling 1 for B bits BSRF
BRLC DE,B ED 2C 8 Rotate left DE for B bits BRLC
MUL D,E ED 30 8 Multiply D with E, result in DE MUL
ADD HL,A ED 31 8 Add unsigned A to HL ADD
ADD DE,A ED 32 8 Add unsigned A to DE ADD
ADD BC,A ED 33 8 Add unsigned A to BC ADD
ADD HL,$im16 ED 34 low high 16 Add a constant to HL ADD
ADD DE,$im16 ED 35 low high 16 Add a constant to DE ADD
ADD BC,$im16 ED 36 low high 16 Add a constant to BC ADD
PUSH $im16 ED 8A high low 23 Push a constant PUSH
OUTINB ED 90 16 OUTI, but don't change B OTIB
NEXTREG $im8,$im8 ED 91 register value 20 Write v to Next register r NREG
NEXTREG $im8,A ED 92 register 17 Write A to Next register r NREG
PIXELDN ED 93 8 HL as a pixel address moved one line down PXDN
PIXELAD ED 94 8 HL := as ULA pixel address from D==Y E==X PXAD
SETAE ED 95 8 Get A as a mask for ULA pixel from E STAE
JP (C) ED 98 13 IN (C) then jump to a 64 byte section JP
LDIX ED A4 16 Extended LDI byte copy LDIX
LDWS ED A5 14 Byte copy as for Layer 2 LDWS
LDDX ED AC 16 Extended LDD byte copy LDDX
LDIRX ED B4 21/16 Extended LDIR LIRX
LDPIRX ED B7 21/16 Byte copy as for a pattern fill LPRX
LDDRX ED BC 21/16 Extended LDDR LDRX

More details and the explanations of all Z80 instructions implemented in the Next Z80 CPU follow.

Notes:

  • The encoding of the operand of the PUSH $im16 is unique: it is the only operand encoded as big-endian.
  • The timings (T-States) are based on some limited testing and may not be accurate.
  • The shorter aliases of the official mnemonics (the 4-letter column) are those suggested in an initiative led by Matt Davies, the author of Odin assembler, editor and debugger tool for ZX Next.
  • A relevant early source for this table could be a Christmas 2018 edit of a comment in a discussion of an issue 312 of z88dk.

Notation

  • In the descriptions any 8-bit register means A, B, C, D, E, H, and L. The registers named F, I and R aren't a part of this set even if they are technically 8 bit registers. Additionally, IXH, IXL, IYH, IYL, which are the high and low byte parts of IX and IY, can be used in some of the instructions as 8-bit registers although this wasn't documented for 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 - - - - - - DE:=DE<<(B&31) 8
BSRA DE,B - - E - - - - - - DE:=signed(DE)>>(B&31) 8
BSRL DE,B - - E - - - - - - DE:=unsigned(DE)>>(B&31) 8
BSRF DE,B - - E - - - - - - DE:=~(unsigned(~DE)>>(B&31)) 8
BRLC DE,B - - E - - - - - - DE:=DE<<(B&15) OR DE>>(16-B&15) 8
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 and TBBlue Register Access.

A note on some Z80-N specific observations

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.

2025-01-25: Testing 3.02.x 1) LDIX, LDDX, LDIRX, LDDRX affect the flags similarly to LDI, LDD, LDIR and LDDR. 2) ADD HL,A, ADD DE,A and ADD BC,A most probably always reset the carry flag.

Errata

This section lists the changes of the specification of the behavior of Z80N instructions, compared to the previous content of this wiki page.

2022-01-11: The previous versions of this page didn't match what was 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).