cancel
Showing results for 
Search instead for 
Did you mean: 

Simple doubt about assembly use into TIM2 ISR

abogani9
Associate II
Posted on May 25, 2009 at 11:37

Simple doubt about assembly use into TIM2 ISR

2 REPLIES 2
abogani9
Associate II
Posted on May 17, 2011 at 15:03

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,

Alessio

luca239955_st
Associate III
Posted on May 17, 2011 at 15:03

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.