急求用Verilog HDL编写的32位并行乘法器程序 奖励100分!谢谢了!

来源:百度知道 编辑:UC知道 时间:2024/09/15 21:02:22
最好是程序多点的 再给写个 测试模块!谢谢了! 我这是要写毕业论文用的,老师让用Verilog 编写一个并行乘法器,可以使8位或者16位的!如果佘影您有更好的答案希望你能发给我,我愿意用我全部的分数奖励!

module MAC(out,opa,opb,clk,clr);
input clk,clr;
input [7:0] opa,opb;
output [15:0] out;
reg [15:0] out;
wire [15:0] result;

function [15:0] mult;
input [7:0] opa,opb;
reg [15:0] result;
integer i;
begin
result = opa[0]?opb : 0;
for(i=1;i<=7;i=i+1)
begin if(opa[i] == 1) result = result + (opb << 1); end
mult = result;
end
endfunction

assign result = mult(opa,opb);

always @(posedge clk or posedge clr)
begin
if(clr) out <= 0;
else out <= result;
end
endmodule

测试代码:
`timescale 1ns/1ns
`include "MAC.v"
module mac_tp;
reg [7:0] opa,opb;
reg clr,clk;
wire [15:0] out;
parameter DELY = 100;
MAC m1(out,opa,opb,clk,clr);
always #(DELY) clk = ~clk;

initial begin
clr = 1;clk = 0;opa = 8'd0;opb = 8'd0;
#DELY clr = 0;opa = 8