Skip to main content
Nikolay
Associate II
May 3, 2021
Solved

Hi, How can I read condition code register in C? I use STM8S standard peripheral library Best regards Nikolay

  • May 3, 2021
  • 5 replies
  • 2141 views

..

    This topic has been closed for replies.
    Best answer by Peter BENSCH

    Regardless of the challenging task of transferring assembler code from another MCU to C code on the STM8, everything is already included in the function ITC_GetCPUCC mentioned above:

    uint8_t ITC_GetCPUCC(void)
    {
    #ifdef _COSMIC_
     _asm("push cc");
     _asm("pop a");
     return; /* Ignore compiler warning, the returned value is in A register */
    #elif defined _RAISONANCE_ /* _RAISONANCE_ */
     return _getCC_();
    #else /* _IAR_ */
     asm("push cc");
     asm("pop a"); /* Ignore compiler warning, the returned value is in A register */
    #endif /* _COSMIC_*/
    }

    In fact it is done using pushing CCR to the stack and pop it back to the accumulator.

    But as @Community member​ already wrote: it is questionable whether it actually makes sense to read the CCR in C directly, since all bits can also be processed in other ways, e.g. by conditional commands.

    If this problem is resolved, please mark this topic as answered by selecting Select as best. This will help other users find that answer faster.

    Good luck!

    /Peter

    5 replies

    Peter BENSCH
    Technical Moderator
    May 4, 2021

    Simply search the SPL for ITC_GetCPUCC or the define CPU_CC_I1I0, which accesses the CCR at 0x28 at the end.

    Regards

    /Peter

    In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
    WilkoL
    Senior
    May 4, 2021

    Why do you want to read it? In assembly it is useful but I can't think of any use in C.

    Nikolay
    NikolayAuthor
    Associate II
    May 4, 2021

    Hey Peter,

    I know this address. I mean, how should I read from it?

    WilkoL
    Senior
    May 5, 2021
    uint8_t condition_code_register;
     
    condition_code_register = ITC_GetCPUCC();

    Nikolay
    NikolayAuthor
    Associate II
    May 4, 2021

    Hi Wilkol,

    I'm translating one Assembly app (some other IC) to C (STM8S) and it's not a very easy task.

    Peter BENSCH
    Peter BENSCHBest answer
    Technical Moderator
    May 4, 2021

    Regardless of the challenging task of transferring assembler code from another MCU to C code on the STM8, everything is already included in the function ITC_GetCPUCC mentioned above:

    uint8_t ITC_GetCPUCC(void)
    {
    #ifdef _COSMIC_
     _asm("push cc");
     _asm("pop a");
     return; /* Ignore compiler warning, the returned value is in A register */
    #elif defined _RAISONANCE_ /* _RAISONANCE_ */
     return _getCC_();
    #else /* _IAR_ */
     asm("push cc");
     asm("pop a"); /* Ignore compiler warning, the returned value is in A register */
    #endif /* _COSMIC_*/
    }

    In fact it is done using pushing CCR to the stack and pop it back to the accumulator.

    But as @Community member​ already wrote: it is questionable whether it actually makes sense to read the CCR in C directly, since all bits can also be processed in other ways, e.g. by conditional commands.

    If this problem is resolved, please mark this topic as answered by selecting Select as best. This will help other users find that answer faster.

    Good luck!

    /Peter

    In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
    Nikolay
    NikolayAuthor
    Associate II
    May 4, 2021

    Peter, thanks for the comprehensive answer. I'll check it tomorrow

    Best regards

    Nikolay