Gettysburg College

CS 221
Computer Organization and Assembly Language Programming

Spring 2026

Assignment 10

Due: Thu, Apr 16, 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

What to turn in

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

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:

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/mcode.

Fibonacci in Machine Code

Write a program in machine code that computes the n-th Fibonacci number where f1=1, f2=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:

Notes on the loop:

We are essentially converting the following Java program:

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

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

    while (i < n)
    {
        currFib, nextFib = nextFib, currFib+nextFib;   // move ahead

        i = i + 1;
    }
    
    return currFib;
}

Drawing in Machine Code

Write a program in machine code that draws a staircase given the number of stairs n ≤ 15:
_._._._.                          put correct value that draws single line with 4 blank dots
        _._._._.                  initially, put any random value
                _._._._.      
                        _._._._.   and so on

(each stair must start with solid segment and end with blank dot; segments are equal length)

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 15, including the required values plus a couple of extra ones:

Hint on line value (highlight within arrows): →You might find it easier to draw the opposite pattern first, i.e. 4 dots.

We are essentially converting the following Java program:

void draw(int n)
{
    int i = 16384;          // top-left cell of screen 

    int count = 0;

    while (count < n)
    {
        M[i] = ?;           // a single value that represents a line with 4 equally spaced blank dots
                            // initially put any random value

        i = i + 545;        // 16*32+33: skip 16 cols/cells (1 row) + 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 m1,m2,m3, i.e. cells 15-17, including 0:

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. You can highlight the blank space to see the answer, but it is better to try to write your own code first:

The End