Gettysburg College

CS 221
Computer Organization and Assembly Language Programming

Spring 2023

Assignment 10

Due: Thu, Apr 13, by 11:59pm

Readings

Description

This assignment will focus on the following tasks:

Build the Computer and Memory circuits described in Project 5:

N2T: Project 5

Chapter 5 provides the contract for each circuit, i.e. description of its behavior, names and number inputs, names and state of outputs. The API is available here:

The Hack Chipset

Programming in Machine Code (in Binary)

vvv
vvv Scroll to the bottom. Consider starting with the Assembly section.
vvv

Design in Logisim, Part I: Ignore Keyboard and Screen

Note the following requirements:

Build Computer as shown in Figure 5.9 on page 24. At this stage:

Here are the chips you need to use or build at this stage:

Design in Logisim, Part II: Memory with RAM, Keyboard, and Screen

In this part you will build only the Memory module as specified in Figure 5.6 on p. 17.

Here are the chips you need to use or build at this stage:

Design in Logisim, Part III: Integrate Computer and and Memory

In this part you will complete the construction of Computer as shown in Figure 5.9 on page 24.

Design in HDL

Note the following additional requirements:

Modify and test the respective .hdl file given by the authors:

Fibonacci in Machine Code

Write a program in machine code that computes the n-th Fibonacci number where f1=1, f2=1, 2, 3, 5, 8, ... .

Submit fib.xlsx and fib.hex, i.e. Excel file with code and a program/text file that can be loaded on the ROM as given here:

machine_code_examples.xlsx | count_5_1.hex

The program should use the following memory cells. Try different values for m1,m2,m3, including 0.

Notes on the loop:

We are essentially converting the following Java program:

int fibonacci(int n)
{
    int curFib = 1;    // value of current fib number
    int nextFib = 1;   // value of next fib number

    int i = 1;         // index of curFib (n=1 computed in curFib)

    while (i < n)
    {
        int newCur = nextFib;            // new value for curFib
        int newNext = curFib + nextFib;  // new value for nextFib

        curFib = newCur;      // change/update curFib	    
        nextFib = newNext;    // change/update nextFib

        i = i + 1;
    }
    
    return curFib;
}

Multiplication in Machine Code

Write a program in machine code that multiplies three numbers m1,m2,m3 ≥ 0 via repeated addition.

Submit mul.xlsx and mul.hex, i.e. Excel file with code and a program/text file that can be loaded on the ROM as given here:

machine_code_examples.xlsx | count_5_1.hex

The program should use the following memory cells. Try different values for n, i.e. cell 11, including the required values plus a couple of extra ones:

We are essentially converting the following Java program:
int multiply(int m1, int m2, int m3)
{
    int result = 0;

    int count1 = m1;
    while (count1 > 0)
    {
        int count2 = m2;
        while (count2 > 0)
        {
            result = result + m3;
            count2 = count2 - 1;
        }
        count1 = count1 - 1;
    }
    
    return result;
}

Drawing in Machine Code

Write a program in machine code that draws a staircase given the number of stairs n ≤ 15:
___
   ___
      ___
         ___ and so on

Submit draw.xlsx and draw.hex, i.e. Excel file with code and a program/text file that can be loaded on the ROM as given here:

machine_code_examples.xlsx | count_5_1.hex

The program should use the following memory cells. Try different values for n, i.e. cell 11, including the required values plus a couple of extra ones:

We are essentially converting the following Java program:
void draw(int n, const int start=16384)
{
    int i = start;
    int count = n;

    while (count > 0)
    {
        M[i] = -1;

        i = i + 545;        // 16*32+33: skip 16 rows + 1 cell
        count = count - 1;
    }
}

Notes on Machine Code

Manipulating a memory cell is a multi-step process as shown in the following examples:

Testing Binary Program in N2T software

It is possible that your Computer implementation does not work, neither in Logisim, nor in HardwareSimulator.

You can still test the program as follows:


What to turn in

Zip folder 07/ in file named 07.zip and upload it to the Moodle dropbox.