Google+ VLSI QnA: Verilog Interview Questions - v1.3

Sunday 4 May 2014

Verilog Interview Questions - v1.3

Q.1) Explain inter-assignment and intra-assignment delay.

Answer) Inter-assignment delay is used when a delay is specified to the left of a procedural assignment.
reg a, b;
initial
begin
    a = 0;
    #10 b = 1;
end
The execution of the procedural assignment is delayed by the number specified by the delay control. Therefore, the 'b' assignment is delayed by the 10 time units.

Intra-assignment delay is used when a delay is specified to the right of a procedural assignment.

reg a, b, c;
initial
begin
   a = 0; b = 0;
   c = #10 a + b;
end
The execution of above statement takes as follows : 
            Take the value of a and b at the time = 0, evaluate a + b and then wait 10 time units to assign value to c.

Q.2) What will be the output/effect of the following statements?
a) a = 4'd12;
    $display("Value of a = %b\n", a);
b) b = 3'd2;
    $monitor($time, "Value of b = %b\n", b[2:0]);
c) `define SIZE 1024
    $display(" Size is %h", SIZE);

Answer) 
a) Value of a = 1100
b) 0Value of b = 010
c) Size  is 00000400

Q.3) What will be the output of following code?
reg a,b,c;
reg [2:0] d;
initial
begin
   a = 1'b0;
   $display("Time %t a %b b %b c %c d %d",$time,a,b,c,d);
   b = #10 1'b1;
   $display("Time %t a %b b %b c %c d %d",$time,a,b,c,d);
   c = #5   1'b0;
   $display("Time %t a %b b %b c %c d %d",$time,a,b,c,d);
   d = #20 {a,b,c};
   $display("Time %t a %b b %b c %c d %d",$time,a,b,c,d);
end

Answer)
Time 0 a 0 b x c x d x
Time 10 a 0 b 1 c x d x
Time 15 a 0 b 1 c 0 d x
Time 35 a 0 b 1 c 0 d 010

Q.4) What will be the output of the below initial block?
initial
begin
   a = 1'b0;
   $display("Initial 1 a  %b b %b c %b d %b\n",a,b,c,d);
   #0 c = b;
   $display("Initial 2 a  %b b %b c %b d %b\n",a,b,c,d);
end
initial
begin
   b = 1'b1;
    $display("Initial 3 a  %b b %b c %b d %b\n",a,b,c,d);
   #0 d = a;
   $display("Initial 4 a  %b b %b c %b d %b\n",a,b,c,d);
end

Answer) Initial 1 a 0 b x c x d x
               Initial 3 a 0 b 1 c x d x
               Initial 2 a 0 b 1 c 1 d x
               Initial 4 a 0 b 1 c 1 d 0

Q.5) What is the final value of d?
initial
begin
    b = 1'b1; c = 1'b0;
    #10 b = 1'b0;
end
initial
begin
    d = #25 (b|c);
end

Answer) In the above example, both the initial blocks will be executed at the same time. Since, in the second initial block, there is an intra assignment delay, so the value of d will be calculated at 0 time, but will be assigned after 25 time units. So, the final value of d will be 1.

No comments:

Post a Comment