I want some suggestions to optimize my code which is a simple one but it need to be fast and by fast I mean something less than 250 ns.
my first code was slow , about 1000 ns but after some works its about 550 ns
but I believe it can be done faster but I don't know how :<
I am using a PIC32 with 80 MHz system clock
my code:
void main()
{
unsigned long int arr_1[4095];
unsigned long int arr_2[4095];
//here I assign arr_1 and arr_2 values
//...
//...
TRISC = 0;
TRISD = 0;
while(1){
LATC = arr_1[PORTE];
LATD = arr_2[PORTE];
}
}
as you can see its very simple as a job, the only problem is the speed.
I saw the assembly listing just to see how many instructions there are , but I don't know assembly language to optimize it.
;main.c, 14 :: LATC = arr_1[PORTE];
0x9D000064 0x27A30000 ADDIU R3, SP, 0
0x9D000068 0x3C1EBF88 LUI R30, 49032
0x9D00006C 0x8FC26110 LW R2, 24848(R30)
0x9D000070 0x00021080 SLL R2, R2, 2
0x9D000074 0x00621021 ADDU R2, R3, R2
0x9D000078 0x8C420000 LW R2, 0(R2)
0x9D00007C 0x3C1EBF88 LUI R30, 49032
0x9D000080 0xAFC260A0 SW R2, 24736(R30)
;main.c, 15 :: LATD = arr_2[PORTE];
0x9D000084 0x27A33FFC ADDIU R3, SP, 16380
0x9D000088 0x3C1EBF88 LUI R30, 49032
0x9D00008C 0x8FC26110 LW R2, 24848(R30)
0x9D000090 0x00021080 SLL R2, R2, 2
0x9D000094 0x00621021 ADDU R2, R3, R2
0x9D000098 0x8C420000 LW R2, 0(R2)
0x9D00009C 0x3C1EBF88 LUI R30, 49032
;main.c, 16 :: }
0x9D0000A0 0x0B400019 J L_main0
0x9D0000A4 0xAFC260E0 SW R2, 24800(R30)
Any suggestions to optimize my code ?
edit:
*PORTE, LATC and LATD are I/O mapped registers
*The goal of the code to change LATC and LATD registers as fast as possible when PORTE is changed(so PORTE is an input and LATC and LATD are output), the output depend on the value of PORTE