I have the following code:
always @ (posedge clk or posedge reset) begin
if (reset) begin
count <= 0;
end else begin
if (rd_en) begin
count <= count - 1;
end else begin
count <= count;
end
if (wr_en) begin
count <= count + 1;
end else begin
count <= count;
end
end
end
If rd_en
and wr_en
occur at the same time, will the count <= count + 1
be nullified by count <= count - 1
, or will the addition due to the wr_en
take effect as it was the final assignment (or code wise it was the last remaining assignment) to the count
register?
Is the below one a better code which specifies the design intent more clearly?
if (rd_en && wr_en) begin
count <= count;
end else if (rd_en) begin
count <= count - 1;
end else if (wr_en) begin
count <= count + 1;
end else begin
count <= count;
end