Although the processing above will certainly work, it is probably
best to process the string data by other means, especially since inter-
rupts will cause catastrophic results. The block instructions imple-
mented in the Z-80 will permit processing of string data in a much
cleaner fashion.
BLOCK TRANSFER INSTRUCTIONS
The Block Transfer instructions in the Z-80 offer a means to move
up to 64-K bytes of data automatically or semi-automatically from
one area of memory to another. The ground rule for moving data is
the following:
NEVER MOVE LARGE BLOCKS OF DATA FROM ONE AREA
OF MEMORY TO ANOTHER UNLESS UNAVOIDABLE!
There are many ways to avoid large data movements. Data should
be input or output directly to a buffer in which they can be proc-
essed. Tables can be set up properly to avoid reformatting of data.
Programming structures such as linked lists may be employed in-
stead of contiguous tables. The primary reason for avoiding block-
data transfers is the enormous amount of time that they require. To
move 1000 bytes of data at 10 microseconds per byte requires 10
milliseconds or 1/100 of a second. Although the time required per
byte in the Z-80 is about one third of this, block movements still take
large amounts of time in comparison to other program operations.
With the above proviso in mind, let us see how the block transfer
instructions in the Z-80 can be set up. The first of these is the LDI
instruction. The LDI requires that the HL register pair points to the
source data block and that the DE register pair points to the desti-
nation data block. The BC register pair contains a byte count. To
transfer 100H bytes of data from a data block starting at location
100011 to a data block starting at 2000H, the following code could
be employed.
LD HL,1000H
SET UP SOURCE PNTR
LD DE,2000H
SET UP DEST PNTR
LD BC,100H
100 BYTES
After initialization, each time an LDI was executed a byte would
be transferred from the location pointed to by the HL to the location
pointed to by DE. The byte count in BC would then be decremented
by one. When the byte count reached zero, the PI V flag would be
reset. The P/V flag therefore can be tested to determine the end of
the transfer. The following code transfers the data:
156
Need help?
Do you have a question about the Z80 and is the answer not in the manual?
Questions and answers