Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Department of Electrical Engineering

McGill University
ECSE 221 Introduction to Computer Engineering I
Final Examination

Tuesday, December 16, 2003 2:00pm

Examiner: Prof. F.P. Ferrie

Associate Examiner: Prof. V. Hayward

Instructions:

Answer ALL questions in the examination booklet provided, showing all of your work.
Calculators are permitted, but they must be the Faculty standard. All questions are equally
weighted.

Question 1

Answer the following questions:

#include <stdio.h>

int main(int argc, char *argv[])


{
union{ float Rvalue;
long Ivalue;
} indata;

indata.Rvalue = 7.62e-17;
printf("Hex value of IEEE 754 number = %08x\n",indata.Ivalue);
indata.Ivalue += 0x80000000;
printf("Integer value after addition = %ld\n",indata.Ivalue);
printf("Real value after addition = %g\n",indata.Rvalue);
}

a) What is the value printed corresponding to the first print statement? You may limit your
answer to the equivalent precision of the assigned value. [4 points]
b) What is the value printed corresponding to the second print statement? [2 points]
c) What is the value printed corresponding to the third print statement? [2 points]
d) Which of the 9 primitive operations listed in Module 1 are required to negate a single
precision IEEE floating point number? [2 points]

1
Question 2

Answer the following questions for the circuits shown below:

A EN
S2
B S1
S0
C
D7
D D6
D5
D4 Q F
D3
D2
D1
D0

+5V

a) Write down the truth table corresponding to this circuit and determine the minimal
canonical forms (∑∏, ∏∑). Use any minimization technique. [2 points]
b) Assume that inputs (A=0,B=0,C=1,D=0) and (A=1,B=0,C=1,D=0) are known to never
occur (i.e. don’t care). Show how the circuit can be implemented using only a 4-input
multiplexer. [2 points]

EN
+5V
M S1
S0
D3
+5V

D2 Q S
D Q Q1
D1
D0 C R Q

EN
+5V
S1
S0
D3
D2 Q S Q0
D Q
D1
D0 C R Q

Clk

Clr'

c) Determine the state transition table, state diagram, and next state equations for the circuit
shown above. [4 points]
d) Assuming that both registers are edge-tiggered and have Tsu = 0.1 nS, Th= 0 nS, Tpd =
2nS, and that the multiplexer has Tpd = 1nS, plot the timing diagram for 3 cycles
beginning at state (Q1=0, Q1=1) with input M = 1. Determine the maximum clock
frequency. [2 points]

2
Question 3

The following “C” language function computes the sum of integers from 0 to the function
argument:
long recsum(unsigned long arg)
{
if (arg < 1)
return(0);
else if (arg < 2)
return(1);
else
return(arg+recsum(arg-1));
}

a) Translate the function into MIPS assembly language. Make sure to observe proper
conventions with respect to saving context and memory allocation. The function
argument is passed in $4, with the return in $5. [4 points]
b) The “C” code above is compiled using the Acme “C” compiler. It produces a function
that has a context of 3 registers. The function is loaded at address 0x400078, with the
stack pointer initialized to 0x7fffeffc, and the data segment located at address 0x7fff0000.
Determine the maximum value of the argument for which the function can compute the
correct sum, assuming that memory is contiguous from the data segment on upwards.
[2 points]

.text 0x400100

foo: slti $10, $4, 6


bne $10, $0, foo10
addi $4, $4, 1
b foo20
foo10: addi $4, $4, 2
li $2, 10
syscall

.data 0x10000000

str1: .asciiz "Error: bad function argument\n"


.align 2
array1: .word 12, -34, 54, 121, 17
str2: .asciiz "\n"
.align 2
array2: .word 21, 22, 23, 24, 25

c) The above code is converted to machine language using the MIPS assembler. Determine
the contents of the lower 16 bits of the second instruction. Express your answer as a
hexadecimal number. [2 points]
d) Determine the memory address corresponding to the 3rd element of the second array in
the program. [2 points]

3
Question 4

a) Carry generator functions are usually defined in terms of the carry generation term, gi =
ai bi , and the carry propagation term, pi = ai + bi , where ai and bi are inputs to the ith full
adder. Begin by writing down the expression for ci in terms of pi-1, gi-1, and ci-1. From
here, determine the expression for the carry generator corresponding to the carry out of a
4-bit full adder. [2 points]
b) Determine the number of switching elements required to fabricate the carry generator
corresponding to the carry output of a 32-bit full adder. You may assume that gates
n
n(n + 1)
contain no passive elements. (Hint: ∑ i = ) [2 points]
i=1
2
c) The datapath shown below is used to multiply two 4-bit signed integers using Booth’s
algorithm.

At T=0, the multiplicand register is loaded with –6, and the lower half of the product
register with 5. The upper half of the product register is cleared along with b-1 register.
Four ALU/shift cycles (8 clock pulses) are required to complete the product. List the
contents of the product register at the end of each clock pulse. [3 points]
d) The datapath shown below is used to implement binary division using the non-restoring
algorithm. At T=0, the remainder register is loaded with 33 and the divisor with 5. On
the next clock pulse, the remainder register is shifted to the left by 1. List the contents of
the remainder register for the next 10 clock pulses (Hint: 8 pulses are required to perform
4 ALU/shift cycles. ) [3 points]

4
Question 5

The datapath for the multi-cycle implementation of the MIPS architecture is shown below.

Assume that the datapath has the following parameters:

For all registers: Tsu = 0.5 nS, Th = 0 nS, Tpd = 5 nS


For all multiplexers: Tpd = 1nS
For the register file: Ta = 5nS
For the ALU Tpd = 20nS
For the Memory Ta = 15nS (for both read and write operations)
All other delays may be neglected.

a) List the microinstructions common to each MIPS instruction. For each, list the
microinstruction name, register transfer operations, and settings for the relevant control
lines. [2 points]
b) List the final 3 microinstructions corresponding to the LW instruction. For each, list the
corresponding register transfer operations and relevant control line settings. [2 points]
c) Given the parameters listed above, determine Tcl for this datapath. Make sure to clearly
specify how you arrived at this number. Determine the datapath’s maximum frequency
of operation. [2 points]
d) Using the R-type instruction as a prototype, devise a suitable set of microinstructions to
implement the jr instruction. For each microinstruction, indicate the relevant control
line settings. (You may start from the 3rd microinstruction). [2 points]
e) Assuming that a microcode controller is used to implement the datapath control, indicate
the changes necessary to implement the jr instruction.

5
Appendix - MIPS Instruction Set

You might also like