From: cbarn24050 on
On Apr 23, 10:03 pm, David Brown
<david.br...(a)hesbynett.removethisbit.no> wrote:
> cbarn24...(a)aol.com wrote:
> > On Apr 23, 7:27�pm, Walter Banks <wal...(a)bytecraft.com> wrote:
> >> Stefan Reuther wrote:
> >>>> register_sp SP;
> >>>> SP = int_value;
> >>> What you're doing here is writing assembly with C syntax. It relies upon
> >>> a heavily non-standard language extension, and makes assumptions about
> >>> how the compiler behaves (you don't want the compiler to use the stack
> >>> before your SP assignment, do you?). So instead of writing assembly in
> >>> C, I prefer using the real thing.
>
> > Yes, thats what he always does! He can then claim his compiler can
> > beat assembler for speed,code size ect. To Walter if it looks Cish,
> > ends in a semicolon and his compiler can change it into machine code
> > then its C.
>
> >> I actually agree with you it is very low level C. The purpose of ISO/IEC
> >> 18037 was to define the low level syntax. Most start up code is very processor
> >> family specific. �Writting start up code in C makes good use of C's
> >> optimization like the branch/jump to main.
>
> > Whats to optimise? Why bother optimising a one time instruction?
>
> > Sometimes I think you'll say anything to sell a compiler.
>
> Why would you bother optimising a traditional call to main into a jump?
>   On some targets (in particular, several that Bytecraft target), the
> saved stack space is significant - and even the couple of saved flash
> bytes is worth doing (given the negligible cost of the compiler's effort).

If it is on your project you are allready are allready up a certain
creek without a paddle. In any event you wouldnt use a "traditional"
ie a C type call to main from startup so stack saveing would be
minimal.

>
> There is also the question of why would one bother to write code that
> you know is less than optimal, if it is just as easy to write better code?- Hide quoted text -
>
> - Show quoted text -

From: Walter Banks on


> Why would you bother optimising a traditional call to main into a jump?
>

When C runs on embedded systems processors that are not hosted main should never return.

w..


From: cbarn24050 on
On Apr 23, 9:38�pm, Walter Banks <wal...(a)bytecraft.com> wrote:
> cbarn24...(a)aol.com wrote:
> > Whats to optimise? Why bother optimising a one time instruction?
>
> > Sometimes I think you'll say anything to sell a compiler.
>
> :) � The serious answer is some initialization on some processors
> requires memory management that is easier for the compiler to
> do.

Any hope of an example that demonstates your point?


>
> I think my comments on startup code would apply to quite a
> few embedded compilers.
>
> w..

From: CBFalconer on
Walter Banks wrote:
>
.... snip ...
>
> In our case the first C compiler was written for the C6805
> and that was based on a 6805 mistral compiler we had written
> a few years earlier. Our initial startup code was written
> in C on a compiler that would support it.
>
> register_sp SP;
>
> SP = int_value;

In other words you seized a user available identifier, register_sp,
and then recognized that in the code to accept an int_value and
initialize the stack pointer. This is not C, but an extension.
The only thing wrong with that is that it is not marked as an
extension. If the mechanism is also used to read the SP the above
declaration should mark it as volatile. I think it would be better
to use a name reserved for the implementation, such as
__register_sp.

I am not objecting to extensions. However I believe they should
minimize any effects on standard C.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.


** Posted from http://www.teranews.com **
From: Bill Leary on
"Walter Banks" <walter(a)bytecraft.com> wrote in message
news:480FAC36.E382E22B(a)bytecraft.com...
>> Why would you bother optimising a traditional call to main into a jump?
>
> When C runs on embedded systems processors that are not hosted main should
> never return.

Usually, no. But it's a good idea to make sure the system does something
reasonable if it does.

I said before that I wrote init routines to "jump" to _main. And I have,
when it had to be that way. But whenever I've had a choice, I've actually
pushed the address of my restart routine onto the stack first then done the
jump. If _main DOES return, the machine reboots. In one case I raised the
error flag on the system and set a code in the status LEDs when _main
returned.

- Bill