Homework #4 - Due 3/4/03 (Tuesday)

The high-level language program to calculate x * y by repeated addition could be written as

result := 0

for counter := 1 to y do

result := result + x

end for

In assembly language this translates to the following program:

 

AREA MAIN, CODE, READONLY

 

 

ENTRY

 

 

 

 

 

LDR R1, X

 

 

LDR R2, Y

 

 

MOV R3, #1

 

 

MOV R4, #0

 

 

MOV R5, #1

 

FOR

CMP R3, R1

 

 

BLE DO_LOOP

 

 

B END_FOR

 

DO_LOOP

ADD R4, R4, R2

 

 

ADD R3, R3, R5

 

 

B FOR

 

END_FOR

STR R4, RESULT

 

 

SWI 0x11

 

 

 

 

 

AREA DATA

 

X

DCD 3

 

Y

DCD 2

 

RESULT

DCD 0

 

 

END

 

Overview: Type in the above program in the Wright Hall labs (Wright 110, 112, or 339) using the ARM simulator. Use the debugger to "step into" the MAIN code and run the program to completion while viewing the registers and memory. Turn in a snap shot of the Debugger window after execution. (Below are step-by-step directions to walk you through this process)

Detailed Directions:

  1. Create a new folder on the 'Student' Z: drive called "cs041"
  2. Start the ARM simulator in Windows by Start | Programs | Programming | ARM Software Development Toolkit | ARM Project Manager
  3. Create a new file called "hw4.s" by File | New. Save the file in the newly created Z:\cs041 folder by File | Save As. Type in the given program in the "hw4.s" file.
  4. Create a new project called "hw4.apj" by Project | New. Add the file containing your assembly language program (hw4.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 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><Print Screen> keys.
  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.