Just like any other language, verilog also uses operators. Most of these you would be familiar from other high level languages. But, there are a few operators which are more consistent with only an HDL laguage. Following is the list of all operators which would be required by an engineer to remember.
Operator | Description |
---|---|
{ }, { { } } | Concatenation, replication |
+, -, *, /, ** | Arithematic |
% | Modulus |
>, >=, <=, < | Relational |
! | Logical Negation |
&& | Logical AND |
|| | Logical OR |
== | Logical Equality |
!= | Logical Inequality |
=== | Case Equality |
!== | Case Inequality |
~ | Bitwise INVERT |
& | Bitwise AND |
| | Bitwise OR |
^ | Bitwise XOR |
^~, ~^ | Bitwise Equivalence |
&, ~&, |, ~|, ^, ~^, ^~ | Reduction Operators |
<< | Logical Left Shift |
>> | Logical Right Shift |
<<< | Arithematic Left Shift |
>>> | Arithematic Right Shift |
? : | Conditional Operator / Ternary Operator |
module top; reg [31:0] VAR = $random; initial begin reg PARITY; PARITY = ^VAR; $display("Parity Is : %0d", PARITY); end endmodule
module top; integer ADDR = 103; initial begin $display("Address Offset From Nearest Segment Boundary : %0d", ADDR-((ADDR/(128/4))*(128/4))); end endmodule
module top; integer ADDR_1 = 678; integer ADDR_2 = 811; integer SEG_SIZE = 1024/8; initial begin $display("Address 1 Offset From Nearest Segment Boundary : %0d", ADDR_1-((ADDR_1/(SEG_SIZE))*SEG_SIZE)); $display("Address 2 Offset From Nearest Segment Boundary : %0d", ADDR_2-((ADDR_2/(SEG_SIZE))*SEG_SIZE)); end endmodule
module top; reg [31:0] NUM; initial begin reg [3:0] HEX_VAL = $urandom; // Hex symbol is picked // Now populate the whole of NUM with this hex symbol integer i = 0; for( i = 0; i < 32/4; i = i + 1 ) begin NUM[i*4+:4] = HEX_VAL; end $display("Output : %h",NUM); end endmodule