Re: [cc65] Package locations

Date view Thread view Subject view

From: Mike McCarty (jmccarty_at_ssd.usa.alcatel.com)
Date: 2001-10-12 00:08:01


On Thu, 11 Oct 2001, Ullrich von Bassewitz wrote:

> 
> Hi!
> 
> On Thu, Oct 11, 2001 at 11:34:02PM +0200, groepaz wrote:
> > UvB> Because the assembler will only do that for backward branches.
> >
> > uhhh?!? _WHY_ ?! even my really-crap-n-featureless 6502 assembler
> > could do this with no problems ;=)
> 
> The long branches are an addon done with macros. The main problem in
> implementing them natively is that the generated code is relocatable. This
> means that not all expressions evaluate to constants as with simpler
> assemblers. This means that you cannot simply go back and change anything,
> because that in turn may change expressions all over the code. That does not
> mean that it cannot be done, it does just mean that it is a lot more work
> because of the relocation.

Other reasons it is not so simple are:

    one must create anonomous labels for targets of jumps which
        have no associated label

    the replacement of a "long" jump with a "short" jump may cause
        other jumps which were out of range to be reachable by means
        of a short jump, in which case one has to repeat the
        optimization pass

    computed values which are differences between label values have
        to be recomputed, so range checks in the code may indicate
        that something may not fit, but after suitable shortening, they
        do... or not... this complicates error reporting

As an example of the last, suppose we have code which does this

    ldaa #Fred-Barney

This means that Fred-Barney must fit into 8 bits, right? But suppose it
doesn't. But it might, after optimization. OTOH, Fred-Barney might fit
before optimization, but not after, because Barney moved to a lower
address. So any passes which emit error messages have to come after all
optimization has been done.

If one is simply trying to optimize for speed, regardless of space, the
the best place to do this is in the linker, not the assembler. The
assembler can tag places which are subject to optimization, and the
linker can substitute short forms when the target is in range. Since
the short form fits in the same space, there is no problem, one simply
fills the extra byte(s) with NOPs. This works across compilation units,
whereas the assembler can only work on one at a time.

Mike
-- 
char *p="char *p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
This message made from 100% recycled bits.
I can explain it for you, but I can't understand it for you.
I don't speak for Alcatel      <- They make me say that.

----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo_at_musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.


Date view Thread view Subject view

This archive was generated by hypermail 2.1.3 : 2001-12-14 22:05:42 CET