Computer Science 281

Exercise set #3

Due: 

Part A:  Consider the following main program in c:

include <stdio.h>
 
/*
      Program to accept three numbers from the user,
      call the subroutine 'mid' to return the middle one.
      Author: Bob Matthews
*/
 
 int main() {
      int x,y,z,m;
      printf("Please enter a value for x ->");
      scanf("%d",&x);
      printf("Please enter a value for y ->");
      scanf("%d", &y);
      printf("Please enter a value for z ->");
      scanf("%d", &z) ;
      m = mid(x,y,z);
      printf("The middle number is %d\n",m);
}

Write an assembly language program (mid.s) to implement the mid function used in this example.  The assembly language routine should examine the three arguments to it, and return the middle one.

 

Part B:  Consider the following main program in c:

#include <stdio.h>

/*
Main program for a Fibonacci subroutine
Author:  Bob Matthews
*/

int main() {
int x,y;

printf("Please enter a value for x ->");
scanf("%d",&x);


y = fib(x);


printf("The %dth Fibonacci number is %d\n",x,y);
}

Write the Fibonacci function fib(x) which takes the integer argument x and returns the x'th fibonacci number.  For example, fib(5) = 5, fib(10) = 55.

 

Both midmain.c and fibmain.c are available on ~matthews/cs281