Hardware Modeling Using Verilog Assignment-Week 4
Hardware Modeling Using Verilog Assignment-Week 4
QUESTION 1:
If A, B, C and D are reg, reg, integer and wire variables respectively, each of size [7:0], which of
the following is/are allowed inside a procedural block?
a. D = A + B;
b. C = A + D;
c. D = C + 1;
d. B[3:0] = D[4:1] + 1;
Correct Answer: b, d
Detailed Solution:
In a procedural assignment statement, only register type variables or part select thereof can be
used in the left hand side. A wire type variable cannot be assigned a value within a procedural
block. Hence, the correct options are (b) and (d).
______________________________________________________________________________
QUESTION 2:
For the following code segment, the final value of variable “d” will be …………..
integer a, b, c, d;
initial
begin
a = 25; b = 12; c = 5; d = 17;
a = b + c;
b = a – 15;
c = a + d;
d = c + d;
end
HINT: ( Please provide numeric answer, e.g. 37, do not type thirty seven.)
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
Correct Answer: 51
Detailed Solution:
QUESTION 3:
For the following code segment, the final value of variable “d” will be …………..
integer a, b, c, d;
initial
begin
a = 25; b = 12; c = 5; d = 17;
end
initial
begin
a <= #10 b + c;
b <= #10 a – 15;
c <= #10 a + d;
d <= #10 c + d;
end
HINT: ( Please provide numeric answer, e.g. 53, do not type fifty three.)
Correct Answer: 22
Detailed Solution:
In non-blocking statements inside a procedural block, all right hand side expressions are
evaluated in parallel, and are assigned to the left hand side variables all together.
First assignment: a = 12 + 5 = 17
Second assignment: b = 25 – 15 = 10
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
Third assignment: c = 25 + 17 = 42
Fourth assignment: d = 5 + 17 = 22
Thus, final value of variable “d” will be 22.
______________________________________________________________________________
QUESTION 4:
What will the following code segment do?
Correct Answer: b
Detailed Solution:
Because the assignments are blocking, first, the value of “x” will be assigned to “y”, and then
the new value of “y” will be assigned to “z”, and then the new value of “z” will be assigned to
“x”. Thus all the three variables will get the previous value stored in “x”. Hence, the correct
option is (b).
______________________________________________________________________________
QUESTION 5:
If the 8-bit variable “data” declared as “reg [7:0] data” is initialized to 8’b01100101,
what will be its value after execution of the following code segment?
end
a. 8’b10110010
b. 8’b00110010
c. 8’b01110010
d. None of these.
Correct Answer: a
Detailed Solution:
______________________________________________________________________________
QUESTION 6:
What will the following code segment generate on synthesis, assuming that the four variables
data0, data1, data2 and data3 map into four latches / flip-flops?
Correct Answer: a
Detailed Solution:
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
Since blocking assignment statements are executed sequentially one after another, the value of
“din” will be first assigned to “data3”, then to “data2”, then to “data1”, and finally to “data0”.
Thus, the same input will feed all the four D flip-flops in the synthesized circuit. The correct
option is (a).
______________________________________________________________________________
QUESTION 7:
What will the following code segment generate on synthesis?
Correct Answer: b
Detailed Solution:
Since we use non-blocking assignments, the values on the RHS are assigned to the variables on
the LHS in synchronism with the clock. This will generate a 4-bit shift register. Thus, the correct
option is (b).
______________________________________________________________________________
QUESTION 8:
What does the following Verilog module do?
genvar p;
generate for (p=0; p<N; p=p+1)
begin xorlp
xor XG (f[p], a[p], b[p]);
end
endgenerate
endmodule
a. Generates the sum of the two N-bit numbers “a” and “b”, and stores it in “f”
b. Performs the bitwise XOR of “a” and “b”, and stores it in “f”
c. Computes whether the number of bits in “a” and “b” are odd
d. None of these.
Correct Answer: b
Detailed Solution:
As discussed in Example 1 of Lecture 19, this Verilog module will generate N XOR gates, and will
compute the bitwise XOR of the two numbers “a” and “b”. Thus, the correct option is (b).
______________________________________________________________________________
QUESTION 9:
Which of the following is/are not true for “generate” blocks?
Correct Answer: d
Detailed Solution:
All of (a), (b) and (c) are true for “generate” blocks. Hence, the correct option is (d).
______________________________________________________________________________
QUESTION 10:
Which of the following is/are true for user defined primitives in Verilog?
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur
Correct Answer: b, d
Detailed Solution:
************END*******