Challenge - 5 Problems
Signed vs Unsigned Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of signed addition in Verilog
What is the output of the following Verilog code snippet when adding a signed and an unsigned 4-bit number?
Verilog
module test; reg signed [3:0] a = -3; reg [3:0] b = 4'd5; wire signed [4:0] sum; assign sum = a + b; initial begin $display("sum = %d", sum); end endmodule
Attempts:
2 left
💡 Hint
Remember that signed and unsigned addition in Verilog extends the sign bit for signed numbers.
✗ Incorrect
The signed number -3 is represented as 4'b1101. Adding 5 (4'b0101) results in 2 (5'b00010) when extended to 5 bits with sign extension.
❓ Predict Output
intermediateResult of signed vs unsigned comparison
What is the output of this Verilog code comparing signed and unsigned values?
Verilog
module test; reg signed [3:0] a = -1; reg [3:0] b = 4'd15; initial begin if (a < b) $display("True"); else $display("False"); end endmodule
Attempts:
2 left
💡 Hint
Consider how Verilog treats signed and unsigned comparisons.
✗ Incorrect
In Verilog, when comparing signed and unsigned, the signed value is treated as unsigned, so -1 (4'b1111) is 15 unsigned, so a < b is false.
🔧 Debug
advancedIdentify the error in signed multiplication
Which option shows the correct way to multiply two signed 4-bit numbers in Verilog without losing sign information?
Attempts:
2 left
💡 Hint
Check the width and signedness of the result wire.
✗ Incorrect
To preserve sign and avoid overflow, the result must be signed and wide enough (8 bits) to hold the product of two 4-bit signed numbers.
📝 Syntax
advancedSyntax error in signed assignment
Which option will cause a syntax error in Verilog when assigning a signed value?
Attempts:
2 left
💡 Hint
Consider how negative values are assigned to unsigned registers.
✗ Incorrect
Assigning a negative value to an unsigned reg (option A) causes a syntax error or unexpected behavior.
🚀 Application
expertPredict the output of mixed signed/unsigned arithmetic
Given the following Verilog code, what is the output printed?
Verilog
module test; reg signed [3:0] a = -4'sd7; reg [3:0] b = 4'd9; wire signed [4:0] c; assign c = a + b; initial begin $display("c = %d", c); end endmodule
Attempts:
2 left
💡 Hint
Remember sign extension rules when adding signed and unsigned numbers.
✗ Incorrect
a is -7, b is 9, sum is 2. The signed wire c holds the correct signed result.
