EE357-Nazarian-Fall09-Lab1-c_asm

EE357-Nazarian-Fall09-Lab1-c_asm - EE 357 Lab 1 – Some...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: EE 357 Lab 1 – Some Assembly Required 1 Introduction In this lab you will compare the assembly code output from a compiler with hand‐ coded assembly. 2 What you will learn This lab is intended to teach you to use the Codewarrior IDE to set breakpoints, view register values, and step through code. This lab will also show you some examples of assembly code. Hopefully by seeing example code, you will be able to write code on your own. 3 Background Information and Notes Please read the “Codewarrior for Coldfire 7.1 Setup” document before attempting this lab. It will provide direction for how to use the Codewarrior IDE to write, compile, and debug software programs. 4 Prelab None 5 Procedure 1. Download the two project zip files: “ee357_lab1_cdemo.zip” and “ee357_lab1_asmdemo.zip”, unzip them to folders on your PC. 2. Open the C‐Demo project, by double‐clicking the .mcp file in the project folder. This project finds the maximum integer in an array of 8 ‘int’ values. It is setup for the Instruction Set Simulator (ISS) and thus does not require your HW board. 3. Open ‘main.c’ and examine the code and understand it. Then compile/make the project and start the debugger. 4. Set a breakpoint at the assignment “max = ‐1;” and another at the “printf” near the bottom. We will find the time it takes to execute the code between these breakpoints. 5. Change the view from “Source” to “Mixed” to view the assembly code generated. Fall 2009 1 EE 357 Lab 1 ‐ Some Assembly Required Figure 1 - Setting Breakpoints and Switching to Mixed C/Assembly View Address of Instruc. Machine Code Assembly Syntax Arguments or Effective Address Figure 2 - Understanding the Mixed C/Assembly Debugger View 6. Use the Coldfire Programmer’s Reference Manual (CFPRM) document posted on Blackboard..Course Documents and look up the MOVEQ instruction (in Chapter 4). What is the range of immediate value that can be stored by MOVEQ. Why do you think this instruction is called “Move Quick” (i.e.we could simply use MOVE.s #imm,dst) Also, try to figure out what the address of the “max” variable is by looking at the code. 7. Now click View..Registers and expand the window so you can see the GPR’s as well as the ISS registers. 2 Fall 2009 EE 357 Lab 1 ‐ Some Assembly Required Figure 3 – Viewing GP Registers and ISS registers values 8. Run the program until the first breakpoint. Record the values of the ISS registers (instruction count and cycle count up to that point). These values include some startup/initialization code executed before main() was started. 9. Now step through the code to understand its operation. As you step through the code, identify how each register is used within the body of the loop and record your findings. 10. Once the next breakpoint has been reached, record the value of the ISS registers again. How many instructions and cycles were required for execution of the loop? 11. Close the C‐Demo Project and associated files and popen the ASM‐Demo project, by double‐clicking the .mcp file in the project folder. This project performs the same operation but using hand‐coded assembly only. It is setup for the Instruction Set Simulator (ISS) and thus does not require your HW board. 12. Open ‘main.s’ and examine the code to understand it. Set a breakpoint at the first instruction “move.l #‐1,d0” and then later on at “movea.l #mytxt,a1”. Recall, that it is necessary in the assembly projects to set a breakpoint at the first instruction of main before the debugger is started. 13. Compile/make the project and start the debugger. View the registers again and record the ISS registers at the first breakpoint (first instruction of main), then step through the code. Again, as you step through the code, identify how each register is used within the body of the loop and record your findings. Describe how this code differs from the code generated by the C compiler (include Fall 2009 3 EE 357 Lab 1 ‐ Some Assembly Required general algorithm approach, use of different addressing modes to access the data array, and anything else that you find important). 14. Run the code through the final breakpoint and again record the ISS registers. Which code ran faster? To give a more accurate measurement, ignore the startup time (i.e. measure only the time that was taken to execute the actual loop by subtracting the initial instruction and cycle count from the final instruction and cycle count? What percentage faster was one vs. the other (i.e. take the longer duration code time divided by the shorter duration code time). 15. Challenge: Modify the assembly code version to use the post‐increment or pre‐decrement addressing mode rather than index mode. Be sure to make all necessary changes (i.e. think about side effects or different initialization that may need to take place) 6 Review 1. In the hand‐coded assembly, why did the index addressing mode use the size modifier *4 (i.e. MOVE.L (A0,D1*4),D2 ) 2. Realizing that each loop ran 8 iterations, use the clock cycle times to extrapolate how much time would be saved between the C and ASM versions if the array had 1 million items and thus required the loop to iterate 1 million times. Calculate actual time by assuming the processor clock speed is 8 MHz (i.e. T = time per clock cycle = 1 / 8 * 106). 4 Fall 2009 EE 357 Lab 1 ‐ Some Assembly Required 7 Lab Report Name: ___________________________________ Due: _____________ Score: ________ (Detach and turn this sheet along with any other requested work or printouts) C‐Demo Questions 1. What is the range of immediate value that can be stored by MOVEQ? ________ 2. Why do you think this instruction is called “Move Quick” (i.e.we could simply use MOVE.s #imm,dst) [Hint: Accessing memory takes time] 3. What is the address of the “max” variable? _______________ 4. ISS Register Values INSTCNT CYCLCNT Start Breakpoint End Breakpoing 5. Register usage description (only w/in the body of the loop): Registers Description A0 D0 D1 D2 ASM‐Demo Questions 6. Register usage description (only w/in the body of the loop): Registers Description A0 D0 D1 D2 Fall 2009 5 EE 357 Lab 1 ‐ Some Assembly Required 7. Description differences between code generated by the C compiler and the hand‐coded assembly. 8. ISS Register Values INSTCNT CYCLCNT Start Breakpoint End Breakpoing 9. Which version executes faster in terms of clock cycles and by what percentage? When calculating the percentage, remove the startup cycle times (values before the start breakpoint) and use only the difference between start and finish. Review Question: 10. In the hand‐coded assembly, why did the index addressing mode use the size modifier *4 (i.e. MOVE.L (A0,D1*4),D2 )? 11. Realizing that each loop ran 8 iterations, use the clock cycle times to extrapolate how much time would be saved between the C and ASM versions if the array had 1 million items and thus required the loop to iterate 1 million times. Calculated actual time by assuming the processor clock speed is 8 MHz. Assigned: Thursday Sep. 10 Due: Friday Sep. 18 in discussion class 6 Fall 2009 ...
View Full Document

This note was uploaded on 09/14/2010 for the course EE 357 at USC.

Ask a homework question - tutors are online