Skip to main content
Visitor II
May 25, 2009
Question

Simple doubt about assembly use into TIM2 ISR

  • May 25, 2009
  • 2 replies
  • 702 views
Posted on May 25, 2009 at 11:37

Simple doubt about assembly use into TIM2 ISR

    This topic has been closed for replies.

    2 replies

    abogani9Author
    Visitor II
    May 17, 2011
    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

    Visitor II
    May 17, 2011
    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.