CSE 2312 - Assignments - Assignment 9

The assignment will be graded out of 100 points. Submit your source code for each task, in files called task1.s, task2.s, and so on. Each source file should include ONLY the functions that you are defining for that task, not the main program. Submit your solutions to Blackboard before the deadline. You will be able to revise your answers until the deadline with no penalty.


Task 1 (10 points)

Consider the following function in C:
int foo(int a, int b)
{
  if (a == b) return 0;
  return b - a + 10;
}
Implement this function in assembly.


Task 2 (15 points)

Consider the following function in C:
int foo(int a, int b)
{
  int result = 0;
  int i;
  for (i = 20; i <= 30; i++)
  {
    if (i == 24) result += 20;
    else if (i == 27) result = result * 2;
    else result = result + a + 3*b;
  }

  return result;
}
Implement this function in assembly.


Task 3 (15 points)

Consider the following function in C:
int foo(int a, int b)
{
  if (a > b) return 0;
  if (a == b) return b;
  return a + foo(a+1, b);
}
Implement this function in assembly.

Task 4 (20 points)

Consider the following function in C:
int foo(int a, int b)
{
  int c = a+3;
  int d = c*5;
  int e = c+d;
  int f = e*d;
  int g = f - c;
  return a+b+c+d+e+f+g;
}
Implement this function in assembly.


Task 5 (20 points)

Consider the following function in C:
int foo(int a)
{
  int result = 0;
  if (a <= 0) return 0;
  while(a > 0)
  {
    int b = a % 2;
    a = a / 2;
    result += b; 
  }

  return result;
}
Implement this function in assembly.


Task 6 (20 points)

Write a function called foo in assembly that:

Back to the list of assignments.