<article>
<title>cc65 Users Guide
<author>Ullrich von Bassewitz, <htmlurl url="mailto:uz@cc65.org" name="uz@cc65.org">
-<date>03.09.2000, 02.10.2001
+<date>03.09.2000, 02.10.2001, 2005-8-1
<abstract>
cc65 is a C compiler for 6502 targets. It supports several 6502 based home
and removing these limitations would mean a rewrite of many more parts of
the compiler.
-There is a separate document named "library.txt" that covers the library
-available for the compiler. If you know C and are interested in doing
-actual programming, the library documentation is probably of much more use
-than this document.
+There are separate documents named <url url="library.html"> and <url
+url="funcref.html"> that cover the library that is available for the compiler.
+If you know C, and are interested in doing actual programming, the library
+documentation is probably of much more use than this document.
If you need some hints for getting the best code out of the compiler, you
-may have a look at "coding.txt" which covers some code generation issues.
+may have a look at <url url="coding.html"> which covers some code generation
+issues.
<sect>Usage<p>
-The compiler translates C files into files containing assembler code that
+The compiler translates C files into files containing assembly code that
may be translated by the ca65 macroassembler (for more information about
-the assembler, have a look at ca65.txt).
+the assembler, have a look at <url url="ca65.html">).
<sect1>Command line option overview<p>
---------------------------------------------------------------------------
Usage: cc65 [options] file
Short options:
- -A Strict ANSI mode
-Cl Make local variables static
-Dsym[=defn] Define a symbol
-I dir Set an include directory search path
-h Help (this text)
-j Default characters are signed
-o name Name the output file
+ -r Enable register variables
-t sys Set the target system
-v Increase verbosity
Long options:
--add-source Include source as comment
- --ansi Strict ANSI mode
--bss-name seg Set the name of the BSS segment
--check-stack Generate stack overflow checks
--code-name seg Set the name of the CODE segment
--data-name seg Set the name of the DATA segment
--debug Debug mode
--debug-info Add debug info to object file
+ --forget-inc-paths Forget include search paths
--help Help (this text)
--include-dir dir Set an include directory search path
+ --register-space b Set space available for register variables
+ --register-vars Enable register variables
--rodata-name seg Set the name of the RODATA segment
--signed-chars Default characters are signed
+ --standard std Language standard (c89, c99, cc65)
--static-locals Make local variables static
--target sys Set the target system
--verbose Increase verbosity
--version Print the compiler version number
+ --writable-strings Make string literals writable
---------------------------------------------------------------------------
</verb></tscreen>
<descrip>
- <label id="option-A">
- <tag><tt>-A, --ansi</tt></tag>
-
- This option disables any compiler exensions. Have a look at section 5
- for a discussion of compiler extensions. In addition, the macro
- <tt/__STRICT_ANSI__/ is defined, when using one of these options.
-
-
<tag><tt>--bss-name seg</tt></tag>
Set the name of the bss segment.
<tag><tt>--check-stack</tt></tag>
Tells the compiler to generate code that checks for stack overflows. See
- <tt><ref id="pragma-checkstack" name="#pragma checkstack"></tt> for an
+ <tt><ref id="pragma-checkstack" name="#pragma checkstack"></tt> for an
explanation of this feature.
Set the name of the code segment.
+ <label id="option-codesize">
<tag><tt>--codesize x</tt></tag>
- This options allows finer control about speed vs. size decisions in the
- code generation phase. It gives the allowed size increase factor (in
- percent). The default is 100 when not using <tt/-Oi/ and 200 when using
- <tt/-Oi/ (<tt/-Oi/ is the same as <tt/--codesize 200/).
+ This options allows finer control about speed vs. size decisions in the code
+ generation and optimization phases. It gives the allowed size increase
+ factor (in percent). The default is 100 when not using <tt/-Oi/ and 200 when
+ using <tt/-Oi/ (<tt/-Oi/ is the same as <tt/--codesize 200/).
<tag><tt>--cpu CPU</tt></tag>
is defined to the value "1".
+ <tag><tt>--forget-inc-paths</tt></tag>
+
+ Forget the builtin include paths. This is most useful when building
+ customized C or runtime libraries, in which case the standard header
+ files should be ignored.
+
+
<tag><tt>-g, --debug-info</tt></tag>
This will cause the compiler to insert a <tt/.DEBUGINFO/ command into the
Print the short option summary shown above.
+ <tag><tt>-o name</tt></tag>
+
+ Specify the name of the output file. If you don't specify a name, the
+ name of the C input file is used, with the extension replaced by ".s".
+
+
+ <tag><tt>-r, --register-vars</tt></tag>
+
+ <tt/-r/ will make the compiler honor the <tt/register/ keyword. Local
+ variables may be placed in registers (which are actually zero page
+ locations). There is some overhead involved with register variables, since
+ the old contents of the registers must be saved and restored. Since register
+ variables are of limited use without the optimizer, there is also a combined
+ switch: <tt/-Or/ will enable both, the optimizer and register variables.
+
+ For more information about register variables see <ref id="regvars"
+ name="register variables">.
+
+ The compiler setting can also be changed within the source file by using
+ <tt><ref id="pragma-regvars" name="#pragma regvars"></tt>.
+
+
+ <tag><tt>--register-space</tt></tag>
+
+ This option takes a numeric parameter and is used to specify, how much
+ zero page register space is available. Please note that just giving this
+ option will not increase or decrease by itself, it will just tell the
+ compiler about the available space. You will have to allocate that space
+ yourself using an assembler module with the necessary allocations, and a
+ linker configuration that matches the assembler module. The default value
+ for this option is 6 (bytes).
+
+ If you don't know what all this means, please don't use this option.
+
+
<tag><tt>--rodata-name seg</tt></tag>
Set the name of the rodata segment (the segment used for readonly data).
6502 has no provisions for sign extending characters (which is needed on
almost any load operation), this will make the code larger and slower. A
better way is to declare characters explicitly as "signed" if needed. You
- can also use <tt><ref id="pragma-signedchars" name="#pragma
- signedchars"></tt> for better control of this option.
+ can also use <tt><ref id="pragma-signedchars"
+ name="#pragma signedchars"></tt> for better control of this option.
+
+
+ <label id="option--standard">
+ <tag><tt>--standard std</tt></tag>
+
+ This option allows to set the language standard supported. The argument is
+ one of
+ <itemize>
+ <item>c89
+ <item>c99
+ <item>cc65
+ </itemize>
<tag><tt>-t target, --target target</tt></tag>
<itemize>
<item>none
<item>apple2
+ <item>apple2enh
<item>atari
<item>atmos
<item>c16 (works also for the c116 with memory up to 32K)
<item>c64
<item>c128
- <item>plus4
<item>cbm510 (CBM-II series with 40 column video)
<item>cbm610 (all CBM-II II computers with 80 column video)
- <item>pet (all CBM PET systems except the 2001)
<item>geos
+ <item>lunix
+ <item>lynx
+ <item>nes
+ <item>pet (all CBM PET systems except the 2001)
+ <item>plus4
+ <item>supervision
+ <item>vic20
</itemize>
<tag><tt>-v, --verbose</tt></tag>
or warnings are encountered.
+ <tag><tt>--writable-strings</tt></tag>
+
+ Make string literals writable by placing them into the data segment instead
+ of the rodata segment.
+
+
<tag><tt>-Cl, --static-locals</tt></tag>
Use static storage for local variables instead of storage on the stack.
}
</verb></tscreen>
- the variable a will always have the value 1 when entering the function
- and using <tt/-Cl/, while in
+ the variable <tt/a/ will always have the value <tt/1/ when entering the
+ function and using <tt/-Cl/, while in
<tscreen><verb>
void f (void)
}
</verb></tscreen>
- the variable a will have the value 1 only the first time, the function
- is entered, and will keep the old value from one call of the function to
- the next.
+ the variable <tt/a/ will have the value <tt/1/ only the first time that the
+ function is entered, and will keep the old value from one call of the
+ function to the next.
- You may also use <tt><ref id="pragma-staticlocals" name="#pragma
- staticlocals"></tt> to change this setting in your sources.
+ You may also use <tt><ref id="pragma-staticlocals"
+ name="#pragma staticlocals"></tt> to change this setting in your
+ sources.
<tag><tt>-I dir, --include-dir dir</tt></tag>
search list.
- <tag><tt>-o name</tt></tag>
-
- Specify the name of the output file. If you don't specify a name, the
- name of the C input file is used, with the extension replaced by ".s".
-
-
+ <label id="option-O">
<tag><tt>-O, -Oi, -Or, -Os</tt></tag>
Enable an optimizer run over the produced code.
runtime functions would have been called, even if the generated code is
larger. This will not only remove the overhead for a function call, but will
make the code visible for the optimizer. <tt/-Oi/ is an alias for
- <tt/--codesize 200/.
+ <tt/--codesize 200/.
<tt/-Or/ will make the compiler honor the <tt/register/ keyword. Local
variables may be placed in registers (which are actually zero page
<tt/-Os/ will actually break things.
<p>
<item>The inlined string and memory functions will not handle strings or
- memory areas larger than 255 bytes. Similar, the inlined <tt/is..()/
- functions will not work with values outside char range.
+ memory areas larger than 255 bytes. Similarly, the inlined <tt/is..()/
+ functions will not work with values outside the char. range (such as
+ <tt/EOF/).
<p>
</itemize>
<p>
version.
+ <label id="option-W">
<tag><tt>-W</tt></tag>
This option will suppress any warnings generated by the compiler. Since
<itemize>
-<item> The compiler allows single line comments that start with //. This
- feature is disabled in strict ANSI mode.
- <p>
<item> The compiler allows unnamed parameters in parameter lists. The
compiler will not issue warnings about unused parameters that don't
- have a name. This feature is disabled in strict ANSI mode.
+ have a name. This feature can be disabled with the <tt><ref
+ id="option--standard" name="--standard"></tt> command line option.
<p>
<item> The compiler has some additional keywords:
<p>
<item><tt/__attribute__/
</itemize>
<p>
- The keywords without the underlines are disabled in strict ANSI mode.
+ The keywords without the underlines can be disabled with the
+ <tt><ref id="option--standard" name="--standard"></tt> command line
+ option.
<p>
<item> The datatypes "float" and "double" are not available.
<p>
<item> The compiler does not support bit fields.
<p>
-<item> Because of the "wrong" order of the parameters on the stack, there is
- an additional macro needed to access parameters in a variable
- parameter list in a C function.
- <p>
-<item> Functions may not return structs (or unions), and structs may not be
- passed as parameters by value. However, struct assignment *is*
+<item> C Functions may not return structs (or unions), and structs may not
+ be passed as parameters by value. However, struct assignment *is*
possible.
<p>
<item> Part of the C library is available only with fastcall calling
- conventions (see below). This means, that you may not mix pointers to
- those functions with pointers to user written functions.
+ conventions (see below). It means that you must not mix pointers to
+ those functions with pointers to user-written, not-fastcall functions.
<p>
</itemize>
-There may be some more minor differences, I'm currently not aware off. The
+There may be some more minor differences I'm currently not aware of. The
biggest problem is the missing float data type. With this limitation in
mind, you should be able to write fairly portable code.
<itemize>
-<item> The compiler allows // comments (like in C++ and in the proposed C9x
- standard). This feature is disabled by <tt><ref id="option-A"
- name="-A"></tt>.
- <p>
-
<item> The compiler allows to insert assembler statements into the output
file. The syntax is
<ref id="inline-asm" name="see there">.
<p>
-<item> There is a special calling convention named "fastcall". This calling
- convention is currently only usable for functions written in
- assembler. The syntax for a function declaration using fastcall is
+<item> There is a special calling convention named "fastcall".
+ The syntax for a function declaration using fastcall is
<tscreen><verb>
<return type> fastcall <function name> (<parameter list>)
<tscreen><verb>
void __fastcall__ f (unsigned char c)
</verb></tscreen>
- The first form of the fastcall keyword is in the user namespace and is
- therefore disabled in strict ANSI mode.
+ The first form of the fastcall keyword is in the user namespace and can
+ therefore be disabled with the <tt><ref id="option--standard"
+ name="--standard"></tt> command line option.
For functions declared as <tt/fastcall/, the rightmost parameter is not
pushed on the stack but left in the primary register when the function
sequences of assembler code. For example, the macro
<tscreen><verb>
- #define hi(x) (__AX__=(x),asm("\ttxa\n\tldx\t#$00",__AX__)
+ #define hi(x) \
+ (__AX__ = (x), \
+ asm ("txa"), \
+ asm ("ldx #$00"), \
+ __AX__)
</verb></tscreen>
will give the high byte of any unsigned value.
<tscreen><verb>
_GCmd:
- .byte 3
- .word $2000
- .word $3000
+ .byte 3
+ .word $2000
+ .word $3000
</verb></tscreen>
Since the variable is of type <tt/void/ you may not use it as is.
However, taking the address of the variable results in a <tt/void*/
which may be passed to any function expecting a pointer.
- See the <htmlurl url="geos.html" name="GEOS library"> for examples on
- how to use this feature.
+ See the <url url="geos.html" name="GEOS library document"> for examples
+ on how to use this feature.
<p>
+<item> cc65 implements flexible array struct members as defined in the C99 ISO
+ standard. As an extension, these fields may be initialized. There are
+ several exceptions, however (which is probably the reason why the
+ standard does not define this feature, because it is highly
+ unorthogonal). Flexible array members cannot be initialized ...
+
+ <itemize>
+ <item>... when defining an array of structs with flexible
+ members.
+ <item>... if such a struct is a member field of another struct
+ which is not the last field.
+ <item>... if the struct which contains a flexible array member is
+ declared as <tt/register/, and the size and compiler settings
+ do allow the compiler actually to place the struct into the
+ register bank in the zero page.
+ </itemize>
+
+ Please note that -- as defined in the ISO C standard -- the <tt/sizeof/
+ operator returns the struct size with the flexible array member having
+ size zero, even if it is initialized.
+ <p>
+
</itemize>
<p>
<tag><tt>__CC65__</tt></tag>
This macro is always defined. Its value is the version number of the
- compiler in hex. Version 2.0.1 of the compiler will have this macro defined
- as 0x0201.
+ compiler in hex. For example, version 2.10.1 of the compiler has this macro
+ defined as <tt/0x02A1/.
+
+ <tag><tt>__APPLE2__</tt></tag>
+
+ This macro is defined if the target is the Apple ][ (-t apple2).
+
+ <tag><tt>__APPLE2ENH__</tt></tag>
+
+ This macro is defined if the target is the enhanced Apple //e (-t apple2enh).
+
+ <tag><tt>__ATARI__</tt></tag>
+
+ This macro is defined if the target is one of the Atari computers
+ (400/800/130XL/800XL).
+
+ <tag><tt>__ATMOS__</tt></tag>
+
+ This macro is defined if the target is the Oric Atmos (-t atmos).
<tag><tt>__CBM__</tt></tag>
This macro is defined if the target is the c128 (-t c128).
- <tag><tt>__PLUS4__</tt></tag>
-
- This macro is defined if the target is the plus/4 (-t plus4).
-
<tag><tt>__CBM510__</tt></tag>
This macro is defined if the target is the CBM 500 series of computers.
This macro is defined if the target is one of the CBM 600/700 family of
computers (called B series in the US).
+ <tag><tt>__GEOS__</tt></tag>
+
+ This macro is defined if you are compiling for the GEOS system (-t geos).
+
+ <tag><tt>__LUNIX__</tt></tag>
+
+ This macro is defined if you are compiling for the LUnix system (-t lunix).
+
+ <tag><tt>__LYNX__</tt></tag>
+
+ This macro is defined if the target is the Atari Lynx (-t lynx).
+
+ <tag><tt>__NES__</tt></tag>
+
+ This macro is defined if the target is the NES (-t nes).
+
<tag><tt>__PET__</tt></tag>
This macro is defined if the target is the PET family of computers (-t pet).
- <tag><tt>__ATARI__</tt></tag>
+ <tag><tt>__PLUS4__</tt></tag>
- This macro is defined if the target is one of the Atari computers
- (400/800/130XL/800XL).
+ This macro is defined if the target is the plus/4 (-t plus4).
- <tag><tt>__APPLE2__</tt></tag>
+ <tag><tt>__SUPERVISION__</tt></tag>
- This macro is defined if the target is the Apple ][ (-t apple2).
+ This macro is defined if the target is the supervision (-t supervision).
- <tag><tt>__GEOS__</tt></tag>
+ <tag><tt>__VIC20__</tt></tag>
- This macro is defined if you are compiling for the GEOS system (-t geos).
+ This macro is defined if the target is the vic20 (-t vic20).
<tag><tt>__FILE__</tt></tag>
This macro expands to the current line number.
- <tag><tt>__STRICT_ANSI__</tt></tag>
+ <tag><tt>__CC65_STD__</tt></tag>
- This macro is defined to 1 if the <tt/-A/ compiler option was given, and
- undefined otherwise.
+ This macro is defined to one of the following depending on the <tt><ref
+ id="option--standard" name="--standard"></tt> command line option:
+ <itemize>
+ <item><tt/__CC65_STD_C89__/
+ <item><tt/__CC65_STD_C99__/
+ <item><tt/__CC65_STD_CC65__/
+ </itemize>
<tag><tt>__OPT__</tt></tag>
</descrip>
-<sect>#pragmas<label id="pragmas"><p>
+<sect>#pragmas<label id="pragmas"><p>
The compiler understands some pragmas that may be used to change code
-generation and other stuff.
-
+generation and other stuff. Some of these pragmas understand a special form:
+If the first parameter is <tt/push/, the old value is saved onto a stack
+before changing it. The value may later be restored by using the <tt/pop/
+parameter with the <tt/#pragma/.
-<sect1><tt>#pragma bssseg (<name>)</tt><p>
+<sect1><tt>#pragma bssseg ([push,]<name>)</tt><p>
This pragma changes the name used for the BSS segment (the BSS segment
is used to store uninitialized data). The argument is a string enclosed
use another BSS segment, you have to do that yourself, otherwise
uninitialized variables do not have the value zero.
+ The <tt/#pragma/ understands the push and pop parameters as explained above.
+
Example:
<tscreen><verb>
#pragma bssseg ("MyBSS")
<itemize>
<item>The character index is actually the code of the character in the
C source, so character mappings do always depend on the source
- character set. This means that <tt/#pragma charmap/ is not portable
- - it depends on the build environment.
+ character set. This means that <tt/#pragma charmap/ is not
+ portable -- it depends on the build environment.
<item>While it is possible to use character literals as indices, the
result may be somewhat unexpected, since character literals are
itself translated. For this reason I would suggest to avoid
</verb></tscreen>
-<sect1><tt>#pragma checkstack (on|off)</tt><label
-id="pragma-checkstack"><p>
+<sect1><tt>#pragma checkstack ([push,]on|off)</tt><label id="pragma-checkstack"><p>
Tells the compiler to insert calls to a stack checking subroutine to detect
stack overflows. The stack checking code will lead to somewhat larger and
If the argument is "off", stack checks are disabled (the default), otherwise
they're enabled.
+ The <tt/#pragma/ understands the push and pop parameters as explained above.
-<sect1><tt>#pragma codeseg (<name>)</tt><p>
+<sect1><tt>#pragma codeseg ([push,]<name>)</tt><p>
This pragma changes the name used for the CODE segment (the CODE segment
is used to store executable code). The argument is a string enclosed in
segments. If you use other segments, you have to create a new linker
configuration file.
+ The <tt/#pragma/ understands the push and pop parameters as explained above.
+
Example:
<tscreen><verb>
#pragma codeseg ("MyCODE")
</verb></tscreen>
-<sect1><tt>#pragma dataseg (<name>)</tt><p>
+<sect1><tt>#pragma codesize ([push,]<int>)</tt><label id="pragma-codesize"><p>
+
+ This pragma allows finer control about speed vs. size decisions in the code
+ generation and optimization phase. It gives the allowed size increase factor
+ (in percent). The default is can be changed by use of the <tt/<ref
+ id="option-codesize" name="--codesize">/ compiler option.
+
+ The <tt/#pragma/ understands the push and pop parameters as explained above.
+
+
+<sect1><tt>#pragma dataseg ([push,]<name>)</tt><p>
This pragma changes the name used for the DATA segment (the DATA segment
is used to store initialized data). The argument is a string enclosed in
segments. If you use other segments, you have to create a new linker
configuration file.
+ The <tt/#pragma/ understands the push and pop parameters as explained above.
+
Example:
<tscreen><verb>
#pragma dataseg ("MyDATA")
</verb></tscreen>
-<sect1><tt>#pragma rodataseg (<name>)</tt><p>
+<sect1><tt>#pragma optimize ([push,]on|off)</tt><label id="pragma-optimize"><p>
+
+ Switch optimization on or off. If the argument is "off", optimization is
+ disabled, otherwise it is enabled. Please note that this pragma only effects
+ whole functions. The setting in effect when the function is encountered will
+ determine if the generated code is optimized or not.
+
+ Optimization and code generation is also controlled by the <ref
+ id="pragma-codesize" name="codesize pragma">.
+
+ The default is "off", but may be changed with the <tt/<ref name="-O"
+ id="option-O">/ compiler option.
+
+ The <tt/#pragma/ understands the push and pop parameters as explained above.
+
+
+<sect1><tt>#pragma rodataseg ([push,]<name>)</tt><p>
This pragma changes the name used for the RODATA segment (the RODATA
segment is used to store readonly data). The argument is a string
segments. If you use other segments, you have to create a new linker
configuration file.
+ The <tt/#pragma/ understands the push and pop parameters as explained above.
+
Example:
<tscreen><verb>
#pragma rodataseg ("MyRODATA")
</verb></tscreen>
-<sect1><tt>#pragma regvaraddr (on|off)</tt><p>
+<sect1><tt>#pragma regvaraddr ([push,]on|off)</tt><p>
The compiler does not allow to take the address of register variables.
The regvaraddr pragma changes this. Taking the address of a register
declared as register. So your programs become non-portable if you use
this pragma. In addition, your program may not work. This is usually the
case if a subroutine is called with the address of a register variable,
- and this subroutine (or a subroutine called from there) uses itself
+ and this subroutine (or a subroutine called from there) uses
register variables. So be careful with this #pragma.
+ The <tt/#pragma/ understands the push and pop parameters as explained above.
+
Example:
<tscreen><verb>
- #pragma regvaraddr(1) /* Allow taking the address
+ #pragma regvaraddr(on) /* Allow taking the address
* of register variables
*/
</verb></tscreen>
-<sect1><tt>#pragma signedchars (on|off)</tt><label id="pragma-signedchars"><p>
+<sect1><tt>#pragma regvars ([push,]on|off)</tt><label id="pragma-regvars"><p>
+
+ Enables or disables use of register variables. If register variables are
+ disabled (the default), the <tt/register/ keyword is ignored. Register
+ variables are explained in more detail in <ref id="regvars" name="a separate
+ chapter">.
+
+ The <tt/#pragma/ understands the push and pop parameters as explained above.
+
+
+<sect1><tt>#pragma signedchars ([push,]on|off)</tt><label id="pragma-signedchars"><p>
Changes the signedness of the default character type. If the argument is
"on", default characters are signed, otherwise characters are unsigned.
lot better code. This default may be overridden by the <tt/--signed-chars/
command line option.
+ The <tt/#pragma/ understands the push and pop parameters as explained above.
-<sect1><tt>#pragma staticlocals (on|off)</tt><label
-id="pragma-staticlocals"<p>
+
+<sect1><tt>#pragma staticlocals ([push,]on|off)</tt><label id="pragma-staticlocals"<p>
Use variables in the bss segment instead of variables on the stack. This
pragma changes the default set by the compiler option <tt/-Cl/. If the
argument is "on", local variables are allocated in the BSS segment,
leading to shorter and in most cases faster, but non-reentrant code.
+ The <tt/#pragma/ understands the push and pop parameters as explained above.
+
+
+<sect1><tt>#pragma warn ([push,]on|off)</tt><label id="pragma-warn"><p>
+
+ Switch compiler warnings on or off. If the argument is "off", warnings are
+ disabled, otherwise they're enabled. The default is "on", but may be changed
+ with the <tt/<ref name="-W" id="option-W">/ compiler option.
+
+ The <tt/#pragma/ understands the push and pop parameters as explained above.
+
<sect1><tt>#pragma zpsym (<name>)</tt><p>
- Tell the compiler that the - previously as external declared - symbol with
+ Tell the compiler that the -- previously as external declared -- symbol with
the given name is a zero page symbol (usually from an assembler file).
The compiler will create a matching import declaration for the assembler.
+<sect>Register variables<label id="regvars"><p>
+
+The runtime for all supported platforms has 6 bytes of zero page space
+available for register variables (this could be increased, but I think it's a
+good value). So you can declare register variables up to a total size of 6 per
+function. The compiler will allocate register space on a "first come, first
+served" base and convert any <tt/register/ declarations that exceed the
+available register space silently to <tt/auto/. Parameters can also be
+declared as <tt/register/, this will in fact give slightly shorter code than
+using a register variable.
+
+Since a function must save the current values of the registers on entry and
+restore them on exit, there is an overhead associated with register variables,
+and this overhead is quite high (about 20 bytes per variable). This means that
+just declaring anything as <tt/register/ is not a good idea.
+
+The best use for register variables are pointers, especially those that point
+to structures. The magic number here is about 3 uses of a struct field: If the
+function contains this number or even more, the generated code will be usually
+shorter and faster when using a register variable for the struct pointer. The
+reason for this is that the register variable can in many cases be used as a
+pointer directly. Having a pointer in an auto variable means that this pointer
+must first be copied into a zero page location, before it can be dereferenced.
+
+Second best use for register variables are counters. However, there is not
+much difference in the code generated for counters, so you will need at least
+100 operations on this variable (for example in a loop) to make it worth the
+trouble. The only savings you get here are by the use of a zero page variable
+instead of one on the stack or in the data segment.
+
+Register variables must be explicitly enabled by using <tt/-Or/ or <tt/-r/ on
+the command line. Register variables are only accepted on function top level,
+register variables declared in interior blocks are silently converted to
+<tt/auto/. With register variables disabled, all variables declared as
+<tt/register/ are actually auto variables.
+
+Please take care when using register variables: While they are helpful and can
+lead to a tremendous speedup when used correctly, improper usage will cause
+bloated code and a slowdown.
+
+
+
<sect>Inline assembler<label id="inline-asm"><p>
The compiler allows to insert assembler statements into the output file. The
<p>
The first form is in the user namespace and is disabled by <tt><ref
-id="option-A" name="-A"></tt>.
+id="option--standard" name="--standard"></tt> if the argument is not <tt/cc65/.
The asm statement may be used inside a function and on global file level. An
inline assembler statement is a primary expression, so it may also be used as
the format specifier before passing the assembly code line to the backend.
<itemize>
- <item><tt/%b/ - Numerical 8 bit value
- <item><tt/%w/ - Numerical 16 bit value
- <item><tt/%l/ - Numerical 32 bit value
+ <item><tt/%b/ - Numerical 8-bit value
+ <item><tt/%w/ - Numerical 16-bit value
+ <item><tt/%l/ - Numerical 32-bit value
<item><tt/%v/ - Assembler name of a (global) variable or function
<item><tt/%o/ - Stack offset of a (local) variable
+ <item><tt/%g/ - Assembler name of a C label
+ <item><tt/%s/ - The argument is converted to a string
<item><tt/%%/ - The % sign itself
</itemize><p>
</verb></tscreen>
<p>
-Note: Do not embedd the assembler labels that are used as names of global
+Note: Do not embed the assembler labels that are used as names of global
variables or functions into your asm statements. Code like this
<tscreen><verb>
int foo;
int bar () { return 1; }
- __asm__ ("lda _foo"); /* DON'T DO THAT! */
+ __asm__ ("lda _foo"); /* DON'T DO THAT! */
...
- __asm__ ("jsr _bar"); /* DON'T DO THAT EITHER! */
+ __asm__ ("jsr _bar"); /* DON'T DO THAT EITHER! */
</verb></tscreen>
<p>
may stop working if the way, the compiler generates these names is changed in
-a future version.
+a future version. Instead use the format specifiers from the table above:
+
+<tscreen><verb>
+ __asm__ ("lda %v", foo); /* OK */
+ ...
+ __asm__ ("jsr %v", bar); /* OK */
+</verb></tscreen>
<p>
If you have problems using the compiler, if you find any bugs, or if you're
doing something interesting with it, I would be glad to hear from you. Feel
-free to contact me by email (<htmlurl url="mailto:uz@cc65.org" name="uz@cc65.org">).
+free to contact me by email (<htmlurl url="mailto:uz@cc65.org"
+name="uz@cc65.org">).
--------------------------------------------------------------------------
</verb></tscreen>
-In acknowledgment of this copyright, I will place my own changes to the
-compiler under the same copyright. Please note however, that the library
-and all binutils are covered by another copyright, and that I'm planning
-to do a complete rewrite of the compiler, after which the compiler
-copyright will also change.
-
-For the list of changes requested by this copyright see newvers.txt.
-
+Small parts of the compiler (parts of the preprocessor and main parser) are
+still covered by this copyright. The main portion is covered by the usual
+cc65 license, which reads:
+
+This software is provided 'as-is', without any expressed or implied
+warranty. In no event will the authors be held liable for any damages
+arising from the use of this software.
+
+Permission is granted to anyone to use this software for any purpose,
+including commercial applications, and to alter it and redistribute it
+freely, subject to the following restrictions:
+
+<enum>
+<item> The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+<item> Altered source versions must be plainly marked as such, and must not
+ be misrepresented as being the original software.
+<item> This notice may not be removed or altered from any source
+ distribution.
+</enum>
</article>