LZ-Adv: cpir counting help


[Prev][Next][Index][Thread]

LZ-Adv: cpir counting help



I am having some problems with the instruction CPIR in my programs. I am 
just a little messed up. In the Z80 instruction set summary it said that 
the instruction CPI does this: "A-(HL),HL=HL+1,BC=BC-1"
for the instructio CPIR it said: "CPI till A=(HL) or BC=0"
this is where I have my problem. Say I wanted to search through the text 
memory and find the address of the first 00. This is what I would type:


sub a
ld hl,TEXT_MEM
ld bc,168
cpir


right? Well would HL be the address of the first 00 or would it be 1 
AFTER the first zero? Here is another example:
this is the memory I want to search through:


80DF=04
80E0=02
80E1=A2
80E2=34
80E3=00-
80E4=23
80E5=00
80E6=E1
BC=4
I want to find the address of the first zero in the first 8 bytes, AND 
how far away it is from where I started (BC).
This is what I would type:


sub a
ld	hl,80DFh
ld	bc,0008
cpir


would HL be 80E3 or 80E4 or what??? would BC 3,4,or 5???
I can't figure out the order in which the parts of the CPIR instruction 
are executed. Does it test if A=(HL) first, or does it decrement HL and 
BC and then test it???
I really need to get this straightened out before I continue to use it 
in my programs.


<pre>
-- 
Thayne Miller
yomaster@geocities.com
YoMaster's Domain:
http://www.geocities.com/SiliconValley/Heights/5084
</pre>