-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnidadeFuncional.v
63 lines (56 loc) · 1.29 KB
/
UnidadeFuncional.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
module UnidadeFuncional(clock, instruction, iIn, instructionIn, instructionOut, done, InstAtual, out, disponivelUnidadeFuncional, R1, R2);
input [2:0]instructionIn;
input [15:0]instruction;
input iIn, clock;
input [15:0] R1, R2;
output reg done;
output reg [15:0]out, InstAtual;
output reg[2:0]instructionOut;
output reg disponivelUnidadeFuncional;
integer Latencia;
initial begin
InstAtual = 16'b0000000000001111;
done = 0;
disponivelUnidadeFuncional = 1;
end
always @(posedge clock)
begin
done=0;
if(iIn == 1 && disponivelUnidadeFuncional == 1)
begin
disponivelUnidadeFuncional = 0;
InstAtual = instruction;
Latencia = 0;
instructionOut = instructionIn;
case(instruction[3:0])
4'b0000: out <= R2 + R1;
4'b0001: out <= R2 - R1;
4'b0100: out <= R2 * R1;
4'b0101: out <= R2 / R1;
endcase
end
else
Latencia = Latencia + 1;
// OPS: ADD E SUB
if(InstAtual[3:0] == 4'b0000 || InstAtual[3:0] == 4'b0001)
begin
if(Latencia == 1)
begin
done = 1'b1;
disponivelUnidadeFuncional = 1;
end
end
else
begin
// OPS: MUL E DIV
if(InstAtual[3:0] == 4'b0100 || InstAtual[3:0] == 4'b0101)
begin
if(Latencia == 2)
begin
done = 1'b1;
disponivelUnidadeFuncional = 1;
end
end
end
end
endmodule