Hi there, this is a working piece of code that I have written and I am wondering if there is any way to reduce the overall execution time, number of cycles or maybe the size of the memory in the code.
; Perform in-place filtering of data supplied in memory ; the filter to be applied is a non-recursive filter of the form ; y[0] = x[-2]/8 + x[-1]/8 + x[0]/4 + x[1]/8 + x[2]/8 ; set up the exception addresses THUMB AREA RESET, CODE, READONLY EXPORT __Vectors EXPORT Reset_Handler __Vectors DCD 0x00180000 ; top of the stack DCD Reset_Handler ; reset vector - where the program starts num_words EQU (end_source-source)/4 ; number of input values filter_length EQU 5 ; number of filter taps (values) AREA Task2c_Code, CODE, READONLY Reset_Handler ENTRY ; set up the filter parameters LDR r0,=source ; point to the start of the area of memory holding inputs MOV r1,#num_words ; get the number of input values MOV r2,#filter_length ; get the number of filter taps LDR r3,=dest ; point to the start of the area of memory holding outputs ; find out how many times the filter needs to be applied SUBS r4,r1,r2 ; find the number of applications of the filter needed, less 1 BMI exit ; give up if there is insufficient data for any filtering ; apply the filter filter_loop LDMIA r0,{r5-r9} ; get the next 5 data values to be filtered ADD r5,r5,r9 ; sum x[-2] with x[2] ADD r6,r6,r8 ; sum x[-1] with x[1] ADD r9,r5,r6 ; sum x[-2]+x[2] with x[-1]+x[1] ADD r7,r7,r9,LSR #1 ; sum x[0] with (x[-2]+x[2]+x[-1]+x[1])/2 MOV r7,r7,LSR #2 ; form (x[0] + (x[-2]+x[-1]+x[1]+x[2])/2)/4 STR r7,[r3],#4 ; save calculated filtered value, move to next output data item ADD r0,r0,#4 ; move to start of next 5 input data values SUBS r4,r4,#1 ; move on to next set of 5 inputs BPL filter_loop ; continue until last set of 5 inputs reached ; execute an endless loop once done exit B exit AREA Task2c_ROData, DATA, READONLY source ; some saw tooth data to filter - should blunt the sharp edges DCD 0,10,20,30,40,50,60,70,80,90,100,0,10,20,30,40,50,60,70,80,90,100 DCD 0,10,20,30,40,50,60,70,80,90,100,0,10,20,30,40,50,60,70,80,90,100 DCD 0,10,20,30,40,50,60,70,80,90,100,0,10,20,30,40,50,60,70,80,90,100 DCD 0,10,20,30,40,50,60,70,80,90,100,0,10,20,30,40,50,60,70,80,90,100 end_source AREA Task2c_RWData, DATA, READWRITE dest ; copy to this area of memory SPACE end_source-source end_dest END ENDI am working with The Cortex M3, as long as one of those three things has been made smaller it's ok. Thank you for your help, the changes don't have to be major as long as something changes.
; Perform in-place filtering of data supplied in memory ; the filter to be applied is a non-recursive filter of the form ; y[0] = x[-2]/8 + x[-1]/8 + x[0]/4 + x[1]/8 + x[2]/8 ; set up the exception addresses THUMB AREA RESET, CODE, READONLY EXPORT __Vectors EXPORT Reset_Handler __Vectors DCD 0x00180000 ; top of the stack DCD Reset_Handler ; reset vector - where the program starts num_words EQU (end_source-source)/4 ; number of input values filter_length EQU 5 ; number of filter taps (values) AREA Task2c_Code, CODE, READONLY Reset_Handler ENTRY ; set up the filter parameters LDR r0,=source ; point to the start of the area of memory holding inputs MOV r1,#num_words ; get the number of input values MOV r2,#filter_length ; get the number of filter taps LDR r3,=dest ; point to the start of the area of memory holding outputs ; find out how many times the filter needs to be applied SUBS r4,r1,r2 ; find the number of applications of the filter needed, less 1 BMI exit ; give up if there is insufficient data for any filtering ; apply the filter filter_loop LDMIA r0,{r5-r9} ; get the next 5 data values to be filtered ADD r5,r5,r9 ; sum x[-2] with x[2] ADD r6,r6,r8 ; sum x[-1] with x[1] ADD r9,r5,r6 ; sum x[-2]+x[2] with x[-1]+x[1] ADD r7,r7,r9,LSR #1 ; sum x[0] with (x[-2]+x[2]+x[-1]+x[1])/2 MOV r7,r7,LSR #2 ; form (x[0] + (x[-2]+x[-1]+x[1]+x[2])/2)/4 STR r7,[r3],#4 ; save calculated filtered value, move to next output data item ADD r0,r0,#4 ; move to start of next 5 input data values SUBS r4,r4,#1 ; move on to next set of 5 inputs BPL filter_loop ; continue until last set of 5 inputs reached ; execute an endless loop once done exit B exit AREA Task2c_ROData, DATA, READONLY source ; some saw tooth data to filter - should blunt the sharp edges DCD 0,10,20,30,40,50,60,70,80,90,100,0,10,20,30,40,50,60,70,80,90,100 DCD 0,10,20,30,40,50,60,70,80,90,100,0,10,20,30,40,50,60,70,80,90,100 DCD 0,10,20,30,40,50,60,70,80,90,100,0,10,20,30,40,50,60,70,80,90,100 DCD 0,10,20,30,40,50,60,70,80,90,100,0,10,20,30,40,50,60,70,80,90,100 end_source AREA Task2c_RWData, DATA, READWRITE dest ; copy to this area of memory SPACE end_source-source end_dest END END