What is the output of this 2-bit comparator module when inputs A=2'b10 and B=2'b01?
module comparator_2bit(input [1:0] A, input [1:0] B, output reg A_gt_B); always @(*) begin if (A > B) A_gt_B = 1'b1; else A_gt_B = 1'b0; end endmodule
Compare the binary values 2'b10 (decimal 2) and 2'b01 (decimal 1).
Since 2 is greater than 1, the output A_gt_B will be 1'b1.
What is the output of this 4-bit equality comparator when inputs A=4'b1010 and B=4'b1010?
module equality_comparator_4bit(input [3:0] A, input [3:0] B, output reg equal); always @(*) begin if (A == B) equal = 1'b1; else equal = 1'b0; end endmodule
Check if both 4-bit inputs are exactly the same.
Both inputs are 4'b1010, so equal is set to 1'b1.
What error will this 3-bit comparator code produce?
module comparator_3bit(input [2:0] A, input [2:0] B, output reg A_lt_B); always @(*) begin if (A < B) A_lt_B = 1'b1; else A_lt_B = 1'b0; end endmodule
Check the syntax of the if statement in Verilog.
The if condition must be enclosed in parentheses. Missing parentheses cause a syntax error.
What is the output of this signed 4-bit comparator when A = -3 (4'b1101) and B = 2 (4'b0010)?
module signed_comparator(input signed [3:0] A, input signed [3:0] B, output reg A_gt_B); always @(*) begin if (A > B) A_gt_B = 1'b1; else A_gt_B = 1'b0; end endmodule
Remember to interpret inputs as signed numbers.
-3 is less than 2, so A_gt_B is 1'b0.
How many output signals are needed to fully represent the comparison results of a 3-input comparator (inputs A, B, C) that indicates which input is the greatest?
Think about how to show which input is the greatest clearly and simply.
Each output corresponds to one input and is high if that input is the greatest. This requires 3 outputs.
