'How can I get the range of numbers that would produce certain flag conditions when subtracted from 43h in Z80 assembly?

I started learning Z80 recently, but I'm struggling with flags.

I want to get the range of register "B" in Z80 assembly.

This is the problem that I faced. Register "A" is 43H (in Hexadecimal number) and I want to sub register "B" from that, doing in 8-bit subtraction.

How can I get the each range of register "B" that would produce:

  • C Flag becomes 1
  • S flag becomes 1
  • P/V flag becomes 1


Solution 1:[1]

67 - x sets C if x > 67 or x < 0.
It sets S if x > 67 or x < -60.
It sets V if x < -60.

In unsigned hexadecimal, 43h - x sets C if x > 43h.
It sets S if x > 43h and x < c4h.
It sets V if x > 7fh and x < c4h.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Peter Cordes