[RTLLM-p012] Arithmetic/Divider/div_16bit


提交解答


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

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

16 位元組合式除法器

題目說明

請設計一個名為 div_16bit 的 Verilog 模組,實作一個 16 位元無號組合式除法器(Unsigned Combinational Divider)

模組接收一個 16 位元被除數 A 與一個 8 位元除數 B,並輸出:

  • 商(Quotient)result
  • 餘數(Remainder)odd

本題需使用組合邏輯(Combinational Logic)完成除法運算,不可使用時脈訊號或暫存器儲存運算結果。


模組介面(Module Interface)

埠(Port) 方向(Direction) 位元寬度(Width) 說明
A input 16 16 位元被除數(Dividend)
B input 8 8 位元除數(Divisor)
result output 16 除法運算所得商(Quotient)
odd output 16 除法運算所得餘數(Remainder)

設計要求

  • 模組名稱必須為 div_16bit
  • 所有輸入皆視為無號整數(Unsigned)
  • 使用組合邏輯完成運算,不可使用 Clock。
  • result 應輸出 A ÷ B 的商。
  • odd 應輸出 A ÷ B 的餘數。
  • 測試資料保證 B 不會為 0,因此不需額外處理除以 0 的情況。

提示

硬體除法通常可利用 Binary Long Division(長除法) 演算法完成。

基本流程如下:

  1. 將目前餘數左移一位。
  2. 將下一個被除數位元加入餘數最低位。
  3. 若餘數大於等於除數,則:
    • 商對應位元設為 1
    • 餘數減去除數
  4. 否則商對應位元設為 0。
  5. 重複上述步驟直到所有位元皆完成處理。

程式設計模板(Code Template)

module div_16bit(
    input  [15:0] A,
    input  [7:0]  B,
    output [15:0] result,
    output [15:0] odd
);

    // Write your code here

endmodule

評論

目前沒有評論。