1. It is legal. (You wait for 5 time units, invert value of a and assign it to a)
2. This is different. you are modelling transport delay here.
3.Define the timescale accordingly..
With VHDL, this will generate a periodic waveform:
Code:
a <= not a after 5ns ;
Why should this yield a different result?
Code:
assign #5 a = ~a;
We assign the inverted value of a to itself with a delay of 5 - and we do it all the time. It sounds like this block of code should also yield a periodic waveform with a duty cycle of 50%.
Uh, assign #5 a = ~a; isn't going to work in simulation. All you'll get is x as a cannot be initialized as it is defined as a wire and you can't initialize a continuous assignment.
So you won't be able to generate a clock in this fashion.
Use one of these to generate a clock in the testbench in Verilog:
// define a as a regreg a;// using foreverinitialbegin
a =0;forever#5 a =~a;end// using alwaysinitialbegin
a =0;endalwaysbegin#5 a =~a;end// alternative using always (starts off as x unless you add an initial block)alwaysbegin#5 a =0;#5 a =1;end
Uh, assign #5 a = ~a; isn't going to work in simulation. All you'll get is x as a cannot be initialized as it is defined as a wire and you can't initialize a continuous assignment.
Just tested this in both Modelsim and Vivado's simulator. Works fine in Modelsim, but doesn't work correctly in Vivado's simulator (a changes one time from 0 to 1 and never updates after that.
Unfortunately we only have a couple of Modelsim licenses and they get hogged by others so I have to use Vivado's simulator and unfortunately it's SV support is spotty at best and isn't even officially documented.
I used the following code to test this.
Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
`timescale1ns/1nsmodule assign_test;bit a;assign#5 a =~a;initialbegin$monitor("%t - a = %b",$time, a);endendmodule
Vivado output:
Code:
Time resolution is 1 ns
xsim% run 100 ns
0 - a = 0
5 - a = 1
modelsim output:
Code:
Time resolution is 1 ns
xsim% run 50
0 - a = 0
10 - a = 1
15 - a = 0
20 - a = 1
25 - a = 0
30 - a = 1
35 - a = 0
40 - a = 1
45 - a = 0
50 - a = 1