C and Assembly Timing problem

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by Alainbs on Tue May 28 09:40:17 MST 2013
I have a project where i have C files and ASM files (LPC1114 xpresso board and lpcxpresso IDE). 

From C i call an assembly function where i read a GPIO and acquire the bits, after that i return again to C.
The problem is that when i add or delete lines of code in C the sampling time in assembly change.
Does the compiler optimize also my assembly code? What can i do?

[COLOR=royalblue]From my C code i make a call to the assembly function and got the last RAM address:[/COLOR]
unsigned int *lastRAMaddr;
[COLOR=black]lastRAMaddr = (unsigned int*)asmfunction();[/COLOR]
here process the data i got from sampling
[COLOR=#3f7f5f][COLOR=#3f7f5f][/COLOR][/COLOR][COLOR=royalblue]Sampling part look like this:[/COLOR]
[SIZE=2]movs   r0,#150[/SIZE]
[SIZE=2]ldr       r2,[r3]   //Read GPIO r3 hold the address of the gpio[/SIZE]
[SIZE=2]stm     r1!,{r2} //Store Bit in Ram and increment address[/SIZE]
[SIZE=2]subs    r0,#1    [/SIZE]
[SIZE=2]bne     [COLOR=darkred]readpin[/COLOR][/SIZE]
[SIZE=2][COLOR=black]movs  r0,#0[/COLOR][/SIZE]
[SIZE=2]orrs    r0,r1      //Get last RAM address
bx     lr[SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]