a4solns - 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
Department of Electrical Engineering Course ECSE-221, Fall 2003 Introduction to Computer Engineering I Assignment 4 Introduction to Assembly Language Programming Due: Wednesday, November 12 th , 2003 Question 1 Using the code on Pages 33 and 34 of the Module 1 notes (as a guide), write a “C” language function to perform binary division according to the following template: int binarydivision (long dividend, long divisor, long *quotient, long *rmdr); The function returns -1 in the event of a divide by zero error, and 0 on successful completion. In addition to checking for a zero divisor, your algorithm must also handle signs correctly. Pay particular attention to the sign of the remainder. Recall that divisor * quotient + remainder = dividend in all cases. Validate your code by writing a suitable test program. To make implementation in Question 2 easier, it is suggested that you prepare a table of test cases that your main program iterates through. Question 2 Implement the binary division function you wrote in Question 1 in MIPS assembly code, assuming the following convention for passing arguments: Register Argument Mechanism $4 dividend pass by value $5 divisor pass by value $6 quotient pass by value $7 rmdr pass by value Although this is not quite the convention used by a “C” compiler (quotient and rmdr are pointers and would otherwise by passed by reference), we will use it here since argument passing mechanisms have not been dealt with in detail at this point in the course. In coding your function it is absolutely essential that the context of the calling program is fully preserved. You will also need to write a suitable test program. The SPIM environment includes a number of SYSCALL functions for printing strings and integers. Test your functions with the same table of test cases that you used in Question 1. Your results should be identical. FPF/October 29, 2003
Background image of page 1

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

View Full DocumentRight Arrow Icon
div32.c 11/11/03 1:27:18 PM Page 1 /*----------------------------------------------------------------------*/ /* File Name: div32.c */ /* Description: A simple package to support binary division of long */ /* integers using the subtract and shift procedure. The */ /* main is a command line procedure for testing the */ /* div32 function which implements the algorithm. */ /* Author: F.P. Ferrie */ /* Date: September 12, 2002. */ /* Modifications: None */ /*----------------------------------------------------------------------*/ /*----------------------------------------------------------------------*/ /* Includes */ /*----------------------------------------------------------------------*/ #include <stdio.h> #include <stdlib.h> /*----------------------------------------------------------------------*/ /* Defines /*----------------------------------------------------------------------*/ #define MSBLONG 0x40000000 /* mask for msb position in long int */ #define DIV0 -1 /* return code for divide by zero */ #define SUCCESS 0 /* return code for success */ #define BADARG -2 /* Can't handle -2147483648
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/06/2008 for the course ESCE 221 taught by Professor Ferrie during the Spring '08 term at McGill.

Page1 / 15

a4solns - 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