Department of Electrical and Computer Engineering
University of Texas at Austin
EE 306, Fall 2019
Programming Assignment 2
Yale N. Patt, Instructor
TAs: Sabee Grewal, Arjun Ramesh, Joseph Ryan, Chirag Sakhuja, Meiling Tang, Grace Zhuang

Due: October 27, 2019 11:59 pm

You must do every programming assignment by yourself. You are permitted to get help ONLY from the TAs and the instructor.


Sort an array of 16 2's complement integers.

Overview: In this programming assignment, you are being asked to "sort an array."

Sorting is the process of arranging a set of elements in some order: numerical order, alphabetical order, height (shortest in front) order, etc.

An array is a collection of elements all having the same data type, and each element identified by the value of its index. (We will explain index momentarily).
An array can be of any dimension. Most common are two-dimentional arrays and one-dimensional arrays. A two-dimensional array is organized as a set of rows
and columns, and requires two index values to specify each element. For example, the first element of the array A would be A[0,0], i.e., top row, left-hand column.
A[2,4] identifies the element that occupies row 2 (the third row), and column 4 (the fifth column). A one-dimensional array only requires one index value to specify each
element. B[0] specifies the first element, B[1] specifies the second, etc.

Arrays are stored in sequential locations of memory. The address of the location of the first element of the array, for example A[0,0] or B[0], is referred to as the
base address of the array. In order to store elements of a two-dimensional array into a one-dimensional memory requires a little thought beyond what we will do in this assignment.
Something for another day. In this assignment we are working with a one-dimensional array, where the location of each element is determined pretty easily. B[0]
is stored at the base address, B[1] is stored at the next address, and so on.

Your program will use an array NUMBERS, where NUMBERS[0] will be stored at the base address, in memory location x32F0. NUMBERS[1] will be stored in M[x32F1],
NUMBERS[2] in M[x32F2]. etc. Since there are 16 elements in the array, and since each element occupies exactly one word of LC-3 memory, the last element NUMBERS[15]
will be stored in M[x32FF].

Your Job: Write a program in LC-3 assembly language to sort an array of 16 2's complement integers. Your program should assume that the
first element of the array is stored in memory location x32F0 and the last element of the array is stored in memory location x32FF. Each memory location
contains a single 2's complement integer. That is, each memory location contains a single element of the array. Your program should sort the array of 2's
complement integers in ascending order and store the result back in memory locations x32F0 through x32FF. Your program should start at memory location x3000.

Example:

Memory locations x32F0 through x32FF before sorting:
Location 
Contents (in hex) 
x32F0 
xFFFF 
x32F1 
x0062 
x32F2 
x0A73 
x32F3 
x006C 
x32F4 
x0070 
x32F5 
x0001 
x32F6 
x0063 
x32F7 
x0065 
x32F8 
x0062 
x32F9 
x0073 
x32FA 
x006E 
x32FB 
x006B 
x32FC 
xFF76 
x32FD 
x0F7A 
x32FE 
x0068 
x32FF 
x006D 

Memory locations x32F0 through x32FF after sorting:

Location 
Contents (in hex) 
x32F0 
xFF76 
x32F1 
xFFFF 
x32F2 
x0001 
x32F3 
x0062 
x32F4 
x0062 
x32F5 
x0063 
x32F6 
x0065 
x32F7 
x0068 
x32F8 
x006B 
x32F9 
x006C 
x32FA 
x006D 
x32FB 
x006E 
x32FC 
x0070 
x32FD 
x0073 
x32FE 
x0A73 
x32FF 
x0F7A 

Write your program in a file called sort.asm.

Hint 1: Note that the array always has 16 elements.

Hint 2: How would you find the smallest 2's complement integer in the array?

Hint 3: If you swap the smallest 2's complement integer in the array with the first 2's complement integer in the array (i.e., the 2's complement integer in memory location x32F0),
             you now have to sort an array with 15 elements (starting from memory location x32F1).

 

Notes and Suggestions:

When and how to submit: Submit your program (sort.asm) on Canvas before October 27th at 11:59 pm.