当前位置:网站首页>[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 ...
边栏推荐
- 部署搭建decentraland流程讲解
- 你还在用命令看日志?快用 Kibana 吧,一张图胜过千万行日志
- 我登录RDB的数据库,提示需要主账号授权,这个我怎么知道该找谁?
- 《canvas》之第9章 渐变与阴影
- Is 100W data table faster than 1000W data table query in MySQL?
- 我想在数仓的几百个节点里面 查找一个都有哪些sql里面用到了某张表 能查吗
- Redis主从复制原理
- Uncover the secret! Pay attention to those machines under the membership system!
- Transport layer selective ACK
- Chapter 8 pixel operation of canvas
猜你喜欢

揭秘!付费会员制下的那些小心机!

Explanation on deployment and establishment of decentraland process

Dynamics 365Online Lookup查找字段多选

MySQL 数据库 - 通用语法 DDL DML DQL DCL

Tiktok's global short video dominance may be reversed by YouTube

类模板案例-【数组类封装】

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

仿头条新闻资讯dz模板 Discuz新闻资讯商业版GBK模板源码

stm32 mbed 入门教程(四)---PWM

【blackduck】jenkins下配置指定的synopsys-detect扫描版本
随机推荐
精品商城拼团秒杀优惠折扣全功能完美双端自适应对接个人免签网站源码
FIFO implementation with single port RAM
idea输出台输出中文乱码问题
【关联分析实战篇】为什么 BI 软件都搞不定关联分析
. Net program configuration file operation (INI, CFG, config)
Class template case - array class encapsulation
Redis master-slave replication principle
JUC多线程:线程池的创建及工作原理
Build your own website (19)
Redis' data expiration clearing strategy and memory obsolescence strategy
Persistence mechanism of redis
Chapter 9 of canvas: gradients and shadows
[important notice] the 2022 series of awards and recommendations of China graphics society were launched
Redis的缓存雪崩、缓存击穿、缓存穿透与缓存预热、缓存降级
类模板案例-【数组类封装】
Whitelabel Error Page访问
Analysis of istio -- observability
QRcode custom QR code middle picture
【jenkins】pipeline控制多job顺序执行,进行定时持续集成
EXCEL的查询功能Vlookup