微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > FPGA,CPLD和ASIC > 求助:这段代码怎么就实现了乘法功能?

求助:这段代码怎么就实现了乘法功能?

时间:10-02 整理:3721RD 点击:
求助高手,这是一个乘法器的代码,可是看不懂为什么就实现了乘法功能?尤其是里面的task看不懂。
希望大侠们有空帮我看看~多谢啦
另外一个问题是:像这样的语句 r1 <= @(posedge sysclk) Multiplier_A; 可综合吗?

// 从这里开始
`define MULT_NUM_STATE_BITS 2
`define MULT_IDLE2'b00
`define MULT_SHIFT2'b01
`define MULT_RESULT2'b10
`timescale1ns/100ps

module Booth_Multiplier(Multiplier_enable,sysclk,Multiplier_A,Multiplier_B,
Multiplier_Result,Multiplier_ready);
inputMultiplier_enable;
inputsysclk;
input [31:0] Multiplier_A, Multiplier_B;

output[31:0] Multiplier_Result;
outputMultiplier_ready;

wireMultiplier_enable, sysclk;
wire[31:0] Multiplier_A, Multiplier_B;

reg[31:0] Multiplier_Result;
regMultiplier_ready;

regprev;
reg[5:0]count; // 0-63计数
reg[31:0] r1;
reg[63:0] r2;
reg[`MULT_NUM_STATE_BITS-1:0] present_state;//[2-1=1:0]

always
begin
@(posedge sysclk) enter_new_state(`MULT_IDLE); // 00,enter_new_state是一个任务Task。
r1 <= @(posedge sysclk) Multiplier_A;
r2 <= @(posedge sysclk) {1'b0, Multiplier_B};
count <= @(posedge sysclk) 0;
prev<= @(posedge sysclk) 0;
Multiplier_ready = 1;
if (Multiplier_enable)
begin
@(posedge sysclk) enter_new_state(`MULT_RESULT); // 10
Multiplier_Result <= @(posedge sysclk) r2[31:0];
while (count <= 31) // While语句,可综合?应该用for语句!
begin
if (prev == 1)
begin
if (r2[0] == 1)
prev <= @(posedge sysclk) 1;
else//r2[0] == 0
begin
prev <= @(posedge sysclk) 0;
`ifdef BUG3
r2[63:32] <= @(posedge sysclk) r2[63:32]+Multiplier_A;
`else
r2[63:32] <= @(posedge sysclk) r2[63:32]+r1;
`endif
end
end
else //prev == 0
begin
if (r2[0] == 1)
begin
prev <= @(posedge sysclk) 1;
`ifdef BUG3
r2[63:32] <= @(posedge sysclk) r2[63:32]-Multiplier_A;
`else
r2[63:32] <= @(posedge sysclk) r2[63:32]-r1;
`endif
end
else //r2[0] == 0
prev <= @(posedge sysclk) 0;
end
@(posedge sysclk) enter_new_state(`MULT_SHIFT);// 01
r2 <= @(posedge sysclk) {r2[63], r2[63:1]};
count <= @(posedge sysclk) count + 1;// 控制count递增,循环
@(posedge sysclk) enter_new_state(`MULT_RESULT); // 10
Multiplier_Result <= @(posedge sysclk) r2[31:0];
end
end
end
///////////////////////////////////////////////////////////
// task任务,完成?
///////////////////////////////////////////////////////////
task enter_new_state;
input [`MULT_NUM_STATE_BITS-1:0] this_state;//[2-1=1:0]
begin
present_state = this_state;
#1 Multiplier_ready = 0;
end
endtask
endmodule
// 到这里结束


oh
oh my god!这是什么风格的代码啊,难道我真的老撩么?

me2.........

不可综合。
里边这么多行为级描述的。
这代码太乱了。

booth乘法啊 计算机原理树上都有的

看不懂  应该可以写的简单点吧

当然是不可综合的

这代码怎么能综合出来呢行为级都没这么混乱的

吓一跳,呵呵。

这只是个行为级模型吧

呵呵.看不懂了.

always块怎么这么写,我是第一次见!

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

网站地图

Top