-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.v
138 lines (118 loc) · 3.38 KB
/
utils.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
137
module mux8to1_8bit( input [7:0] in0,in1,in2,in3,in4,in5,in6,in7, input [2:0] Sel, output reg [7:0] outBus );
always@(in0 or in1 or in2 or in3 or in4 or in5 or in6 or in7 or Sel)
case (Sel)
3'b000: outBus=in0;
3'b001: outBus=in1;
3'b010: outBus=in2;
3'b011: outBus=in3;
3'b100: outBus=in4;
3'b101: outBus=in5;
3'b110: outBus=in6;
3'b111: outBus=in7;
endcase
endmodule
module mux2to1_8bit( input [7:0] in0,in1, input Sel, output reg [7:0] outBus );
always@(in0 or in1 or Sel)
case (Sel)
1'b0: outBus=in0;
1'b1: outBus=in1;
endcase
endmodule
module mux8to1_32bit( input [31:0] in0,in1,in2,in3,in4,in5,in6,in7, input [2:0] Sel, output reg [31:0] outBus );
always@(in0 or in1 or in2 or in3 or in4 or in5 or in6 or in7 or Sel)
case (Sel)
3'b000: outBus=in0;
3'b001: outBus=in1;
3'b010: outBus=in2;
3'b011: outBus=in3;
3'b100: outBus=in4;
3'b101: outBus=in5;
3'b110: outBus=in6;
3'b111: outBus=in7;
endcase
endmodule
module mux4to1_32bit( input [31:0] in0,in1,in2,in3, input [1:0] Sel, output reg [31:0] outBus );
always@(in0 or in1 or in2 or in3 or Sel)
case (Sel)
2'b00: outBus=in0;
2'b01: outBus=in1;
2'b10: outBus=in2;
2'b11: outBus=in3;
endcase
endmodule
module mux2to1_32bit( input [31:0] in0,in1, input Sel, output reg [31:0] outBus );
always@(in0 or in1 or Sel)
case (Sel)
1'b0: outBus=in0;
1'b1: outBus=in1;
endcase
endmodule
module mux2to1_1bit( input in0, in1, input Sel, output reg outBus );
always@(in0 or in1 or Sel)
case (Sel)
1'b0: outBus=in0;
1'b1: outBus=in1;
endcase
endmodule
// Sign extension : 3,5,8,11 bits
module signExt3to32( input [2:0] offset, output reg [31:0] signExtOffset);
//Write your code here
always@(offset)
begin
case(offset[2])
1'b0: signExtOffset = { 29'b00000000000000000000000000000, offset};
1'b1: signExtOffset = { 29'b11111111111111111111111111111, offset};
endcase
end
endmodule
module signExt5to32( input [4:0] offset, output reg [31:0] signExtOffset);
//Write your code here
always@(offset)
begin
case(offset[4])
1'b0: signExtOffset = { 27'b000000000000000000000000000, offset};
1'b1: signExtOffset = { 27'b111111111111111111111111111, offset};
endcase
end
endmodule
module signExt8to32( input [7:0] offset, output reg [31:0] signExtOffset);
//Write your code here
always@(offset)
begin
case(offset[7])
1'b0: signExtOffset = { 24'b00000000000000000000000, offset};
1'b1: signExtOffset = { 24'b111111111111111111111111, offset};
endcase
end
endmodule
module signExt11to32( input [10:0] offset, output reg [31:0] signExtOffset);
//Write your code here
always@(offset)
begin
case(offset[10])
1'b0: signExtOffset = { 21'b000000000000000000000, offset};
1'b1: signExtOffset = { 21'b111111111111111111111, offset};
endcase
end
endmodule
module zeroExt8to32( input [7:0] offset, output reg [31:0] zeroExtOffset);
always@(offset)
begin
zeroExtOffset = { 24'b000000000000000000000000, offset};
end
endmodule
module decoder3to8( input [2:0] encoded, output reg [7:0] decOut);
always@(encoded)
begin
case(encoded)
3'b000: decOut=8'b00000001;
3'b001: decOut=8'b00000010;
3'b010: decOut=8'b00000100;
3'b011: decOut=8'b00001000;
3'b100: decOut=8'b00010000;
3'b101: decOut=8'b00100000;
3'b110: decOut=8'b01000000;
3'b111: decOut=8'b10000000;
endcase
end
endmodule