用Verilog实现一个桶形移位器

用Verilog实现一个桶形移位器实验六桶型移位器实验介绍本实验使用Verilog语言设计实现一个32位桶型移位器。实验目标1.使用ISE软件设计并进行仿真2.学会使用Modelsim3.理解桶型移位器原理,使用logicsim软件搭建一个8位的桶型移位器4.用verilog实现一个32位桶型移位器实验原理桶型移位器是一个多输入、单输出电路。对于输入a[31:0],移位器首先会根据aluc[1:0]值来

实验六 桶型移位器

实验介绍

本实验使用Verilog语言设计实现一个32位桶型移位器。

实验目标


1. 使用ISE软件设计并进行仿真
2. 学会使用Modelsim
3. 理解桶型移位器原理,使用logicsim软件搭建一个8位的桶型移位器
4. 用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代码

代码如下:

`timescale 1ns / 1ps // // 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

今天的文章用Verilog实现一个桶形移位器分享到此就结束了,感谢您的阅读。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/12341.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注