2009-05-25 02:37 AM
Simple doubt about assembly use into TIM2 ISR
2011-05-17 06:03 AM
Hi All,
Excuse me for my bad english. Moreover sorry for this very stupid question: I'm only newbie! :) I have just noticed that in some STM8S firmware library examples the TIM2 ISR contains this code: #asm xdef _GTimeStamp inc _GTimeStamp + 3 jrne endinc_tbu inc _GTimeStamp + 2 jrne endinc_tbu inc _GTimeStamp + 1 jrne endinc_tbu inc _GTimeStamp endinc_tbu: #endasm Anyone know (and can share with me) the reason why the developer choose to coded it in Assembly? A simple GTimeStamp++; isn't enough? Thanks! Ciao, Alessio2011-05-17 06:03 AM
Hi,
the C version would give the same result, but with a slower execution (because the compiler calls a general function that adds 1 to a long value). I guess the developer wanted this specific operation (increment by 1) to execute as fast as possible because it happens very often... On a side note, note that this kind of variable (long) is not atomic on the stm8 -> every time there is an access to it interrupts should be disabled.