马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
用一个低位乘法器计算高位乘法器。
比如:我用一个4位乘法器来计算8位乘法,用分治,高位、低位互相乘之后把结果overlap起来。
即:A,B都是8位数,Ah,Bh是A,B的高4位,Al,Bl是A,B的低四位
A * B = {Ah:Al} * {Bh:bl} = (Ah*Bh << 8) + (Al*Bh << 4) + (Ah*Bl << 4) + (Al*Bl)
所以1个8位乘法,分解成4个4位乘法,和一些加法。
要求:只能用1个4位乘法器,串行计算。(为了控制模块面积)
所以我写了下面的代码,但是:
Gf2_mul_4 m(pa, pb, part); 这句好像没有起作用
观察波形pa,pb都是会随着clk变化的,但part一直是0。应该怎么改呢?
万分感谢!!
//这是一个GF(2^8)乘法器。a,b是乘数、被乘数,prob用来观察结果
module gf28(clk, a, b, c, prob);
parameter SIZE = 8;
parameter HALF = 4;
input clk;
input [SIZE-1:0] a, b;
output [SIZE-1:0] c;
output [2*SIZE-1:0]prob;
reg [2*SIZE-1:0] pro;
reg [2*HALF-1:0] part;
reg [SIZE-1:0] c;
reg [4:0]round = 0;
reg [HALF-1:0] pa, pb;
Gf2_mul_4 m(pa, pb, part); //本意是计算part = pa * pb,但这样写好像不起作用?part总是0
assign prob = pro;
initial begin
c = 0;
pro = 0;
part = 0;
end
always @(posedge clk) begin
round <= round + 1;
case (round)
1: begin
pa = a[HALF-1:0];
pb = b[HALF-1:0];
end
3: begin
pa = a[SIZE-1:HALF];
pb = b[HALF-1:0];
end
5: begin
pa = a[HALF-1:0];
pb = b[SIZE-1:HALF];
end
7: begin
pa = a[SIZE-1:HALF];
pb = b[SIZE-1:HALF];
end
default: ;
endcase
case (round)
2: begin
pro[SIZE-1:0] <= pro[SIZE-1:0] ^
part;
end
4: begin
pro[SIZE+HALF-1:HALF] <=
pro[SIZE+HALF-1:HALF] ^ part;
end
6: begin
pro[SIZE+HALF-1:HALF] <=
pro[SIZE+HALF-1:HALF] ^ part;
end
8: begin
pro[2*SIZE-1:SIZE] <= pro[2*SIZE-1:SIZE] ^ part;
end
default: ;
endcase
round <= round + 1;
end
endmodule
//一个Gf(2^4)乘法器
module Gf2_mul_4(a, b, c);
input [3:0] a, b;
output [6:0] c;
assign c[0] = a[0] & b[0];
assign c[1] = (a[0] & b[1]) ^ (a[1] & b[0]);
assign c[2] = ((a[0] & b[2]) ^ (a[1] & b[1])) ^ (a[2] &
b[0]);
assign c[3] = ((a[0] & b[3]) ^ (a[1] & b[2])) ^ ((a[2] &
b[1]) ^ (a[3] & b[0]));
assign c[4] = ((a[1] & b[3]) ^ (a[2] & b[2])) ^ (a[3] &
b[1]);
assign c[5] = (a[2] & b[3]) ^ (a[3] & b[2]);
assign c[6] = a[3] & b[3];
endmodule
|