CS2200 Fall 2002 :: Homework 1 :: Assembly


Navigate

Turn-in Information

Background

Prior to attempting this homework, be sure and read Chapter 3 in the Patterson and Hennessey book.

Part 1: Assembly Programming Warmup

1. [10 points]

Exercise 3.1 from Patterson and Hennessey book.

2. [30 points]

Convert the following C program to symbolic MIPS instructions.
int fib(int n)
{
  if(n == 1)
    return 1;
  else if(n == 2)
    return 1;
  else
    return fib(n-1) + fib(n-2);
}

Part 2: Introducing the LC-2200 Instruction Set

Read the description of the
LC-2200 machine before beginning the next two problems.

2. [40 points]

Convert the following piece of C code into symbolic LC-2200 instructions:

int fact (int n)
{
  int answer;

  answer = 1;
  while (n != 0) {
     answer = answer * n;
     n--;
  }

  return answer;
}
3. [20 Points]

Convert the following LC-2200 symbolic instructions into hexadecimal.
Here are some examples to help you.

(address 0)             lw      0       1       seven
(address 1)             lw      1       2       5
(address 2)             lw      1       5       6
(address 3)             jalr    5       3
(address 4)             nand    1       0       7
(address 5)    start    add     1       2       1
(address 6)             beq     0       1       1
(address 7)             beq     0       0       start
(address 8)             sw      0       2       14
(address 9)             noop
(address 10)            halt
(address 11)   seven   .fill   7
(address 12)   neg13   .fill   -1
(address 13)   pos4    .fill   4
(address 14)   store   .fill   0