HDLbits——Shift18
// Build a 64-bit arithmetic shift register,
// with synchronous load. The shifter can shift both left and right,
// and by 1 or 8 bit positions, selected by amount.
// An arithmetic(算数) right shift shifts in the sign bit of the number in the shift register (q[63] in this case) instead of zero as done by a logical right shift. Another way of thinking about an arithmetic right shift is that it assumes the number being shifted is signed and preserves the sign, so that arithmetic right shift divides a signed number by a power of two.
// There is no difference between logical and arithmetic left shifts.
// load: Loads shift register with data[63:0] instead of shifting.
// ena: Chooses whether to shift.
// amount: Chooses which direction and how much to shift.
// 2'b00: shift left by 1 bit.
// 2'b01: shift left by 8 bits.
// 2'b10: shift right by 1 bit.
// 2'b11: shift right by 8 bits.
// q: The contents of the shifter.
**注意**:算数右移和逻辑右移的区别
>>逻辑右移不考虑符号位,空缺的位置补领操作即可
>>算数右移动需要考虑符号位,右移一位,如果符号位为1,则在符号位补1,如果符号位为0,则在符号位补0.即算数右移后,空缺的位置补符号位的数字即可
module top_module(
input clk,
input load,
input ena,
input [1:0] amount,
input [63:0] data,
output reg [63:0] q);
always @(posedge clk)begin
if(load)begin
q <= data;
end
else if(ena) begin
case(amount)
2'b00: q <= {q[62:0],1'b0};
2'b01: q <= {q[55:0], 8'b0};
2'b10: q <= {q[63],q[63:1]};//有符号数右移动 如果符号位为1,则右移后是补1;如果符号位为0,则右移后是补0
2'b11: q <= { { 8{q[63]} },q[63:8]};
endcase
end
else q <= q;
end
endmodule
仿真图:


原理图:

HDLbits——Shift18的更多相关文章
- 学会使用Hdlbits网页版Verilog代码仿真验证平台
给大家推荐一款网页版的 Verilog代码编辑仿真验证平台,这个平台是国外的一家开源FPGA学习网站,通过“https://hdlbits.01xz.net/wiki/Main_Page” 地址链接进 ...
- HDLBits答案——Circuits
1 Combinational Logic 1.1 Basic Gates 1.1.1 Exams/m2014 q4h module top_module ( input in, output out ...
- HDLBits答案——Verification: Writing Testbenches
1 clock module top_module ( ); reg clk; dut U1(.clk(clk)); initial begin clk = 0; end always begin # ...
- HDLBits答案——Verification: Reading Simulations
1 Finding bugs in code 1.1 Bugs mux2 module top_module ( input sel, input [7:0] a, input [7:0] b, ou ...
- HDLBits答案——Verilog Language
Verilog Language 1 Basics 1.1 Wire module top_module( input in, output out ); assign out = in; endmo ...
- HDLBits答案——Getting started
Getting started 1 Step one module top_module( output one ); // Insert your code here assign one = 1' ...
- verilog常见错误列表
Error/Warning 来源:https://hdlbits.01xz.net/wiki/ 题目: 1.Quartus Warning 10235: Warning (): Verilog HDL ...
- Verilog HDL
https://wenku.baidu.com/view/9943b7acf524ccbff1218463.html https://hdlbits.01xz.net/wiki/Main_Page h ...
- Verilog设计技巧实例及实现
Verilog设计技巧实例及实现 1 引言 最近在刷HDLBits的过程中学习了一些Verilog的设计技巧,在这里予以整理.部分操作可能降低代码的可读性和Debug的难度,请大家根据实际情况进行使用 ...
- 入行数字IC验证的一些建议
0x00 首先,推荐你看两本书,<"胡"说IC菜鸟工程师完美进阶>(pdf版本就行)本书介绍整个流程都有哪些岗位,充分了解IC行业的职业发展方向.<SoC设计方法 ...
随机推荐
- PXE自动安装linux系统
一.PXE自动安装Linux系统的大致流程 1.环境准备 2.安装所需的必要软件包并开启对应的服务 3.准备安装源 4.准备自动应答文件,并放到可以被访问到的地方 5.配置DHCP服务并启动 6.将必 ...
- vite中使用img标签
<img class="icon-logo" :src="iconsUrl[imgName]" alt="" /> const ...
- cisco-RIPv2重分发缺省路由
项目设计: 网络拓扑图: IP地址规划表 设备 端口 接口模式 绑定vlan IP地址 对端设备 端口 IP地址 R1 Fa0/0 无 无 172.16.1.1/30 R2 Fa0/0 172.16. ...
- 创建异步倒计时触发Task
https://www.cnblogs.com/shanfeng1000/p/13402152.html //Task关闭 CancellationTokenSource cancel = new C ...
- web开发(1): html简介/ sublime text3使用/VScode使用
导论 web设计概述 web的核心特征是超链接. web应用:浏览器看新闻:访问网页 非web的网络应用: QQ. 微信 web的组织:W3C 1994年成立,负责管理和维护与web相关的各种技术标准 ...
- js-惰性函数
1. 需求:我们现在需要写一个 foo 函数,这个函数返回首次调用时的 Date 对象,注意是首次. 使用场景:当我们每次都需要进行条件判断,其实只需要判断一次,接下来的使用方式都不会发生改变的时候, ...
- linux忘记密码-进入单用户模式修改密码
1.重启系统 重启可以使用命令 reboot.init 6.shutdown -r now 或点击VMware-虚拟机-电源-重新启动客户机 2.进入GRUB界面 重启后,在启动界面按上下方向键选择第 ...
- pip 下载换源
命令:[pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple]
- ADE-XL bsub提交超时
查找命令行log, Fatal server error: could not open default font 'fixed' 解决方案: yum install 'xorg-x11-font*'
- python常用的六个字符串处理方法
1.upper(将小写字母转换为大写) 语法: str.upper() 参数: NA 实例: a = 'abc' b = a.upper() print(b) 结果: ABC 2.lower(将小写字 ...