Download Print this page

ZiLOG Z80 Handbook page 139

Hide thumbs Also See for Z80:

Advertisement

placement can be added to the pointer to access data within a
"block" of 256 bytes, starting from the location the index register
points to -128 bytes and ending with the index register +127 bytes
as shown in Fig. 10-1.
IX OR IY
LOCN-128
LOCN-2
LOCN-1
LOCN+O
LOCN+1
LOCN+2
LOCN+127
Fig. 10-1. Index register block access.
Suppose that the requirement was to store the A, B, C, and D
registers into locations BLOCK - 4, BLOCK, BLOCK + 4, and
BLOCK + 8, respectively. The following instructions would accom-
plish the task:
LD IX,BLOCK
POINT TO BLOCK
LD (IX - 4),A
STORE A INTO BLOCK - 4
LD (IX + 0),B
STORE B INTO BLOCK
LD (IX + 4),C
STORE C INTO BLOCK + 4
LD (IX + 8),D
STORE D INTO BLOCK + 8
The displacements in the third byte of the instruction would be
-4, 0, 4, and 8, respectively. Here the process of storing data within
the 256-byte block was made much more efficient than the example
using the HL register pair pointer. Or was it? Let's compare the rel-
ative sizes and timing of the two programs. The first program using
the HL registers used four three-byte instructions (LD HL,STORX)
and four 1-byte instructions (LD (HL),D) for a total of sixteen
bytes and 17 microseconds. The program above used five 3-byte in-
structions for a total fifteen bytes and 22.5 microseconds! It appears
that the first implementation was faster and only slightly more ex-
pensive in terms of memory usage than the second. This is only one
example of how execution speeds and memory storage requirements
must be compared between one method of implementation and an-
other if one is concerned about program efficiency.
148

Advertisement

loading
Need help?

Need help?

Do you have a question about the Z80 and is the answer not in the manual?

Questions and answers