-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.v
60 lines (56 loc) · 1.75 KB
/
controller.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
`timescale 1ns / 1ps
//`include "ALU_design.v"
module controller
#(
//parameters
parameter NB_DATA = 8,
parameter NB_OPCODE = 6,
parameter N_PULSADORES = 3
)
(
input wire signed [NB_DATA-1:0] i_switches,
input wire [N_PULSADORES-1:0] i_pulsadores,
input wire i_clock,
input wire i_reset,
output wire signed [NB_DATA-1:0] o_result
);
// internal registers to store inputs
reg signed [NB_DATA-1:0] operandA;
reg signed [NB_DATA-1:0] operandB;
reg [NB_OPCODE-1:0] opcode;
always @(posedge i_clock)
begin
if(i_reset)
begin
operandA <= {NB_DATA {1'b0}};
operandB <= {NB_DATA {1'b0}};
opcode <= {NB_OPCODE {1'b0}};
end
else
begin
case(i_pulsadores)
{{N_PULSADORES-3 {1'b0}}, 3'b001}: operandA <= i_switches;
{{N_PULSADORES-3 {1'b0}}, 3'b010}: operandB <= i_switches;
{{N_PULSADORES-3 {1'b0}}, 3'b100}: opcode <= i_switches; //pulsador 2: switches -> opcode
default: // by default we keep the previous values
begin
operandA <= operandA;
operandB <= operandB;
opcode <= opcode;
end
endcase
end
end
alu
#(
.NB_DATA (NB_DATA),
.NB_OPCODE (NB_OPCODE)
)
dut
(
.i_op_1 (operandA),
.i_op_2 (operandB),
.i_opcode(opcode),
.o_result(o_result)
);
endmodule