HDLbits——Rotate100
2024-10-21 17:28:28
verilog代码:
// Build a 100-bit left/right rotator, with synchronous load and left/right enable.
//A rotator shifts-in the shifted-out bit from the other end of the register,
// unlike a shifter that discards the shifted-out bit and shifts in a zero. If enabled,
// a rotator rotates the bits around and does not modify/discard them.
// 移出的一位不会丢弃而是补在空缺的位置,即就是题目中的a rotator要求
// load: Loads shift register with data[99:0] instead of rotating.
// ena[1:0]: Chooses whether and which direction to rotate.
// 2'b01 rotates right by one bit
// 2'b10 rotates left by one bit
// 2'b00 and 2'b11 do not rotate.
// q: The contents of the rotator.
module top_module(
input clk,
input load,
input [1:0] ena,
input [99:0] data,
output reg [99:0] q);
always @(posedge clk)
begin
if(load)begin
q <= data;
end
else begin
case(ena)
2'b01: q <= {q[0],q[99:1]};//拼接运算符号{,} ,向右移动1bit
2'b10: q <= {q[98:0],q[99]};//向左边移动1bit
2'b00,2'b11:q <= q; // 保持
default:
q<= q; //所有情况考虑完整的情况下,此处可以省略
endcase
end
end
endmodule
RTL原理图:
最新文章
- ubuntu处理中文时设置locale
- 【BZOJ 2005】【NOI 2010】能量采集 数论+容斥原理
- Java的自动装箱和拆箱的简单讲解
- xcode7.3 升级 xcode8.0 后权限设置问题(升级xcode 8.0 后构建版本不显示问题)
- GML、SVG、VML的比较
- wxWidgets+wxSmith版电子词典
- Mock原理学习
- docker installation on ubuntu
- OC语言(六)
- kafka 集群
- MVC Views文件夹下js无法访问问题解决方案
- exec 命令简单用法 和 find 搭配用法示例
- gcc生成含有C信息的汇编
- Solve Error: nafxcw.lib(afxmem.obj) : error LNK2005: ";void * __cdecl operator new[](unsigned int)"; (??_U@YAPAXI@Z) already defined in libcpmt.lib(newaop.obj)
- MT【234】正方形染色(二)
- Unity3d跨平台原理
- SpringCloud+Boot简单例子笔记
- 更改MySQL数据库目录位置[zz]
- 玩转mongodb(一):初识mongodb
- 【转载】C++创建对象的两种方法