test test

Bug in Codewarrior for HC12?

Discussion created by test test on Apr 19, 2006
Latest reply on Apr 22, 2006 by Mark Hotchkiss
Hi!

I'm currently adapting a small static "multi-tasking OS" for the HC12 written in C. It was created by other students of my university with ICC12. My job is to make it work with Codewarrior (so it can be compiled there with chc12.exe (I'm currently using V-5.0.24 Build 4047) and VisualStudio can be used as editor). It is working nearly perfect - except of one little thing.
There are four modes: Round-Robin and Lottery, each with and without priorities.
In Round-Robin mode it works perfectly. In Lottery, there is a random number generator as assembler code in the C code. It creates a number from 0 to (the number of threads - 1). After that, a for-slope decrements that value to 0. Every time it decrements that value by 1, it also set the pointer from the current thread to the next one (thread number + 1; if the next thread number doesn't exists -> thread number = 0) so the next thread is chosen randomly.

---- piece of C code ----

asm(" LDAA random\n ROLA\n ROLA\n ROLA\n EORA random\n COMA\n ROLA\n LDAA random\n ROLA\n STAA random"); /* Generate random number */

jumps=random%NUMBER_OF_THREADS;

for(;jumps>0;jumps--){ /* Chose next thread randomly */
ThreadRunPtr=ThreadRunPtr->Next;
}

---- piece of C code ----

But that doesn't work! One thread is chosen at the very beginning which runs all the time.
Now the funny thing: With a "NOP" for example as first instruction within the for-slope it works perfectly!
The disassembled programs without and with that NOP are looking pretty similar, at least at the beginning. But there is also a significant difference: In first case there is a "bset" and in second case at the same address there is a "call".

Could that be the reason for the problem? A bug in Codewarrior?

But I don't know how I should update. I can't find that page with Codewarrior for HC12 and the link to the 32k student license on www.metrowerks.com anymore. And the updater doesn't show suitable updates as far I understand that (and sometimes it doesn't work although I really don't have any problems with my internet connection).

Because I don't know if you prefere the complete C code or the disassembled program, please tell me if and what you need to tell me more.

TIA!

Outcomes