A85: Bug


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

A85: Bug




I ran into a bug that has me completly confused.  It's a 32-bit compare
function comparing where hl points and where de points.
ex:

Hl->11,20,0,0
De->5,0,0,0

if you call Cp32 it should return nc,nz
it returnd nc but it returns z also, but it shouldn't.
here's the code:

Cp32:
  push hl
  push de
  push af
  push bc
  ld b,3
Cp32IncLoop:            ;hl & de point to last byte
  inc de
  inc hl
  djnz Cp32IncLoop
 
  ld b,4
  ex de,hl
Cp32Loop:
  ld a,(de)
  cp (hl)               ;(hl)-(de) c:hl<hl, nc:hl>=de, z:hl=de, nz:hl!=de 
  jr nz,Cp32AllDone     ;not equal then done
  dec hl
  dec de                ;try next bytes
  djnz Cp32Loop
 
Cp32AllDone:
  pop bc
  pop af
  pop de
  pop hl
  ret 

I checked b after I called the routine and it wasn't  zero so it MUST have
exited the loop through

jr nz,Cp32AllDone

How can the flags change after that?  Everything I've read says shouldn't.

-Humberto Yeverino Jr.

"I kick ass for the Lord."

http://www.engr.csufresno.edu/~humberto/Home.html
humberto@engr.csufresno.edu

<font size=3>For browsers:<br>
<a href="http://www.engr.csufresno.edu/~humberto/Home.html">
Have a look.</a></font><br>