Programming for
ARM Cortex M0 processors
Program Control ( If-then-else)
● One the most important functions of the instruction set is to
handle conditional branches.
● For example, if we need to carry out the task:
Program Control ( If-then-else)
● Assume the R0 is used as “counter” variable, the above
operation can be implemented as:
Program Control (Loop)
● Assume “Total” is R0, “i” is R1, the program can be
implemented as:
Program Control (Loop)
● Assume the R0 is used as “counter” variable, the above
operation can be implemented as:
●
Program Control (Loop)
● Assume “Total” is R0, “i” is R1, the program can be
implemented as:
Data Accesses
For example, if we need to calculate the sum of an integer array
“DataIn” with 10 elements (32 bit each), and put the result in
another variable called “Sum” (also 32 bit),
Data Accesses
For example, if we need to calculate the sum of an integer array
“DataIn” with 10 elements (32 bit each), and put the result in
another variable called “Sum” (also 32 bit),
Using Memory Access Instruction
In order to demonstrate how different memory access instructions
can be used, several simple examples of memory copying functions
are shown in this section.
The most basic approach is copy the data byte by byte, thus
allowing any number of bytes to be copied and do not have
memory alignment issue.
Using Memory Access Instruction
The most basic approach is copy the data byte by byte, thus
allowing any number of bytes to be copied and do not have
memory alignment issue.
Using Memory Access Instruction
The program code uses a number of add and subtract instructions in the
loop, which reduce the performance.
We could modify the code to reduce the program size using a register offset
address mode:
Using Memory Access Instruction
For copying large amount of data, we can use multiple load and store
instructions to increase the performance.
Since the load store multiple instructions can only be used with word
accesses, we usually use them in memory copying functions only when we
know that the size of memory being copied is large and the data are word
aligned.
Memory Access Instruction (using SP)
Another type of useful memory access instructions is the load and store
instructions with stack pointer (SP)-related addressing.
This is commonly used for local variables, as C compilers often store simple
local variables on the stack memory.
For example, let’s say we need to create two local variables in a function
called “function1,” the code can be written as: