Hi, I'm using xc16 on PIC24F and I have a block of code that could be implemented in a much nicer fashion if I were using asm. Is there a trick I'm missing in C that can replicate the asm efficiency?
My C code, fast if phase==0; gets progressively slower when phase==5 because every condition needs to be evaluated along the way.
ASM code, fast for all phases because the program counter jumps straight to the appropriate instruction
My C code, fast if phase==0; gets progressively slower when phase==5 because every condition needs to be evaluated along the way.
Code:
if(phase==0)
LATAbits.RA0 = 1;
else if(phase==1)
LATCbits.RC7 = 1;
else if(phase==2)
LATBbits.RB2 = 1;
Etc…
Code:
phase = phase*2;
Add PCL, phase
BSF LATA, 0
GOTO done
BSF LATC, 7
GOTO done
BSF LATB, 2
GOTO done
Etc…
done: