How to use bit, sfr and push/pop intrinsics

Technical Note 40085






11/6/2015 12:46 PM


This Technical Note discusses some issues that occurs for users that are migrating from the Keil tools to IAR Embedded Workbench for 8051.


The examples are written using IAR Embedded Workbench for 8051 version V7.x (or later).

The examples show how to use bit variables, sfr variables and how to replace the Keil intrinsic functions _push_() and _pop_().

One common question... how you can replace the Keil sbit syntax and the answer is that you simply use our header files instead. In there we use anonymous SFR unions with both a char and a bitfield.

Example 1

#include <stdbool.h>
__no_init bool __bit mybit;

#define BIT __no_init bool __bit
BIT mybit2;

void main(void)
mybit = 1;
mybit2 = 1;

Example 2

__sfr __no_init volatile unsigned int test_int @0x92;
__sfr __no_init volatile unsigned char test_char @0x94;

#define SFR __sfr __no_init volatile
SFR unsigned int test_int2 @0x96;
SFR unsigned char test_char2 @0x98;

void main(void)
test_int = 0x1122;
test_char = 0x33;
test_int2 = 0x4455;
test_char2 = 0x66;

Example 3

#define _push_(X) { char __tmp; __tmp=X;
#define _pop_(X) X=__tmp;}

All product names are trademarks or registered trademarks of their respective owners.

We do no longer support Internet Explorer. To get the best experience of, we recommend upgrading to a modern browser such as Chrome or Edge.