beautypg.com

Cpir compare, increment and repeat (byte) – Zilog Z80380 User Manual

Page 73

background image

5-39

Z380

U

SER

'

S

M

ANUAL

Z

ILOG

DC-8297-03

CPIR

COMPARE, INCREMENT AND REPEAT (BYTE)

CPIR

Operation:

Repeat until (BC=0 OR match) begin

A - (HL)
if (XM) then begin

HL(31-0)

HL(31-0) + 1

end

else begin

HL(15-0)

HL(15-0) + 1

end

BC(15-0)

BC(15-0) - 1

end

This instruction is used for searching strings of byte data. The bytes of data starting at the
location addressed by the HL register are compared with the contents of the accumulator
until either an exact match is found or the string length is exhausted becuase the BC register
has decremented to zero. The Sign and Zero flags are set to reflect the result of the
comparison. The contents of the accumulator and the memory bytes are unaffected.
Two’s complement subtraction is performed.

After each comparison, the HL register is incremented by one, thus moving the pointer to
the next element in the string. The BC register, used as a counter, is then decremented by
one. If the result of decrementing the BC register is not zero and no match has been found,
the process is repeated. If the contents of the BC register are zero at the start of this
instruction, a string length of 65,536 is indicated.

This instruction can be interrupted after each execution of the basic operation. The PC value
at the start of this instruction is pushed onto the stack so that the instruction can be resumed.

Flags:

S:

Set if the last result is negative; cleared otherwise

Z:

Set if the last result is zero, indicating a match; cleared otherwise

H:

Set if there is a borrow from bit 4 of the last result; cleared otherwise

V:

Set if the result of decrementing BC is not equal to zero; cleared otherwise

N:

Set

C:

Unaffected

Addressing

Execute

Mode

Syntax

Instruction Format

Time

Note

CPIR

11101101 10110001

(3+r)n

X