Hi,
I am developing code using MC9S08QD2 and codewarrior v6.2
For certain critical operations, I want my generated code to be optimized in size and execution speed.
Are there ready to use intrinsic functions defined in codewarrior to use assembly instructions like ROR - rotate right through carry, SEC - set carry, CLC - clear carry etc?
As I do not find these intrinsic function, I tried to put down macro definition for these purpose.
However it does not compile.
For ex.
unsigned char VarC;
#defined RotateRight(x) {__asm ROR x;}
void main (void)
{
:
:
RotateRight(VarC);
:
}
I get compiler error messages C18700 and C18701.
How to resolve it?
Same error messages go away if I first transfer operand to accumulator and work on accumulator.
Why so?
Kindly advice asap.
Thanks and regards,
Rakesh
Solved! Go to Solution.
The ROR instruction does only support DIR (meaning 8 bit addresses) and not EXT (meaning 16 bit addresses). Therefore either allocate VarC in a __DIRECT_SEG area (and tell the compiler), load, rotate in a register, rotate the register and store it back to VarC or load the address of VarC into H:X and use "ROR ,X".
I'm guessing that placing the variable into a __DIRECT_SEG segment is the best way to go as this is an optimization task.
E.g.
#pragma push#pragma DATA_SEG __SHORT_SEG MY_NEAR_DATA_SEG // must be mapped in the prmunsigned char VarC;#pragma pop
Check the ROR access details in the HCS08 reference manual and AN2093.pdf also contains samples using the direct page.
Daniel
The ROR instruction does only support DIR (meaning 8 bit addresses) and not EXT (meaning 16 bit addresses). Therefore either allocate VarC in a __DIRECT_SEG area (and tell the compiler), load, rotate in a register, rotate the register and store it back to VarC or load the address of VarC into H:X and use "ROR ,X".
I'm guessing that placing the variable into a __DIRECT_SEG segment is the best way to go as this is an optimization task.
E.g.
#pragma push#pragma DATA_SEG __SHORT_SEG MY_NEAR_DATA_SEG // must be mapped in the prmunsigned char VarC;#pragma pop
Check the ROR access details in the HCS08 reference manual and AN2093.pdf also contains samples using the direct page.
Daniel
Pls. ignore Solved Tag.
It was by mistake.
The issue is not solved.
Thanks and regards,
Rakesh
Hi,
VarC is declared in direct page area. In map file, its location is 0x87.
But still error comes.
Is #pragma push and #pragma pop necessary in definition?
what they do?
Kindly advice.
Thanks and regards,
Rakesh
> VarC is declared in direct page area. In map file, its location is 0x87.
Is is declared in a section with a __SHORT_SEG qualifier? The compiler does not read map files .
It's the other way round, if the variable is placed in a __SHORT_SEG section and that section is placed in the prm file into the first 256 bytes, then the map file will show an address < 256.
Here a simplistic snippet which works for me:
#pragma DATA_SEG __SHORT_SEG MY_ZEROPAGEunsigned char VarC;#define RotateRight(x) {__asm ROR x;}void main (void){ RotateRight(VarC);}
Also note the manuals in the help and help\pdf folders.
Daniel