Homework #5 - Due 3/11/03 (Tuesday)
Write an ARM assembly langage program to perform bubble sort of n elements.
lastUnsorted = n - 1;
sortedFlag = 0; // not sorted
while (lastUnsorted >= 1 && sortedFlag == 0) {
sortedFlag = 1;
for (test = 0; test < lastUnsorted; test++) {
if (a[test] > a[test+1]) {
temp = a[test];
a[test] = a[test+1];
a[test+1] = temp;
sortedFlag = 0;
} // end if
} // end for
lastUnsorted = lastUnsorted - 1;
} // end while
|
AREA MAIN, CODE, READONLY |
|
ENTRY |
|
|
|
|
|
|
|
AREA DATA |
N |
DCD 5 |
A |
DCD 33, 6, 10, 5, 1 |
POINTER |
A |
|
END |
Detailed Directions:
- Write your assembly language program on paper first! I will not help anyone debug their program without your handwritten program.
- Start the ARM simulator in Windows by Start | Programs | Programming | ARM Software Development Toolkit | ARM Project Manager
- Create a new file called "hw5.s" by File | New. Save the file in the Z:\cs041 folder by File | Save As. Type in your program in the "hw5.s" file.
- Create a new project called "hw5.apj" by Project | New. Add the file containing your assembly language program (hw5.s) to the project by clicking the "Add" button in the Edit Project window.
- Assemble the project by doing Project | Build. Fix any errors in your assembly language code. (If ARM Project Manager cannot find the assembler, then use Options | Directories to set the Project Manager path to C:\Lang\Arm\BIN\, the Libraries path to C:\Lang\Arm\Lib\, and the Tools path to C:\Lang\Arm\BIN\)
- Use the ARM Debugger to run your program by Project | Debug. The green bar in the Execution window indicates the current PC value. "Step" past the initialization subprogram by Execute | Step (or F10 or by clicking the icon on task bar)
- "Step Into" the MAIN program by Execute | Step Into (or F8 or by clicking the icon on task bar)
- Before you start executing the main program, display the register values by View | Registers | User Mode.
- Before you start executing the main program, display the portion of memory containing the DATA area. To find out where the data area is in memory, use View | Low Level Symbols to find the memory address of "DATA". Use View | Memory and enter the address of DATA.
- Step (or F10 or by clicking the icon on task bar) through the main program one line at a time. Observe how the registers and memory change as you step through the program.
- When you step to the "SWI 0x11" instruction, copy to the Windows clipboard a snapshot of the ARM Debugger window by using the <Alt> and <Print Screen> keys together.
- Open up new Word document and set its page layout to Landscape by File | Page Setup | Paper Size and then select Landscape.
- Paste into the snapshot of the ARM Debugger window into the Word document. Resize the snapshot to the margins and print a copy to turn in.