当前位置:网站首页>[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 ...
边栏推荐
- Opengauss community establishes sig knowledgegraph
- Uniapp problem list and experience
- Ogg synchronize MySQL data to greenplus
- Chapter 10 of canvas path
- Chapter 11 of canvas canvas status
- Redis哨兵机制原理详解
- Why is redis so fast? Is redis single threaded or multi-threaded?
- Can futures accounts be opened offline? Is it safe to open an account online?
- NuScenes关于Radar的配置信息
- 熊市慢慢,Bit.Store提供稳定Staking产品助你穿越牛熊
猜你喜欢

织梦dedecms资源素材教程下载网站模板源码(带手机移动端)附安装教程

Is 100W data table faster than 1000W data table query in MySQL?

Imitation headline news information DZ template discuz news information business version GBK template source code

Analysis of istio -- observability

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

【blackduck】jenkins下配置指定的synopsys-detect扫描版本

重磅!2022最新SCI影响因子发布,三大名刊NCS及国内期刊TOP10排名有变化 (内附2022年最新影响因子)

Explanation on deployment and establishment of decentraland process

NuScenes关于Radar的配置信息

Mysql database - general syntax DDL DML DQL DCL
随机推荐
知乎热议:一个程序员的水平能差到什么程度?
Chapter 6 picture operation of canvas
建立自己的网站(19)
Which is better and safer for Dongguan Humen securities company to open a stock account?
论文学习——考虑场次降雨年际变化特征的年径流总量控制率准确核算
Mysql database - general syntax DDL DML DQL DCL
校园转转二手市场源码
Introduction to bloom filter
[use of veux developer tools - use of getters]
Imitation headline news information DZ template discuz news information business version GBK template source code
你还在用命令看日志?快用 Kibana 吧,一张图胜过千万行日志
关于项目采购管理,这些你需要知道
模电 2个NPN管组成的恒流源电路分析
国内十大券商,有哪些安全吗?
word如何自动生成目录
Redis主从复制原理
Class template case - array class encapsulation
广州开展瓶装气安全宣传活动,普及燃气安全知识
Recruiting talents and seeking development | Jincang of the National People's Congress won the "best employer school recruitment case Award"
部署搭建decentraland流程讲解