-
Notifications
You must be signed in to change notification settings - Fork 0
/
draft2_wrapper
60 lines (47 loc) · 1.05 KB
/
draft2_wrapper
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
60
module ALU_ROM_Wrapper(
input [1:0] Opcode,
input [15:0] Input_A,
input [15:0] Input_B,
output reg [15:0] Result
);
parameter IDLE = 2'b00;
parameter LOAD = 2'b01;
parameter STORE = 2'b10;
reg [1:0] state;
reg [15:0] Data_from_memory;
alu16 ALU_instance (
.a(Input_A),
.b(Input_B),
.op(Opcode),
.y(Result)
);
always @(*) begin
case (state)
IDLE: begin
if (Opcode == 2'b01)
state = LOAD;
else if (Opcode == 2'b10)
state = STORE;
else
state = IDLE;
end
LOAD: begin
Data_from_memory = Fetch_from_memory(Input_A);
state = IDLE;
end
STORE: begin
Store_in_memory(Input_A, Input_B);
state = IDLE;
end
default: state = IDLE;
endcase
end
function [15:0] Fetch_from_memory;
input [15:0] Address;
Fetch_from_memory = ...;
endfunction
function Store_in_memory;
input [15:0] Address, Data;
...;
endfunction
endmodule