{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

AN2093 - Freescale Semiconductor Inc Order this document by...

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

View Full Document Right Arrow Icon
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 Freescale Semiconductor, I Freescale Semiconductor, Inc. For More Information On This Product, Go to: www.freescale.com nc. ..
Image of page 1

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

View Full Document Right Arrow Icon
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.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern