Re: [cc65] DA65 Selfmodification

From: Ullrich von Bassewitz <uz1musoftware.de>
Date: 2008-08-05 00:27:16
Hi!

On Mon, Aug 04, 2008 at 10:53:18PM +0200, Stefan wrote:
> I want to pass constants from a c programm to an assembler program.
> If i use #define statements, the constans are only defined while the
> preprocessor
> is active. So i had the idea to use enum instead, which i hopefully can
> import into the
> assembler code. Is this a good idea? I don't know how i can do it, else.

There is no way to do that automatically. Both, #defines and enums aren't
passed to the assembler file by name.

The other way (passing constants from assembler to C) is possible but weird.
To do that, define and export the constants in an assembler module:

        .export         _foo = 1
        .export         _bar = 2

Be sure to use underlines so that the symbols are accessible from C. In the C
source use something like

        extern char foo, bar;           /* Type doesn't matter */

Then make #defines from that:

        #define FOO ((int) &foo)
        #define BAR ((int) &bar)

One problem of this approach is that the #defines are not known at compile
time. Using real constants, the optimizer can usually do a better job.

I would suggest using an assembler file that contains an .enum declaration and
a small perl script that translates this into a C header.

Regards


        Uz


-- 
Ullrich von Bassewitz                                  uz@musoftware.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 Tue Aug 5 00:27:27 2008

This archive was generated by hypermail 2.1.8 : 2008-08-05 00:27:29 CEST