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设计方法 ...
随机推荐
- 手算推导BP神经网络
一.神经元 下图的蓝色区域被称为一个"感知机"(Perceptron), 感知机是对信息进行编码.压缩.集成.融合的计算机智能接口系统. 说白了,就是在输入端输入X1~X7这7个输 ...
- CPU性能测试-coremark
测试CPU性能指标会用到 Benchmarks常见的为 Dhrystone 和 CoreMark. CoreMark是一个综合基准,用于测量嵌入式系统中使用的中央处理器(CPU)的性能.它是在2009 ...
- Linxu后台运行Java的jar包
1.直接运行 java -jar myjar-0.0.1-SNAPSHOT.jar 这种方式需要一直挂载终端(Ctrl+C会结束进程.关闭shell也会结束进程),故不符合需求 2.后台运行 A.Ct ...
- node 内存全局配置(--max-old-space-size)
安装完了node和angular之后,使用powershell 窗口进行 ng build --prod打包,会提示内存溢出:JavaScript heap out of memory. 项目内打包解 ...
- springcloud day01
单体架构:业务所有功能都在一个项目中开发,打成一个包部署 优点是架构简单 部署成本低 缺点是 耦合度高 分布式架构:根据业务功能对系统做拆分,每个业务功能模块作为一个独立的项目开发,也称为一个服务 优 ...
- Docker技术知识点总纲
基本介绍的安装使用 1.Docker简要介绍 2.windows下Docker的安装 3.CentOS下Docker的安装 快速入门与常用操作 4.Docker引擎升级与存储驱动的升级 5.Docke ...
- KingbaseES V8R6集群运维案例之---repmgr standby promote应用案例
案例说明: 在容灾环境中,跨区域部署的异地备节点不会自主提升为主节点,在主节点发生故障或者人为需要切换时需要手动执行切换操作.若主节点已经失效,希望将异地备机提升为主节点. $bin/repmgr s ...
- vue项目埋点实践,使用img发送埋点数据
埋点数据种类:1.按钮点击2.页面切换(具体数据内容根据实际需求再定义)埋点数据交互:采用img的默认下载功能,发送get请求,带上埋点数据(此处后期需要加上加密)发送频率:1.固定时间2.固定数据量 ...
- 超强大的PS汉化插件Specs 一键尺寸标注
尺寸标注是大多数设计师必不可少的细节工作,特别是在一些特定的设计图中,标注至关重要.大部分设计大大都直接用CAD标注,其实借助插件,PS也是完全可以搞定常见的尺寸标注的. 插件介绍 这是一款超级强大的 ...
- python 中的lamda 表达式
#1. print(list(filter(lambda x: x%2,range(10)))) #[1, 3, 5, 7, 9]# 非lamda表示def odd(x): return x ...