第11讲 Verilog数字电路设计II.pptVIP

  • 8
  • 0
  • 约 29页
  • 2017-09-23 发布于河南
  • 举报
9.4 乘累加器 在本节中,设计实现一个简单的乘累加器。 例9. 8 乘累加器的代码 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[i]==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 例9.30 测试代码 timescale 1ns/1ns `include mac.v module mac_tp; reg[7:0] op

文档评论(0)

1亿VIP精品文档

相关文档