I'm new to Verilog. I tried the below code calling the 'task' into a if loop.. Syntax is correct. But when I execute behavioral simulation with choice
as 010 the loop is not working. The output is shown all zeroes and the synthesis report shows latches are generated..How to fix these two.
module a(choice,data1,data2,result);
input[2:0]choice;
input[6:0]data1;
input[8:0]data2;
output[8:0]result;
reg[8:0]reg_result;
wire[3:0]choice;
wire[6:0]data1;
wire[8:0]data2;
wire[8:0]result;
initial///initailllllllllllllllllllllllllll
begin
reg_result=0; //declaring output register to 0 initially
end
always @(data1 or data2 or choice )
begin
if(choice==001)////if loop 1
begin
taskoperation(data1,reg_result);///load result from task
end
if(choice==010)//when choice is given as 010 the simulated output gives me all
begin//zeroes in result(output reg)
taskoperation(data2,reg_result);
end
end
//task operation
task taskoperation(
input [8:0]datainput;
output [8:0]dataoutput
);
dataoutput[8:0]=~(datainput[8:0]);//taskoperation
endtask
assign result=reg_result;
endmodule