Gettysburg College

CS 221
Computer Organization and Assembly Language Programming

Spring 2025

Assignment 7

Due: Thu, Mar 27, by 11:59pm

Readings

Description

This assignment will focus on the following tasks: Build the RAM circuits described in Project 3:

N2T: Project 3

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

The Hack Chipset

Assembly Language Programming

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

Design in Logisim

Note the following requirements:

Here are additional specific requirements:

Design in HDL

Here are additional specific requirements:

Assembly Language Programming

If you have implemented Bubble Sort previously, do not refer to your previous work.

Implement the Bubble Sort algorithm. Briefly the algorithm works as follows:

1. Go through the whole array examining each pair of items. Exchange the items in a pair if the first is bigger than the second.

2. Repeat Step 1. n-1 times, where n is the size of the array.

// does one run of the bubble sort algorithm -- every
// pair of neighbors that are out of order are swapped
void bubbleRun(int[] numbers)
{
    for (int i = 0; i < numbers.length-1; i = i + 1)
    {
        if (numbers[i] > numbers[i+1])     // if out of order:
        {
            int temp = numbers[i];         // swap them    
            numbers[i] = numbers[i+1];
            numbers[i+1] = temp;
        }
    }
}

// sorts an array in increasing order -- simply executes *n-1* 
// bubble runs through the array, where *n* is the array length
void bubbleSort(int[] numbers)
{
    int n = numbers.length;
    for (int run = 1; run <= n-1; run = run + 1)
    {
        bubbleRun(numbers);
    }
}
Here is a visualization of the process from Wikipedia:
Hint: Instead of size you might find it more convenient to have a variable that represents number of pairs.

Hint: In general, the meaning of a comparison should be flipped from what it would be in CS111.

Hint: An if statement is set up similar to a loop. It still has a jump/branch that is designed to skip over the section that normally would have been executed. The same structure was used for the loop, where the focus was on when to stop looping and to skip the body.

Part I

In file bubbleRunSimple.arm write a program that only implements Step 1. of Bubble Sort. Create an array of 6 elements at the top and check if the array was modified correctly.

Make sure to test with: scrambled array, sorted array, reverse sorted array.

Part II

In file bubbleSortSimple.arm copy the contents of bubbleRunSimple.arm and make the following changes.

Wrap the copied code in another loop so that bubbleRun is called exactly n-1 times.

Make sure to test with: scrambled array, sorted array, reverse sorted array.

Part III

In file bubbleRun.arm copy the contents of bubbleRunSimple.arm and make the following changes.

Ensure that when bubbleRun finishes register R10 is set to 0 if no swap was made during the run; otherwise, R10 should be set to 1 to indicate a comparison took place. Do not count how many comparisons were made.

Make sure to test with: scrambled array, sorted array, reverse sorted array.

Part IV

In file bubbleSort.arm copy the contents of bubbleRun.arm and make the following changes.

Keep looping around the code from bubbleRun as long as register R10 is 1.

Make sure to test with: scrambled array, sorted array, reverse sorted array.

Part V

Modify file bubbleSort.arm so that the code from bubbleRun loops less and less each time. That is:

Make sure to test with: scrambled array, sorted array, reverse sorted array.


What to turn in

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