I was intrigued coming across the extra rotate, shift, set and reset instructions you get when you add the DD CB and FD CB byte prefixes to normally unused opcodes... I'm talking about the instructions you get that put the result of the memory operation in an 8 bit register 'for free'
like:
RL (IX+0)->A takes 23T
which I believe does the same as:
RL (IX+0)
LD A,(IX+0) which takes 23+19 = 42T
so saving 3 bytes and 19T states - quite a saving.
I like the idea of the savings gained from these undocumented instructions but the index registers are hardly known for being fast anyway, and are somewhat bloated compared to the HL equivalent (though admittedly easier to code with when handling data structures).
I'd be interested if anyone's found any practical benefit for this type of undocumented instruction - like a piece of code designed around these instructions to take advantage of them - and do all Z80s support these instructions?
"Undocumented" Z80 index register instructions
- Lethargeek
- Manic Miner
- Posts: 743
- Joined: Wed Dec 11, 2019 6:47 am
Re: "Undocumented" Z80 index register instructions
not the same, as the value of A will be the original byte rotated even if IX was pointing to ROM, so it's more like "ld a,(ix+):rla:ld (ix+),a"
anyway, i've never once seen these used in the actual code and i've seen quite a lot of Spectrum game code (mostly gfx routines but nonetheless)
Re: "Undocumented" Z80 index register instructions
I wonder if there is ani emulator that is counting statistics of decoded instructions.
Proud owner of Didaktik M
Re: "Undocumented" Z80 index register instructions
I used one of those instructions to save a byte in a 64-column print routine. Since I was only operating on temporary strings, it didn't matter that the character byte in memory was corrupted.
Re: "Undocumented" Z80 index register instructions
Interesting. Hmm, so these instructions don't seem to offer as much practical benefit as first hoped.
Come to think of it, personally I don't think any of the "undocumented instructions" have been all that useful ..except for being able to reference IX,IY as their 8 bit halves.
Come to think of it, personally I don't think any of the "undocumented instructions" have been all that useful ..except for being able to reference IX,IY as their 8 bit halves.
Cosmium
https://cosmium.itch.io/
https://cosmium.itch.io/
Re: "Undocumented" Z80 index register instructions
Interesting - never heard of this particular set of hidden instructions. Does the result always go into A?
- arkannoyed
- Manic Miner
- Posts: 438
- Joined: Mon Feb 05, 2018 9:56 am
- Location: Northamptonshire
Re: "Undocumented" Z80 index register instructions
I think they can be applied to all the 8 bit registers.
- Lethargeek
- Manic Miner
- Posts: 743
- Joined: Wed Dec 11, 2019 6:47 am
Re: "Undocumented" Z80 index register instructions
SLL (i prefer SLI designation meaning "shift left and increment") is useful for shifting sprite masks and marking the end of bitstreamCosmium wrote: ↑Tue Apr 28, 2020 6:20 am Interesting. Hmm, so these instructions don't seem to offer as much practical benefit as first hoped.
Come to think of it, personally I don't think any of the "undocumented instructions" have been all that useful ..except for being able to reference IX,IY as their 8 bit halves.
OUT(C),0 might be useful for beeper sound or for some tight border effects
- Ast A. Moore
- Rick Dangerous
- Posts: 2641
- Joined: Mon Nov 13, 2017 3:16 pm
Re: "Undocumented" Z80 index register instructions
SLL is quite useful, as well. So are (in rarer cases) IN (C) and OUT (C),0.
Indeed. The only exceptions are, obviously, the index register halves themselves.
Every man should plant a tree, build a house, and write a ZX Spectrum game.
Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
- Turtle_Quality
- Manic Miner
- Posts: 506
- Joined: Fri Dec 07, 2018 10:19 pm
Re: "Undocumented" Z80 index register instructions
Here's a link documenting the undocumented
http://www.z80.info/z80undoc.htm
More info can be found here https://www.z80cpu.eu/mirrors/www.z80.info/, for example a table of opcodes timings that includes the undocumented instructions
http://www.z80.info/z80undoc.htm
More info can be found here https://www.z80cpu.eu/mirrors/www.z80.info/, for example a table of opcodes timings that includes the undocumented instructions
Definition of loop : see loop