Мне просто нужно изменить код, чтобы он выполнял ту же базовую функцию, но более оптимизированную, в основном я думаю, что цикл фильтрации - это основной кусок кода, который можно изменить, так как я чувствую, что там слишком много инструкций, но не знаю с чего начать. Я работаю с Cortex M3 и Thumb 2.
Я попытался вмешаться в цикл фильтрации, чтобы я мог добавить предыдущее число, сохраненное в регистре, и разделить его на 8, но я не знаю, как на самом деле это выполнить.
; 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 2a_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 2a_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 2a_RWData, DATA, READWRITE
dest ; copy to this area of memory
SPACE end_source-source
end_dest
END
END
Я ожидаю, что будет более эффективный способ выполнения кода, который уменьшит общий размер кода или ускорит время выполнения циклов, если он делает то же самое. Любая помощь будет оценена.