z80:Opcodes:CPDR

From Learn @ Cemetech
Jump to navigationJump to search

Repeats CPD until either:

  • BC=0
  • A=HL

Syntax

No operands.

   CPDR

Effects

The carry is preserved, N is set and all the other flags are affected as defined. P/V denotes the overflowing of BC, while the Z flag is set if A=(HL) before HL is decreased.

Uses

Say you want to find the last occurrence of 124 in the valid memory space:


   LD HL,0000h
   LD BC,0000h
   LD A,124
   CPDR


Note if you used CPIR it would find the first occurrence of 124 in the valid memory space.

T-States

BC ≠ 0 and A ≠ (HL) 21
BC = 0 or A = (HL) 16

See Also

BIT,CALL,CP,CPD,CPI,CPIR,JP,JR