2_Verilog_assignment_blocking_and_non_blocking
2_Verilog_assignment_blocking_and_non_blocking
Q1. Given the following Verilog code, what will be the value of "a" at output?
(a)
always @(clk) begin
a = 0;
a <= 1;
$display(a);
end
(b)
always @(clk) begin
a <= 0;
a = 1;
$display(a);
end
Q2. Develop a Verilog code to swap contents of two registers without using a temporary register?
Q3. Analyze the value of ’A’ and ‘B’ in the following two Verilog codes:
(a)
module blocking;
reg [0:7] A, B;
initial begin: init1
A = 3;
#1 A = A + 1; // blocking procedural assignment
B = A+1;
$display("Blocking: A= %b B= %b", A, B );
endmodule
(b)
module nonblocking;
reg [0:7] A, B;
initial begin: init1 A = 3;
#1 A <= A + 1; // non-blocking procedural assignment
B <= A+1;
#1 $display("Non-blocking: A= %b B= %b", A, B );
end
endmodule
1
Blocking & non-blocking
Q4. Registers x and y are declared as reg [2:0] x,y;. x and y have initial values of 1 and 2
respectively. Find the value of x and y after each of the following Verilog codes have been
executed.
(a) y = x && y;
x = y & x;
(b) x <= (y) ? y : x;
y <= (x) ? x : y;
(c) x = (y) ? y : x;
y = (x) ? x
: y;
(d) x <= x << 1;
x[0] <= x[2];
(e) x = x && (˜y);
y = x + y;
Q5. Registers a, b are declared as reg [2:0] a,b;. a and b have initial values of 3 and 1 respectively.
Find the values of a and b after each of the following Verilog codes are executed.
(a) a = b + 2;
b = a + 2;
(b) b = a + 2;
a = b + 2;
(c) a <= b + 2;
b <= a + 2;
(d) b <= a + 2;
a <= b + 2;
(e) b = a && b;
a = b & a;
(f) a <= |b;
b <= &a;
2
Blocking & non-blocking
Q6. How will these procedural assignments behave, draw the waveform for o1, o2, o3,o4, o5, o6?
Also Specify the type of assignment(blocking/nonblocking).
3
Blocking & non-blocking
4
Blocking & non-blocking
Q7. How will the following procedural assignments behave? Draw the waveforms for Y1 and Y2,
for the given inputs. Also draw the hardware for all the codes.
5
Blocking & non-blocking
y2 = y1;
Q8. Assume state and next_state are `STOP at the first clock, what is state in the following code:
- At the 2nd clock?
- At the 3rd clock?
- At the 4th clock?
- At the 5th clock?
6
Blocking & non-blocking
Q9. Write a procedure for an adder (combinational logic) that assigns C the sum of A plus B with
a 7ns propagation delay.
Q10. Write the procedure(s) for a 4-bit wide shift register (positive edge triggered) of clock and
has a 4ns propagation delay.
(b)
(c)
(d)
7
Blocking & non-blocking
Q12. Draw the RTL design of the following Verilog codes. “Simulate the circuit’s behavior by loading
the pattern 001 into the LFSR and then enabling the register to count. What is the counting sequence
for all?
a)
module lfsr (R, L, Clock, Q);
input [0:2] R;
input L, Clock;
output reg [0:2] Q;
always @(posedge Clock) begin
if (L)
Q<=R;
else
Q < = {Q[2], Q[0]^Q[2], Q[1]};
end
endmodule
b)
module lfsr (R, L, Clock, Q);
input [0:2] R;
input L, Clock;
output reg [0:2] Q;
always @(posedge Clock) begin
if (L)
Q<=R;
else
Q < = {Q[2], Q[0], Q[1]^Q[2]};
end
endmodule
c)
8
Blocking & non-blocking
d)