hw5_A09_sol

hw5_A09_sol - ECE2801 Homework#5 Assembly and Mixed...

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

View Full Document Right Arrow Icon
ECE2801 Homework #5 – Assembly and Mixed Language Programming Solutions 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; } 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
Background image of page 1

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

View Full DocumentRight Arrow Icon
(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 and, hence, would take ~3times as long to execute.
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> \ In segment CODE, align 2 5 void main() \ main: 6 7 { \ 000000 0A12 PUSH.W R10 \ 000002 0B12 PUSH.W R11 \ 000004 0812 PUSH.W R8 \ 000006 0912 PUSH.W R9 \ 000008 0612 PUSH.W R6 \ 00000A 0712 PUSH.W R7 \ 00000C 0412 PUSH.W R4 \ 00000E 0512 PUSH.W R5 \ 000010 31802400 SUB.W #0x24, SP 8 unsigned int x[8] = {150,172,147,161,180,179,162,166}; \ 000014 0C41 MOV.W SP, R12 \ 000016 2C52 ADD.W #0x4, R12 \ 000018 3E40. ... MOV.W #`?<Constant {150, 172, 147, 161, 180, 179, 162,`, R14
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 10/12/2009 for the course ECE 2801 taught by Professor Jarvis during the Spring '08 term at WPI.

Page1 / 8

hw5_A09_sol - ECE2801 Homework#5 Assembly and Mixed...

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