目录

4 bit的右移寄存器设计

100 bit循环移位寄存器

算术移位寄存器


4 bit的右移寄存器设计

先给出一个4位右移寄存器的设计题:

Build a 4-bit shift register (right shift), with asynchronous reset, synchronous load, and enable.

  • areset: Resets shift register to zero.
  • load: Loads shift register with data[3:0] instead of shifting.
  • ena: Shift right (q[3] becomes zero, q[0] is shifted out and disappears).
  • q: The contents of the shift register.

If both the load and ena inputs are asserted (1), the load input has higher priority.

题目过于简单,直接给出我的设计:

module top_module(input clk,input areset,  // async active-high reset to zeroinput load,input ena,input [3:0] data,output reg [3:0] q); always@(posedge clk or posedge areset) beginif(areset) q <= 0;else if(load) q <= data;else if(ena) beginq <= {1'b0, q[3:1]};    endendendmodule

100 bit循环移位寄存器

Build a 100-bit left/right rotator, with synchronous load and left/right enable. A rotator shifts-in the shifted-out bit from the other end of the register, unlike a shifter that discards the shifted-out bit and shifts in a zero. If enabled, a rotator rotates the bits around and does not modify/discard them.

  • load: Loads shift register with data[99:0] instead of rotating.
  • ena[1:0]: Chooses whether and which direction to rotate.
    • 2'b01 rotates right by one bit
    • 2'b10 rotates left by one bit
    • 2'b00 and 2'b11 do not rotate.
  • q: The contents of the rotator.

Module Declaration

module top_module(input clk,input load,input [1:0] ena,input [99:0] data,output reg [99:0] q);

也很简单,直接给出我的设计:

module top_module(input clk,input load,input [1:0] ena,input [99:0] data,output reg [99:0] q); always@(posedge clk) beginif(load) q <= data;else beginif(ena == 2'b01) q <= {q[0], q[99:1]};else if(ena == 2'b10) q <= {q[98:0], q[99]};else ;endendendmodule

算术移位寄存器

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.

Module Declaration

module top_module(input clk,input load,input ena,input [1:0] amount,input [63:0] data,output reg [63:0] q); 

不用看题目,都知道要做什么:

提示:

A 5-bit number 11000 arithmetic right-shifted by 1 is 11100, while a logical right shift would produce 01100.

Similarly, a 5-bit number 01000 arithmetic right-shifted by 1 is 00100, and a logical right shift would produce the same result, because the original number was non-negative.

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) beginif(load) q <= data;else if(ena) beginif(amount == 2'b00) q <= {q[62:0],1'b0};else if(amount == 2'b01) q <= {q[55:0],{8{1'b0}}};else if(amount == 2'b10) q <= {q[63],q[63:1]};else if(amount == 2'b11) q <= {{8{q[63]}},q[63:8]};endelse ;endendmodule

