Re: [cc65] Macros in inline assembler

From: Andreas Rückert <a_rueckert1gmx.net>
Date: 2012-01-19 16:35:26
Hi!

-------- Original-Nachricht --------
> Datum: Thu, 19 Jan 2012 15:38:57 +0100
> Von: Ullrich von Bassewitz <uz@musoftware.de>
> An: cc65@musoftware.de
> Betreff: Re: [cc65] Macros in inline assembler

--<snip>--
 
> Just as a side note, because this is not your actual question: You should
> never generate the names of variables yourself by prepending an
> underscore.
> Please read this:
> 
>         http://www.cc65.org/snapshot-doc/cc65-9.html

I know. The problem was, that I couldn't find any examples with 
multiple arguments. That's why I tried the _data etc. Vars in
the code.

> Reading that chapter may also give some clues how your problem can be
> solved
> easily: Just use %w for the offset.

I did something else and just unrolled the loop by hand
========
        uint8 *datap = data;

        __asm__( "lda %v+3", datap);
        __asm__( "sta %v", W);
        __asm__( "lda %v+2", datap);
        __asm__( "sta %v+1", W);
        __asm__( "lda %v+1", datap);
        __asm__( "sta %v+2", W);
        __asm__( "lda %v", datap);
        __asm__( "sta %v+3", W);

        __asm__( "lda %v+19", datap);
        __asm__( "sta %v+4", W);
...
========
, which is also wrong as I see it, since the compiler might
rearrange the asm statements. So far ist does not, so the code 
works with all optimization on. It's just not very readable to
have so many asm-lines in the code, that's why I wanted the 
macros.

> Apart from that, above lines have several other errors: There's something
> named "q" in the second line which leads to an error.

Sorry, you're right. It came while inserting the code into the mail...

> And, using the token
> pasting operator (##) is wrong, because pasting two strings together gives
> an
> invalid token. Strings do not need an operator to have them concatenated.

That's what I thought. But when I had the macro argument in the
string, I always got complaints, that asm expectected a ')'.

> > , but this doesn't work so far, because the macro parameter is
> > not expanded and the linker complains about unresolved externals
> > _data and _W .
> 
> I would first fix the problems then try again. There are some problems
> with
> cc65 macros, but as far as I can say, your code doesn't trigger any of
> them.

So far I just accepted, that they don't work in asm Statements.

--<snip>--
 
> > Or is there a way to expand macro parameters within a string, so
> > I get something like sta _W+(3*4+3), which could be used as an
> > absolute address? (_W is a local var, but static as I understand it).
> 
> There's an old saying among us engineers: If nothing else helps, read the
> documentation:-) Hint: It does also describe how to access a static local
> variable from inline assembly.

I know. It just couldn't find an example in the docs...

Ciao,
Andreas

-- 
Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Thu Jan 19 16:35:35 2012

This archive was generated by hypermail 2.1.8 : 2012-01-19 16:35:38 CET