Verilog 递减运算符(缩减运算符)(Reduction operators),以及$display系统函数 ModelSim 仿真

Verilog 递减运算符(缩减运算符)(Reduction operator ),以及$display系统函数 ModelSim 仿真

更多操作符请参考这篇:
https://blog.csdn.net/malcolm_110/article/details/107784776

递减运算符(Reduction Operators)为单目运算符,运算符紧跟变量,结果为1bit值。
如“&C”表示将C的第一位与第二位相与,再将结果与第三位相与,再与第四位…一直到最后一位。

OperatorDescription
&and
~&nand
|or
~|nor
^xor
^~ or ~^xnor

仿真:
1.打开modlesim, File – new – source ,输入如下代码。
2. Saveas
3. 点击compile,找到刚才存储文件的路径,选中文件。
4. 点击simulate,在弹出串口中,点击最上面work前面的加号,选中跟module相同名字的选项,点右下角OK。
5. 在下面的transcript串口输入run命令,即可看到$display 函数的效果。
在这里插入图片描述

拷贝如下代码:

module reduction_operators();

initial begin
  // Bit Wise AND reduction
  $display (" &  4'b1001 = %b", (&  4'b1001));
  $display (" &  4'bx111 = %b", (&  4'bx111));
  $display (" &  4'bz111 = %b", (&  4'bz111));
  // Bit Wise NAND reduction
  $display (" ~& 4'b1001 = %b", (~& 4'b1001));
  $display (" ~& 4'bx001 = %b", (~& 4'bx001));
  $display (" ~& 4'bz001 = %b", (~& 4'bz001));
  // Bit Wise OR reduction
  $display (" |  4'b1001 = %b", (|  4'b1001));
  $display (" |  4'bx000 = %b", (|  4'bx000));
  $display (" |  4'bz000 = %b", (|  4'bz000));
  // Bit Wise OR reduction
  $display (" ~| 4'b1001 = %b", (~| 4'b1001));
  $display (" ~| 4'bx001 = %b", (~| 4'bx001));
  $display (" ~| 4'bz001 = %b", (~| 4'bz001));
  // Bit Wise XOR reduction
  $display (" ^  4'b1001 = %b", (^  4'b1001));
  $display (" ^  4'bx001 = %b", (^  4'bx001));
  $display (" ^  4'bz001 = %b", (^  4'bz001));
  // Bit Wise XNOR
  $display (" ~^ 4'b1001 = %b", (~^ 4'b1001));
  $display (" ~^ 4'bx001 = %b", (~^ 4'bx001));
  $display (" ~^ 4'bz001 = %b", (~^ 4'bz001));
  #10 $finish;
end

endmodule

可以看到如下效果:

 &  4'b1001 = 0
  &  4'bx111 = x
  &  4'bz111 = x
  ~& 4'b1001 = 1
  ~& 4'bx001 = 1
  ~& 4'bz001 = 1
  |  4'b1001 = 1
  |  4'bx000 = x
  |  4'bz000 = x
  ~| 4'b1001 = 0
  ~| 4'bx001 = 0
  ~| 4'bz001 = 0
  ^  4'b1001 = 0
  ^  4'bx001 = x
  ^  4'bz001 = x
  ~^ 4'b1001 = 1
  ~^ 4'bx001 = x
  ~^ 4'bz001 = x
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值