|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
求助高手,这是一个乘法器的代码,可是看不懂为什么就实现了乘法功能?尤其是里面的task看不懂。
希望大侠们有空帮我看看~多谢啦
另外一个问题是:像这样的语句 r1 <= @(posedge sysclk) Multiplier_A; 可综合吗?
// 从这里开始
`define MULT_NUM_STATE_BITS 2
`define MULT_IDLE 2'b00
`define MULT_SHIFT 2'b01
`define MULT_RESULT 2'b10
`timescale 1ns/100ps
module Booth_Multiplier(Multiplier_enable,sysclk,Multiplier_A,Multiplier_B,
Multiplier_Result,Multiplier_ready);
input Multiplier_enable;
input sysclk;
input [31:0] Multiplier_A, Multiplier_B;
output[31:0] Multiplier_Result;
output Multiplier_ready;
wire Multiplier_enable, sysclk;
wire [31:0] Multiplier_A, Multiplier_B;
reg [31:0] Multiplier_Result;
reg Multiplier_ready;
reg prev;
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
// 到这里结束
|
|