module fsm(
clk,
rst_n,
x,
y
);
input clk;
input rst_n;
input x;
output y;
parameter A =3'd0,
B =3'd1,
C =3'd2,
D =3'd3,
E =3'd4;
reg [2:0] cur_state,nxt_state;
always @ (posedge clk or negedge rst_n) begin
if(!rst_n) begin
cur_state <= A;
end
else begin
cur_state <= nxt_state;
end
end
always @(*) begin
if(!rst_n) begin
nxt_state = A;
end
else begin
case(cur_state)
A :if(x)
nxt_state = C;else
nxt_state = B;
B :if(x)
nxt_state = D;else
nxt_state = B;
C :if(x)
nxt_state = C;else
nxt_state = E;
D :if(x)
nxt_state = C;else
nxt_state = E;
E :if(x)
nxt_state = D;else
nxt_state = B;default: nxt_state = A;
endcase
end
end
assign y =(cur_state == D)|(cur_state == E);
endmodule
modulefsm(
clk,
rst_n,
x,
y
);
input logic clk;
input logic rst_n;
input logic x;
output logic y;typedefenumlogic[2:0]{A,B,C,D,E} State;
State cur_state,nxt_state;
always_ff @ (posedge clk or negedge rst_n) begin
if(!rst_n) begin
cur_state <= A;
end
else begin
cur_state <= nxt_state;
end
end
always_comb begin
if(!rst_n) begin
nxt_state = A;
end
else begin
case(cur_state)
A :if(x)
nxt_state = C;else
nxt_state = B;
B :if(x)
nxt_state = D;else
nxt_state = B;
C :if(x)
nxt_state = C;else
nxt_state = E;
D :if(x)
nxt_state = C;else
nxt_state = E;
E :if(x)
nxt_state = D;else
nxt_state = B;default: nxt_state = A;
endcase
end
end
assign y =(cur_state == D)|(cur_state == E);
endmodule
文章目录 RNA折叠RNA folding representation1 DP for simple folds1.1 Nussinov Algorithm objective1.2 energy constraints1.3 The key idea of the algorithm 2 DP for stacking and complex foldsStochastic context free grammars 来自Manolis Kellis教授(MIT…