当前位置:网站首页>赋值时'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
边栏推荐
- 1913. 两个数对之间的最大乘积差-无需排序法
- 生成随机数random学习之uniform_int_distribution,uniform_real_distribution
- [QNX Hypervisor 2.2用户手册]9.7 generate
- Several commonly used traversal methods
- POI special effects Market Research
- 762. Prime number calculation setting in binary representation
- Canada EE channel
- Mongodb query and projection operators
- 图的遍历-DFS,BFS(代码详解)
- Deep and shallow copies
猜你喜欢

BI 系统中为什么会有很多快照表?

意向不到的Dubug妙招

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

学习探索-波浪

chown: changing ownership of ‘/var/lib/mysql/‘: Operation not permitted

学习探索-3d轮播卡片
![[testing technology automated testing pytest] basic summary of pytest](/img/30/7c632cd6ad93c9294745dda7642f17.png)
[testing technology automated testing pytest] basic summary of pytest

File contains vulnerability

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

多模态——Deep Multi-Modal Sets
随机推荐
Summary of built-in instructions and custom instructions
Simulate and implement common interfaces of string class
类和对象(2)(6个默认成员函数)
Anti shake and throttling
学习探索-3d轮播卡片
Learning exploration - waves
XxE & XML external entity injection utilization and bypass
Docker installation redis-5.0.12 (remote access)
[QNX Hypervisor 2.2用户手册]9.8 load
TS class
E-commerce RPA, a magic weapon to promote easy entry
多模态——Deep Multi-Modal Sets
Promise asynchronous callback function
TS basic data type
Summary of kotlin common knowledge points
从哪些维度评判代码质量的好坏?如何具备写出高质量代码的能力?
Dynamic memory management
Node基础
EasyExcel实用技巧
利用用户脚本优化 Yandere/Konachan 站点浏览体验