]> git.sur5r.net Git - cc65/blob - doc/cc65.sgml
Date update
[cc65] / doc / cc65.sgml
1 <!doctype linuxdoc system>
2
3 <article>
4 <title>cc65 Users Guide
5 <author>Ullrich von Bassewitz, <htmlurl url="mailto:uz@cc65.org" name="uz@cc65.org">
6 <date>03.09.2000, 02.10.2001
7
8 <abstract>
9 cc65 is a C compiler for 6502 targets. It supports several 6502 based home
10 computers like the Commodore and Atari machines, but it is easily retargetable.
11 </abstract>
12
13 <!-- Table of contents -->
14 <toc>
15
16 <!-- Begin the document -->
17
18
19 <sect>Overview<p>
20
21 cc65 was originally a C compiler for the Atari 8-bit machines written by
22 John R. Dunning. In prior releases I've described the compiler by listing
23 up the changes made by me. I have made many more changes in the meantime
24 (and rewritten major parts of the compiler), so I will no longer do that,
25 since the list would be too large and of no use to anyone. Instead I will
26 describe the compiler in respect to the ANSI/ISO C standard. In fact, I'm
27 planning a complete rewrite (that is, a complete new compiler) for the
28 next release, since there are too many limitations in the current code,
29 and removing these limitations would mean a rewrite of many more parts of
30 the compiler.
31
32 There is a separate document named "library.txt" that covers the library
33 available for the compiler. If you know C and are interested in doing
34 actual programming, the library documentation is probably of much more use
35 than this document.
36
37 If you need some hints for getting the best code out of the compiler, you
38 may have a look at "coding.txt" which covers some code generation issues.
39
40
41
42 <sect>Usage<p>
43
44 The compiler translates C files into files containing assembler code that
45 may be translated by the ca65 macroassembler (for more information about
46 the assembler, have a look at ca65.txt).
47
48
49 <sect1>Command line option overview<p>
50
51 The compiler may be called as follows:
52
53 <tscreen><verb>
54 ---------------------------------------------------------------------------
55 Usage: cc65 [options] file
56 Short options:
57   -d                    Debug mode
58   -g                    Add debug info to object file
59   -h                    Help (this text)
60   -j                    Default characters are signed
61   -o name               Name the output file
62   -t sys                Set the target system
63   -v                    Increase verbosity
64   -A                    Strict ANSI mode
65   -Cl                   Make local variables static
66   -Dsym[=defn]          Define a symbol
67   -I dir                Set an include directory search path
68   -O                    Optimize code
69   -Oi                   Optimize code, inline more code
70   -Or                   Enable register variables
71   -Os                   Inline some known functions
72   -T                    Include source as comment
73   -V                    Print the compiler version number
74   -W                    Suppress warnings
75
76 Long options:
77   --ansi                Strict ANSI mode
78   --bss-name seg        Set the name of the BSS segment
79   --check-stack         Generate stack overflow checks
80   --code-name seg       Set the name of the CODE segment
81   --codesize x          Accept larger code by factor x
82   --cpu type            Set cpu type
83   --data-name seg       Set the name of the DATA segment
84   --debug               Debug mode
85   --debug-info          Add debug info to object file
86   --help                Help (this text)
87   --include-dir dir     Set an include directory search path
88   --rodata-name seg     Set the name of the RODATA segment
89   --signed-chars        Default characters are signed
90   --static-locals       Make local variables static
91   --target sys          Set the target system
92   --verbose             Increase verbosity
93   --version             Print the compiler version number
94 ---------------------------------------------------------------------------
95 </verb></tscreen>
96
97
98 <sect1>Command line options in detail<p>
99
100 Here is a description of all the command line options:
101
102 <descrip>
103
104   <label id="option-A">
105   <tag><tt>-A, --ansi</tt></tag>
106
107   This option disables any compiler exensions. Have a look at section 5
108   for a discussion of compiler extensions. In addition, the macro
109   <tt/__STRICT_ANSI__/ is defined, when using one of these options.
110
111
112   <tag><tt>--bss-name seg</tt></tag>
113
114   Set the name of the bss segment.
115
116
117   <tag><tt>--check-stack</tt></tag>
118
119   Tells the compiler to generate code that checks for stack overflows. See
120   <tt><ref id="pragma-checkstack" name="#pragma checkstack"></tt> for an
121   explanation of this feature.
122
123
124   <tag><tt>--code-name seg</tt></tag>
125
126   Set the name of the code segment.
127
128
129   <tag><tt>--codesize x</tt></tag>
130
131   This options allows finer control about speed vs. size decisions in the
132   code generation phase. It gives the allowed size increase factor (in
133   percent). The default is 100 when not using <tt/-Oi/ and 200 when using
134   <tt/-Oi/ (<tt/-Oi/ is the same as <tt/--codesize 200/).
135
136
137   <tag><tt>--cpu CPU</tt></tag>
138
139   A new, still experimental option. You may specify "6502" or "65C02" as
140   the CPU. 6502 is the default, so this will not change anything.
141   Specifying 65C02 will use a few 65C02 instructions when generating code.
142   Don't expect too much from this option: It is still new (and may have
143   bugs), and the additional instructions for the 65C02 are not that
144   overwhelming.
145
146
147   <tag><tt>-d, --debug</tt></tag>
148
149   Enables debug mode, something that should not be needed for mere
150   mortals:-)
151
152
153   <tag><tt>-D sym[=definition]</tt></tag>
154
155   Define a macro on the command line. If no definition is given, the macro
156   is defined to the value "1".
157
158
159   <tag><tt>-g, --debug-info</tt></tag>
160
161   This will cause the compiler to insert a <tt/.DEBUGINFO/ command into the
162   generated assembler code. This will cause the assembler to include all
163   symbols in a special section in the object file.
164
165
166   <tag><tt>-h, --help</tt></tag>
167
168   Print the short option summary shown above.
169
170
171   <tag><tt>--rodata-name seg</tt></tag>
172
173   Set the name of the rodata segment (the segment used for readonly data).
174
175
176   <tag><tt>-j, --signed-chars</tt></tag>
177
178   Using this option, you can make the default characters signed. Since the
179   6502 has no provisions for sign extending characters (which is needed on
180   almost any load operation), this will make the code larger and slower. A
181   better way is to declare characters explicitly as "signed" if needed. You
182   can also use <tt><ref id="pragma-signedchars" name="#pragma
183   signedchars"></tt> for better control of this option.
184
185
186   <tag><tt>-t target, --target target</tt></tag>
187
188   This option is used to set the target system. The target system
189   determines things like the character set that is used for strings and
190   character constants. The following target systems are supported:
191
192   <itemize>
193   <item>none
194   <item>atari
195   <item>c64
196   <item>c128
197   <item>plus4
198   <item>cbm510 (CBM-II series with 40 column video)
199   <item>cbm610 (all CBM-II II computers with 80 column video)
200   <item>pet (all CBM PET systems except the 2001)
201   <item>apple2
202   <item>geos
203   </itemize>
204
205   <tag><tt>-v, --verbose</tt></tag>
206
207   Using this option, the compiler will be somewhat more verbose if errors
208   or warnings are encountered.
209
210
211   <tag><tt>-Cl, --static-locals</tt></tag>
212
213   Use static storage for local variables instead of storage on the stack.
214   Since the stack is emulated in software, this gives shorter and usually
215   faster code, but the code is no longer reentrant. The difference between
216   <tt/-Cl/ and declaring local variables as static yourself is, that
217   initializer code is executed each time, the function is entered. So when
218   using
219
220   <tscreen><verb>
221         void f (void)
222         {
223             unsigned a = 1;
224             ...
225         }
226   </verb></tscreen>
227
228   the variable a will always have the value 1 when entering the function
229   and using <tt/-Cl/, while in
230
231   <tscreen><verb>
232         void f (void)
233         {
234             static unsigned a = 1;
235             ....
236         }
237   </verb></tscreen>
238
239   the variable a will have the value 1 only the first time, the function
240   is entered, and will keep the old value from one call of the function to
241   the next.
242
243   You may also use <tt><ref id="pragma-staticlocals" name="#pragma
244   staticlocals"></tt> to change this setting in your sources.
245
246
247   <tag><tt>-I dir, --include-dir dir</tt></tag>
248
249   Set a directory where the compiler searches for include files. You may
250   use this option multiple times to add more than one directory to the
251   search list.
252
253
254   <tag><tt>-o name</tt></tag>
255
256   Specify the name of the output file. If you don't specify a name, the
257   name of the C input file is used, with the extension replaced by ".s".
258
259
260   <tag><tt>-O, -Oi, -Or, -Os</tt></tag>
261
262   Enable an optimizer run over the produced code.
263
264   Using <tt/-Oi/, the code generator will inline some code where otherwise a
265   runtime functions would have been called, even if the generated code is
266   larger. This will not only remove the overhead for a function call, but will
267   make the code visible for the optimizer. <tt/-Oi/ is an alias for
268   <tt/--codesize 200/.
269
270   <tt/-Or/ will make the compiler honor the <tt/register/ keyword. Local
271   variables may be placed in registers (which are actually zero page
272   locations). There is some overhead involved with register variables, since
273   the old contents of the registers must be saved and restored. In addition,
274   the current implementation does not make good use of register variables, so
275   using <tt/-Or/ may make your program even slower and larger. Use with care!
276
277   Using <tt/-Os/ will force the compiler to inline some known functions from
278   the C library like strlen. Note: This has two consequences:
279   <p>
280   <itemize>
281   <item>You may not use names of standard C functions in your own code. If you
282         do that, your program is not standard compliant anyway, but using
283         <tt/-Os/ will actually break things.
284         <p>
285   <item>The inlined string and memory functions will not handle strings or
286         memory areas larger than 255 bytes. Similar, the inlined <tt/is..()/
287         functions will not work with values outside char range.
288         <p>
289   </itemize>
290   <p>
291   It is possible to concatenate the modifiers for <tt/-O/. For example, to
292   enable register variables and inlining of known functions, you may use
293   <tt/-Ors/.
294
295
296   <tag><tt>-T</tt></tag>
297
298   This include the source code as comments in the generated code. This is
299   normally not needed.
300
301
302   <tag><tt>-V, --version</tt></tag>
303
304   Print the version number of the compiler. When submitting a bug report,
305   please include the operating system you're using, and the compiler
306   version.
307
308
309   <tag><tt>-W</tt></tag>
310
311   This option will suppress any warnings generated by the compiler. Since
312   any source file may be written in a manner that it will not produce
313   compiler warnings, using this option is usually not a good idea.
314
315 </descrip><p>
316
317
318 <sect>Input and output<p>
319
320 The compiler will accept one C file per invocation and create a file with
321 the same base name, but with the extension replaced by ".s". The output
322 file contains assembler code suitable for the use with the ca65 macro
323 assembler.
324
325 In addition to the paths named in the <tt/-I/ option on the command line, the
326 directory named in the environment variable <tt/CC65_INC/ is added to the
327 search path for include files on startup.
328
329
330
331 <sect>Differences to the ISO standard<p>
332
333 Here is a list of differences between the language, the compiler accepts,
334 and the one defined by the ISO standard:
335
336 <itemize>
337
338 <item>  The compiler allows single line comments that start with //. This
339         feature is disabled in strict ANSI mode.
340         <p>
341 <item>  The compiler allows unnamed parameters in parameter lists. The
342         compiler will not issue warnings about unused parameters that don't
343         have a name. This feature is disabled in strict ANSI mode.
344         <p>
345 <item>  The compiler has some additional keywords:
346         <p>
347         <itemize>
348         <item><tt/asm/
349         <item><tt/__asm__/
350         <item><tt/fastcall/
351         <item><tt/__fastcall__/
352         <item><tt/__AX__/
353         <item><tt/__EAX__/
354         <item><tt/__func__/
355         <item><tt/__attribute__/
356         </itemize>
357         <p>
358         The keywords without the underlines are disabled in strict ANSI mode.
359         <p>
360 <item>  The datatypes "float" and "double" are not available.
361         <p>
362 <item>  The compiler does not support bit fields.
363         <p>
364 <item>  Initialization of local variables is only possible for scalar data
365         types (that is, not for arrays and structs).
366         <p>
367 <item>  Because of the "wrong" order of the parameters on the stack, there is
368         an additional macro needed to access parameters in a variable
369         parameter list in a C function.
370         <p>
371 <item>  Functions may not return structs (or unions), and structs may not be
372         passed as parameters by value. However, struct assignment *is*
373         possible.
374         <p>
375 <item>  Part of the C library is available only with fastcall calling
376         conventions (see below). This means, that you may not mix pointers to
377         those functions with pointers to user written functions.
378         <p>
379 </itemize>
380
381 There may be some more minor differences, I'm currently not aware off. The
382 biggest problem is the missing float data type. With this limitation in
383 mind, you should be able to write fairly portable code.
384
385
386
387 <sect>Extensions<p>
388
389 This cc65 version has some extensions to the ISO C standard.
390
391 <itemize>
392
393 <item>  The compiler allows // comments (like in C++ and in the proposed C9x
394         standard). This feature is disabled by <tt><ref id="option-A"
395         name="-A"></tt>.
396         <p>
397
398 <item>  The compiler allows to insert assembler statements into the output
399         file. The syntax is
400
401         <tscreen><verb>
402         asm (&lt;string literal&gt;[, optional parameters]) ;
403         </verb></tscreen>
404         or
405         <tscreen><verb>
406         __asm__ (&lt;string literal&gt;[, optional parameters]) ;
407         </verb></tscreen>
408
409         The first form is in the user namespace and is disabled if the <tt/-A/
410         switch is given.
411
412         There is a whole section covering inline assembler statements,
413         <ref id="inline-asm" name="see there">.
414         <p>
415
416 <item>  There is a special calling convention named "fastcall". This calling
417         convention is currently only usable for functions written in
418         assembler. The syntax for a function declaration using fastcall is
419
420         <tscreen><verb>
421         <tt/&lt;return type&gt; fastcall &lt;function name&gt; (&lt;parameter list&gt;)/
422         </verb></tscreen>
423         or
424         <tscreen><verb>
425         <tt/&lt;return type&gt; __fastcall__ &lt;function name&gt; (&lt;parameter list&gt;)/
426         </verb></tscreen>
427         An example would be
428         <tscreen><verb>
429         <tt/void __fastcall__ f (unsigned char c)/
430         </verb></tscreen>
431         The first form of the fastcall keyword is in the user namespace and is
432         therefore disabled in strict ANSI mode.
433
434         For functions declared as <tt/fastcall/, the rightmost parameter is not
435         pushed on the stack but left in the primary register when the function
436         is called. This will reduce the cost when calling assembler functions
437         significantly, especially when the function itself is rather small.
438         <p>
439
440 <item>  There are two pseudo variables named <tt/__AX__/ and <tt/__EAX__/.
441         Both refer to the primary register that is used by the compiler to
442         evaluate expressions or return function results. <tt/__AX__/ is of
443         type <tt/unsigned int/ and <tt/__EAX__/ of type <tt/long unsigned int/
444         respectively. The pseudo variables may be used as lvalue and rvalue as
445         every other variable. They are most useful together with short
446         sequences of assembler code. For example, the macro
447
448         <tscreen><verb>
449         #define hi(x) (__AX__=(x),asm("\ttxa\n\tldx\t#$00",__AX__)
450         </verb></tscreen>
451
452         will give the high byte of any unsigned value.
453         <p>
454
455 <item>  Inside a function, the identifier <tt/__func__/ gives the name of the
456         current function as a string. Outside of functions, <tt/__func__/ is
457         undefined.
458         Example:
459
460         <tscreen><verb>
461         #define PRINT_DEBUG(s)  printf ("%s: %s\n", __func__, s);
462         </verb></tscreen>
463
464         The macro will print the name of the current function plus a given
465         string.
466         <p>
467
468 <item>  cc65 allows the initialization of <tt/void/ variables. This may be
469         used to create variable structures that are more compatible with
470         interfaces written for assembler languages. Here is an example:
471
472         <tscreen><verb>
473         void GCmd = {   (char)3, (unsigned)0x2000, (unsigned)0x3000 };
474         </verb></tscreen>
475
476         This will be translated as follows:
477
478         <tscreen><verb>
479         _GCmd:
480                 .byte   3
481                 .word   $2000
482                 .word   $3000
483         </verb></tscreen>
484
485         Since the variable is of type <tt/void/ you may not use it as is.
486         However, taking the address of the variable results in a <tt/void*/
487         which may be passed to any function expecting a pointer.
488
489         See the <htmlurl url="geos.html" name="GEOS library"> for examples on
490         how to use this feature.
491         <p>
492
493 </itemize>
494 <p>
495
496
497 <sect>Predefined macros<p>
498
499 The compiler defines several macros at startup:
500
501 <descrip>
502
503   <tag><tt>__CC65__</tt></tag>
504
505   This macro is always defined. Its value is the version number of the
506   compiler in hex. Version 2.0.1 of the compiler will have this macro defined
507   as 0x0201.
508
509   <tag><tt>__CBM__</tt></tag>
510
511   This macro is defined if the target system is one of the CBM targets.
512
513   <tag><tt>__C64__</tt></tag>
514
515   This macro is defined if the target is the c64 (-t c64).
516
517   <tag><tt>__C128__</tt></tag>
518
519   This macro is defined if the target is the c128 (-t c128).
520
521   <tag><tt>__PLUS4__</tt></tag>
522
523   This macro is defined if the target is the plus/4 (-t plus4).
524
525   <tag><tt>__CBM510__</tt></tag>
526
527   This macro is defined if the target is the CBM 500 series of computers.
528
529   <tag><tt>__CBM610__</tt></tag>
530
531   This macro is defined if the target is one of the CBM 600/700 family of
532   computers (called B series in the US).
533
534   <tag><tt>__PET__</tt></tag>
535
536   This macro is defined if the target is the PET family of computers (-t pet).
537
538   <tag><tt>__ATARI__</tt></tag>
539
540   This macro is defined if the target is one of the Atari computers
541   (400/800/130XL/800XL).
542
543   <tag><tt>__APPLE2__</tt></tag>
544
545   This macro is defined if the target is the Apple ][ (-t apple2).
546
547   <tag><tt>__GEOS__</tt></tag>
548
549   This macro is defined if you are compiling for the GEOS system (-t geos).
550
551   <tag><tt>__FILE__</tt></tag>
552
553   This macro expands to a string containing the name of the C source file.
554
555   <tag><tt>__LINE__</tt></tag>
556
557   This macro expands to the current line number.
558
559   <tag><tt>__STRICT_ANSI__</tt></tag>
560
561   This macro is defined to 1 if the <tt/-A/ compiler option was given, and
562   undefined otherwise.
563
564   <tag><tt>__OPT__</tt></tag>
565
566   Is defined if the compiler was called with the <tt/-O/ command line option.
567
568   <tag><tt>__OPT_i__</tt></tag>
569
570   Is defined if the compiler was called with the <tt/-Oi/ command line option.
571
572   <tag><tt>__OPT_r__</tt></tag>
573
574   Is defined if the compiler was called with the <tt/-Or/ command line option.
575
576   <tag><tt>__OPT_s__</tt></tag>
577
578   Is defined if the compiler was called with the <tt/-Os/ command line option.
579
580 </descrip>
581
582
583 <sect>#pragmas<label id="pragmas"><p>
584
585 The compiler understands some pragmas that may be used to change code
586 generation and other stuff.
587
588
589 <sect1><tt>#pragma bssseg (&lt;name&gt;)</tt><p>
590
591   This pragma changes the name used for the BSS segment (the BSS segment
592   is used to store uninitialized data). The argument is a string enclosed
593   in double quotes.
594
595   Note: The default linker configuration file does only map the standard
596   segments. If you use other segments, you have to create a new linker
597   configuration file.
598
599   Beware: The startup code will zero only the default BSS segment. If you
600   use another BSS segment, you have to do that yourself, otherwise
601   uninitialized variables do not have the value zero.
602
603   Example:
604   <tscreen><verb>
605         #pragma bssseg ("MyBSS")
606   </verb></tscreen>
607
608
609 <sect1><tt>#pragma checkstack (&lt;const int&gt;)</tt><label
610 id="pragma-checkstack"><p>
611
612   Tells the compiler to insert calls to a stack checking subroutine to detect
613   stack overflows. The stack checking code will lead to somewhat larger and
614   slower programs, so you may want to use this pragma when debugging your
615   program and switch it off for the release version. If a stack overflow is
616   detected, the program is aborted.
617
618   If the argument is zero, stack checks are disabled (the default), otherwise
619   they're enabled.
620
621
622 <sect1><tt>#pragma codeseg (&lt;name&gt;)</tt><p>
623
624   This pragma changes the name used for the CODE segment (the CODE segment
625   is used to store executable code). The argument is a string enclosed in
626   double quotes.
627
628   Note: The default linker configuration file does only map the standard
629   segments. If you use other segments, you have to create a new linker
630   configuration file.
631
632   Example:
633   <tscreen><verb>
634         #pragma codeseg ("MyCODE")
635   </verb></tscreen>
636
637
638 <sect1><tt>#pragma dataseg (&lt;name&gt;)</tt><p>
639
640   This pragma changes the name used for the DATA segment (the DATA segment
641   is used to store initialized data). The argument is a string enclosed in
642   double quotes.
643
644   Note: The default linker configuration file does only map the standard
645   segments. If you use other segments, you have to create a new linker
646   configuration file.
647
648   Example:
649   <tscreen><verb>
650         #pragma dataseg ("MyDATA")
651   </verb></tscreen>
652
653
654 <sect1><tt>#pragma rodataseg (&lt;name&gt;)</tt><p>
655
656   This pragma changes the name used for the RODATA segment (the RODATA
657   segment is used to store readonly data). The argument is a string
658   enclosed in double quotes.
659
660   Note: The default linker configuration file does only map the standard
661   segments. If you use other segments, you have to create a new linker
662   configuration file.
663
664   Example:
665   <tscreen><verb>
666         #pragma rodataseg ("MyRODATA")
667   </verb></tscreen>
668
669
670 <sect1><tt>#pragma regvaraddr (&lt;const int&gt;)</tt><p>
671
672   The compiler does not allow to take the address of register variables.
673   The regvaraddr pragma changes this. Taking the address of a register
674   variable is allowed after using this pragma, if the argument is not
675   zero. Using an argument of zero changes back to the default behaviour.
676
677   Beware: The C standard does not allow taking the address of a variable
678   declared as register. So your programs become non-portable if you use
679   this pragma. In addition, your program may not work. This is usually the
680   case if a subroutine is called with the address of a register variable,
681   and this subroutine (or a subroutine called from there) uses itself
682   register variables. So be careful with this #pragma.
683
684   Example:
685   <tscreen><verb>
686         #pragma regvaraddr(1)   /* Allow taking the address
687                                  * of register variables
688                                  */
689   </verb></tscreen>
690
691
692 <sect1><tt>#pragma signedchars (&lt;const int&gt;)</tt><label
693 id="pragma-signedchars"><p>
694
695   Changes the signedness of the default character type. If the argument
696   is not zero, default characters are signed, otherwise characters are
697   unsigned. The compiler default is to make characters unsigned since this
698   creates a lot better code. This default may be overridden by the
699   <tt/--signed-chars/ command line option.
700
701
702 <sect1><tt>#pragma staticlocals (&lt;const int&gt;)</tt><label
703 id="pragma-staticlocals"<p>
704
705   Use variables in the bss segment instead of variables on the stack. This
706   pragma changes the default set by the compiler option <tt/-Cl/. If the
707   argument is not zero, local variables are allocated in the BSS segment,
708   leading to shorter and in most cases faster, but non-reentrant code.
709
710
711 <sect1><tt>#pragma zpsym (&lt;name&gt;)</tt><p>
712
713   Tell the compiler that the - previously as external declared - symbol with
714   the given name is a zero page symbol (usually from an assembler file).
715   The compiler will create a matching import declaration for the assembler.
716
717   Example:
718   <tscreen><verb>
719         extern int foo;
720         #pragma zpsym ("foo");  /* foo is in the zeropage */
721   </verb></tscreen>
722
723
724
725
726 <sect>Inline assembler<label id="inline-asm"><p>
727
728 The compiler allows to insert assembler statements into the output file. The
729 syntax is
730
731 <tscreen><verb>
732         asm (&lt;string literal&gt;[, optional parameters]) ;
733 </verb></tscreen>
734 or
735 <tscreen><verb>
736         __asm__ (&lt;string literal&gt;[, optional parameters]) ;
737 </verb></tscreen>
738 <p>
739
740 The first form is in the user namespace and is disabled by <tt><ref
741 id="option-A" name="-A"></tt>.
742
743 The asm statement may be used inside a function and on global file level. An
744 inline assembler statement is a primary expression, so it may also be used as
745 part of an expression. Please note however that the result of an expression
746 containing just an inline assembler statement is always of type <tt/void/.
747
748 The contents of the string literal are preparsed by the compiler and inserted
749 into the generated assembly output, so that the can be further processed by
750 the backend and especially the optimizer. For this reason, the compiler does
751 only allow regular 6502 opcodes to be used with the inline assembler. Pseudo
752 instructions (like <tt/.import/, <tt/.byte/ and so on) are <em/not/ allowed,
753 even if the ca65 assembler (which is used to translate the generated assembler
754 code) would accept them. The builtin inline assembler is not a replacement for
755 the full blown macro assembler which comes with the compiler.
756
757 Note: Inline assembler statements are subject to all optimizations done by the
758 compiler. There is currently no way to protect an inline assembler statement
759 from being moved or removed completely by the optimizer. If in doubt, check
760 the generated assembler output, or disable optimizations.
761
762 The string literal may contain format specifiers from the following list. For
763 each format specifier, an argument is expected which is inserted instead of
764 the format specifier before passing the assembly code line to the backend.
765
766 <itemize>
767   <item><tt/%b/ - Numerical 8 bit value
768   <item><tt/%w/ - Numerical 16 bit value
769   <item><tt/%l/ - Numerical 32 bit value
770   <item><tt/%v/ - Assembler name of a (global) variable
771   <item><tt/%o/ - Stack offset of a (local) variable
772   <item><tt/%%/ - The % sign itself
773 </itemize><p>
774
775 Using these format specifiers, you can access C <tt/#defines/, variables or
776 similar stuff from the inline assembler. For example, to load the value of
777 a C <tt/#define/ into the Y register, one would use
778
779 <tscreen><verb>
780         #define OFFS  23
781         __asm__ ("ldy #%b", OFFS);
782 </verb></tscreen>
783
784 Or, to access a struct member of a static variable:
785
786 <tscreen><verb>
787         typedef struct {
788             unsigned char x;
789             unsigned char y;
790             unsigned char color;
791         } pixel_t;
792         static pixel_t pixel;
793         __asm__ ("ldy #%b", offsetof(pixel, color));
794         __asm__ ("lda %v,y", pixel);
795 </verb></tscreen>
796 <p>
797
798
799
800 <sect>Bugs/Feedback<p>
801
802 If you have problems using the compiler, if you find any bugs, or if you're
803 doing something interesting with it, I would be glad to hear from you. Feel
804 free to contact me by email (<htmlurl url="mailto:uz@cc65.org" name="uz@cc65.org">).
805
806
807
808 <sect>Copyright<p>
809
810 This is the original compiler copyright:
811
812 <tscreen><verb>
813 --------------------------------------------------------------------------
814   -*- Mode: Text -*-
815
816      This is the copyright notice for RA65, LINK65, LIBR65, and other
817   Atari 8-bit programs.  Said programs are Copyright 1989, by John R.
818   Dunning.  All rights reserved, with the following exceptions:
819
820       Anyone may copy or redistribute these programs, provided that:
821
822   1:  You don't charge anything for the copy.  It is permissable to
823       charge a nominal fee for media, etc.
824
825   2:  All source code and documentation for the programs is made
826       available as part of the distribution.
827
828   3:  This copyright notice is preserved verbatim, and included in
829       the distribution.
830
831       You are allowed to modify these programs, and redistribute the
832   modified versions, provided that the modifications are clearly noted.
833
834       There is NO WARRANTY with this software, it comes as is, and is
835   distributed in the hope that it may be useful.
836
837       This copyright notice applies to any program which contains
838   this text, or the refers to this file.
839
840       This copyright notice is based on the one published by the Free
841   Software Foundation, sometimes known as the GNU project.  The idea
842   is the same as theirs, ie the software is free, and is intended to
843   stay that way.  Everybody has the right to copy, modify, and re-
844   distribute this software.  Nobody has the right to prevent anyone
845   else from copying, modifying or redistributing it.
846
847 --------------------------------------------------------------------------
848 </verb></tscreen>
849
850 In acknowledgment of this copyright, I will place my own changes to the
851 compiler under the same copyright. Please note however, that the library
852 and all binutils are covered by another copyright, and that I'm planning
853 to do a complete rewrite of the compiler, after which the compiler
854 copyright will also change.
855
856 For the list of changes requested by this copyright see newvers.txt.
857
858
859 </article>
860