Yes, the Z-80 has block move instructions for memory, I/O and searching. These were additions made by Zilog and were more definitely not available on the Intel 8080.
Nominally the Z-80 accesses devices though a different I/O address space using special IN
and OUT
instructions. There's nothing stopping the Z-80 from using memory mapped devices but the block move instructions continue this separation of memory and I/O.
The two block memory move instructions are LDIR
and LDDR
short for "LoaD, Increment and Repeat" and "LoaD, Decrement and Repeat" respectively. Like TFM
a fixed register (BC
) is used to track the count of bytes moved. Unlike TFM
the source and destinations addresses always use HL
and DE
respectively and the instructions are safely interruptable.
Those familiar with TFM
can read them instructions as follows:
LD BC,256 LDW #256
LDIR TFM HL+,DE+
LDDR TFM HL-,DE-
A zero count in BC
will transfer 65536 bytes.
For I/O ports there is OTIR
/OTDR
for outputting data and INIR
/INDR
for inputting data. For those instructions C
register is used as the I/O port address and B
register tracks the byte count. So unlike TFM
these instructions can only output 1 to 256 bytes at a time.
Their relationship to TFM
is not exact because of the separate I/O address space but it is roughly as follows:
OTIR TFM HL+,C
OTDR TFM HL-,C
INIR TFM C,HL+
INDR TFM C,HL-
I won't go into the CPIR
and CPDR
instructions here as they are only similar to TFM
in that they repeat.
There are a few details I glossed over that I'll cover now.
Technically the I/O instructions work on port BC
, not just C
. This is a bit odd as the changing byte count in B
means the port number is changing as data is output. Some Z-80 systems simply ignore the upper 8 bits of the port address and act as if there are only 256 ports. In other words, the effective operation of the instructions depends on system architecture and not just the Z-80 itself.
All the Z-80 block move instructions come in non-repeating form. They do exactly the same operation and the repeating forms including decrementing BC
(or B
) register but do not repeat themselves until BC
(or B
) is zero.
Repeating Single
LDIR LDI
LDDR LDD
INIR INI
INDR IND
OTIR OUTI
OTDR OUTD
They do set flags to indicate if BC
or B
has reached zero so are useful when you wish to do the block copy operation but with some extra checks along the way. As they are all 5 T-States faster than the repeat forms they can also be used to unroll the operation for faster execution.
Finally it should be noted that these instructions are optimized for program compactness and programmer convenience. At 21 T-States per byte copied they're not particularly fast.