ass5 - Department of Electrical Engineering Course...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Department of Electrical Engineering Course ECSE-221, Fall 2003 Introduction to Computer Engineering I Assignment 5 Computer Arithmetic and Assembly Language II Due: Wednesday, April 2 nd , 2008, at 5:00 pm in the Trottier assignments box 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 Question 3 We revisit binary division yet again, but this time using a much more efficient implementation. This will provide an example of how hardware can sometimes be directly emulated in software. As before, the following prototype will be used: 1/36 long div32(long dividend, long divisor, long *quotient, long *rmdr); Your algorithm must be implemented according to the datapath shown on Page 187 (Figure 3.13 Third Edition) of the text. Notice that the dividend is specified to be type long. We could have passed a 64-bit argument using an array (pointer), but this was avoided to keep the assignment to a reasonable length. Implement the datapath exactly as specified in the text, with the proviso that when the remainder register is loaded, the upper 32-bits will be set to 0 and the dividend will be placed in the lower 32-bits. As before, your function must explicitly deal with signs. Make sure that your function works correctly be calling it using the same test program used in Assignment 4 with the same test examples. Question 4 Translate your C function into assembly language, using the following layout to pass arguments on the stack. addi $sp, $sp, -16 sw $4, 0($sp) # dividend sw $5, 4($sp) # divisor sw $6, 8($sp) # pointer to quotient sw $7, 12($sp) # pointer to remainder jal div32 addi $sp, $sp, 16 Even though argument passing on the stack has been specified, the function return is customarily placed in a register. Since there is the possibility of a divide by 0 error, the function should return a 1 in $7 if this occurs and 0 otherwise....
View Full Document

Page1 / 36

ass5 - Department of Electrical Engineering Course...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online