2
\$\begingroup\$

What are the values of the Z, V, C and N bits in the status register after the operation 1000 + 1111 for a 4-bit ALU?

\$\endgroup\$
6
  • \$\begingroup\$ @Camil Staps I tried adding the binaries together, but currently I am re reading over what each letter represents in regards to the ALU, e.g. zero flag etc \$\endgroup\$
    – Sim
    Apr 6, 2013 at 12:20
  • \$\begingroup\$ In doing this I guess the C = 1 and the and N = 0 V = 1 and Z = 1? I think that could be the answer but... any clarification on that? \$\endgroup\$
    – Sim
    Apr 6, 2013 at 12:23
  • 1
    \$\begingroup\$ The first step is: what would be the 5 bit result value? (5 bits because it makes you notice any carry) \$\endgroup\$ Apr 6, 2013 at 12:26
  • \$\begingroup\$ @WoutervanOoijen 5 bit result would be 10111 I believe \$\endgroup\$
    – Sim
    Apr 6, 2013 at 12:27
  • 1
    \$\begingroup\$ Correct, and what happens next... what do the Z, V, C and N status bits do? What are their names and how is the answer (10111) going to affect the status bits. I think you are nearly there dude... just a little more confidence and practise. \$\endgroup\$
    – Andy aka
    Apr 6, 2013 at 12:31

1 Answer 1

1
\$\begingroup\$

Let's look at bit level what happens in an addition. We're going to add 1111 to 1000.

  • First, take the Least Significant Bits (LSB, the most right). We have a 1 and a 0. Summed, that makes 1. There's no overflow here.
  • Now, the second bit. Again a 1 and a 0, so again a 1. No overflow, again.
  • The same goes for the third bit.
  • The Most Significant Bit (MSB, the most left) is different: two ones. This gives summed a 0, with an overflow. That would mean the fifth bit would get an extra 1, however, there's no fifth bit, so the overflow is placed in the carry.

The end result is thus: 0111

Now, let's have a look at the status bits.

  • Z: "Indicates that the result of an arithmetic or logical operation (or, sometimes, a load) was zero." Is 0111 zero?
  • V: "Indicates that the signed result of an operation is too large to fit in the register width using twos complement representation." Did we have an overflow?
  • C: "used to indicate when an arithmetic carry or borrow has been generated out of the most significant ALU bit position." Was the MSB carried out?
  • N: "Indicates that the result of a mathematical operation is negative." Is the result negative?
\$\endgroup\$
8
  • \$\begingroup\$ Ok, so they're all 1 then...except Z \$\endgroup\$
    – Sim
    Apr 6, 2013 at 12:41
  • \$\begingroup\$ @Sim Almost. Is the result negative? \$\endgroup\$
    – user17592
    Apr 6, 2013 at 12:43
  • \$\begingroup\$ ah crap it is isn't it! since its 10111 = -9 \$\endgroup\$
    – Sim
    Apr 6, 2013 at 12:44
  • \$\begingroup\$ @Sim the result isn't 10111. The result is 0111. Is that negative? If so, N=1. If not, N=0. \$\endgroup\$
    – user17592
    Apr 6, 2013 at 12:46
  • \$\begingroup\$ Oh right getting confused again, its just 7 which is not negative so N is 0, I just thought about that myself since 1 = true 0 = false was wondering why i thought you said it was wrong when i had it as 1, thanks alot Camil \$\endgroup\$
    – Sim
    Apr 6, 2013 at 12:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.