// 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

仿真图:





原理图:

最新文章

  1. PE读写
  2. working with fitnesse wiki pages
  3. windows phone 8.1教务在线客户端(后续)
  4. Android 数据库的事务
  5. Oracle RAC 11.2.0.4 – RHRL 6.4: DiskGroup resource are not running on nodes. Database instance may not come up on these nodes
  6. Kerberos的基本概念
  7. IOS init initWith 等相关集中
  8. 廖雪锋笔记2:list,tuble
  9. 【Bootstrap】优秀小插件收集
  10. iOS多线程编程--NSOperation(转)
  11. 附录D——自动微分(Autodiff)
  12. css选择器+、~、&gt;
  13. css零碎知识点小结
  14. 【已处理完】Centos 6.5版本,df -h出来的容量与du -sh的容量不对应是怎么会事呢?
  15. C# Winform右下角弹窗方式
  16. ReactNative 环境的搭建和启动(安卓版)
  17. 基于jQuery仿去哪儿城市选择代码
  18. ASP.NET Core 2 学习笔记(八)URL重写
  19. Python 利用 BeautifulSoup 爬取网站获取新闻流
  20. Ubuntu开机自动禁用无线网络

热门文章

  1. vue+elementUI表格实现自定义右键菜单
  2. 【面试题】 用vue想要拿20k,面试题要这样回答(源码版)
  3. @Target:注解的作用目标
  4. Linux 搭建Apache(httpd)服务
  5. 在TMOS系统中添加按键检测功能
  6. 面试题 --MySQL索引
  7. 编译报错Could NoT find Threads (missing: Threads FOUND)
  8. Pytest 插件
  9. 批量添加esxi主机到Vcenter
  10. vue重置data数据为初始状态