DSD Lab Manuals: Design and Implementation of Multiplier in Fpga
DSD Lab Manuals: Design and Implementation of Multiplier in Fpga
OBJECTIVES
INTRODUCTION
MULTIPLIER:
1
DSD lab Manuals Lab14
Verilog Code:
module multiplier(clk,addr,load,clear,data_in,calc,result);
inputclk,clear,calc,load;
inputaddr;
input [7:0]data_in;
outputreg [15:0]result;
reg [7:0]ram[1:0];
always@(posedgeclk)
begin
if(~clear)
begin
ram[0]=8'b0;
ram[1]=8'b0;
end
else if(~load)
ram[addr]=data_in;
end
always@(posedgeclk)
begin
if(~load)
result={8'b0,data_in};
else if(~calc)
result= multiply_8x8_2sC (ram[0],ram[1]);
else
result={8'b0,ram[addr]};
end
function[15:0] multiply_8x8_2sC;
input[7:0] a,b;
reg[7:0] a_mag,b_mag;
reg[14:0] y_mag;
reg[14:0] y_neg;
begin
case (a[7])
0: a_mag = a[6:0];
1: a_mag = 128 - a[6:0]; // max(a_mag) = 128, thus 8 bits
endcase
case (b[7])
0: b_mag = b[6:0];
1: b_mag = 128 - b[6:0];
endcase
y_mag = a_mag * b_mag; // max(y_mag) = 16384, thus 15 bits
if ((a[7] ^ b[7]) & (y_mag != 0)) // if (a * b) is -ve AND non-zero
begin
// y_mag>=1, <= 16256, thus need only 14 bits
y_neg = 32768 - y_mag[13:0]; // max(y_neg) = 32767, thus need 15 bits
2
DSD lab Manuals Lab14
multiply_8x8_2sC = {1'b1,y_neg};
end
else
multiply_8x8_2sC = y_mag;
end
endfunction
endmodule
Simulation:
3
DSD lab Manuals Lab14
RTL Schematic:
RESULT:
Thus the onboard switches and LEDs were designed using Verilog HDL and it was
simulated and tested in the FPGA device.
4
Observations/Comments/Explanation of Results