-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSignExtendModule.v
32 lines (27 loc) · 966 Bytes
/
SignExtendModule.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
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// fullname : Milad Nooraei
// student number : 9935701
// Computer Architecture HomeWork 1
//////////////////////////////////////////////////////////////////////////////////
module SignExtendModule(
input [11:0]immediate,
input [4:0]rd,
input [6:0]opcode,
output reg[31:0] result
);
always @(*) begin
if (opcode == 7'b0110011) //R-type
result = {{20{immediate[11]}}, immediate[11:0]};
else if (opcode == 7'b1100011) //Branch
result = {{20{immediate[11]}}, immediate[11], rd[0], immediate[10:5], rd[4:1]};
else if (opcode == 7'b0000011) //Load
result = {{20{immediate[11]}}, immediate[11:0]};
else if (opcode == 7'b0100011) //Store
result = {{20{immediate[11]}}, immediate[11:5], rd};
else if (opcode == 7'b0010011) //Immediate
result = {{20{immediate[11]}}, immediate[11:0]};
else //Default
result = 0;
end
endmodule