0
\$\begingroup\$

We have Z80. This processor do following operation in U2:
200 - (-56). What will be values of following register flags:
S - the oldest bit of result
V - overflow
C - carry
Z - result is zero.

Now, we know that in U2 we have: 200-(-56) = 200+56 = 00000000(U2) Then, I know that:
S = 0
V = 1
Z = 1.
However, when it comes to C I am not sure about it. Although, we see the carried bit, I think that in U2 we can ignore it, so C = 0.
Am I right ?

\$\endgroup\$
  • 1
    \$\begingroup\$ I bet it's not currying (which you should know, as your name suggests), but carry. I have no idea about this architecture, but usually it is set when the addition is resulting in an overflow. \$\endgroup\$ – Eugene Sh. Aug 23 '16 at 18:10
  • \$\begingroup\$ According to this C=1 and rest of flags I correctly set. Yeah ? z80.info/z80sflag.htm \$\endgroup\$ – user119974 Aug 23 '16 at 18:12
  • \$\begingroup\$ What is 'U2'? I don't recognise that notation. Is 'U2' an unsigned double-byte? In which case 200+56 = 0000 0001 0000 0000. Otherwise, i agree with @EugeneSh, the carry bit 'does what it says on the can' and it holds the bit carried out of the top of the 8-bit add (a Z80 is a mostly 8bit CPU). Also please correct 'curried' to carried, the C bit os the carry bit. \$\endgroup\$ – gbulmer Aug 23 '16 at 18:37
  • \$\begingroup\$ The Z80 V and C flags are thoroughly explained at : stackoverflow.com/questions/8034566/… \$\endgroup\$ – Peter Smith Aug 24 '16 at 10:14
1
\$\begingroup\$

I don't know what U2 is.

In 8-bit binary,

      200                          -> 1100 1000
      -56 -> 200                   -> 1100 1000
   -(-56) -> 56                    -> 0011 1000
200-(-56) -> 1100 1000 + 0011 1000 -> 0000 0000 with carry flag
200-(-56) -> 1100 1000 - 1100 1000 -> 0000 0000 with no carry flag

The expression 200 - (-56) is problematic for 8-bit. 200 cannot be represented as an 8-bit signed number. While -56 cannot be represented as an unsigned number. That leads to the problem of interpreting what the expression really means. Depending on the context of the actual codes:

If the codes had been compiled to an 8-bit add then: S = 0, V = 0, C = 1, Z = 1.

If the codes had been compiled to an 8-bit subtract then: S = 0, V = 0, C = 0, Z = 1.

For 16-bit operation, it is simple: S = 0, V = 0, C = 0, Z = 0.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy