Es Module 2 Notes PDF
Es Module 2 Notes PDF
Processor
The processor used in embedded systems can be of three types:
Micro-Controllers
Microprocessors
Each of them is specified by clock speed( 100MHz, etc) and data word length( 8-bit, 16-bit, 32bit). The higher the clock speed, the faster the processor. Same way, bigger data word-length
leads to higher precision. The word length also indicates the processor's capability to address the
memory. This addressing capability is specified by the number of bits used for addressing. For
instance, an 8-bit processor can be use 8 or 16-bit for addressing.
Micro-controller
Micro-controllers are mainly of Intel's 805x family, Motorola's 68HCxx, etc. A typical microcontroller contains a CPU, interrupts, timer/counter, memory (RAM, ROM, or both) and other
peripherals in same Integrated Circuit(IC). Micro-controller are often an ideal solution for control
applications because you can use them to build an embedded system with little additional
circuitry. The 8-bit micro-controllers are used for process control applications, such as the ones
found in toys and smart cards. If your processing power and memory requirements are high, you
need to choose a 16-bit or 32-bit processor.
High level language programming makes the program development cycle short, enables
use of the modular programming approach and lets us follow sound software engineering
principles. It facilitates the program development with Bottom up design and top down
design approaches. Embedded system programmers have long preferred C for the following
reasons: (i) The feature of embedding assembly codes using in-line assembly. (ii) Readily
available modules in C compilers for the embedded system and library codes that can directly
port into the system-programmer codes.
Advantages of embedded c
It is a mid-level, with high-level features (such as support for functions and
modules), and low-level features (such as good access to hardware via pointers)
C , when used correctly is as safe and robust as any other high level language.
Good, well proven compilers are available for every embedded processor(8-bit to
32-bit or more)
Code optimisation
Code-optimization techniques include the following:
To minimize the code working set of a program, pack frequently executed code
together, while separating infrequently used code. In other words, do not put long
blocks of error handling code in line and load frequently called modules next to their
callers.
To minimize the data working set, concentrate frequently used data together and avoid
unnecessary references to pages. This can be accomplished by using the malloc()
subroutine instead of the calloc() subroutine, initializing data structures immediately
before they are used and being sure to free and disclaim allocated space when no
longer needed.
To minimize pinned storage, package pinned code in separate load modules. Make
sure it is necessary to use pinned code. Certain system structures (such as mbuf
pools) are pinned in memory; do not arbitrarily increase them.
Real-time techniques can be used, such as the plock() subroutine to pin code in
memory, and priorities pinned with the setpri() subroutine
Techniques
o
Constant propagation
Constant folding
Copy propagation
Loop Optimization
Function related
Branch optimization
Rearranges the program code to minimize branching logic and to combine physically
separate blocks of code.
Code motion
If variables used in a computation within a loop are not altered within the loop, the
calculation can be performed outside of the loop and the results used within the loop.
Common subexpression elimination
In common expressions, the same value is recalculated in a subsequent expression.
The duplicate expression can be eliminated by using the previous value.
Constant propagation
Constants used in an expression are combined, and new ones are generated. Some
implicit conversions between integers and floating-point types are done.
Dead code elimination
Eliminates code that cannot be reached or where the results are not subsequently
used.
Dead store elimination
Eliminates stores when the value stored is never referenced again. For example, if two
stores to the same location have no intervening load, the first store is unnecessary
and is removed.
Global register allocation
Allocates variables and expressions to available hardware registers using a "graph
coloring" algorithm.
Inlining
Replaces function calls with actual program code
Instruction scheduling
Reorders instructions to minimize execution time
Interprocedural analysis
Uncovers relationships across function calls, and eliminates loads, stores, and
computations that cannot be eliminated with more straightforward optimizations.
Invariant IF code floating (Unswitching)
Removes invariant branching code from loops to make more opportunity for other
optimizations.
Reassociation
Rearranges the sequence of calculations in an array subscript expression, producing
more candidates for common expression elimination.
Store motion
Moves store instructions out of loops.
Strength Reduction
Replaces less efficient instructions with more efficient ones. For example, in array
subscripting, an add instruction replaces a multiply instruction.
Value numbering
Involves constant propagation, expression elimination, and folding of several
instructions into a single instruction.
C PROGRAM ELEMENTS
Preprocessor Macros
Macro - A named collection of codes that is defined in a program as pre processor directive.
Differs from a function in the sense that once a macro is defined by a name, the compiler
puts the corresponding codes at the macro at every place where that macro-name appears.
Difference between Macro and Function
The codes for a function compiled once only
On calling that function, the processor has to save the context, and on return restore the
context.
Macros are used for short codes only. When a function call is used instead of macro, the
overheads (context saving and return) will take a time, Overheads that is the same order of
magnitude as the time, Texec for execution of short codes within a function.
Use the function when the Toverheads <<Texec and macro when Toverheads ~= or >
Texec.