Question 2.2: What is wrong with the following code for a half adder that ...

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;

else

sum = 0;

carry = 0;

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.

(d). This code will not even compile due to the missing begin and end inside the if statement. When the compiler gets to the else, it finds that the corresponding if statement is missing. Both if and else clauses need begin and end. Once that is corrected, both simulation and synthesis will work correctly.

Related Answered Questions