// 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的更多相关文章

  1. 学会使用Hdlbits网页版Verilog代码仿真验证平台

    给大家推荐一款网页版的 Verilog代码编辑仿真验证平台,这个平台是国外的一家开源FPGA学习网站,通过“https://hdlbits.01xz.net/wiki/Main_Page” 地址链接进 ...

  2. HDLBits答案——Circuits

    1 Combinational Logic 1.1 Basic Gates 1.1.1 Exams/m2014 q4h module top_module ( input in, output out ...

  3. HDLBits答案——Verification: Writing Testbenches

    1 clock module top_module ( ); reg clk; dut U1(.clk(clk)); initial begin clk = 0; end always begin # ...

  4. 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 ...

  5. HDLBits答案——Verilog Language

    Verilog Language 1 Basics 1.1 Wire module top_module( input in, output out ); assign out = in; endmo ...

  6. HDLBits答案——Getting started

    Getting started 1 Step one module top_module( output one ); // Insert your code here assign one = 1' ...

  7. verilog常见错误列表

    Error/Warning 来源:https://hdlbits.01xz.net/wiki/ 题目: 1.Quartus Warning 10235: Warning (): Verilog HDL ...

  8. Verilog HDL

    https://wenku.baidu.com/view/9943b7acf524ccbff1218463.html https://hdlbits.01xz.net/wiki/Main_Page h ...

  9. Verilog设计技巧实例及实现

    Verilog设计技巧实例及实现 1 引言 最近在刷HDLBits的过程中学习了一些Verilog的设计技巧,在这里予以整理.部分操作可能降低代码的可读性和Debug的难度,请大家根据实际情况进行使用 ...

  10. 入行数字IC验证的一些建议

    0x00 首先,推荐你看两本书,<"胡"说IC菜鸟工程师完美进阶>(pdf版本就行)本书介绍整个流程都有哪些岗位,充分了解IC行业的职业发展方向.<SoC设计方法 ...

随机推荐

  1. HP DC7800 升级CPU出现:Missing or Invalid Processor Microcode Update —— 解决方案:更新主板BIOS

    1.所需文件在这个网盘里面:链接:https://pan.baidu.com/s/140DI2SyRmPf0Q-ikXcJMcQ 提取码:yjth 2.这个问题的解决参考了:https://h3043 ...

  2. Windows10安装VMware

    系统环境: Windows 10 安装步骤: 1.下载vmware https://my.vmware.com/cn/web/vmware/downloads 2.安装(这里安装语言我选择的是中文) ...

  3. 让自己的笔记本变wifi,如何设置呢?

    让自己的笔记本变wifi,如何设置呢?   笔记本变wifi,居然有这样的好事,没错,就是这样的,我也是才知道,哈哈.果然,世上无奇不有,只是你不知罢了.   以win10笔记本为例,亲试有效,附上链 ...

  4. Python中Websocket的实现及基本原理

    一.什么是 WebSocket ? WebSocket 是一种标准协议,用于在客户端和服务端之间进行双向数据传输.但它跟 HTTP 没什么关系,它是基于 TCP 的一种独立实现. 以前客户端想知道服务 ...

  5. cuda、cudnn、tnesorrt的查看安装

    1.首先本地查看cuda已安装的版本 11.7输入命令:[nvcc -V]输出:nvcc: NVIDIA (R) Cuda compiler driverCopyright (c) 2005-2022 ...

  6. 树莓派Raspbian 玩耍

    树莓派Raspbian玩耍 把第一次安装树莓派并通过花生壳实现内网穿透的过程记录下来 下载工具 Win32DiskImager v0.9.zip 和 SD Formatter 4.0 for SD/S ...

  7. 教你快速理解Linux虚拟化网络的全脉络,正确配置网络联通性。

    https://www.bilibili.com/video/BV1iy4y177f4?p=12 实用的干货快先码起来,说不定以后会用到哟

  8. 通过 HDU 2048 来初步理解动态规划

    HDU 2048 数塔 问题描述: 题目链接-点我查看题目   给出一个数塔,要求从顶层走到底层,每一步只能从高层走到相邻的低层节点,求经过的结点的数字之和最大是多少? 动态规划的定义   dynam ...

  9. 常见Linux命令二

    常见Linux命令二 一:shutdown命令--用来系统关机命令. 语法:shutdown(选择)(参数) 常见选项:-r:shutdown之后重启 -h:将系统关机 二:reboot命令-- 重新 ...

  10. cnblogs.com/linycat

    核心技术 Java MySQL SSM SpringBoot MyBatisPlus Redis RabbitMQ Git Google ChatGPT 分布式架构 分布式会话 单点登录 分布式锁 读 ...