-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathca65.html
More file actions
6948 lines (5681 loc) · 235 KB
/
ca65.html
File metadata and controls
6948 lines (5681 loc) · 235 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<LINK REL="stylesheet" TYPE="text/css" HREF="doc.css">
<META NAME="GENERATOR" CONTENT="LinuxDoc-Tools 0.9.83">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<TITLE>ca65 Users Guide</TITLE>
</HEAD>
<BODY>
<H1>ca65 Users Guide</H1>
<H2>
<A HREF="mailto:uz@cc65.org">Ullrich von Bassewitz</A>,<BR>
<A HREF="mailto:greg.king5@verizon.net">Greg King</A></H2>
<HR>
<EM>ca65 is a powerful macro assembler for the 6502, 65C02, and 65816 CPUs. It is
used as a companion assembler for the cc65 crosscompiler, but it may also be
used as a standalone product.</EM>
<HR>
<P>
<H2><A NAME="toc1">1.</A> <A HREF="ca65.html#s1">Overview</A></H2>
<UL>
<LI><A NAME="toc1.1">1.1</A> <A HREF="ca65.html#ss1.1">Design criteria</A>
</UL>
<P>
<H2><A NAME="toc2">2.</A> <A HREF="ca65.html#s2">Usage</A></H2>
<UL>
<LI><A NAME="toc2.1">2.1</A> <A HREF="ca65.html#ss2.1">Command line option overview</A>
<LI><A NAME="toc2.2">2.2</A> <A HREF="ca65.html#ss2.2">Command line options in detail</A>
</UL>
<P>
<H2><A NAME="toc3">3.</A> <A HREF="ca65.html#s3">Search paths</A></H2>
<P>
<H2><A NAME="toc4">4.</A> <A HREF="ca65.html#s4">Input format</A></H2>
<UL>
<LI><A NAME="toc4.1">4.1</A> <A HREF="ca65.html#ss4.1">Assembler syntax</A>
<LI><A NAME="toc4.2">4.2</A> <A HREF="ca65.html#ss4.2">Number format</A>
<LI><A NAME="toc4.3">4.3</A> <A HREF="ca65.html#ss4.3">Conditional assembly</A>
</UL>
<P>
<H2><A NAME="toc5">5.</A> <A HREF="ca65.html#s5">Expressions</A></H2>
<UL>
<LI><A NAME="toc5.1">5.1</A> <A HREF="ca65.html#ss5.1">Expression evaluation</A>
<LI><A NAME="toc5.2">5.2</A> <A HREF="ca65.html#ss5.2">Size of an expression result</A>
<LI><A NAME="toc5.3">5.3</A> <A HREF="ca65.html#ss5.3">Boolean expressions</A>
<LI><A NAME="toc5.4">5.4</A> <A HREF="ca65.html#ss5.4">Constant expressions</A>
<LI><A NAME="toc5.5">5.5</A> <A HREF="ca65.html#ss5.5">Available operators</A>
</UL>
<P>
<H2><A NAME="toc6">6.</A> <A HREF="ca65.html#s6">Symbols and labels</A></H2>
<UL>
<LI><A NAME="toc6.1">6.1</A> <A HREF="ca65.html#ss6.1">Numeric constants</A>
<LI><A NAME="toc6.2">6.2</A> <A HREF="ca65.html#ss6.2">Numeric variables</A>
<LI><A NAME="toc6.3">6.3</A> <A HREF="ca65.html#ss6.3">Standard labels</A>
<LI><A NAME="toc6.4">6.4</A> <A HREF="ca65.html#ss6.4">Local labels and symbols</A>
<LI><A NAME="toc6.5">6.5</A> <A HREF="ca65.html#ss6.5">Cheap local labels</A>
<LI><A NAME="toc6.6">6.6</A> <A HREF="ca65.html#ss6.6">Unnamed labels</A>
<LI><A NAME="toc6.7">6.7</A> <A HREF="ca65.html#ss6.7">Using macros to define labels and constants</A>
<LI><A NAME="toc6.8">6.8</A> <A HREF="ca65.html#ss6.8">Symbols and <CODE>.DEBUGINFO</CODE></A>
</UL>
<P>
<H2><A NAME="toc7">7.</A> <A HREF="ca65.html#s7">Scopes</A></H2>
<UL>
<LI><A NAME="toc7.1">7.1</A> <A HREF="ca65.html#ss7.1">Global scope</A>
<LI><A NAME="toc7.2">7.2</A> <A HREF="ca65.html#ss7.2">Cheap locals</A>
<LI><A NAME="toc7.3">7.3</A> <A HREF="ca65.html#ss7.3">Generic nested scopes</A>
<LI><A NAME="toc7.4">7.4</A> <A HREF="ca65.html#ss7.4">Nested procedures</A>
<LI><A NAME="toc7.5">7.5</A> <A HREF="ca65.html#ss7.5">Structs, unions and enums</A>
<LI><A NAME="toc7.6">7.6</A> <A HREF="ca65.html#ss7.6">Explicit scope specification</A>
<LI><A NAME="toc7.7">7.7</A> <A HREF="ca65.html#ss7.7">Scope search order</A>
</UL>
<P>
<H2><A NAME="toc8">8.</A> <A HREF="ca65.html#s8">Address sizes and memory models</A></H2>
<UL>
<LI><A NAME="toc8.1">8.1</A> <A HREF="ca65.html#ss8.1">Address sizes</A>
<LI><A NAME="toc8.2">8.2</A> <A HREF="ca65.html#ss8.2">Address sizes of segments</A>
<LI><A NAME="toc8.3">8.3</A> <A HREF="ca65.html#ss8.3">Address sizes of symbols</A>
<LI><A NAME="toc8.4">8.4</A> <A HREF="ca65.html#ss8.4">Memory models</A>
</UL>
<P>
<H2><A NAME="toc9">9.</A> <A HREF="ca65.html#s9">Pseudo variables</A></H2>
<UL>
<LI><A NAME="toc9.1">9.1</A> <A HREF="ca65.html#ss9.1"><CODE>*</CODE></A>
<LI><A NAME="toc9.2">9.2</A> <A HREF="ca65.html#ss9.2"><CODE>.ASIZE</CODE></A>
<LI><A NAME="toc9.3">9.3</A> <A HREF="ca65.html#ss9.3"><CODE>.CPU</CODE></A>
<LI><A NAME="toc9.4">9.4</A> <A HREF="ca65.html#ss9.4"><CODE>.ISIZE</CODE></A>
<LI><A NAME="toc9.5">9.5</A> <A HREF="ca65.html#ss9.5"><CODE>.PARAMCOUNT</CODE></A>
<LI><A NAME="toc9.6">9.6</A> <A HREF="ca65.html#ss9.6"><CODE>.TIME</CODE></A>
<LI><A NAME="toc9.7">9.7</A> <A HREF="ca65.html#ss9.7"><CODE>.VERSION</CODE></A>
</UL>
<P>
<H2><A NAME="toc10">10.</A> <A HREF="ca65.html#s10">Pseudo functions</A></H2>
<UL>
<LI><A NAME="toc10.1">10.1</A> <A HREF="ca65.html#ss10.1"><CODE>.ADDRSIZE</CODE></A>
<LI><A NAME="toc10.2">10.2</A> <A HREF="ca65.html#ss10.2"><CODE>.BANK</CODE></A>
<LI><A NAME="toc10.3">10.3</A> <A HREF="ca65.html#ss10.3"><CODE>.BANKBYTE</CODE></A>
<LI><A NAME="toc10.4">10.4</A> <A HREF="ca65.html#ss10.4"><CODE>.BLANK</CODE></A>
<LI><A NAME="toc10.5">10.5</A> <A HREF="ca65.html#ss10.5"><CODE>.CAP, .CAPABILITY</CODE></A>
<LI><A NAME="toc10.6">10.6</A> <A HREF="ca65.html#ss10.6"><CODE>.CONCAT</CODE></A>
<LI><A NAME="toc10.7">10.7</A> <A HREF="ca65.html#ss10.7"><CODE>.CONST</CODE></A>
<LI><A NAME="toc10.8">10.8</A> <A HREF="ca65.html#ss10.8"><CODE>.DEF, .DEFINED</CODE></A>
<LI><A NAME="toc10.9">10.9</A> <A HREF="ca65.html#ss10.9"><CODE>.DEFINEDMACRO</CODE></A>
<LI><A NAME="toc10.10">10.10</A> <A HREF="ca65.html#ss10.10"><CODE>.HIBYTE</CODE></A>
<LI><A NAME="toc10.11">10.11</A> <A HREF="ca65.html#ss10.11"><CODE>.HIWORD</CODE></A>
<LI><A NAME="toc10.12">10.12</A> <A HREF="ca65.html#ss10.12"><CODE>.IDENT</CODE></A>
<LI><A NAME="toc10.13">10.13</A> <A HREF="ca65.html#ss10.13"><CODE>.ISMNEM, .ISMNEMONIC</CODE></A>
<LI><A NAME="toc10.14">10.14</A> <A HREF="ca65.html#ss10.14"><CODE>.LEFT</CODE></A>
<LI><A NAME="toc10.15">10.15</A> <A HREF="ca65.html#ss10.15"><CODE>.LOBYTE</CODE></A>
<LI><A NAME="toc10.16">10.16</A> <A HREF="ca65.html#ss10.16"><CODE>.LOWORD</CODE></A>
<LI><A NAME="toc10.17">10.17</A> <A HREF="ca65.html#ss10.17"><CODE>.MATCH</CODE></A>
<LI><A NAME="toc10.18">10.18</A> <A HREF="ca65.html#ss10.18"><CODE>.MAX</CODE></A>
<LI><A NAME="toc10.19">10.19</A> <A HREF="ca65.html#ss10.19"><CODE>.MID</CODE></A>
<LI><A NAME="toc10.20">10.20</A> <A HREF="ca65.html#ss10.20"><CODE>.MIN</CODE></A>
<LI><A NAME="toc10.21">10.21</A> <A HREF="ca65.html#ss10.21"><CODE>.REF, .REFERENCED</CODE></A>
<LI><A NAME="toc10.22">10.22</A> <A HREF="ca65.html#ss10.22"><CODE>.RIGHT</CODE></A>
<LI><A NAME="toc10.23">10.23</A> <A HREF="ca65.html#ss10.23"><CODE>.SIZEOF</CODE></A>
<LI><A NAME="toc10.24">10.24</A> <A HREF="ca65.html#ss10.24"><CODE>.SPRINTF</CODE></A>
<LI><A NAME="toc10.25">10.25</A> <A HREF="ca65.html#ss10.25"><CODE>.STRAT</CODE></A>
<LI><A NAME="toc10.26">10.26</A> <A HREF="ca65.html#ss10.26"><CODE>.STRING</CODE></A>
<LI><A NAME="toc10.27">10.27</A> <A HREF="ca65.html#ss10.27"><CODE>.STRLEN</CODE></A>
<LI><A NAME="toc10.28">10.28</A> <A HREF="ca65.html#ss10.28"><CODE>.TCOUNT</CODE></A>
<LI><A NAME="toc10.29">10.29</A> <A HREF="ca65.html#ss10.29"><CODE>.XMATCH</CODE></A>
</UL>
<P>
<H2><A NAME="toc11">11.</A> <A HREF="ca65.html#s11">Control commands</A></H2>
<UL>
<LI><A NAME="toc11.1">11.1</A> <A HREF="ca65.html#ss11.1"><CODE>.A16</CODE></A>
<LI><A NAME="toc11.2">11.2</A> <A HREF="ca65.html#ss11.2"><CODE>.A8</CODE></A>
<LI><A NAME="toc11.3">11.3</A> <A HREF="ca65.html#ss11.3"><CODE>.ADDR</CODE></A>
<LI><A NAME="toc11.4">11.4</A> <A HREF="ca65.html#ss11.4"><CODE>.ALIGN</CODE></A>
<LI><A NAME="toc11.5">11.5</A> <A HREF="ca65.html#ss11.5"><CODE>.ASCIIZ</CODE></A>
<LI><A NAME="toc11.6">11.6</A> <A HREF="ca65.html#ss11.6"><CODE>.ASSERT</CODE></A>
<LI><A NAME="toc11.7">11.7</A> <A HREF="ca65.html#ss11.7"><CODE>.AUTOIMPORT</CODE></A>
<LI><A NAME="toc11.8">11.8</A> <A HREF="ca65.html#ss11.8"><CODE>.BANKBYTES</CODE></A>
<LI><A NAME="toc11.9">11.9</A> <A HREF="ca65.html#ss11.9"><CODE>.BSS</CODE></A>
<LI><A NAME="toc11.10">11.10</A> <A HREF="ca65.html#ss11.10"><CODE>.BYT, .BYTE</CODE></A>
<LI><A NAME="toc11.11">11.11</A> <A HREF="ca65.html#ss11.11"><CODE>.CASE</CODE></A>
<LI><A NAME="toc11.12">11.12</A> <A HREF="ca65.html#ss11.12"><CODE>.CHARMAP</CODE></A>
<LI><A NAME="toc11.13">11.13</A> <A HREF="ca65.html#ss11.13"><CODE>.CODE</CODE></A>
<LI><A NAME="toc11.14">11.14</A> <A HREF="ca65.html#ss11.14"><CODE>.CONDES</CODE></A>
<LI><A NAME="toc11.15">11.15</A> <A HREF="ca65.html#ss11.15"><CODE>.CONSTRUCTOR</CODE></A>
<LI><A NAME="toc11.16">11.16</A> <A HREF="ca65.html#ss11.16"><CODE>.DATA</CODE></A>
<LI><A NAME="toc11.17">11.17</A> <A HREF="ca65.html#ss11.17"><CODE>.DBYT</CODE></A>
<LI><A NAME="toc11.18">11.18</A> <A HREF="ca65.html#ss11.18"><CODE>.DEBUGINFO</CODE></A>
<LI><A NAME="toc11.19">11.19</A> <A HREF="ca65.html#ss11.19"><CODE>.DEFINE</CODE></A>
<LI><A NAME="toc11.20">11.20</A> <A HREF="ca65.html#ss11.20"><CODE>.DELMAC, .DELMACRO</CODE></A>
<LI><A NAME="toc11.21">11.21</A> <A HREF="ca65.html#ss11.21"><CODE>.DESTRUCTOR</CODE></A>
<LI><A NAME="toc11.22">11.22</A> <A HREF="ca65.html#ss11.22"><CODE>.DWORD</CODE></A>
<LI><A NAME="toc11.23">11.23</A> <A HREF="ca65.html#ss11.23"><CODE>.ELSE</CODE></A>
<LI><A NAME="toc11.24">11.24</A> <A HREF="ca65.html#ss11.24"><CODE>.ELSEIF</CODE></A>
<LI><A NAME="toc11.25">11.25</A> <A HREF="ca65.html#ss11.25"><CODE>.END</CODE></A>
<LI><A NAME="toc11.26">11.26</A> <A HREF="ca65.html#ss11.26"><CODE>.ENDENUM</CODE></A>
<LI><A NAME="toc11.27">11.27</A> <A HREF="ca65.html#ss11.27"><CODE>.ENDIF</CODE></A>
<LI><A NAME="toc11.28">11.28</A> <A HREF="ca65.html#ss11.28"><CODE>.ENDMAC, .ENDMACRO</CODE></A>
<LI><A NAME="toc11.29">11.29</A> <A HREF="ca65.html#ss11.29"><CODE>.ENDPROC</CODE></A>
<LI><A NAME="toc11.30">11.30</A> <A HREF="ca65.html#ss11.30"><CODE>.ENDREP, .ENDREPEAT</CODE></A>
<LI><A NAME="toc11.31">11.31</A> <A HREF="ca65.html#ss11.31"><CODE>.ENDSCOPE</CODE></A>
<LI><A NAME="toc11.32">11.32</A> <A HREF="ca65.html#ss11.32"><CODE>.ENDSTRUCT</CODE></A>
<LI><A NAME="toc11.33">11.33</A> <A HREF="ca65.html#ss11.33"><CODE>.ENDUNION</CODE></A>
<LI><A NAME="toc11.34">11.34</A> <A HREF="ca65.html#ss11.34"><CODE>.ENUM</CODE></A>
<LI><A NAME="toc11.35">11.35</A> <A HREF="ca65.html#ss11.35"><CODE>.ERROR</CODE></A>
<LI><A NAME="toc11.36">11.36</A> <A HREF="ca65.html#ss11.36"><CODE>.EXITMAC, .EXITMACRO</CODE></A>
<LI><A NAME="toc11.37">11.37</A> <A HREF="ca65.html#ss11.37"><CODE>.EXPORT</CODE></A>
<LI><A NAME="toc11.38">11.38</A> <A HREF="ca65.html#ss11.38"><CODE>.EXPORTZP</CODE></A>
<LI><A NAME="toc11.39">11.39</A> <A HREF="ca65.html#ss11.39"><CODE>.FARADDR</CODE></A>
<LI><A NAME="toc11.40">11.40</A> <A HREF="ca65.html#ss11.40"><CODE>.FATAL</CODE></A>
<LI><A NAME="toc11.41">11.41</A> <A HREF="ca65.html#ss11.41"><CODE>.FEATURE</CODE></A>
<LI><A NAME="toc11.42">11.42</A> <A HREF="ca65.html#ss11.42"><CODE>.FILEOPT, .FOPT</CODE></A>
<LI><A NAME="toc11.43">11.43</A> <A HREF="ca65.html#ss11.43"><CODE>.FORCEIMPORT</CODE></A>
<LI><A NAME="toc11.44">11.44</A> <A HREF="ca65.html#ss11.44"><CODE>.GLOBAL</CODE></A>
<LI><A NAME="toc11.45">11.45</A> <A HREF="ca65.html#ss11.45"><CODE>.GLOBALZP</CODE></A>
<LI><A NAME="toc11.46">11.46</A> <A HREF="ca65.html#ss11.46"><CODE>.HIBYTES</CODE></A>
<LI><A NAME="toc11.47">11.47</A> <A HREF="ca65.html#ss11.47"><CODE>.I16</CODE></A>
<LI><A NAME="toc11.48">11.48</A> <A HREF="ca65.html#ss11.48"><CODE>.I8</CODE></A>
<LI><A NAME="toc11.49">11.49</A> <A HREF="ca65.html#ss11.49"><CODE>.IF</CODE></A>
<LI><A NAME="toc11.50">11.50</A> <A HREF="ca65.html#ss11.50"><CODE>.IFBLANK</CODE></A>
<LI><A NAME="toc11.51">11.51</A> <A HREF="ca65.html#ss11.51"><CODE>.IFCONST</CODE></A>
<LI><A NAME="toc11.52">11.52</A> <A HREF="ca65.html#ss11.52"><CODE>.IFDEF</CODE></A>
<LI><A NAME="toc11.53">11.53</A> <A HREF="ca65.html#ss11.53"><CODE>.IFNBLANK</CODE></A>
<LI><A NAME="toc11.54">11.54</A> <A HREF="ca65.html#ss11.54"><CODE>.IFNDEF</CODE></A>
<LI><A NAME="toc11.55">11.55</A> <A HREF="ca65.html#ss11.55"><CODE>.IFNREF</CODE></A>
<LI><A NAME="toc11.56">11.56</A> <A HREF="ca65.html#ss11.56"><CODE>.IFP02</CODE></A>
<LI><A NAME="toc11.57">11.57</A> <A HREF="ca65.html#ss11.57"><CODE>.IFP02X</CODE></A>
<LI><A NAME="toc11.58">11.58</A> <A HREF="ca65.html#ss11.58"><CODE>.IFP4510</CODE></A>
<LI><A NAME="toc11.59">11.59</A> <A HREF="ca65.html#ss11.59"><CODE>.IFP45GS02</CODE></A>
<LI><A NAME="toc11.60">11.60</A> <A HREF="ca65.html#ss11.60"><CODE>.IFP6280</CODE></A>
<LI><A NAME="toc11.61">11.61</A> <A HREF="ca65.html#ss11.61"><CODE>.IFP816</CODE></A>
<LI><A NAME="toc11.62">11.62</A> <A HREF="ca65.html#ss11.62"><CODE>.IFPC02</CODE></A>
<LI><A NAME="toc11.63">11.63</A> <A HREF="ca65.html#ss11.63"><CODE>.IFPCE02</CODE></A>
<LI><A NAME="toc11.64">11.64</A> <A HREF="ca65.html#ss11.64"><CODE>.IFPDTV</CODE></A>
<LI><A NAME="toc11.65">11.65</A> <A HREF="ca65.html#ss11.65"><CODE>.IFPM740</CODE></A>
<LI><A NAME="toc11.66">11.66</A> <A HREF="ca65.html#ss11.66"><CODE>.IFPSC02</CODE></A>
<LI><A NAME="toc11.67">11.67</A> <A HREF="ca65.html#ss11.67"><CODE>.IFPSWEET16</CODE></A>
<LI><A NAME="toc11.68">11.68</A> <A HREF="ca65.html#ss11.68"><CODE>.IFREF</CODE></A>
<LI><A NAME="toc11.69">11.69</A> <A HREF="ca65.html#ss11.69"><CODE>.IFPWC02</CODE></A>
<LI><A NAME="toc11.70">11.70</A> <A HREF="ca65.html#ss11.70"><CODE>.IMPORT</CODE></A>
<LI><A NAME="toc11.71">11.71</A> <A HREF="ca65.html#ss11.71"><CODE>.IMPORTZP</CODE></A>
<LI><A NAME="toc11.72">11.72</A> <A HREF="ca65.html#ss11.72"><CODE>.INCBIN</CODE></A>
<LI><A NAME="toc11.73">11.73</A> <A HREF="ca65.html#ss11.73"><CODE>.INCLUDE</CODE></A>
<LI><A NAME="toc11.74">11.74</A> <A HREF="ca65.html#ss11.74"><CODE>.INTERRUPTOR</CODE></A>
<LI><A NAME="toc11.75">11.75</A> <A HREF="ca65.html#ss11.75"><CODE>.LIST</CODE></A>
<LI><A NAME="toc11.76">11.76</A> <A HREF="ca65.html#ss11.76"><CODE>.LISTBYTES</CODE></A>
<LI><A NAME="toc11.77">11.77</A> <A HREF="ca65.html#ss11.77"><CODE>.LITERAL</CODE></A>
<LI><A NAME="toc11.78">11.78</A> <A HREF="ca65.html#ss11.78"><CODE>.LOBYTES</CODE></A>
<LI><A NAME="toc11.79">11.79</A> <A HREF="ca65.html#ss11.79"><CODE>.LOCAL</CODE></A>
<LI><A NAME="toc11.80">11.80</A> <A HREF="ca65.html#ss11.80"><CODE>.LOCALCHAR</CODE></A>
<LI><A NAME="toc11.81">11.81</A> <A HREF="ca65.html#ss11.81"><CODE>.MACPACK</CODE></A>
<LI><A NAME="toc11.82">11.82</A> <A HREF="ca65.html#ss11.82"><CODE>.MAC, .MACRO</CODE></A>
<LI><A NAME="toc11.83">11.83</A> <A HREF="ca65.html#ss11.83"><CODE>.ORG</CODE></A>
<LI><A NAME="toc11.84">11.84</A> <A HREF="ca65.html#ss11.84"><CODE>.OUT</CODE></A>
<LI><A NAME="toc11.85">11.85</A> <A HREF="ca65.html#ss11.85"><CODE>.P02</CODE></A>
<LI><A NAME="toc11.86">11.86</A> <A HREF="ca65.html#ss11.86"><CODE>.P02X</CODE></A>
<LI><A NAME="toc11.87">11.87</A> <A HREF="ca65.html#ss11.87"><CODE>.P4510</CODE></A>
<LI><A NAME="toc11.88">11.88</A> <A HREF="ca65.html#ss11.88"><CODE>.P45GS02</CODE></A>
<LI><A NAME="toc11.89">11.89</A> <A HREF="ca65.html#ss11.89"><CODE>.P6280</CODE></A>
<LI><A NAME="toc11.90">11.90</A> <A HREF="ca65.html#ss11.90"><CODE>.P816</CODE></A>
<LI><A NAME="toc11.91">11.91</A> <A HREF="ca65.html#ss11.91"><CODE>.PAGELEN, .PAGELENGTH</CODE></A>
<LI><A NAME="toc11.92">11.92</A> <A HREF="ca65.html#ss11.92"><CODE>.PC02</CODE></A>
<LI><A NAME="toc11.93">11.93</A> <A HREF="ca65.html#ss11.93"><CODE>.PCE02</CODE></A>
<LI><A NAME="toc11.94">11.94</A> <A HREF="ca65.html#ss11.94"><CODE>.PDTV</CODE></A>
<LI><A NAME="toc11.95">11.95</A> <A HREF="ca65.html#ss11.95"><CODE>.PM740</CODE></A>
<LI><A NAME="toc11.96">11.96</A> <A HREF="ca65.html#ss11.96"><CODE>.POPCHARMAP</CODE></A>
<LI><A NAME="toc11.97">11.97</A> <A HREF="ca65.html#ss11.97"><CODE>.POPCPU</CODE></A>
<LI><A NAME="toc11.98">11.98</A> <A HREF="ca65.html#ss11.98"><CODE>.POPSEG</CODE></A>
<LI><A NAME="toc11.99">11.99</A> <A HREF="ca65.html#ss11.99"><CODE>.PROC</CODE></A>
<LI><A NAME="toc11.100">11.100</A> <A HREF="ca65.html#ss11.100"><CODE>.PSC02</CODE></A>
<LI><A NAME="toc11.101">11.101</A> <A HREF="ca65.html#ss11.101"><CODE>.PSWEET16</CODE></A>
<LI><A NAME="toc11.102">11.102</A> <A HREF="ca65.html#ss11.102"><CODE>.PUSHCHARMAP</CODE></A>
<LI><A NAME="toc11.103">11.103</A> <A HREF="ca65.html#ss11.103"><CODE>.PUSHCPU</CODE></A>
<LI><A NAME="toc11.104">11.104</A> <A HREF="ca65.html#ss11.104"><CODE>.PUSHSEG</CODE></A>
<LI><A NAME="toc11.105">11.105</A> <A HREF="ca65.html#ss11.105"><CODE>.PWC02</CODE></A>
<LI><A NAME="toc11.106">11.106</A> <A HREF="ca65.html#ss11.106"><CODE>.REFERTO, .REFTO</CODE></A>
<LI><A NAME="toc11.107">11.107</A> <A HREF="ca65.html#ss11.107"><CODE>.RELOC</CODE></A>
<LI><A NAME="toc11.108">11.108</A> <A HREF="ca65.html#ss11.108"><CODE>.REPEAT</CODE></A>
<LI><A NAME="toc11.109">11.109</A> <A HREF="ca65.html#ss11.109"><CODE>.RES</CODE></A>
<LI><A NAME="toc11.110">11.110</A> <A HREF="ca65.html#ss11.110"><CODE>.RODATA</CODE></A>
<LI><A NAME="toc11.111">11.111</A> <A HREF="ca65.html#ss11.111"><CODE>.SCOPE</CODE></A>
<LI><A NAME="toc11.112">11.112</A> <A HREF="ca65.html#ss11.112"><CODE>.SEGMENT</CODE></A>
<LI><A NAME="toc11.113">11.113</A> <A HREF="ca65.html#ss11.113"><CODE>.SET</CODE></A>
<LI><A NAME="toc11.114">11.114</A> <A HREF="ca65.html#ss11.114"><CODE>.SETCPU</CODE></A>
<LI><A NAME="toc11.115">11.115</A> <A HREF="ca65.html#ss11.115"><CODE>.SMART</CODE></A>
<LI><A NAME="toc11.116">11.116</A> <A HREF="ca65.html#ss11.116"><CODE>.STRUCT</CODE></A>
<LI><A NAME="toc11.117">11.117</A> <A HREF="ca65.html#ss11.117"><CODE>.TAG</CODE></A>
<LI><A NAME="toc11.118">11.118</A> <A HREF="ca65.html#ss11.118"><CODE>.UNDEF, .UNDEFINE</CODE></A>
<LI><A NAME="toc11.119">11.119</A> <A HREF="ca65.html#ss11.119"><CODE>.UNION</CODE></A>
<LI><A NAME="toc11.120">11.120</A> <A HREF="ca65.html#ss11.120"><CODE>.WARNING</CODE></A>
<LI><A NAME="toc11.121">11.121</A> <A HREF="ca65.html#ss11.121"><CODE>.WORD</CODE></A>
<LI><A NAME="toc11.122">11.122</A> <A HREF="ca65.html#ss11.122"><CODE>.ZEROPAGE</CODE></A>
</UL>
<P>
<H2><A NAME="toc12">12.</A> <A HREF="ca65.html#s12">Macros</A></H2>
<UL>
<LI><A NAME="toc12.1">12.1</A> <A HREF="ca65.html#ss12.1">Introduction</A>
<LI><A NAME="toc12.2">12.2</A> <A HREF="ca65.html#ss12.2">Macros without parameters</A>
<LI><A NAME="toc12.3">12.3</A> <A HREF="ca65.html#ss12.3">Parametrized macros</A>
<LI><A NAME="toc12.4">12.4</A> <A HREF="ca65.html#ss12.4">Detecting parameter types</A>
<LI><A NAME="toc12.5">12.5</A> <A HREF="ca65.html#ss12.5">Recursive macros</A>
<LI><A NAME="toc12.6">12.6</A> <A HREF="ca65.html#ss12.6">Local symbols inside macros</A>
<LI><A NAME="toc12.7">12.7</A> <A HREF="ca65.html#ss12.7">C style macros</A>
<LI><A NAME="toc12.8">12.8</A> <A HREF="ca65.html#ss12.8">Characters in macros</A>
<LI><A NAME="toc12.9">12.9</A> <A HREF="ca65.html#ss12.9">Deleting macros</A>
</UL>
<P>
<H2><A NAME="toc13">13.</A> <A HREF="ca65.html#s13">Macro packages</A></H2>
<UL>
<LI><A NAME="toc13.1">13.1</A> <A HREF="ca65.html#ss13.1"><CODE>.MACPACK generic</CODE></A>
<LI><A NAME="toc13.2">13.2</A> <A HREF="ca65.html#ss13.2"><CODE>.MACPACK longbranch</CODE></A>
<LI><A NAME="toc13.3">13.3</A> <A HREF="ca65.html#ss13.3"><CODE>.MACPACK apple2</CODE></A>
<LI><A NAME="toc13.4">13.4</A> <A HREF="ca65.html#ss13.4"><CODE>.MACPACK atari</CODE></A>
<LI><A NAME="toc13.5">13.5</A> <A HREF="ca65.html#ss13.5"><CODE>.MACPACK cbm</CODE></A>
<LI><A NAME="toc13.6">13.6</A> <A HREF="ca65.html#ss13.6"><CODE>.MACPACK module</CODE></A>
</UL>
<P>
<H2><A NAME="toc14">14.</A> <A HREF="ca65.html#s14">Predefined constants</A></H2>
<P>
<H2><A NAME="toc15">15.</A> <A HREF="ca65.html#s15">Structs and unions</A></H2>
<UL>
<LI><A NAME="toc15.1">15.1</A> <A HREF="ca65.html#ss15.1">Structs and unions Overview</A>
<LI><A NAME="toc15.2">15.2</A> <A HREF="ca65.html#ss15.2">Declaration</A>
<LI><A NAME="toc15.3">15.3</A> <A HREF="ca65.html#ss15.3">The storage allocator keywords</A>
<LI><A NAME="toc15.4">15.4</A> <A HREF="ca65.html#ss15.4">The <CODE>.ORG</CODE> keyword</A>
<LI><A NAME="toc15.5">15.5</A> <A HREF="ca65.html#ss15.5">The <CODE>.TAG</CODE> keyword</A>
<LI><A NAME="toc15.6">15.6</A> <A HREF="ca65.html#ss15.6">Limitations</A>
</UL>
<P>
<H2><A NAME="toc16">16.</A> <A HREF="ca65.html#s16">Module constructors/destructors</A></H2>
<UL>
<LI><A NAME="toc16.1">16.1</A> <A HREF="ca65.html#ss16.1">Module constructors/destructors Overview</A>
<LI><A NAME="toc16.2">16.2</A> <A HREF="ca65.html#ss16.2">Calling order</A>
<LI><A NAME="toc16.3">16.3</A> <A HREF="ca65.html#ss16.3">Pitfalls</A>
</UL>
<P>
<H2><A NAME="toc17">17.</A> <A HREF="ca65.html#s17">Porting sources from other assemblers</A></H2>
<UL>
<LI><A NAME="toc17.1">17.1</A> <A HREF="ca65.html#ss17.1">TASS</A>
</UL>
<P>
<H2><A NAME="toc18">18.</A> <A HREF="ca65.html#s18">Copyright</A></H2>
<HR>
<H2><A NAME="s1">1.</A> <A HREF="#toc1">Overview</A></H2>
<P>ca65 is a replacement for the ra65 assembler that was part of the cc65 C
compiler, originally developed by John R. Dunning. I had some problems with
ra65 and the copyright does not permit some things which I wanted to be
possible, so I decided to write a completely new assembler/linker/archiver
suite for the cc65 compiler. ca65 is part of this suite.</P>
<P>Some parts of the assembler (code generation and some routines for symbol
table handling) are taken from an older crossassembler named a816 written
by me a long time ago.</P>
<H2><A NAME="ss1.1">1.1</A> <A HREF="#toc1.1">Design criteria</A>
</H2>
<P>Here's a list of the design criteria, that I considered important for the
development:</P>
<P>
<UL>
<LI> The assembler must support macros. Macros are not essential, but they
make some things easier, especially when you use the assembler in the
backend of a compiler.</LI>
<LI> The assembler must support the newer 65C02 and 65816 CPUs. I have been
thinking about a 65816 backend for the C compiler, and even my old
a816 assembler had support for these CPUs, so this wasn't really a
problem.</LI>
<LI> The assembler must produce relocatable code. This is necessary for the
compiler support, and it is more convenient.</LI>
<LI> Conditional assembly must be supported. This is a must for bigger
projects written in assembler (like Elite128).</LI>
<LI> The assembler must support segments, and it must support more than
three segments (this is the count, most other assemblers support).
Having more than one code segments helps developing code for systems
with a divided ROM area (like the C64).</LI>
<LI> The linker must be able to resolve arbitrary expressions. It should
be able to get things like
<BLOCKQUOTE><CODE>
<PRE>
.import S1, S2
.export Special
Special = 2*S1 + S2/7
</PRE>
</CODE></BLOCKQUOTE>
right.</LI>
<LI> True lexical nesting for symbols. This is very convenient for larger
assembly projects.</LI>
<LI> "Cheap" local symbols without lexical nesting for those quick, late
night hacks.</LI>
<LI> I liked the idea of "options" as Anre Fachats .o65 format has it, so I
introduced the concept into the object file format use by the new cc65
binutils.</LI>
<LI> The assembler will be a one pass assembler. There was no real need for
this decision, but I've written several multipass assemblers, and it
started to get boring. A one pass assembler needs much more elaborated
data structures, and because of that it's much more fun:-)</LI>
<LI> Non-GPLed code that may be used in any project without restrictions or
fear of "GPL infecting" other code.</LI>
</UL>
</P>
<H2><A NAME="s2">2.</A> <A HREF="#toc2">Usage</A></H2>
<H2><A NAME="ss2.1">2.1</A> <A HREF="#toc2.1">Command line option overview</A>
</H2>
<P>The assembler accepts the following options:</P>
<P>
<BLOCKQUOTE><CODE>
<PRE>
---------------------------------------------------------------------------
Usage: ca65 [options] file
Short options:
-D name[=value] Define a symbol
-I dir Set an include directory search path
-U Mark unresolved symbols as import
-V Print the assembler version
-W n Set warning level n
-d Debug mode
-g Add debug info to object file
-x Expand macros in the listing
repeat -x for full expansion
-h Help (this text)
-i Ignore case of symbols
-l name Create a listing file if assembly was ok
-mm model Set the memory model
-o name Name the output file
-s Enable smart mode
-S Generate segment offsets in listing
-t sys Set the target system
-v Increase verbosity
Long options:
--auto-import Mark unresolved symbols as import
--bin-include-dir dir Set a search path for binary includes
--color [on|auto|off] Color diagnostics (default: auto)
--cpu type Set cpu type
--create-dep name Create a make dependency file
--create-full-dep name Create a full make dependency file
--debug Debug mode
--debug-info Add debug info to object file
--expand-macros Expand macros in listing
Repeat to get full expansion
--feature name Set an emulation feature
--help Help (this text)
--ignore-case Ignore case of symbols
--include-dir dir Set an include directory search path
--large-alignment Don't warn about large alignments
--listing name Create a listing file if assembly was ok
--list-bytes n Maximum number of bytes per listing line
--memory-model model Set the memory model
--no-utf8 Disable use of UTF-8 in diagnostics
--pagelength n Set the page length for the listing
--relax-checks Relax some checks (see docs)
--segment-list Generate segment offsets in listing
--smart Enable smart mode
--target sys Set the target system
--verbose Increase verbosity
--version Print the assembler version
--warn-align-waste Print bytes "wasted" for alignment
--warnings-as-errors Treat warnings as errors
---------------------------------------------------------------------------
</PRE>
</CODE></BLOCKQUOTE>
</P>
<H2><A NAME="ss2.2">2.2</A> <A HREF="#toc2.2">Command line options in detail</A>
</H2>
<P>Here is a description of all the command line options:</P>
<P>
<DL>
<P>
<A NAME="option--bin-include-dir"></A> </P>
<DT><B><CODE>--bin-include-dir dir</CODE></B><DD>
<P>Name a directory which is searched for binary include files. The option
may be used more than once to specify more than one directory to search. The
current directory is always searched first before considering any
additional directories. See also the section about
<A HREF="#search-paths">search paths</A>.</P>
<P>
<A NAME="option--color"></A> </P>
<DT><B><CODE>--color</CODE></B><DD>
<P>This option controls if the assembler will use colors when printing
diagnostics. The default is "auto" which will enable colors if the output
goes to a terminal (not to a file).</P>
<P>
<A NAME="option--cpu"></A> </P>
<DT><B><CODE>--cpu type</CODE></B><DD>
<P>Set the default for the CPU type. The option takes a parameter, which
may be one of
<UL>
<LI>6502 - NMOS 6502 (all legal instructions)</LI>
<LI>6502X - NMOS 6502 with all undocumented instructions</LI>
<LI>6502DTV - the emulated CPU of the C64DTV device</LI>
<LI>65SC02 - first CMOS instruction set (no bit manipulation, no wai/stp)</LI>
<LI>65C02 - CMOS with Rockwell extensions</LI>
<LI>W65C02 - full CMOS instruction set (has bit manipulation and wai/stp)</LI>
<LI>65CE02 - CMOS with CSG extensions</LI>
<LI>4510 - the CPU of the Commodore C65</LI>
<LI>45GS02 - the CPU of the Commodore MEGA65</LI>
<LI>HuC6280 - the CPU of the PC engine</LI>
<LI>M740 - a Microcontroller by Mitsubishi</LI>
<LI>65816 - the CPU of the SNES, and the SCPU</LI>
<LI>sweet16 - an interpreter for a pseudo 16 bit CPU</LI>
</UL>
</P>
<P>
<A NAME="option-create-dep"></A> </P>
<DT><B><CODE>--create-dep name</CODE></B><DD>
<P>Tells the assembler to generate a file containing the dependency list for
the assembled module in makefile syntax. The output is written to a file
with the given name. The output does not include files passed via debug
information to the assembler.</P>
<P>
<A NAME="option-create-full-dep"></A> </P>
<DT><B><CODE>--create-full-dep name</CODE></B><DD>
<P>Tells the assembler to generate a file containing the dependency list for
the assembled module in makefile syntax. The output is written to a file
with the given name. The output does include files passed via debug
information to the assembler.</P>
<DT><B><CODE>-d, --debug</CODE></B><DD>
<P>Enables debug mode, something that should not be needed for mere
mortals:-)</P>
<P>
<A NAME="option-D"></A> </P>
<DT><B><CODE>-D</CODE></B><DD>
<P>This option allows you to define symbols on the command line. Without a
value, the symbol is defined with the value zero. When giving a value,
you may use the '$' prefix for hexadecimal symbols. Please note
that for some operating systems, '$' has a special meaning, so
you may have to quote the expression.</P>
<P>
<A NAME="option--feature"></A> </P>
<DT><B><CODE>--feature name</CODE></B><DD>
<P>Enable an emulation feature. This is identical as using <CODE>.FEATURE</CODE>
in the source with two exceptions: Feature names must be lower case, and
each feature must be specified by using a separate <CODE>--feature</CODE> option,
comma separated lists are not allowed.</P>
<P>See the discussion of the <CODE>
<A HREF="#.FEATURE">.FEATURE</A></CODE>
command for a list of emulation features.</P>
<P>
<A NAME="option-g"></A> </P>
<DT><B><CODE>-g, --debug-info</CODE></B><DD>
<P>When this option (or the equivalent control command <CODE>.DEBUGINFO</CODE>) is
used, the assembler will add a section to the object file that contains
all symbols (including local ones) together with the symbol values and
source file positions. The linker will put these additional symbols into
the VICE label file, so even local symbols can be seen in the VICE
monitor.</P>
<P>
<A NAME="option-h"></A> </P>
<DT><B><CODE>-h, --help</CODE></B><DD>
<P>Print the short option summary shown above.</P>
<P>
<A NAME="option-I"></A> </P>
<DT><B><CODE>-I dir, --include-dir dir</CODE></B><DD>
<P>Name a directory which is searched for include files. The option may be
used more than once to specify more than one directory to search. The
current directory is always searched first before considering any
additional directories. See also the section about
<A HREF="#search-paths">search paths</A>.</P>
<P>
<A NAME="option-i"></A> </P>
<DT><B><CODE>-i, --ignore-case</CODE></B><DD>
<P>This option makes the assembler case insensitive on identifiers and labels.
This option will override the default, but may itself be overridden by the
<CODE>
<A HREF="#.CASE">.CASE</A></CODE> control command.</P>
<P>
<A NAME="option-l"></A> </P>
<DT><B><CODE>-l name, --listing name</CODE></B><DD>
<P>Generate an assembler listing with the given name. A listing file will
never be generated in case of assembly errors.</P>
<P>
<A NAME="option--large-alignment"></A> </P>
<DT><B><CODE>--large-alignment</CODE></B><DD>
<P>Disable warnings about a large combined alignment. See the discussion of the
<CODE>
<A HREF="#.ALIGN">.ALIGN</A></CODE> directive for further information.</P>
<P>
<A NAME="option--list-bytes"></A> </P>
<DT><B><CODE>--list-bytes n</CODE></B><DD>
<P>Set the maximum number of bytes printed in the listing for one line of
input. See the <CODE>
<A HREF="#.LISTBYTES">.LISTBYTES</A></CODE> directive
for more information. The value zero can be used to encode an unlimited
number of printed bytes.</P>
<P>
<A NAME="option-mm"></A> </P>
<DT><B><CODE>-mm model, --memory-model model</CODE></B><DD>
<P>Define the default memory model. Possible model specifiers are near, far and
huge.</P>
<P>
<A NAME="option--no-utf8"></A> </P>
<DT><B><CODE>--no-utf8</CODE></B><DD>
<P>Disable the use of UTF-8 characters in diagnostics. This might be necessary
if auto detection fails or if the output is captured for processing with a
tool that is not UTF-8 capable.</P>
<P>
<A NAME="option-o"></A> </P>
<DT><B><CODE>-o name</CODE></B><DD>
<P>The default output name is the name of the input file with the extension
replaced by ".o". If you don't like that, you may give another name with
the -o option. The output file will be placed in the same directory as
the source file, or, if -o is given, the full path in this name is used.</P>
<P>
<A NAME="option--pagelength"></A> </P>
<DT><B><CODE>--pagelength n</CODE></B><DD>
<P>sets the length of a listing page in lines. See the <CODE>
<A HREF="#.PAGELENGTH">.PAGELENGTH</A></CODE> directive for more information.</P>
<P>
<A NAME="option--relax-checks"></A> </P>
<DT><B><CODE>--relax-checks</CODE></B><DD>
<P>Disables some error checks done by the assembler. This will allow code that is an
error in most cases and flagged as such by the assembler, but can be valid
in special situations.</P>
<P>Disabled checks are:
<UL>
<LI>Address vs. fragment size: a byte sized load from an non-zeropage
address is truncated instead of producing an error.</LI>
<LI>Indirect jump on page boundary: <CODE>jmp (label)</CODE> on a label that
resides on a page boundary (<CODE>$xxFF</CODE>) fetches the second byte from the
wrong address on 6502 CPUs, now allowed instead of producing an error.</LI>
</UL>
</P>
<P>
<A NAME="option-S"></A> </P>
<DT><B><CODE>-S, --segment-list</CODE></B><DD>
<P>Add the segment ID in front of each address in the listing file.</P>
<P>
<A NAME="option-s"></A> </P>
<DT><B><CODE>-s, --smart-mode</CODE></B><DD>
<P>In smart mode (enabled by -s or the <CODE>
<A HREF="#.SMART">.SMART</A></CODE>
pseudo instruction) the assembler will track usage of the <CODE>REP</CODE> and
<CODE>SEP</CODE> instructions in 65816 mode and update the operand sizes
accordingly. If the operand of such an instruction cannot be evaluated by
the assembler (for example, because the operand is an imported symbol), a
warning is issued.</P>
<P>Beware: Since the assembler cannot trace the execution flow this may
lead to false results in some cases. If in doubt, use the .ixx and .axx
instructions to tell the assembler about the current settings. Smart
mode is off by default.</P>
<P>
<A NAME="option-t"></A> </P>
<DT><B><CODE>-t sys, --target sys</CODE></B><DD>
<P>Set the target system. This will enable translation of character strings and
character constants into the character set of the target platform. The
default for the target system is "none", which means that no translation
will take place. The assembler supports the same target systems as the
compiler, see
<A HREF="ca65.html#option-t">there for a list</A>.</P>
<P>Depending on the target, the default CPU type is also set. This can be
overridden by using the <CODE>
<A HREF="#option--cpu">--cpu</A></CODE> option.</P>
<P>
<A NAME="option-U"></A> </P>
<DT><B><CODE>-U, --auto-import</CODE></B><DD>
<P>Mark symbols that are not defined in the sources as imported symbols. This
should be used with care since it delays error messages about typos and such
until the linker is run. The compiler uses the equivalent of this switch
(<CODE>
<A HREF="#.AUTOIMPORT">.AUTOIMPORT</A></CODE>) to enable auto imported
symbols for the runtime library. However, the compiler is supposed to
generate code that runs through the assembler without problems, something
which is not always true for assembler programmers.</P>
<P>
<A NAME="option-v"></A> </P>
<DT><B><CODE>-v, --verbose</CODE></B><DD>
<P>Increase the assembler verbosity. Usually only needed for debugging
purposes. You may use this option more than one time for even more
verbose output.</P>
<P>
<A NAME="option-V"></A> </P>
<DT><B><CODE>-V, --version</CODE></B><DD>
<P>Print the version number of the assembler. If you send any suggestions
or bugfixes, please include the version number.</P>
<P>
<A NAME="option-W"></A> </P>
<DT><B><CODE>-Wn</CODE></B><DD>
<P>Set the warning level for the assembler. Using -W2 the assembler will
even warn about such things like unused imported symbols. The default
warning level is 1, and it would probably be silly to set it to
something lower.</P>
<P>
<A NAME="option--warn-align-waste"></A> </P>
<DT><B><CODE>--warn-align-waste</CODE></B><DD>
<P>Warnings will be generated when alignment requirements cause emission of
fill bytes.</P>
<P>
<A NAME="option--warnings-as-errors"></A> </P>
<DT><B><CODE>--warnings-as-errors</CODE></B><DD>
<P>An error will be generated if any warnings were produced.</P>
<P>
<A NAME="option-x"></A> </P>
<DT><B><CODE>-x, --expand-macros</CODE></B><DD>
<P>In the listing file, show exactly how macros were expanded. Use twice for
more verbose output.</P>
</DL>
</P>
<H2><A NAME="search-paths"></A> <A NAME="s3">3.</A> <A HREF="#toc3">Search paths</A></H2>
<P>Normal include files are searched in the following places:</P>
<P>
<OL>
<LI>The current file's directory.</LI>
<LI>Any directory added with the <CODE>
<A HREF="#option-I">-I</A></CODE> option
on the command line.</LI>
<LI>The value of the environment variable <CODE>CA65_INC</CODE> if it is defined.</LI>
<LI>A subdirectory named <CODE>asminc</CODE> of the directory defined in the
environment variable <CODE>CC65_HOME</CODE>, if it is defined.</LI>
<LI>An optionally compiled-in directory.</LI>
</OL>
</P>
<P>Binary include files are searched in the following places:</P>
<P>
<OL>
<LI>The current file's directory.</LI>
<LI>Any directory added with the <CODE>
<A HREF="#option--bin-include-dir">--bin-include-dir</A></CODE> option on the command line.</LI>
</OL>
</P>
<H2><A NAME="s4">4.</A> <A HREF="#toc4">Input format</A></H2>
<P>
<A NAME="input-format"></A> </P>
<H2><A NAME="ss4.1">4.1</A> <A HREF="#toc4.1">Assembler syntax</A>
</H2>
<P>The assembler accepts the standard 6502/65816 assembler syntax. One line may
contain a label (which is identified by a colon), and, in addition to the
label, an assembler mnemonic, a macro, or a control command (see section
<A HREF="#control-commands">Control Commands</A> for supported control
commands). Alternatively, the line may contain a symbol definition using
the '=' token. Everything after a semicolon is handled as a comment (that is,
it is ignored).</P>
<P>Here are some examples for valid input lines:</P>
<P>
<BLOCKQUOTE><CODE>
<PRE>
Label: ; A label and a comment
lda #$20 ; A 6502 instruction plus comment
L1: ldx #$20 ; Same with label
L2: .byte "Hello world" ; Label plus control command
mymac $20 ; Macro expansion
MySym = 3*L1 ; Symbol definition
MaSym = Label ; Another symbol
</PRE>
</CODE></BLOCKQUOTE>
</P>
<P>The assembler accepts</P>
<P>
<UL>
<LI>all valid 6502 mnemonics when in
<A HREF="#6502-mode">6502 mode</A>
(the default or after the
<CODE>
<A HREF="#.P02">.P02</A></CODE> command was given).</LI>
<LI>all valid 6502 mnemonics, plus a set of illegal instructions, when in
<A HREF="#6502X-mode">6502X mode</A> (after the
<CODE>
<A HREF="#.P02X">.P02X</A></CODE> command was given).</LI>
<LI>all valid 6502DTV mnemonics when in
<A HREF="#DTV-mode">DTV mode</A> (after the
<CODE>
<A HREF="#.PDTV">.PDTV</A></CODE> command was given).</LI>
<LI>all valid 65SC02 mnemonics when in
<A HREF="#65SC02-mode">65SC02 mode</A> (after the
<CODE>
<A HREF="#.PSC02">.PSC02</A></CODE> command was given).</LI>
<LI>all valid 65C02 mnemonics when in
<A HREF="#65C02-mode">65C02 mode</A> (after the
<CODE>
<A HREF="#.PC02">.PC02</A></CODE> command was given).</LI>
<LI>all valid W65C02 mnemonics when in
<A HREF="#W65C02-mode">W65C02 mode</A> (after the
<CODE>
<A HREF="#.PWC02">.PWC02</A></CODE> command was given).</LI>
<LI>all valid 65CE02 mnemonics when in
<A HREF="#65CE02-mode">65CE02 mode</A> (after the
<CODE>
<A HREF="#.PCE02">.PCE02</A></CODE> command was given).</LI>
<LI>all valid 4510 mnemonics when in
<A HREF="#4510-mode">4510 mode</A> (after the
<CODE>
<A HREF="#.P4510">.P4510</A></CODE> command was given).</LI>
<LI>all valid 45GS02 mnemonics when in
<A HREF="#45GS02-mode">45GS02 mode</A> (after the
<CODE>
<A HREF="#.P45GS02">.P45GS02</A></CODE> command was given).</LI>
<LI>all valid HuC6280 mnemonics when in
<A HREF="#HUC6280-mode">HuC6280 mode</A> (after the
<CODE>
<A HREF="#.P6280">.P6280</A></CODE> command was given).</LI>
<LI>all valid M740 mnemonics when in
<A HREF="#M740-mode">M740 mode</A> (after the
<CODE>
<A HREF="#.PM740">.PM740</A></CODE> command was given).</LI>
<LI>all valid 65816 mnemonics when in
<A HREF="#65816-mode">65816 mode</A> (after the
<CODE>
<A HREF="#.P816">.P816</A></CODE> command was given).</LI>
</UL>
</P>
<P>for more details on the various CPUs, see <CODE>
<A HREF="cpus.html">here</A></CODE>.</P>
<P>On 6502-derived platforms the <CODE>BRK</CODE> instruction has an optional signature
byte. If omitted, the assembler will only produce only 1 byte.</P>
<P>
<BLOCKQUOTE><CODE>
<PRE>
brk ; 1-byte: $00
brk $34 ; 2-bytes: $00 $34
brk #$34 ; 2-bytes: $00 $34
</PRE>
</CODE></BLOCKQUOTE>
</P>
<H3><A NAME="6502-mode"></A> 6502 mode</H3>
<P>In 6502 mode (which is the default) the assembler accepts all regular "legal"
6502 mnemonics and addressing modes.</P>
<H3><A NAME="6502X-mode"></A> 6502X mode</H3>
<P>6502X mode is an extension to the normal 6502 mode. In this mode, several
mnemonics for undocumented instructions of the NMOS 6502 CPUs are accepted.</P>
<P>Note: Since these instructions are undocumented, there are no official mnemonics
for them.</P>
<P>
<UL>
<LI><CODE>ALR: A:=(A and #{imm})/2;</CODE></LI>
<LI><CODE>ANC: A:= A and #{imm};</CODE> Generates opcode $0B.</LI>
<LI><CODE>ANE: A:= (A or CONST) and X and #{imm};</CODE></LI>
<LI><CODE>ARR: A:=(A and #{imm})/2;</CODE></LI>
<LI><CODE>AXS: X:=A and X-#{imm};</CODE></LI>
<LI><CODE>DCP: {addr}:={addr}-1; A-{addr};</CODE></LI>
<LI><CODE>ISC: {addr}:={addr}+1; A:=A-{addr};</CODE></LI>
<LI><CODE>JAM:</CODE></LI>
<LI><CODE>LAS: A,X,S:={addr} and S;</CODE></LI>
<LI><CODE>LAX: A,X:={addr};</CODE></LI>
<LI><CODE>NOP: #{imm}; zp; zp,x; abs; abs,x</CODE></LI>
<LI><CODE>RLA: {addr}:={addr}rol; A:=A and {addr};</CODE></LI>
<LI><CODE>RRA: {addr}:={addr}ror; A:=A adc {addr};</CODE></LI>
<LI><CODE>SAX: {addr}:=A and X;</CODE></LI>
<LI><CODE>SHA: {addr}:=A and X and {addr hi +1};</CODE></LI>
<LI><CODE>SHX: {addr}:=X and {addr hi +1};</CODE></LI>
<LI><CODE>SHY: {addr}:=Y and {addr hi +1};</CODE></LI>
<LI><CODE>SLO: {addr}:={addr}*2; A:=A or {addr};</CODE></LI>
<LI><CODE>SRE: {addr}:={addr}/2; A:=A xor {addr};</CODE></LI>
<LI><CODE>TAS: {addr}:=A and X and {addr hi +1}; SP:=A and X;</CODE></LI>
</UL>
</P>
<H3><A NAME="DTV-mode"></A> DTV mode</H3>
<P>The C64DTV CPU is based on the 6510, but adds some instructions, and does not
support all undocumented instructions.</P>
<P>
<UL>
<LI><CODE>bra {rel}</CODE> Generates opcode $12.</LI>
<LI><CODE>sac #{imm}</CODE> Generates opcode $32.</LI>
<LI><CODE>sir #{imm}</CODE> Generates opcode $42.</LI>
</UL>
</P>
<P>Supported undocumented instructions:</P>
<P>
<UL>
<LI><CODE>ALR: A:=(A and #{imm})/2;</CODE></LI>
<LI><CODE>ANC: A:=A and #{imm};</CODE> Generates opcode $0B.</LI>
<LI><CODE>ARR: A:=(A and #{imm})/2;</CODE></LI>
<LI><CODE>AXS: X:=A and X-#{imm};</CODE></LI>
<LI><CODE>LAS: A,X,S:={addr} and S;</CODE></LI>
<LI><CODE>LAX: A,X:={addr};</CODE></LI>
<LI><CODE>NOP: #{imm}; zp; zp,x; abs; abs,x</CODE></LI>
<LI><CODE>RLA: {addr}:={addr}rol; A:=A and {addr};</CODE></LI>
<LI><CODE>RRA: {addr}:={addr}ror; A:=A adc {addr};</CODE></LI>
<LI><CODE>SHX: {addr}:=X and {addr hi +1};</CODE></LI>
<LI><CODE>SHY: {addr}:=y and {addr hi +1};</CODE></LI>
</UL>
</P>
<H3><A NAME="65SC02-mode"></A> 65SC02 mode</H3>
<P>65SC02 mode supports all regular 6502 instructions, plus the original CMOS
instructions.</P>
<H3><A NAME="65C02-mode"></A> 65C02 mode (CMOS with Rockwell extensions)</H3>
<P>65C02 mode supports all original CMOS instructions, plus the Rockwell (bit
manipulation instructions) extensions.</P>
<H3><A NAME="W65C02-mode"></A> W65C02 mode (CMOS with WDC extensions)</H3>
<P>W65C02 mode supports the Rockwell extensions, plus wai and stp.</P>
<H3><A NAME="65CE02-mode"></A> 65CE02 mode</H3>
<P>All 65CE02 instructions are accepted, plus the Rockwell extensions.</P>
<H3><A NAME="4510-mode"></A> 4510 mode</H3>
<P>The 4510 is a microcontroller that is the core of the Commodore C65 aka C64DX.
It contains among other functions a slightly modified 65CE02/4502 CPU, to allow
address mapping for 20 bits of address space (1 megabyte addressable area).</P>
<P>As compared to the description of the CPU in the
<A HREF="http://www.zimmers.net/anonftp/pub/cbm/c65/c65manualupdated.txt.gz">C65 System Specification</A>
<A HREF="https://raw.githubusercontent.com/MEGA65/c65-specifications/master/c65manualupdated.txt">(updated version)</A> uses these changes:
<UL>
<LI><CODE>LDA (d,SP),Y</CODE> may also be written as <CODE>LDA (d,S),Y</CODE>
(matching the 65816 notation).</LI>
<LI>All branch instruction allow now 16 bit offsets. To use a 16 bit
branch you have to prefix these with an "L" (e.g. "<CODE>LBNE</CODE>" instead of
"<CODE>BNE</CODE>"). This might change at a later implementation of the assembler.</LI>
</UL>
</P>
<P>For more information about the Commodore C65/C64DX and the 4510 CPU, see
<A HREF="http://www.zimmers.net/anonftp/pub/cbm/c65/">http://www.zimmers.net/anonftp/pub/cbm/c65/</A> and
<A HREF="https://en.wikipedia.org/wiki/Commodore_65">Wikipedia</A>.</P>
<H3><A NAME="45GS02-mode"></A> 45GS02 mode</H3>
<P>The 45GS02 is a microcontroller that is the core of the MEGA65.
It is an extension of the 4510 CPU and adds 32-bit addressing and a 32-bit
pseudo register Q that is comprised of the four registers A, X, Y, and Z.</P>
<H3><A NAME="HUC6280-mode"></A> HUC6280 mode (CMOS with Hudson extensions)</H3>
<P>The HUC6280 is a superset of 65C02, used in the PC Engine.</P>
<H3><A NAME="M740-mode"></A> M740 mode</H3>
<P>The M740 is a microcontroller by Mitsubishi, which was marketed for embedded
devices in the mid 80s. It is a superset of 6502, and a subset of 65SC02, plus
some new instructions.</P>
<P>For more information about the M740 Controllers, see
<A HREF="https://en.wikipedia.org/wiki/Mitsubishi_740">Wikipedia</A>.</P>
<H3><A NAME="65816-mode"></A> 65816 mode</H3>
<P>In 65816 mode, several aliases are accepted, in addition to the official
mnemonics:</P>
<P>
<UL>
<LI><CODE>CPA</CODE> is an alias for <CODE>CMP</CODE></LI>
<LI><CODE>DEA</CODE> is an alias for <CODE>DEC A</CODE></LI>
<LI><CODE>INA</CODE> is an alias for <CODE>INC A</CODE></LI>