ECE2801_hw3_C08_sol

ECE2801_hw3_C08_sol - ECE2801Homework#( PLEASE(NEATLY)SHOWALLWORK!Commentallcodewell.Donotmakethe ! ,

Info iconThis 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; }
Background image of page 1

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

View Full DocumentRight 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 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.
Background 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>        
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/24/2009 for the course ECE 2801 taught by Professor Jarvis during the Spring '08 term at WPI.

Page1 / 9

ECE2801_hw3_C08_sol - ECE2801Homework#( PLEASE(NEATLY)SHOWALLWORK!Commentallcodewell.Donotmakethe ! ,

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online