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设计方法 ...
随机推荐
- 安全测试-WEB安全渗透测试基础知识(五)
1.5. 代码审计 1.5.1. 简介 代码审计是找到应用缺陷的过程.其通常有白盒.黑盒.灰盒等方式.白盒指通过对源代码的分析找到应用缺陷,黑盒通常不涉及到源代码,多使用模糊测试的方式,而灰盒则是黑白 ...
- C++ 手动创建二叉树,并实现前序、中序、后序、层次遍历
二叉树的创建是个麻烦事,我的思路是:首先将一个普通的二叉树转化为满二叉树,其中的空节点用一些标识数据来代替,如此一来,就可以用数组索引来描述数据在二叉树的什么位置了. 比如,数组[2,4,3,1,5, ...
- 前端下载csv文件
var str = [ 'ssssssssssssssssssssssssssssssssssssssss' ]; var uri = 'data:text/csv;charset=utf-8,%EF ...
- cuda、cudnn、tnesorrt的查看安装
1.首先本地查看cuda已安装的版本 11.7输入命令:[nvcc -V]输出:nvcc: NVIDIA (R) Cuda compiler driverCopyright (c) 2005-2022 ...
- HIVE-CREATE TABLE
(1) create table 表A as select 字段 from 表B; (2) create table 表A stored as parquet as select 字段 from 表B ...
- Flink常见问题解决记录
1.Hardlink from files of previous local stored state might cross devices 开启了state.backend.local-reco ...
- gitee 操作
腾讯软件搜索 腾讯软件中心-海量软件高速下载 (qq.com) git,下载 git,安装.右键git bash here,输入,Git clone url地址.输入码云用户名密码,下载 $ Git ...
- sleep(0)的意义
Thread.Sleep(0) 并非是真的要线程挂起0毫秒,意义在于这次调用Thread.Sleep(0)的当前线程确实的被冻结了一下,让其他线程有机会优先执行. Thread.Sleep(0) 是你 ...
- sxt_(001_003)_spring_ioc
一.spring简介 Spring是一个轻量级控制反转(IoC)和面向切面(AOP)的容器框架.Spring框架是由于软件开发的复杂性而创建的.Spring使用的是基本的JavaBean来完成以前只可 ...
- 【Hive】元数据库部署的三种方式和选择【metaStore server】
一.Derby 元数据使用之前,要在hive目录下执行schematool命令,进行初始化设置 bin/schematool -dbType derby -initSchema 启动hive后,可以用 ...