{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

ECE2801_hw3_C08_sol

ECE2801_hw3_C08_sol - ECE2801Homework#(...

Info icon This preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
ECE2801 Homework #3 – Assembly and Mixed Language Programming   (Due Thursday 2/7/08 At the BEGINNING of class) PLEASE (NEATLY) SHOW ALL WORK !  Comment all code well. Do not make the  grader guess what your doing! All code should be typed. To ensure proper grading and return, include the following header info on each   homework you submit:  Name, Course # and HW#, WPI e-mail, ECE Box #. References :  Class Notes, MSP430 User's Guide Ch. 3, 7 and IAR EW Assembly           Reference Guide (all available on class website) 1. (25 pts)  The programs below both perform exponential averaging, or  “smoothing”, on the input data array X according to Y[n] = (1-alfa)*Y[n-1]  + alfa*X[n] a)  Create a C project in IAR Kickstart and add the code below to it.  Create a LIST  file and notice the length and complexity of the assembly code that results from  this simple C program.  Step through the code and note the values of Y[0] thru  Y[7]. #include "msp430x44x.h" #include <stdlib.h> #include <math.h> void main() { unsigned int x[8] = {150,172,147,161,180,179,162,166}; unsigned int y[8]; char i, arr_sz = 8; float alfa = 0.25; WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer y[0] = x[0]; i = 1; while (i < arr_sz) { y[i] = (1-alfa)*y[i-1] + alfa*x[i]; i++; } while (1) // dead loop does nothing useful i = i; }
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
b)  Now create an assembly only project in IAR Kickstart and add this assembly  code to it.  Step through the code to verify that it gives the same results as the C  code from part (a).  Which code (a or b) would be more efficient in term of code  storage and execution speed. Why? NAME hw3pr3b ORG 0FFFEh DW main ORG 0200h x DW 150,172,147,161,180,179,162,166 y DS16 8 sz DS8 1 alf DW 1 RSEG CODE main MOV #0A00h,SP MOV.B #08,&sz ; set array size = 8 MOV.B &sz,R6 CLR R7 MOV x(R7),y(R7) DEC R6 top MOV y(R7),R10 ADD y(R7),R10 ADD y(R7),R10 ; R10 = 3*Y[n-1] INCD R7 ADD x(R7), R10 ; R10 = 3*Y[n-1] + 1*X[n] RRA R10 ; Rotate right 1 bit = R10/2 RRA R10 ; Rotate right 1 bit = R10/2 MOV R10, y(R7) DEC R6 CMP #0,R6 JNZ top dun JMP dun END The point of this problem was to illustrate the “hand written” assembly programs are  almost always more efficient in terms of code size and execution time than code  produced automatically from a higher level compiler.  Below is the list file of the  assembly produced for the C code. It is approximately 3 times longer than the  assembly file shown above.
Image of page 2
e:\ece2801_C08\lab2\hw3pr1C08.c       1          #include "msp430x44x.h"       \                                 In  segment DATA16_AN, at 0x120    \   unsigned short volatile __data16 WDTCTL    \                     WDTCTL:    \   000000                DS8 2       2          #include <stdlib.h>       3          #include <math.h>        
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.
  • Spring '08
  • Jarvis
  • SEPTA Regional Rail, X86 assembly language, R10, MOV DEC MOV, MOV   x,R8  MOV, MOV  R8,MPYS        MOV

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern