Verilog_notes topper notes
Verilog_notes topper notes
module _name_;
This is written when we start a new section of the code and is like a small box where
we write our instructions. It can be named anything.
reg a,b;
wire _exit_port_name, output_port_name;
a and b are given the datatype register which will get turned on and off. They act like
inputs.
The wire datatype will carry out the outputs from the gates/circuits. Both of these
things can be named anything.
Remember the wire is the output and reg is the register which is the input type.
Then we connect our circuits/gates.
and_gate and1 (
.a(a),
.b(b),
.result(and_out)
);
Each block in this sample connects a specific type of gate, it can be a circuit as well.
The line inside tells the machine to take the input and process them through the logic
gate given and then send the result out through the specific wire name.
why are we writing .a(a), what if we write something else inside the bracket and why
is there a dot
the ‘.a(a)’ is used to connect the internal port of the module (‘a’) to a signal outside
the module. The dot indicates which specific port we are connecting it to.
‘.a(a)’ means "connect the module's internal port ‘a’ to the signal called ‘a’ in the
testbench."
The first ‘a’ after the dot is the name of the internal port defined in the module and the
‘a’ inside the bracket is the signal or wire in the testbench that we wish to connect to
the port.
The dot ‘(.)’ helps Verilog know that you are specifying which port inside the module
you want to connect to something in the testbench. Without it, Verilog would not
know which internal port you’re referring to.
a = 0; b = 0;
#10;
$display("a=%b, b=%b, AND=%b, XOR=%b, NOR=%b, XNOR=%b", a, b, and_out,
xor_out, nor_out, xnor_out);
Here we are testing different combination of the switches to find out the outputs. The
#10 tells the amount of time the machine should wait before checing the result.
The thing inside the display tells what to print.
$finish
End
This tells the machine that the test is complete and the block is now closed.
The Display syntax
$display("input1=%b, input2=%b, AND=%b, XOR=%b, NOR=%b, XNOR=%b", input1,
input2, and_output, xor_output, nor_output, xnor_output);
The things inside the inverted comma except the ‘%b’ will be printed out exactly in the
output. The first %b corresponds to input1, the second %b corresponds to input2, the third
%b corresponds to and_output, and so on.
Common Format Specifiers:
%b: Binary format.
%d: Decimal format.
%h: Hexadecimal format.
%o: Octal format.
%s: String format.
%c: Character format.
// Logic description
assign result = a & b; // AND operation
endmodule