Adnan86
Full Member level 2
Hi
I write this code for adding 4 number but with prefix sum. It means, we need all sum : sum0 , sum1 . ....
but the code dont work.
I will appreciate for any advice.
thanks a lot
I write this code for adding 4 number but with prefix sum. It means, we need all sum : sum0 , sum1 . ....
Code:
module prefix_sum(
input [3:0] data_in,
input clk, rst, ld,
output reg [3:0] sum [0:3]
);
reg [3:0] temp = 4'b0000;
reg [1:0] num = 2'b0;
always @ (posedge clk) begin
if (rst) begin
sum[0] <= 4'b0000;
sum[1] <= 4'b0000;
sum[2] <= 4'b0000;
sum[3] <= 4'b0000;
end else if (!ld) begin
num <= 2'b0;
end else begin
temp <= temp + data_in;
sum[num] <= temp;
num <= num + 1;
end
end
endmodule
but the code dont work.
I will appreciate for any advice.
thanks a lot