Verilog基础知识(有符号数运算规则,加减运算,乘法运算中的符号位拓展问题)

本文详细介绍了Verilog中有符号数的表示方法及其在加法、乘法运算中的应用,包括不同版本Verilog语法的区别及注意事项。同时,还探讨了有符号数与无符号数混合运算时的处理方式。

rule of thumb

  1. The format of the signed type is two’s complement. 有符号数均为补码表示
  2. If any operand in an expression is unsigned the operation is considered to be unsigned. 只有计算表达式右边有无符号数,整个计算式都按照无符号数规则运算
  3. 只有算式右边全为有符号数,运算才会自动补齐所需的bit数,n+n=n+1.n*n=2n
  4. The value -4 represented as a 3bit signed hex value would be specified as -3’sh4. A decimal number is always signed. verilog2001中用’s来特别声明有符号数,十进制的数都是有符号数
  5. Type casting using $unsigned will make the operation unsigned. The operand will be sign extended with 0’s if necessary. $usigned()函数在高位补0
  6. A=$signed(B) will extend using sign bit. $unsigned()函数会在高位补与符号位相同的bit

basic signed addition

两个n bit数相加,得到n+1 bit结果,比如-2(3’sb110)+3(3’sb011)=1(4’sb0011)

//Code Example 1: Addition - Verilog 1995
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值