[RTLLM-p006] Arithmetic/Substractor/sub_64bit
64 位元有號減法器與 Overflow 偵測
題目說明
請設計一個名為 sub_64bit 的 Verilog 模組,實作一個具有溢位檢查功能的 64 位元有號減法器。
模組需要計算:
result = A - B
其中:
AB
皆為使用二補數表示法的 64 位元有號整數。
除了輸出減法結果外,還需要判斷此次運算是否造成 signed overflow。
模組介面
| 埠 | 方向 | 位元寬度 | 描述 |
|---|---|---|---|
A |
input | 64 | 第一個有號運算元 |
B |
input | 64 | 第二個有號運算元 |
result |
output | 64 | A-B 的結果 |
overflow |
output | 1 | 溢位旗標 |
設計要求與提示
- 模組名稱: 必須為
sub_64bit - 執行:
A - B
- 使用二補數運算。
- 偵測 signed overflow。
Overflow 條件
減法:
A - B
可能產生兩種 overflow:
1. 正數減負數結果變負
例如:
MAX_INT - (-1)
結果超出最大正數範圍。
條件:
A[63] = 0
B[63] = 1
result[63] = 1
2. 負數減正數結果變正
例如:
MIN_INT - 1
結果超出負數範圍。
條件:
A[63] = 1
B[63] = 0
result[63] = 0
當發生上述情況:
overflow = 1
否則:
overflow = 0
程式設計模板
module sub_64bit (
input [63:0] A,
input [63:0] B,
output [63:0] result,
output overflow
);
// 在此處填寫您的程式碼
endmodule
評論