This the multi-page printable view of this section.Click here to print.
The Block copy instructions allow for data to be moved around in memory.
The programmer needs to configure the 16 bit registers to define the properties of the move:
HL
is the source address to copy from;
DE
is the destination address to copy to;
BC
is the number of bytes to copy.
\(\begin{rcases} \begin{rcases} HL \longleftarrow HL+1 \\ DE \longleftarrow DE+1 \end{rcases} \text{ if } D = 0\\ \begin{rcases} HL \longleftarrow HL-1 \\DE \longleftarrow DE-1 \end{rcases} \text{ if } D=1 \\BC \longleftarrow BC-1 \end{rcases} \text{repeat while } \begin{cases} L=1\\BC \not = 0 \end{cases}\)
7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | |
---|---|---|---|---|---|---|---|---|
1 | 1 | 1 | 0 | 1 | 1 | 0 | 1 | ED |
1 | 0 | 1 | L | D | 0 | 0 | 0 |
D 0=Increment, 1=Decrement HL
after each iteration.
L If set then if \( BC \not = 0 \) at the end if the instruction then \( PC \longleftarrow PC - 2 \)
so that the instruction is repeated.
If BC=0 at start of a repeatable instruction then 65536 iterations will occur.
The LD*
instructions then perform the equivalent of the following:
(HL)
to (DE)
BC
by oneHL
and DE
are either incremented (for LDI/LDIR) or decremented (for LDD/LDDR) by
one.
LDIR
and LDDR
instructions will loop back to step one if \( BC \not = 0 \)For the non-repeating instructions, they take 16(4,4,3,5) T-States to execute.
For the repeating instructions, they take either 21(4,4,3,5,5) T-States when they loop and 16(4,4,3,5) T-States when terminating.
Also note, that for these instructions the timing is for each iteration, not for the entire run. So if LDIR is run with BC=4 then the number of T-States for the entire operation would take 79(21+21+21+16) T-States.
Flags |
| ||||||||
---|---|---|---|---|---|---|---|---|---|
h | Reset | ||||||||
p/v | Non-repeating: Set if BC-1 != 0, otherwise reset Repeating: N/A as BC=0 after instruction completes |
Increment | Decrement | |
---|---|---|
Single Copy |
LDI
EDA0216 |
LDD
EDA8216 |
Repeat Copy |
LDIR
EDB0221 |
LDDR
EDB8221 |
Instruction
Opcode hexSize bytesCycle count
| Memory |
The Block compare instructions allow for data to be searched for in memory.
The programmer needs to configure the following registers to define the properties of the search:
HL
is the source address to search from;
BC
is the number of bytes to search.
A
is set to the value to search for.
\(\begin{rcases} A-(HL) \\ HL \longleftarrow HL+1 \text{ if } D = 0\\ HL \longleftarrow HL-1 \text{ if } D=1 \\BC \longleftarrow BC-1 \end{rcases} \text{repeat while } \begin{cases} L=1\\A \not = (HL)\\BC \not = 0 \end{cases}\)
7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | |
---|---|---|---|---|---|---|---|---|
1 | 1 | 1 | 0 | 1 | 1 | 0 | 1 | ED |
1 | 0 | 1 | L | D | 0 | 0 | 1 |
D 0=Increment, 1=Decrement HL
after each iteration.
L If set then if \( BC \not = 0 \) at the end if the instruction then \( PC \longleftarrow PC - 2 \)
so that the instruction is repeated.
If BC=0 at start of a repeatable instruction then 65536 iterations will occur.
The CP*
instructions compare memory against the Accumulator
A
and content of memory in (HL)
to set/clear Z flag
BC
by oneHL
is either incremented (for CPI/CPIR) or decremented (for CPD/CPDR) by one.For the non-repeating instructions, they take 16(4,4,3,5) T-States to execute.
For the repeating instructions, they take either 21(4,4,3,5,5) T-States when they loop and 16(4,4,3,5) T-States when terminating.
Also note, that for these instructions the timing is for each iteration, not for the entire run. So if LDIR is run with BC=4 then the number of T-States for the entire operation would take 79(21+21+21+16) T-States.
Flags |
| ||||||||
---|---|---|---|---|---|---|---|---|---|
s | Set if result is negative | ||||||||
z | Set if A = (HL) | ||||||||
h | Borrow from bit 4, otherwise reset | ||||||||
p/v | Non-repeating: Set if BC-1 != 0, otherwise reset Repeating: N/A as BC=0 after instruction completes |
Increment | Decrement | |
---|---|---|
Single Search |
CPI
EDA1216 |
CPD
EDA9216 |
Repeat Search |
CPIR
EDB1221 |
CPDR
EDB9221 |
Instruction
Opcode hexSize bytesCycle count
| Memory |