Solution of Quiz 5
Solution of Quiz 5
Solution of Quiz 5
Answer: (b)
The “always” block also used inside test bench for generating inputs. Thus
option (a) is false. Both blocking and non-blocking assignments are
allowed inside “always” block. Thus option (b) is true. The RHS of an
assignment inside “always” block can be register or wire type. Thus
option (c) is false. Only procedural assignment statements are allowed
inside the “always” block. Thus option (d) is also false.
Answer: (d)
The $dumpall directive dump current values of the variables, whereas
$dumpvar directive without any parameter dump all values of the all
variables only when there is change in values. Thus option (a) is false. The
dumped file contains information about changes of values of selected
variables. Thus option (b) is false. The $dumpon directive is used to start
previously stopped dumping of variables. Thus option (c) is false. After
encountering the $dumpoff statement, all variables are dumped with “x”
values and next change of variables will not be dumped. Thus option (d) is
true.
4. Which of the following are true about the following verilog directive
`timescale 10ns / 10ps
a. The synthesis tool interprets 10 nanoseconds as unit of delay.
b. The directive is only considered during simulation and ignores
during actual synthesis.
c. The simulator interprets 10 nanoseconds as unit of delay with a
resolution of 10 picoseconds.
d. The directive is considered during simulation and synthesis both.
Answer: (b)
Here timescale is 10 ns. Thus the delay of 10.4567 will become 104.567 ns
and the fractional part will be rounded to the nearest time precision i.e.
10.600 ns. Thus option (b) is correct and option (a), (c) and (d) are not
correct.
Answer: (a)
Here the “clk” variable is initialized with 0 and changes it’s state at a
regular interval of 10 time unit. So the raising edge of the clk variable will
be at time unit 10, 30, 50, 70, … . The for loop after an initial delay of 5
time unit and variable “x” is assigned values 0 to 15 after a delay of 20
time unit. Thus value of “x” will be updated at time units 25, 45, 65, …, so
on before the raising edge of the clock “clk”.
7. What will be the time period of the clock (clk) generated by the following
code segment?
`timescale
10ns/1ns module
test_dut; reg clk
initial
#0.35 clk = 1’b0;
always
#0.63 clk = ~clk;
endmodule
a. 6.2 ns
b. 7 ns
c. 12 ns
d. 9.7 ns
Answer: (c)
Here the time scale is 10ns with precision 1ns. Thus the “clk” variable will
be toggled after 6 ns and the “clk” value will be repeated after 12ns. Thus
option (c) is correct, and options (a), (b) and (d) are incorrect.
8. What will be the time period of the clock (clk) generated by the
following code segment?
`timescale 10ns/10ns
module test_dut;
initial
clk = 1’b1;
always
forever begin
#2.2 clk = 1’b0;
#1.5 clk = 1’b1;
end
endmodule
a. 40 ns
b. 3.7 ns
c. 37 ns
d. 30 ns
Answer: (a)
Here the time unit is 10ns with precision 10ns. Thus here the clock will
remain 0 for 20 time unit and 1 for 20 time unit. Thus option (a) is
correct, and options (b), (c) and (d) are incorrect.
10. The number of flip-flops will be realized by the following code segment
will be ……………
module demo_fsm (clk, signals);
input clk;
output reg [4:0] signals;
parameter S0=0, S1=1, S2=2; S3=3, S4=4;
reg [0:2] state;
always @(posedge clk)
case (state)
S0: begin
signals<= 5’b11100; state <= S3;
end
S1: begin
signals<= 5’b10010; state <= S2;
end
S2: begin
signals<= 5’b01011; state <= S0;
end
S3: begin
signals<= 5’b01001; state <= S4;
end
S4: begin
signals<= 5’b01101; state <= S1;
end
default: begin
signals<= 5’b01010; state <= S0;
end
endcase
endmodule
Answer: 8
Here flip-flops will be synthesized for both the signals and state
variables. Thus the number of flip-flop will be 5 + 3 = 8.