EmbeddedRelated.com
Forums

Metrowerks HC12 Compiler

Started by bkohan_2000 January 28, 2005

I have noticed a weird thing. My startup code looks like this:

#pragma CODE_SEG FLSH_ROM
#pragma NO_FRAME
void a_reset(void)
{
unsigned int *int_ee_location;

// write to mapping registers once
asm {
clra
staa INITRG ; control regs at $0000-$03ff
nop
ldaa #0x21
staa INITRM ; RAM at $2000-$3FFF
nop
ldaa #0x09
staa INITEE ; interal EEPROM at $0800-$0fff
nop
}

asm { /* redundant, unless call ever made to reset() */
orcc #0xd0 disable interrupts, disable stop inst., disable
XIRQ
lds #0x03ffe ; initialize stack
};

The first instruction the compliler generates is a PSHD. The stack
pointer is not yet initialized. Where does this instruction come
from and how can I get rid of it?

Thanks,

B.K.



Just a guess:
Unsigned int *int_ee_location;
Is being allocated for you on the stack via the push rather than the less
efficient method of adding to stack for one variable location. To get rid of
this, use a global of the variable, or a static for *int_ee_location. This
of course means dedicating a piece of RAM for this one routine called once,
but you could always use a temp location that could be re-used at the sake
of maintainability.
Other things I have done in the past is my main function would have
parameters rather than void, and chew a few bytes of default/random stack
location.
-Mark W
_____

From: bkohan_2000 [mailto:]
Sent: Friday, January 28, 2005 11:49 AM
To:
Subject: [68HC12] Metrowerks HC12 Compiler

I have noticed a weird thing. My startup code looks like this:

#pragma CODE_SEG FLSH_ROM
#pragma NO_FRAME
void a_reset(void)
{
unsigned int *int_ee_location;

// write to mapping registers once
asm {
clra
staa INITRG ; control regs at $0000-$03ff
nop
ldaa #0x21
staa INITRM ; RAM at $2000-$3FFF
nop
ldaa #0x09
staa INITEE ; interal EEPROM at $0800-$0fff
nop
}

asm { /* redundant, unless call ever made to reset() */
orcc #0xd0 disable interrupts, disable stop inst., disable
XIRQ
lds #0x03ffe ; initialize stack
};

The first instruction the compliler generates is a PSHD. The stack
pointer is not yet initialized. Where does this instruction come
from and how can I get rid of it?

Thanks,

B.K.
_____

> Terms of Service.


The pshd comes from
> unsigned int *int_ee_location;
As the compiler allocates space on stack.
I do not see your full code below, but you can only use local vars if you
have a stack.

You may make it global or static local if you really need it that time.
Or set the stack pointer earlier (separate the functionality with local
variable into a separate function you call after the stack is initialized).

Erich

> -----Original Message-----
> From: bkohan_2000 [mailto:]
> Sent: Freitag, 28. Januar 2005 17:49
> To:
> Subject: [68HC12] Metrowerks HC12 Compiler >
>
> I have noticed a weird thing. My startup code looks like this:
>
> #pragma CODE_SEG FLSH_ROM
> #pragma NO_FRAME
> void a_reset(void)
> {
> unsigned int *int_ee_location;
>
> // write to mapping registers once
> asm {
> clra
> staa INITRG ; control regs at $0000-$03ff
> nop
> ldaa #0x21
> staa INITRM ; RAM at $2000-$3FFF
> nop
> ldaa #0x09
> staa INITEE ; interal EEPROM at $0800-$0fff
> nop
> }
>
> asm { /* redundant, unless call ever made to reset() */
> orcc #0xd0 disable interrupts, disable stop inst., disable
> XIRQ
> lds #0x03ffe ; initialize stack
> };
>
> The first instruction the compliler generates is a PSHD. The stack
> pointer is not yet initialized. Where does this instruction come
> from and how can I get rid of it?
>
> Thanks,
>
> B.K. >
> Yahoo! Groups Links