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:

  1. Write your assembly language program on paper first! I will not help anyone debug their program without your handwritten program.
  2. Start the ARM simulator in Windows by Start | Programs | Programming | ARM Software Development Toolkit | ARM Project Manager
  3. 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.
  4. 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.
  5. 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\)
  6. 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)
  7. "Step Into" the MAIN program by Execute | Step Into (or F8 or by clicking the icon on task bar)
  8. Before you start executing the main program, display the register values by View | Registers | User Mode.
  9. 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.
  10. 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.
  11. 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.
  12. Open up new Word document and set its page layout to Landscape by File | Page Setup | Paper Size and then select Landscape.
  13. 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.