Due date: See Class Webpage
The alternative method to get the prepared files is to enter these commands in the EGTAPI terminal:
mkdir ~/cs255/pj7
For CS255-1 students:
cp /home/cs255001/Handouts/pj7/* ~/cs255/pj7
For CS255-2 students:
cp /home/cs255002/Handouts/pj7/* ~/cs255/pj7
|
// How the variables are used:
//
// input A: array of integers that needs to be sorted
// N: size of array A
//
// Done: integer (functioning as a boolean: 0 = false, 1 = true)
// Help: integer (help variable for swapping)
void BubbleSort(int[] A, int N)
{
int i, Done, k;
Done = 0; // 0 represents false
k = 1;
while (Done == 0)
{
Done = 1; // 1 represents true.
for (i = 0; i < N-k; i++)
{
if (A[i] > A[i+1])
{
Swap A[i] and A[i+1];
Done = 0; // Not sorted...
}
}
k = k + 1;
}
}
|
Basically, the bubble sort algorithm swaps two adjacent elements A[i] and A[i+1] when the latter is smaller. When two adjacent element are exchanged, the Done variable is set to FALSE , indicating that another iteration is necessary.
The main program is stored in the file pj7.s
The main program will call (i.e., executes a bsr BubbleSort instruction) the BubbleSort subroutine twice, each time with a different array.
The main program calls the BubbleSort with 2 parameters:
|
The type of the elements of the array is int.
The main program passes the parameters as follows:
|
Here are the code segments that shows you how the main program calls the BubbleSort subroutine:
movw r0, #:lower16:A // Pass address of the array A in r0
movt r0, #:upper16:A
mov r1, #5 // Pass size of the array in r1
bl BubbleSort // Call BubbleSort to sort array A (5 elements)
....
movw r0, #:lower16:B // Pass address of the array B in r0
movt r0, #:upper16:B
mov r1, #10 // Pass size of the array in r1
bl BubbleSort // Sort array B (10 elements)
|
Therefore, your BubbleSort subroutine must use as parameters:
|
Note:
|
Right now, the bubblesort.s looks like this:
.global BubbleSort
.text
BubbleSort:
//*****************************************************
// Write your bubble sort assembler subroutine here
//
// BubbleSort: input r0 = address of int array
// r1 = # elements in the array
//*****************************************************
// Write your bubble sort function here.....
// Make sure you RETURN to the caller !!!
// *************************************************************************
// Do NOT define any variables with .skip or .4bytes in this file
//
// Use REGISTER to store your (local) variables
// *************************************************************************
.end
|
You must write the BubbleSort function in ARM assembler code and put the code after the BubbleSort (and before the .data directive)
|
This is also the file that you must turn in.
1. First: press the CONTROL key and select pj7.s
2. THEN:
On a Window PC: press the CONTROL key and select bubblesort.s
On a Mac PC: press the COMMAND key and select bubblesort.s
NOTE: the ORDER of clicking is VERY IMPORTANT
DO NOT click on bubblesort.s first !!!!
(A wrong order will cause EGTAPI to generate the output "bubblesort.arm"
and not "pj7.arm")
3. Finally: click "Compile"
NOTE: You MUST see the digit "1" next to the "pj7.s" file before
you click "compile" or else, EGTAPI will generate a
WRONG assembler output filename !!!
|
If you have a hard time using the CONTROL + click to compile the project, you can also compile the programs in this project, by opening the Terminal in EGTAPI and type the follow commands:
cd ~/cs255/pj7 // Execute this once
/home/cs255001/bin/as255 pj7.s bubblesort.s
|
|
I am sure you will have bugs in your program with this assignment.
|
The breakpoints are very helpful in finding errors in assembler programs.
|
(In EGTAPI, select: File Browser, Turnin, click on the file you want to turn in (bubblesort.s), use the turn in code: pj7)
You can also use the turnin command (executed while you're in your cs255 directory)
Open the Terminal in EGTAPI and type in these command:
cd ~/cs255/pj7
/home/cs255001/turnin bubblesort.s pj7 // If you're in section 1
or
/home/cs255002/turnin bubblesort.s pj7 // If you're in section 2
|
You do not need to turn in the pj7.s file !!!
As usual, I want the source (so I can read it). DO NOT turn in the executable or the object code !
8. Extension request
However, you need to use pj7 as homework code to make extension for this homework/project.
/home/cs255001/req-ext pj7 // IF you're in section 1
or:
/home/cs255002/req-ext pj7 // IF you're in section 2
|
You request will be successful if you have not exceeded the maximum number of "free" (no-questions-asked) requests allowed