please verify...

R

raghu

Guest
Is the following verilog code correct?

module check(data,sel);
output [5:0] data;
input [1:0]sel;

data = { data[3:5], box(data[3:5] , com(sel) ) ^ data[0:2] };

function [2:0] com; // com function definition
input [1:0] sel;
begin
statements;
end
endfunction

here com() function returns 3 bit value..

can anyone please tell me how to define the function box()...assuming
box function returns a 3-bit value..

I tried as...

function [2:0] box;
input [3:5] data;
input com(sel); /// ..is it correct?
begin
statements;
end
endfunction

Hoping for a positive response...

Thanks a lot..

Regards,
Raghu
 
If the function takes the input values as local variables, the "com(sel)"
and "[3:5] data" would confuse things a bit. If you want a function that
multiplies x and y, the inputs are x and y even if the values aren't (e.g.,
mult(4,17) ). I believe you can specify the function without the input
statements such that the data and com values are used globally but if you do
that, why bother with a function?

Functions are generally used when they're reused. Often. Which means
varying inputs.


"raghu" <raghujindia@gmail.com> wrote in message
news:1158263368.141244.284530@i42g2000cwa.googlegroups.com...
Is the following verilog code correct?

module check(data,sel);
output [5:0] data;
input [1:0]sel;

data = { data[3:5], box(data[3:5] , com(sel) ) ^ data[0:2] };

function [2:0] com; // com function definition
input [1:0] sel;
begin
statements;
end
endfunction

here com() function returns 3 bit value..

can anyone please tell me how to define the function box()...assuming
box function returns a 3-bit value..

I tried as...

function [2:0] box;
input [3:5] data;
input com(sel); /// ..is it correct?
begin
statements;
end
endfunction

Hoping for a positive response...

Thanks a lot..

Regards,
Raghu
 
You mean to say that the function can be defined as follows:

function [2:0] box;
begin /// without declaring the inputs...
statements;
end
endfunction

Thank you.

Regards,
Raghu
 
raghu wrote:
You mean to say that the function can be defined as follows:

function [2:0] box;
begin /// without declaring the inputs...
statements;
end
endfunction

If suppose i want to perform xor operation with the 3-bit return
value of com() function inside the function box how should i use the
com() function ..Please help me out.

Thank you.

Regards,
Raghu
 
"raghu" <raghujindia@gmail.com> a écrit dans le message de news:
1158263368.141244.284530@i42g2000cwa.googlegroups.com...
Is the following verilog code correct?

module check(data,sel);
output [5:0] data;
input [1:0]sel;

data = { data[3:5], box(data[3:5] , com(sel) ) ^ data[0:2] };

function [2:0] com; // com function definition
input [1:0] sel;
begin
statements;
end
endfunction

here com() function returns 3 bit value..

can anyone please tell me how to define the function box()...assuming
box function returns a 3-bit value..

I tried as...

function [2:0] box;
input [3:5] data;
input com(sel); /// ..is it correct?
begin
statements;
end
endfunction

Hoping for a positive response...

Thanks a lot..

Regards,
Raghu
The "box" function seams to take 2 3 bits values as input, I would declare
it as:
function [2:0] box;
input [2:0] a;
input [2:0] b;

begin
statements;
end
endfunction


and use it as you did: box(data[3:5] , com(sel) ), so data[3,5] will be send
to function input variable a and com(sel) to b as function parameter as
passed by order.

Serge
 
raghu wrote:
raghu wrote:
You mean to say that the function can be defined as follows:

function [2:0] box;
begin /// without declaring the inputs...
statements;
end
endfunction

If suppose i want to perform xor operation with the 3-bit return
value of com() function inside the function box how should i use the
com() function ..Please help me out.

Thank you.

Regards,
Raghu
If you want to perform xor operation with the com() function return
value and the dat[3:5] bits, why would you *want* to use the function
and not just an inline

data = { data[3:5], data[3:5] ^ com(sel) ^ data[0:2] };

?

Functions are typically used because there are different values that
need to be manipulated the same way in different parts of the program.
A simple assign in place of the function would product the same results.

You can use global or local variables within the function. I have never
seen and hope never to see a function without inputs that produces the
same result wherever it's called.

Look at what you're trying to accomplish and consider how a simple
assignment for a 3-bit vector called box might simplify your code.
 
"raghu" <raghujindia@gmail.com> wrote:
1158263368.141244.284530@i42g2000cwa.googlegroups.com...
Is the following verilog code correct?

module check(data,sel);
output [5:0] data;
input [1:0]sel;

data = { data[3:5], box(data[3:5] , com(sel) ) ^ data[0:2] };

function [2:0] com; // com function definition
input [1:0] sel;
begin
statements;
end
endfunction

here com() function returns 3 bit value..

can anyone please tell me how to define the function box()...assuming
box function returns a 3-bit value..

I tried as...

function [2:0] box;
input [3:5] data;
input com(sel); /// ..is it correct?
begin
statements;
end
endfunction

Hoping for a positive response...

Thanks a lot..

Regards,
Raghu
and also:

If suppose i want to perform xor operation with the 3-bit return
value of com() function inside the function box how should i use the
com() function ..Please help me out.
The answer is that your formulation is not correct. And, until you
wrote the above statement, it wasn't possible to guess what you
wanted, even now it isn't certain.

If you want to write a statement like:

assign data = { data[3:5], box(data[3:5] , com(sel) ) ^ data[0:2] };
// you are passing two 3 bit values to box,
// the result of the function com(sel) is simply
// a 3 bit input to the function

Then you write the function like:

function [2:0] box;
input [2:0] left_arg; // give these better names to decribe what they mean,
// but note that I didn't call them data or con(sel)
// data is an "okay" name, not descriptive, but legal.
// con(sel) is not a legal name.
input [2:0] right_arg;
begin
// do something with the 2 3-bit values to caluate you 3 bit result
box = left_arg ^ right_arg;
end
endfunction

If you want to make com(sel) part of the box function and not an
input. That, is if instead of what you wrote above, you want to
write:

assign data = { data[3:5], box(data[3:5] , sel ) ^ data[0:2] };
// note we are now passing sel, not con(sel)
Then you write the function like:

function [2:0] box;
input [2:0] left_arg;
input [1:0] right_arg;
begin
box = left_arg ^ con(right_arg);
end
endfunction

Hope this helps,
-Chris

*****************************************************************************
Chris Clark Internet : compres@world.std.com
Compiler Resources, Inc. Web Site : http://world.std.com/~compres
23 Bailey Rd voice : (508) 435-5016
Berlin, MA 01503 USA fax : (978) 838-0263 (24 hours)
------------------------------------------------------------------------------
 

Welcome to EDABoard.com

Sponsor

Back
Top