The compiler translates C files into files containing assembler code that may be translated by the ca65 macroassembler (for more information about the assembler, have a look at ca65.txt).
The compiler may be called as follows:
---------------------------------------------------------------------------
Usage: cc65 [options] file
Short options:
-d Debug mode
-g Add debug info to object file
-h Help (this text)
-j Default characters are signed
-o name Name the output file
-t sys Set the target system
-v Increase verbosity
-A Strict ANSI mode
-Cl Make local variables static
-Dsym[=defn] Define a symbol
-I dir Set an include directory search path
-O Optimize code
-Oi Optimize code, inline more code
-Or Enable register variables
-Os Inline some known functions
-T Include source as comment
-V Print the compiler version number
-W Suppress warnings
Long options:
--ansi Strict ANSI mode
--cpu type Set cpu type
--debug Debug mode
--debug-info Add debug info to object file
--help Help (this text)
--include-dir dir Set an include directory search path
--signed-chars Default characters are signed
--static-locals Make local variables static
--target sys Set the target system
--verbose Increase verbosity
--version Print the compiler version number
---------------------------------------------------------------------------
Here is a description of all the command line options:
-A, --ansi
This option disables any compiler exensions. Have a look at section 5
for a discussion of compiler extensions. In addition, the macro
__STRICT_ANSI__
is defined, when using one of these options.
--cpu CPU
A new, still experimental option. You may specify "6502" or "65C02" as the CPU. 6502 is the default, so this will not change anything. Specifying 65C02 will use a few 65C02 instructions when generating code. Don't expect too much from this option: It is still new (and may have bugs), and the additional instructions for the 65C02 are not that overwhelming.
-d, --debug
Enables debug mode, something that should not be needed for mere mortals:-)
-D sym[=definition]
Define a macro on the command line. If no definition is given, the macro is defined to the value "1".
-g, --debug-info
This will cause the compiler to insert a .DEBUGINFO
command into the
generated assembler code. This will cause the assembler to include all
symbols in a special section in the object file.
-h, --help
Print the short option summary shown above.
-j, --signed-chars
Using this option, you can make the default characters signed. Since the
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
#pragma signedchars
for better control of this option.
-t target, --target target
This option is used to set the target system. The target system determines things like the character set that is used for strings and character constants. The following target systems are supported:
-v, --verbose
Using this option, the compiler will be somewhat more verbose if errors or warnings are encountered.
-Cl, --static-locals
Use static storage for local variables instead of storage on the stack.
Since the stack is emulated in software, this gives shorter and usually
faster code, but the code is no longer reentrant. The difference between
-Cl
and declaring local variables as static yourself is, that
initializer code is executed each time, the function is entered. So when
using
void f (void)
{
unsigned a = 1;
...
}
the variable a will always have the value 1 when entering the function
and using -Cl
, while in
void f (void)
{
static unsigned a = 1;
....
}
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.
You may also use
#pragma staticlocals
to change this setting in your sources.
-I dir, --include-dir dir
Set a directory where the compiler searches for include files. You may use this option multiple times to add more than one directory to the search list.
-o name
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".
-O, -Oi, -Or, -Os
Enable an optimizer run over the produced code.
Using -Oi
, the code generator will inline some code where otherwise a
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.
-Or
will make the compiler honor the 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. In addition,
the current implementation does not make good use of register variables, so
using -Or
may make your program even slower and larger. Use with care!
Using -Os
will force the compiler to inline some known functions from
the C library like strlen. Note: This has two consequences:
-Os
will actually break things.
is..()
functions will not work with values outside char range.
It is possible to concatenate the modifiers for -O
. For example, to
enable register variables and inlining of known functions, you may use
-Ors
.
-T
This include the source code as comments in the generated code. This is normally not needed.
-V, --version
Print the version number of the compiler. When submitting a bug report, please include the operating system you're using, and the compiler version.
-W
This option will suppress any warnings generated by the compiler. Since any source file may be written in a manner that it will not produce compiler warnings, using this option is usually not a good idea.