-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtend.v
More file actions
37 lines (24 loc) · 798 Bytes
/
Copy pathExtend.v
File metadata and controls
37 lines (24 loc) · 798 Bytes
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
`timescale 1ns / 1ps
//unit is used for extend the immediate value for different intruction foramts
module Extend(instr, imm_ext);
input [31:0] instr;
output reg[31:0] imm_ext;
always @(*)
begin
case(instr[6:0])
// I_type
7'b0010011: imm_ext = {{20{instr[31]}}, instr[31:20]};
//I_type ALU
7'b0000011: imm_ext = {{20{instr[31]}}, instr[31:20]};
// S_type (stores)
7'b0100011: imm_ext = {{20{instr[31]}}, instr[31:25], instr[11:7]};
// B_type (branches)
7'b1100111: imm_ext = {{20{instr[31]}}, instr[7], instr[30:25], instr[11:8], 1'b0};
// J_type (jal)
7'b1101111: imm_ext = {{12{instr[31]}}, instr[19:12], instr[20], instr[30:21], 1'b0};
// U_type
7'b0110111: imm_ext = {instr[31:12], 12'b0};
default: imm_ext = 32'bx; // undefined
endcase
end
endmodule