**Mixed Signed/Unsigned Operation** What is the decimal equivalent stored…
**Mixed Signed/Unsigned Operation** What is the decimal equivalent stored in res ? reg signed [3:0] a; reg [3:0] b; reg [4:0] res; initial begin a = -4'sd3; // 4'b1101 b = 4'd2; // 4'b0010 res = a + b; end
- -1
- 31
- 15
- 13
Correct answer
C. 15
Explanation
In Verilog, if any operand in an arithmetic operation is unsigned, the entire expression is coerced to unsigned arithmetic. Variable a (stored as 4'b1101 = 13 unsigned) is added to b (2): $13 + 2 = 15$ ( 5'b01111 ).