[RTLLM-p015] Arithmetic/Comparator/comparator_4bit 的題解


記住 在沒有思路時使用題解,不要從它複製貼上程式碼。請尊重題目和題解的作者。
在真正解決題目之前提交題解的程式碼是可以封禁的罪行。

作者: m1145505

module comparator_4bit(
    input [3:0] A,   // First 4-bit input operand
    input [3:0] B,   // Second 4-bit input operand
    output A_greater, 
    output A_equal,   
    output A_less     
);

    wire [3:0] diff;  
    wire cout;       

    assign {cout, diff} = A - B;

    // A > B: if there's no borrow and the difference isn't zero
    assign A_greater = (~cout && diff != 4'b0000);

    assign A_equal = (A == B);

    assign A_less = cout;

endmodule

評論

目前沒有評論。