当前位置:网站首页>FPGA systematic learning notes serialization_ Day8 [design of 4-bit multiplier and 4-bit divider]
FPGA systematic learning notes serialization_ Day8 [design of 4-bit multiplier and 4-bit divider]
2022-06-24 17:04:00 【FPGA technology Jianghu】
FPGA Systematic study notes serial _Day8【4 Bit multiplier 、4 Bit divider design 】 【 Principle and verilog Realization 、 Simulation 】 piece
Serial 《 Three core smart fpga Design and development - The first 8 God 》 【4 Bit multiplier 、4 Bit divider design 】 【 Principle and verilog Realization 、 Simulation 】
Original author : Zifeng River Please contact the group owner for authorization , Otherwise, we will be held responsible
One 、 Principle of multiplier
1、 Let's first look at the multiplication process of the decimal system
You can see it , We are using the bits of the multiplier separately 、 ten 、 The hundreds are multiplied by the multiplicand to get ;
The final result be equal to A + B10 + C100 = 401050
2、 Binary multiplication process
You can see it , Binary multiplication is the same as decimal
The final result be equal to A + B2 + C4 + D*8 = 1991
Two 、verilog Code implementation
mult4bit.v
module mult4bit(
input [3:0] a,
input [3:0] b,
output [7:0] y
);
wire [7:0] temp1;
wire [7:0] temp2;
wire [7:0] temp3;
wire [7:0] temp4;
assign temp1 = {4'b0000,a&{4{b[0]}}};
assign temp2 = {3'b000,a&{4{b[1]}},1'b0};
assign temp3 = {2'b00,a&{4{b[2]}},2'b0};
assign temp4 = {1'b0,a&{4{b[3]}},3'b0};
assign y = temp1 + temp2 + temp3 + temp4;
endmodule3、 ... and 、 Write simulation scripts
mult4bit.v
`timescale 1ns/1ps
module mult4bit_tb();
reg [3:0] a;
reg [3:0] b;
wire [7:0] y;
mult4bit mult4bit_inst(
.a (a),
.b (b),
.y (y)
);
initial begin
repeat (100)begin
a = {$random}%16;
b = {$random}%16;
#20;
end
end
endmoduleFour 、 Simulation results
Simulation results show that our multiplier design is correct
5、 ... and 、 The principle of the divider
1、 Let's first look at the division process of the decimal system
Division from decimal , We can see that there are several steps ;
1.1、 First, division is done from high to low ;
1.2、 Each one should add the remainder left by the previous one , Make a new number and divisor comparison ;
1.3、 When the new number is greater than / When it's equal to the divisor , Write quotient for surplus ;
1.4、 Proceed in the above manner , Until the end of the divisor , Division is over .
2、 Binary division process
As you can see from the figure, binary division , It's in line with the decimal system
6、 ... and 、 Code implementation
div4bit.v
module div4bit(
input [3:0] a,
input [3:0] b,
output [3:0] s,
output [3:0] y
);
wire [3:0] part1;
wire [3:0] part2;
wire [3:0] part3;
wire [3:0] part4;
assign s[3] = (a[3] >= b)?1'b1:1'b0;
assign part1 = (a[3] >= b)?(a[3]-b):a[3];
assign s[2] = ({part1[0],a[2]} >= b)?1'b1:1'b0;
assign part2 = ({part1[0],a[2]} >= b)?({part1[0],a[2]}-b):{part1[0],a[2]};
assign s[1] = ({part2[1:0],a[1]} >= b)?1'b1:1'b0;
assign part3 = ({part2[1:0],a[1]} >= b)?({part2[1:0],a[1]}-b):{part2[1:0],a[1]};
assign s[0] = ({part3[2:0],a[0]} >= b)?1'b1:1'b0;
assign part4 = ({part3[2:0],a[0]} >= b)?({part3[2:0],a[0]}-b):{part3[2:0],a[0]};
assign y = part4;
// This code is also executed correctly , But the compiler will warn , Because we put 5bit Data assigned to 4bit
// assign s[3] = a[3] >= b;
// assign part1 = (s[3]) ? a[3] - b : a[3];
//
// assign s[2] = {part1,a[2]} >= b;
// assign part2 = (s[2]) ? {part1,a[2]} - b : {part1,a[2]};
//
// assign s[1] = {part2,a[1]} >= b;
// assign part3 = (s[1]) ? {part2,a[1]} - b : {part2,a[1]};
//
// assign s[0] = {part3,a[0]} >= b;
// assign part4 = (s[0]) ? {part3,a[0]} - b : {part3,a[0]};
//
// assign y = part4;
endmodule7、 ... and 、 Write simulation files
div4bit_tb.v
`timescale 1ns/1ps
module div4bit_tb();
reg [3:0] a;
reg [3:0] b;
wire [3:0] s;
wire [3:0] y;
div4bit div4bit_isnt(
.a (a),
.b (b),
.s (s),
.y (y)
);
initial begin
repeat(100)begin
a ={$random}%16;
b ={$random}%16;
#20;
end
end
endmodule8、 ... and 、 Simulation results
It can be seen from the simulation results that , We designed 4bit The divider is correct .
边栏推荐
- Several cloud products of Tencent cloud have passed IPv6 enabled cloud logo certification
- API documents are simple and beautiful. It only needs three steps to open
- Yiwen teaches you to understand the stack operation in go
- ## Kubernetes集群中流量暴露的几种方案 Kubernetes集群中流量暴露的几种方案
- Data acquisition and transmission instrument reservoir dam safety monitoring
- 未来银行需要用明天的思维,来思考今天架构
- Let ups "Impressionist users" re understand reliability
- A survey on model compression for natural language processing (NLP model compression overview)
- 构建跨公链平台解决DApp开发问题
- The problem is as big as the middle stage
猜你喜欢

MySQL learning -- table structure of SQL test questions

A survey of training on graphs: taxonomy, methods, and Applications

A survey on model compression for natural language processing (NLP model compression overview)

A survey on dynamic neural networks for natural language processing, University of California
![[leetcode108] convert an ordered array into a binary search tree (medium order traversal)](/img/e1/0fac59a531040d74fd7531e2840eb5.jpg)
[leetcode108] convert an ordered array into a binary search tree (medium order traversal)

Daily algorithm & interview questions, 28 days of special training in large factories - the 15th day (string)
随机推荐
Future banks need to think about today's structure with tomorrow's thinking
How to use the national standard streaming media server to view the video stream of the surveillance camera? How to correctly use UDP and TCP protocols?
Several schemes of traffic exposure in kubernetes cluster
Cloud native monitoring via blackbox_ Exporter monitoring website
Explore cloudera manager management software tuning (1)
Industrial security experts talk about how to guarantee the safety of data elements in the rapid development of digital economy?
构建跨公链平台解决DApp开发问题
Prometheus deployment
Modern finite element analysis can easily achieve accurate results
A survey on model compression for natural language processing (NLP model compression overview)
Data acquisition and transmission instrument reservoir dam safety monitoring
Go kit microservice integrates Promtheus to solve monitoring alarm problems
Is CICC securities reliable? Is it legal? Is it safe to open a stock account?
2021-04-02: given a square or rectangular matrix, zigzag printing can be realized.
If only 2 people are recruited, can the enterprise do a good job in content risk control?
What is the difference between a network card and a port
Finite element simulation in design
Nonholonomic constrained robot
Markdown syntax -- Formula
[play with Tencent cloud] TSF User Guide