Professional Documents
Culture Documents
IV ECE – I Sem
(PE-IV)
r. G. Prasad Acharya, Ph.D. (JNTUH)
D
Associate Professor and Associate HoD, Dept. of ECE.,
Program Coordinator, SNIST-Microchip Academy
UNIT-V: ARM Programming
Avoid using char and short as local variable types, even if you
are manipulating an 8- or 16-bit value. The
Function Argument Types
• converting local variables from types char or
short to type int increases performance and
reduces code size
• same holds for function arguments also.
Should the compiler assume that these 32-bit values are in the range of
a short type, that is, −32,768 to +32,767? Or
should the compiler force values to be in this range by sign-extending the lowest 16 bits to
fill the 32-bit register?
The armcc compiler casts the return value to a short type, but does not cast the
input values.
■ A subtract to decrement
the loop counter, which
also sets the condition
code flags on
the result
■ A conditional branch
instruction
Loops Using a Variable Number of Iterations
In this case the second value of *step is different from the first and has the value *timer1.
The compiler evaluates state->step twice in case state->step and timers-
>timer1 are at the same memory address
When you call another function, this function may alter the state
of memory and so change the values of any expressions involving
memory reads. The compiler will evaluate the expressions again.
The fix is easy: Create a new local variable to hold the value
of state->step so the compiler only performs a single load.
Another pitfall is to take the address of a local variable. Once you do this, the
variable is referenced by a pointer and so aliasing can occur with other pointers. The
compiler is likely to keep reading the variable from the stack in case aliasing occurs.
Structure