Coldfire: Simple Assembly in Code Warrior

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Coldfire: Simple Assembly in Code Warrior

3,529 Views
Nathan
Contributor I
Hello, I'm a new user of Code Warrior and I am having difficulty getting started. I am an instructor at a university, and we are starting a lab that uses the Coldfire processor in a development board in our Computer Architechture course. I want to have the students develop code that utilizes specific things on the processors, like the Random Number Generator, or the Ethernet Port directly so they get a feel for the inner workings of the processor. Obviously, assembly is a much better tool for learning the guts of a system than C. In previous classes we used the MC68332 chip and the students wrote thier code in a text editor, then used a dBug 'OS' on the boards for debugging. This took a lot of time, and was not a good solution. The Code Warrior IDE I think will help alleviate a lot of the simple time wasted finding coding errors, and let them focus more on getting inside the chip itself. Here's my problem. I can't see how to create a simple project that only takes assembly code, compiles it, and allows you to debug. I'm sure it's possible, but after going through the online tutorial, reading as much of the Help as I could stand, I don't see how to do it.

I have tried writing a
asm
{
code....


}

inside a main c page, but it didn't compile are run. And when I tried to debug it, it gave me all kinds of garbage in the Stack, wouldn't let me track variables, or even set breakpoints. Any suggestions would be great. One more note, most of my students are not C programmers, they are EE majors, and have more experience working with hardware than software. That's another reason I prefer assembly. I can get them coding in assembly much quicker than C or CPP.

Thanks,

Nathan

Message Edited by CrasyCat on 2007-04-13 01:32 PM

Labels (1)
0 Kudos
6 Replies

643 Views
CrasyCat
Specialist III
Hello
 
  Which CPU are you targeting (HC08, HC12, Coldfire, ...)?
  For some CPU like Coldfire we do not provide sample project or stationery for assembly only application.
 
  If you are using Coldfire, I would recommend you to start with an ANSI C project and add assembly 
  source files in there.
  Otherwise you will have to create your project from scratch. But this may be rather complicated and
  I do not recommend that.
 
CrasyCat
0 Kudos

643 Views
Nathan
Contributor I
Thanks for the reply. I'm targeting the Coldfire processor. We purchased some development boards based on the CF5235. I guess I'll have to learn as much as I can over the next few weeks to teach to the students. Do you have any suggestions as to where I can read how to include assembly commands into C? Especially, I want to be able to write to registers directly, and access specific memory locations. Also, how do you access the specific modules on the chip in C? For instance, how do you target math operations to the Multiply and Accumulate from C? If you can just give me a clue on where to search in the documentation, I would appreciate it.

Nathan
0 Kudos

643 Views
CrasyCat
Specialist III
Hello
Basically once you have created your ANSI C project, you have 3 choices:
  1- Implement the rest of the application in macro assembler.
  2- Implement the rest of the application in C using inline adssembler
  3- Implement your application in ANSI C.
 
If you decide to go with 1, just add your assembly source file to the application. In that case I would remove the file main.c from eth project and define an exported label called _main somewhere in my assembly source file.
The standard startup code is calling that function as to start theapplication.
Alternatively you can decide to use your own entyr point for the application and get rid of the default startup code. In that case just specify your entry point in the ColdFire Linker.
For more information on macro assembler language, please refer to following manual.
   {Install}\Help\PDF\CF_Assem_Ref.pdf.
 
If you decide to go with 2, I would recommend you to look at the manual
   {Install}\Help\PDF\ColdFire_Build_Tools_Reference.pdf
Chapter "Inline Assembly" around page 187 explains the inline assembly syntax.
 
If you decide to go with 3, when you create a project from a stationery, we are providing header files, containing  register definition.
So to access a register directly through it names :smileyhappy:
 
Finally if you want to use the Core MAC instructionsm you have to encode it in inlune assembler.
ANSI C will not use these instructions at all (as far as I know).
 
I hope this helps a bit :smileysurprised:
CrasyCat
0 Kudos

643 Views
Nathan
Contributor I
Thanks for the help. I'll have to do some research on the options to pick one.

Nathan
0 Kudos

643 Views
Kerrie
Contributor I

We do something akin to what your looking for...

the main.c file looks like this:

 

void main(void){    asm_startmeup();}

 Then we have an *.asm file, that has the following define at the top:

 

  .global _asm_startmeup  .global _ATODINT  .include "mcf51je256.inc" ;Codewarrior Style  .text .function "_asm_startmeup",_asm_startmeup,_asm_startmeup_end-_asm_startmeup_asm_startmeup:        sei   ;Disable Interrupts lea RAMSTACK,A7 ;setup the stack pointer movea.l #0,A6  ;setup A6 dummy stack frame link A6,#0......_asm_startmeup_end:

 when your passing functions back and forth between assembly and C, it is important to have the assembly names include an _ and the calls in C don't

 

Also in the above example you could at the following to the exceptions.c file

 

extern void ATODINT(void);...__declspec(weak) vectorTableEntryType vector_71  @Vadc = ATODINT;

 

That's just my newbie way of doing things but it appears to work

0 Kudos

643 Views
BlackNight
NXP Employee
NXP Employee

Hello,

another way is to transform a normal C project created by the wizard into an assembly only project:

Here are the steps for eclipse based CodeWarrior for MCU10, but in principle apply as well for the non-eclipse version:

http://mcuoneclipse.wordpress.com/2012/02/05/go-assembly-go

 

BK

0 Kudos