-
Notifications
You must be signed in to change notification settings - Fork 0
/
lc_EX.v
136 lines (126 loc) · 3.74 KB
/
lc_EX.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
`timescale 1ns / 1ps
`include "opcodes.v"
module LC_EX(
input [`WORD_SIZE-1:0] PC,
input [`WORD_SIZE-1:0] instruction,
input [`WORD_SIZE-1:0] A,
input [`WORD_SIZE-1:0] B,
output reg [`WORD_SIZE-1:0] realPC,
output reg aluSrcA,
output reg aluSrcB,
output reg [5:0] func
);
// parse instruction
wire [3:0] inst_opcode = instruction[15:12];
wire [5:0] inst_func = instruction[5:0];
reg realPC;
always @(*) begin
aluSrcA = 0;
aluSrcB = 0;
case(inst_opcode)
`OPCODE_ADI:
begin
func = `FUNC_ADI;
aluSrcA = 1;
aluSrcB = 1;
realPC = PC+1;
end
`OPCODE_ORI:
begin
func = `FUNC_ORI;
aluSrcA = 1;
aluSrcB = 1;
realPC = PC+1;
end
`OPCODE_LHI:
begin
func = `FUNC_LHI;
aluSrcA = 1;
aluSrcB = 1;
realPC = PC+1;
end
`OPCODE_LWD:
begin
func = `FUNC_LWD;
aluSrcA = 1;
aluSrcB = 1;
realPC = PC+1;
end
`OPCODE_SWD:
begin
func = `FUNC_SWD;
aluSrcA = 1;
aluSrcB = 1;
realPC = PC+1;
end
`OPCODE_BNE:
begin
func = `FUNC_BPC;
aluSrcB = 1;
if(A != B) realPC = PC + 1 + {{8{instruction[7]}}, instruction[7:0]};
else realPC = PC + 1;
end
`OPCODE_BEQ:
begin
func = `FUNC_BPC;
aluSrcB = 1;
if(A == B) realPC = PC + 1 + {{8{instruction[7]}}, instruction[7:0]};
else realPC = PC + 1;
end
`OPCODE_BGZ:
begin
func = `FUNC_BPC;
aluSrcB = 1;
if(A[15] == 0 && A[14:0] > 0) realPC = PC + 1 + {{8{instruction[7]}}, instruction[7:0]};
else realPC = PC + 1;
end
`OPCODE_BLZ:
begin
func = `FUNC_BPC;
aluSrcB = 1;
if(A[15] == 1) realPC = PC + 1 + {{8{instruction[7]}}, instruction[7:0]};
else realPC = PC + 1;
end
`OPCODE_JMP:
begin
realPC = {PC[15:12], instruction[11:0]};
end
`OPCODE_JAL:
begin
func = `FUNC_JPC;
aluSrcA = 0;
realPC = {PC[15:12], instruction[11:0]};
end
`OPCODE_RRR:
begin
if(inst_func == `FUNC_JPR) begin
func = `FUNC_A;
aluSrcA = 1;
realPC = A;
end
else if(inst_func == `FUNC_JRL) begin
func = `FUNC_JPC;
aluSrcA = 0;
realPC = A;
end
else if(inst_func == `FUNC_HLT) begin
end
else if(inst_func == `FUNC_WWD) begin
func = `FUNC_A;
aluSrcA = 1;
realPC = PC + 1;
end
else begin
func = inst_func;
aluSrcA = 1;
aluSrcB = 0;
realPC = PC + 1;
end
end
`OPCODE_NOP:
begin
realPC = `WORD_SIZE'bz;
end
endcase
end
endmodule