当前位置:网站首页>赋值时'1和'b1有什么区别
赋值时'1和'b1有什么区别
2022-07-25 23:31:00 【有点迷茫】
在sv中赋值时,'1和'b1赋值会有什么区别?
给出一个简单的赋值文件,看看输出结果
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

变量i和j都声明为byte型(8 bit),当用'1进行赋值时,所有位均为1;当用'b1进行赋值时,只有最低位是1
这有什么好处呢
我们做个更改
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
设置一个参数,此时的输出应和更改之前一致

但如果我们后续更改了参数的数值,比如我们将SIZE的值更改为16,再来看看运行结果
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

可以看到,采用'1的赋值方式,无论位宽是多少,都会将所有的位置为1
而如果我们用常见的Verilog赋值方式,当位宽为8 bit时
i = 8'hFF
当位宽改为16 bit时
i = 16'hFFFF
才能实现这个效果,更改时简化了很多步骤
回头看了看Verilog的书,发现其实Verilog也有可以实现这种效果的方法,就是利用补码
i = ~0; //1的补码运算
j = -1; //2的补码运算
放在这个例子中看看运行结果
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

确实可以实现,再将SIZE的值更改为32

依旧可以将所有位置1
边栏推荐
- Discuz magazine / news report template (jeavi_line) utf8 GBK / DZ template download
- Three board axe! Help you become an excellent software engineer
- Why are there many snapshot tables in the BI system?
- Summary of common PHP functions
- Recursion of function (use recursion to find the factorial of 1-N) (use recursion to find Fibonacci sequence) (use recursion to traverse data)
- Simulate and implement common interfaces of string class
- Source code of YY music wechat applet imitating Netease cloud music
- Es5 new method
- 152. 乘积最大子数组-动态规划
- PHP wechat scan code, follow official account and authorize login source code
猜你喜欢

学习探索-波浪

电商RPA,大促轻松上阵的法宝

Dynamic memory management

MVVM model

Discuz atmosphere game style template / imitation lol hero League game DZ game template GBK

Learning exploration-3d rotation card

类和对象(3)

WebMvcConfigurationSupport

Inheritance (the child constructor inherits the attributes in the parent constructor)

WordPress removes the website publishing time
随机推荐
Node基础
类和对象(2)(6个默认成员函数)
ratio学习之ratio_add,ratio_subtract,ratio_multiply,ratio_divide的使用
Summary of common PHP functions
The new UI people help task help PHP source code with a value of 1500 / reward task Tiktok Kwai headline like source code / with three-level distribution can be packaged applet
Three board axe! Help you become an excellent software engineer
[Database Foundation] summary of MySQL Foundation
S4/HANA MM & SD EDI基于NAST的集成配置(ORDERS, ORDRSP, DESADV, INVOIC)
JS regular expression content:
Vscode shortcut key: collapse and expand code
Recursion of function (use recursion to find the factorial of 1-N) (use recursion to find Fibonacci sequence) (use recursion to traverse data)
idea设置get、set模板解决boolean类型字段的命名问题
数组中重复的数字
模拟实现string类常用接口
Summary of kotlin common knowledge points
策略模式_
从哪些维度评判代码质量的好坏?如何具备写出高质量代码的能力?
Take away applet with main version of traffic / repair to add main access function of traffic
Regular expression (user name form verification / verification of landline number / regular replacement)
XxE & XML external entity injection utilization and bypass