当前位置:网站首页>[Verilog quick start of Niuke online question series] ~ shift operation and multiplication
[Verilog quick start of Niuke online question series] ~ shift operation and multiplication
2022-06-29 14:47:00 【AI is very good】
Catalog :
1. VL4 Shift operation and multiplication
1.1 Title Description
It is known that d For one 8 digit , Please output this number in each clock cycle 1/3/7/8, And output a signal to inform the input at this time d It works (d The rising edge of the given signal indicates that the write is valid )
1.1.1 Signal schematic diagram
1.1.2 Waveform diagram
1.1.3 Input description
Input signal d, clk, rst
type wire
stay testbench in ,clk For cycles 5ns The clock of ,rst Reset for low level
1.1.4 Output description
The output signal input_grant out
type reg
1.2 Their thinking
This question has two points : One is how to solve multiplication ? Another is how to ensure the completion of four times of multiplication ?
1、 We usually use shift operation to solve multiplication and division , But it should be noted that , There is a difference between unsigned numbers and signed numbers :
An unsigned number ===> Move one bit to the left to multiply 2, Shift one bit to the right to divide 2
Signed number ===> You can only move left , Cannot move right , Why? ? Because if you move to the right , High position compensation 0, That will affect the highest sign bit !!!
2、 Solve the second problem , That has to be done with a counter . just 2 The bit counter is just right , Ha ha ha !!!
1.3 Code implementation
`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 The test file
To be updated ...
1.5 Simulation waveform
To be updated ...
边栏推荐
- matplotlib直方图,柱状图
- Configuration tutorial for swagger2
- Build your own website (19)
- [important notice] the 2022 series of awards and recommendations of China graphics society were launched
- June 27 talk SofiE
- 《canvas》之第9章 渐变与阴影
- Redis的数据过期清除策略 与 内存淘汰策略
- Whitelabel Error Page访问
- Differences between @resource and @autowired annotations automatically injected:
- 【关联分析实战篇】为什么 BI 软件都搞不定关联分析
猜你喜欢
Analysis of istio -- observability
Source code of campus secondary market
[blackduck] configure the specified Synopsys detect scan version under Jenkins
第五届中国软件开源创新大赛 | openGauss赛道直播培训
Swagger2的配置教程
Netease strict selection offline data warehouse quality construction practice
织梦dedecms资源素材教程下载网站模板源码(带手机移动端)附安装教程
The first lesson on cloud - how easy is it to build a small broken station? The old driver of cloud computing will take you one hour to finish it
Nuscenes configuration information about radar
Is 100W data table faster than 1000W data table query in MySQL?
随机推荐
《canvas》之第10章 canvas路径
《canvas》之第8章 像素操作
Chapter 6 picture operation of canvas
How bad can a programmer be?
I want to search the hundreds of nodes in the data warehouse. Can I check a table used in the SQL
Chapter 5 text operation of canvas
[network bandwidth] Mbps & Mbps
openGauss社区成立SIG KnowledgeGraph
论文学习——考虑场次降雨年际变化特征的年径流总量控制率准确核算
Why is redis so fast? Is redis single threaded or multi-threaded?
Thanos Store 组件
《canvas》之第12章 其他应用
The first lesson on cloud - how easy is it to build a small broken station? The old driver of cloud computing will take you one hour to finish it
VQA needs not only pictures, but also external knowledge! University of Washington & Microsoft proposed revive, using gpt-3 and wikidata to help answer questions
Are the top ten domestic securities companies safe?
Chapter 8 pixel operation of canvas
MySQL中100w数据表比1000w数据表查询更快吗?
我想在数仓的几百个节点里面 查找一个都有哪些sql里面用到了某张表 能查吗
模电 2个NPN管组成的恒流源电路分析
阿里云体验有奖:使用PolarDB-X与Flink搭建实时数据大屏