Using Module on Module

T

Tadeu

Guest
///////////////////////////////////////////////////////////////////////////////
//Logical Unit
module UnidadeLogica(a, b, s, f);
input [0:3] a,b;
input [0:1] s;
output [0:3] f;

assign f = Logica(a,b,s);

function[0:3] Logica;
input [0:3] a,b;
input [0:1] s;
case(s)
2'b00 : begin//AND
Logica = a & b;
end
2'b01 : begin//OR
Logica = a | b;
end
2'b10 : begin//XOR
Logica = a ^ b;
end
2'b11 : begin//XNOR
Logica = ~(a ^ b);
end
default: begin
Logica = 4'bz;
end
endcase
endfunction
endmodule
////////////
This works good. Now I intended to create a aritmetical unit but for
that I need a fullAdder4Bits created by me "FullAdderQuatro" then I
tried to do this:
///////////////////////////////////////////////////////////////////////////////
//Unidade Aritmética
module UnidadeAritmetica(a, b, s, cIn, cOut, f);
input [0:3] a,b;
input [0:1] s;
output [0:3] f;
input cIn;
output cOut;

wire [0:4] result;

assign result = Aritmetica(a,b,s,cIn);
assign f = result[0:3];
assign cOut = result[4];

function[0:4] Aritmetica;
input [0:3] a,b;
input [0:1] s;
input cIn;
case(s)
2'b00 : begin//transfer a to output adding cIn
FullAdderQuatro
fa4(cIn,a,4'b0000,Aritmetica[0:3],Aritmetica[4]);
end
2'b01 : begin
FullAdderQuatro fa4(cIn,a,b,Aritmetica[0:3],Aritmetica[4]);
end
default: begin
Aritmetica = 4'bz;
//$display("Operaçăo năo existe!");
end
endcase
endfunction
endmodule
//////////////
but I got this error:

and.v:145: parse error
and.v:145: error: malformed statement
and.v:148: parse error
and.v:148: error: malformed statement

where line 145 is FullAdderQuatro
fa4(cIn,a,4'b0000,Aritmetica[0:3],Aritmetica[4]);

what is the problem now?
tnkz
 
On 8 Sep 2006 09:28:56 -0700, "Tadeu" <tadeu.fo@gmail.com> wrote:

//Unidade Aritmética
module UnidadeAritmetica(a, b, s, cIn, cOut, f);
input [0:3] a,b;
input [0:1] s;
output [0:3] f;
input cIn;
output cOut;

wire [0:4] result;

assign result = Aritmetica(a,b,s,cIn);
assign f = result[0:3];
assign cOut = result[4];

function[0:4] Aritmetica;
input [0:3] a,b;
input [0:1] s;
input cIn;
case(s)
2'b00 : begin//transfer a to output adding cIn
FullAdderQuatro
fa4(cIn,a,4'b0000,Aritmetica[0:3],Aritmetica[4]);
end
2'b01 : begin
FullAdderQuatro fa4(cIn,a,b,Aritmetica[0:3],Aritmetica[4]);
end
default: begin
Aritmetica = 4'bz;
//$display("Operaçăo năo existe!");
end
endcase
endfunction
endmodule
//////////////
but I got this error:

and.v:145: parse error
and.v:145: error: malformed statement
and.v:148: parse error
and.v:148: error: malformed statement

where line 145 is FullAdderQuatro
fa4(cIn,a,4'b0000,Aritmetica[0:3],Aritmetica[4]);

what is the problem now?
tnkz
You can not instantiate modules in fuctions.You should instantiate
FullAdderQuatro outside the function but inside the module
UnidadeAritmetica. Generate a vector bin which muxes 0 and b input of
the module and connect the FAQ outputs to f & cOut directly. Even if
you could instantiate FAQ in the function, you would get two copies of
it which is probably not what you want. Instantiate it once and put a
mux at the b input.

HTH.
 
mk escreveu:

On 8 Sep 2006 09:28:56 -0700, "Tadeu" <tadeu.fo@gmail.com> wrote:

//Unidade Aritmética
module UnidadeAritmetica(a, b, s, cIn, cOut, f);
input [0:3] a,b;
input [0:1] s;
output [0:3] f;
input cIn;
output cOut;

wire [0:4] result;

assign result = Aritmetica(a,b,s,cIn);
assign f = result[0:3];
assign cOut = result[4];

function[0:4] Aritmetica;
input [0:3] a,b;
input [0:1] s;
input cIn;
case(s)
2'b00 : begin//transfer a to output adding cIn
FullAdderQuatro
fa4(cIn,a,4'b0000,Aritmetica[0:3],Aritmetica[4]);
end
2'b01 : begin
FullAdderQuatro fa4(cIn,a,b,Aritmetica[0:3],Aritmetica[4]);
end
default: begin
Aritmetica = 4'bz;
//$display("Operaçăo năo existe!");
end
endcase
endfunction
endmodule
//////////////
but I got this error:

and.v:145: parse error
and.v:145: error: malformed statement
and.v:148: parse error
and.v:148: error: malformed statement

where line 145 is FullAdderQuatro
fa4(cIn,a,4'b0000,Aritmetica[0:3],Aritmetica[4]);

what is the problem now?
tnkz

You can not instantiate modules in fuctions.You should instantiate
FullAdderQuatro outside the function but inside the module
UnidadeAritmetica. Generate a vector bin which muxes 0 and b input of
the module and connect the FAQ outputs to f & cOut directly. Even if
you could instantiate FAQ in the function, you would get two copies of
it which is probably not what you want. Instantiate it once and put a
mux at the b input.

HTH.
thank you I solved the problem with your suggestion, I changed the
Aritmetica function so it only return the operators needed in
FullAdderQuatro()
here is the code I used:
module UnidadeAritmetica(a, b, s, cIn, cOut, f);
input [0:3] a,b;
input [0:1] s;
output [0:3] f;
input cIn;
output cOut;

wire [0:7] result;
wire [0:3] a1,b1;
assign result = Aritmetica(s);

assign a1 = result[0:3];
assign b1 = result[4:7];

FullAdderQuatro fa4_0(cIn,a1,b1,f,cOut);

function[0:7] Aritmetica;
input [0:1] s;
begin
case(s)
2'b00 : begin//transfer a to output adding cIn
assign Aritmetica = {a,4'b0000};
end
2'b01 : begin
assign Aritmetica = {a,b};
end
2'b10 : begin
assign Aritmetica = {a,~b};
end
2'b11 : begin
assign Aritmetica = {~a,b};
end
default: begin
Aritmetica = 4'bxxxx;
end
endcase
end

endfunction
endmodule
 

Welcome to EDABoard.com

Sponsor

Back
Top