1
votes

If I have both alwas_comb and always_ff in a single module, which one executed first?.

for example, I have seen this code in a book but I am confused about the functionality. for example, if WE=0 what will be the value of Qout?

module SyncRAM #(parameter M = 4, N = 8)(output logic [N-1:0] Qout,
   input logic [M-1:0] Address, input logic [N-1:0] Data, input logic clk, WE);

logic [N-1:0] mem [0:(1<<M)-1];

always_comb
  Qout = mem[Address];

always_ff @(posedge clk)
  if (~WE)
    mem[Address] <= Data;

endmodule

Any help about the truth table of this code is appreciated, regards

1

1 Answers

0
votes

The specific answer to your question is that Qout will just track the value of mem[Address]. In other words, on the rising edge of the clock, if WE is 0, Qout will be driven with the value written to the memory. This is because the memory will behave like a bank of flip-flops, while the Qout output will behave as if it is directly connected to the Q output of a bank of flip-flops.

The order of the execution of the two always blocks is deterministic, because Qout is driven using a blocking assignment (=), whereas the memory is written to using a non-blocking assignment (<=). See the answer here for much more detail.