Gettysburg College

CS 221
Computer Organization and Assembly Language Programming

Fall 2025

Assignment 10

Due: Thu, Nov 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) and Hack Assembly

vvv
vvv Scroll to the bottom. Consider starting with the Machine Code 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 additional specific requirements:

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

Here are additional specific requirements:

Programming in Machine Code

See at the bottom for "Notes on Machine Code".

Testing Machine Code with Logisim

Testing Machine Code with N2T software

Initially use the CPUEmulator to test the binary programs. Later test the programs on your own computer in Logisim and in HardwareSimulator.

Here is how to test in the CPUEmulator:

Program Folder

Save the program files in folder computer/hack-computer/mcode.

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, fib.hex, fib.hack, i.e. Excel file with code and a program/text files that can be loaded on the ROM as given here:

machine_code_examples.xlsx | count_5_1.hex | count_5_1.hack

Show that the Fibonnacci program works in the Logisim computer by computing the 6th Fibonnacci number. Take a screenshot named fib.png that shows the contents of the RAM and ROM after the program has finished.

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)
    {
        curFib, nextFib = nextFib, curFib+nextFib;   // move ahead

        i = i + 1;
    }
    
    return curFib;
}

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, draw.hex, draw.hack, 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 | count_5_1.hack

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)
{
    int i = 16384;
    int count = n;

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

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

(Optional) Multiplication in Machine Code

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

Submit mul.xlsx, mul.hex, mul.hack, 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 | count_5_1.hack

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;
}

Notes on Machine Code

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


What to turn in

Zip folder hack-computer/ in file named hack-computer.zip and upload it to the Moodle dropbox. When hack-computer.zip is unzipped it should produce folder hack-computer with the required subfolders and files inside.