微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > FPGA,CPLD和ASIC > 求指教!‘assign sum=mult(opa,opb)+out;“为什么还要+out?

求指教!‘assign sum=mult(opa,opb)+out;“为什么还要+out?

时间:10-02 整理:3721RD 点击:
乘累加器
module MAC(out,opa,opb,clk,clr);
output[15:0] out;
input[7:0] opa,opb;
input clk,clr;
wire[15:0] sum;
reg[15:0] out;
function[15:0] mult; //函数定义,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==1) result=result+(opb<<(i-1));
end
mult=result;
end
endfunction
assign sum=mult(opa,opb)+out;
always @(posedge clk or posedge clr)
begin
if(clr) out<=0;
else out<=sum;
end
endmodule

“累加”

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top