Hardware Reference
In-Depth Information
1 //Module header:---------------------------------------------
2 module control_unit_for_multiplier
3
#(parameter N=4) //number of bits
4
(
5
input logic dv, prod, clk, rst,
6
output logic wrR1, sel, wrR2, shft,
7
output logic [1:0] ALUop);
8
9 //Declarations:----------------------------------------------
10
11
//FSM-related declarations:
12
typedef enum logic [2:0]
13
{idle, load, waitt, nop, add, shift} state;
14
state pr_state, nx_state;
15
16
//Auxiliary-register-related declarations:
17
logic [$clog2(N):0] i, i_reg; //function ceiling(log2(N))
18
19 //Statements:------------------------------------------------
20
21
// Auxiliary register:
22
always_ff @(posedge clk, posedge rst)
23
if (rst) i_reg <= 0;
24
else i_reg <= i;
25
26
//FSM state register:
27
always_ff @(posedge clk, posedge rst)
28
if (rst) pr_state <= idle;
29
else pr_state <= nx_state;
30
31
//FSM combinational logic:
32
always_comb begin
33
34
//Default values:
35
wrR1 <= 'b0;
36
sel <= 'b0;
37
wrR2 <= 'b0;
38
shft <= 'b0;
39
ALUop <= 2'b00;
40
i <= 0;
41
42
case (pr_state)
43
idle:
44
if (dv) nx_state <= load;
45
else nx_state <= idle;
46
load: begin
47
wrR1 <= 'b1;
48
sel <= 'b1;
49
wrR2 <= 'b1;
50
nx_state <= waitt;
51
end
52
waitt: begin
53
i <= i_reg;
54
if (~prod) nx_state <= nop;
55
else nx_state <= add;
Search WWH ::




Custom Search