v2vh_factor.v
module factor(n, result);
input [3:0] n;
output [31:0] result;
reg [31:0] result;
function integer factorial;
input [3:0] operand;
integer index;
begin
factorial = operand ? 1 : 0;
index = 2;
while ( index <= operand )
begin
factorial = index * factorial;
index = index + 1;
end
end
endfunction
always @n
result = factorial(n) ;
endmodule
|