Pular para o conteúdo principal
Knowledgebase
Home
Renesas Brasil - Knowledgebase

How can clr1 or set1 operand be generated using C language?

Latest Updated:12/03/2014

Question:

I wrote a code to operate SFR (Special Function Register) bit, but "mov" operand has been generated.
How can clr1 or set1 operand be generated using C language?

Answer:

Since GNU-RL78 compiler does not generate clr1 nor set1 operand, you need to prepare macro definitions as following example:

/*---- sample code ----*/
#define IF1H 0xFFFE3
#define CB(ADDR, BIT) asm volatile ("clr1 " #ADDR ".%S0" : : "n"(BIT) : "memory")
#define CLEAR_BIT(A, B) CB (A, B)

#define SB(ADDR, BIT) asm volatile ("set1 " #ADDR ".%S0" : : "n"(BIT) : "memory")
#define SET_BIT(A, B) SB (A, B)

int main (void)
{
	CLEAR_BIT (IF1H, 0);
	CLEAR_BIT (IF1H, 1);
	SET_BIT (IF1H, 0);

	return 0;
}
/*---- end of sample code ----*/

Note: This sample code is written for RL78 G13 100LE. Please adjust descriptions to fit to desired devices.

Suitable Products
e² studio