[RTLLM-p013] Arithmetic/Divider/radix2_div
Radix-2 8 位元除法器
題目說明
請設計一個名為 radix2_div 的 Verilog 模組,實作一個 Radix-2(基數為 2)序向除法器(Sequential Divider)。
模組支援 8 位元有號(Signed) 與 8 位元無號(Unsigned) 除法運算。
當輸入有效訊號 opn_valid 為 1 時,模組開始一次新的除法運算。完成運算後,將商與餘數輸出至 result,並將 res_valid 拉高表示輸出有效。
模組介面(Module Interface)
| 埠 (Port) | 方向 | 位元寬度 | 說明 |
|---|---|---|---|
clk |
input | 1 | 系統時脈 |
rst |
input | 1 | 高有效重置信號 |
sign |
input | 1 | 除法模式,1 表示有號除法,0 表示無號除法 |
dividend |
input | 8 | 被除數 |
divisor |
input | 8 | 除數 |
opn_valid |
input | 1 | 輸入資料有效 |
res_ready |
input | 1 | 接收端已準備好接收結果 |
res_valid |
output | 1 | 輸出結果有效 |
result |
output | 16 | 高 8 位元為餘數,低 8 位元為商 |
設計要求
- 模組名稱必須為
radix2_div。 - 使用同步時序電路完成設計。
- 每次收到
opn_valid = 1時開始新的除法運算。 - 除法完成後,
res_valid應輸出為 1。 - 當
res_valid與res_ready同時為 1 時,本次結果視為已被接收,模組即可接受下一筆輸入。 result[15:8]為餘數(Remainder)。result[7:0]為商(Quotient)。- 測試資料保證
divisor不會為 0。
有號除法說明
當 sign = 1 時:
- 被除數與除數皆視為 8 位元二補數(Two's Complement)。
- 商的正負號依照一般整數除法規則決定。
- 餘數與被除數具有相同符號。
例如:
| Dividend | Divisor | Quotient | Remainder |
|---|---|---|---|
| -100 | 10 | -10 | 0 |
| 100 | -10 | -10 | 0 |
| -100 | -10 | 10 | 0 |
程式設計模板
module radix2_div(
input clk,
input rst,
input sign,
input [7:0] dividend,
input [7:0] divisor,
input opn_valid,
input res_ready,
output res_valid,
output [15:0] result
);
// Write your code here
endmodule
評論