Question HVL234
Question HVL234
1. What will be the equivalent code of the following Verilog code using blocking statements? No
temporary variable.
Initial
Begin
A = 10;
A <= 25;
B <= A;
End
4. What will be the logic implementation using a case statement and an if-else statement?
Answer: - Multiplexer.
module delay(in,transport,inertial);
input in;
output transport;
output inertial;
reg transport;
wire inertial;
// behaviour of delays
always @(in)
begin
transport <= #10 in;
end
endmodule // delay
_______
inertial _________| |____________
Non blocking assignment gives you transport delay. Whenever input changes, output is immediately
evaluated and kept in a event queue and assigned to output after specified "transport" delay.
In Continuous assign statement the latest event overrides the earlier event in the queue.
module test;
reg in;
wire transport, inertial;
// apply inputs
initial
begin
in = 0;
#20 in = 1;
#20 in = 0;
#30 in = 1;
#5 in = 0;
#30 in = 1;
#30 $finish;
end
// monitor signals
initial
begin
$monitor($time," in = %b transport = %b inertial = %b",
in,transport, inertial);
end
endmodule // test
log file
Compiling source file "delay.v"
Highest level modules:
test
0 in = 0 transport = x inertial = x
10 in = 0 transport = 0 inertial = 0
20 in = 1 transport = 0 inertial = 0
30 in = 1 transport = 1 inertial = 1
40 in = 0 transport = 1 inertial = 1
50 in = 0 transport = 0 inertial = 0
70 in = 1 transport = 0 inertial = 0
75 in = 0 transport = 0 inertial = 0
80 in = 0 transport = 1 inertial = 0
85 in = 0 transport = 0 inertial = 0
105 in = 1 transport = 0 inertial = 0
115 in = 1 transport = 1 inertial = 1
L35 "delay.v": $finish at simulation time 135
81 simulation events
6. always clock = #2.5 clock; delayed_clock = #7 clock. What will be the simulation result?
Question: - Write a Verilog code for a single clock FIFO.
Answer: -
7. Difference between compiled code and normal simulator. A compiled code simulator compiles all
the files(design and verification) and writes out an executable(similar to a.out, for people familiar
with C language). The engineer then needs to run this executable in order to perform the
simulation. This simulator will speed up the simulation since it need not compile each and every
file for every simulation run. It will detect the files that are modified and compile those files and
files that depend on those modified files. A normal simulator performs compilation and execution
in the same step. So it has to compile each and every file whenever a simulation is performed.
8. Blocking and Non-blocking assignments*
Case I: Blocking Procedural Assignments
Initial begin
#1 a=b;
#1 c=d;
#1 e=f;
end
In this case, as soon as the initial block is entered, we wait for 1time unit and then sample the
value of b and assign that value of b to a. Then wait for 1 more time unit, sample the value of d
and assign that value of d to c and so on.
Case II: Blocking Intra-procedural assignment
Initial begin
a= #1 b;
c= #1 d;
e= #1 f;
end
In this case, as soon as the initial block is entered, we sample the value of b, then wait for 1 time
unit and assign that value of b to a. Then sample the value of d, wait for 1 more time unit, and
assign that value of d to c and so on.
Case III: Non-Blocking procedural assignment
Initial begin
#1 a <= b;
#1 c <= d;
#1 e <= f;
end
In this case, as soon as the initial block is entered, we wait for 1time unit and then sample the
value of b and assign that value of b to a. Then wait for 1 more time unit, sample the value of d
and assign that value of d to c and so on. Because its non-blocking assignment, the assignment
is made at the END of the timestep.
Case IV: Non-Blocking Intra-procedural assignment
Initial begin
a<= #1 b;
c<= #1 d;
e<= #1 f;
end
In this case, as soon as the initial block is entered, we sample the value of b,d and f, then wait for
1 time unit and assign that value of b to a, value of d to c and the value of f to e.
Answer: - Special versions of the case statement allow the x ad z logic values to be used
as "don't care":
Question: - What's the difference between a latch and a flip-flop? Write Verilog RTL code for
each?
Answer: - A latch is a level sensitive where as Flip-Flop is a edge sensitive.
Question: - assign #4 out = in; in the above statement if the signal in changes with in 4 units of
time what will be the value of out after 4 units?
Answer: -
Question: - Whatever a function does, a task can also do. Why do we still use functions?
Out = select?In1:In2;
Always @ (select or In1 or in2)
Begin
Case{select}
Endcase
End
Question: - What are the various timing violations: setup, hold, width, recovery, remova
`timescale <reference_time_unit>/<time_precision>
Timescale directive tends to make more sense at gatelevel simulation than at RTL simulation.
module mdl;
--
--
fork
m;
m;
m;
join
1 module re_entrant_task();
2
3 task automatic print_value;
4 input [7:0] value;
5 input [7:0] delay;
6 begin
7 #(delay) $display("%g Passed Value %d Delay %d", $time, value,
delay);
8 end
9 endtask
10
11 initial begin
12 fork
13 #1 print_value (10,7);
14 #1 print_value (8,5);
15 #1 print_value (4,2);
16 join
17 #1 $finish;
18 end
19
20 ndmodule