[RTLLM-p015] Arithmetic/Comparator/comparator_4bit


提交解答


分數: 5
時間限制: 2.0s
記憶體限制: 256M

作者:
題目代碼
題目類型
允許的語言
Verilog

4 位元減法式比較器

題目說明

請設計一個名為 comparator_4bit 的 Verilog 模組,使用組合邏輯比較兩個 4 位元無號二進位數 AB

模組須透過減法運算 A - B 判斷兩數的大小關係,並輸出三個互斥的比較結果:

  • A_greater:當 A > B 時為 1。
  • A_equal:當 A == B 時為 1。
  • A_less:當 A < B 時為 1。

三個輸出必須互斥,任一時刻只能有一個輸出為 1。


模組介面

方向 位元寬度 說明
A input 4 第一個 4 位元無號運算元
B input 4 第二個 4 位元無號運算元
A_greater output 1 A > B 時輸出 1
A_equal output 1 A == B 時輸出 1
A_less output 1 A < B 時輸出 1

設計要求

  1. 模組名稱必須為 comparator_4bit
  2. 使用組合邏輯完成設計。
  3. 使用減法結果判斷 AB 的關係。
  4. 減法必須保留額外的借位資訊。
  5. A_greaterA_equalA_less 必須互斥。
  6. 輸入視為無號數。

比較規則

A - B 發生借位時:

A_less = 1

當減法結果為零時:

A_equal = 1

當沒有借位且減法結果不為零時:

A_greater = 1

程式設計模板

module comparator_4bit (
    input  [3:0] A,
    input  [3:0] B,
    output       A_greater,
    output       A_equal,
    output       A_less
);

    // Write your code here

endmodule

評論

目前沒有評論。