Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module srt(input [7:0] IN,
- output reg [7:0] QUOTIENT,
- output reg [7:0] REMAINDER,
- input clk,
- input rst);
- localparam BEGIN = 0;
- localparam INA = 1;
- localparam INQ = 2;
- localparam INM = 3;
- localparam NOR = 4;
- localparam T1 = 5;
- localparam T2 = 6;
- localparam COR = 7;
- localparam T3 = 8;
- localparam OUTQ = 9;
- localparam OUTA = 10;
- localparam ADD = 11;
- localparam SUB = 12;
- reg [3:0] s_current, s_next;
- reg [8:0] a_current, a_next;
- reg [7:0] m_current, m_next;
- reg [7:0] q_current, q_next;
- reg [7:0] q1_current, q1_next;
- reg [2:0] count, count_next;
- reg [2:0] countc, countc_next;
- always@( posedge clk, negedge rst)
- begin
- if(!rst)
- begin
- a_current<=0;
- m_current<=0;
- q_current<=0;
- q1_current<=0;
- count<=0;
- countc<=0;
- s_current<=BEGIN;
- end
- else
- begin
- a_current<=a_next;
- m_current<=m_next;
- q_current<=q_next;
- q1_current<=q1_next;
- s_current<=s_next;
- count<=count_next;
- countc<=countc_next;
- end
- end
- always@(*)
- begin
- a_next=a_current;
- m_next=m_current;
- q_next=q_current;
- q1_next=q1_current;
- s_next=s_current;
- count_next=count;
- countc_next=countc;
- QUOTIENT=0;
- REMAINDER=0;
- case(s_current)
- BEGIN:
- begin
- s_next=INA;
- end
- INA:
- begin
- a_next=IN;
- s_next=INQ;
- end
- INQ:
- begin
- q_next=IN;
- s_next=INM;
- end
- INM:
- begin
- m_next=IN;
- s_next=NOR;
- end
- NOR:
- begin
- if(m_current[7]==1)
- s_next=T1;
- else
- begin
- m_next={m_current[7:0],1'b0};
- a_next={a_current[7:0],q_current[7]};
- q_next={q_current[6:0],m_current[7]};
- countc_next=countc+1;
- s_next=NOR;
- end
- end
- T1:
- begin
- if(a_current[8:6]==3'b000 || a_current[8:6]==3'b111)
- begin
- a_next={a_current[7:0],q_current[7]};
- q_next={q_current[6:0],1'b0};
- q1_next={q1_current[6:0],1'b0};
- count_next=count+1;
- s_next=T2;
- end
- else if(a_current[8]==1)
- begin
- a_next={a_current[7:0],q_current[7]};
- q_next={q_current[6:0],1'b0};
- q1_next={q1_current[6:0],1'b1};
- count_next=count+1;
- s_next=ADD;
- end
- else
- begin
- a_next={a_current[7:0],q_current[7]};
- q_next={q_current[6:0],1'b1};
- q1_next={q1_current[6:0],1'b0};
- count_next=count+1;
- s_next=SUB;
- end
- end
- ADD:
- begin
- a_next=a_current+m_current;
- s_next=T2;
- end
- SUB:
- begin
- a_next=a_current-m_current;
- s_next=T2;
- end
- T2:
- begin
- if(count!=3'b111)
- s_next=T1;
- else
- begin
- a_next={a_current[7:0],q_current[7]};
- q_next={q_current[6:0],1'b0};
- q1_next={q1_current[6:0],1'b0};
- s_next=COR;
- end
- end
- COR:
- begin
- if(a_current[8]==1)
- begin
- a_next=a_current+m_current;
- q_next=q_current-1;
- end
- s_next=T3;
- end
- T3:
- begin
- if(countc!=0)
- a_next=a_current>>countc;
- s_next=OUTQ;
- end
- OUTQ:
- begin
- QUOTIENT<=q_current-q1_current;
- s_next=OUTA;
- end
- OUTA:
- begin
- REMAINDER<=a_current;
- end
- endcase
- end
- endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement