当前位置:网站首页>What is the difference between'1 and'b1 when assigning values
What is the difference between'1 and'b1 when assigning values
2022-07-25 23:34:00 【A little confused】
stay sv When assigning a value in ,'1 and 'b1 What difference does assignment make ?
Give a simple assignment file , Look at the output
module tb;
byte i;
byte j;
initial begin
i = '1;
j = 'b1;
$display("**************");
$display("i --> %b", i);
$display("j --> %b", j);
$display("*****End*******");
end
endmodule

Variable i and j All declared as byte type (8 bit), When used '1 When assigning values , All bits are 1; When used 'b1 When assigning values , Only the lowest is 1
What are the benefits
Let's make a change
module tb;
parameter SIZE = 8;
bit [SIZE-1 : 0] i;
bit [SIZE-1 : 0] j;
initial begin
i = '1;
j = 'b1;
$display("**************");
$display("i --> %b", i);
$display("j --> %b", j);
$display("*****End*******");
end
endmodule
Set a parameter , The output at this time should be consistent with that before the change

But if we subsequently change the value of the parameter , For example, we will SIZE The value of is changed to 16, Let's take a look at the results
module tb;
parameter SIZE = 16;
bit [SIZE-1 : 0] i;
bit [SIZE-1 : 0] j;
initial begin
i = '1;
j = 'b1;
$display("**************");
$display("i --> %b", i);
$display("j --> %b", j);
$display("*****End*******");
end
endmodule

You can see , use '1 The way of assignment , No matter how wide the seat is , All positions will be 1
And if we use the common Verilog Assignment method , When the bit width is 8 bit when
i = 8'hFF
When the bit width is changed to 16 bit when
i = 16'hFFFF
To achieve this effect , Many steps are simplified when changing
I looked back Verilog The book of , Found in fact Verilog There are also ways to achieve this effect , Is to use complement
i = ~0; //1 Complement operation of
j = -1; //2 Complement operation of
Take a look at the running results in this example
module tb;
parameter SIZE = 16;
bit [SIZE-1 : 0] i;
bit [SIZE-1 : 0] j;
initial begin
i = ~0;
j = -1;
$display("**************");
$display("i --> %b", i);
$display("j --> %b", j);
$display("*****End*******");
end
endmodule

It does , then SIZE The value of is changed to 32

All positions can still be 1
边栏推荐
- 物理防火墙是什么?有什么作用?
- ratio学习之ratio_add,ratio_subtract,ratio_multiply,ratio_divide的使用
- Serialize addition, deletion, modification and query
- 152. Product maximum subarray - dynamic programming
- Summary of built-in instructions and custom instructions
- 疫情之下的好消息
- From which dimensions can we judge the quality of code? How to have the ability to write high-quality code?
- About priority queues
- 762. 二进制表示中质数个计算置位
- 数组中重复的数字
猜你喜欢

Idea sets get and set templates to solve the naming problem of boolean type fields

S4/HANA ME21N创建PO 输出控制消息按钮丢失解决方法(切换EDI 输出模式BRF+至NAST模式)

Apple CMS V10 template /mxone Pro adaptive film and television website template

Why are there many snapshot tables in the BI system?
![[JUC] concurrent keyword volatile](/img/80/2f1b33f1e8c87fd4f8806eafb83139.png)
[JUC] concurrent keyword volatile

LeetCode 0135. 分发糖果

idea设置get、set模板解决boolean类型字段的命名问题

Classes and objects (2) (6 default member functions)

ABAP 代码中读取会计科目的字段状态(隐藏、可选、必输)

Inheritance (the child constructor inherits the attributes in the parent constructor)
随机推荐
红娘的话
类和对象(2)(6个默认成员函数)
Vscode shortcut key: collapse and expand code
E-commerce RPA, a magic weapon to promote easy entry
Duplicate numbers in array
Same origin strategy and cross domain
学习探索-3d轮播卡片
学习探索-波浪
EasyExcel实用技巧
Pytorch data input format requirements and conversion
Using jetpack libraries in applications
【代码案例】博客页面设计(附完整源码)
Serialize addition, deletion, modification and query
LeetCode 0135. 分发糖果
[code case] blog page design (with complete source code)
模拟实现string类常用接口
ratio学习之ratio_add,ratio_subtract,ratio_multiply,ratio_divide的使用
物理防火墙是什么?有什么作用?
Three board axe! Help you become an excellent software engineer
From which dimensions can we judge the quality of code? How to have the ability to write high-quality code?