Home › Practice › RTL Design › ALU flags: N, Z, C, V

ALU flags: N, Z, C, V

EasyRTLcombinationalarithmeticarchitecture

After every add or subtract, a processor records a few facts about the result so that later instructions can branch on them: was it negative, was it zero, did it overflow?

Concept first. Processors keep four condition flags after an ALU operation. N (negative): the top bit of the result is 1. Z (zero): every bit of the result is 0. C (carry): the carry out of the top bit; for unsigned numbers it says the result did not fit, and for a subtraction done as "add the inverted b plus 1" the carry is 1 when there was no borrow. V (overflow): for signed numbers, two operands of the same sign gave a result of the other sign. C and V answer different questions: C is about unsigned numbers, V about two's-complement signed numbers. A number like 0111 + 0001 = 1000 is fine as unsigned (7 + 1 = 8) but overflows as signed (+7 + 1 is not -8).

What to build.

Solve in your browser →

No install and no sign-up needed. You write your answer in the editor and Nishkam checks it.

More in this track

← Credits: never overflow the receiverK-map: the hallway lamp →