No15-原-用Verilog实现一个桶形移位器
实验六 桶型移位器
实验介绍
本实验使用Verilog语言设计实现一个32位桶型移位器。
实验目标
- 使用ISE软件设计并进行仿真
- 学会使用Modelsim
- 理解桶型移位器原理,使用logicsim软件搭建一个8位的桶型移位器
- 用verilog实现一个32位桶型移位器
实验原理
桶型移位器是一个多输入、单输出电路。对于输入a[31:0],移位器首先会根据aluc[1:0]值来确定做何种移位,然后根据b[4:0]的值来确定移多少位,最后将结果c[31:0]输出。
下表为aluc的值所对应的运算:
MIPS指令 | alu[1] | alu[0] | 说明 |
---|---|---|---|
算术右移(sra) | 0 | 0 | a向右移动b位,最高位补b位符号位 |
逻辑右移(srl) | 0 | 1 | a向右移动b位,最高位补b位0 |
算术左移(sll) | 1 | 0 | a向左移动b位,最低位补b位0 |
逻辑左移(sll) | 1 | 1 | a向左移动b位,最低位补b位0 |
下图为桶型移位器的逻辑流程图,可根据其流程编写行为及的桶型移位器
Verilog代码
代码如下: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
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 14:17:05 11/13/2015
// Design Name:
// Module Name: barrelshifter32
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module barrelshifter32(
input [31:0] a, // 32 位原始输入数据
input [4:0] b, // 5 位输入数据,控制移位的位数
input [1:0] aluc, // 2 位输入控制移位的方式
output reg [31:0] c // 32 位输出,由a 经过b 位通过aluc 指定的移位方式移位而得
);
reg [31:0] temp;
always @ (a or b or aluc) begin
case(aluc)
2'b00: begin
temp = b[0] ? {{a[31]}, a[31:1]} : a;
temp = b[1] ? {{2{temp[31]}}, temp[31:2]} : temp;
// b = sext ? {{(32-WIDTH){a[WIDTH-1]}},a} : {32'b0, a};
temp = b[2] ? {{4{temp[31]}}, temp[31:4]} : temp;
temp = b[3] ? {{8{temp[31]}}, temp[31:8]} : temp;
temp = b[4] ? {{16{temp[31]}}, temp[31:16]} : temp;
end
2'b01: begin
temp = b[0] ? {32'b0, a[31:1]} : a;
temp = b[1] ? {32'b0, temp[31:2]} : temp;
temp = b[2] ? {32'b0, temp[31:4]} : temp;
temp = b[3] ? {32'b0, temp[31:8]} : temp;
temp = b[4] ? {32'b0, temp[31:16]} : temp;
end
2'b10, 2'b11: begin
temp = b[0] ? {{a[30:0]}, 1'b0} : a;
temp = b[1] ? {{temp[29:0]}, 2'b0} : temp;
temp = b[2] ? {{temp[27:0]}, 4'b0} : temp;
temp = b[3] ? {{temp[23:0]}, 8'b0} : temp;
temp = b[4] ? {{temp[15:0]}, 16'b0} : temp;
end
endcase
c = temp;
end
endmodule
感谢
感谢访问我的个人博客的朋友,如果您感觉本站对您搜索的问题有所帮助,并感觉对本站还满意的话,顶一下吧,希望您把本站分享给您的朋友!在此对您表示由衷的谢意!
文章作者:王用
发布时间:2015-11-14 13:37:15
原始链接:http://blog.54yongf.com/计算机组成原理/15.html
许可协议: "署名-非商用-相同方式共享 3.0" 转载请保留原文链接及作者。