Re: [cc65] Minor feature request? Inline assembly section?

From: Ullrich von Bassewitz <>
Date: 2009-08-15 11:03:42

On Fri, Aug 14, 2009 at 11:29:38PM -0500, Scott Hutter wrote:
> Rather than a function style, as in _asm("LDA #$00");.  what about blocks
> like:
> asm
> {
>     LDA #$00
>     TAX
>      STA $C000
> };
> Could this be done? (Maybe it already can and I just havent done it right or
> something.)

The correct question is not if it could be done, but if it should be done.
Currently I see no appealing reasons to implement asm {}. If you had good
reasons to suggest it, you forgot to mention them:-)

Here are some of the reasons why it is as it is:

Very old versions had this style of inline assembler (#asm if I remember
correctly). There are a few problems with this approach that let me do it the
other way: First, the C standard suggests to use

        asm ( character-string-literal );

(in ISO/IEC 9899:1999 (E), Annex J, Chapter 5, "Common Extensions").

Second, for quite a few things, an extended syntax is necessary. For example
when accessing variables declared in C (quite a common case). How do you
determine the name of a static variable in your asm {} block?

Third, an asm {} block has much more impact on the compiler itself. You will
need to enable the scanner to read tokens from this block. An asm("string")
statement is much less disruptive, because it needs support in the parser

Fourth, asm {} is a block, while asm() as implemented by cc65 is a primary
expression. This means you can use it in every place, where a primary
expression is expected, not only on statement level. As an example, the
isalpha() function may be implemented as a macro:

#define isalpha(c)  (__AX__ = (c),                  \
                    asm ("tay"),                    \
                    asm ("lda %v,y", _ctype),       \
                    asm ("and #%b", _CT_ALPHA),     \

Calling isalpha() will then add the assembler sequence to the code without
calling a subroutine.

Fifth, for portability and readability reasons, you don't want to add larger
pieces of assembler code to your C sources anyway. cc65 makes it very easy to
mix C and assembler modules, so for more than a few lines of assembler just
use the ca65 macro assembler that comes with cc65.



Ullrich von Bassewitz                        
To unsubscribe from the list send mail to with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Sat Aug 15 11:04:53 2009

This archive was generated by hypermail 2.1.8 : 2009-08-15 11:04:55 CEST