Midterm f02 Solutions
Midterm f02 Solutions
Midterm Exam
Thursday, October 24, 2002
1:00--2:15PM (75 minutes)
Instructions:
1.
2.
3.
4.
Problem
Points
18
20
16
10
12
12
Total
88
Score
Solution notes: Answers are given in boxes. For many questions, multiple answers are possible.
10/31/02
(c) (2 pts) Write a Verilog statement that declares a 6-bit register constant, C_24, with the
decimal value 24.
parameter C_24 = 6d24;
(d) (2 pts) Write Verilog code that declares an 8-bit register, R_H38, and initially assigns it the
hexadecimal value 38.
reg [7:0] R_H38;
initial R_H38 = 8h38;
.
(e) (4 pts) Complete the following clk_gen module, which generates a clock signal that initially
goes to zero for 15 ns, then goes to one for 5 ns, and then repeats this pattern indefinitely.
Your module can only use one initial statement.
module clk_gen;
reg clock;
initial begin
clock = 0;
forever begin
#15 clock = 1;
#5 clock = 0;
end
end
endmodule;
10/31/02
(f) (3 pts) Give the instantiation of an array of five 3-input AND gates (with inputs a, b, and c
and output y, and the instance name A3), where each AND gate has a falling delay of 12 time
units and a rising delay of 9 time units. Assume a, b, c, and d are each 5-bit wires.
and #(9, 12) A3[0:4] (y, a, b, c);
10/31/02
(c) (3 pts) Draw a gate-level diagram for your module in (b). Label all nets on the diagram
and write the delay of each gate inside the gate.
Answers vary based on design in (b).
(d) (6 points) Rewrite the RTL_circuit using behavioral Verilog . Use a specify section and
specparam to specify the delays between inputs and outputs. Part of the module is done
for you.
module Behave_circuit(x, y, a, b, c, d);
input a, b, c, d;
output x, y;
reg x, y;
always @(a, b, c, d) begin
y = (a | b) & (c | ~d);
x = a ^~ b;
end
specify
specparam x_delay = 3, y_delay = 7;
(a, b, c, d *> y) = y_delay;
(a, b *> x) = x_delay;
endspecify
endmodule;
(e) (2 pts) Show how to use the timescale directive so that the x_delay and y_delay
correspond to 0.3 ns and 0.7 ns, respectively and the simulator time step is 1 ps.
timescale 100 ps / 1 ps
10/31/02
10/31/02
(c) (2 pts) What is an advantage that VHDL has over Verilog in terms of design reuse?
VHDL supports packages and libraries, which allows components, functions, tasks, type
declarations, etc. to be used by other entities.
(d) (2 pts) What are two advantages that Verilog has over VHDL in terms of support for lowlevel constructs.
Verilog supports both built-in primitives and user-define primitives. VHDL does not.
(e) (2 pts) In what way is the VHDL generate statement more powerful than Verilogs ability to
instantiate arrays of instances.
10/31/02
00
predict
=1
taken = 1
taken = 0
taken = 1
taken = 0
taken = 1
11
predict
=0
01
predict
=1
taken = 1
taken = 0
10
predict
=0
taken = 0
(a) (2 pts) Does the above finite state machine correspond to a Mealy machine or a Moore
machine. A Moore machine, since outputs only depend on the current state, not on inputs.
(b) (8 pts) Write behavioral Verilog code that implements this state machine. Your code should
use a single behavior for the state register, next-state logic, and output logic. Use the signal
or register names and state assignments given on the above graph. Feel free to use the back of
the previous sheet to write your code.
module branch_predict(predict, taken, reset, clk);
input taken, reset, clk; output predict; reg predict;
reg [1:0] state;
parameter s0 = 2b00, s1 = 2b01, s2 = 2b10, s3 = 2b11;
always@(posedge clk or reset) begin
if (reset = 1b1) state == s0; else
case (state)
// determine next state
s0: if (taken == 1b0) state = s1;
s1: if (taken == 1b0) state = s2; else state = s0;
s2: if (taken == 1b1) state = s3;
s3: if (taken == 1b0) state = s2; else state = s0;
endcase
case (state)
// set predict output based on state
s0 , s1: predict = 1b1;
s2, s3 : predict = 1b0;
default : predict = 1bx;
endcase
end
endmodule;
ECE 551 Midterm Exam
10/31/02
:
:
:
:
:
:
y
0;
0;
0;
1;
1;
// 0b01:0 sufficient
// b101:0 sufficient
// 1001:1 sufficient
(b) (2 pts). How many input/state combinations does the following row in a sequential UDP
correspond to (or in other words, how many rows would the following row require if
table shortcuts were not allowed). ___1*2*2*3 = 12______
// clk
f
a
b
b
b
:
:
state
?
:
:
q_out/next_state
-
(c) (2 pts) What are two advantages that UDPs have compared to Verilog modules?
UDPs are faster to simulate and require less memory than Verilog modules.
(d) (2 pts) What are two limitations of UDPs?
UDPs can only have one output and they become difficult to write correctly when the
number of inputs is large.
10/31/02
10/31/02