Due date: See Canvas
The Bubble sort algorithm is described in Section 2.
// How the variables are used: // // int A[]: an array of integers that needs to be sorted // int N: integersize of array A // // int Done: integer (functioning as a boolean: 0 = false, 1 = true) // int i, k: indexes used in the algorithm BubbleSort: sorts the array A that contains N integers Done = 0; // 0 represents "not done with sorting" k = 1; while (Done == 0) { Done = 1; // 1 represents "done with sorting" for (i = 0; i < N-k; i++) { if (A[i] > A[i+1]) { Swap A[i] and A[i+1]; // You must swap using registers 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 hw10.s already contain the definition of these variables:
int A[]; Array A that needs to be sorted. This array has been initialized int N; N = number of elements in array A N has been initialized already int Done; Variable used in the Bubble Sort Algorithm int i; Variable used in the Bubble Sort Algorithm int k; Variable used in the Bubble Sort Algorithm |
Right now, the hw10.s looks like this:
.global main, Stop, CodeEnd, DataStart, DataEnd main: // Write the Bubble Sort program here Stop: nop CodeEnd: /********************************************************************* DO NOT make any changed to the code below this line The included file "variables.h" contains the variable definitions for int i, k, Done; int A[]; // Array to be sorted int N; // contains the length of the array *********************************************************************/ #include "variables.h" .end |
You must write the BubbleSort function in ARM assembler code at the location indicted in hw10.s
This is also the file that you must turn in.
1. Open File Browser in EGTAPI 2. Select hw10.s 3. Click "Compile" |
|
|
I have also display the variables N, Done, i and j. You need to click on the Variables tab in the display window to see them.
Watch these variables (and array) carefully when you execute hw10. Read the Debug Help section below for hints on how to debug an assembler program.
To find bugs in an assembler program, you have to look the the execution of the portion of the program that is in error. First, you have to make the program stop at the place that contains an error - that is done using "break points".
A breakpoint is a location in the program that when the program reaches that location, Egtapi will stop and await your next command. After the program stopped, you can: look at the value of the variables to see if the program has progressed correctly so far.
After examining various things (e.g. variables), you can then choose to continue the execution of the program from the breakpoint with one of these two actions:
When you click on the "Run" button, Egtapi will run the program until it reaches a break point.
When you click on the "Step" button, Egtapi will execute one assembler instruction and stop.
When Egtapi stops, it will show you the current value of all registers and variables that you have requested (in the variable watch window).
The "Step" button is very helpful to find bugs in your program !!
To find bugs in a program, you need to
If the result prodcued by the program differs from what it supposed to do, you found yourself a bug....
Ofcourse, this requires from you that you know what the assembler program is supposed to do. If you don't have a clue about the assembler program is supposed to do, Egtapi will not be much help to you.... - because you do not know what to look for. (Analogy: if you know nothing about radiology, showing you an X-ray picture is useless since you don't know what to look for....)
So to be successful in finding bugs:
Find out what caused the program to stray !
More information on how to find errors in your assembler programs using Egtapi:
|
(In EGTAPI, select: File Browser, Turnin, click on the file you want to turn in (hw10.s), use the turn in code: hw10)