当前位置:网站首页>Verilog grammar basics HDL bits training 05
Verilog grammar basics HDL bits training 05
2022-07-26 00:33:00 【Nanyou school slag】
List of articles
- Preface
- More Verilog Features
- One 、Conditional ternary operator
- Two 、Reduction operators
- 3、 ... and 、Reduction:Even wider gates
- Four 、Combinational for-loop:Vector reversal
- 5、 ... and 、Combinational for-loop:255-bit population count
- 6、 ... and 、Generate for-loop:100-bit binary adder
- 7、 ... and 、Generate for-loop:100-digit BCD adder
Preface
Several examples of this time focus on for Circulation and generate&for Loop statement , Benefited greatly
More Verilog Features
One 、Conditional ternary operator

Ternary conditional operators :((a)?:c:b);? The former is the condition , Conditions will be met c give , If the condition does not hold, it will b give .
- RTL Code
module top_module (
input [7:0] a, b, c, d,
output [7:0] min);//
// assign intermediate_result1 = compare? true: false;
wire [7:0]min1;
wire [7:0]min2;
assign min1 = (a<b) ? a:b;
assign min2 = (c<d) ? c:d;
assign min = (min1<min2) ? min1:min2;
endmodule
- Simulation oscillogram

Two 、Reduction operators

Perform bit operations on all bits in a vector
- RTL Code
module top_module (
input [7:0] in,
output parity);
assign parity = ^ in[7:0];
endmodule
3、 ... and 、Reduction:Even wider gates
Conduct 100 All bit operations of bit data
- RTL Code
module top_module(
input [99:0] in,
output out_and,
output out_or,
output out_xor
);
assign out_and = & in[99:0];
assign out_or = | in[99:0];
assign out_xor = ^ in[99:0];
endmodule
- Simulation oscillogram


Four 、Combinational for-loop:Vector reversal
Will input 100 Bit data is inverted and assigned to the output
- RTL Code
module top_module(
input [99:0] in,
output [99:0] out
);
integer i;
always @(*)
for(i=0;i<=99;i=i+1)
out[i] = in[99-i];
endmodule
5、 ... and 、Combinational for-loop:255-bit population count
Statistics 255 Bit data ‘1’( High level ) The number of , And send the total number of statistics to out in
- RTL Code
module top_module(
input [254:0] in,
output [7:0] out );
integer i;
always @(*)
begin
out = 1'b0;
for(i=0;i<=254;i=i+1)
begin
if(in[i])
out = out+1;
else
out = out;
end
end
endmodule
- Simulation oscillogram

6、 ... and 、Generate for-loop:100-bit binary adder
To design a 100 Bit full adder ,cin Is the overall carry ,cout[99] Is the final carry , Use generate sentence
- RTL Code
module top_module(
input [99:0] a, b,
input cin,
output [99:0] cout,
output [99:0] sum );
genvar i;
generate
for(i=0;i<100;i=i+1)begin:adder
if(i==0)
assign {
cout[0] , sum[0]} = a[0] + b[0] + cin;
else
assign {
cout[i] , sum[i]} = a[i] + b[i] + cout[i-1];
end
endgenerate
endmodule
- Use integer and for sentence
module top_module(
input [99:0] a, b,
input cin,
output [99:0] cout,
output [99:0] sum );
integer i;
always @(*)
for(i=0;i<100;i=i+1)
begin
if(i==0)
{
cout[0] , sum[0]} = a[0] + b[0] + cin;
else
{
cout[i] , sum[i]} = a[i] + b[i] + cout[i-1];
end
endmodule
7、 ... and 、Generate for-loop:100-digit BCD adder
To design a BCD Code full adder , call bcd_fadd Instantiation module , because always Instantiated modules cannot be called in blocks , So it can't be used always Block and for The combination of sentences , Only use generate sentence
- RTL Code
module top_module(
input [399:0] a, b,
input cin,
output cout,
output [399:0] sum );
wire [99:0]cout_t;
genvar i;
generate
for(i=0;i<100;i=i+1)begin:bcd_fadd
if(i==0)
bcd_fadd bcd_fadd_inst(a[3:0],b[3:0],cin,cout_t[0],sum[3:0]);
else
bcd_fadd bcd_fadd_inst(a[4*i+3:4*i],b[4*i+3:4*i],cout_t[i-1],cout_t[i],sum[4*i+3:4*i]);
end
assign cout = cout_t[99];
endgenerate
endmodule
边栏推荐
- 2022/7/24 examination summary
- nodejs启动mqtt服务报错SchemaError: Expected `schema` to be an object or boolean问题解决
- letfaw
- 测试7年,面试华为最后面议要薪1万,HR说我不尊重华为,他们没有那么低薪资的岗位~
- 攻防世界web题-favorit_number
- 前缀异或和,异或差分数组
- 【redis】③ 数据淘汰策略、pipeline 管道命令、发布订阅
- [contents] mqtt, nodejs projects
- Nest. JS uses express but not completely
- MPLS experiment
猜你喜欢

白蛋白纳米粒表面修饰低分子量鱼精蛋白LMWP/PEG-1900修饰牛血清白蛋白制备研究

GOM和GEE引擎黑屏不显示界面,装备地图怪物的解决方法

TID-MOP:面向数据交易所场景下的安全管控综合框架

Nodejs surface longitude

快速入门顺序表链表

SQL time splicing problem, splicing recovery automatically truncated by the system

【计算一个字符串和另一个字符串相等的次数】

JVM Tri Color marking and read-write barrier

After seven years of testing, the interview with Huawei finally negotiated a salary of 10000. HR said that I didn't respect Huawei and they didn't have such a low salary position~
![[redis] ① introduction and installation of redis](/img/87/af98c862524a81d4636f1cb3be5181.png)
[redis] ① introduction and installation of redis
随机推荐
Tid-mop: a comprehensive framework for security management and control under the scenario of data exchange
2022/7/25 考试总结
【NumPy中数组创建】
FreeRTOS personal notes - mutex
12. Neural network model
Semaphore
Tarjan 求强连通分量 O(n+m) ,缩点
白蛋白纳米-超声微泡载组织型纤溶酶原激活物基因靶向制备研究
攻防世界web题-favorit_number
分布式事务 :可靠消息最终一致性方案
基于网络分析和文本挖掘的意见领袖影响力研究
Quick start sequence table chain table
SQL server failed to send mail, prompting that the recipient must be specified
Distributed transactions: the final consistency scheme of reliable messages
Four characteristics and isolation level of MySQL transactions
sql(基础二)
Research on the influence of opinion leaders based on network analysis and text mining
【无标题】如何实现可插拔配置?
Nest. JS uses express but not completely
Flask send verification code logic