avimit
Banned
Can somebody suggest me how to write a function in verilog which takes a vector as input and produces a vector as output, and the function iteself is independent of the length or size of the vector. I need the syntax of the function.
In vhdl I can do it very eaisly
FUNCTION myabs(s1:std_logic_vector) return std_logic_vector is
--this function returns absolute of the input std_logic_vector
VARIABLE V : std_logic_vector(s1'high downto s1'low) ;
BEGIN
V := s1;
for i in V'low to V'high loop
V(i) := V(i) XOR V(V'HIGH);
end loop;
V:=V+V(V'HIGH);
return V;
end myabs; -- end function
Note that the function does not mention anywhere the 'size of' or the 'width of' the input or output vectors, instead, 'high and 'low vhdl attributes are used.
Can somebody write this in Verilog?
In vhdl I can do it very eaisly
FUNCTION myabs(s1:std_logic_vector) return std_logic_vector is
--this function returns absolute of the input std_logic_vector
VARIABLE V : std_logic_vector(s1'high downto s1'low) ;
BEGIN
V := s1;
for i in V'low to V'high loop
V(i) := V(i) XOR V(V'HIGH);
end loop;
V:=V+V(V'HIGH);
return V;
end myabs; -- end function
Note that the function does not mention anywhere the 'size of' or the 'width of' the input or output vectors, instead, 'high and 'low vhdl attributes are used.
Can somebody write this in Verilog?