【Verilog-HDLBits刷题】2022.02.20学习笔记

1、题目:Build a circuit that sign-extends an 8-bit number to 32 bits. This requires a concatenation of 24 copies of the sign bit (i.e., replicate bit[7] 24 times) followed by the 8-bit number itself.

题目意思:将输入信号的高位赋值24次,并和原来的信号进行拼接

报错:Error (10170): Verilog HDL syntax error at top_module.v(4) near text: “,”; expecting “}”. Check for and fix any syntax errors that appear immediately before or at the specified keyword. The Intel FPGA Knowledge Database contains many articles with specific details on how to resolve this error.

解决:当使用位拼接符的时候需要注意, 对于 assign out= { 24{in[7]} , in };如果想重复24{1’b1},则需要将其整个打包到一起,即:{ 24{in[7]} },更改后:assign out={ { 24{in[7]} } , in }正确√

2、知识点:自定义模块时避免使用verilog语言的 ‘关键词’,如定义模块名不可以定义为 instance,会报错。之前跑个小project出错,很久都没找到原因,最后更改了模块名就没问题了。基础知识啊。。。哈哈

3、题目:You are given a module my_dff8 with two inputs and one output (that implements a set of 8 D flip-flops). Instantiate three of them, then chain them together to make a 8-bit wide shift register of length 3. In addition, create a 4-to-1 multiplexer (not provided) that chooses what to output depending on sel[1:0]: The value at the input d, after the first, after the second, or after the third D flip-flop.

题目意思:实例化三个模块并将它们连接起来,并且要求我们写一个选择器,当sel为00时输出d,当sel为01时输出经过第一个触发器后的q值,以此类推。这里选择用case语句来实现。

解决:两个内部模块连接时,wire/reg 定义的连接需要标明位宽,eg:wire [7:0]q1,q2,q3;

4、进位选择加法器(carry-select adder)如下图:
提前计算好第二个加法器的结果,使用一个多路选择器来确定最终选择哪个加法器的结果,大大减少延时。
在这里插入图片描述

5、加减法器(adder-subtractor)如下图所示
当sub=0时,执行加法;
当sub=1时,执行减法;
注意:异或时,sub位宽也需要是32位的,否则会出现问题。
在这里插入图片描述

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值