Mnemonics

CPDR

Exchange, Block Transfer and Search Group
Expansion:
ComPare and Decrement Repeated
Usage:
cpdr

The CPDR operation compares the contents of the memory location addressed by the HL register pair with the Accumulator (A). After the comparison, the HL and Byte Counter (BC) Register pairs are decremented.

If decrementing allows the BC to go to 0 or if A equals the value at the memory location pointed to by HL (A = (HL)), the instruction is terminated. If BC is not 0 and A ≠ (HL), the program counter is decremented by two and the instruction is repeated.

Multi-function instruction which performs the following actions in order.

  1. CP (HL)
  2. DEC HL
  3. DEC BC (goes back to step 1 if BC is not zero)
Z80.CPU instructions
Instruction Description Opcode
CPDR Self-repeated Multi-function instruction EDB9

Example

; Example ld a, $42 ; load the value to compare into the accumulator ld hl, $4000 ; load the starting address of the memory block into HL ld bc, $1000 ; load the length of the memory block into BC cpdr ; compare (HL) with A, decrement HL, and decrement BC repeat until bc is zero jp nz, NotFound ; jump to NotFound if Non-zero flag jp z, Found ; jump to Found if a match is found (A == (HL)) NotFound: ; handle case where the value was not found nop ; no operation (placeholder for not found code) Found: ; handle case where the value was found nop ; no operation (placeholder for found code)

See also