0

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
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Kir
  • 11
  • 3

1 Answers1

3

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.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
prl
  • 11,716
  • 2
  • 13
  • 31
  • Small typo: the way it's written, those would **re**set carry – Zeda May 08 '22 at 15:39
  • 1
    subtraction sets carry if there was a borrow, so `x - y` sets carry if y > x. For what it's worth, I do have a live Z80 that I tried `3E43D6449F` (`ld a,$43 \ sub $44 \ sbc a,a`; the `sbc a,a` returns A as $FF if carry was set, $00 if carry was reset) and it returned $FF in A indicating the subtraction set carry. – Zeda May 08 '22 at 21:47
  • I used sub in my code for the actual comparison. The `sbc a,a` was just to get the state of the carry flag in A. If carry is reset, `sbc a,a` ==> A - A - 0 = $00 If carry is set, `sbc a,a` ==> A - A - 1 = $FF – Zeda May 08 '22 at 22:11
  • 2
    @Zeda, thanks. I corrected the answer. Thanks for your help. I'll have to make a note in my book that it's wrong. – prl May 08 '22 at 22:37