[RTLLM-p007] Arithmetic/Multiplier/multi_8bit


提交解答


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

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

8 位元 Shift-and-Add 乘法器

題目說明

請設計一個名為 multi_8bit 的 Verilog 模組,使用 Shift-and-Add 演算法實作 8 位元乘法器。

模組輸入:

  • A:被乘數(Multiplicand)
  • B:乘數(Multiplier)

並輸出:

  • product:16 位元乘法結果

本題要求不可直接使用 Verilog 的乘法運算子:

*

而需要透過:

  • 位移(Shift)
  • 加法(Add)

完成乘法。


模組介面

方向 位元寬度 描述
A input 8 被乘數
B input 8 乘數
product output 16 乘法結果

設計要求與提示

乘法流程:

假設:

A = 被乘數
B = 乘數

逐一檢查 B 的每一個 bit:

如果:

B[i] = 1

則:

product += A << i

例如:

A × B

可以展開為:

B[0] ? A<<0 : 0
+
B[1] ? A<<1 : 0
+
B[2] ? A<<2 : 0
...

最後得到:

product = A * B

程式設計模板

module multi_8bit (
    input  [7:0] A,
    input  [7:0] B,

    output [15:0] product
);

    // 在此處填寫您的程式碼

endmodule

評論

目前沒有評論。