C++ Assembly Language Programming - Sorting Subroutines

C++ Assembly Language Programming - Sorting Subroutines

Cancelled

Job Description

This script needs to be completed by midnight on Monday, November 19th.

ARM Assembly Programming

Problem description

Write three ARM assembly language subroutines for sorting numbers. Use a C++ program for tying them all together.

Getting Specific:

Use the files found in the .zip archive below: makefile, sortmain.cpp, sortfuncs.s, and sort-solution. The last file is a solution executable for reference.

Explain in your own words how sortmain.cpp fills in the three arrays. See the appropriate man page(s). Place your explanation in a file called sortmain.txt. Hint: See man -s 3 rand and man -s 3 memcpy.

Subroutine sort1 works as follows. Each pair of elements from the N element long arrays listA and listB are compared. If the value of the element from listA is less than the value of the element from listB, the former is replaced by the latter. Write a few lines of C++ code that outlines how to achieve this result. Place this code in a comment field above the sort1 ARM subroutine in the sortfuncs.s file. Hint: Follow the format of the pseudo code for the sort2 ARM subroutine in the same file.

Write the ARM subroutine sort1. Include comments that refer back to the C code from (b). Test the code on different sized input arrays.

Subroutine sort2 is given an N element long array which it sorts using the C++ code listed below and in the sortfuncs.s file. Explain in your own words how sort2 which implements a so-called selection sort works. Place your explanation in the sortmain.txt file.

Write the ARM subroutine sort2. Include comments that refer back to the C code mentioned in (d). Test the code on different sized input arrays.

Develop and implement subroutine sort3 which implements a socalled insertion sort. See Wikipedia for an algorithmic explanation. Basically, sort3 is a more efficient version of sort2. During each pass thru a sublist, sort2 swaps list entries LIST[k] and LIST[j] whenever LIST[k] > LIST[j]. An alternative strategy is to keep track of the address of the largest value in the sublist and to perform, at most, one swap at the end of the sublist search. As before, write C++ pseudo code that outlines what needs to be done before
you try to write the ARM assembly code.

Hints

Pay attention to how the C++ code passes arguments to the ARM subroutines and how it expects to receive arguments back.

See the ARM Programming Techniques manual for a detailed description of ARM assembly language programming techniques. Do not print this document as it is 250+ pages long. View and print individual pages as you need to. Chapters 2–5 and 7 are probably those of most interest to you.

Keep in mind that the GNU assembler uses different directives.

C++ code for selection sort
for (j=n-1; j>0; j=j-1) {
for (k=j-1; k>=0; k=k-1;) {
if (list[k] > list[j]) {
tmp = list[k];
list[k] = list[j];
list[j] = tmp;
}
}
}

---
Skills: gnu

Open Attachment