当前位置:网站首页>【牛客网刷题系列 之 Verilog快速入门】~ 移位运算与乘法
【牛客网刷题系列 之 Verilog快速入门】~ 移位运算与乘法
2022-06-29 14:26:00 【AI很不错呦】
1. VL4 移位运算与乘法
1.1 题目描述
已知d为一个8位数,请在每个时钟周期分别输出该数乘1/3/7/8,并输出一个信号通知此时刻输入的d有效(d给出的信号的上升沿表示写入有效)
1.1.1 信号示意图

1.1.2 波形示意图

1.1.3 输入描述
输入信号 d, clk, rst
类型 wire
在testbench中,clk为周期5ns的时钟,rst为低电平复位
1.1.4 输出描述
输出信号 input_grant out
类型 reg
1.2 解题思路
这个题有两个点:一个是乘法运算怎么解决?还有一个就是怎么保证完成四次乘法运算呢?
1、 我们一般用移位操作来解决乘除法,但需要注意的是,无符号数和有符号数是有区别的:
无符号数===>左移一位表示乘2,右移一位表示除2
有符号数===>只能进行左移操作,不能右移操作,为什么呢?因为右移的话,高位得补0,那岂不是会影响最高位的符号位嘛!!!
2、 解决第二个问题,那得用计数器来完成即可。刚好2位计数器刚刚好,哈哈哈!!!
1.3 代码实现
`timescale 1ns/1ns
module multi_sel(
input [7:0]d ,
input clk,
input rst,
output reg input_grant,
output reg [10:0]out
);
//*************code***********//
//counter
reg [1:0] cnt;
always @ (posedge clk or negedge rst) begin
if(!rst) begin
cnt <= 2'b00;
end
else begin
cnt <= cnt + 1'b1;
end
end
reg [7:0] d_reg;
always @ (posedge clk or negedge rst) begin
if(!rst) begin
out <= 11'd0;
input_grant <= 1'b0;
d_reg <= 8'd0;
end
else begin
case (cnt)
2'b00 : begin
out <= d;
d_reg <= d;
input_grant <= 1'b1;
end
2'b01 : begin
out <= d_reg + (d_reg<<1);
input_grant <= 1'b0;
end
2'b10 : begin
out <= d_reg + (d_reg<<1) + (d_reg<<2);
input_grant <= 1'b0;
end
2'b11 : begin
out <= d_reg<<3;
input_grant <= 1'b0;
end
default : begin
out <= d;
input_grant <= 1'b0;
end
endcase
end
end
//*************code***********//
endmodule
1.4 测试文件
待更新。。。
1.5 仿真波形
待更新。。。
边栏推荐
- redis在window和Linux环境下的安装
- idea输出台输出中文乱码问题
- Class template case - array class encapsulation
- leetcode:226. Flip binary tree
- 单端口RAM实现FIFO
- Redis master-slave replication principle
- I want to search the hundreds of nodes in the data warehouse. Can I check a table used in the SQL
- Underlying implementation principle of five data structures of redis
- 【置顶】博客使用须知,公告板,留言板,关于博主
- 布隆过滤器Bloom Filter简介
猜你喜欢

Crazy digital collections, the next myth of making wealth?
![[top] blog instructions, bulletin board, message board, about bloggers](/img/3a/6100ae88874cad57305decce41c1e7.png)
[top] blog instructions, bulletin board, message board, about bloggers

Thanos store component

浅析 Istio——可观测性

Mysql database - general syntax DDL DML DQL DCL

Zhimeng dedecms resource material tutorial download website template source code (with mobile terminal) with installation tutorial

【Try to Hack】vulnhub DC2

模电 2个NPN管组成的恒流源电路分析

Deploy redis sentry in k8s

【blackduck】jenkins下配置指定的synopsys-detect扫描版本
随机推荐
一次mysql的.ibd文件过大处理过程记录
k8s部署redis哨兵
自动注入@Resource和@Autowired注解的区别:
FIFO implementation with single port RAM
Redis' cache avalanche, cache breakdown, cache penetration, cache preheating, and cache degradation
Mysql database - general syntax DDL DML DQL DCL
Transport layer user datagram protocol (UDP)
布隆过滤器Bloom Filter简介
论文学习——考虑场次降雨年际变化特征的年径流总量控制率准确核算
Explanation on deployment and establishment of decentraland process
你还在用命令看日志?快用 Kibana 吧,一张图胜过千万行日志
揭秘!付费会员制下的那些小心机!
Redis主从复制原理
【置顶】博客使用须知,公告板,留言板,关于博主
leetcode:226. Flip binary tree
[blackduck] configure the specified Synopsys detect scan version under Jenkins
Redis fragment cluster setup and use tutorial
重磅!2022最新SCI影响因子发布,三大名刊NCS及国内期刊TOP10排名有变化 (内附2022年最新影响因子)
Uncover the secret! Pay attention to those machines under the membership system!
Chapter 14 of canvas physical animation