Challenge - 5 Problems
Subtractor Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of 4-bit subtractor module
What is the output of the following 4-bit subtractor module when inputs A = 4'b1010 and B = 4'b0011?
Verilog
module subtractor_4bit(input [3:0] A, input [3:0] B, output [3:0] Diff, output Borrow); assign {Borrow, Diff} = A - B; endmodule
Attempts:
2 left
💡 Hint
Remember that Borrow is the carry out bit from subtraction in Verilog when using the assign with concatenation.
✗ Incorrect
The subtraction 1010 (decimal 10) minus 0011 (decimal 3) equals 0111 (decimal 7) with no borrow (Borrow=0).
🧠 Conceptual
intermediateUnderstanding borrow in binary subtraction
In a 1-bit subtractor, what does the borrow output represent?
Attempts:
2 left
💡 Hint
Think about what happens when you subtract a larger bit from a smaller bit in binary.
✗ Incorrect
Borrow signals that the current bit of the minuend is less than the subtrahend bit, so borrowing from the next higher bit is needed.
🔧 Debug
advancedIdentify the error in this subtractor module
What error will occur when compiling this Verilog subtractor module?
Verilog
module subtractor(input a, input b, output diff, output borrow); assign diff = a ^ b; assign borrow = ~a & b; endmodule
Attempts:
2 left
💡 Hint
Check each line carefully for missing punctuation.
✗ Incorrect
The line assigning borrow is missing a semicolon at the end, causing a syntax error.
📝 Syntax
advancedCorrect syntax for 1-bit full subtractor
Which option correctly implements a 1-bit full subtractor in Verilog?
Attempts:
2 left
💡 Hint
Recall the borrow output formula for a full subtractor: bout = (~a & b) | ((~a | b) & bin)
✗ Incorrect
Option A correctly implements the borrow logic for a full subtractor. Other options have incorrect boolean expressions.
🚀 Application
expertNumber of bits in output of subtractor with borrow
If you design an 8-bit subtractor module in Verilog that outputs the difference and borrow, how many bits should the borrow output have and why?
Attempts:
2 left
💡 Hint
Think about how borrow is represented in multi-bit subtraction.
✗ Incorrect
The borrow output is a single bit indicating if the overall subtraction resulted in a borrow from a higher bit beyond the most significant bit.
