Plaintext
`timescale 1ns / 1ps
module Mul_Booth(
clk,a,b,product
);
input clk;
input [7:0] a;
input [7:0] b;
output [15:0] product;
reg [3:0] Booth4,Booth3,Booth2,Booth1;
wire [15:0] product1,product2,product3,product4;
wire [7:0] fb;
wire [8:0] fbb;
/*-----------------//基4 Booth 编码表----------------*/
always @(posedge clk) begin
case(a[7:5])
3'b000:Booth4=0;//0
3'b001:Booth4=1;//1
3'b010:Booth4=1;//1
3'b011:Booth4=2;//2
3'b100:Booth4=4;//-2
3'b101:Booth4=3;//-1
3'b110:Booth4=3;//-1
default:Booth4=0;//0
endcase
end
always @(posedge clk) begin
case(a[5:3])
3'b000:Booth3=0;
3'b001:Booth3=1;
3'b010:Booth3=1;
3'b011:Booth3=2;
3'b100:Booth3=4;
3'b101:Booth3=3;
3'b110:Booth3=3;
default:Booth3=0;
endcase
end
always @(posedge clk) begin
case(a[3:1])
3'b000:Booth2=0;
3'b001:Booth2=1;
3'b010:Booth2=1;
3'b011:Booth2=2;
3'b100:Booth2=4;
3'b101:Booth2=3;
3'b110:Booth2=3;
default:Booth2=0;
endcase
end
always @(posedge clk) begin
case({a[1:0],1'b0})
3'b000:Booth1=0;
3'b001:Booth1=1;
3'b010:Booth1=1;
3'b011:Booth1=2;
3'b100:Booth1=4;
3'b101:Booth1=3;
3'b110:Booth1=3;
default:Booth1=0;
endcase
end
/*--------------------部分积相加--------------------*/
assign product=product1+(product2<<2)+(product3<<4)+(product4<<6);
BuFenJi p1(.clk(clk),.Booth(Booth1),.b(b),.product(product1),.fb(fb),.fbb(fbb));
BuFenJi p2(.clk(clk),.Booth(Booth2),.b(b),.product(product2),.fb(fb),.fbb(fbb));
BuFenJi p3(.clk(clk),.Booth(Booth3),.b(b),.product(product3),.fb(fb),.fbb(fbb));
BuFenJi p4(.clk(clk),.Booth(Booth4),.b(b),.product(product4),.fb(fb),.fbb(fbb));
endmodule
|
文章评论(0条评论)
登录后参与讨论