The third step to translating a flip-flop is to build an always block that replaces the flip-flop instantiations - the three statements that begin with dFF as in the example below.
dFF a_reg ( new_a, clk, a );
dFF b_reg ( new_b, clk, b );
dFF c_reg ( new_c, clk, c );
always @ ( posedge clk ) begin
a = new_a ;
b = new_b ;
c = new_c ;
end
module simple ( d, e, f, load, clk, zero );
input d, e, f, load, clk;
output zero;
reg new_a, new_b, new_c;
module new_simple ( d, e, f, load, clk, zero );
input d, e, f, load, clk;
output zero;
reg zero;
reg a, b, c;
reg new_a, new_b, new_c;
The following example shows the complete new module with always blocks.
module new_simple ( d, e, f, load, clk, zero );
input d, e, f, load, clk;
output zero;
reg zero;
reg a, b, c;
reg new_a, new_b, new_c;
always @ ( a or b or c or d or e or f or load ) begin
if ( load ) begin
new_a = d;
new_b = e;
new_c = f;
end
else begin
new_a = a;
new_b = b;
new_c = c;
end
if ( a==0 & b==0 & c==0 )
zero=1;
else
zero=0;
end
always @ ( posedge clk ) begin
a = new_a ;
b = new_b ;
c = new_c ;
end
endmodule