HDLBits 系列(20)移位寄存器(逻辑移位、算术移位、循环移位)相关推荐

  1. HDLBits 系列(0)专题目录

    本篇博文是近来总结HDLBits系列的目录,点击蓝色字体即可进入查看具体内容. HDLBits 系列(1)从HDLBits中获取灵感,整顿自己,稳步前行 HDLBits 系列(2)如何避免生成锁存器? ...

  2. SAP PM入门系列20 - IH08 Equipment报表

    SAP PM入门系列20 - IH08 Equipment报表 SAP PM模块中有比较多的报表.对于各个主数据,各个主要的单据对象,都有标准的报表可供使用. 对于设备这个技术对象,事务代码IH08是 ...

  3. HDLBits 系列(31)Serial Receiver and Datapath

    目录 序言 原题复现 我的设计 序言 上篇博文: HDLBits 系列(30)Serial Receiver 写了串行接收器如何接收8位串行数据,正确接收8位串行数据后给一个接收完毕标志信号,这篇博文 ...

  4. HDLBits 系列(29)PS/2 mouse protocol(PS/2 packet parser and datapath)

    目录 序言 原题传送 题目解释 我的设计 序言 上篇博客: HDLBits 系列(28)PS/2 mouse protocol(PS/2 packet parser) 只对PS/2 mouse pro ...

  5. 小酌重构系列[20]——用条件判断代替异常

    小酌重构系列[20]--用条件判断代替异常 参考文章: (1)小酌重构系列[20]--用条件判断代替异常 (2)https://www.cnblogs.com/keepfool/p/5513946.h ...

  6. 视频教程-华为路由交换精讲系列20:OSPF技术精讲 [肖哥]视频课程-华为认证

    华为路由交换精讲系列20:OSPF技术精讲 [肖哥]视频课程 肖老师(肖哥),思科认证讲师讲师(CCIE#27529),RedHat Linux认证讲师讲师,Juniper 认证讲师讲师,微软认证讲师 ...

  7. HDLBits 系列(21)LFSR(线性反馈移位寄存器)

    目录 5 bit LFSR 3 bit LFSR 32 bit LFSR 5 bit LFSR A linear feedback shift register is a shift register ...

  8. (计算机组成原理)第二章数据的表示和运算-第二节3:定点数的移位运算(算数移位、逻辑移位和循环移位)

    文章目录 一:算数移位 (1)原码的算数移位 (2)反码的算术移位 (3)补码的算数移位 二:逻辑移位 三:循环移位 定点数的移位运算根据操作对象的不同划分为算数移位和逻辑移位.有符号数的移位称为算数 ...

  9. [计算机组成原理]2-6、算数移位、逻辑移位、循环移位

    逻辑移位 看笔记一定要心静,慢慢来不急. 在移位运算中,考察最频繁的就是算术移位和逻辑移位,逻辑移位相对来说比较简单,我们先从它入手. 首先我们来看什么叫移位,移位就是移动位置,移动数据的位置,也就是 ...

最新文章

  1. 逆向工程、软件后门……原来美剧《硅谷》里藏着这么多知识点
  2. ASP.NET2.0 - skmMenu 的使用
  3. (二十九)、Java字符串中去除空格
  4. 2019年春季学期第二周作业
  5. 3/3 常用符号:转义字符
  6. [机器学习] 半监督学习---伪标签Pseudo-Label
  7. 中国央行将发行全球首个法定数字货币,消息是真的吗?
  8. 关中断是否禁止任务调度?关中断能作为互斥吗?
  9. Java基础篇:如何解决成员的访问和继承?
  10. 华为海思总裁深夜发文:进入至暗时刻,技术“备胎”将全部转正应敌
  11. 广州恒义计算机科技,【长文】SONY MAP-S1解码一体机恒义科技HY-05台式耳放听感测评...
  12. fmask云检测 matlab_高分四号卫星数据云和云阴影检测算法
  13. 中国富豪第一桶金挖掘的九大方式
  14. python语言支持中文输出_python2输出汉字的解决办法暨python2/python3的编码环境参数的查看-Go语言中文社区...
  15. 安装vue脚手架出现的问题 npm ERR! code EEXIST。。。
  16. win10忘记密码_电脑忘记密码没关系,这招教你简单轻松改密码
  17. 微信号开通检测软件的使用方法
  18. 第三届江西省高校网络安全技能大赛 部分wpCrypto的疑惑
  19. 【附源码】计算机毕业设计JAVA销售人员绩效管理系统
  20. 4 基于matplotlib的python数据可视化——导入Excel数据批量制作柱形图

热门文章

  1. DirectX 9的坐标系统变换
  2. swift Swauth install
  3. HG522-C 刷Openwrt记录
  4. VC++中GlobalAlloc()、malloc()和new()函数之间区别
  5. android 封装状态页面,Android 缺省页状态切换方案
  6. 日期如何比较 java_如何比较Java中的日期?
  7. 成人怎么学计算机英语单词,成人怎么从零开始学英语单词
  8. 瑞丽噪声与信噪比的关系_演出扩声系统的噪声与接地
  9. 计算机起源于发展论文,关于计算机起源及发展的论文1500字左右,论文形式.
  10. 华为linux笔记本开售,华为 MateBook D Linux 版明天开售 一种价格两种版本