[RTLLM-p014] Arithmetic/Comparator/comparator_3bit
3 位元比較器
題目說明
請設計一個名為 comparator_3bit 的 Verilog 模組,用於比較兩個 3 位元無號二進位數 的大小。
模組接收兩個 3 位元輸入 A 與 B,並輸出三個互斥(Mutually Exclusive)的比較結果:
A_greater:當A > B時輸出為 1。A_equal:當A == B時輸出為 1。A_less:當A < B時輸出為 1。
任一時刻,三個輸出中僅有一個會為 1。
模組介面 (Module Interface)
| 埠 (Port) | 方向 (Direction) | 位元寬度 (Width) | 描述 (Description) |
|---|---|---|---|
A |
input | 3 | 第一個 3 位元輸入 |
B |
input | 3 | 第二個 3 位元輸入 |
A_greater |
output | 1 | 當 A > B 時輸出為 1 |
A_equal |
output | 1 | 當 A == B 時輸出為 1 |
A_less |
output | 1 | 當 A < B 時輸出為 1 |
設計要求
- 模組名稱必須為
comparator_3bit。 - 使用組合邏輯(Combinational Logic)完成設計。
- 三個輸出必須互斥,同一時間只能有一個輸出為 1。
- 不可產生不合法的輸出組合。
程式設計模板 (Code Template)
module comparator_3bit(
input [2:0] A,
input [2:0] B,
output A_greater,
output A_equal,
output A_less
);
// Write your code here
endmodule
評論