Let's start with d=0 q1=1 q2=2 q3=3.
always@(posedge clk)
begin
q1=d;
q1 immediately gets the value of d=0.
q2<=q1;
Non-blocking assignment: save the current value of q1 (which is currently the same as d=0)
q3=q2;
q3 gets the unchanged value of q2, =2
end
At this point the nonblocking assignment happens and q2 gets the value 0.
I'm assuming the next always block is in a different module; putting it in the same module will just cause further confusion as you're overwriting the same variables again.
Start with d=0 q1=1 q2=2 q3=3 again.
always@(posedge clk)
begin
q1<=d;
q2<=q1;
Queue assignment of q1 to 0 and q2 to 1. These happen at the end of the block.
q3=q2;
Set q3 to the current value of q2, ie 2.
end
Finally set q1=0 and q2=1.
Generally it's bad style to mix = and <= in the same block, and generally for synthesis you should always use <=. '=' can be helpful in testbenches where it behaves more like a conventional imperative programming language.
1'b0 is Verilog syntax for a constant value that is a one bit number expressed in binary format with a value of zero.
A bit value of one would be expressed as 1'b1.
Similarly a four bit value in binary that is equivalent magnitude to a decimal value of 11 could be written as 4'b1011.
You could also express this same value in a hexadecimal notation as 4'hB.
Best Answer
Even though the type indicator may be hexadecimal or decimal, the size indicator is always measured in bits.
8'h81
Since
81
is an 8-bit number in binary (1000 0001
), it requires 8 bits. This is why the size is 8, even though the number is expressed in hex.Also, size may be the bus size that the signal is driving (or part of it), even though the value itself may require fewer bits.
This is shown here:
16'd5
The decimal
5
only needs 3 bits (101
), however, this value may be desgnated for a 16 bit bus:While verilog does pad smaller sizes, sometimes if you're concatenating, you want to specify each length:
In the last case:
32'h8f_32_ab_f7
32 bits are required to store the hexadecimal number, which is
1000 1111 0011 0010 1010 1011 1111 0111
in binary.The hexadecimal is just the short way of writing the number, but the size is still 32 bits.