cancel
Showing results for 
Search instead for 
Did you mean: 

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

Nikolay
Associate II
 
1 ACCEPTED SOLUTION

Accepted Solutions

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.

View solution in original post

7 REPLIES 7
Peter BENSCH
ST Employee

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

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

Nikolay
Associate II

Hey Peter,

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

Nikolay
Associate II

Hi Wilkol,

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

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
Associate II

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

Best regards

Nikolay

uint8_t condition_code_register;
 
condition_code_register = ITC_GetCPUCC();