Computer Science 281

First Exercise Set

Purpose

Due:  Wednesday, Feb. 4

Consider the following C program:

#include <stdio.h>

	int main() {
	int x = 3;
	int y;

	y = calc(x);

	printf("Value of y is %d\n",y);
}

Write an assembly language program with a global entry point calc which will accept the argument x and calculate and return (x-1)*(x+1).  Please do not simplify the expression (it is, of course, x*x-1).  Use the program example in our textbook to see how multiplication is done, and the subroutine.s file in ~matthews/cs281 to see what is necessary in a called subroutine to get arguments and to return a result (you could also simply write calc.c in c, compile it to assembly language, and look at that, but do this only as a last resort, and then still figure out how to get rid of the references to the frame pointer (%fp)).

Three programs to look at (all in ~matthews/cs281):

I am still working out details of picking up programs.  For this one, let's try picking it out of your root directory on Orion.  Please call your program calc.s, make sure that permissions are set so that I can read it, and place it in your root directory on Orion.

Some notes:

Any questions?  Please ask!