Gettysburg College

CS 221
Computer Organization and Assembly Language Programming

Fall 2024

Assignment 8

Due: Thu, Oct 31, by 11:59pm

Readings

Description

This assignment will focus on the following tasks: Build the PC circuit 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

Note the following:

Arrays as Parameters

Modify the example from class sum_array.asm (linked at the top), so that it can be used as a function of two parameters that returns the sum of the first n numbers:

def sum_array( numbers, n ):
    ...
    ...
    return the-sum-of-first-n-numbers

At the top declare two different arrays of different lengths and run the function as follows:

Fibonacci Numbers

In file fibonacci.asm write a recursive function that computes the n-th Fibonacci number:

def fib( n ):
    if n == 1:
        return 0
    elif n == 2:
        return 1
    else:
        return fib(n-1) + fib(n-2)
At the top run the function 4 times times one after the other:

Recursive Binary Search

In file binarySearch.asm write a recursive function that searches for a value in an array using binary search. Recall that binary search requires a sorted array and works as follows:
def binarySearch( i, j, numbers, value ):
    if i > j:
        return 0, -1

    m = (i+j) / 2
    if numbers[m] == value:
        return 1, m
    elif numbers[m] > value:
        return binarySearch( i, m-1, numbers, value )
    else:
        return binarySearch( m+1, j, numbers, value )

The function takes 4 parameters in this order:

The function returns two numbers:

Note that ARM does not have instruction to divide, but division by 2 can be accomplished via right shift. To emphasize the distinction between the various types of shifts we are using Arithmetic Right Shift, which handles the sign properly, although, technically, it is not needed, since the indices are not negative:

ASR DestReg, RegToShift, NumShifts

At the top declare two different arrays of different lengths and run the function several times:


What to turn in

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