Assignment5Sol

# Assignment5Sol - McGill University Department of Electrical...

This preview shows pages 1–4. Sign up to view the full content.

McGill University Department of Electrical and Computer Engineering ECSE-221 Introduction to Computer Engineering Assignment 5 – Assembly and Datapaths Due Date: Monday, November 30 th 2009 at 11:59PM Question 1 Implement a “C” language function that computes the factorial of a number, recursively , according to the following prototype: void factorial (long argument, long *result); If you are unsure how to proceed, try Googling on the keywords recursive and factorial; the function is relatively straightforward to write. Demonstrate your function by writing an interactive test program that operates as follows: % factorial 6 6! = 720 Question 2 Translate your “C” function into MIPS assembly, passing arguments on the stack according to the following call convention (assume, below, that the argument is in \$10, and that the data is to be returned to location data_return in the data segment): addi \$sp, \$sp, -8 sw \$10, 0(\$sp) la \$11, data_return sw \$11, 4(\$sp) jal factorial addi \$sp, \$sp, 8 Using the SPIM console I/O functions, write a simple interactive program to query a value from the user and print the factorial of the value as output, e.g., Enter data > 6 6! = 120

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Question 3 The figure shown above shows a datapath for a 4-bit x 4-bit unsigned binary multiplier adapted from the one shown in Patterson and Hennessy. The corresponding algorithm, taken literally from the text, is reproduced below. 0. Init . Place Multiplicand in Multiplicand register. Place Multiplier in lower half of Product register. Clear upper half of Product register 1. Test and Update . If the LSB of Product register is 1, add Multiplicand register to upper half of Product register and place result back in the upper half of Product register . 2. Shift . Product register shifted right one 1 bit . 3. Count. If 4th repetition then done else goto step 1. 4 8 4
Do the following: 1. Implement the datapath shown on the previous page in LogicWorks. The Multiplicand and Multiplier inputs are supplied using Hex keypads (i.e. there is no need for an explicit Multiplicand register). The Product register can be implemented using the Shift Reg-4 component and the ALU with the Adder-4. Since the multiplication is unsigned, you will need to take care of the carry out generated by the ALU. Logic will also have to be provided for initializing the Product register at the start of the sequence as well as latching the final product

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 05/06/2010 for the course ENG ECSE221 taught by Professor Ferri during the Fall '09 term at McGill.

### Page1 / 13

Assignment5Sol - McGill University Department of Electrical...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online