Operation: The bitwise-NOT operator performs a bitwise inversion on its operand. This means that each bit of the operand is flipped; 0 becomes 1 and 1 becomes 0.
Usage: It is used when you need to invert the bits of a binary number or a vector.
Logical-NOT (!)
Operation: The logical-NOT operator evaluates the logical value of its operand. It converts 0 to 1 and any non-zero value to 0.
Usage: It is used when you want to negate a condition or expression. This is typically used in control flow statements like if or while.
bitwise-AND (&) and logical-AND (&&)
Norgate
1 2 3 4 5 6
module top_module( input a, input b, output out ); assign out=~(a|b); endmodule
Xnorgate
1 2 3 4 5 6
module top_module( input a, input b, output out ); assign out=~(a^b); endmodule
wire [7:0] w; // 8-bit wire reg [4:1] x; // 4-bit reg outputreg [0:0] y; // 1-bit reg that is also an output port (this is still a vector) inputwire [3:-2] z; // 6-bit wire input (negative ranges are allowed) output [3:0] a; // 4-bit output wire. Type is 'wire' unless specified otherwise. wire [0:7] b; // 8-bit wire where b[0] is the most-significant bit.
Build a combinational circuit that splits an input half-word (16 bits, [15:0] ) into lower [7:0] and upper [15:8] bytes.
Module Declaration
1 2 3 4 5
`default_nettype none // Disable implicit nets. Reduces some types of bugs. module top_module( input wire [15:0] in, output wire [7:0] out_hi, output wire [7:0] out_lo );
1 2 3 4 5 6 7 8 9
`default_nettype none // Disable implicit nets. Reduces some types of bugs. module top_module( inputwire [15:0] in, outputwire [7:0] out_hi, outputwire [7:0] out_lo ); assign out_lo=in[7:0]; assign out_hi=in[15:8]; endmodule
Vector 2
A 32-bit vector can be viewed as containing 4 bytes (bits [31:24], [23:16], etc.). Build a circuit that will reverse the byte ordering of the 4-byte word.
This operation is often used when the endianness of a piece of data needs to be swapped, for example between little-endian x86 systems and the big-endian formats used in many Internet protocols.
1 2 3 4 5 6 7 8 9 10
module top_module( input [31:0] in, output [31:0] out );//