forked from bumblebee17/5-Stage-Pipeline-Processor-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDecode.v
68 lines (61 loc) · 2.37 KB
/
Decode.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
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 23:01:37 04/10/2020
// Design Name:
// Module Name: Decode
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module Decode(clk,rd_wb,w_en_wb,d_in_wb,ins,r1,r2,im_ext,im_addr,ctrl_sig,func,WriteRegister,rs_out,rt_out);
input clk,w_en_wb;
input [4:0] rd_wb; // location
input [31:0] d_in_wb; // Value from Write Back Stage
input[31:0] ins;
output [31:0] im_ext,r1,r2,im_addr;
output [8:0] ctrl_sig;
output [5:0] func;
output [4:0] WriteRegister,rs_out,rt_out;
wire [8:0] ctrl_sig_in; // Control Signal: {RegDst,ALUSrc,MemtoReg,RegWrite,MemRead,MemWrite,Branch,AlUOp_1,ALUOp_0}
wire [4:0] rs,rt,rd;
wire [5:0] opcode;
wire RegDst,ALUSrc,MemtoReg,RegWrite,MemRead,MemWrite,Branch,AlUOp_1,ALUOp_0;
wire [1:0] ALUOp;
wire [15:0] im;
wire [25:0] pc_jump;
wire z;
assign opcode = ins[31:26]; // Assigning bits to opcode variable
control_unit C1(opcode,ctrl_sig_in); // instantiating control unit
assign {RegDst,ALUSrc,MemtoReg,RegWrite,MemRead,MemWrite,Branch,ALUOp_1,ALUOp_0} = ctrl_sig; // concatenating all control variables in a single variable 'ctrl_sig'
assign ALUOp = {ALUOp_1,ALUOp_0}; // concatenating initial 2 bits to variable ALUOp
assign ctrl_sig = ctrl_sig_in;
// R-Type:opcode+rs+rt+rd+shmt+func
assign z = ins[31] | ins[30] | ins[29] | ins[28] | ins[27] | ins[26];
assign rd = ins[15:11];
assign func = z ? ins[31:26] : ins[5:0]; //
// I-Type:opcode+rs+rt+im
assign im = ins[15:0]; //
assign im_ext = {{16{ins[15]}},im}; // sign extended value
// J-Type:opcode+imm
assign im_addr = {{6{ins[25]}},ins[25:0]};
// common
assign rs = ins[25:21];
assign rt = ins[20:16];
// Write Register (MUX)
assign WriteRegister = RegDst? rd : rt; //If RegDst is high then rd will go in writeregister, otherwise rt will go
assign rs_out = rs;
assign rt_out = rt;
reg_bank re1(clk,r1,r2,rs,rt,rd_wb,w_en_wb,d_in_wb); //Instantiating register bank
//reg_bank(clk,r1,r2,rs1,rs2,rd,w_en,d_in);
endmodule