I am using a CORTEX-M4 micro controller board. Could you send me an Assembly example for programming the board?
As Alban says, examples are going to be different from one board to another and from one vendor to another. If you share some more details about the specific board which you are using and some idea of what you are trying to do with it, I'm sure will be able to help.
Best wishes
Chris
As I am not using Windows, I've chosen to use GCC and open-source tools for my development.
The assembler-syntax for GCC might differ slightly from ARM's assembler, but in general, the differences are not too big.
So if you happen to use GCC, I'll be happy to give you code-examples for the Cortex-M4.
As I am not using a Freescale chip (yet), I'll be writing my example more or less generic (I mainly use LPC microcontrollers these days).
One thing you will want to do, if you use the GCC toolchain (the assembler is called GAS), is that you want to place this line before any code:
.syntax unified
That will make the assembler automatically create IT-instructions when necessary. This will help you focus more on the code.
-But you should know a few things...
All Cortex-M0/Cortex-M0+ code, which is not hardware-specific, can be compiled/assembled unmodified for Cortex-M3 or Cortex-M4.
All Cortex-M3 code, which is not hardware-specific, can be compiled/assembled unmodified for Cortex-M4.
-When I say "hardware-specific", I mean that it accesses hardware registers that are special to the microcontroller the code was written for.
Example of hardware-specific code: Code that writes a value on a GPIO-port.
Example of non hardware-specfic code: A subroutine that performs a heavy calculation and returns the result.
Hi, all. Thanks for your reply. I feel doomed. The Freescale technical team keeps pointing me to a Kinetis Reference Manual as if all the Kinetis microcontrollers support the same instruction set. I asked them explicitly for assembly code as well but they told me that only C/C++ samples are available and this closed the discussion.
I plan to teach Assembly using the board. Towards this end, I need to write Assembly programs myself.
Do you have any suggestion?
Hello, Jensbauer. Thank you so much for your reply. This comment is helpful as well. Unfortunately I run out of the "helpful" options.
No problem; it's a pleasure to be able to help an assembly-programmer getting started.
You can look forward to programming the Cortex-M4, there are many nice features to explore and benefit from.
Many instructions only use a single clock-cycle, where they use two or more on a Cortex-M3.
That means if you use a large block (or loop), your code might become 3 times as fast per clock-cycle.
In addition to the above, the Cortex-M4 also have "DSP instructions", which can also save a lot of clock cycles, compared to when you had to use a different approach on the Cortex-M3.
The Freescale implementations have some extra hardware features, which you can benefit from using (especially the BME, Bit Manipulation Engine).
I see Jens has been keeping you supplied with excellent advice about assembly code!
The Freescale technical team are actually doing the right thing, really, as one of the selling points of the Cortex-M microcontrollers is that they are capable of being programmed entirely in C. You can even write boot code and interrupt handlers all in C because of the way in which the hardware handles a lot of the low-level functionality automatically. This does make things much easier for many developers who don't want to bother with assembly code!
Two other things help here. First, most compilers support a wide range of intrinsic functions, like __svc, which allow assembly-level functions to be accessed direct from C.
Second, most board vendors make available a CMSIS-compliant middleware library which provides a standard C API to hardware-level operations.
So, there is (deliberately!) very little actual need to use assembly language when developing for a Cortex-M microcontroller.
Of course, there are still times when you might want to do so and Jens has given you some excellent pointers for that.
Hope this helps.
In order to give you an idea of what Cortex-M4 code could look like, I'm attaching one of my own assembly sources.
The code will not be very useful as it is; you wouldn't be able to run it on your microcontroller, but you would be able to learn a few different instructions and a few assembler-directives from looking at it.
I'm attaching a file instead of posting it, because the tabulations get destroyed, thus making it almost unreadable.
(Note: The file is written for tab-size 4)
Assembler directives start with a dot, for instance ".include" is a directive.
I've chosen to make my macros uppercase. For instance "QFUNCTION" is neither a directive, nor an assembler-instruction.
In the example, you'll see how I use one of GCC's nice features, recursive macros, in order to 'draw' characters in the source-code.
This makes it very easy to see what the characters look like.
To learn the instruction set, I recommend going to the ARM Information Center and click...
"Cortex-M series processors", then ...
"Cortex-M4", then ...
"Revision: r0p1", then ...
"Cortex-M4 Devices Generic User Guide", then ...
"The Cortex-M4 Instruction Set".
... and you're good to go.