Function declaration

R

raghu

Guest
can a function be defined as in the following code????
module ex;
output [1:56]hum;
reg[1:56] skey,hum;
integer rsel;
hum=key_rot(skey,rsel);
function [1:56]key_rot; //function definition
input [1:56]skey;
input rsel;
wire [1:28] c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16;
wire [1:28] d1,d2,d3,d4,d5,d6,d7,d8,d9,d10,d11,d12,d13,d14,d15,d16;
begin
assign c1[1:28] = {skey[2:28],skey[1]};
assign d1[1:28] = {skey[30:56],skey[29]};
assign c2[1:28] = {c1[2:28],c1[1]};
assign d2[1:28] = {d1[2:28],d1[1]};
assign c3[1:28] = {c2[3:28],c2[1:2]};
assign d3[1:28] = {d2[3:28],d2[1:2]};
assign c4[1:28] = {c3[3:28],c3[1:2]};
assign d4[1:28] = {d3[3:28],d3[1:2]};
assign c5[1:28] = {c4[3:28],c4[1:2]};
assign d5[1:28] = {d4[3:28],d4[1:2]};
assign c6[1:28] = {c5[3:28],c5[1:2]};
assign d6[1:28] = {d5[3:28],d5[1:2]};
assign c7[1:28] = {c6[3:28],c6[1:2]};
assign d7[1:28] = {d6[3:28],d6[1:2]};
assign c8[1:28] = {c7[3:28],c7[1:2]};
assign d8[1:28] = {d7[3:28],d7[1:2]};
assign c9[1:28] = {c8[3:28],c8[1:2]};
assign d9[1:28] = {d8[3:28],d8[1:2]};
assign c10[1:28] = {c9[2:28],c9[1]};
assign d10[1:28] = {d9[2:28],d9[1]};
assign c11[1:28] = {c10[3:28],c10[1:2]};
assign d11[1:28] = {d10[3:28],d10[1:2]};
assign c12[1:28] = {c11[3:28],c11[1:2]};
assign d12[1:28] = {d11[3:28],d11[1:2]};
assign c13[1:28] = {c12[3:28],c12[1:2]};
assign d13[1:28] = {d12[3:28],d12[1:2]};
assign c14[1:28] = {c13[3:28],c13[1:2]};
assign d14[1:28] = {d13[3:28],d13[1:2]};
assign c15[1:28] = {c14[3:28],c14[1:2]};
assign d15[1:28] = {d14[3:28],d14[1:2]};
assign c16[1:28] = {c15[2:28],c15[1]};
assign d16[1:28] = {d15[2:28],d15[1]};
always @(rsel)
begin
case(rsel)
0: key_rot = {c1[1:28],d1[1:28]};
1: key_rot = {c2[1:28],d2[1:28]};
2: key_rot = {c3[1:28],d3[1:28]};
3: key_rot = {c4[1:28],d4[1:28]};
4: key_rot = {c5[1:28],d5[1:28]};
5: key_rot = {c6[1:28],d6[1:28]};
6: key_rot = {c7[1:28],d7[1:28]};
7: key_rot = {c8[1:28],d8[1:28]};
8: key_rot = {c9[1:28],d9[1:28]};
9: key_rot = {c10[1:28],d10[1:28]};
10: key_rot = {c11[1:28],d11[1:28]};
11: key_rot = {c12[1:28],d12[1:28]};
12: key_rot = {c13[1:28],d13[1:28]};
13: key_rot = {c14[1:28],d14[1:28]};
14: key_rot = {c15[1:28],d15[1:28]};
15: key_rot = {c16[1:28],d16[1:28]};
endcase
end
end
endfunction
endmodule

please do tell if there are any errors in the code...

Thanks a lot.

Regards,
Raghu
 
Hi,

I think the correct way to code what you want to do is:
module ex(skey,rsel,hum);
input [3:0] rsel;
output [1:56]hum;
input [1:56] skey;
assign hum=key_rot(skey,rsel);
function [1:56]key_rot; //function definition
input [1:56]skey;
input [3:0] rsel;
reg [1:28] c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16;
reg [1:28] d1,d2,d3,d4,d5,d6,d7,d8,d9,d10,d11,d12,d13,d14,d15,d16;
begin
c1[1:28] = {skey[2:28],skey[1]};
d1[1:28] = {skey[30:56],skey[29]};
c2[1:28] = {c1[2:28],c1[1]};
d2[1:28] = {d1[2:28],d1[1]};
c3[1:28] = {c2[3:28],c2[1:2]};
d3[1:28] = {d2[3:28],d2[1:2]};
c4[1:28] = {c3[3:28],c3[1:2]};
d4[1:28] = {d3[3:28],d3[1:2]};
c5[1:28] = {c4[3:28],c4[1:2]};
d5[1:28] = {d4[3:28],d4[1:2]};
c6[1:28] = {c5[3:28],c5[1:2]};
d6[1:28] = {d5[3:28],d5[1:2]};
c7[1:28] = {c6[3:28],c6[1:2]};
d7[1:28] = {d6[3:28],d6[1:2]};
c8[1:28] = {c7[3:28],c7[1:2]};
d8[1:28] = {d7[3:28],d7[1:2]};
c9[1:28] = {c8[3:28],c8[1:2]};
d9[1:28] = {d8[3:28],d8[1:2]};
c10[1:28] = {c9[2:28],c9[1]};
d10[1:28] = {d9[2:28],d9[1]};
c11[1:28] = {c10[3:28],c10[1:2]};
d11[1:28] = {d10[3:28],d10[1:2]};
c12[1:28] = {c11[3:28],c11[1:2]};
d12[1:28] = {d11[3:28],d11[1:2]};
c13[1:28] = {c12[3:28],c12[1:2]};
d13[1:28] = {d12[3:28],d12[1:2]};
c14[1:28] = {c13[3:28],c13[1:2]};
d14[1:28] = {d13[3:28],d13[1:2]};
c15[1:28] = {c14[3:28],c14[1:2]};
d15[1:28] = {d14[3:28],d14[1:2]};
c16[1:28] = {c15[2:28],c15[1]};
d16[1:28] = {d15[2:28],d15[1]};

case(rsel)
0: key_rot = {c1[1:28],d1[1:28]};
1: key_rot = {c2[1:28],d2[1:28]};
2: key_rot = {c3[1:28],d3[1:28]};
3: key_rot = {c4[1:28],d4[1:28]};
4: key_rot = {c5[1:28],d5[1:28]};
5: key_rot = {c6[1:28],d6[1:28]};
6: key_rot = {c7[1:28],d7[1:28]};
7: key_rot = {c8[1:28],d8[1:28]};
8: key_rot = {c9[1:28],d9[1:28]};
9: key_rot = {c10[1:28],d10[1:28]};
10: key_rot = {c11[1:28],d11[1:28]};
11: key_rot = {c12[1:28],d12[1:28]};
12: key_rot = {c13[1:28],d13[1:28]};
13: key_rot = {c14[1:28],d14[1:28]};
14: key_rot = {c15[1:28],d15[1:28]};
15: key_rot = {c16[1:28],d16[1:28]};
endcase
end
endfunction
endmodule

Serge

"raghu" <raghujindia@gmail.com> a écrit dans le message de news:
1158176262.273796.240960@p79g2000cwp.googlegroups.com...
can a function be defined as in the following code????
module ex;
output [1:56]hum;
reg[1:56] skey,hum;
integer rsel;
hum=key_rot(skey,rsel);
function [1:56]key_rot; //function definition
input [1:56]skey;
input rsel;
wire [1:28] c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16;
wire [1:28] d1,d2,d3,d4,d5,d6,d7,d8,d9,d10,d11,d12,d13,d14,d15,d16;
begin
assign c1[1:28] = {skey[2:28],skey[1]};
assign d1[1:28] = {skey[30:56],skey[29]};
assign c2[1:28] = {c1[2:28],c1[1]};
assign d2[1:28] = {d1[2:28],d1[1]};
assign c3[1:28] = {c2[3:28],c2[1:2]};
assign d3[1:28] = {d2[3:28],d2[1:2]};
assign c4[1:28] = {c3[3:28],c3[1:2]};
assign d4[1:28] = {d3[3:28],d3[1:2]};
assign c5[1:28] = {c4[3:28],c4[1:2]};
assign d5[1:28] = {d4[3:28],d4[1:2]};
assign c6[1:28] = {c5[3:28],c5[1:2]};
assign d6[1:28] = {d5[3:28],d5[1:2]};
assign c7[1:28] = {c6[3:28],c6[1:2]};
assign d7[1:28] = {d6[3:28],d6[1:2]};
assign c8[1:28] = {c7[3:28],c7[1:2]};
assign d8[1:28] = {d7[3:28],d7[1:2]};
assign c9[1:28] = {c8[3:28],c8[1:2]};
assign d9[1:28] = {d8[3:28],d8[1:2]};
assign c10[1:28] = {c9[2:28],c9[1]};
assign d10[1:28] = {d9[2:28],d9[1]};
assign c11[1:28] = {c10[3:28],c10[1:2]};
assign d11[1:28] = {d10[3:28],d10[1:2]};
assign c12[1:28] = {c11[3:28],c11[1:2]};
assign d12[1:28] = {d11[3:28],d11[1:2]};
assign c13[1:28] = {c12[3:28],c12[1:2]};
assign d13[1:28] = {d12[3:28],d12[1:2]};
assign c14[1:28] = {c13[3:28],c13[1:2]};
assign d14[1:28] = {d13[3:28],d13[1:2]};
assign c15[1:28] = {c14[3:28],c14[1:2]};
assign d15[1:28] = {d14[3:28],d14[1:2]};
assign c16[1:28] = {c15[2:28],c15[1]};
assign d16[1:28] = {d15[2:28],d15[1]};
always @(rsel)
begin
case(rsel)
0: key_rot = {c1[1:28],d1[1:28]};
1: key_rot = {c2[1:28],d2[1:28]};
2: key_rot = {c3[1:28],d3[1:28]};
3: key_rot = {c4[1:28],d4[1:28]};
4: key_rot = {c5[1:28],d5[1:28]};
5: key_rot = {c6[1:28],d6[1:28]};
6: key_rot = {c7[1:28],d7[1:28]};
7: key_rot = {c8[1:28],d8[1:28]};
8: key_rot = {c9[1:28],d9[1:28]};
9: key_rot = {c10[1:28],d10[1:28]};
10: key_rot = {c11[1:28],d11[1:28]};
11: key_rot = {c12[1:28],d12[1:28]};
12: key_rot = {c13[1:28],d13[1:28]};
13: key_rot = {c14[1:28],d14[1:28]};
14: key_rot = {c15[1:28],d15[1:28]};
15: key_rot = {c16[1:28],d16[1:28]};
endcase
end
end
endfunction
endmodule

please do tell if there are any errors in the code...

Thanks a lot.

Regards,
Raghu
 

Welcome to EDABoard.com

Sponsor

Back
Top