Skip to content

Instantly share code, notes, and snippets.

@pasali
Created April 22, 2014 05:36
Show Gist options
  • Save pasali/11166364 to your computer and use it in GitHub Desktop.
Save pasali/11166364 to your computer and use it in GitHub Desktop.
module carp(a, b, y);
parameter N = 4;
input [N - 1:0] a;
input [N - 1:0] b;
output [2*N - 1:0] y;
wire [N - 1:0] m [0:N - 1];
wire [N - 1:0] p [0:N - 1];
genvar i;
generate
for (i = 0; i < N; i = i + 1)
begin
assign m[i] = a[i] ? b : 0;
end
endgenerate
assign p[0] = {1'b0, m[0]};
generate
for (i = 1; i <N; i = i + 1)
begin
assign y[i - 1] = p[i - 1][0];
assign p[i] = m[i] + p[i - 1][N:1];
end
endgenerate
assign y[2*N - 1:N - 2] = p[N - 1];
endmodule
module carpici();
parameter UZUNLUK = 3; //matristeki her bir satirdaki ya da sutundaki eleman sayisi
parameter BITUZUNLUK = 3; //matristeki her bir sayinin bit uzunlugu
reg [BITUZUNLUK:0] matris1 [0:UZUNLUK][0:UZUNLUK];
reg [BITUZUNLUK:0] matris2 [0:UZUNLUK][0:UZUNLUK];
wire [BITUZUNLUK*2+1:0] matris_out [0:UZUNLUK][0:UZUNLUK];
integer i, j, k = 1;
initial begin
for( i = 0 ; i <= UZUNLUK; i = i+1 )
begin
for( j = 0 ; j <= UZUNLUK; j = j+1 )
begin
matris1[i][j] = k;
matris2[i][j] = k;
k = k + 1;
end
end
end
wire [BITUZUNLUK*2+1:0] toplam;
wire gecici_toplam ;
genvar m,n,p;
generate
for (m = 0; m <= UZUNLUK; m = m+1)
begin
for (n = 0; n <= UZUNLUK; n = n+1)
begin
assign toplam = 0;
for (p = 0; p <= UZUNLUK; p = p+1)
begin
carp dene(matris1[m][p],matris2[p][n],gecici_toplam);
//topla top (gecici_toplam,toplam,toplam);
assign toplam = toplam + gecici_toplam;
end
assign matris_out[m][n] = toplam;
end
end
endgenerate
endmodule
module carp(a, b, y);
input a;
input b;
output y;
assign y = a * b;
endmodule
module topla(a, b, sonuc);
input a , b;
output sonuc;
assign sonuc = a + b;
endmodule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment