heron_sqrt/verilog/heron_fsm.v

69 lines
1.5 KiB
Coq
Raw Normal View History

2014-01-08 15:35:30 +00:00
`include "heron_states.v"
2014-01-02 12:01:07 +00:00
2014-01-08 15:35:30 +00:00
module heron_fsm(clk, load, reset, flag_z, flag_c, flag_s, state);
2014-01-02 12:01:07 +00:00
input clk;
input load;
input reset;
input flag_z;
input flag_c;
input flag_s;
output [3:0] state;
reg [3:0] state;
reg [3:0] next_state;
always @(posedge clk or posedge reset)
if(reset) begin
2014-01-08 15:35:30 +00:00
state <= `IDLE;
2014-01-02 12:01:07 +00:00
end else begin
state <= next_state;
end
always @(state or flag_z or load)
case(state)
2014-01-08 15:35:30 +00:00
`IDLE: begin
2014-01-02 12:01:07 +00:00
if(load) begin
2014-01-08 15:35:30 +00:00
next_state = `LD_N_1;
2014-01-02 12:01:07 +00:00
end else begin
2014-01-08 15:35:30 +00:00
next_state = `IDLE;
2014-01-02 12:01:07 +00:00
end
2014-01-08 15:35:30 +00:00
end
`LD_N_1: next_state = `LD_N_2;
`LD_N_2: next_state = `I_GT_ZERO;
`I_GT_ZERO: begin
2014-01-02 12:01:07 +00:00
if (flag_z) begin
2014-01-08 15:35:30 +00:00
next_state = `LD_S_1;
2014-01-02 12:01:07 +00:00
end else begin
2014-01-08 15:35:30 +00:00
next_state = `IDLE;
2014-01-02 12:01:07 +00:00
end
2014-01-08 15:35:30 +00:00
end
`LD_S_1: next_state = `LD_S_2;
`LD_S_2: next_state = `S_GT_ONE;
`S_GT_ONE: begin
2014-01-02 12:01:07 +00:00
if (flag_s || flag_z) begin
2014-01-08 15:35:30 +00:00
next_state = `STORE_X;
2014-01-02 12:01:07 +00:00
end else begin
2014-01-08 15:35:30 +00:00
next_state = `X_1;
2014-01-02 12:01:07 +00:00
end
2014-01-08 15:35:30 +00:00
end
`X_1: next_state = `DIV_2;
`DIV_1: next_state = `DIV_2;
`DIV_2: next_state = `DIV_3;
`DIV_3: next_state = `DIV_4;
`DIV_4: next_state = `OLD_X_LTE_X_1;
`OLD_X_LTE_X_1: next_state = `OLD_X_LTE_X_2;
`OLD_X_LTE_X_2: begin
2014-01-02 12:01:07 +00:00
if (flag_c) begin
2014-01-08 15:35:30 +00:00
next_state = `DIV_1;
2014-01-02 12:01:07 +00:00
end else begin
2014-01-08 15:35:30 +00:00
next_state = `STORE_X;
2014-01-02 12:01:07 +00:00
end
2014-01-08 15:35:30 +00:00
end
`STORE_X: next_state = `DEC_I;
`DEC_I: next_state = `I_GT_ZERO;
2014-01-02 12:01:07 +00:00
endcase
endmodule
2014-01-10 12:22:11 +00:00