Go, assembly, go!

As mentioned in my post about the memory view:  I want to go down to the bits and bytes. Same applies to programming: I want to get down to the assembly instruction level, the heavy metal world :-).

Although it sounds a little bit weird in the age of object-oriented programming and C++, but sometimes I need to do ‘assembly level only’ programming on a 32bit controller too. CodeWarrior for MCU offers assembly only project creation for all the 8bit microprocessors, but for the 32bit including the ColdFire it assumes that the usual way is to use C and C++? Yes, it offers C and C++ and you can add assembly files. But how to do assembly only?

Luckily it is not hard to transform a normal high level language project into an assembly only one:

  1. Create a normal high level language project.
  2. Remove all the files you do not need.
  3. Add the heavy metal stuff.
  4. Have fun!

Ok, point 4 above will requires that I have to do really everything in assembly, but hey, that’s what I have asked for, right ;-)?

I’m illustrating the steps for the MCF51JM128. It works the same way for other controller types too.

  1. Start the new project wizard in CodeWarrior for MCU using the menu File > New > Bareboard project.
  2. Specify a project name, press Next.
  3. Select the device you want to use, e.g. MCF51JM128.
  4. At this time I’m going with the defaults, so I can press Finish.

This will create a project like the one shown below:

High Level Language Project

High Level Language Project

All the parts marked in yellow are things used for the high level language environment, in my case for ANSI C: header files with registers and derivative information, startup code to initialize global variables, exceptions table and the file with the main() application starting point.

The next step is to remove all these files, as I want to do everything in assembly. This gives me following structure:

Asm project with deleted high level language files

Project with removed high level language files

I keep the files for the debugger, I’m not ready for a blind flight (yet). I could remove the empty folders too. But in that case I need to remove the folder names from the compiler/assembler project settings too, as otherwise I will get warnings from the compiler/assembler complaining about folders not found. So I keep them, as I can put useful things into the folders later.

What is missing is the assembly source file where I can to do the heavy metal stuff. For this I select the Sources folder (or any place in the project where I want to create the new file), use the context menu New > Source File. This will prompt a dialog where I can enter the information for my new file:

Creating new assembly source file

Creating new assembly source file

As Template I can specified <None>, otherwise it will add some high language headers to the file which I could remove later. I use an extension supported by the assembler. Usually this .asm or .s, and I prefer .asm over .s.

Now all what I need is to enter at least a minimal skeleton: declaring the external symbol __startup as application starting point for the linker with the .global directive. .text starts my code section and .end marks the end of my file. Then added some very little code to get things rolled:

Minimal assembly code

Minimal assembly code

No I build my project and hopefully the assembler and linker are happy. Then I download to the target and hopefully I have made my first baby step in that little project.

Of course I will need to add all the other useful stuff: vector table, processor and register initialization, and finally the putting in all my blood, sweat and assembly.
But this is what I aimed for, right?

Happy assembling 🙂

1 thought on “Go, assembly, go!

  1. Pingback: MCU10.2 is here! Or: 4 t-shirts in 13 weeks… | MCU on Eclipse

What do you think?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.