AN2093

AN2093 - Motorola Semiconductor Application Note Order this...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Motorola Semiconductor Application Note Order this document by AN2093/D © Motorola, Inc., 2000 AN2093 AN2093 Creating Efficient C Code for the MC68HC08 by Stuart Robb East Kilbride, Scotland 1 Introduction The C programming language is a powerful, flexible and potentially portable high-level programming language. These and other features, such as support for low-level operations, make this a useful language for programming embedded applications. Many embedded applications use low-cost microcontrollers with an 8-bit data bus. Such microcontrollers often have limited on-chip resources, such as few CPU registers and limited amounts of RAM and ROM. Compared to other 8-bit microcontrollers, the HC08 architecture is well suited to the C programming language. It has an effective instruction set with addressing modes which enable efficient implementation of C instructions. The instruction set includes instructions for manipulating the stack pointer. The addressing modes include indexed addressing modes with the index contained in the index register or the stack pointer register. These features allow efficient access to local variables. The C language may be used successfully to create the program for the HC08 microcontroller, but to produce the most efficient machine code, the programmer must carefully construct the C language program. In this context, “efficient code” means compact code size and fast execution time. The programmer must not only create an efficient high level design, but also pay attention to the detailed implementation. Principally, efficiency improvements may be obtained by appropriate design of data structures and use of data types. Programmers accustomed to coding in assembly language will be familiar with these issues and C programmers should remember that their C code is converted into assembly language by the compiler. In actual fact, the compiler will recognise certain constructs in C and replace them with functions or in-line code which have often been hand coded in assembly. Thus a F r e e s c a l e S e m i c o n d u c t o r , I Freescale Semiconductor, Inc. For More Information On This Product, Go to: www.freescale.com n c . . . AN2093 2 MOTOROLA Application Note compiler is no more efficient that a good assembly programmer. It is however, much easier to write good code in C which can be converted into efficient assembly code than it is to write efficient assembly code by hand. The potential drawback is that it is very easy to create C code which no compiler, no matter how good, can convert into efficient assembly code. Some hints and tips are presented in this paper to aid the programmer to write their code in C in a way in which a compiler can convert into efficient machine code. Some of these tips will also improve the portability of the code. Examples are given based on real compiler output generated by the Hiware HC08 compiler from Metrowerks Europe (formerly Hiware AG), a Motorola company....
View Full Document

This note was uploaded on 02/08/2011 for the course EE 459L taught by Professor Weber during the Spring '11 term at USC.

Page1 / 16

AN2093 - Motorola Semiconductor Application Note Order this...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online