C/C++ programming and efficient coding |
| The performance of an embedded application is determined by a number of factors, including how the source code was written. This section contains articles that describe how to write compiler-friendly code and other programming hints for embedded applications. |
| |
Important Points in 8051 Programming: 8051 Data Memory Architecture |
8051 is an old microcontroller released by Intel in 1980. After its release several semiconductor vendors started offering 8051-based microcontrollers, and it is still widely used with a variety of improvements/enhancements made to it. While it’s designed to improve efficiency considerably when programming in assembler, many instances have been observed where it’s challenging to program in standard C language in terms of memory capacity, without taking special consideration. On the other hand, IAR Embedded Workbench for 8051 supports a wide range of devices for 8051 core, and can generate in the standard C language code comparable to what is written in the assembler. Click to continue... |
| |
What became of my ??!—Pitfalls and possibilities from compiler preprocessing |
Code commented in your mother tongue occasionally leads to odd error messages from compilation. Two question marks and an exclamation ditto are replaced by one vertical bar. The seemingly strange is easier to understand with an insight in the translation phases of your compiler. This text is a brief guide to helping you to avoid problems and gain advantages from knowing a little bit more about the preprocessing phases of translation. Click to continue... |
| |
The behavior of integral types |
When you read the ISO/ANSI C standard, some points look all clear on paper, but when you compile your code it turns out that it does everything except what you wanted it to do! Some parts of the standard need to be analyzed before you fully understand their behavior, and can take advantage of them. Click to continue... |
| |
Interrupt Service Routine calling functions |
One part of embedded programming that has to some extent been lagging in the broad transition from assembly language to C is Interrupt Service Routines (ISRs). One of the notable reasons is the traditional argument for assembly and against C: the need for precise control and optimal code. Click to continue... |
| |
Thoughts on readable code: Conditional expressions |
The problem with conditional expressions is that they too often become large, unstructured, and thus impossible to read. Several studies have shown that complex conditional expressions often cause problems in programs. By making conditional expressions easy to read, it will be easier for both the programmers and people who inspect the code to ensure that the code is correct. Click to continue... |
| |
Writing optimizer-friendly code |
An optimizing compiler tries to generate code that is both small and fast. It does so by repeatedly applying a number of transformations to the source program. Most optimizations follow mathematical or logical rules based on a sound theoretical foundation. Other transformations are based on heuristics, where experience has shown that some transformations often result in good code or open up opportunities for further optimization. There are very few cases where the optimizer relies on black magic, so the way you write your source code can determine whether an optimization can be applied to your program or not. Click to continue... |
| |
Beyond volatile—how to save days of debugging time |
When debugging embedded applications, intermittent problems are among the more difficult ones. This text discusses one source of such problems: variables that are accessed asynchronously, e.g., by interrupt routines or by code running in separate threads. Click to continue... |
| |
Instant C++ for C programmers |
So, your boss gave you the job of moving all your existing C code to the new C++ compiler and you have no idea of where to begin or where the problems might be. Click to continue... |
| |
Tips and tricks using the preprocessor—part 1 and 2 |
Anyone who has ever read a piece of C source code has seen them—the preprocessor directives. For example, you can find include directives (#include) at the beginning of most source files. The preprocessor is a system that rewrites the source before the actual compiler sees it. Clearly, this is a very powerful tool—the downside is that you could accidentally shoot yourself in the foot. Click to continue... |
In this article we will cover some advanced preprocessor topics. First we will talk in-depth about function-like macros, focusing on how to avoid some common pitfalls. Click to continue... |
| |
MISRA C—some key rules to make embedded systems safer |
No one can deny that embedded systems are becoming more and more common. However, as the number of systems grows, and as we put more and more responsibility on the systems, some important questions must be asked. The most important question is: How can we ensure that embedded systems are safe? Click to continue... |
| |