`define width 16
`timescale 1ns/1ps
39
Appendix- 4B
VERILOG CODE OF BOOTH MULTILPIER
`define width 16
`timescale 1ns/1ps
module booth_mult (p, x, y);
parameter width=`width;
parameter N = `width/2;
input[width-1:0]x, y;
output[width+width-1:0]p;
reg [2:0] cc[N-1:0];
reg [width:0] pp[N-1:0];
reg [width+width-1:0] spp[N-1:0];
reg [width+width-1:0] prod;
wire [width:0] inv_x;
integer kk,ii;
assign inv_x = {~x[width-1],~x}+1;
always @ (x or y or inv_x)
begin
cc[0] = {y[1],y[0],1'b0};
for(kk=1;kk<N;kk=kk+1)
cc[kk] = {y[2*kk+1],y[2*kk],y[2*kk-1]};
for(kk=0;kk<N;kk=kk+1)
begin
case(cc[kk])
3'b001 , 3'b010 : pp[kk] = {x[width-1],x};
3'b011 : pp[kk] = {x,1'b0};
3'b100 : pp[kk] = {inv_x[width-1:0],1'b0};
3'b101 , 3'b110 : pp[kk] = inv_x;
default : pp[kk] = 0;
endcase
spp[kk] = $signed(pp[kk]);
for(ii=0;ii<kk;ii=ii+1)
spp[kk] = {spp[kk],2'b00};
end
prod = spp[0];
for(kk=1;kk<N;kk=kk+1)
prod = prod + spp[kk];
end
assign p = prod;
endmodule
40
Appendix-4C
VERILOG CODE OF VEDIC MULTIPLIER
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////
////////////
// Company:
// Engineer:
//
// Create Date:
16:06:33 04/20/2014
// Design Name:
// Module Name:
vedic_16x16
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////
////////////
module vedic_16x16(a,b,c
);
input [15:0]a;
input [15:0]b;
output [31:0]c;
wire
wire
wire
wire
wire
wire
wire
wire
wire
wire
wire
wire
[15:0]q0;
[15:0]q1;
[15:0]q2;
[15:0]q3;
[31:0]c;
[15:0]temp1;
[23:0]temp2;
[23:0]temp3;
[23:0]temp4;
[15:0]q4;
[23:0]q5;
[23:0]q6;
vedic_8X8
vedic_8X8
vedic_8X8
vedic_8X8
z1(a[7:0],b[7:0],q0[15:0]);
z2(a[15:8],b[7:0],q1[15:0]);
z3(a[7:0],b[15:8],q2[15:0]);
z4(a[15:8],b[15:8],q3[15:0]);
41
begin
filter_reg <= filter_next ;
f_ps2c_reg <= f_ps2c_next ;
end
assign filter_next= {ps2c, filter_reg[7:1]};
assign f_ps2c_next= {filter_reg==8'b11111111} ? 1'b1
:(filter_reg==8'b00000000) ? 1'b0 :f_ps2c_reg;
assign fall_edge = f_ps2c_reg &(~f_ps2c_next);
// FSMD s t a t e & d a t a r e g i s t e r s
always@( posedge clk , posedge reset )
if(reset)
begin
state_reg <= idle;
n_reg <= 0;
b_reg <= 0;
//flag<=2'b0;
end
else
begin
state_reg <= state_next ;
n_reg <= n_next;
b_reg <= b_next;
end
// FSMD n e x t - s t a t e l o g i c
always@(*)
begin
state_next = state_reg;
rx_done_tick = 1'b0;
n_next = n_reg;
b_next = b_reg;
case(state_reg)
idle :
if(fall_edge & rx_en)
begin
// s h i f t in s t a r t b i t
b_next = {ps2d, b_reg[10:1]};
n_next = 4'b1001;
state_next = dps;
end
dps: // 8 datu + I p a r i t y + I s t o p
if(fall_edge)
begin
b_next = {ps2d, b_reg[10:1]};
if(n_reg==0)
begin
state_next = load;
/*if(flag==2'b11)
flag<=2'b0;
else
43
flag<=flag+1;*/
end
else
n_next = n_reg-4'b0001 ;
end
load: // I e x t r a c l o c k t o c o m p l e t e the l a s t s h i
f t
begin
state_next = idle ;
rx_done_tick = 1'b1;
end
endcase
end
assign data_out1 = (b_reg[8:1]==8'h45)?4'b0000:
(b_reg[8:1]==8'h16)?4'b0001:
(b_reg[8:1]==8'h1e)?4'b0010:
(b_reg[8:1]==8'h26)?4'b0011:
(b_reg[8:1]==8'h25)?4'b0100:
(b_reg[8:1]==8'h2e)?4'b0101:
(b_reg[8:1]==8'h36)?4'b0110:
(b_reg[8:1]==8'h3d)?4'b0111:
(b_reg[8:1]==8'h3e)?4'b1000:
(b_reg[8:1]==8'h46)?4'b1001:
(b_reg[8:1]==8'h1c)?4'b1010:
(b_reg[8:1]==8'h32)?4'b1011:
(b_reg[8:1]==8'h21)?4'b1100:
(b_reg[8:1]==8'h23)?4'b1101:
(b_reg[8:1]==8'h24)?4'b1110:
(b_reg[8:1]==8'h2b)?4'b1111:4'b0000;
a bits
endmodule
module mem(input [3:0] data_out1,
output reg [15:0] in1,in2,
input clk,clk2,reset,
output reg [2:0] count
);
// d a t
3'd0: in1[15:12]<=data_out1;
3'd1: in1[11:8]<=data_out1;
3'd2: in1[7:4]<=data_out1;
3'd3: in1[3:0]<=data_out1;
3'd4: in2[15:12]<=data_out1;
3'd5: in2[11:8]<=data_out1;
3'd6: in2[7:4]<=data_out1;
3'd7: in2[3:0]<=data_out1;
endcase
end
endmodule
module final_mult(input wire clk, reset,clk2,
input wire ps2d, ps2c, rx_en,
output reg sf_e,e,rs,r_w,d,c,b,a,
output wire [2:0] count
);
wire rx_done_tick;
wire [3:0] data_out1;
wire [15:0] in1,in2;
wire [31:0] prod;
if(reset)
lcd_count<=0;
else
lcd_count <=lcd_count + 27'd1;
case ( lcd_count[26:21])
6'd0:code
6'd1:code
6'd2:code
6'd3:code
<=6'h03;
<=6'h03;
<=6'h03;
<=6'h02;
6'd4:code <=6'h02;
6'd5:code <=6'h08;
///function mode
6'd6:code <=6'h00;
6'd7:code <=6'h06;
6'd8:code <=6'h00;
6'd9:code <=6'h0C;
set
6'd10:code <=6'h00;
6'd11:code <=6'h01; ///clear the lcd
6'd12:code <={2'b10, temp[3][7:4]};
6'd13:code <={2'b10, temp[3][3:0]};
6'd29:code <={2'b10,temp[4][3:0]};
6'd30:code <=6'b001100;
6'd31:code <=6'b000000;
6'd32:code <={2'b10, temp[15][7:4]};
6'd33:code <={2'b10,temp[15][3:0]};
6'd34:code <={2'b10, temp[14][7:4]};
6'd35:code <={2'b10,temp[14][3:0]};
6'd36:code <={2'b10, temp[13][7:4]};
6'd37:code <={2'b10,temp[13][3:0]};
6'd38:code <={2'b10, temp[12][7:4]};
6'd39:code <={2'b10,temp[12][3:0]};
6'd40:code <={2'b10, temp[11][7:4]};
6'd41:code <={2'b10, temp[11][3:0]};
6'd42:code <={2'b10, temp[10][7:4]};
6'd43:code <={2'b10, temp[10][3:0]};
6'd44:code <={2'b10, temp[9][7:4]};
6'd45:code <={2'b10, temp[9][3:0]};
6'd46:code <={2'b10, temp[8][7:4]};
6'd47:code <={2'b10, temp[8][3:0]};
default : code <=6'h10;
endcase
///busy flag
47
References:
[1] Honey Durga Tiwari, Ganzorig Gankhuyag, Chan Mo Kim, Yong Beom Cho Multiplier
design based on ancient Indian Vedic Mathematics
Conference .
[2] H. Thapliyal, M. B. Srinivas and H. R. Arabnia , "Design And Analysis of a VLSI Based
High Performance Low Power Parallel square Architecture", in Proc. Int. Conf. Also. Math.
Compo. Sc., Las Vegas, June 2005, pp. 72-76
[3] Xilinx Spartan 3E User Guide.
[4] Harpreet Singh Dhillon and Abhijit Mitra "A Digital Multiplier Architecture using Urdhava
Tiryakbhyam Sutra of Vedic Mathematics" IEEE Conference Proceedings,2008.
[5] Hussin R An Efficient Modified Booth Multiplier Architecture published in Electronics
Design 2008 ICED.
48