Programming Assignment 2
Due: Tuesday October 26, 2004 11:59 pm
You must do the programming assignment by yourself. You are permitted to get help from ONLY the TAs and the instructor The file you submit should be an assembly language file called sort.asm. This is the only file you need to submit. Submission instructions are posted on the class website in the Software and Documentation section. If you are having trouble submitting, please email Danny (lynch@ece.utexas.edu) or Linda (bigelow@ece.utexas.edu).
Sort an array of 16 characters in alphabetical order.
In this assignment, you are asked to write a program in LC-3 assembly language to sort an array of 16 characters (stored in memory) in alphabetical order. Your program should assume that the first character of the array is stored in memory location x30F0 and the last character of the array is stored in memory location x30FF. Each memory location contains a single ASCII character. Your program should sort the array of characters in alphabetical order and store the sorted result back in memory locations x30F0 through x30FF. You may assume that the characters in the array will all be lowercase letters. Your program should start at memory location x3000.
Example:
Memory locations x30F0 through x30FF before sorting:
Location |
Contents (in hex) |
ASCII char |
---|---|---|
x30F0 |
x0069 |
i |
x30F1 |
x0062 |
b |
x30F2 |
x0073 |
s |
x30F3 |
x006C |
l |
x30F4 |
x0070 |
p |
x30F5 |
x0061 |
a |
x30F6 |
x0063 |
c |
x30F7 |
x0065 |
e |
x30F8 |
x0062 |
b |
x30F9 |
x0076 |
v |
x30FA |
x006E |
n |
x30FB |
x006B |
k |
x30FC |
x0076 |
v |
x30FD |
x007A |
z |
x30FE |
x0068 |
h |
x30FF |
x006D |
m |
Location |
Contents (in hex) |
ASCII char |
---|---|---|
x30F0 |
x0061 |
a |
x30F1 |
x0062 |
b |
x30F2 |
x0062 |
b |
x30F3 |
x0063 |
c |
x30F4 |
x0065 |
e |
x30F5 |
x0068 |
h |
x30F6 |
x0069 |
i |
x30F7 |
x006B |
k |
x30F8 |
x006C |
l |
x30F9 |
x006D |
m |
x30FA |
x006E |
n |
x30FB |
x0070 |
p |
x30FC |
x0073 |
s |
x30FD |
x0076 |
v |
x30FE |
x0076 |
v |
x30FF |
x007A |
z |
Hint 1: How would you find the smallest character in the array?
Hint 2: If you swap the smallest character in the array with the first character in the array (i.e., the character in memory location x30F0), you now have a 15-character array to sort (starting from memory location x30F1).
Initial Values: Your program should assume that there are already values
stored in memory locations x30F0 through x30FF. When testing your program with the
LC-3 simulator, you should manually load test values into these memory locations
before running your program. On UNIX machines (Sun, Linux) you can do this by using the
"Set Values" option on the menubar and selecting the "Set Register or Memory" option.
On Windows machines, you can click on "Simulate" in menubar and select "Set Value".
Instead, you can just press F4 and the "Set Value" dialog box will pop up.
Notes and Suggestions: