Home     Blog    News    Twitter    Google+    Contact

8051 C Compiler

The Crossware 8051 C compiler is an ANSI standard compiler that generates code for the 8051 family of microcontrollers. It provides numerous extensions that allow access to 8051 specific features so that you can write your code completely in the C language without the need to resort to assembler code. It supports both small and large memory models so you can create code for all 8051 variants whether or not they have external ram.


Language Definition

The compiler conforms to the ANSI C specification and in addition provides a number of general enhancements including:

The support libraries are a subset of the ANSI standard libraries. The supported functions are listed below.

8051 specific language extensions are described below.

Data sizes

The compiler uses the following sizes for the various C data types:

char and unsigned char: 1 byte
short int and unsigned short int: 2 byte
int and unsigned int: 2 bytes
long and unsigned long: 4 bytes
float: 4 bytes (32 bits)
double: 8 bytes (64 bits)
long double: 8 bytes (64 bits)
enum: up to 4 bytes (minimum size to
accommodate members)
bit fields: up to 32 bits
bit: 1 bit


Optimizations include:

8051 Language Extensions

In addition to the general extensions described above, the compiler supports numerous 8051 specific extensions which enable you to maximise your use of the internal resources of the 8051 and its variants. These include:

Smart Pointers

The compiler supports pointers that point to any specific memory area and generic 3 byte pointers that can point to all memory areas. Some 8051 C compilers default to generic 3 byte pointers unless you declare a memory specific pointer using a qualifying keyword. It is then necessary to decorate your source code with non-ANSI keywords in order to avoid program inefficiency. This decoration may be memory model specific and so if you switch memory models you have to change your source code too. The Crossware 8051 ANSI C compiler avoids this problem. Although it supports these pointer qualifiers, in most cases it is not necessary to use them. Instead any pointer that is not qualified is a smart pointer. It will then work out for itself from the way it is used what type of pointer it should be. This leaves you free to write memory model independent source code without any unnecessary loss of efficiency. For further information see Memory models, pointer types and smart pointers.

Floating Point

The Crossware 8051 ANSI C compiler supports both 32 bit and 64 bit floating point objects.

32 bit floating point objects contain only 23 bits of precision (the rest is used by the exponent and sign) and are therefore less precise than 32 bit long integers. They are however ideal for the application where low precision floating point arithmetic is all that is required. 64 bit floating point objects contain 53 bits of precision and are therefore ideal where arithmetic accuracy is an important issue.

All floating point arithmetic and normalisation routines are hand-coded in 8051 assembler to provide fast and compact library code.

Memory Models

The compiler supports a small memory model for use with chips that do not have any external ram and a large memory model for chips with external ram. Functions can be either reentrant or non-reentrant. A non-reentrant function is faster and smaller but cannot be called either directly or indirectly from within itself.

8051 Variants

The compiler supports all 8051 variants including those that require the use of the ACALL and AJMP instructions.

Debug output

The compiler generates full IEEE695 debug records. These records provide full information to the simulator and debugger allowing you to single step through your C source code and watch all of your C variables.

In-Line Assembler

The compiler provides numerous features that allow you to access the 8051 features at the C source level. Nevertheless you can still embed assembler in your C code if you wish using the #asm/#endasm directives.

C Library Support Routines

abs( ), coshl( ), fscanf( ), ldexp( ), rand( ), strncat( ),
acos( ), exit( ), getc( ), ldexpl( ), sbrk( ), strncmp( ),
acosl( ), exp( ), getchar( ), log( ), scanf( ), strncpy( ),
asin( ), expl( ), getche( ), logl( ), sin( ), strpbrk( ),
asinl( ), fabs( ), gets( ), log10( ), sinl( ), strrchr( ),
atan( ), fabsl( ), isalnum( ), log10l( ), sinh( ), strspn( ),
atanl( ), _fcvt( ), isalpha( ), ltoa( ), sinhl( ), strstr( ),
atan2( ), ferror( ), isacii( ), malloc( ), sprintf( ), tan( ),
atan2l( ), fgetc( ), iscntrl( ), memchr( ), sqrt( ), tanl( ),
atof( ), fgets( ), isdigit( ), memcmp( ), sqrtl( ), tanh( ),
atofl( ), fileno( ), isgraph( ), memcpy( ), srand( ), tanhl( ),
atoi( ), floor( ), islower( ), memmove( ), sscanf( ), time( ),
atol( ), floorl( ), isprintf( ), memset( ), strcat( ), toascii( ),
clearerr( ), fprintf( ), ispunct( ), pow( ), scanf( ), tolower( ),
ceil( ), fputc( ), isspace( ), powl( ), strchr( ), toupper( ),
ceill( ), fputs( ), isupper( ), printf( ), strcmp( ), ultoa( ),
cos( ), free( ), isxdigit( ), putc( ), strcpy( ), ungetc( ),
cosl( ), frexp( ), itoa( ), putchar( ), strcspn( ), ungetch( ),
cosh( ), frexpl( ), labs( ), puts( ), strlen( ),  

Relocating Linker

The linker combines object modules created with the compiler and/or the assembler to create the final code that will run on your target system. It carries out the following functions:

The linker will also construct a call tree of your C functions. It will use this to perform an overlay analysis of the local data areas of any non-reentrant functions, sharing memory wherever possible. It will report potential recursion of non-reentrant functions. At the same time, the parameter space for non-reentrant functions with variable numbers of arguments will be sized to the maximum required by any of the calls to that function.

The target program can be produced in a number of different formats including Intel hex, Intel OMF51, Motorola 'S' record, HP/Microtec IEEE695 format or as a binary rom image. No conversion utility has to be used - the linker directly outputs the program in the specified format.

An optional link map will show the final location and sizes of all segments and the values of all global variables.

Library Manager

Instead of being used to create a final target program, the object modules produced by the compiler and assembler can be integrated into a library. The library manager performs the tasks of:

Make Utility

The MAKE utility simplifies the task of keeping object files, libraries and target programs up-to-date. It detects if any source or dependency files have changed since the last build and runs the appropriate tools (compiler, assembler, linker or library manager) to rebuild out-of-date files. It supports many advanced features including macros, inference rules, conditional inclusion and other preprocessing directives and in-line files with automatic temporary file creation.

Although the Embedded Development Studio uses its own integrated routines to keep projects up-to-date, this stand-alone MAKE utility can be used to build projects from the command-line or from within another application. The Embedded Development Studio will automatically create a makefile which is fully compatible with this stand-alone MAKE utility.

Relocatable Macro Cross Assembler