1 <!doctype linuxdoc system>
4 <title>ca65 Users Guide
5 <author>Ullrich von Bassewitz, <tt/uz@musoftware.de/
7 <abstract>ca65 is a macro assembler for the 6502, 65C02 and 65816 CPUs.
10 <!-- Table of contents -->
13 <!-- Begin the document -->
19 ca65 is a replacement for the ra65 assembler that was part of the cc65 C
20 compiler developed by John R. Dunning. I had some problems with ra65 and
21 the copyright does not permit some things which I wanted to be possible,
22 so I decided to write a completely new assembler/linker/archiver suite for
23 the cc65 compiler. ca65 is part of this suite.
25 Some parts of the assembler (code generation and some routines for symbol
26 table handling) are taken from an older crossassembler named a816 written
27 by me a long time ago.
29 Here's a list of the design criteria, that were important for the
34 <item> The assembler must support macros. Macros are not essential, but they
35 make some things easier, especially when you use the assembler in the
36 backend of a compiler.
37 <item> The assembler must support the newer 65C02 and 65816 CPUs. I have been
38 thinking about a 65816 backend for the C compiler, and even my old
39 a816 assembler had support for these CPUs, so this wasn't really a
41 <item> The assembler must produce relocatable code. This necessary for the
42 compiler support, and it is more convenient.
43 <item> Conditional assembly must be supported. This is a must for bigger
44 projects written in assembler (like Elite128).
45 <item> The assembler must support segments, and it must support more than
46 three segments (this is the count, most other assemblers support).
47 Having more than one code segments helps developing code for systems
48 with a divided ROM area (like the C64).
49 <item> The linker must be able to resolve arbitrary expressions. Years ago I
50 spent half a day to convince Borlands Turbo Assembler to let me use
51 the size of a structure I had created. So I decided that this is a
52 must. The linker should be able to get things like
59 <item> True lexical nesting for symbols. This is very convenient for larger
61 <item> "Cheap" local symbols without lexical nesting for those quick, late
63 <item> I liked the idea of "options" as Anre Fachats .o65 format has it, so I
64 introduced the concept into the object file format use by the new cc65
66 <item> The assembler will be a one pass assembler. There was no real need for
67 this decision, but I've written several multipass assemblers, and it
68 started to get boring. A one pass assembler needs much more elaborated
69 data structures, and because of that it's much more fun:-)
70 <item> Non-GPLed code that may be used in any project without restrictions or
71 fear of "GPL infecting" other code.
78 The assembler accepts the following options:
81 ---------------------------------------------------------------------------
82 Usage: ca65 [options] file
84 -g Add debug info to object file
86 -i Ignore case of symbols
87 -l Create a listing if assembly was ok
88 -o name Name the output file
91 -D name[=value] Define a symbol
92 -I dir Set an include directory search path
93 -U Mark unresolved symbols as import
94 -V Print the assembler version
95 -W n Set warning level n
98 --auto-import Mark unresolved symbols as import
99 --cpu type Set cpu type
100 --debug-info Add debug info to object file
101 --help Help (this text)
102 --ignore-case Ignore case of symbols
103 --include-dir dir Set an include directory search path
104 --listing Create a listing if assembly was ok
105 --pagelength n Set the page length for the listing
106 --smart Enable smart mode
107 --verbose Increase verbosity
108 --version Print the assembler version
109 ---------------------------------------------------------------------------
112 Here is a description of all the command line options:
116 <tag><tt>--cpu type</tt></tag>
118 Set the default for the CPU type. The option takes a parameter, which
121 6502, 65C02, 65816 and sunplus
123 (the latter is not available in the freeware version).
126 <tag><tt>-g, --debug-info</tt></tag>
128 When this option (or the equivalent control command <tt/.DEBUGINFO/) is
129 used, the assembler will add a section to the object file that contains
130 all symbols (including local ones) together with the symbol values and
131 source file positions. The linker will put these additional symbols into
132 the VICE label file, so even local symbols can be seen in the VICE
136 <tag><tt>-h, --help</tt></tag>
138 Print the short option summary shown above.
141 <tag><tt>-i, --ignore-case</tt></tag>
143 This option makes the assembler case insensitive on identifiers and
144 labels. This option will override the default, but may itself be
145 overriden by the <tt/.CASE/ control command (see section 6).
148 <tag><tt>-l, --listing</tt></tag>
150 Generate an assembler listing. The listing file will always have the
151 name of the main input file with the extension replaced by ".lst". This
152 may change in future versions.
155 <tag><tt>-o name</tt></tag>
157 The default output name is the name of the input file with the extension
158 replaced by ".o". If you don't like that, you may give another name with
159 the -o option. The output file will be placed in the same directory as
160 the source file, or, if -o is given, the full path in this name is used.
163 <tag><tt>--pagelength n</tt></tag>
165 sets the length of a listing page in lines. See the <tt/.PAGELENGTH/
166 directive for more information.
169 <tag><tt>-s, --smart-mode</tt></tag>
171 In smart mode (enabled by -s or the <tt/.SMART/ pseudo instruction) the
172 assembler will track usage of the REP and SEP instructions in 65816 mode
173 and update the operand sizes accordingly. If the operand of such an
174 instruction cannot be evaluated by the assembler (for example, because
175 the operand is an imported symbol), a warning is issued.
177 Beware: Since the assembler cannot trace the execution flow this may
178 lead to false results in some cases. If in doubt, use the .ixx and .axx
179 instructions to tell the assembler about the current settings. Smart
180 mode is off by default.
183 <tag><tt>-v, --verbose</tt></tag>
185 Increase the assembler verbosity. Usually only needed for debugging
186 purposes. You may use this option more than one time for even more
190 <tag><tt>-D</tt></tag>
192 This option allows you to define symbols on the command line. Without a
193 value, the symbol is defined with the value zero. When giving a value,
194 you may use the '$' prefix for hexadecimal symbols. Please note
195 that for some operating systems, '$' has a special meaning, so
196 you may have to quote the expression.
199 <tag><tt>-I dir, --include-dir dir</tt></tag>
201 Name a directory which is searched for include files. The option may be
202 used more than once to specify more than one directory to search. The
203 current directory is always searched first before considering any
204 additional directores.
207 <tag><tt>-U, --auto-import</tt></tag>
209 Mark symbols that are not defined in the sources as imported symbols.
210 This should be used with care since it delays error messages about typos
211 and such until the linker is run. The compiler uses the equivalent of
212 this switch (<tt/.AUTOIMPORT/, see control command section below) to enable
213 auto imported symbols for the runtime library. However, the compiler is
214 supposed to generate code that runs through the assembler without
215 problems, something which is not always true for assembler programmers.
218 <tag><tt>-V, --version</tt></tag>
220 Print the version number of the assembler. If you send any suggestions
221 or bugfixes, please include the version number.
224 <tag><tt>-Wn</tt></tag>
226 Set the warning level for the assembler. Using -W2 the assembler will
227 even warn about such things like unused imported symbols. The default
228 warning level is 1, and it would probably be silly to set it to
238 The assembler accepts the standard 6502/65816 assembler syntax. One line
239 may contain a label (which is identified by a colon), and, in addition to
240 the label, an assembler mnemonic, a macro, or a control command (see
241 section 6 for supported control commands). Alternatively, the line may
242 contain a symbol definition using the '=' token. Everything after a
243 semicolon is handled as a comment (that is, it is ignored).
245 Here are some examples for valid input lines:
248 Label: ; A label and a comment
249 lda #$20 ; A 6502 instruction plus comment
250 L1: ldx #$20 ; Same with label
251 L2: .byte "Hello world" ; Label plus control command
252 mymac $20 ; Macro expansion
253 MySym = 3*L1 ; Symbol definition
254 MaSym = Label ; Another symbol
257 The assembler accepts all valid 6502 mnemonics when in 6502 mode (the
258 default). The assembler accepts all valid 65SC02 mnemonics when in 65SC02
259 mode (after a <tt/.PC02/ command is found). The assembler accepts all valid
260 65816 mnemonics with a few exceptions after a .P816 command is found.
261 These exceptions are listed below.
263 In 65816 mode several aliases are accepted in addition to the official
267 BGE is an alias for BCS
268 BLT is an alias for BCC
269 CPA is an alias for CMP
270 DEA is an alias for DEC A
271 INA is an alias for INC A
272 SWA is an alias for XBA
273 TAD is an alias for TCD
274 TAS is an alias for TCS
275 TDA is an alias for TDC
276 TSA is an alias for TSC
279 Evaluation of banked expressions in 65816 mode differs slightly from the
282 Instead of accepting a 24 bit address (something that is difficult for
283 the assembler to determine and would have required one more special
284 .import command), the bank and the absolute address in that bank are
288 jsl 3.$1234 ; Call subroutine at $1234 in bank 3
291 For literal values, the assembler accepts the widely used number formats:
292 A preceeding '$' denotes a hex value, a preceeding '%' denotes a
293 binary value, and a bare number is interpeted as a decimal. There are
294 currently no octal values and no floats.
301 All expressions are evaluated with (at least) 32 bit precision. An
302 expression may contain constant values and any combination of internal and
303 external symbols. Expressions that cannot be evaluated at assembly time
304 are stored inside the object file for evaluation by the linker.
305 Expressions referencing imported symbols must always be evaluated by the
308 Sometimes, the assembler must know about the size of the value that is the
309 result of an expression. This is usually the case, if a decision has to be
310 made, to generate a zero page or an absolute memory references. In this
311 case, the assembler has to make some assumptions about the result of an
315 <item> If the result of an expression is constant, the actual value is
316 checked to see if it's a byte sized expression or not.
317 <item> If the expression is explicitly casted to a byte sized expression by
318 one of the '>'/'<' operators, it is a byte expression.
319 <item> If this is not the case, and the expression contains a symbol,
320 explicitly declared as zero page symbol (by one of the .importzp or
321 .exportzp instructions), then the whole expression is assumed to be
323 <item> If the expression contains symbols that are not defined, and these
324 symbols are local symbols, the enclosing scopes are searched for a
325 symbol with the same name. If one exists and this symbol is defined,
326 it's attributes are used to determine the result size.
327 <item> In all other cases the expression is assumed to be word sized.
330 Note: If the assembler is not able to evaluate the expression at assembly
331 time, the linker will evaluate it and check for range errors as soon as
335 <bf>Boolean expressions:</bf>
337 In the context of a boolean expression, any non zero value is evaluated as
338 true, any other value to false. The result of a boolean expression is 1 if
339 it's true, and zero if it's false. There are boolean operators with extrem
340 low precedence with version 2.x (where x > 0). The <tt/.AND/ and <tt/.OR/
341 operators are shortcut operators. That is, if the result of the expression is
342 already known, after evaluating the left hand side, the right hand side is
346 Available operators sorted by precedence:
349 Op Description Precedence
350 -------------------------------------------------------------------
351 .CONCAT Builtin function 0
352 .LEFT Builtin function 0
353 .MID Builtin function 0
354 .RIGHT Builtin function 0
355 .STRING Builtin function 0
357 * Builtin pseudo variable (r/o) 1
358 .BLANK Builtin function 1
359 .CONST Builtin function 1
360 .CPU Builtin pseudo variable (r/o) 1
361 .DEFINED Builtin function 1
362 .MATCH Builtin function 1
363 .TCOUNT Builtin function 1
364 .XMATCH Builtin function 1
365 .PARAMCOUNT Builtin pseudo variable (r/o) 1
366 .REFERENCED Builtin function 1
367 :: Global namespace override 1
370 ~ Unary bitwise not 1
371 .BITNOT Unary bitwise not 1
372 < Low byte operator 1
373 > High byte operator 1
377 .MOD Modulo operation 2
379 .BITAND Bitwise and 2
381 .BITXOR Bitwise xor 2
382 << Shift left operator 2
383 .SHL Shift left operator 2
384 >> Shift right operator 2
385 .SHR Shift right operator 2
392 = Compare operation (equal) 4
393 <> Compare operation (not equal) 4
394 < Compare operation (less) 4
395 > Compare operation (greater) 4
396 <= Compare operation (less or equal) 4
397 >= Compare operation (greater or equal) 4
399 && Boolean and 5
411 To force a specific order of evaluation, braces may be used as usual.
413 Some of the pseudo variables mentioned above need some more explanation:
415 * This symbol is replaced by the value of the program
416 counter at start of the current instruction. Note, that
417 '*' yields a rvalue, that means, you cannot assign to it.
418 Use <tt/.ORG/ to set the program counter in sections with
423 <sect>Symbols and labels
426 The assembler allows you to use symbols instead of naked values to make
427 the source more readable. There are a lot of different ways to define and
428 use symbols and labels, giving a lot of flexibility.
433 <tag/Numeric constants/
435 Numeric constants are defined using the equal sign. After doing
441 may use the symbol "two" in every place where a number is expected,
442 and it is evaluated to the value 2 in this context. An example would be
449 <tag/Standard labels/
451 A label is defined by writing the name of the label at the start of
452 the line (before any instruction mnemonic, macro or pseudo
453 directive), followed by a colon. This will declare a symbol with the
454 given name and the value of the current program counter.
457 <tag/Local labels and symbols/
459 Using the <tt/.PROC/ directive, it is possible to create regions of code
460 where the names of labels and symbols are local to this region. They
461 are not know outside and cannot be accessed from there. Such regions
462 may be nested like PROCEDUREs in Pascal.
464 See the description of the <tt/.PROC/ directive for more information.
466 <tag/Cheap local labels/
468 Cheap local labels are defined like standard labels, but the name of
469 the label must begin with a special symbol (usually '@', but this can
470 be changed by the <tt/.LOCALCHAR/ directive).
472 Cheap local labels are visible only between two no cheap labels. As
473 soon as a standard symbol is encountered (this may also be a local
474 symbol if inside a region defined with the .PROC directive), the
475 cheap local symbol goes out of scope.
477 You may use cheap local labels as an easy way to reuse common label
478 names like "Loop". Here is an example:
481 Clear: lda #$00 ; Global label
483 @Loop: sta Mem,y ; Local label
487 Sub: ... ; New global label
488 bne @Loop ; ERROR: Unknown identifier!
493 If you really want to write messy code, there are also unnamed
494 labels. These labels do not have a name (you guessed that already,
495 didn't you?). A colon is used to mark the absence of the name.
497 Unnamed labels may be accessed by using the colon plus several minus
498 or plus characters as a label designator. Using the '-' characters
499 will create a back reference (use the n'th label backwards), using
500 '+' will create a forward reference (use the n'th label in forward
501 direction). An example will help to understand this:
523 As you can see from the example, unnamed labels will make even short
524 sections of code hard to understand, because you have to count labels
525 to find branch targets (this is the reason why I for my part do
526 prefer the "cheap" local labels). Nevertheless, unnamed labels are
527 convenient in some situations, so it's your decision.
529 - Using macros to define labels and constants
531 While there are drawbacks with this approach, it may be handy in some
532 situations. Using <tt/.DEFINE/, it is possible to define symbols or
533 constants that may be used elsewhere. Since the macro facility works
534 on a very low level, there is no scoping. On the other side, you may
535 also define string constants this way (this is not possible with the
542 .DEFINE version "SOS V2.3"
544 four = two * two ; Ok
547 .PROC ; Start local scope
548 two = 3 ; Will give "2 = 3" - invalid!
555 If <tt/.DEBUGINFO/ is enabled (or -g is given on the command line), global,
556 local and cheap local labels are written to the object file and will be
557 available in the symbol file via the linker. Unnamed labels are not
558 written to the object file, because they don't have a name which would
559 allow to access them.
563 <sect>Control commands
566 Here's a list of all control commands and a description, what they do:
570 <tag><tt>.A16</tt></tag>
572 Valid only in 65816 mode. Switch the accumulator to 16 bit.
574 Note: This command will not emit any code, it will tell the assembler to
575 create 16 bit operands for immediate accumulator adressing mode.
577 See also: <tt/.SMART/
580 <tag><tt>.A8</tt></tag>
582 Valid only in 65816 mode. Switch the accumulator to 8 bit.
584 Note: This command will not emit any code, it will tell the assembler to
585 create 8 bit operands for immediate accu adressing mode.
587 See also: <tt/.SMART/
590 <tag><tt>.ADDR</tt></tag>
592 Define word sized data. In 6502 mode, this is an alias for <tt/.WORD/ and
593 may be used for better readability if the data words are address values.
594 In 65816 mode, the address is forced to be 16 bit wide to fit into the
595 current segment. See also <tt/.FARADDR/. The command must be followed by a
596 sequence of (not necessarily constant) expressions.
601 .addr $0D00, $AF13, _Clear
605 <tag><tt>.ALIGN</tt></tag>
607 Align data to a given boundary. The command expects a constant integer
608 argument that must be a power of two, plus an optional second argument
609 in byte range. If there is a second argument, it is used as fill value,
610 otherwise the value defined in the linker configuration file is used
611 (the default for this value is zero).
613 Since alignment depends on the base address of the module, you must
614 give the same (or a greater) alignment for the segment when linking.
615 The linker will give you a warning, if you don't do that.
624 <tag><tt>.ASCIIZ</tt></tag>
626 Define a string with a trailing zero.
631 Msg: .asciiz "Hello world"
634 This will put the string "Hello world" followed by a binary zero into
635 the current segment. There may be more strings separated by commas, but
636 the binary zero is only appended once (after the last one).
639 <tag><tt>.AUTOIMPORT</tt></tag>
641 Is followd by a plus or a minus character. When switched on (using a
642 +), undefined symbols are automatically marked as import instead of
643 giving errors. When switched off (which is the default so this does not
644 make much sense), this does not happen and an error message is
645 displayed. The state of the autoimport flag is evaluated when the
646 complete source was translated, before outputing actual code, so it is
647 <em/not/ possible to switch this feature on or off for separate sections
648 of code. The last setting is used for all symbols.
650 You should probably not use this switch because it delays error
651 messages about undefined symbols until the link stage. The cc65
652 compiler (which is supposed to produce correct assembler code in all
653 circumstances, something which is not true for most assembler
654 programmers) will insert this command to avoid importing each and every
655 routine from the runtime library.
660 .autoimport + ; Switch on auto import
664 <tag><tt>.BLANK</tt></tag>
666 Builtin function. The function evaluates its argument in braces and
667 yields "false" if the argument is non blank (there is an argument), and
668 "true" if there is no argument. As an example, the <tt/.IFBLANK/ statement
676 <tag><tt>.BSS</tt></tag>
678 Switch to the BSS segment. The name of the BSS segment is always "BSS",
679 so this is a shortcut for
685 See also the <tt/.SEGMENT/ command.
688 <tag><tt>.BYTE</tt></tag>
690 Define byte sized data. Must be followed by a sequence of (byte ranged)
691 expressions or strings.
696 .byte "Hello world", $0D, $00
700 <tag><tt>.CASE</tt></tag>
702 Switch on or off case sensitivity on identifiers. The default is off
703 (that is, identifiers are case sensitive), but may be changed by the
704 -i switch on the command line.
705 The command must be followed by a '+' or '-' character to switch the
706 option on or off respectively.
711 .case - ; Identifiers are not case sensitive
715 <tag><tt>.CODE</tt></tag>
717 Switch to the CODE segment. The name of the CODE segment is always
718 "CODE", so this is a shortcut for
724 See also the <tt/.SEGMENT/ command.
727 <tag><tt>.CONCAT</tt></tag>
729 Builtin function. The function allows to concatenate a list of string
730 constants separated by commas. The result is a string constant that
731 is the concatentation of all arguments. This function is most useful
732 in macros and when used together with the <tt/.STRING/ builtin function.
733 The function may be used in any case where a string constant is
739 .include .concat ("myheader", ".", "inc)
742 This is the same as the command
745 .include "myheader.inc"
749 <tag><tt>.CONST</tt></tag>
751 Builtin function. The function evaluates its argument in braces and
752 yields "true" if the argument is a constant expression (that is, an
753 expression that yields a constant value at assembly time) and "false"
754 otherwise. As an example, the .IFCONST statement may be replaced by
761 <tag><tt>.CPU</tt></tag>
763 Reading this pseudo variable will give a constant integer value that
764 tells which instruction set is currently enabled. Possible values are:
773 It may be used to replace the .IFPxx pseudo instructions or to construct
774 even more complex expressions.
779 .if (.cpu = 0) .or (.cpu = 1)
791 <tag><tt>.DATA</tt></tag>
793 Switch to the DATA segment. The name of the DATA segment is always
794 "DATA", so this is a shortcut for
800 See also the <tt/.SEGMENT/ command.
803 <tag><tt>.DBYT</tt></tag>
805 Define word sized data with the hi and lo bytes swapped (use <tt/.WORD/ to
806 create word sized data in native 65XX format). Must be followed by a
807 sequence of (word ranged) expressions.
815 This will emit the bytes
821 into the current segment in that order.
824 <tag><tt>.DEBUGINFO</tt></tag>
826 Switch on or off debug info generation. The default is off (that is,
827 the object file will not contain debug infos), but may be changed by the
828 -g switch on the command line.
829 The command must be followed by a '+' or '-' character to switch the
830 option on or off respectively.
835 .debuginfo + ; Generate debug info
839 <tag><tt>.DEFINE</tt></tag>
841 Start a define style macro definition. The command is followed by an
842 identifier (the macro name) and optionally by a list of formal arguments
844 See separate section about macros.
847 <tag><tt>.DEF, .DEFINED</tt></tag>
849 Builtin function. The function expects an identifier as argument in
850 braces. The argument is evaluated, and the function yields "true" if the
851 identifier is a symbol that is already defined somewhere in the source
852 file up to the current position. Otherwise the function yields false. As
853 an example, the <tt/.IFDEF/ statement may be replaced by
860 <tag><tt>.DWORD</tt></tag>
862 Define dword sized data (4 bytes) Must be followed by a sequence of
868 .dword $12344512, $12FA489
872 <tag><tt>.ELSE</tt></tag>
874 Conditional assembly: Reverse the current condition.
877 <tag><tt>.ELSEIF</tt></tag>
879 Conditional assembly: Reverse current condition and test a new one.
882 <tag><tt>.END</tt></tag>
884 Forced end of assembly. Assembly stops at this point, even if the command
885 is read from an include file.
888 <tag><tt>.ENDIF</tt></tag>
890 Conditional assembly: Close a <tt/.IF.../ or <tt/.ELSE/ branch.
893 <tag><tt>.ENDMAC, .ENDMACRO</tt></tag>
895 End of macro definition (see separate section).
898 <tag><tt>.ENDPROC</tt></tag>
900 End of local lexical level (see <tt/.PROC/).
903 <tag><tt>.ERROR</tt></tag>
905 Force an assembly error. The assembler will output an error message
906 preceeded by "User error" and will <em/not/ produce an object file.
908 This command may be used to check for initial conditions that must be
909 set before assembling a source file.
919 .error "Must define foo or bar!"
923 See also the <tt/.WARNING/ and <tt/.OUT/ directives.
926 <tag><tt>.EXITMAC, .EXITMACRO</tt></tag>
928 Abort a macro expansion immidiately. This command is often useful in
929 recursive macros. See separate chapter about macros.
932 <tag><tt>.EXPORT</tt></tag>
934 Make symbols accessible from other modules. Must be followed by a comma
935 separated list of symbols to export.
944 <tag><tt>.EXPORTZP</tt></tag>
946 Make symbols accessible from other modules. Must be followed by a comma
947 separated list of symbols to export. The exported symbols are explicitly
948 marked as zero page symols.
957 <tag><tt>.FARADDR</tt></tag>
959 Define far (24 bit) address data. The command must be followed by a
960 sequence of (not necessarily constant) expressions.
965 .faraddr DrawCircle, DrawRectangle, DrawHexagon
969 <tag><tt>.FEATURE</tt></tag>
971 This directive may be used to enable one or more compatibility features
972 of the assembler. While the use of <tt/.FEATURE/ should be avoided when
973 possible, it may be useful when porting sources written for other
974 assemblers. There is no way to switch a feature off, once you have
981 will enable the feature until end of assembly is reached.
983 The following features are available:
987 <tag><tt>dollar_is_pc</tt></tag>
989 The dollar sign may be used as an alias for the star (`*'), which
990 gives the value of the current PC in expressions.
991 Note: Assignment to the pseudo variable is not allowed.
993 <tag><tt>labels_without_colons</tt></tag>
995 Allow labels without a trailing colon. These labels are only accepted,
996 if they start at the beginning of a line (no leading white space).
998 <tag><tt>loose_string_term</tt></tag>
1000 Accept single quotes as well as double quotes as terminators for string
1003 <tag><tt>at_in_identifiers</tt></tag>
1005 Accept the at character (`@') as a valid character in identifiers. The
1006 at character is not allowed to start an identifier, even with this
1009 <tag><tt>dollar_in_identifiers</tt></tag>
1011 Accept the dollar sign (`$') as a valid character in identifiers. The
1012 at character is not allowed to start an identifier, even with this
1018 <tag><tt>.FILEOPT, .FOPT</tt></tag>
1020 Insert an option string into the object file. There are two forms of
1021 this command, one specifies the option by a keyword, the second
1022 specifies it as a number. Since usage of the second one needs knowledge
1023 of the internal encoding, its use is not recommended and I will only
1024 describe the first form here.
1026 The command is followed by one of the keywords
1034 a comma and a string. The option is written into the object file
1035 together with the string value. This is currently unidirectional and
1036 there is no way to actually use these options once they are in the
1042 .fileopt comment, "Code stolen from my brother"
1043 .fileopt compiler, "BASIC 2.0"
1044 .fopt author, "J. R. User"
1048 <tag><tt>.GLOBAL</tt></tag>
1050 Declare symbols as global. Must be followed by a comma separated list
1051 of symbols to declare. Symbols from the list, that are defined somewhere
1052 in the source, are exported, all others are imported. An additional
1053 explicit <tt/.IMPORT/ or <tt/.EXPORT/ command for the same symbol is
1063 <tag><tt>.GLOBALZP</tt></tag>
1065 Declare symbols as global. Must be followed by a comma separated list
1066 of symbols to declare. Symbols from the list, that are defined
1067 somewhere in the source, are exported, all others are imported. An
1068 additional explicit <tt/.IMPORT/ or <tt/.EXPORT/ command for the same
1069 symbol is explicitly allowed. The symbols in the list are explicitly
1070 marked as zero page symols.
1079 <tag><tt>.I16</tt></tag>
1081 Valid only in 65816 mode. Switch the index registers to 16 bit.
1083 Note: This command will not emit any code, it will tell the assembler to
1084 create 16 bit operands for immediate operands.
1086 See also the <tt/.SMART/ command.
1089 <tag><tt>.I8</tt></tag>
1091 Valid only in 65816 mode. Switch the index registers to 8 bit.
1093 Note: This command will not emit any code, it will tell the assembler to
1094 create 8 bit operands for immediate operands.
1096 See also the <tt/.SMART/ command.
1099 <tag><tt>.IF</tt></tag>
1101 Conditional assembly: Evalute an expression and switch assembler output
1102 on or off depending on the expression. The expression must be a constant
1103 expression, that is, all operands must be defined.
1105 A expression value of zero evaluates to FALSE, any other value evaluates
1109 <tag><tt>.IFBLANK</tt></tag>
1111 Conditional assembly: Check if there are any remaining tokens in this
1112 line, and evaluate to FALSE if this is the case, and to TRUE otherwise.
1113 If the condition is not true, further lines are not assembled until
1114 an <tt/.ELSE/, <tt/.ELSEIF/ or <tt/.ENDIF/ directive.
1116 This command is often used to check if a macro parameter was given.
1117 Since an empty macro parameter will evaluate to nothing, the condition
1118 will evaluate to FALSE if an empty parameter was given.
1132 See also: <tt/.BLANK/
1135 <tag><tt>.IFCONST</tt></tag>
1137 Conditional assembly: Evaluate an expression and switch assembler output
1138 on or off depending on the constness of the expression.
1140 A const expression evaluates to to TRUE, a non const expression (one
1141 containing an imported or currently undefined symbol) evaluates to
1144 See also: <tt/.CONST/
1147 <tag><tt>.IFDEF</tt></tag>
1149 Conditional assembly: Check if a symbol is defined. Must be followed by
1150 a symbol name. The condition is true if the the given symbol is already
1151 defined, and false otherwise.
1153 See also: <tt/.DEFINED/
1156 <tag><tt>.IFNBLANK</tt></tag>
1158 Conditional assembly: Check if there are any remaining tokens in this
1159 line, and evaluate to TRUE if this is the case, and to FALSE otherwise.
1160 If the condition is not true, further lines are not assembled until
1161 an <tt/.ELSE/, <tt/.ELSEIF/ or <tt/.ENDIF/ directive.
1163 This command is often used to check if a macro parameter was given.
1164 Since an empty macro parameter will evaluate to nothing, the condition
1165 will evaluate to FALSE if an empty parameter was given.
1178 See also: <tt/.BLANK/
1181 <tag><tt>.IFNDEF</tt></tag>
1183 Conditional assembly: Check if a symbol is defined. Must be followed by
1184 a symbol name. The condition is true if the the given symbol is not
1185 defined, and false otherwise.
1187 See also: <tt/.DEFINED/
1190 <tag><tt>.IFNREF</tt></tag>
1192 Conditional assembly: Check if a symbol is referenced. Must be followed
1193 by a symbol name. The condition is true if if the the given symbol was
1194 not referenced before, and false otherwise.
1196 See also: <tt/.REFERENCED/
1199 <tag><tt>.IFP02</tt></tag>
1201 Conditional assembly: Check if the assembler is currently in 6502 mode
1202 (see <tt/.P02/ command).
1205 <tag><tt>.IFP816</tt></tag>
1207 Conditional assembly: Check if the assembler is currently in 65816 mode
1208 (see <tt/.P816/ command).
1211 <tag><tt>.IFPC02</tt></tag>
1213 Conditional assembly: Check if the assembler is currently in 65C02 mode
1214 (see <tt/.PC02/ command).
1217 <tag><tt>.IFREF</tt></tag>
1219 Conditional assembly: Check if a symbol is referenced. Must be followed
1220 by a symbol name. The condition is true if if the the given symbol was
1221 referenced before, and false otherwise.
1223 This command may be used to build subroutine libraries in include files
1224 (you may use separate object modules for this purpose too).
1229 .ifref ToHex ; If someone used this subroutine
1230 ToHex: tay ; Define subroutine
1236 See also: <tt/.REFERENCED/
1239 <tag><tt>.IMPORT</tt></tag>
1241 Import a symbol from another module. The command is followed by a comma
1242 separated list of symbols to import.
1251 <tag><tt>.IMPORTZP</tt></tag>
1253 Import a symbol from another module. The command is followed by a comma
1254 separated list of symbols to import. The symbols are explicitly imported
1255 as zero page symbols (that is, symbols with values in byte range).
1264 <tag><tt>.INCBIN</tt></tag>
1266 Include a file as binary data. The command expects a string argument
1267 that is the name of a file to include literally in the current segment.
1272 .incbin "sprites.dat"
1276 <tag><tt>.INCLUDE</tt></tag>
1278 Include another file. Include files may be nested up to a depth of 16.
1287 <tag><tt>.LEFT</tt></tag>
1289 Builtin function. Extracts the left part of a given token list.
1294 .LEFT (<int expr>, <token list>)
1297 The first integer expression gives the number of tokens to extract from
1298 the token list. The second argument is the token list itself.
1302 To check in a macro if the given argument has a '#' as first token
1303 (immidiate addressing mode), use something like this:
1308 .if (.match (.left (1, arg), #))
1310 ; ldax called with immidiate operand
1318 See also the <tt/.MID/ and <tt/.RIGHT/ builtin functions.
1321 <tag><tt>.LINECONT</tt></tag>
1323 Switch on or off line continuations using the backslash character
1324 before a newline. The option is off by default.
1325 Note: Line continuations do not work in a comment. A backslash at the
1326 end of a comment is treated as part of the comment and does not trigger
1328 The command must be followed by a '+' or '-' character to switch the
1329 option on or off respectively.
1334 .linecont + ; Allow line continuations
1337 #$20 ; This is legal now
1341 <tag><tt>.LIST</tt></tag>
1343 Enable output to the listing. The command must be followed by a boolean
1344 switch ("on", "off", "+" or "-") and will enable or disable listing
1346 The option has no effect if the listing is not enabled by the command line
1347 switch -l. If -l is used, an internal counter is set to 1. Lines are output
1348 to the listing file, if the counter is greater than zero, and suppressed if
1349 the counter is zero. Each use of <tt/.LIST/ will increment or decrement the
1355 .list on ; Enable listing output
1359 <tag><tt>.LISTBYTES</tt></tag>
1361 Set, how many bytes are shown in the listing for one source line. The
1362 default is 12, so the listing will show only the first 12 bytes for any
1363 source line that generates more than 12 bytes of code or data.
1364 The directive needs an argument, which is either "unlimited", or an
1365 integer constant in the range 4..255.
1370 .listbytes unlimited ; List all bytes
1371 .listbytes 12 ; List the first 12 bytes
1372 .incbin "data.bin" ; Include large binary file
1376 <tag><tt>.LOCAL</tt></tag>
1378 This command may only be used inside a macro definition. It declares a
1379 list of identifiers as local to the macro expansion.
1381 A problem when using macros are labels: Since they don't change their
1382 name, you get a "duplicate symbol" error if the macro is expanded the
1383 second time. Labels declared with <tt/.LOCAL/ have their name mapped to
1384 an internal unique name (<tt/___ABCD__/) with each macro invocation.
1386 Some other assemblers start a new lexical block inside a macro
1387 expansion. This has some drawbacks however, since that will not allow
1388 <em/any/ symbol to be visible outside a macro, a feature that is sometimes
1389 useful. The <tt/.LOCAL/ command is in my eyes a better way to address
1392 You get an error when using <tt/.LOCAL/ outside a macro.
1395 <tag><tt>.LOCALCHAR</tt></tag>
1397 Defines the character that start "cheap" local labels. You may use one
1398 of '@' and '?' as start character. The default is '@'.
1400 Cheap local labels are labels that are visible only between two non
1401 cheap labels. This way you can reuse identifiers like "<tt/loop/" without
1402 using explicit lexical nesting.
1409 Clear: lda #$00 ; Global label
1410 ?Loop: sta Mem,y ; Local label
1414 Sub: ... ; New global label
1415 bne ?Loop ; ERROR: Unknown identifier!
1419 <tag><tt>.MACPACK</tt></tag>
1421 Insert a predefined macro package. The command is followed by an
1422 identifier specifying the macro package to insert. Available macro
1425 generic Defines generic macros like add and sub.
1426 longbranch Defines conditional long jump macros.
1428 Including a macro package twice, or including a macro package that
1429 redefines already existing macros will lead to an error.
1434 .macpack longbranch ; Include macro package
1436 cmp #$20 ; Set condition codes
1437 jne Label ; Jump long on condition
1440 See separate section about macros packages.
1443 <tag><tt>.MAC, .MACRO</tt></tag>
1445 Start a classic macro definition. The command is followed by an identifier
1446 (the macro name) and optionally by a comma separated list of identifiers
1447 that are macro parameters.
1448 See separate section about macros.
1451 <tag><tt>.MATCH</tt></tag>
1453 Builtin function. Matches two token lists against each other. This is
1454 most useful within macros, since macros are not stored as strings, but
1460 .MATCH(<token list #1>, <token list #2>)
1463 Both token list may contain arbitrary tokens with the exception of the
1464 terminator token (comma resp. right parenthesis) and
1471 Often a macro parameter is used for any of the token lists.
1473 Please note that the function does only compare tokens, not token
1474 attributes. So any number is equal to any other number, regardless of
1475 the actual value. The same is true for strings. If you need to compare
1476 tokens <em/and/ token attributes, use the <tt/.XMATCH/ function.
1480 Assume the macro <tt/ASR/, that will shift right the accumulator by one, while
1481 honoring the sign bit. The builtin processor instructions will allow an
1482 optional "A" for accu addressing for instructions like <tt/ROL/ and <tt/ROR/.
1483 We will use the <tt/.MATCH/ function to check for this and print and error
1489 .if (.not .blank(arg)) .and (.not .match (arg, a))
1490 .error "Syntax error"
1493 cmp #$80 ; Bit 7 into carry
1494 lsr a ; Shit carry into bit 7
1499 The macro will only accept no arguments, or one argument that must be the
1500 reserved keyword "A".
1503 <tag><tt>.MID</tt></tag>
1505 Builtin function. Takes a starting index, a count and a token list as
1506 arguments. Will return part of the token list.
1511 .MID (<int expr>, <int expr>, <token list>)
1514 The first integer expression gives the starting token in the list (the
1515 first token has index 0). The second integer expression gives the number
1516 of tokens to extract from the token list. The third argument is the
1521 To check in a macro if the given argument has a '<tt/#/' as first token
1522 (immidiate addressing mode), use something like this:
1527 .if (.match (.mid (0, 1, arg), #))
1529 ; ldax called with immidiate operand
1537 See also the <tt/.LEFT/ and <tt/.RIGHT/ builtin functions.
1540 <tag><tt>.ORG</tt></tag>
1542 Start a section of absolute code. The command is followed by a constant
1543 expression that gives the new PC counter location for which the code is
1544 assembled. Use <tt/.RELOC/ to switch back to relocatable code.
1546 You may not switch segments while inside a section of absolute code.
1551 .org $7FF ; Emit code starting at $7FF
1555 <tag><tt>.OUT</tt></tag>
1557 Output a string to the console without producing an error. This command
1558 is similiar to <tt/.ERROR/, however, it does not force an assembler error
1559 that prevents the creation of an object file.
1564 .out "This code was written by the codebuster(tm)"
1567 See also the <tt/.WARNING/ and <tt/.ERROR/ directives.
1570 <tag><tt>.P02</tt></tag>
1572 Enable the 6502 instruction set, disable 65C02 and 65816 instructions.
1573 This is the default if not overridden by the <tt/--cpu/ command line
1577 <tag><tt>.P816</tt></tag>
1579 Enable the 65816 instruction set. This is a superset of the 65C02 and
1580 6502 instruction sets.
1583 <tag><tt>.PAGELEN, .PAGELENGTH</tt></tag>
1585 Set the page length for the listing. Must be followed by an integer
1586 constant. The value may be "unlimited", or in the range 32 to 127. The
1587 statement has no effect if no listing is generated. The default value
1588 is -1 but may be overridden by the <tt/--pagelength/ command line option.
1589 Beware: Since the listing is generated after assembly is complete, you
1590 cannot use multiple line lengths with one source. Instead, the value
1591 set with the last <tt/.PAGELENGTH/ is used.
1596 .pagelength 66 ; Use 66 lines per listing page
1598 .pagelength unlimited ; Unlimited page length
1602 <tag><tt>.PARAMCOUNT</tt></tag>
1604 This builtin pseudo variable is only available in macros. It is replaced
1605 by the actual number of parameters that were given in the macro
1611 .macro foo arg1, arg2, arg3
1612 .if .paramcount <> 3
1613 .error "Too few parameters for macro foo"
1620 <tag><tt>.PC02</tt></tag>
1622 Enable the 65C02 instructions set. This instruction set includes all
1626 <tag><tt>.PROC</tt></tag>
1628 Start a nested lexical level. All new symbols from now on are in the
1629 local lexical level and are not accessible from outside. Symbols defined
1630 outside this local level may be accessed as long as their names are not
1631 used for new symbols inside the level. Symbols names in other lexical
1632 levels do not clash, so you may use the same names for identifiers. The
1633 lexical level ends when the <tt/.ENDPROC/ command is read. Lexical levels
1634 may be nested up to a depth of 16.
1636 The command may be followed by an identifier, in this case the
1637 identifier is declared in the outer level as a label having the value of
1638 the program counter at the start of the lexical level.
1640 Note: Macro names are always in the global level and in a separate name
1641 space. There is no special reason for this, it's just that I've never
1642 had any need for local macro definitions.
1647 .proc Clear ; Define Clear subroutine, start new level
1649 L1: sta Mem,y ; L1 is local and does not cause a
1650 ; duplicate symbol error if used in other
1653 bne L1 ; Reference local symbol
1655 .endproc ; Leave lexical level
1659 <tag><tt>.REF, .REFERENCED</tt></tag>
1661 Builtin function. The function expects an identifier as argument in
1662 braces. The argument is evaluated, and the function yields "true" if the
1663 identifier is a symbol that has already been referenced somewhere in the
1664 source file up to the current position. Otherwise the function yields
1665 false. As an example, the <tt/.IFREF/ statement may be replaced by
1672 <tag><tt>.RELOC</tt></tag>
1674 Switch back to relocatable mode. See the <tt/.ORG/ command.
1677 <tag><tt>.RES</tt></tag>
1679 Reserve storage. The command is followed by one or two constant
1680 expressions. The first one is mandatory and defines, how many bytes of
1681 storage should be defined. The second, optional expression must by a
1682 constant byte value that will be used as value of the data. If there
1683 is no fill value given, the linker will use the value defined in the
1684 linker configuration file (default: zero).
1689 ; Reserve 12 bytes of memory with value $AA
1694 <tag><tt>.RIGHT</tt></tag>
1696 Builtin function. Extracts the right part of a given token list.
1701 .RIGHT (<int expr>, <token list>)
1704 The first integer expression gives the number of tokens to extract from
1705 the token list. The second argument is the token list itself.
1707 See also the <tt/.LEFT/ and <tt/.MID/ builtin functions.
1710 <tag><tt>.RODATA</tt></tag>
1712 Switch to the RODATA segment. The name of the RODATA segment is always
1713 "RODATA", so this is a shortcut for
1719 The RODATA segment is a segment that is used by the compiler for
1720 readonly data like string constants. See also the <tt/.SEGMENT/ command.
1723 <tag><tt>.SEGMENT</tt></tag>
1725 Switch to another segment. Code and data is always emitted into a
1726 segment, that is, a named section of data. The default segment is
1727 "CODE". There may be up to 254 different segments per object file
1728 (and up to 65534 per executable). There are shortcut commands for
1729 the most common segments ("CODE", "DATA" and "BSS").
1731 The command is followed by a string containing the segment name (there
1732 are some constraints for the name - as a rule of thumb use only those
1733 segment names that would also be valid identifiers). There may also be
1734 an optional attribute separated by a comma. Valid attributes are
1735 "<tt/zeropage/" and "<tt/absolute/".
1737 When specifying a segment for the first time, "absolute" is the
1738 default. For all other uses, the attribute specified the first time
1741 "absolute" means that this is a segment with absolute addressing. That
1742 is, the segment will reside somewhere in core memory outside the zero
1743 page. "zeropage" means the opposite: The segment will be placed in the
1744 zero page and direct (short) addressing is possible for data in this
1747 Beware: Only labels in a segment with the zeropage attribute are marked
1748 as reachable by short addressing. The `*' (PC counter) operator will
1749 work as in other segments and will create absolute variable values.
1754 .segment "ROM2" ; Switch to ROM2 segment
1755 .segment "ZP2", zeropage ; New direct segment
1756 .segment "ZP2" ; Ok, will use last attribute
1757 .segment "ZP2", absolute ; Error, redecl mismatch
1761 <tag><tt>.SMART</tt></tag>
1763 Switch on or off smart mode. The command must be followed by a '+' or
1764 '-' character to switch the option on or off respectively. The default
1765 is off (that is, the assembler doesn't try to be smart), but this
1766 default may be changed by the -s switch on the command line.
1768 In smart mode the assembler will track usage of the <tt/REP/ and <tt/SEP/
1769 instructions in 65816 mode and update the operand sizes accordingly. If
1770 the operand of such an instruction cannot be evaluated by the assembler
1771 (for example, because the operand is an imported symbol), a warning is
1772 issued. Beware: Since the assembler cannot trace the execution flow this
1773 may lead to false results in some cases. If in doubt, use the <tt/.Inn/ and
1774 <tt/.Ann/ instructions to tell the assembler about the current settings.
1780 .smart - ; Stop being smart
1784 <tag><tt>.STRING</tt></tag>
1786 Builtin function. The function accepts an argument in braces and
1787 converts this argument into a string constant. The argument may be an
1788 identifier, or a constant numeric value.
1789 Since you can use a string in the first place, the use of the function
1790 may not be obvious. However, it is useful in macros, or more complex
1796 ; Emulate other assemblers:
1798 .segment .string(name)
1803 <tag><tt>.TCOUNT</tt></tag>
1805 Builtin function. The function accepts a token list in braces. The
1806 function result is the number of tokens given as argument.
1810 The <tt/ldax/ macro accepts the '#' token to denote immidiate addressing (as
1811 with the normal 6502 instructions). To translate it into two separate 8 bit
1812 load instructions, the '#' token has to get stripped from the argument:
1816 .if (.match (.mid (0, 1, arg), #))
1817 ; ldax called with immidiate operand
1818 lda #<(.right (.tcount (arg)-1, arg))
1819 ldx #>(.right (.tcount (arg)-1, arg))
1827 <tag><tt>.WARNING</tt></tag>
1829 Force an assembly warning. The assembler will output a warning message
1830 preceeded by "User warning". This warning will always be output, even
1831 if other warnings are disabled with the <tt/-W0/ command line option.
1833 This command may be used to output possible problems when assembling
1842 .warning "Forward jump in jne, cannot optimize!"
1852 See also the <tt/.ERROR/ and <tt/.OUT/ directives.
1855 <tag><tt>.WORD</tt></tag>
1857 Define word sized data. Must be followed by a sequence of (word ranged,
1858 but not necessarily constant) expressions.
1863 .word $0D00, $AF13, _Clear
1867 <tag><tt>.ZEROPAGE</tt></tag>
1869 Switch to the ZEROPAGE segment and mark it as direct (zeropage) segment.
1870 The name of the ZEROPAGE segment is always "ZEROPAGE", so this is a
1874 .segment "ZEROPAGE", zeropage
1877 Because of the "zeropage" attribute, labels declared in this segment are
1878 addressed using direct addressing mode if possible. You <em/must/ instruct
1879 the linker to place this segment somewhere in the address range 0..$FF
1880 otherwise you will get errors.
1889 Macros may be thought of as "parametrized super instructions". Macros are
1890 sequences of tokens that have a name. If that name is used in the source
1891 file, the macro is "expanded", that is, it is replaced by the tokens that
1892 were specified when the macro was defined.
1894 In it's simplest form, a macro does not have parameters. Here's an
1898 .macro asr ; Arithmetic shift right
1899 cmp #$80 ; Put bit 7 into carry
1900 ror ; Rotate right with carry
1904 The macro above consists of two real instructions, that are inserted into
1905 the code, whenever the macro is expanded. Macro expansion is simply done
1906 by using the name, like this:
1914 When using macro parameters, macros can be even more useful:
1928 When calling the macro, you may give a parameter, and each occurence of
1929 the name "addr" in the macro definition will be replaced by the given
1948 A macro may have more than one parameter, in this case, the parameters
1949 are separated by commas. You are free to give less parameters than the
1950 macro actually takes in the definition. You may also leave intermediate
1951 parameters empty. Empty parameters are replaced by empty space (that is,
1952 they are removed when the macro is exanded). If you have a look at our
1953 macro definition above, you will see, that replacing the "addr" parameter
1954 by nothing will lead to wrong code in most lines. To help you, writing
1955 macros with a variable parameter list, there are some control commands:
1957 <tt/.IFBLANK/ tests the rest of the line and returns true, if there are any
1958 tokens on the remainder of the line. Since empty parameters are replaced by
1959 nothing, this may be used to test if a given parameter is empty.
1960 <tt/.IFNBLANK/ tests the opposite.
1962 Look at this example:
1965 .macro ldaxy a, x, y
1978 This macro may be called as follows:
1981 ldaxy 1, 2, 3 ; Load all three registers
1983 ldaxy 1, , 3 ; Load only a and y
1985 ldaxy , , 3 ; Load y only
1988 There's another helper command for determining, which macro parameters are
1989 valid: <tt/.PARAMCOUNT/. This command is replaced by the parameter count
1990 given, <em/including/ intermediate empty macro parameters:
1993 ldaxy 1 ; .PARAMCOUNT = 1
1994 ldaxy 1,,3 ; .PARAMCOUNT = 3
1995 ldaxy 1,2 ; .PARAMCOUNT = 2
1996 ldaxy 1, ; .PARAMCOUNT = 2
1997 ldaxy 1,2,3 ; .PARAMCOUNT = 3
2000 Macros may be used recursively:
2003 .macro push r1, r2, r3
2012 There's also a special macro to help writing recursive macros:
2013 <tt/.EXITMACRO/. This command will stop macro expansion immidiately:
2016 .macro push r1, r2, r3, r4, r5, r6, r7
2018 ; First parameter is empty
2024 push r2, r3, r4, r5, r6, r7
2028 When expanding this macro, the expansion will push all given parameters
2029 until an empty one is encountered. The macro may be called like this:
2032 push $20, $21, $32 ; Push 3 ZP locations
2033 push $21 ; Push one ZP location
2036 Now, with recursive macros, <tt/.IFBLANK/ and <tt/.PARAMCOUNT/, what else do
2037 you need? Have a look at the inc16 macro above. Here is it again:
2051 If you have a closer look at the code, you will notice, that it could be
2052 written more efficiently, like this:
2066 But imagine what happens, if you use this macro twice? Since the label
2067 "Skip" has the same name both times, you get a "duplicate symbol" error.
2068 Without a way to circumvent this problem, macros are not as useful, as
2069 they could be. One solution is, to start a new lexical block inside the
2086 Now the label is local to the block and not visible outside. However,
2087 sometimes you want a label inside the macro to be visible outside. To make
2088 that possible, there's a new command that's only usable inside a macro
2089 definition: <tt/.LOCAL/. <tt/.LOCAL/ declares one or more symbols as local to
2090 the macro expansion. The names of local variables are replaced by a unique
2091 name in each separate macro expansion. So we could also solve the problem
2092 above by using <tt/.LOCAL/:
2096 .local Skip ; Make Skip a local symbol
2103 Skip: ; Not visible outside
2107 Starting with version 2.5 of the assembler, there is a second macro type
2108 available: C style macros using the <tt/.DEFINE/ directive. These macros are
2109 similar to the classic macro type speified above, but behaviour is sometimes
2114 <item> Macros defined with <tt/.DEFINE/ may not span more than a line. You
2115 may use line continuation (see <tt/.LINECONT/) to spread the
2116 definition over more than one line for increased readability, but the
2117 macro itself does not contain an end-of-line token.
2119 <item> Macros defined with <tt/.DEFINE/ share the name space with classic
2120 macros, but they are detected and replaced at the scanner level. While
2121 classic macros may be used in every place, where a mnemonic or other
2122 directive is allowed, <tt/.DEFINE/ style macros are allowed anywhere
2123 in a line. So they are more versatile in some situations.
2125 <item> <tt/.DEFINE/ style macros may take parameters. While classic macros
2126 may have empty parameters, this is not true for <tt/.DEFINE/ style
2127 macros. For this macro type, the number of actual parameters must
2128 match exactly the number of formal parameters.
2130 To make this possible, formal parameters are enclosed in braces when
2131 defining the macro. If there are no parameters, the empty braces may
2134 <item> Since <tt/.DEFINE/ style macros may not contain end-of-line tokens,
2135 there are things that cannot be done. They may not contain several
2136 processor instructions for example. So, while some things may be done
2137 with both macro types, each type has special usages. The types
2138 complement each other.
2142 Let's look at a few examples to make the advantages and disadvantages
2145 To emulate assemblers that use "<tt/EQU/" instead of "<tt/=/" you may use the
2146 following <tt/.DEFINE/:
2151 foo EQU $1234 ; This is accepted now
2154 You may use the directive to define string constants used elsewhere:
2157 ; Define the version number
2158 .define VERSION "12.3a"
2164 Macros with parameters may also be useful:
2167 .define DEBUG(message) .out message
2169 DEBUG "Assembling include file #3"
2172 Note that, while formal parameters have to be placed in braces, this is
2173 not true for the actual parameters. Beware: Since the assembler cannot
2174 detect the end of one parameter, only the first token is used. If you
2175 don't like that, use classic macros instead:
2183 (This is an example where a problem can be solved with both macro types).
2187 <sect>Macro packages
2190 Using the <tt/.MACPACK/ directive, predefined macro packages may be included
2191 with just one command. Available macro packages are:
2195 <tag><tt>generic</tt></tag>
2197 This macro package defines macros that are useful in almost any program.
2198 Currently, two macros are defined:
2213 <tag><tt>longbranch</tt></tag>
2215 This macro package defines long conditional jumps. They are named like the
2216 short counterpart but with the 'b' replaced by a 'j'. Here is a sample
2217 definition for the "<tt/jeq/" macro, the other macros are built using the
2222 .if .def(Target) .and ((*+2)-(Target) <= 127)
2231 All macros expand to a short branch, if the label is already defined (back
2232 jump) and is reachable with a short jump. Otherwise the macro expands to a
2233 conditional branch with the branch condition inverted, followed by an
2234 absolute jump to the actual branch target.
2236 The package defines the following macros:
2239 jeq, jne, jmi, jpl, jcs, jcc, jvs, jvc
2248 If you have problems using the assembler, if you find any bugs, or if
2249 you're doing something interesting with the assembler, I would be glad to
2250 hear from you. Feel free to contact me by email
2251 (<htmlurl url="uz@musoftware.de" name="uz@musoftware.de">).
2258 ca65 (and all cc65 binutils) are (C) Copyright 1998-2000 Ullrich von
2259 Bassewitz. For usage of the binaries and/or sources the following
2260 conditions do apply:
2262 This software is provided 'as-is', without any expressed or implied
2263 warranty. In no event will the authors be held liable for any damages
2264 arising from the use of this software.
2266 Permission is granted to anyone to use this software for any purpose,
2267 including commercial applications, and to alter it and redistribute it
2268 freely, subject to the following restrictions:
2271 <item> The origin of this software must not be misrepresented; you must not
2272 claim that you wrote the original software. If you use this software
2273 in a product, an acknowledgment in the product documentation would be
2274 appreciated but is not required.
2275 <item> Altered source versions must be plainly marked as such, and must not
2276 be misrepresented as being the original software.
2277 <item> This notice may not be removed or altered from any source