Search code examples
assemblyz80

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

  • 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.