Question 2.1: For a half adder, sum and carry can be found using the equat...

For a half adder, sum and carry can be found using the equations sum = x XOR y ; carry = x AND y. What is wrong with the following code for a half adder that must add if add signal equals 1?

always @(*)

begin

if (add == 1)

sum = x ^ y;

carry = x & y;

end

(a) It will compile but not simulate correctly

(b) It will compile and simulate correctly but not synthesize correctly

(c) It will work correctly in simulation and synthesis

(d) It will not even compile

The blue check mark means that this solution has been answered and checked by an expert. This guarantees that the final answer is accurate.
Learn more on how we answer questions.

(a). This code will compile but will not simulate correctly. The if statement is missing begin and end. Currently only the sum is part of the if statement. The carry statement will get executed regardless of the add signal. This can be corrected by adding begin and end for the if statement. That will result in correct simulation. It can still lead to latches in synthesis. Latches can be avoided by adding else clause or by initializing sum and carry to 0 at the beginning of the always statement.

Related Answered Questions