Skip to main content
edited tags
Link
Became Hot Network Question
added 22 characters in body
Source Link
cjs
  • 29.5k
  • 3
  • 88
  • 220

I'd preferI need 8080 code if possiblefor some of my applications, but I'm openwilling to admire Z80 code if that can be significantly more efficient.

I'd prefer 8080 code if possible, but I'm open to Z80 code if that can be significantly more efficient.

I need 8080 code for some of my applications, but I'm willing to admire Z80 code if that can be significantly more efficient.

Source Link
cjs
  • 29.5k
  • 3
  • 88
  • 220

16-bit comparisons setting both zero and carry flag on 8080/Z80

I have a routine cpBCHL that compares the contents of BC and HL and returns the carry set appropriately:

; ---------------------------------------------------------------------- ; ♠BCHL ♣A ♡* Compare BC - HL and set "borrow" (carry): ; • BC ≥ HL ⇒ NCy (carry clear) ; • BC < HL ⇒ Cy (carry set) cpBCHL ld a,c ; LSB sub a,l ; affects carry ld a,b ; MSB sbc a,h ; use and affect carry ret 

And I have a very similar routine, that compares the two and returns the zero flag set based on whether they're equal or not:

; ---------------------------------------------------------------------- ; ♠BCHL ♣A ♡* Compare BC to HL and set Z flag (1=equal, 0=not equal) eqBCHL ld a,c ; LSB sub a,l ret NZ ld a,b ; MSB sbc a,h ret 

Is there some compact way to combine these two so I can have one routine that sets both Z and Cy appropriately?

I'd prefer 8080 code if possible, but I'm open to Z80 code if that can be significantly more efficient.

I'm more concerned about size than speed here.