a949aecabd82e4ea46571492c5287d99bde66efc
[fw/sdcc] / doc / sdccman.lyx
1 #LyX 1.5.6 created this file. For more info see http://www.lyx.org/
2 \lyxformat 276
3 \begin_document
4 \begin_header
5 \textclass book
6 \begin_preamble
7 \pdfoptionpdfminorversion=3
8 \usepackage[
9   pdftitle={SDCC Compiler User Guide},
10   pdfauthor={SDCC development team},
11   pdfsubject={installation, user manual},
12   pdfkeywords={68hc08 8032 8051 ansi c compiler assembler CPU DS390 embedded development free Floating Point Arithmetic Freescale GPL HC08 inline Intel ISO/IEC 9899:1990 Linux MAC OS X manual Maxim mcs51 Microchip microcontroller open source PIC Unix Windows Z80 Zilog},
13   pdfpagemode=UseOutlines,
14   colorlinks=true,
15   linkcolor=blue] {hyperref}
16 %
17 \sloppy
18 \tolerance=500          
19 \emergencystretch=30pt 
20 %
21 \date{}
22 \end_preamble
23 \language english
24 \inputencoding default
25 \font_roman times
26 \font_sans helvet
27 \font_typewriter courier
28 \font_default_family default
29 \font_sc false
30 \font_osf false
31 \font_sf_scale 100
32 \font_tt_scale 100
33 \graphics default
34 \paperfontsize default
35 \spacing single
36 \papersize letterpaper
37 \use_geometry true
38 \use_amsmath 1
39 \use_esint 0
40 \cite_engine basic
41 \use_bibtopic false
42 \paperorientation portrait
43 \leftmargin 30mm
44 \topmargin 20mm
45 \rightmargin 25mm
46 \bottommargin 20mm
47 \secnumdepth 3
48 \tocdepth 3
49 \paragraph_separation indent
50 \defskip medskip
51 \quotes_language swedish
52 \papercolumns 1
53 \papersides 1
54 \paperpagestyle fancy
55 \tracking_changes false
56 \output_changes false
57 \author "" 
58 \author "" 
59 \end_header
60
61 \begin_body
62
63 \begin_layout Standard
64 \begin_inset Note Note
65 status collapsed
66
67 \begin_layout Standard
68 Please note: double dashed longoptions (e.g.
69  --version) are written this way: -
70 \begin_inset ERT
71 status collapsed
72
73 \begin_layout Standard
74
75
76 \backslash
77 /
78 \end_layout
79
80 \end_inset
81
82 -
83 \end_layout
84
85 \begin_layout Standard
86 Two resp.
87  three consecutive dashes would otherwise result in a long resp.
88  extra long dash.
89 \end_layout
90
91 \begin_layout Standard
92 Architecture specific stuff (like memory models, code examples) should maybe
93  later go
94 \end_layout
95
96 \begin_layout Standard
97 into separate sections/chapters/appendices (it is hard to document PIC or
98  Z80 in 
99 \end_layout
100
101 \begin_layout Standard
102 a 8051 centered document) - for now simply add.
103 \end_layout
104
105 \end_inset
106
107
108 \end_layout
109
110 \begin_layout Title
111 SDCC Compiler User Guide
112 \end_layout
113
114 \begin_layout Date
115
116 \size normal
117 SDCC 2.8.9
118 \size footnotesize
119
120 \newline
121 $Date: 2008-11-16#$ 
122 \newline
123 $Revision: 5272$
124 \end_layout
125
126 \begin_layout Standard
127 \begin_inset Note Note
128 status collapsed
129
130 \begin_layout Standard
131 The above strings enclosed in $ are automatically updated by Subversion
132 \end_layout
133
134 \end_inset
135
136
137 \end_layout
138
139 \begin_layout Standard
140 \begin_inset LatexCommand tableofcontents
141
142 \end_inset
143
144
145 \end_layout
146
147 \begin_layout Chapter
148 Introduction
149 \end_layout
150
151 \begin_layout Section
152 About SDCC
153 \end_layout
154
155 \begin_layout Standard
156
157 \series bold
158 SDCC
159 \series default
160  (
161 \emph on
162 S
163 \emph default
164 mall 
165 \emph on
166 D
167 \emph default
168 evice 
169 \emph on
170 C
171 \emph default
172  
173 \emph on
174 C
175 \emph default
176 ompiler) is free open source, retargettable, optimizing ANSI-C compiler
177  by 
178 \series bold
179 Sandeep Dutta
180 \series default
181  designed for 8 bit Microprocessors.
182  The current version targets Intel MCS51 based Microprocessors (8031, 8032,
183  8051, 8052
184 \begin_inset LatexCommand index
185 name "8031, 8032, 8051, 8052, mcs51 CPU"
186
187 \end_inset
188
189 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
190  Zilog Z80 based MCUs.
191  It can be retargeted for other microprocessors, support for Microchip PIC,
192  Atmel AVR is under development.
193  The entire source code for the compiler is distributed under GPL.
194  SDCC uses ASXXXX
195 \begin_inset LatexCommand index
196 name "asXXXX (as-gbz80, as-hc08, asx8051, as-z80)"
197
198 \end_inset
199
200  & ASLINK
201 \begin_inset LatexCommand index
202 name "aslink"
203
204 \end_inset
205
206 , an open source retargetable assembler & linker.
207  SDCC has extensive language extensions suitable for utilizing various microcont
208 rollers and underlying hardware effectively.
209  
210 \newline
211
212 \newline
213 In addition to the MCU specific optimizations SDCC also does a host of
214  standard optimizations like:
215 \end_layout
216
217 \begin_layout Itemize
218 global sub expression elimination, 
219 \end_layout
220
221 \begin_layout Itemize
222 loop optimizations (loop invariant, strength reduction of induction variables
223  and loop reversing), 
224 \end_layout
225
226 \begin_layout Itemize
227 constant folding & propagation, 
228 \end_layout
229
230 \begin_layout Itemize
231 copy propagation, 
232 \end_layout
233
234 \begin_layout Itemize
235 dead code elimination 
236 \end_layout
237
238 \begin_layout Itemize
239 jump tables for 
240 \emph on
241 switch
242 \emph default
243  statements.
244 \end_layout
245
246 \begin_layout Standard
247 For the back-end SDCC uses a global register allocation scheme which should
248  be well suited for other 8 bit MCUs.
249  
250 \newline
251
252 \newline
253 The peep hole optimizer uses a rule based substitution mechanism which
254  is MCU independent.
255  
256 \newline
257
258 \newline
259 Supported data-types are:
260 \end_layout
261
262 \begin_layout Standard
263 \begin_inset Tabular
264 <lyxtabular version="3" rows="8" columns="5">
265 <features>
266 <column alignment="center" valignment="top" leftline="true" width="0">
267 <column alignment="center" valignment="top" leftline="true" width="0">
268 <column alignment="center" valignment="top" leftline="true" width="0">
269 <column alignment="center" valignment="top" leftline="true" width="0">
270 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
271 <row topline="true" bottomline="true">
272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
273 \begin_inset Text
274
275 \begin_layout Standard
276 type
277 \end_layout
278
279 \end_inset
280 </cell>
281 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
282 \begin_inset Text
283
284 \begin_layout Standard
285 width
286 \end_layout
287
288 \end_inset
289 </cell>
290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
291 \begin_inset Text
292
293 \begin_layout Standard
294 default
295 \end_layout
296
297 \end_inset
298 </cell>
299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
300 \begin_inset Text
301
302 \begin_layout Standard
303 signed range
304 \end_layout
305
306 \end_inset
307 </cell>
308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
309 \begin_inset Text
310
311 \begin_layout Standard
312 unsigned range
313 \end_layout
314
315 \end_inset
316 </cell>
317 </row>
318 <row topline="true">
319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
320 \begin_inset Text
321
322 \begin_layout Standard
323 bool
324 \end_layout
325
326 \end_inset
327 </cell>
328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
329 \begin_inset Text
330
331 \begin_layout Standard
332 1 bit
333 \end_layout
334
335 \end_inset
336 </cell>
337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
338 \begin_inset Text
339
340 \begin_layout Standard
341 unsigned
342 \end_layout
343
344 \end_inset
345 </cell>
346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
347 \begin_inset Text
348
349 \begin_layout Standard
350 -
351 \end_layout
352
353 \end_inset
354 </cell>
355 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
356 \begin_inset Text
357
358 \begin_layout Standard
359 0, 1
360 \end_layout
361
362 \end_inset
363 </cell>
364 </row>
365 <row topline="true">
366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
367 \begin_inset Text
368
369 \begin_layout Standard
370 char
371 \end_layout
372
373 \end_inset
374 </cell>
375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
376 \begin_inset Text
377
378 \begin_layout Standard
379 8 bits, 1 byte
380 \end_layout
381
382 \end_inset
383 </cell>
384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
385 \begin_inset Text
386
387 \begin_layout Standard
388 signed
389 \end_layout
390
391 \end_inset
392 </cell>
393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
394 \begin_inset Text
395
396 \begin_layout Standard
397 -128, +127
398 \end_layout
399
400 \end_inset
401 </cell>
402 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
403 \begin_inset Text
404
405 \begin_layout Standard
406 0, +255
407 \end_layout
408
409 \end_inset
410 </cell>
411 </row>
412 <row topline="true">
413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
414 \begin_inset Text
415
416 \begin_layout Standard
417 short
418 \end_layout
419
420 \end_inset
421 </cell>
422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
423 \begin_inset Text
424
425 \begin_layout Standard
426 16 bits, 2 bytes
427 \end_layout
428
429 \end_inset
430 </cell>
431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
432 \begin_inset Text
433
434 \begin_layout Standard
435 signed
436 \end_layout
437
438 \end_inset
439 </cell>
440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
441 \begin_inset Text
442
443 \begin_layout Standard
444 -32.768, +32.767
445 \end_layout
446
447 \end_inset
448 </cell>
449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
450 \begin_inset Text
451
452 \begin_layout Standard
453 0, +65.535
454 \end_layout
455
456 \end_inset
457 </cell>
458 </row>
459 <row topline="true">
460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
461 \begin_inset Text
462
463 \begin_layout Standard
464 int
465 \end_layout
466
467 \end_inset
468 </cell>
469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
470 \begin_inset Text
471
472 \begin_layout Standard
473 16 bits, 2 bytes
474 \end_layout
475
476 \end_inset
477 </cell>
478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
479 \begin_inset Text
480
481 \begin_layout Standard
482 signed
483 \end_layout
484
485 \end_inset
486 </cell>
487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
488 \begin_inset Text
489
490 \begin_layout Standard
491 -32.768, +32.767
492 \end_layout
493
494 \end_inset
495 </cell>
496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
497 \begin_inset Text
498
499 \begin_layout Standard
500 0, +65.535
501 \end_layout
502
503 \end_inset
504 </cell>
505 </row>
506 <row topline="true" bottomline="true">
507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
508 \begin_inset Text
509
510 \begin_layout Standard
511 long
512 \end_layout
513
514 \end_inset
515 </cell>
516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
517 \begin_inset Text
518
519 \begin_layout Standard
520 32 bits, 4 bytes
521 \end_layout
522
523 \end_inset
524 </cell>
525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
526 \begin_inset Text
527
528 \begin_layout Standard
529 signed
530 \end_layout
531
532 \end_inset
533 </cell>
534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
535 \begin_inset Text
536
537 \begin_layout Standard
538 -2.147.483.648, +2.147.483.647
539 \end_layout
540
541 \end_inset
542 </cell>
543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
544 \begin_inset Text
545
546 \begin_layout Standard
547 0, +4.294.967.295
548 \end_layout
549
550 \end_inset
551 </cell>
552 </row>
553 <row topline="true" bottomline="true">
554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
555 \begin_inset Text
556
557 \begin_layout Standard
558 float
559 \end_layout
560
561 \end_inset
562 </cell>
563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
564 \begin_inset Text
565
566 \begin_layout Standard
567 4 bytes IEEE 754
568 \end_layout
569
570 \end_inset
571 </cell>
572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
573 \begin_inset Text
574
575 \begin_layout Standard
576 signed
577 \end_layout
578
579 \end_inset
580 </cell>
581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
582 \begin_inset Text
583
584 \begin_layout Standard
585
586 \end_layout
587
588 \end_inset
589 </cell>
590 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
591 \begin_inset Text
592
593 \begin_layout Standard
594 1.175494351E-38, 
595 \family roman
596 \series medium
597 \shape up
598 \size normal
599 \emph off
600 \bar no
601 \noun off
602 \color none
603 3.402823466E+38
604 \end_layout
605
606 \end_inset
607 </cell>
608 </row>
609 <row topline="true" bottomline="true">
610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
611 \begin_inset Text
612
613 \begin_layout Standard
614 pointer
615 \end_layout
616
617 \end_inset
618 </cell>
619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
620 \begin_inset Text
621
622 \begin_layout Standard
623 1, 2, 3 or 4 bytes
624 \end_layout
625
626 \end_inset
627 </cell>
628 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
629 \begin_inset Text
630
631 \begin_layout Standard
632 generic
633 \end_layout
634
635 \end_inset
636 </cell>
637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
638 \begin_inset Text
639
640 \begin_layout Standard
641
642 \end_layout
643
644 \end_inset
645 </cell>
646 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
647 \begin_inset Text
648
649 \begin_layout Standard
650
651 \end_layout
652
653 \end_inset
654 </cell>
655 </row>
656 </lyxtabular>
657
658 \end_inset
659
660
661 \newline
662 The compiler also allows 
663 \emph on
664 inline assembler code
665 \emph default
666  to be embedded anywhere in a function.
667  In addition, routines developed in assembly can also be called.
668 \newline
669
670 \newline
671 SDCC also
672  provides an option (-
673 \begin_inset ERT
674 status collapsed
675
676 \begin_layout Standard
677
678
679 \backslash
680 /
681 \end_layout
682
683 \end_inset
684
685 -cyclomatic) to report the relative complexity of a function.
686  These functions can then be further optimized, or hand coded in assembly
687  if needed.
688  
689 \newline
690
691 \newline
692 SDCC also comes with a companion source level debugger SDCDB.
693  The debugger currently uses ucSim, a free open source simulator for 8051
694  and other micro-controllers.
695 \newline
696
697 \newline
698 The latest SDCC version can be downloaded from
699  
700 \begin_inset LatexCommand url
701 target "http://sdcc.sourceforge.net/snap.php"
702
703 \end_inset
704
705 .
706  
707 \emph on
708 Please note: the compiler will probably always be some steps ahead of this
709  documentation
710 \series bold
711 \emph default
712
713 \begin_inset LatexCommand index
714 name "Status of documentation"
715
716 \end_inset
717
718
719 \begin_inset Foot
720 status open
721
722 \begin_layout Standard
723 Obviously this has pros and cons
724 \end_layout
725
726 \end_inset
727
728 .
729 \end_layout
730
731 \begin_layout Section
732 Open Source
733 \end_layout
734
735 \begin_layout Standard
736 All packages used in this compiler system are 
737 \emph on
738 open source
739 \emph default
740  and 
741 \emph on
742 freeware
743 \emph default
744 ; source code for all the sub-packages (pre-processor, assemblers, linkers
745  etc.) is distributed with the package.
746  This documentation is maintained using a free open source word processor
747  (LyX).
748 \newline
749 This program is free software; you can redistribute it and/or modify
750  it under the terms of the GNU General Public License
751 \begin_inset LatexCommand index
752 name "GNU General Public License, GPL"
753
754 \end_inset
755
756  as published by the Free Software Foundation; either version 2, or (at
757  your option) any later version.
758  This program is distributed in the hope that it will be useful, but WITHOUT
759  ANY WARRANTY; without even the implied warranty
760 \begin_inset LatexCommand index
761 name "warranty"
762
763 \end_inset
764
765  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
766  See the GNU General Public License for more details.
767  You should have received a copy of the GNU General Public License along
768  with this program; if not, write to the Free Software Foundation, 59 Temple
769  Place - Suite 330, Boston, MA 02111-1307, USA.
770  In other words, you are welcome to use, share and improve this program.
771  You are forbidden to forbid anyone else to use, share and improve what
772  you give them.
773  Help stamp out software-hoarding! 
774 \end_layout
775
776 \begin_layout Section
777 Typographic conventions
778 \begin_inset LatexCommand index
779 name "Typographic conventions"
780
781 \end_inset
782
783
784 \end_layout
785
786 \begin_layout Standard
787 Throughout this manual, we will use the following convention.
788  Commands you have to type in are printed in 
789 \family sans
790 \series bold
791 "sans serif"
792 \series default
793 .
794
795 \family default
796  Code samples are printed in 
797 \family typewriter
798 typewriter font.
799
800 \family default
801  Interesting items and new terms are printed in 
802 \emph on
803 italic.
804 \end_layout
805
806 \begin_layout Section
807 Compatibility
808 \begin_inset LatexCommand label
809 name "sec:Compatibility-with-previous"
810
811 \end_inset
812
813  with previous versions
814 \begin_inset LatexCommand index
815 name "Compatibility with previous versions"
816
817 \end_inset
818
819
820 \end_layout
821
822 \begin_layout Standard
823 Newer versions have usually numerous bug fixes compared with the previous
824  version.
825  But we also sometimes introduce some incompatibilities with older versions.
826  Not just for the fun of it, but to make the compiler more stable, efficient
827  and ANSI compliant
828 \begin_inset LatexCommand index
829 name "ANSI-compliance"
830
831 \end_inset
832
833  (see section 
834 \begin_inset LatexCommand ref
835 reference "sub:ANSI-Compliance"
836
837 \end_inset
838
839  for ANSI-Compliance).
840  
841 \begin_inset Note Note
842 status collapsed
843
844 \begin_layout Standard
845 It would be fine to add to each item, in which version was it changed.
846 \end_layout
847
848 \end_inset
849
850
851 \newline
852
853 \end_layout
854
855 \begin_layout Itemize
856 short is now equivalent to int (16 bits), it used to be equivalent to char
857  (8 bits) which is not ANSI compliant.
858  To maintain compatibility, old programs may be compiled using the -
859 \begin_inset ERT
860 status collapsed
861
862 \begin_layout Standard
863
864
865 \backslash
866 /
867 \end_layout
868
869 \end_inset
870
871 -short-is-8bits commandline option (see 
872 \begin_inset LatexCommand vref
873 reference "lyx:--short-is-8bits"
874
875 \end_inset
876
877 ).
878 \end_layout
879
880 \begin_layout Itemize
881 the default directory for gcc-builds where include, library and documentation
882  files are stored is now in /usr/local/share.
883 \end_layout
884
885 \begin_layout Itemize
886 char type parameters to vararg
887 \begin_inset LatexCommand index
888 name "vararg, va\\_arg"
889
890 \end_inset
891
892  functions are casted to int unless explicitly casted and 
893 \series bold
894 -
895 \begin_inset ERT
896 status collapsed
897
898 \begin_layout Standard
899
900
901 \backslash
902 /
903 \end_layout
904
905 \end_inset
906
907 -std-c89
908 \begin_inset LatexCommand index
909 name "-\\/-std-c89"
910
911 \end_inset
912
913
914 \series default
915  and 
916 \series bold
917 -
918 \begin_inset ERT
919 status collapsed
920
921 \begin_layout Standard
922
923
924 \backslash
925 /
926 \end_layout
927
928 \end_inset
929
930 -std-c99
931 \begin_inset LatexCommand index
932 name "-\\/-std-c99"
933
934 \end_inset
935
936
937 \series default
938  command line option are not defined 
939 \begin_inset Marginal
940 status collapsed
941
942 \begin_layout Standard
943
944 \series bold
945 \InsetSpace ~
946 !
947 \end_layout
948
949 \end_inset
950
951 , e.g.: 
952 \newline
953
954 \family typewriter
955 \InsetSpace ~
956 \InsetSpace ~
957 char a=3;
958 \newline
959 \InsetSpace ~
960 \InsetSpace ~
961 printf ("%d %c
962 \backslash
963 n", a, (char)a);
964 \family default
965
966 \newline
967  will push a as an int and as a char resp if 
968 \series bold
969 -
970 \begin_inset ERT
971 status collapsed
972
973 \begin_layout Standard
974
975
976 \backslash
977 /
978 \end_layout
979
980 \end_inset
981
982 -std-c89
983 \begin_inset LatexCommand index
984 name "-\\/-std-c89"
985
986 \end_inset
987
988
989 \series default
990  and 
991 \series bold
992 -
993 \begin_inset ERT
994 status collapsed
995
996 \begin_layout Standard
997
998
999 \backslash
1000 /
1001 \end_layout
1002
1003 \end_inset
1004
1005 -std-c99
1006 \begin_inset LatexCommand index
1007 name "-\\/-std-c99"
1008
1009 \end_inset
1010
1011
1012 \series default
1013  command line options are not defined,
1014 \newline
1015  will push a as two ints if 
1016 \series bold
1017 -
1018 \begin_inset ERT
1019 status collapsed
1020
1021 \begin_layout Standard
1022
1023
1024 \backslash
1025 /
1026 \end_layout
1027
1028 \end_inset
1029
1030 -std-c89
1031 \begin_inset LatexCommand index
1032 name "-\\/-std-c89"
1033
1034 \end_inset
1035
1036
1037 \series default
1038  or 
1039 \series bold
1040 -
1041 \begin_inset ERT
1042 status collapsed
1043
1044 \begin_layout Standard
1045
1046
1047 \backslash
1048 /
1049 \end_layout
1050
1051 \end_inset
1052
1053 -std-c99
1054 \begin_inset LatexCommand index
1055 name "-\\/-std-c99"
1056
1057 \end_inset
1058
1059
1060 \series default
1061  command line option is defined.
1062 \end_layout
1063
1064 \begin_layout Itemize
1065 option -
1066 \begin_inset ERT
1067 status collapsed
1068
1069 \begin_layout Standard
1070
1071
1072 \backslash
1073 /
1074 \end_layout
1075
1076 \end_inset
1077
1078 -regextend has been removed.
1079 \end_layout
1080
1081 \begin_layout Itemize
1082 option -
1083 \begin_inset ERT
1084 status collapsed
1085
1086 \begin_layout Standard
1087
1088
1089 \backslash
1090 /
1091 \end_layout
1092
1093 \end_inset
1094
1095 -noregparms has been removed.
1096 \end_layout
1097
1098 \begin_layout Itemize
1099 option -
1100 \begin_inset ERT
1101 status collapsed
1102
1103 \begin_layout Standard
1104
1105
1106 \backslash
1107 /
1108 \end_layout
1109
1110 \end_inset
1111
1112 -stack-after-data has been removed.
1113 \end_layout
1114
1115 \begin_layout Itemize
1116 bit
1117 \begin_inset LatexCommand index
1118 name "bit"
1119
1120 \end_inset
1121
1122  and sbit
1123 \begin_inset LatexCommand index
1124 name "sbit"
1125
1126 \end_inset
1127
1128
1129 \begin_inset LatexCommand index
1130 name "\\_\\_sbit"
1131
1132 \end_inset
1133
1134  types now consistently behave like the C99 _Bool type with respect to type
1135  conversion
1136 \begin_inset LatexCommand index
1137 name "type conversion"
1138
1139 \end_inset
1140
1141
1142 \begin_inset LatexCommand index
1143 name "type promotion"
1144
1145 \end_inset
1146
1147 .
1148  The most common incompatibility resulting from this change is related to
1149  bit toggling
1150 \begin_inset LatexCommand index
1151 name "Bit toggling"
1152
1153 \end_inset
1154
1155  idioms, e.g.:
1156 \newline
1157
1158 \family typewriter
1159 \InsetSpace ~
1160 \InsetSpace ~
1161 bit b;
1162 \newline
1163 \InsetSpace ~
1164 \InsetSpace ~
1165 b = ~
1166 \begin_inset LatexCommand index
1167 name "\\~\\/ Operator"
1168
1169 \end_inset
1170
1171 b; /* equivalent to b=1 instead of toggling b */
1172 \begin_inset Marginal
1173 status collapsed
1174
1175 \begin_layout Standard
1176
1177 \series bold
1178 \InsetSpace ~
1179 !
1180 \end_layout
1181
1182 \end_inset
1183
1184
1185 \newline
1186 \InsetSpace ~
1187 \InsetSpace ~
1188 b = !b; /* toggles b */
1189 \newline
1190
1191 \family default
1192 In previous versions, both forms would have toggled the bit.
1193 \end_layout
1194
1195 \begin_layout Itemize
1196 in older versions, the preprocessor was always called with 
1197 \series bold
1198 -
1199 \begin_inset ERT
1200 status collapsed
1201
1202 \begin_layout Standard
1203
1204
1205 \backslash
1206 /
1207 \end_layout
1208
1209 \end_inset
1210
1211 -std-c99
1212 \begin_inset LatexCommand index
1213 name "-\\/-std-c99"
1214
1215 \end_inset
1216
1217
1218 \series default
1219  regardless of the 
1220 \series bold
1221 -
1222 \begin_inset ERT
1223 status collapsed
1224
1225 \begin_layout Standard
1226
1227
1228 \backslash
1229 /
1230 \end_layout
1231
1232 \end_inset
1233
1234 -std-xxx
1235 \series default
1236  setting.
1237  This is no longer true, and can cause compilation failures on code built
1238  with 
1239 \series bold
1240 -
1241 \begin_inset ERT
1242 status collapsed
1243
1244 \begin_layout Standard
1245
1246
1247 \backslash
1248 /
1249 \end_layout
1250
1251 \end_inset
1252
1253 -std-c89
1254 \begin_inset LatexCommand index
1255 name "-\\/-std-c89"
1256
1257 \end_inset
1258
1259
1260 \series default
1261  but using c99 preprocessor features, such as one-line (//) comments
1262 \end_layout
1263
1264 \begin_layout Itemize
1265 in versions older then 2.8.4 the pic16 *printf() and printf_tiny() library
1266  functions supported undocumented and not standard compliant 'b' binary
1267  format specifier ("%b", "%hb" and "%lb").
1268  The 'b' specifier is now disabled by default.
1269  It can be enabled by defining BINARY_SPECIFIER macro in files device/lib/pic16/
1270 libc/stdio/vfprintf.c and device/lib/pic16/libc/stdio/printf_tiny.c and recompilin
1271 g the library.
1272 \end_layout
1273
1274 \begin_layout Itemize
1275 in versions older then 2.8.5 the unnamed bitfield structure members participated
1276  in initialization, which is not conforming with ISO/IEC 9899:1999 standard
1277  (see section Section 6.7.8 Initialization, clause 9)
1278 \newline
1279
1280 \newline
1281 Old behavior, before
1282  version 2.8.5:
1283 \family typewriter
1284
1285 \newline
1286 \InsetSpace ~
1287 \InsetSpace ~
1288 struct {
1289 \newline
1290 \InsetSpace ~
1291 \InsetSpace ~
1292 \InsetSpace ~
1293 \InsetSpace ~
1294 int a : 2;
1295 \newline
1296 \InsetSpace ~
1297 \InsetSpace ~
1298 \InsetSpace ~
1299 \InsetSpace ~
1300 char\InsetSpace ~
1301  : 2;
1302 \newline
1303 \InsetSpace ~
1304 \InsetSpace ~
1305 \InsetSpace ~
1306 \InsetSpace ~
1307 int b : 2;
1308 \newline
1309 \InsetSpace ~
1310 \InsetSpace ~
1311 } s = {1, 2, 3};
1312 \family default
1313
1314 \newline
1315
1316 \family typewriter
1317 /* s.a = 1, s.b = 3 */
1318 \family default
1319
1320 \newline
1321
1322 \newline
1323 New behavior:
1324 \family typewriter
1325
1326 \newline
1327 \InsetSpace ~
1328 \InsetSpace ~
1329 struct {
1330 \newline
1331 \InsetSpace ~
1332 \InsetSpace ~
1333 \InsetSpace ~
1334 \InsetSpace ~
1335 int a : 2;
1336 \newline
1337 \InsetSpace ~
1338 \InsetSpace ~
1339 \InsetSpace ~
1340 \InsetSpace ~
1341 char\InsetSpace ~
1342  : 2;
1343 \newline
1344 \InsetSpace ~
1345 \InsetSpace ~
1346 \InsetSpace ~
1347 \InsetSpace ~
1348 int b : 2;
1349 \newline
1350 \InsetSpace ~
1351 \InsetSpace ~
1352 } s = {1, 2};
1353 \family default
1354
1355 \newline
1356
1357 \family typewriter
1358 /* s.a = 1, s.b = 2 */
1359 \end_layout
1360
1361 \begin_layout Section
1362 System Requirements
1363 \end_layout
1364
1365 \begin_layout Standard
1366 What do you need before you start installation of SDCC? A computer, and
1367  a desire to compute.
1368  The preferred method of installation is to compile SDCC from source using
1369  GNU gcc and make.
1370  For Windows some pre-compiled binary distributions are available for your
1371  convenience.
1372  You should have some experience with command line tools and compiler use.
1373 \end_layout
1374
1375 \begin_layout Section
1376 Other Resources
1377 \end_layout
1378
1379 \begin_layout Standard
1380 The SDCC home page at 
1381 \begin_inset LatexCommand url
1382 target "http://sdcc.sourceforge.net/"
1383
1384 \end_inset
1385
1386  is a great place to find distribution sets.
1387  You can also find links to the user mailing lists that offer help or discuss
1388  SDCC with other SDCC users.
1389  Web links to other SDCC related sites can also be found here.
1390  This document can be found in the DOC directory of the source package as
1391  a text or HTML file.
1392  A pdf version of this document is available at 
1393 \begin_inset LatexCommand url
1394 target "http://sdcc.sourceforge.net/doc/sdccman.pdf"
1395
1396 \end_inset
1397
1398 .
1399  Some of the other tools (simulator and assembler) included with SDCC contain
1400  their own documentation and can be found in the source distribution.
1401  If you want the latest unreleased software, the complete source package
1402  is available directly from Subversion on https://sdcc.svn.sourceforge.net/svnroot/
1403 sdcc/trunk/sdcc.
1404 \end_layout
1405
1406 \begin_layout Section
1407 Wishes for the future
1408 \end_layout
1409
1410 \begin_layout Standard
1411 There are (and always will be) some things that could be done.
1412  Here are some I can think of:
1413 \newline
1414
1415 \end_layout
1416
1417 \begin_layout Standard
1418
1419 \family typewriter
1420 char KernelFunction3(char p) at 0x340;
1421 \newline
1422
1423 \end_layout
1424
1425 \begin_layout Standard
1426
1427 \family typewriter
1428 better code banking
1429 \begin_inset LatexCommand index
1430 name "code banking (limited support)"
1431
1432 \end_inset
1433
1434  support for mcs51
1435 \newline
1436
1437 \newline
1438
1439 \family default
1440 If you can think of some more, please see the section 
1441 \begin_inset LatexCommand ref
1442 reference "sub:Requesting-Features"
1443
1444 \end_inset
1445
1446  about filing feature requests
1447 \begin_inset LatexCommand index
1448 name "Requesting features"
1449
1450 \end_inset
1451
1452
1453 \begin_inset LatexCommand index
1454 name "Feature request"
1455
1456 \end_inset
1457
1458 .
1459 \newline
1460
1461 \end_layout
1462
1463 \begin_layout Chapter
1464 Installing SDCC
1465 \begin_inset LatexCommand index
1466 name "Installation"
1467
1468 \end_inset
1469
1470
1471 \end_layout
1472
1473 \begin_layout Standard
1474 For most users it is sufficient to skip to either section 
1475 \begin_inset LatexCommand ref
1476 reference "sub:Building-SDCC-on-Linux"
1477
1478 \end_inset
1479
1480  (Unix) or section 
1481 \begin_inset LatexCommand ref
1482 reference "sub:Windows-Install"
1483
1484 \end_inset
1485
1486  (Windows).
1487  More detailed instructions follow below.
1488 \end_layout
1489
1490 \begin_layout Section
1491 Configure Options
1492 \begin_inset LatexCommand index
1493 name "Options SDCC configuration"
1494
1495 \end_inset
1496
1497
1498 \end_layout
1499
1500 \begin_layout Standard
1501 The install paths, search paths and other options are defined when running
1502  'configure'.
1503  The defaults can be overridden by:
1504 \end_layout
1505
1506 \begin_layout List
1507 \labelwidthstring 00.00.0000
1508 -
1509 \begin_inset ERT
1510 status collapsed
1511
1512 \begin_layout Standard
1513
1514
1515 \backslash
1516 /
1517 \end_layout
1518
1519 \end_inset
1520
1521 -prefix see table below
1522 \end_layout
1523
1524 \begin_layout List
1525 \labelwidthstring 00.00.0000
1526 -
1527 \begin_inset ERT
1528 status collapsed
1529
1530 \begin_layout Standard
1531
1532
1533 \backslash
1534 /
1535 \end_layout
1536
1537 \end_inset
1538
1539 -exec_prefix see table below
1540 \end_layout
1541
1542 \begin_layout List
1543 \labelwidthstring 00.00.0000
1544 -
1545 \begin_inset ERT
1546 status collapsed
1547
1548 \begin_layout Standard
1549
1550
1551 \backslash
1552 /
1553 \end_layout
1554
1555 \end_inset
1556
1557 -bindir see table below
1558 \end_layout
1559
1560 \begin_layout List
1561 \labelwidthstring 00.00.0000
1562 -
1563 \begin_inset ERT
1564 status collapsed
1565
1566 \begin_layout Standard
1567
1568
1569 \backslash
1570 /
1571 \end_layout
1572
1573 \end_inset
1574
1575 -datadir see table below
1576 \end_layout
1577
1578 \begin_layout List
1579 \labelwidthstring 00.00.0000
1580 -
1581 \begin_inset ERT
1582 status collapsed
1583
1584 \begin_layout Standard
1585
1586
1587 \backslash
1588 /
1589 \end_layout
1590
1591 \end_inset
1592
1593 -datarootdir see table below
1594 \newline
1595
1596 \end_layout
1597
1598 \begin_layout List
1599 \labelwidthstring 00.00.0000
1600 \InsetSpace ~
1601 \InsetSpace ~
1602 docdir environment variable, see table below
1603 \end_layout
1604
1605 \begin_layout List
1606 \labelwidthstring 00.00.0000
1607 \InsetSpace ~
1608 \InsetSpace ~
1609 include_dir_suffix environment variable, see table below
1610 \end_layout
1611
1612 \begin_layout List
1613 \labelwidthstring 00.00.0000
1614 \InsetSpace ~
1615 \InsetSpace ~
1616 lib_dir_suffix environment variable, see table below
1617 \end_layout
1618
1619 \begin_layout List
1620 \labelwidthstring 00.00.0000
1621 \InsetSpace ~
1622 \InsetSpace ~
1623 sdccconf_h_dir_separator environment variable, either / or 
1624 \backslash
1625
1626 \backslash
1627  makes sense here.
1628  This character will only be used in sdccconf.h; don't forget it's a C-header,
1629  therefore a double-backslash is needed there.
1630 \newline
1631
1632 \end_layout
1633
1634 \begin_layout List
1635 \labelwidthstring 00.00.0000
1636 -
1637 \begin_inset ERT
1638 status collapsed
1639
1640 \begin_layout Standard
1641
1642
1643 \backslash
1644 /
1645 \end_layout
1646
1647 \end_inset
1648
1649 -disable-mcs51-port Excludes the Intel mcs51 port
1650 \end_layout
1651
1652 \begin_layout List
1653 \labelwidthstring 00.00.0000
1654 -
1655 \begin_inset ERT
1656 status collapsed
1657
1658 \begin_layout Standard
1659
1660
1661 \backslash
1662 /
1663 \end_layout
1664
1665 \end_inset
1666
1667 -disable-gbz80-port Excludes the Gameboy gbz80 port
1668 \end_layout
1669
1670 \begin_layout List
1671 \labelwidthstring 00.00.0000
1672 -
1673 \begin_inset ERT
1674 status collapsed
1675
1676 \begin_layout Standard
1677
1678
1679 \backslash
1680 /
1681 \end_layout
1682
1683 \end_inset
1684
1685 -disable-z80-port Excludes the z80 port
1686 \end_layout
1687
1688 \begin_layout List
1689 \labelwidthstring 00.00.0000
1690 -
1691 \begin_inset ERT
1692 status collapsed
1693
1694 \begin_layout Standard
1695
1696
1697 \backslash
1698 /
1699 \end_layout
1700
1701 \end_inset
1702
1703 -disable-avr-port Excludes the AVR port
1704 \end_layout
1705
1706 \begin_layout List
1707 \labelwidthstring 00.00.0000
1708 -
1709 \begin_inset ERT
1710 status collapsed
1711
1712 \begin_layout Standard
1713
1714
1715 \backslash
1716 /
1717 \end_layout
1718
1719 \end_inset
1720
1721 -disable-ds390-port Excludes the DS390 port
1722 \end_layout
1723
1724 \begin_layout List
1725 \labelwidthstring 00.00.0000
1726 -
1727 \begin_inset ERT
1728 status collapsed
1729
1730 \begin_layout Standard
1731
1732
1733 \backslash
1734 /
1735 \end_layout
1736
1737 \end_inset
1738
1739 -disable-hc08-port Excludes the HC08 port
1740 \end_layout
1741
1742 \begin_layout List
1743 \labelwidthstring 00.00.0000
1744 -
1745 \begin_inset ERT
1746 status collapsed
1747
1748 \begin_layout Standard
1749
1750
1751 \backslash
1752 /
1753 \end_layout
1754
1755 \end_inset
1756
1757 -disable-pic-port Excludes the PIC14 port
1758 \end_layout
1759
1760 \begin_layout List
1761 \labelwidthstring 00.00.0000
1762 -
1763 \begin_inset ERT
1764 status collapsed
1765
1766 \begin_layout Standard
1767
1768
1769 \backslash
1770 /
1771 \end_layout
1772
1773 \end_inset
1774
1775 -disable-pic16-port Excludes the PIC16 port
1776 \end_layout
1777
1778 \begin_layout List
1779 \labelwidthstring 00.00.0000
1780 -
1781 \begin_inset ERT
1782 status collapsed
1783
1784 \begin_layout Standard
1785
1786
1787 \backslash
1788 /
1789 \end_layout
1790
1791 \end_inset
1792
1793 -disable-xa51-port Excludes the XA51 port
1794 \end_layout
1795
1796 \begin_layout List
1797 \labelwidthstring 00.00.0000
1798 -
1799 \begin_inset ERT
1800 status collapsed
1801
1802 \begin_layout Standard
1803
1804
1805 \backslash
1806 /
1807 \end_layout
1808
1809 \end_inset
1810
1811 -disable-ucsim Disables configuring and building of ucsim
1812 \end_layout
1813
1814 \begin_layout List
1815 \labelwidthstring 00.00.0000
1816 -
1817 \begin_inset ERT
1818 status collapsed
1819
1820 \begin_layout Standard
1821
1822
1823 \backslash
1824 /
1825 \end_layout
1826
1827 \end_inset
1828
1829 -disable-device-lib Disables automatically building device libraries
1830 \end_layout
1831
1832 \begin_layout List
1833 \labelwidthstring 00.00.0000
1834 -
1835 \begin_inset ERT
1836 status collapsed
1837
1838 \begin_layout Standard
1839
1840
1841 \backslash
1842 /
1843 \end_layout
1844
1845 \end_inset
1846
1847 -disable-packihx Disables building packihx
1848 \newline
1849
1850 \end_layout
1851
1852 \begin_layout List
1853 \labelwidthstring 00.00.0000
1854 -
1855 \begin_inset ERT
1856 status collapsed
1857
1858 \begin_layout Standard
1859
1860
1861 \backslash
1862 /
1863 \end_layout
1864
1865 \end_inset
1866
1867 -enable-doc Build pdf, html and txt files from the lyx sources
1868 \end_layout
1869
1870 \begin_layout List
1871 \labelwidthstring 00.00.0000
1872 -
1873 \begin_inset ERT
1874 status collapsed
1875
1876 \begin_layout Standard
1877
1878
1879 \backslash
1880 /
1881 \end_layout
1882
1883 \end_inset
1884
1885 -enable-libgc Use the Bohem memory allocator.
1886  Lower runtime footprint.
1887 \end_layout
1888
1889 \begin_layout List
1890 \labelwidthstring 00.00.0000
1891 -
1892 \begin_inset ERT
1893 status collapsed
1894
1895 \begin_layout Standard
1896
1897
1898 \backslash
1899 /
1900 \end_layout
1901
1902 \end_inset
1903
1904 -without-ccache Do not use ccache even if available
1905 \end_layout
1906
1907 \begin_layout Standard
1908 Furthermore the environment variables CC, CFLAGS, ...
1909  the tools and their arguments can be influenced.
1910  Please see `configure -
1911 \begin_inset ERT
1912 status collapsed
1913
1914 \begin_layout Standard
1915
1916
1917 \backslash
1918 /
1919 \end_layout
1920
1921 \end_inset
1922
1923 -help' and the man/info pages of `configure' for details.
1924 \newline
1925
1926 \newline
1927 The names of the
1928  standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1929 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1930  SDCC_LIB_NAME are defined by `configure' too.
1931  At the moment it's not possible to change the default settings (it was
1932  simply never required).
1933 \newline
1934
1935 \newline
1936 These configure options are compiled into the binaries,
1937  and can only be changed by rerunning 'configure' and recompiling SDCC.
1938  The configure options are written in 
1939 \emph on
1940 italics
1941 \emph default
1942  to distinguish them from run time environment variables (see section search
1943  paths).
1944 \newline
1945
1946 \newline
1947 The settings for 
1948 \begin_inset Quotes sld
1949 \end_inset
1950
1951 Win32 builds
1952 \begin_inset Quotes srd
1953 \end_inset
1954
1955  are used by the SDCC team to build the official Win32 binaries.
1956  The SDCC team uses Mingw32 to build the official Windows binaries, because
1957  it's
1958 \end_layout
1959
1960 \begin_layout Enumerate
1961 open source, 
1962 \end_layout
1963
1964 \begin_layout Enumerate
1965 a gcc compiler and last but not least
1966 \end_layout
1967
1968 \begin_layout Enumerate
1969 the binaries can be built by cross compiling on SDCC Distributed Compile
1970  Farm.
1971 \end_layout
1972
1973 \begin_layout Standard
1974 See the examples, how to pass the Win32 settings to 'configure'.
1975  The other Win32 builds using Borland, VC or whatever don't use 'configure',
1976  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1977  for Win32.
1978 \newline
1979
1980 \newline
1981 These defaults are:
1982 \newline
1983
1984 \end_layout
1985
1986 \begin_layout Standard
1987 \align center
1988 \begin_inset Tabular
1989 <lyxtabular version="3" rows="9" columns="3">
1990 <features>
1991 <column alignment="block" valignment="top" leftline="true" width="0in">
1992 <column alignment="block" valignment="top" leftline="true" width="0in">
1993 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1994 <row topline="true" bottomline="true">
1995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1996 \begin_inset Text
1997
1998 \begin_layout Standard
1999 Variable
2000 \end_layout
2001
2002 \end_inset
2003 </cell>
2004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2005 \begin_inset Text
2006
2007 \begin_layout Standard
2008 default
2009 \end_layout
2010
2011 \end_inset
2012 </cell>
2013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2014 \begin_inset Text
2015
2016 \begin_layout Standard
2017 Win32 builds
2018 \end_layout
2019
2020 \end_inset
2021 </cell>
2022 </row>
2023 <row topline="true">
2024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2025 \begin_inset Text
2026
2027 \begin_layout Standard
2028
2029 \emph on
2030 PREFIX
2031 \end_layout
2032
2033 \end_inset
2034 </cell>
2035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2036 \begin_inset Text
2037
2038 \begin_layout Standard
2039 /usr/local
2040 \end_layout
2041
2042 \end_inset
2043 </cell>
2044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2045 \begin_inset Text
2046
2047 \begin_layout Standard
2048
2049 \backslash
2050 sdcc
2051 \end_layout
2052
2053 \end_inset
2054 </cell>
2055 </row>
2056 <row topline="true">
2057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2058 \begin_inset Text
2059
2060 \begin_layout Standard
2061
2062 \emph on
2063 EXEC_PREFIX
2064 \end_layout
2065
2066 \end_inset
2067 </cell>
2068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2069 \begin_inset Text
2070
2071 \begin_layout Standard
2072
2073 \emph on
2074 $PREFIX
2075 \end_layout
2076
2077 \end_inset
2078 </cell>
2079 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2080 \begin_inset Text
2081
2082 \begin_layout Standard
2083
2084 \emph on
2085 $PREFIX
2086 \end_layout
2087
2088 \end_inset
2089 </cell>
2090 </row>
2091 <row topline="true">
2092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2093 \begin_inset Text
2094
2095 \begin_layout Standard
2096
2097 \emph on
2098 BINDIR
2099 \end_layout
2100
2101 \end_inset
2102 </cell>
2103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2104 \begin_inset Text
2105
2106 \begin_layout Standard
2107
2108 \emph on
2109 $EXEC_PREFIX
2110 \emph default
2111 /bin
2112 \end_layout
2113
2114 \end_inset
2115 </cell>
2116 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2117 \begin_inset Text
2118
2119 \begin_layout Standard
2120
2121 \emph on
2122 $EXEC_PREFIX
2123 \emph default
2124
2125 \backslash
2126 bin
2127 \end_layout
2128
2129 \end_inset
2130 </cell>
2131 </row>
2132 <row topline="true">
2133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2134 \begin_inset Text
2135
2136 \begin_layout Standard
2137
2138 \emph on
2139 DATADIR
2140 \end_layout
2141
2142 \end_inset
2143 </cell>
2144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2145 \begin_inset Text
2146
2147 \begin_layout Standard
2148
2149 \emph on
2150 $DATAROOTDIR
2151 \end_layout
2152
2153 \end_inset
2154 </cell>
2155 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2156 \begin_inset Text
2157
2158 \begin_layout Standard
2159
2160 \emph on
2161 $DATAROOTDIR
2162 \end_layout
2163
2164 \end_inset
2165 </cell>
2166 </row>
2167 <row topline="true">
2168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2169 \begin_inset Text
2170
2171 \begin_layout Standard
2172
2173 \emph on
2174 DATAROOTDIR
2175 \end_layout
2176
2177 \end_inset
2178 </cell>
2179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2180 \begin_inset Text
2181
2182 \begin_layout Standard
2183
2184 \emph on
2185 $PREFIX
2186 \emph default
2187 /share
2188 \end_layout
2189
2190 \end_inset
2191 </cell>
2192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2193 \begin_inset Text
2194
2195 \begin_layout Standard
2196
2197 \emph on
2198 $PREFIX
2199 \end_layout
2200
2201 \end_inset
2202 </cell>
2203 </row>
2204 <row topline="true">
2205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2206 \begin_inset Text
2207
2208 \begin_layout Standard
2209
2210 \emph on
2211 DOCDIR
2212 \end_layout
2213
2214 \end_inset
2215 </cell>
2216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2217 \begin_inset Text
2218
2219 \begin_layout Standard
2220
2221 \emph on
2222 $DATAROOTDIR
2223 \emph default
2224 /sdcc/doc
2225 \end_layout
2226
2227 \end_inset
2228 </cell>
2229 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2230 \begin_inset Text
2231
2232 \begin_layout Standard
2233
2234 \emph on
2235 $DATAROOTDIR
2236 \emph default
2237
2238 \backslash
2239 doc
2240 \end_layout
2241
2242 \end_inset
2243 </cell>
2244 </row>
2245 <row topline="true">
2246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2247 \begin_inset Text
2248
2249 \begin_layout Standard
2250
2251 \emph on
2252 INCLUDE_DIR_SUFFIX
2253 \end_layout
2254
2255 \end_inset
2256 </cell>
2257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2258 \begin_inset Text
2259
2260 \begin_layout Standard
2261 sdcc/include
2262 \end_layout
2263
2264 \end_inset
2265 </cell>
2266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2267 \begin_inset Text
2268
2269 \begin_layout Standard
2270 include
2271 \end_layout
2272
2273 \end_inset
2274 </cell>
2275 </row>
2276 <row topline="true" bottomline="true">
2277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2278 \begin_inset Text
2279
2280 \begin_layout Standard
2281
2282 \emph on
2283 LIB_DIR_SUFFIX
2284 \end_layout
2285
2286 \end_inset
2287 </cell>
2288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2289 \begin_inset Text
2290
2291 \begin_layout Standard
2292 sdcc/lib
2293 \end_layout
2294
2295 \end_inset
2296 </cell>
2297 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2298 \begin_inset Text
2299
2300 \begin_layout Standard
2301 lib
2302 \end_layout
2303
2304 \end_inset
2305 </cell>
2306 </row>
2307 </lyxtabular>
2308
2309 \end_inset
2310
2311
2312 \newline
2313
2314 \end_layout
2315
2316 \begin_layout Standard
2317 \noindent
2318 'configure' also computes relative paths.
2319  This is needed for full relocatability of a binary package and to complete
2320  search paths (see section search paths below):
2321 \newline
2322  
2323 \end_layout
2324
2325 \begin_layout Standard
2326 \align center
2327 \begin_inset Tabular
2328 <lyxtabular version="3" rows="4" columns="3">
2329 <features>
2330 <column alignment="block" valignment="top" leftline="true" width="0in">
2331 <column alignment="block" valignment="top" leftline="true" width="0in">
2332 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2333 <row topline="true" bottomline="true">
2334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2335 \begin_inset Text
2336
2337 \begin_layout Standard
2338 Variable (computed)
2339 \end_layout
2340
2341 \end_inset
2342 </cell>
2343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2344 \begin_inset Text
2345
2346 \begin_layout Standard
2347 default
2348 \end_layout
2349
2350 \end_inset
2351 </cell>
2352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2353 \begin_inset Text
2354
2355 \begin_layout Standard
2356 Win32 builds
2357 \end_layout
2358
2359 \end_inset
2360 </cell>
2361 </row>
2362 <row topline="true" bottomline="true">
2363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2364 \begin_inset Text
2365
2366 \begin_layout Standard
2367
2368 \emph on
2369 BIN2DATA_DIR
2370 \end_layout
2371
2372 \end_inset
2373 </cell>
2374 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2375 \begin_inset Text
2376
2377 \begin_layout Standard
2378 ../share
2379 \end_layout
2380
2381 \end_inset
2382 </cell>
2383 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2384 \begin_inset Text
2385
2386 \begin_layout Standard
2387 ..
2388 \end_layout
2389
2390 \end_inset
2391 </cell>
2392 </row>
2393 <row bottomline="true">
2394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2395 \begin_inset Text
2396
2397 \begin_layout Standard
2398
2399 \emph on
2400 PREFIX2BIN_DIR
2401 \end_layout
2402
2403 \end_inset
2404 </cell>
2405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2406 \begin_inset Text
2407
2408 \begin_layout Standard
2409 bin
2410 \end_layout
2411
2412 \end_inset
2413 </cell>
2414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2415 \begin_inset Text
2416
2417 \begin_layout Standard
2418 bin
2419 \end_layout
2420
2421 \end_inset
2422 </cell>
2423 </row>
2424 <row bottomline="true">
2425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2426 \begin_inset Text
2427
2428 \begin_layout Standard
2429
2430 \emph on
2431 PREFIX2DATA_DIR
2432 \end_layout
2433
2434 \end_inset
2435 </cell>
2436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2437 \begin_inset Text
2438
2439 \begin_layout Standard
2440 share/sdcc
2441 \end_layout
2442
2443 \end_inset
2444 </cell>
2445 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2446 \begin_inset Text
2447
2448 \begin_layout Standard
2449
2450 \end_layout
2451
2452 \end_inset
2453 </cell>
2454 </row>
2455 </lyxtabular>
2456
2457 \end_inset
2458
2459
2460 \newline
2461
2462 \end_layout
2463
2464 \begin_layout Standard
2465 \noindent
2466 Examples:
2467 \end_layout
2468
2469 \begin_layout LyX-Code
2470 ./configure
2471 \newline
2472 ./configure -
2473 \begin_inset ERT
2474 status collapsed
2475
2476 \begin_layout Standard
2477
2478
2479 \backslash
2480 /
2481 \end_layout
2482
2483 \end_inset
2484
2485 -prefix=
2486 \begin_inset Quotes srd
2487 \end_inset
2488
2489 /usr/bin
2490 \begin_inset Quotes srd
2491 \end_inset
2492
2493  -
2494 \begin_inset ERT
2495 status collapsed
2496
2497 \begin_layout Standard
2498
2499
2500 \backslash
2501 /
2502 \end_layout
2503
2504 \end_inset
2505
2506 -datarootdir=
2507 \begin_inset Quotes srd
2508 \end_inset
2509
2510 /usr/share
2511 \begin_inset Quotes srd
2512 \end_inset
2513
2514
2515 \newline
2516 ./configure -
2517 \begin_inset ERT
2518 status collapsed
2519
2520 \begin_layout Standard
2521
2522
2523 \backslash
2524 /
2525 \end_layout
2526
2527 \end_inset
2528
2529 -disable-avr-port -
2530 \begin_inset ERT
2531 status collapsed
2532
2533 \begin_layout Standard
2534
2535
2536 \backslash
2537 /
2538 \end_layout
2539
2540 \end_inset
2541
2542 -disable-xa51-port
2543 \end_layout
2544
2545 \begin_layout Standard
2546 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2547 32'):
2548 \end_layout
2549
2550 \begin_layout LyX-Code
2551 ./configure 
2552 \backslash
2553
2554 \newline
2555 CC=
2556 \begin_inset Quotes srd
2557 \end_inset
2558
2559 i586-mingw32msvc-gcc
2560 \begin_inset Quotes srd
2561 \end_inset
2562
2563  CXX=
2564 \begin_inset Quotes srd
2565 \end_inset
2566
2567 i586-mingw32msvc-g++
2568 \begin_inset Quotes srd
2569 \end_inset
2570
2571  
2572 \backslash
2573  
2574 \newline
2575 RANLIB=
2576 \begin_inset Quotes srd
2577 \end_inset
2578
2579 i586-mingw32msvc-ranlib
2580 \begin_inset Quotes srd
2581 \end_inset
2582
2583  
2584 \backslash
2585
2586 \newline
2587 STRIP=
2588 \begin_inset Quotes srd
2589 \end_inset
2590
2591 i586-mingw32msvc-strip
2592 \begin_inset Quotes srd
2593 \end_inset
2594
2595  
2596 \backslash
2597
2598 \newline
2599 -
2600 \begin_inset ERT
2601 status collapsed
2602
2603 \begin_layout Standard
2604
2605
2606 \backslash
2607 /
2608 \end_layout
2609
2610 \end_inset
2611
2612 -prefix=
2613 \begin_inset Quotes srd
2614 \end_inset
2615
2616 /sdcc
2617 \begin_inset Quotes srd
2618 \end_inset
2619
2620  
2621 \backslash
2622
2623 \newline
2624 -
2625 \begin_inset ERT
2626 status collapsed
2627
2628 \begin_layout Standard
2629
2630
2631 \backslash
2632 /
2633 \end_layout
2634
2635 \end_inset
2636
2637 -datarootdir=
2638 \begin_inset Quotes srd
2639 \end_inset
2640
2641 /sdcc
2642 \begin_inset Quotes srd
2643 \end_inset
2644
2645  
2646 \backslash
2647
2648 \newline
2649 docdir=
2650 \begin_inset Quotes srd
2651 \end_inset
2652
2653
2654 \backslash
2655 ${datarootdir}/doc
2656 \begin_inset Quotes srd
2657 \end_inset
2658
2659  
2660 \backslash
2661
2662 \newline
2663 include_dir_suffix=
2664 \begin_inset Quotes srd
2665 \end_inset
2666
2667 include
2668 \begin_inset Quotes srd
2669 \end_inset
2670
2671  
2672 \backslash
2673
2674 \newline
2675 lib_dir_suffix=
2676 \begin_inset Quotes srd
2677 \end_inset
2678
2679 lib
2680 \begin_inset Quotes srd
2681 \end_inset
2682
2683  
2684 \backslash
2685
2686 \newline
2687 sdccconf_h_dir_separator=
2688 \begin_inset Quotes srd
2689 \end_inset
2690
2691
2692 \backslash
2693
2694 \backslash
2695
2696 \backslash
2697
2698 \backslash
2699
2700 \begin_inset Quotes srd
2701 \end_inset
2702
2703  
2704 \backslash
2705
2706 \newline
2707 -
2708 \begin_inset ERT
2709 status collapsed
2710
2711 \begin_layout Standard
2712
2713
2714 \backslash
2715 /
2716 \end_layout
2717
2718 \end_inset
2719
2720 -disable-device-lib
2721 \backslash
2722
2723 \newline
2724 -
2725 \begin_inset ERT
2726 status collapsed
2727
2728 \begin_layout Standard
2729
2730
2731 \backslash
2732 /
2733 \end_layout
2734
2735 \end_inset
2736
2737 -host=i586-mingw32msvc
2738 \backslash
2739
2740 \newline
2741 -
2742 \begin_inset ERT
2743 status collapsed
2744
2745 \begin_layout Standard
2746
2747
2748 \backslash
2749 /
2750 \end_layout
2751
2752 \end_inset
2753
2754 -build=unknown-unknown-linux-gnu
2755 \end_layout
2756
2757 \begin_layout Standard
2758 To 
2759 \begin_inset Quotes sld
2760 \end_inset
2761
2762 cross
2763 \begin_inset Quotes srd
2764 \end_inset
2765
2766 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2767 ):
2768 \end_layout
2769
2770 \begin_layout LyX-Code
2771 ./configure -C 
2772 \backslash
2773
2774 \newline
2775 -
2776 \begin_inset ERT
2777 status collapsed
2778
2779 \begin_layout Standard
2780
2781
2782 \backslash
2783 /
2784 \end_layout
2785
2786 \end_inset
2787
2788 -prefix=
2789 \begin_inset Quotes srd
2790 \end_inset
2791
2792 /sdcc
2793 \begin_inset Quotes srd
2794 \end_inset
2795
2796  
2797 \backslash
2798
2799 \newline
2800 -
2801 \begin_inset ERT
2802 status collapsed
2803
2804 \begin_layout Standard
2805
2806
2807 \backslash
2808 /
2809 \end_layout
2810
2811 \end_inset
2812
2813 -datarootdir=
2814 \begin_inset Quotes srd
2815 \end_inset
2816
2817 /sdcc
2818 \begin_inset Quotes srd
2819 \end_inset
2820
2821  
2822 \backslash
2823
2824 \newline
2825 docdir=
2826 \begin_inset Quotes srd
2827 \end_inset
2828
2829
2830 \backslash
2831 ${datarootdir}/doc
2832 \begin_inset Quotes srd
2833 \end_inset
2834
2835  
2836 \backslash
2837  
2838 \newline
2839 include_dir_suffix=
2840 \begin_inset Quotes srd
2841 \end_inset
2842
2843 include
2844 \begin_inset Quotes srd
2845 \end_inset
2846
2847  
2848 \backslash
2849
2850 \newline
2851 lib_dir_suffix=
2852 \begin_inset Quotes srd
2853 \end_inset
2854
2855 lib
2856 \begin_inset Quotes srd
2857 \end_inset
2858
2859  
2860 \backslash
2861
2862 \newline
2863 sdccconf_h_dir_separator=
2864 \begin_inset Quotes srd
2865 \end_inset
2866
2867
2868 \backslash
2869
2870 \backslash
2871
2872 \backslash
2873
2874 \backslash
2875
2876 \begin_inset Quotes srd
2877 \end_inset
2878
2879  
2880 \backslash
2881
2882 \newline
2883 CC=
2884 \begin_inset Quotes srd
2885 \end_inset
2886
2887 gcc -mno-cygwin
2888 \begin_inset Quotes srd
2889 \end_inset
2890
2891  
2892 \backslash
2893
2894 \newline
2895 CXX=
2896 \begin_inset Quotes srd
2897 \end_inset
2898
2899 g++ -mno-cygwin
2900 \begin_inset Quotes srd
2901 \end_inset
2902
2903  
2904 \end_layout
2905
2906 \begin_layout Standard
2907 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2908  The option '-
2909 \begin_inset ERT
2910 status collapsed
2911
2912 \begin_layout Standard
2913
2914
2915 \backslash
2916 /
2917 \end_layout
2918
2919 \end_inset
2920
2921 -C' turns on caching, which gives a little bit extra speed.
2922  However if options are changed, it can be necessary to delete the config.cache
2923  file.
2924 \end_layout
2925
2926 \begin_layout Section
2927 Install paths
2928 \begin_inset LatexCommand label
2929 name "sub:Install-paths"
2930
2931 \end_inset
2932
2933
2934 \begin_inset LatexCommand index
2935 name "Install paths"
2936
2937 \end_inset
2938
2939
2940 \end_layout
2941
2942 \begin_layout Standard
2943 \begin_inset VSpace medskip
2944 \end_inset
2945
2946
2947 \end_layout
2948
2949 \begin_layout Standard
2950 \align center
2951 \begin_inset Tabular
2952 <lyxtabular version="3" rows="5" columns="4">
2953 <features>
2954 <column alignment="left" valignment="top" leftline="true" width="0">
2955 <column alignment="left" valignment="top" leftline="true" width="0">
2956 <column alignment="left" valignment="top" leftline="true" width="0">
2957 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2958 <row topline="true" bottomline="true">
2959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2960 \begin_inset Text
2961
2962 \begin_layout Standard
2963
2964 \series bold
2965 Description
2966 \end_layout
2967
2968 \end_inset
2969 </cell>
2970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2971 \begin_inset Text
2972
2973 \begin_layout Standard
2974
2975 \series bold
2976 Path
2977 \end_layout
2978
2979 \end_inset
2980 </cell>
2981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2982 \begin_inset Text
2983
2984 \begin_layout Standard
2985
2986 \series bold
2987 Default
2988 \end_layout
2989
2990 \end_inset
2991 </cell>
2992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2993 \begin_inset Text
2994
2995 \begin_layout Standard
2996
2997 \series bold
2998 Win32 builds
2999 \end_layout
3000
3001 \end_inset
3002 </cell>
3003 </row>
3004 <row topline="true">
3005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3006 \begin_inset Text
3007
3008 \begin_layout Standard
3009 Binary files*
3010 \end_layout
3011
3012 \end_inset
3013 </cell>
3014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3015 \begin_inset Text
3016
3017 \begin_layout Standard
3018
3019 \emph on
3020 $EXEC_PREFIX
3021 \end_layout
3022
3023 \end_inset
3024 </cell>
3025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3026 \begin_inset Text
3027
3028 \begin_layout Standard
3029 /usr/local/bin
3030 \end_layout
3031
3032 \end_inset
3033 </cell>
3034 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3035 \begin_inset Text
3036
3037 \begin_layout Standard
3038
3039 \backslash
3040 sdcc
3041 \backslash
3042 bin
3043 \end_layout
3044
3045 \end_inset
3046 </cell>
3047 </row>
3048 <row topline="true">
3049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3050 \begin_inset Text
3051
3052 \begin_layout Standard
3053 Include files
3054 \end_layout
3055
3056 \end_inset
3057 </cell>
3058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3059 \begin_inset Text
3060
3061 \begin_layout Standard
3062
3063 \emph on
3064 $DATADIR/ $INCLUDE_DIR_SUFFIX
3065 \end_layout
3066
3067 \end_inset
3068 </cell>
3069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3070 \begin_inset Text
3071
3072 \begin_layout Standard
3073 /usr/local/share/sdcc/include
3074 \end_layout
3075
3076 \end_inset
3077 </cell>
3078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3079 \begin_inset Text
3080
3081 \begin_layout Standard
3082
3083 \backslash
3084 sdcc
3085 \backslash
3086 include
3087 \end_layout
3088
3089 \end_inset
3090 </cell>
3091 </row>
3092 <row topline="true">
3093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3094 \begin_inset Text
3095
3096 \begin_layout Standard
3097 Library file**
3098 \end_layout
3099
3100 \end_inset
3101 </cell>
3102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3103 \begin_inset Text
3104
3105 \begin_layout Standard
3106
3107 \emph on
3108 $DATADIR/$LIB_DIR_SUFFIX
3109 \end_layout
3110
3111 \end_inset
3112 </cell>
3113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3114 \begin_inset Text
3115
3116 \begin_layout Standard
3117 /usr/local/share/sdcc/lib
3118 \end_layout
3119
3120 \end_inset
3121 </cell>
3122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3123 \begin_inset Text
3124
3125 \begin_layout Standard
3126
3127 \backslash
3128 sdcc
3129 \backslash
3130 lib
3131 \end_layout
3132
3133 \end_inset
3134 </cell>
3135 </row>
3136 <row topline="true" bottomline="true">
3137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3138 \begin_inset Text
3139
3140 \begin_layout Standard
3141 Documentation
3142 \end_layout
3143
3144 \end_inset
3145 </cell>
3146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3147 \begin_inset Text
3148
3149 \begin_layout Standard
3150
3151 \emph on
3152 $DOCDIR
3153 \end_layout
3154
3155 \end_inset
3156 </cell>
3157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3158 \begin_inset Text
3159
3160 \begin_layout Standard
3161 /usr/local/share/sdcc/doc
3162 \end_layout
3163
3164 \end_inset
3165 </cell>
3166 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3167 \begin_inset Text
3168
3169 \begin_layout Standard
3170
3171 \backslash
3172 sdcc
3173 \backslash
3174 doc
3175 \end_layout
3176
3177 \end_inset
3178 </cell>
3179 </row>
3180 </lyxtabular>
3181
3182 \end_inset
3183
3184
3185 \end_layout
3186
3187 \begin_layout Verse
3188
3189 \size footnotesize
3190 *compiler, preprocessor, assembler, and linker
3191 \newline
3192 **the 
3193 \shape italic
3194 model
3195 \shape default
3196  is auto-appended by the compiler, e.g.
3197  small, large, z80, ds390 etc
3198 \end_layout
3199
3200 \begin_layout Standard
3201 \noindent
3202 The install paths can still be changed during `make install' with e.g.:
3203 \end_layout
3204
3205 \begin_layout LyX-Code
3206 make install prefix=$(HOME)/local/sdcc
3207 \end_layout
3208
3209 \begin_layout Standard
3210 Of course this doesn't change the search paths compiled into the binaries.
3211 \newline
3212
3213 \newline
3214 Moreove
3215 r the install path can be changed by defining DESTDIR
3216 \begin_inset LatexCommand index
3217 name "DESTDIR"
3218
3219 \end_inset
3220
3221 :
3222 \end_layout
3223
3224 \begin_layout LyX-Code
3225 make install DESTDIR=$(HOME)/sdcc.rpm/
3226 \end_layout
3227
3228 \begin_layout Standard
3229 Please note that DESTDIR must have a trailing slash!
3230 \end_layout
3231
3232 \begin_layout Section
3233 Search Paths
3234 \begin_inset LatexCommand label
3235 name "sub:Search-Paths"
3236
3237 \end_inset
3238
3239
3240 \begin_inset LatexCommand index
3241 name "Search path"
3242
3243 \end_inset
3244
3245
3246 \end_layout
3247
3248 \begin_layout Standard
3249 Some search paths or parts of them are determined by configure variables
3250  (in 
3251 \emph on
3252 italics
3253 \emph default
3254 , see section above).
3255  Further search paths are determined by environment variables during runtime.
3256  
3257 \newline
3258 The paths searched when running the compiler are as follows (the first
3259  catch wins):
3260 \newline
3261
3262 \newline
3263 1.
3264  Binary files (preprocessor, assembler and linker)
3265 \newline
3266
3267 \end_layout
3268
3269 \begin_layout Standard
3270 \align center
3271 \begin_inset Tabular
3272 <lyxtabular version="3" rows="4" columns="3">
3273 <features>
3274 <column alignment="block" valignment="top" leftline="true" width="0in">
3275 <column alignment="block" valignment="top" leftline="true" width="0in">
3276 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3277 <row topline="true" bottomline="true">
3278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3279 \begin_inset Text
3280
3281 \begin_layout Standard
3282 Search path
3283 \end_layout
3284
3285 \end_inset
3286 </cell>
3287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3288 \begin_inset Text
3289
3290 \begin_layout Standard
3291 default
3292 \end_layout
3293
3294 \end_inset
3295 </cell>
3296 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3297 \begin_inset Text
3298
3299 \begin_layout Standard
3300 Win32 builds
3301 \end_layout
3302
3303 \end_inset
3304 </cell>
3305 </row>
3306 <row topline="true">
3307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3308 \begin_inset Text
3309
3310 \begin_layout Standard
3311 $SDCC_HOME/
3312 \emph on
3313 $PPREFIX2BIN_DIR
3314 \end_layout
3315
3316 \end_inset
3317 </cell>
3318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3319 \begin_inset Text
3320
3321 \begin_layout Standard
3322 $SDCC_HOME/bin
3323 \end_layout
3324
3325 \end_inset
3326 </cell>
3327 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3328 \begin_inset Text
3329
3330 \begin_layout Standard
3331 $SDCC_HOME
3332 \backslash
3333 bin
3334 \end_layout
3335
3336 \end_inset
3337 </cell>
3338 </row>
3339 <row topline="true">
3340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3341 \begin_inset Text
3342
3343 \begin_layout Standard
3344 Path of argv[0] (if available)
3345 \end_layout
3346
3347 \end_inset
3348 </cell>
3349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3350 \begin_inset Text
3351
3352 \begin_layout Standard
3353 Path of argv[0]
3354 \end_layout
3355
3356 \end_inset
3357 </cell>
3358 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3359 \begin_inset Text
3360
3361 \begin_layout Standard
3362 Path of argv[0]
3363 \end_layout
3364
3365 \end_inset
3366 </cell>
3367 </row>
3368 <row topline="true" bottomline="true">
3369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3370 \begin_inset Text
3371
3372 \begin_layout Standard
3373 $PATH
3374 \end_layout
3375
3376 \end_inset
3377 </cell>
3378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3379 \begin_inset Text
3380
3381 \begin_layout Standard
3382 $PATH
3383 \end_layout
3384
3385 \end_inset
3386 </cell>
3387 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3388 \begin_inset Text
3389
3390 \begin_layout Standard
3391 $PATH
3392 \end_layout
3393
3394 \end_inset
3395 </cell>
3396 </row>
3397 </lyxtabular>
3398
3399 \end_inset
3400
3401  
3402 \newline
3403
3404 \end_layout
3405
3406 \begin_layout Standard
3407 \noindent
3408 2.
3409  Include files
3410 \newline
3411
3412 \end_layout
3413
3414 \begin_layout Standard
3415 \align center
3416 \begin_inset Tabular
3417 <lyxtabular version="3" rows="6" columns="3">
3418 <features>
3419 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3420 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3421 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3422 <row topline="true" bottomline="true">
3423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3424 \begin_inset Text
3425
3426 \begin_layout Standard
3427 Search path
3428 \end_layout
3429
3430 \end_inset
3431 </cell>
3432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3433 \begin_inset Text
3434
3435 \begin_layout Standard
3436 default
3437 \end_layout
3438
3439 \end_inset
3440 </cell>
3441 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3442 \begin_inset Text
3443
3444 \begin_layout Standard
3445 Win32 builds
3446 \end_layout
3447
3448 \end_inset
3449 </cell>
3450 </row>
3451 <row topline="true">
3452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3453 \begin_inset Text
3454
3455 \begin_layout Standard
3456 -
3457 \begin_inset ERT
3458 status collapsed
3459
3460 \begin_layout Standard
3461
3462
3463 \backslash
3464 /
3465 \end_layout
3466
3467 \end_inset
3468
3469 -I dir
3470 \end_layout
3471
3472 \end_inset
3473 </cell>
3474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3475 \begin_inset Text
3476
3477 \begin_layout Standard
3478 -
3479 \begin_inset ERT
3480 status collapsed
3481
3482 \begin_layout Standard
3483
3484
3485 \backslash
3486 /
3487 \end_layout
3488
3489 \end_inset
3490
3491 -I dir
3492 \end_layout
3493
3494 \end_inset
3495 </cell>
3496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3497 \begin_inset Text
3498
3499 \begin_layout Standard
3500 -
3501 \begin_inset ERT
3502 status collapsed
3503
3504 \begin_layout Standard
3505
3506
3507 \backslash
3508 /
3509 \end_layout
3510
3511 \end_inset
3512
3513 -I dir
3514 \end_layout
3515
3516 \end_inset
3517 </cell>
3518 </row>
3519 <row topline="true">
3520 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3521 \begin_inset Text
3522
3523 \begin_layout Standard
3524 $SDCC_INCLUDE
3525 \end_layout
3526
3527 \end_inset
3528 </cell>
3529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3530 \begin_inset Text
3531
3532 \begin_layout Standard
3533 $SDCC_INCLUDE
3534 \end_layout
3535
3536 \end_inset
3537 </cell>
3538 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3539 \begin_inset Text
3540
3541 \begin_layout Standard
3542 $SDCC_INCLUDE
3543 \end_layout
3544
3545 \end_inset
3546 </cell>
3547 </row>
3548 <row topline="true">
3549 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3550 \begin_inset Text
3551
3552 \begin_layout Standard
3553 $SDCC_HOME/
3554 \newline
3555
3556 \emph on
3557 $PREFIX2DATA_DIR/
3558 \newline
3559 $INCLUDE_DIR_SUFFIX
3560 \end_layout
3561
3562 \end_inset
3563 </cell>
3564 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3565 \begin_inset Text
3566
3567 \begin_layout Standard
3568 $SDCC_ HOME/
3569 \newline
3570 share/sdcc/
3571 \newline
3572 include
3573 \end_layout
3574
3575 \end_inset
3576 </cell>
3577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3578 \begin_inset Text
3579
3580 \begin_layout Standard
3581 $SDCC_HOME
3582 \backslash
3583 include
3584 \end_layout
3585
3586 \end_inset
3587 </cell>
3588 </row>
3589 <row topline="true">
3590 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3591 \begin_inset Text
3592
3593 \begin_layout Standard
3594 path(argv[0])/
3595 \newline
3596
3597 \emph on
3598 $BIN2DATADIR/
3599 \emph default
3600
3601 \newline
3602
3603 \emph on
3604 $INCLUDE_DIR_SUFFIX
3605 \end_layout
3606
3607 \end_inset
3608 </cell>
3609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3610 \begin_inset Text
3611
3612 \begin_layout Standard
3613 path(argv[0])/
3614 \newline
3615 ../sdcc/include
3616 \newline
3617 \InsetSpace ~
3618 \InsetSpace ~
3619 \InsetSpace ~
3620 \InsetSpace ~
3621 \InsetSpace ~
3622 \InsetSpace ~
3623 \InsetSpace ~
3624 \InsetSpace ~
3625 \InsetSpace ~
3626 \InsetSpace ~
3627 \InsetSpace ~
3628 \InsetSpace ~
3629 \InsetSpace ~
3630 \InsetSpace ~
3631 \InsetSpace ~
3632 \InsetSpace ~
3633 \InsetSpace ~
3634 \InsetSpace ~
3635 \InsetSpace ~
3636 \InsetSpace ~
3637 \InsetSpace ~
3638 \InsetSpace ~
3639 \InsetSpace ~
3640 \InsetSpace ~
3641 \InsetSpace ~
3642 \InsetSpace ~
3643 \InsetSpace ~
3644 \InsetSpace ~
3645 \InsetSpace ~
3646 \InsetSpace ~
3647 \InsetSpace ~
3648 \InsetSpace ~
3649 \InsetSpace ~
3650 \InsetSpace ~
3651 \InsetSpace ~
3652 \InsetSpace ~
3653 \InsetSpace ~
3654 \InsetSpace ~
3655
3656 \end_layout
3657
3658 \end_inset
3659 </cell>
3660 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3661 \begin_inset Text
3662
3663 \begin_layout Standard
3664 path(argv[0])
3665 \backslash
3666 ..
3667 \backslash
3668 include
3669 \end_layout
3670
3671 \end_inset
3672 </cell>
3673 </row>
3674 <row topline="true" bottomline="true">
3675 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3676 \begin_inset Text
3677
3678 \begin_layout Standard
3679
3680 \emph on
3681 $DATADIR/
3682 \emph default
3683
3684 \newline
3685
3686 \emph on
3687 $INCLUDE_DIR_SUFFIX
3688 \end_layout
3689
3690 \end_inset
3691 </cell>
3692 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3693 \begin_inset Text
3694
3695 \begin_layout Standard
3696 /usr/local/share/sdcc/
3697 \newline
3698 include
3699 \end_layout
3700
3701 \end_inset
3702 </cell>
3703 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3704 \begin_inset Text
3705
3706 \begin_layout Standard
3707 (not on Win32)
3708 \end_layout
3709
3710 \end_inset
3711 </cell>
3712 </row>
3713 </lyxtabular>
3714
3715 \end_inset
3716
3717  
3718 \newline
3719
3720 \end_layout
3721
3722 \begin_layout Standard
3723 \noindent
3724 The option -
3725 \begin_inset ERT
3726 status collapsed
3727
3728 \begin_layout Standard
3729
3730
3731 \backslash
3732 /
3733 \end_layout
3734
3735 \end_inset
3736
3737 -nostdinc disables the last two search paths.
3738 \newline
3739
3740 \newline
3741 3.
3742  Library files 
3743 \newline
3744
3745 \end_layout
3746
3747 \begin_layout Standard
3748 With the exception of 
3749 \begin_inset Quotes sld
3750 \end_inset
3751
3752 -
3753 \begin_inset ERT
3754 status collapsed
3755
3756 \begin_layout Standard
3757
3758
3759 \backslash
3760 /
3761 \end_layout
3762
3763 \end_inset
3764
3765 -L dir
3766 \begin_inset Quotes srd
3767 \end_inset
3768
3769  the 
3770 \shape italic
3771 model
3772 \shape default
3773  is auto-appended by the compiler (e.g.
3774  small, large, z80, ds390 etc.).
3775  
3776 \newline
3777
3778 \end_layout
3779
3780 \begin_layout Standard
3781 \align center
3782 \begin_inset Tabular
3783 <lyxtabular version="3" rows="6" columns="3">
3784 <features>
3785 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3786 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3787 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3788 <row topline="true" bottomline="true">
3789 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3790 \begin_inset Text
3791
3792 \begin_layout Standard
3793 Search path
3794 \end_layout
3795
3796 \end_inset
3797 </cell>
3798 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3799 \begin_inset Text
3800
3801 \begin_layout Standard
3802 default
3803 \end_layout
3804
3805 \end_inset
3806 </cell>
3807 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3808 \begin_inset Text
3809
3810 \begin_layout Standard
3811 Win32 builds
3812 \end_layout
3813
3814 \end_inset
3815 </cell>
3816 </row>
3817 <row topline="true">
3818 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3819 \begin_inset Text
3820
3821 \begin_layout Standard
3822 -
3823 \begin_inset ERT
3824 status collapsed
3825
3826 \begin_layout Standard
3827
3828
3829 \backslash
3830 /
3831 \end_layout
3832
3833 \end_inset
3834
3835 -L dir
3836 \end_layout
3837
3838 \end_inset
3839 </cell>
3840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3841 \begin_inset Text
3842
3843 \begin_layout Standard
3844 -
3845 \begin_inset ERT
3846 status collapsed
3847
3848 \begin_layout Standard
3849
3850
3851 \backslash
3852 /
3853 \end_layout
3854
3855 \end_inset
3856
3857 -L dir
3858 \end_layout
3859
3860 \end_inset
3861 </cell>
3862 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3863 \begin_inset Text
3864
3865 \begin_layout Standard
3866 -
3867 \begin_inset ERT
3868 status collapsed
3869
3870 \begin_layout Standard
3871
3872
3873 \backslash
3874 /
3875 \end_layout
3876
3877 \end_inset
3878
3879 -L dir
3880 \end_layout
3881
3882 \end_inset
3883 </cell>
3884 </row>
3885 <row topline="true">
3886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3887 \begin_inset Text
3888
3889 \begin_layout Standard
3890 $SDCC_LIB/
3891 \newline
3892
3893 \emph on
3894 <model>
3895 \end_layout
3896
3897 \end_inset
3898 </cell>
3899 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3900 \begin_inset Text
3901
3902 \begin_layout Standard
3903 $SDCC_LIB/
3904 \newline
3905
3906 \emph on
3907 <model>
3908 \end_layout
3909
3910 \end_inset
3911 </cell>
3912 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3913 \begin_inset Text
3914
3915 \begin_layout Standard
3916 $SDCC_LIB
3917 \backslash
3918
3919 \newline
3920
3921 \emph on
3922 <model>
3923 \end_layout
3924
3925 \end_inset
3926 </cell>
3927 </row>
3928 <row topline="true">
3929 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3930 \begin_inset Text
3931
3932 \begin_layout Standard
3933 $SDCC_HOME/
3934 \newline
3935
3936 \emph on
3937 $PREFIX2DATA_DIR/
3938 \newline
3939 $LIB_DIR_SUFFIX/<model>
3940 \end_layout
3941
3942 \end_inset
3943 </cell>
3944 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3945 \begin_inset Text
3946
3947 \begin_layout Standard
3948 $SDCC_HOME/
3949 \newline
3950 share/sdcc/
3951 \newline
3952 lib/
3953 \emph on
3954 <model>
3955 \end_layout
3956
3957 \end_inset
3958 </cell>
3959 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3960 \begin_inset Text
3961
3962 \begin_layout Standard
3963 $SDCC_HOME
3964 \backslash
3965 lib
3966 \backslash
3967
3968 \emph on
3969
3970 \newline
3971 <model>
3972 \end_layout
3973
3974 \end_inset
3975 </cell>
3976 </row>
3977 <row topline="true">
3978 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3979 \begin_inset Text
3980
3981 \begin_layout Standard
3982 path(argv[0])/
3983 \newline
3984
3985 \emph on
3986 $BIN2DATADIR/
3987 \emph default
3988
3989 \newline
3990
3991 \emph on
3992 $LIB_DIR_SUFFIX/<model>
3993 \end_layout
3994
3995 \end_inset
3996 </cell>
3997 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3998 \begin_inset Text
3999
4000 \begin_layout Standard
4001 path(argv[0])/
4002 \newline
4003 ../sdcc/lib/
4004 \emph on
4005 <model>
4006 \newline
4007 \InsetSpace ~
4008 \InsetSpace ~
4009 \InsetSpace ~
4010 \InsetSpace ~
4011 \InsetSpace ~
4012 \InsetSpace ~
4013 \InsetSpace ~
4014 \InsetSpace ~
4015 \InsetSpace ~
4016 \InsetSpace ~
4017 \InsetSpace ~
4018 \InsetSpace ~
4019 \InsetSpace ~
4020 \InsetSpace ~
4021 \InsetSpace ~
4022 \InsetSpace ~
4023 \InsetSpace ~
4024 \InsetSpace ~
4025 \InsetSpace ~
4026 \InsetSpace ~
4027 \InsetSpace ~
4028 \InsetSpace ~
4029 \InsetSpace ~
4030 \InsetSpace ~
4031 \InsetSpace ~
4032 \InsetSpace ~
4033 \InsetSpace ~
4034 \InsetSpace ~
4035 \InsetSpace ~
4036 \InsetSpace ~
4037 \InsetSpace ~
4038 \InsetSpace ~
4039 \InsetSpace ~
4040 \InsetSpace ~
4041 \InsetSpace ~
4042 \InsetSpace ~
4043 \InsetSpace ~
4044 \InsetSpace ~
4045 \InsetSpace ~
4046
4047 \end_layout
4048
4049 \end_inset
4050 </cell>
4051 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4052 \begin_inset Text
4053
4054 \begin_layout Standard
4055 path(argv[0])
4056 \backslash
4057
4058 \newline
4059 ..
4060 \backslash
4061 lib
4062 \backslash
4063
4064 \emph on
4065 <model>
4066 \newline
4067 \InsetSpace ~
4068 \InsetSpace ~
4069 \InsetSpace ~
4070 \InsetSpace ~
4071 \InsetSpace ~
4072 \InsetSpace ~
4073 \InsetSpace ~
4074 \InsetSpace ~
4075 \InsetSpace ~
4076 \InsetSpace ~
4077 \InsetSpace ~
4078 \InsetSpace ~
4079 \InsetSpace ~
4080 \InsetSpace ~
4081 \InsetSpace ~
4082 \InsetSpace ~
4083 \InsetSpace ~
4084 \InsetSpace ~
4085 \InsetSpace ~
4086 \InsetSpace ~
4087 \InsetSpace ~
4088 \InsetSpace ~
4089 \InsetSpace ~
4090 \InsetSpace ~
4091 \InsetSpace ~
4092 \InsetSpace ~
4093 \InsetSpace ~
4094 \InsetSpace ~
4095 \InsetSpace ~
4096 \InsetSpace ~
4097 \InsetSpace ~
4098 \InsetSpace ~
4099 \InsetSpace ~
4100 \InsetSpace ~
4101 \InsetSpace ~
4102
4103 \end_layout
4104
4105 \end_inset
4106 </cell>
4107 </row>
4108 <row topline="true" bottomline="true">
4109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4110 \begin_inset Text
4111
4112 \begin_layout Standard
4113
4114 \emph on
4115 $DATADIR/
4116 \newline
4117 $LIB_DIR_SUFFIX/<model>
4118 \end_layout
4119
4120 \end_inset
4121 </cell>
4122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4123 \begin_inset Text
4124
4125 \begin_layout Standard
4126 /usr/local/share/sdcc/
4127 \newline
4128 lib/
4129 \emph on
4130 <model>
4131 \end_layout
4132
4133 \end_inset
4134 </cell>
4135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4136 \begin_inset Text
4137
4138 \begin_layout Standard
4139 (not on Win32)
4140 \end_layout
4141
4142 \end_inset
4143 </cell>
4144 </row>
4145 </lyxtabular>
4146
4147 \end_inset
4148
4149
4150 \newline
4151
4152 \end_layout
4153
4154 \begin_layout Standard
4155 \begin_inset Note Note
4156 status collapsed
4157
4158 \begin_layout Standard
4159 Don't delete any of the stray spaces in the table above without checking
4160  the HTML output (last line)!
4161 \end_layout
4162
4163 \end_inset
4164
4165
4166 \end_layout
4167
4168 \begin_layout Standard
4169 \InsetSpace ~
4170
4171 \newline
4172 The option -
4173 \begin_inset ERT
4174 status collapsed
4175
4176 \begin_layout Standard
4177
4178
4179 \backslash
4180 /
4181 \end_layout
4182
4183 \end_inset
4184
4185 -nostdlib disables the last two search paths.
4186 \end_layout
4187
4188 \begin_layout Section
4189 Building SDCC
4190 \begin_inset LatexCommand index
4191 name "Building SDCC"
4192
4193 \end_inset
4194
4195
4196 \end_layout
4197
4198 \begin_layout Subsection
4199 Building SDCC on Linux
4200 \begin_inset LatexCommand label
4201 name "sub:Building-SDCC-on-Linux"
4202
4203 \end_inset
4204
4205
4206 \end_layout
4207
4208 \begin_layout Enumerate
4209
4210 \series medium
4211 Download the source package
4212 \series default
4213  either from the SDCC Subversion repository or from snapshot builds
4214 \series medium
4215 , it will be named something like sdcc
4216 \series default
4217 -src
4218 \series medium
4219 -yyyymmdd-rrrr.t
4220 \series default
4221 ar.
4222 \series medium
4223 bz2
4224 \series default
4225  
4226 \begin_inset LatexCommand url
4227 target "http://sdcc.sourceforge.net/snap.php"
4228
4229 \end_inset
4230
4231 .
4232 \end_layout
4233
4234 \begin_layout Enumerate
4235
4236 \series medium
4237 Bring up a command line terminal, such as xterm.
4238 \end_layout
4239
4240 \begin_layout Enumerate
4241
4242 \series medium
4243 Unpack the file using a command like:
4244 \series default
4245  
4246 \family sans
4247 \series bold
4248 "tar -xvzf sdcc-src-yyyymmdd-rrrr.tar.bz2
4249 \begin_inset Quotes srd
4250 \end_inset
4251
4252
4253 \family default
4254 \series medium
4255 , this will create a sub-directory called sdcc with all of the sources.
4256 \end_layout
4257
4258 \begin_layout Enumerate
4259 Change directory into the main SDCC directory, for example type: 
4260 \family sans
4261 \series bold
4262 "cd sdcc
4263 \series default
4264 ".
4265 \end_layout
4266
4267 \begin_layout Enumerate
4268
4269 \series medium
4270 Type
4271 \series default
4272  
4273 \family sans
4274 \series bold
4275 "./configure
4276 \family default
4277 \series default
4278 ".
4279  This configures the package for compilation on your system.
4280 \end_layout
4281
4282 \begin_layout Enumerate
4283
4284 \series medium
4285 Type
4286 \series default
4287  
4288 \family sans
4289 \series bold
4290 "make
4291 \family default
4292 \series default
4293 "
4294 \series medium
4295 .
4296
4297 \series default
4298  All of the source packages will compile, this can take a while.
4299 \end_layout
4300
4301 \begin_layout Enumerate
4302
4303 \series medium
4304 Type
4305 \series default
4306  
4307 \family sans
4308 \series bold
4309 "make install"
4310 \family default
4311 \series default
4312  as root
4313 \series medium
4314 .
4315
4316 \series default
4317  This copies the binary executables, the include files, the libraries and
4318  the documentation to the install directories.
4319  Proceed with section 
4320 \begin_inset LatexCommand ref
4321 reference "sec:Testing-the-SDCC"
4322
4323 \end_inset
4324
4325 .
4326 \end_layout
4327
4328 \begin_layout Subsection
4329 Building SDCC on Mac OS X
4330 \end_layout
4331
4332 \begin_layout Standard
4333 Follow the instruction for Linux.
4334 \newline
4335
4336 \newline
4337 On Mac OS X 10.2.x it was reported, that the
4338  default gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
4339  Fortunately there's also gcc 2.9.x installed, which works fine.
4340  This compiler can be selected by running 'configure' with:
4341 \end_layout
4342
4343 \begin_layout LyX-Code
4344 ./configure CC=gcc2 CXX=g++2
4345 \end_layout
4346
4347 \begin_layout Standard
4348 Universal (ppc and i386) binaries can be produced on Mac OS X 10.4.x with
4349  Xcode.
4350  Run 'configure' with:
4351 \end_layout
4352
4353 \begin_layout LyX-Code
4354 ./configure 
4355 \backslash
4356
4357 \end_layout
4358
4359 \begin_layout LyX-Code
4360 LDFLAGS="-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4361  ppc" 
4362 \backslash
4363
4364 \end_layout
4365
4366 \begin_layout LyX-Code
4367 CXXFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4368  ppc" 
4369 \backslash
4370
4371 \end_layout
4372
4373 \begin_layout LyX-Code
4374 CFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc"
4375 \end_layout
4376
4377 \begin_layout Subsection
4378 Cross compiling SDCC on Linux for Windows
4379 \end_layout
4380
4381 \begin_layout Standard
4382 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
4383  See section 'Configure Options'.
4384 \end_layout
4385
4386 \begin_layout Subsection
4387 Building SDCC using Cygwin and Mingw32
4388 \end_layout
4389
4390 \begin_layout Standard
4391 For building and installing a Cygwin executable follow the instructions
4392  for Linux.
4393 \newline
4394
4395 \newline
4396 On Cygwin a 
4397 \begin_inset Quotes sld
4398 \end_inset
4399
4400 native
4401 \begin_inset Quotes srd
4402 \end_inset
4403
4404  Win32-binary can be built, which will not need the Cygwin-DLL.
4405  For the necessary 'configure' options see section 'configure options' or
4406  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
4407 \newline
4408
4409 \newline
4410 In order to install
4411  Cygwin on Windows download setup.exe from 
4412 \begin_inset LatexCommand url
4413 name "www.cygwin.com"
4414 target "http://www.cygwin.com/"
4415
4416 \end_inset
4417
4418 .
4419  Run it, set the 
4420 \begin_inset Quotes sld
4421 \end_inset
4422
4423 default text file type
4424 \begin_inset Quotes srd
4425 \end_inset
4426
4427  to 
4428 \begin_inset Quotes sld
4429 \end_inset
4430
4431 unix
4432 \begin_inset Quotes srd
4433 \end_inset
4434
4435  and download/install at least the following packages.
4436  Some packages are selected by default, others will be automatically selected
4437  because of dependencies with the manually selected packages.
4438  Never deselect these packages!
4439 \end_layout
4440
4441 \begin_layout Itemize
4442 flex
4443 \end_layout
4444
4445 \begin_layout Itemize
4446 bison
4447 \end_layout
4448
4449 \begin_layout Itemize
4450 gcc ; version 3.x is fine, no need to use the old 2.9x
4451 \end_layout
4452
4453 \begin_layout Itemize
4454 binutils ; selected with gcc
4455 \end_layout
4456
4457 \begin_layout Itemize
4458 make
4459 \end_layout
4460
4461 \begin_layout Itemize
4462 rxvt ; a nice console, which makes life much easier under windoze (see below)
4463 \end_layout
4464
4465 \begin_layout Itemize
4466 man ; not really needed for building SDCC, but you'll miss it sooner or
4467  later
4468 \end_layout
4469
4470 \begin_layout Itemize
4471 less ; not really needed for building SDCC, but you'll miss it sooner or
4472  later
4473 \end_layout
4474
4475 \begin_layout Itemize
4476 svn ; only if you use Subversion access
4477 \end_layout
4478
4479 \begin_layout Standard
4480 If you want to develop something you'll need:
4481 \end_layout
4482
4483 \begin_layout Itemize
4484 python ; for the regression tests
4485 \end_layout
4486
4487 \begin_layout Itemize
4488 gdb ; the gnu debugger, together with the nice GUI 
4489 \begin_inset Quotes sld
4490 \end_inset
4491
4492 insight
4493 \begin_inset Quotes srd
4494 \end_inset
4495
4496
4497 \end_layout
4498
4499 \begin_layout Itemize
4500 openssh ; to access the CF or commit changes
4501 \end_layout
4502
4503 \begin_layout Itemize
4504 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4505  use autoconf-stable!
4506 \end_layout
4507
4508 \begin_layout Standard
4509 rxvt is a nice console with history.
4510  Replace in your cygwin.bat the line
4511 \end_layout
4512
4513 \begin_layout LyX-Code
4514 bash -
4515 \begin_inset ERT
4516 status collapsed
4517
4518 \begin_layout Standard
4519
4520
4521 \backslash
4522 /
4523 \end_layout
4524
4525 \end_inset
4526
4527 -login -i 
4528 \end_layout
4529
4530 \begin_layout Standard
4531 with (one line):
4532 \end_layout
4533
4534 \begin_layout LyX-Code
4535 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4536 \end_layout
4537
4538 \begin_layout LyX-Code
4539      -bg black -fg white -geometry 100x65 -e bash -
4540 \begin_inset ERT
4541 status collapsed
4542
4543 \begin_layout Standard
4544
4545
4546 \backslash
4547 /
4548 \end_layout
4549
4550 \end_inset
4551
4552 -login
4553 \end_layout
4554
4555 \begin_layout Standard
4556 Text selected with the mouse is automatically copied to the clipboard, pasting
4557  works with shift-insert.
4558 \newline
4559
4560 \newline
4561 The other good tip is to make sure you have no //c/-styl
4562 e paths anywhere, use /cygdrive/c/ instead.
4563  Using // invokes a network lookup which is very slow.
4564  If you think 
4565 \begin_inset Quotes sld
4566 \end_inset
4567
4568 cygdrive
4569 \begin_inset Quotes srd
4570 \end_inset
4571
4572  is too long, you can change it with e.g.
4573 \end_layout
4574
4575 \begin_layout LyX-Code
4576 mount -s -u -c /mnt
4577 \end_layout
4578
4579 \begin_layout Standard
4580 SDCC sources use the unix line ending LF.
4581  Life is much easier, if you store the source tree on a drive which is mounted
4582  in binary mode.
4583  And use an editor which can handle LF-only line endings.
4584  Make sure not to commit files with windows line endings.
4585  The tabulator spacing
4586 \begin_inset LatexCommand index
4587 name "tabulator spacing (8 columns)"
4588
4589 \end_inset
4590
4591  used in the project is 8.
4592  Although a tabulator spacing of 8 is a sensible choice for programmers
4593  (it's a power of 2 and allows to display 8/16 bit signed variables without
4594  loosing columns) the plan is to move towards using only spaces in the source.
4595 \end_layout
4596
4597 \begin_layout Subsection
4598 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4599 \end_layout
4600
4601 \begin_layout Standard
4602
4603 \series medium
4604 Download the source package
4605 \series default
4606  either from the SDCC Subversion repository or from the 
4607 \begin_inset LatexCommand url
4608 name "snapshot builds"
4609 target "http://sdcc.sourceforge.net/snap.php"
4610
4611 \end_inset
4612
4613
4614 \series medium
4615 , it will be named something like sdcc
4616 \series default
4617 -src
4618 \series medium
4619 -yyyymmdd-rrrr.tar.bz2.
4620
4621 \series default
4622  SDCC is distributed with all the projects, workspaces, and files you need
4623  to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4624  The workspace name is 'sdcc.dsw'.
4625  Please note that as it is now, all the executables are created in a folder
4626  called sdcc
4627 \backslash
4628 bin_vc.
4629  Once built you need to copy the executables from sdcc
4630 \backslash
4631 bin_vc to sdcc
4632 \backslash
4633 bin before running SDCC.
4634  
4635 \newline
4636
4637 \newline
4638 WARNING: Visual studio is very picky with line terminations; it expects
4639  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4640  When using the Subversion repository it's easiest to configure the svn
4641  client to convert automatically for you.
4642  If however you are getting a message such as "This makefile was not generated
4643  by Developer Studio etc.
4644  etc.
4645 \begin_inset Quotes srd
4646 \end_inset
4647
4648  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4649  need to convert the Unix style line endings to DOS style line endings.
4650  To do so you can use the 
4651 \begin_inset Quotes sld
4652 \end_inset
4653
4654 unix2dos
4655 \begin_inset Quotes srd
4656 \end_inset
4657
4658  utility freely available on the internet.
4659  Doug Hawkins reported in the sdcc-user list that this works:
4660 \newline
4661
4662 \newline
4663 C:
4664 \backslash
4665 Programming
4666 \backslash
4667 SDCC> unix2dos sdcc.dsw
4668 \newline
4669 C:
4670 \backslash
4671 Programming
4672 \backslash
4673 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4674 \newline
4675
4676 \newline
4677 In order to build SDCC with MSVC
4678  you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4679  One good place to get them is 
4680 \begin_inset LatexCommand url
4681 name "here"
4682 target "http://unxutils.sourceforge.net"
4683
4684 \end_inset
4685
4686
4687 \newline
4688
4689 \newline
4690 Download the file UnxUtils
4691 \begin_inset LatexCommand index
4692 name "UnxUtils"
4693
4694 \end_inset
4695
4696 .zip.
4697  Now you have to install the utilities and setup MSVC so it can locate the
4698  required programs.
4699  Here there are two alternatives (choose one!):
4700 \end_layout
4701
4702 \begin_layout Enumerate
4703 The easy way:
4704 \newline
4705
4706 \newline
4707 a) Extract UnxUtils.zip to your C:
4708 \backslash
4709  hard disk PRESERVING the original paths, otherwise bison won't work.
4710  (If you are using WinZip make certain that 'Use folder names' is selected)
4711 \newline
4712
4713 \newline
4714 b)
4715  In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4716  'Show directories for:' select 'Executable files', and in the directories
4717  window add a new path: 'C:
4718 \backslash
4719 user
4720 \backslash
4721 local
4722 \backslash
4723 wbin', click ok.
4724 \newline
4725
4726 \newline
4727 (As a side effect, you get a bunch of Unix utilities that
4728  could be useful, such as diff and patch.)
4729 \end_layout
4730
4731 \begin_layout Enumerate
4732 A more compact way:
4733 \newline
4734
4735 \newline
4736 This one avoids extracting a bunch of files you may not
4737  use, but requires some extra work:
4738 \newline
4739
4740 \newline
4741 a) Create a directory were to put the
4742  tools needed, or use a directory already present.
4743  Say for example 'C:
4744 \backslash
4745 util'.
4746 \newline
4747
4748 \newline
4749 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4750  gawk.exe to such directory WITHOUT preserving the original paths.
4751  (If you are using WinZip make certain that 'Use folder names' is not selected)
4752 \newline
4753
4754 \newline
4755 c
4756 ) Rename bison.exe to '_bison.exe'.
4757 \newline
4758
4759 \newline
4760 d) Create a batch file 'bison.bat' in 'C:
4761 \backslash
4762 util
4763 \backslash
4764 ' and add these lines: 
4765 \newline
4766 \InsetSpace ~
4767 \InsetSpace ~
4768 set BISON_SIMPLE=C:
4769 \backslash
4770 util
4771 \backslash
4772 bison.simple 
4773 \newline
4774 \InsetSpace ~
4775 \InsetSpace ~
4776 set BISON_HAIRY=C:
4777 \backslash
4778 util
4779 \backslash
4780 bison.hairy
4781 \newline
4782 \InsetSpace ~
4783 \InsetSpace ~
4784 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4785 \newline
4786
4787 \newline
4788 Steps 'c' and 'd' are needed
4789  because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4790  reside in some weird Unix directory, '/usr/local/share/' I think.
4791  So it is necessary to tell bison where those files are located if they
4792  are not in such directory.
4793  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4794 \newline
4795
4796 \newline
4797 e
4798 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4799  in 'Show directories for:' select 'Executable files', and in the directories
4800  window add a new path: 'c:
4801 \backslash
4802 util', click ok.
4803  Note that you can use any other path instead of 'c:
4804 \backslash
4805 util', even the path where the Visual C++ tools are, probably: 'C:
4806 \backslash
4807 Program Files
4808 \backslash
4809 Microsoft Visual Studio
4810 \backslash
4811 Common
4812 \backslash
4813 Tools'.
4814  So you don't have to execute step 'e' :)
4815 \end_layout
4816
4817 \begin_layout Standard
4818 That is it.
4819  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4820  the executables from sdcc
4821 \backslash
4822 bin_vc to sdcc
4823 \backslash
4824 bin, and you can compile using SDCC.
4825 \end_layout
4826
4827 \begin_layout Subsection
4828 Building SDCC Using Borland
4829 \end_layout
4830
4831 \begin_layout Enumerate
4832 From the sdcc directory, run the command "make -f Makefile.bcc".
4833  This should regenerate all the .exe files in the bin directory except for
4834  SDCDB and ucSim.
4835 \end_layout
4836
4837 \begin_layout Enumerate
4838 If you modify any source files and need to rebuild, be aware that the dependenci
4839 es may not be correctly calculated.
4840  The safest option is to delete all .obj files and run the build again.
4841  From a Cygwin BASH prompt, this can easily be done with the command (be
4842  sure you are in the sdcc directory):
4843 \newline
4844
4845 \newline
4846
4847 \family sans
4848 \series bold
4849 find .
4850  
4851 \backslash
4852 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
4853 \backslash
4854 ) -print -exec rm {} 
4855 \backslash
4856 ;
4857 \family default
4858 \series default
4859
4860 \newline
4861
4862 \newline
4863 or on Windows NT/2000/XP from the command prompt with the command:
4864 \newline
4865
4866 \family sans
4867 \series bold
4868
4869 \newline
4870 del /s *.obj *.lib *.rul
4871 \family default
4872 \series default
4873  from the sdcc directory.
4874 \end_layout
4875
4876 \begin_layout Subsection
4877 Windows Install Using a ZIP Package
4878 \end_layout
4879
4880 \begin_layout Enumerate
4881 Download the binary zip package from 
4882 \begin_inset LatexCommand url
4883 target "http://sdcc.sf.net/snap.php"
4884
4885 \end_inset
4886
4887  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4888  This should unpack to a group of sub-directories.
4889  An example directory structure after unpacking the mingw32 package is:
4890  c:
4891 \backslash
4892 sdcc
4893 \backslash
4894 bin for the executables, c:
4895 \backslash
4896 sdcc
4897 \backslash
4898 include and c:
4899 \backslash
4900 sdcc
4901 \backslash
4902 lib for the include and libraries.
4903 \end_layout
4904
4905 \begin_layout Enumerate
4906 Adjust your environment variable PATH to include the location of the bin
4907  directory or start sdcc using the full path.
4908 \end_layout
4909
4910 \begin_layout Subsection
4911 Windows Install Using the Setup Program
4912 \begin_inset LatexCommand label
4913 name "sub:Windows-Install"
4914
4915 \end_inset
4916
4917
4918 \end_layout
4919
4920 \begin_layout Standard
4921 Download the setup program 
4922 \emph on
4923 sdcc-x.y.z-setup.exe
4924 \emph default
4925  for an official release from 
4926 \newline
4927
4928 \begin_inset LatexCommand url
4929 target "http://sf.net/project/showfiles.php?group_id=599"
4930
4931 \end_inset
4932
4933  or a setup program for one of the snapshots 
4934 \emph on
4935 sdcc-yyyymmdd-xxxx-setup.exe
4936 \emph default
4937  from 
4938 \begin_inset LatexCommand url
4939 target "http://sdcc.sf.net/snap.php"
4940
4941 \end_inset
4942
4943  and execute it.
4944  A windows typical installer will guide you through the installation process.
4945 \end_layout
4946
4947 \begin_layout Subsection
4948 VPATH
4949 \begin_inset LatexCommand index
4950 name "VPATH"
4951
4952 \end_inset
4953
4954  feature
4955 \end_layout
4956
4957 \begin_layout Standard
4958 SDCC supports the VPATH feature provided by configure and make.
4959  It allows to separate the source and build trees.
4960  Here's an example:
4961 \end_layout
4962
4963 \begin_layout Standard
4964
4965 \family typewriter
4966 cd ~\InsetSpace ~
4967 \InsetSpace ~
4968 \InsetSpace ~
4969 \InsetSpace ~
4970 \InsetSpace ~
4971 \InsetSpace ~
4972 \InsetSpace ~
4973 \InsetSpace ~
4974 \InsetSpace ~
4975 \InsetSpace ~
4976 \InsetSpace ~
4977 \InsetSpace ~
4978 \InsetSpace ~
4979 \InsetSpace ~
4980 \InsetSpace ~
4981 \InsetSpace ~
4982 \InsetSpace ~
4983 \InsetSpace ~
4984 \InsetSpace ~
4985 \InsetSpace ~
4986 \InsetSpace ~
4987 # cd $HOME
4988 \end_layout
4989
4990 \begin_layout Standard
4991
4992 \family typewriter
4993 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4994 # extract source to directory sdcc
4995 \end_layout
4996
4997 \begin_layout Standard
4998
4999 \family typewriter
5000 mkdir sdcc.build\InsetSpace ~
5001 \InsetSpace ~
5002 \InsetSpace ~
5003 \InsetSpace ~
5004 \InsetSpace ~
5005 \InsetSpace ~
5006 \InsetSpace ~
5007 \InsetSpace ~
5008 \InsetSpace ~
5009 # put output in sdcc.build
5010 \end_layout
5011
5012 \begin_layout Standard
5013
5014 \family typewriter
5015 cd sdcc.build
5016 \end_layout
5017
5018 \begin_layout Standard
5019
5020 \family typewriter
5021 ../sdcc/configure\InsetSpace ~
5022 \InsetSpace ~
5023 \InsetSpace ~
5024 \InsetSpace ~
5025 \InsetSpace ~
5026 \InsetSpace ~
5027 \InsetSpace ~
5028 \InsetSpace ~
5029 # configure is doing all the magic!
5030 \end_layout
5031
5032 \begin_layout Standard
5033
5034 \family typewriter
5035 make
5036 \end_layout
5037
5038 \begin_layout Standard
5039 \noindent
5040 That's it! 
5041 \series bold
5042 configure
5043 \series default
5044  will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
5045  It automagically computes the variables srcdir, top_srcdir and top_buildir
5046  for each directory.
5047  After running 
5048 \series bold
5049 make
5050 \series default
5051  the generated files will be in ~/sdcc.build, while the source files stay
5052  in ~/sdcc.
5053 \newline
5054 This is not only usefull for building different binaries, e.g.
5055  when cross compiling.
5056  It also gives you a much better overview in the source tree when all the
5057  generated files are not scattered between the source files.
5058  And the best thing is: if you want to change a file you can leave the original
5059  file untouched in the source directory.
5060  Simply copy it to the build directory, edit it, enter `make clean', `rm
5061  Makefile.dep' and `make'.
5062  
5063 \series bold
5064 make
5065 \series default
5066  will do the rest for you!
5067 \end_layout
5068
5069 \begin_layout Section
5070 Building the Documentation
5071 \end_layout
5072
5073 \begin_layout Standard
5074 Add -
5075 \begin_inset ERT
5076 status collapsed
5077
5078 \begin_layout Standard
5079
5080
5081 \backslash
5082 /
5083 \end_layout
5084
5085 \end_inset
5086
5087 -enable-doc to the configure arguments to build the documentation together
5088  with all the other stuff.
5089  You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
5090  dvips and makeindex) to get the job done.
5091  Another possibility is to change to the doc directory and to type 
5092 \family sans
5093 \series bold
5094
5095 \begin_inset Quotes srd
5096 \end_inset
5097
5098 make
5099 \begin_inset Quotes srd
5100 \end_inset
5101
5102
5103 \family default
5104 \series default
5105  there.
5106  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
5107 x).
5108  Using LyX 
5109 \begin_inset LatexCommand url
5110 target "http://www.lyx.org"
5111
5112 \end_inset
5113
5114  as editor is straightforward.
5115  Prebuilt documentation in html and pdf format is available from 
5116 \begin_inset LatexCommand url
5117 target "http://sdcc.sf.net/snap.php"
5118
5119 \end_inset
5120
5121 .
5122 \end_layout
5123
5124 \begin_layout Section
5125 Reading the Documentation
5126 \begin_inset LatexCommand index
5127 name "Documentation"
5128
5129 \end_inset
5130
5131
5132 \end_layout
5133
5134 \begin_layout Standard
5135 Currently reading the document in pdf format is recommended, as for unknown
5136  reason the hyperlinks are working there whereas in the html version they
5137  are not
5138 \begin_inset Foot
5139 status open
5140
5141 \begin_layout Standard
5142 If you should know why please drop us a note
5143 \end_layout
5144
5145 \end_inset
5146
5147 .
5148  
5149 \newline
5150 You'll find the pdf version
5151 \begin_inset LatexCommand index
5152 name "PDF version of this document"
5153
5154 \end_inset
5155
5156  at 
5157 \begin_inset LatexCommand url
5158 target "http://sdcc.sf.net/doc/sdccman.pdf"
5159
5160 \end_inset
5161
5162 .
5163  
5164 \newline
5165 A html version
5166 \begin_inset LatexCommand index
5167 name "HTML version of this document"
5168
5169 \end_inset
5170
5171  should be online at 
5172 \begin_inset LatexCommand url
5173 target "http://sdcc.sf.net/doc/sdccman.html/index.html"
5174
5175 \end_inset
5176
5177 .
5178 \newline
5179 This documentation is in some aspects different from a commercial documentation:
5180  
5181 \end_layout
5182
5183 \begin_layout Itemize
5184 It tries to document SDCC for several processor architectures in one document
5185  (commercially these probably would be separate documents/products).
5186  This document
5187 \begin_inset LatexCommand index
5188 name "Status of documentation"
5189
5190 \end_inset
5191
5192  currently matches SDCC for mcs51 and DS390 best and does give too few informati
5193 on about f.e.
5194  Z80, PIC14, PIC16 and HC08.
5195 \end_layout
5196
5197 \begin_layout Itemize
5198 There are many references pointing away from this documentation.
5199  Don't let this distract you.
5200  If there f.e.
5201  was a reference like 
5202 \begin_inset LatexCommand url
5203 target "http://www.opencores.org"
5204
5205 \end_inset
5206
5207  together with a statement 
5208 \begin_inset Quotes sld
5209 \end_inset
5210
5211 some processors which are targetted by SDCC can be implemented in a 
5212 \emph on
5213 f
5214 \emph default
5215 ield 
5216 \emph on
5217 p
5218 \emph default
5219 rogrammable 
5220 \emph on
5221 g
5222 \emph default
5223 ate 
5224 \emph on
5225 a
5226 \emph default
5227 rray
5228 \begin_inset LatexCommand index
5229 name "FPGA (field programmable gate array)"
5230
5231 \end_inset
5232
5233
5234 \begin_inset Quotes srd
5235 \end_inset
5236
5237  or 
5238 \begin_inset LatexCommand url
5239 target "http://sf.net/projects/fpgac"
5240
5241 \end_inset
5242
5243
5244 \begin_inset LatexCommand index
5245 name "FpgaC ((subset of) C to FPGA compiler)"
5246
5247 \end_inset
5248
5249  
5250 \begin_inset Quotes sld
5251 \end_inset
5252
5253 have you ever heard of an open source compiler that compiles a subset of
5254  C for an FPGA?
5255 \begin_inset Quotes srd
5256 \end_inset
5257
5258  we expect you to have a quick look there and come back.
5259  If you read this you are on the right track.
5260 \end_layout
5261
5262 \begin_layout Itemize
5263 Some sections attribute more space to problems, restrictions and warnings
5264  than to the solution.
5265 \end_layout
5266
5267 \begin_layout Itemize
5268 The installation section and the section about the debugger is intimidating.
5269 \end_layout
5270
5271 \begin_layout Itemize
5272 There are still lots of typos and there are more different writing styles
5273  than pictures.
5274 \end_layout
5275
5276 \begin_layout Section
5277 Testing the SDCC Compiler
5278 \begin_inset LatexCommand label
5279 name "sec:Testing-the-SDCC"
5280
5281 \end_inset
5282
5283
5284 \end_layout
5285
5286 \begin_layout Standard
5287 The first thing you should do after installing your SDCC compiler is to
5288  see if it runs.
5289  Type 
5290 \family sans
5291 \series bold
5292 "sdcc -
5293 \begin_inset ERT
5294 status collapsed
5295
5296 \begin_layout Standard
5297
5298
5299 \backslash
5300 /
5301 \end_layout
5302
5303 \end_inset
5304
5305 -version"
5306 \begin_inset LatexCommand index
5307 name "version"
5308
5309 \end_inset
5310
5311
5312 \family default
5313 \series default
5314  at the prompt, and the program should run and output its version like:
5315  
5316 \newline
5317
5318 \family typewriter
5319 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
5320  (UNIX)
5321 \end_layout
5322
5323 \begin_layout Standard
5324 If it doesn't run, or gives a message about not finding sdcc program, then
5325  you need to check over your installation.
5326  Make sure that the sdcc bin directory is in your executable search path
5327  defined by the PATH environment setting (
5328 \series medium
5329 see
5330 \series default
5331  section 
5332 \begin_inset LatexCommand ref
5333 reference "sub:Install-Trouble-shooting"
5334
5335 \end_inset
5336
5337 \InsetSpace ~
5338
5339 \series medium
5340 Install trouble-shooting for suggestions
5341 \series default
5342 ).
5343  Make sure that the sdcc program is in the bin folder, if not perhaps something
5344  did not install correctly.
5345 \newline
5346
5347 \newline
5348
5349 \series medium
5350 SDCC
5351 \series default
5352  is commonly installed as described in section 
5353 \begin_inset Quotes sld
5354 \end_inset
5355
5356 Install and search paths
5357 \begin_inset Quotes srd
5358 \end_inset
5359
5360 .
5361 \newline
5362
5363 \newline
5364
5365 \series medium
5366 Make sure the compiler works on a very simple example.
5367  Type in the following test.c program using your favorite
5368 \series default
5369  ASCII 
5370 \series medium
5371 editor:
5372 \end_layout
5373
5374 \begin_layout Verse
5375
5376 \family typewriter
5377 char test;
5378 \newline
5379
5380 \newline
5381 void main(void) {
5382 \newline
5383 \InsetSpace ~
5384 \InsetSpace ~
5385 \InsetSpace ~
5386 \InsetSpace ~
5387 test=0;
5388 \newline
5389 }
5390 \end_layout
5391
5392 \begin_layout Standard
5393
5394 \series medium
5395 Compile this using the following command:
5396 \series default
5397  
5398 \family sans
5399 \series bold
5400 "sdcc -c test.c".
5401
5402 \family default
5403 \series default
5404  
5405 \series medium
5406 If all goes well, the compiler will generate a test.asm and test.rel file.
5407  Congratulations, you've just compiled your first program with SDCC.
5408  We used the -c option to tell SDCC not to link the generated code, just
5409  to keep things simple for this step.
5410 \series default
5411
5412 \newline
5413
5414 \newline
5415
5416 \series medium
5417 The next step is to try it with the linker.
5418  Type in
5419 \series default
5420  
5421 \family sans
5422 \series bold
5423 "sdcc test.c
5424 \family default
5425 \series default
5426 "
5427 \series medium
5428 .
5429  If all goes well the compiler will link with the libraries and produce
5430  a test.ihx output file.
5431  If this step fails
5432 \series default
5433  
5434 \series medium
5435 (no test.ihx, and the linker generates warnings), then the problem is most
5436  likely that
5437 \series default
5438  SDCC 
5439 \series medium
5440 cannot find the
5441 \series default
5442  /
5443 \series medium
5444 usr/local/share/sdcc/lib directory
5445 \series default
5446  
5447 \series medium
5448 (see
5449 \series default
5450  section 
5451 \begin_inset LatexCommand ref
5452 reference "sub:Install-Trouble-shooting"
5453
5454 \end_inset
5455
5456 \InsetSpace ~
5457
5458 \series medium
5459 Install trouble-shooting for suggestions).
5460 \series default
5461
5462 \newline
5463
5464 \newline
5465
5466 \series medium
5467 The final test is to ensure
5468 \series default
5469  SDCC 
5470 \series medium
5471 can use the
5472 \series default
5473  standard 
5474 \series medium
5475 header files and libraries.
5476  Edit test.c and change it to the following:
5477 \end_layout
5478
5479 \begin_layout Verse
5480
5481 \family typewriter
5482 #include <string.h>
5483 \newline
5484
5485 \newline
5486 char str1[10];
5487 \newline
5488
5489 \newline
5490 void main(void) {
5491 \newline
5492 \InsetSpace ~
5493 \InsetSpace ~
5494 strcpy(str1, "testing");
5495 \newline
5496 }
5497 \end_layout
5498
5499 \begin_layout Standard
5500
5501 \series medium
5502 Compile this by typing
5503 \series default
5504  
5505 \family sans
5506 \series bold
5507 "sdcc test.c"
5508 \family default
5509 \series medium
5510 .
5511  This should generate a test.ihx output file, and it should give no warnings
5512  such as not finding the string.h file.
5513  If it cannot find the string.h file, then the problem is that
5514 \series default
5515  SDCC 
5516 \series medium
5517 cannot find the /usr/local/share/sdcc/include directory
5518 \series default
5519  
5520 \series medium
5521 (see the
5522 \series default
5523  section 
5524 \begin_inset LatexCommand ref
5525 reference "sub:Install-Trouble-shooting"
5526
5527 \end_inset
5528
5529 \InsetSpace ~
5530
5531 \series medium
5532 Install trouble-shooting section for suggestions).
5533
5534 \series default
5535  Use option 
5536 \series bold
5537 -
5538 \begin_inset ERT
5539 status collapsed
5540
5541 \begin_layout Standard
5542
5543
5544 \backslash
5545 /
5546 \end_layout
5547
5548 \end_inset
5549
5550 -print-search-dirs
5551 \series default
5552
5553 \begin_inset LatexCommand index
5554 name "-\\/-print-search-dirs"
5555
5556 \end_inset
5557
5558  to find exactly where SDCC is looking for the include and lib files.
5559 \end_layout
5560
5561 \begin_layout Section
5562 Install Trouble-shooting
5563 \begin_inset LatexCommand label
5564 name "sub:Install-Trouble-shooting"
5565
5566 \end_inset
5567
5568
5569 \begin_inset LatexCommand index
5570 name "Install trouble-shooting"
5571
5572 \end_inset
5573
5574
5575 \end_layout
5576
5577 \begin_layout Subsection
5578 If SDCC does not build correctly
5579 \end_layout
5580
5581 \begin_layout Standard
5582 A thing to try is starting from scratch by unpacking the .tgz source package
5583  again in an empty directory.
5584  Configure it like:
5585 \newline
5586
5587 \newline
5588
5589 \family sans
5590 \series bold
5591 ./configure 2>&1 | tee configure.log
5592 \family default
5593 \series default
5594
5595 \newline
5596
5597 \newline
5598 and build it like:
5599 \newline
5600
5601 \newline
5602
5603 \family sans
5604 \series bold
5605 make 2>&1 | tee make.log
5606 \family default
5607 \series default
5608
5609 \newline
5610
5611 \newline
5612 If anything goes wrong, you can review the log files to locate the problem.
5613  Or a relevant part of this can be attached to an email that could be helpful
5614  when requesting help from the mailing list.
5615 \end_layout
5616
5617 \begin_layout Subsection
5618 What the 
5619 \begin_inset Quotes sld
5620 \end_inset
5621
5622 ./configure
5623 \begin_inset Quotes srd
5624 \end_inset
5625
5626  does
5627 \end_layout
5628
5629 \begin_layout Standard
5630 The 
5631 \begin_inset Quotes sld
5632 \end_inset
5633
5634 ./configure
5635 \begin_inset Quotes srd
5636 \end_inset
5637
5638  command is a script that analyzes your system and performs some configuration
5639  to ensure the source package compiles on your system.
5640  It will take a few minutes to run, and will compile a few tests to determine
5641  what compiler features are installed.
5642 \end_layout
5643
5644 \begin_layout Subsection
5645 What the 
5646 \begin_inset Quotes sld
5647 \end_inset
5648
5649 make
5650 \begin_inset Quotes srd
5651 \end_inset
5652
5653  does
5654 \end_layout
5655
5656 \begin_layout Standard
5657 This runs the GNU make tool, which automatically compiles all the source
5658  packages into the final installed binary executables.
5659 \end_layout
5660
5661 \begin_layout Subsection
5662 What the 
5663 \begin_inset Quotes sld
5664 \end_inset
5665
5666 make install
5667 \begin_inset Quotes erd
5668 \end_inset
5669
5670  command does.
5671 \end_layout
5672
5673 \begin_layout Standard
5674 This will install the compiler, other executables libraries and include
5675  files into the appropriate directories.
5676  See sections 
5677 \begin_inset LatexCommand ref
5678 reference "sub:Install-paths"
5679
5680 \end_inset
5681
5682 ,\InsetSpace ~
5683
5684 \begin_inset LatexCommand ref
5685 reference "sub:Search-Paths"
5686
5687 \end_inset
5688
5689 \InsetSpace ~
5690 about install and search paths.
5691 \newline
5692 On most systems you will need super-user privilege
5693 s to do this.
5694 \end_layout
5695
5696 \begin_layout Section
5697 Components of SDCC
5698 \end_layout
5699
5700 \begin_layout Standard
5701 SDCC is not just a compiler, but a collection of tools by various developers.
5702  These include linkers, assemblers, simulators and other components.
5703  Here is a summary of some of the components.
5704  Note that the included simulator and assembler have separate documentation
5705  which you can find in the source package in their respective directories.
5706  As SDCC grows to include support for other processors, other packages from
5707  various developers are included and may have their own sets of documentation.
5708 \newline
5709
5710 \newline
5711 You
5712  might want to look at the files which are installed in <installdir>.
5713  At the time of this writing, we find the following programs for gcc-builds:
5714 \newline
5715
5716  
5717 \newline
5718 In <installdir>/bin:
5719 \end_layout
5720
5721 \begin_layout Itemize
5722 sdcc - The compiler.
5723 \end_layout
5724
5725 \begin_layout Itemize
5726 sdcpp - The C preprocessor.
5727 \end_layout
5728
5729 \begin_layout Itemize
5730 asx8051 - The assembler for 8051 type processors.
5731 \end_layout
5732
5733 \begin_layout Itemize
5734 as-z80
5735 \series bold
5736 ,
5737 \series default
5738  as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5739 \end_layout
5740
5741 \begin_layout Itemize
5742 aslink -The linker for 8051 type processors.
5743 \end_layout
5744
5745 \begin_layout Itemize
5746 link-z80
5747 \series bold
5748 ,
5749 \series default
5750  link-gbz80 - The Z80 and GameBoy Z80 linkers.
5751 \end_layout
5752
5753 \begin_layout Itemize
5754 s51 - The ucSim 8051 simulator.
5755 \end_layout
5756
5757 \begin_layout Itemize
5758 sdcdb - The source debugger.
5759 \end_layout
5760
5761 \begin_layout Itemize
5762 packihx - A tool to pack (compress) Intel hex files.
5763 \end_layout
5764
5765 \begin_layout Standard
5766 In <installdir>/share/sdcc/include
5767 \end_layout
5768
5769 \begin_layout Itemize
5770 the include files
5771 \end_layout
5772
5773 \begin_layout Standard
5774 In <installdir>/share/sdcc/lib
5775 \end_layout
5776
5777 \begin_layout Itemize
5778 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5779  relocatables.
5780 \end_layout
5781
5782 \begin_layout Standard
5783 In <installdir>/share/sdcc/doc
5784 \end_layout
5785
5786 \begin_layout Itemize
5787 the documentation
5788 \end_layout
5789
5790 \begin_layout Standard
5791 As development for other processors proceeds, this list will expand to include
5792  executables to support processors like AVR, PIC, etc.
5793 \end_layout
5794
5795 \begin_layout Subsection
5796 sdcc - The Compiler
5797 \end_layout
5798
5799 \begin_layout Standard
5800 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5801  the assembler and linkage editor.
5802 \end_layout
5803
5804 \begin_layout Subsection
5805 sdcpp - The C-Preprocessor
5806 \end_layout
5807
5808 \begin_layout Standard
5809 The preprocessor
5810 \begin_inset LatexCommand index
5811 name "sdcpp (preprocessor)"
5812
5813 \end_inset
5814
5815  is a modified version of the GNU cpp
5816 \begin_inset LatexCommand index
5817 name "cpp|see{sdcpp}"
5818
5819 \end_inset
5820
5821  preprocessor 
5822 \begin_inset LatexCommand url
5823 target "http://gcc.gnu.org/"
5824
5825 \end_inset
5826
5827 .
5828  The C preprocessor is used to pull in #include sources, process #ifdef
5829  statements, #defines and so on.
5830 \end_layout
5831
5832 \begin_layout Subsection
5833 as
5834 \emph on
5835 xxxx
5836 \emph default
5837 , aslink, link-
5838 \emph on
5839 xxx
5840 \emph default
5841  - The Assemblers and Linkage Editors
5842 \end_layout
5843
5844 \begin_layout Standard
5845 This is retargettable assembler & linkage editor, it was developed by Alan
5846  Baldwin.
5847  John Hartman created the version for 8051, and I (Sandeep) have made some
5848  enhancements and bug fixes for it to work properly with SDCC.
5849 \end_layout
5850
5851 \begin_layout Subsection
5852 s51 - The Simulator
5853 \end_layout
5854
5855 \begin_layout Standard
5856 S51
5857 \begin_inset LatexCommand index
5858 name "s51"
5859
5860 \end_inset
5861
5862  is a free open source simulator developed by Daniel Drotos.
5863  The simulator is built as part of the build process.
5864  For more information visit Daniel's web site at: 
5865 \begin_inset LatexCommand url
5866 target "http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51"
5867
5868 \end_inset
5869
5870 .
5871  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5872  XA51 family.
5873 \end_layout
5874
5875 \begin_layout Subsection
5876 sdcdb - Source Level Debugger
5877 \end_layout
5878
5879 \begin_layout Standard
5880 SDCDB
5881 \begin_inset LatexCommand index
5882 name "SDCDB (debugger)"
5883
5884 \end_inset
5885
5886  is the companion source level debugger.
5887  More about SDCDB in section 
5888 \begin_inset LatexCommand ref
5889 reference "cha:Debugging-with-SDCDB"
5890
5891 \end_inset
5892
5893 .
5894  The current version of the debugger uses Daniel's Simulator S51
5895 \begin_inset LatexCommand index
5896 name "s51"
5897
5898 \end_inset
5899
5900 , but can be easily changed to use other simulators.
5901 \end_layout
5902
5903 \begin_layout Chapter
5904 Using SDCC
5905 \end_layout
5906
5907 \begin_layout Section
5908 Compiling
5909 \end_layout
5910
5911 \begin_layout Subsection
5912 Single Source File Projects
5913 \end_layout
5914
5915 \begin_layout Standard
5916 For single source file 8051 projects the process is very simple.
5917  Compile your programs with the following command 
5918 \family sans
5919 \series bold
5920 "sdcc sourcefile.c".
5921
5922 \family default
5923 \series default
5924  This will compile, assemble and link your source file.
5925  Output files are as follows:
5926 \end_layout
5927
5928 \begin_layout Itemize
5929 sourcefile.asm
5930 \begin_inset LatexCommand index
5931 name "<file>.asm"
5932
5933 \end_inset
5934
5935  - Assembler source
5936 \begin_inset LatexCommand index
5937 name "Assembler source"
5938
5939 \end_inset
5940
5941  file created by the compiler
5942 \end_layout
5943
5944 \begin_layout Itemize
5945 sourcefile.lst
5946 \begin_inset LatexCommand index
5947 name "<file>.lst"
5948
5949 \end_inset
5950
5951  - Assembler listing
5952 \begin_inset LatexCommand index
5953 name "Assembler listing"
5954
5955 \end_inset
5956
5957  file created by the Assembler
5958 \end_layout
5959
5960 \begin_layout Itemize
5961 sourcefile.rst
5962 \begin_inset LatexCommand index
5963 name "<file>.rst"
5964
5965 \end_inset
5966
5967  - Assembler listing
5968 \begin_inset LatexCommand index
5969 name "Assembler listing"
5970
5971 \end_inset
5972
5973  file updated with linkedit information, created by linkage editor
5974 \end_layout
5975
5976 \begin_layout Itemize
5977 sourcefile.sym
5978 \begin_inset LatexCommand index
5979 name "<file>.sym"
5980
5981 \end_inset
5982
5983  - symbol listing
5984 \begin_inset LatexCommand index
5985 name "Symbol listing"
5986
5987 \end_inset
5988
5989  for the sourcefile, created by the assembler
5990 \end_layout
5991
5992 \begin_layout Itemize
5993 sourcefile.rel
5994 \begin_inset LatexCommand index
5995 name "<file>.rel"
5996
5997 \end_inset
5998
5999  or sourcefile.o
6000 \begin_inset LatexCommand index
6001 name "<file>.o"
6002
6003 \end_inset
6004
6005  - Object file
6006 \begin_inset LatexCommand index
6007 name "Object file"
6008
6009 \end_inset
6010
6011  created by the assembler, input to Linkage editor
6012 \end_layout
6013
6014 \begin_layout Itemize
6015 sourcefile.map
6016 \begin_inset LatexCommand index
6017 name "<file>.map"
6018
6019 \end_inset
6020
6021  - The memory map
6022 \begin_inset LatexCommand index
6023 name "Memory map"
6024
6025 \end_inset
6026
6027  for the load module, created by the Linker
6028 \end_layout
6029
6030 \begin_layout Itemize
6031 sourcefile.mem
6032 \begin_inset LatexCommand index
6033 name "<file>.mem"
6034
6035 \end_inset
6036
6037  - A file with a summary of the memory usage
6038 \end_layout
6039
6040 \begin_layout Itemize
6041 sourcefile.ihx
6042 \begin_inset LatexCommand index
6043 name "<file>.ihx"
6044
6045 \end_inset
6046
6047  - The load module in Intel hex format
6048 \begin_inset LatexCommand index
6049 name "Intel hex format"
6050
6051 \end_inset
6052
6053  (you can select the Motorola S19 format
6054 \begin_inset LatexCommand index
6055 name "Motorola S19 format"
6056
6057 \end_inset
6058
6059  with -
6060 \begin_inset ERT
6061 status collapsed
6062
6063 \begin_layout Standard
6064
6065
6066 \backslash
6067 /
6068 \end_layout
6069
6070 \end_inset
6071
6072 -out-fmt-s19
6073 \begin_inset LatexCommand index
6074 name "-\\/-out-fmt-s19"
6075
6076 \end_inset
6077
6078 .
6079  If you need another format you might want to use 
6080 \family sans
6081 \shape italic
6082 objdump
6083 \family default
6084 \shape default
6085
6086 \begin_inset LatexCommand index
6087 name "objdump (tool)"
6088
6089 \end_inset
6090
6091  or 
6092 \family sans
6093 \shape italic
6094 srecord
6095 \family default
6096 \shape default
6097
6098 \begin_inset LatexCommand index
6099 name "srecord (bin, hex, ... tool)"
6100
6101 \end_inset
6102
6103
6104 \begin_inset Note Note
6105 status collapsed
6106
6107 \begin_layout Standard
6108 hyperlinks needed
6109 \end_layout
6110
6111 \end_inset
6112
6113  - see also section 
6114 \begin_inset LatexCommand vref
6115 reference "sub:Postprocessing-the-Intel"
6116
6117 \end_inset
6118
6119 ).
6120  Both formats are documented in the documentation of srecord
6121 \begin_inset LatexCommand index
6122 name "srecord (bin, hex, ... tool)"
6123
6124 \end_inset
6125
6126
6127 \end_layout
6128
6129 \begin_layout Itemize
6130 sourcefile.adb
6131 \begin_inset LatexCommand index
6132 name "<file>.adb"
6133
6134 \end_inset
6135
6136  - An intermediate file containing debug information needed to create the
6137  .cdb file (with -
6138 \begin_inset ERT
6139 status collapsed
6140
6141 \begin_layout Standard
6142
6143
6144 \backslash
6145 /
6146 \end_layout
6147
6148 \end_inset
6149
6150 -debug
6151 \begin_inset LatexCommand index
6152 name "-\\/-debug"
6153
6154 \end_inset
6155
6156
6157 \end_layout
6158
6159 \begin_layout Itemize
6160 sourcefile.cdb
6161 \begin_inset LatexCommand index
6162 name "<file>.cdb"
6163
6164 \end_inset
6165
6166  - An optional file (with -
6167 \begin_inset ERT
6168 status collapsed
6169
6170 \begin_layout Standard
6171
6172
6173 \backslash
6174 /
6175 \end_layout
6176
6177 \end_inset
6178
6179 -debug) containing debug information.
6180  The format is documented in cdbfileformat.pdf
6181 \end_layout
6182
6183 \begin_layout Itemize
6184 sourcefile.
6185  - (no extension)
6186 \begin_inset LatexCommand index
6187 name "<file> (no extension)"
6188
6189 \end_inset
6190
6191  An optional AOMF or AOMF51
6192 \begin_inset LatexCommand index
6193 name "AOMF, AOMF51"
6194
6195 \end_inset
6196
6197  
6198 \begin_inset LatexCommand label
6199 name "OMF file"
6200
6201 \end_inset
6202
6203 file containing debug information (generated with option -
6204 \begin_inset ERT
6205 status collapsed
6206
6207 \begin_layout Standard
6208
6209
6210 \backslash
6211 /
6212 \end_layout
6213
6214 \end_inset
6215
6216 -debug).
6217  The (Intel) 
6218 \emph on
6219 a
6220 \emph default
6221 bsolute 
6222 \emph on
6223 o
6224 \emph default
6225 bject 
6226 \emph on
6227 m
6228 \emph default
6229 odule 
6230 \emph on
6231 f
6232 \emph default
6233 ormat is a subformat of the OMF51 format and is commonly used by third party
6234  tools (debuggers
6235 \begin_inset LatexCommand index
6236 name "Debugger"
6237
6238 \end_inset
6239
6240 , simulators, emulators).
6241 \end_layout
6242
6243 \begin_layout Itemize
6244 sourcefile.dump*
6245 \begin_inset LatexCommand index
6246 name "<file>.dump*"
6247
6248 \end_inset
6249
6250  - Dump file to debug the compiler it self (generated with option -
6251 \begin_inset ERT
6252 status collapsed
6253
6254 \begin_layout Standard
6255
6256
6257 \backslash
6258 /
6259 \end_layout
6260
6261 \end_inset
6262
6263 -dumpall) (see section 
6264 \begin_inset LatexCommand ref
6265 reference "sub:Intermediate-Dump-Options"
6266
6267 \end_inset
6268
6269 \InsetSpace ~
6270  and section 
6271 \begin_inset LatexCommand ref
6272 reference "sub:The-anatomy-of"
6273
6274 \end_inset
6275
6276 \InsetSpace ~
6277
6278 \begin_inset Quotes sld
6279 \end_inset
6280
6281 Anatomy of the compiler
6282 \begin_inset Quotes srd
6283 \end_inset
6284
6285 ).
6286 \end_layout
6287
6288 \begin_layout Subsection
6289 Postprocessing the Intel Hex
6290 \begin_inset LatexCommand index
6291 name "Intel hex format"
6292
6293 \end_inset
6294
6295  file
6296 \begin_inset LatexCommand label
6297 name "sub:Postprocessing-the-Intel"
6298
6299 \end_inset
6300
6301
6302 \end_layout
6303
6304 \begin_layout Standard
6305 In most cases this won't be needed but the Intel Hex file
6306 \begin_inset LatexCommand index
6307 name "<file>.ihx"
6308
6309 \end_inset
6310
6311  which is generated by SDCC might include lines of varying length and the
6312  addresses within the file are not guaranteed to be strictly ascending.
6313  If your toolchain or a bootloader does not like this you can use the tool
6314  
6315 \family typewriter
6316 packihx
6317 \family default
6318
6319 \begin_inset LatexCommand index
6320 name "packihx (tool)"
6321
6322 \end_inset
6323
6324  which is part of the SDCC distribution: 
6325 \newline
6326
6327 \newline
6328  
6329 \family sans
6330 \series bold
6331 packihx sourcefile.ihx >sourcefile.hex
6332 \family default
6333 \series default
6334
6335 \newline
6336
6337 \newline
6338 The separately available 
6339 \emph on
6340 srecord
6341 \emph default
6342
6343 \begin_inset LatexCommand index
6344 name "srecord (bin, hex, ... tool)"
6345
6346 \end_inset
6347
6348  package additionally allows to set undefined locations to a predefined
6349  value, to insert checksums
6350 \begin_inset LatexCommand index
6351 name "checksum"
6352
6353 \end_inset
6354
6355  of various flavours (crc, add, xor) and to perform other manipulations
6356  (convert, split, crop, offset, ...).
6357  
6358 \newline
6359
6360 \newline
6361
6362 \family sans
6363 \series bold
6364 srec_cat\InsetSpace ~
6365 \InsetSpace ~
6366 sourcefile.ihx -intel\InsetSpace ~
6367 \InsetSpace ~
6368 -o sourcefile.hex -intel
6369 \newline
6370
6371 \newline
6372
6373 \family default
6374 \series default
6375 An example for a more complex command line
6376 \begin_inset Foot
6377 status open
6378
6379 \begin_layout Standard
6380 the command backfills
6381 \begin_inset LatexCommand index
6382 name "backfill unused memory"
6383
6384 \end_inset
6385
6386  unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
6387  block is zero.
6388  If the program counter on an mcs51 runs wild the backfill pattern 0x12
6389  will be interpreted as an 
6390 \family typewriter
6391 lcall
6392 \family default
6393  to address 
6394 \family typewriter
6395 0x1212
6396 \family default
6397  (where an emergency routine could sit).
6398 \end_layout
6399
6400 \end_inset
6401
6402  could look like:
6403 \newline
6404
6405 \newline
6406
6407 \family sans
6408 \series bold
6409 \size footnotesize
6410 srec_cat\InsetSpace ~
6411 sourcefile.ihx -intel\InsetSpace ~
6412 \InsetSpace ~
6413 -fill 0x12 0x0000 0xfffe\InsetSpace ~
6414 -little-endian-checksum-nega
6415 tive 0xfffe 0x02 0x02\InsetSpace ~
6416 \InsetSpace ~
6417 -o sourcefile.hex -intel
6418 \size default
6419
6420 \newline
6421
6422 \newline
6423
6424 \family default
6425 \series default
6426 The srecord package is available at 
6427 \begin_inset LatexCommand url
6428 target "http://sf.net/projects/srecord"
6429
6430 \end_inset
6431
6432  .
6433 \end_layout
6434
6435 \begin_layout Subsection
6436 Projects with Multiple Source Files
6437 \end_layout
6438
6439 \begin_layout Standard
6440 SDCC can compile only ONE file at a time.
6441  Let us for example assume that you have a project containing the following
6442  files:
6443 \newline
6444
6445 \newline
6446 foo1.c (contains some functions)
6447 \newline
6448 foo2.c (contains some more functions)
6449 \newline
6450 foomai
6451 n.c (contains more functions and the function main)
6452 \newline
6453
6454 \size footnotesize
6455
6456 \newline
6457
6458 \size default
6459 The first two files will need to be compiled separately with the commands:
6460 \size footnotesize
6461  
6462 \size default
6463
6464 \newline
6465
6466 \newline
6467
6468 \family sans
6469 \series bold
6470 sdcc\InsetSpace ~
6471 -c\InsetSpace ~
6472 foo1.c
6473 \family default
6474 \series default
6475 \size footnotesize
6476
6477 \newline
6478
6479 \family sans
6480 \series bold
6481 \size default
6482 sdcc\InsetSpace ~
6483 -c\InsetSpace ~
6484 foo2.c
6485 \family default
6486 \series default
6487
6488 \newline
6489
6490 \newline
6491 Then compile the source file containing the 
6492 \emph on
6493 main()
6494 \emph default
6495  function and link
6496 \begin_inset LatexCommand index
6497 name "Linker"
6498
6499 \end_inset
6500
6501  the files together with the following command: 
6502 \newline
6503
6504 \newline
6505
6506 \family sans
6507 \series bold
6508 sdcc\InsetSpace ~
6509 foomain.c\InsetSpace ~
6510 foo1.rel\InsetSpace ~
6511 foo2.rel
6512 \family default
6513 \series default
6514
6515 \begin_inset LatexCommand index
6516 name "<file>.rel"
6517
6518 \end_inset
6519
6520
6521 \newline
6522
6523 \newline
6524 Alternatively, 
6525 \emph on
6526 foomain.c
6527 \emph default
6528  can be separately compiled as well: 
6529 \family sans
6530 \series bold
6531
6532 \newline
6533
6534 \newline
6535 sdcc\InsetSpace ~
6536 -c\InsetSpace ~
6537 foomain.c
6538 \newline
6539 sdcc foomain.rel foo1.rel foo2.rel
6540 \newline
6541
6542 \newline
6543
6544 \family default
6545 \series default
6546 The file containing the 
6547 \emph on
6548 main()
6549 \emph default
6550  function 
6551 \noun on
6552 must
6553 \noun default
6554  be the 
6555 \noun on
6556 first
6557 \noun default
6558  file specified in the command line, since the linkage editor processes
6559  file in the order they are presented to it.
6560  The linker is invoked from SDCC using a script file with extension .lnk
6561 \begin_inset LatexCommand index
6562 name "<file>.lnk"
6563
6564 \end_inset
6565
6566 .
6567  You can view this file to troubleshoot linking problems such as those arising
6568  from missing libraries.
6569 \end_layout
6570
6571 \begin_layout Subsection
6572 Projects with Additional Libraries
6573 \begin_inset LatexCommand index
6574 name "Libraries"
6575
6576 \end_inset
6577
6578
6579 \end_layout
6580
6581 \begin_layout Standard
6582 Some reusable routines may be compiled into a library, see the documentation
6583  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6584  for how to create a 
6585 \emph on
6586 .lib
6587 \begin_inset LatexCommand index
6588 name "<file>.lib"
6589
6590 \end_inset
6591
6592
6593 \emph default
6594  library file.
6595  Libraries created in this manner can be included in the command line.
6596  Make sure you include the -L <library-path> option to tell the linker where
6597  to look for these files if they are not in the current directory.
6598  Here is an example, assuming you have the source file 
6599 \emph on
6600 foomain.c
6601 \emph default
6602  and a library 
6603 \emph on
6604 foolib.lib
6605 \emph default
6606  in the directory 
6607 \emph on
6608 mylib
6609 \emph default
6610  (if that is not the same as your current project):
6611 \newline
6612
6613 \newline
6614
6615 \family sans
6616 \series bold
6617 sdcc foomain.c foolib.lib -L mylib
6618 \newline
6619
6620 \newline
6621
6622 \family default
6623 \series default
6624 Note here that 
6625 \emph on
6626 mylib
6627 \emph default
6628  must be an absolute path name.
6629 \newline
6630
6631 \newline
6632 The most efficient way to use libraries is
6633  to keep separate modules in separate source files.
6634  The lib file now should name all the modules.rel
6635 \begin_inset LatexCommand index
6636 name "<file>.rel"
6637
6638 \end_inset
6639
6640  files.
6641  For an example see the standard library file 
6642 \emph on
6643 libsdcc.lib
6644 \emph default
6645  in the directory <installdir>/share/lib/small.
6646 \end_layout
6647
6648 \begin_layout Subsection
6649 Using sdcclib to Create and Manage Libraries
6650 \begin_inset LatexCommand index
6651 name "sdcclib"
6652
6653 \end_inset
6654
6655
6656 \end_layout
6657
6658 \begin_layout Standard
6659 Alternatively, instead of having a .rel file for each entry on the library
6660  file as described in the preceding section, sdcclib can be used to embed
6661  all the modules belonging to such library in the library file itself.
6662  This results in a larger library file, but it greatly reduces the number
6663  of disk files accessed by the linker.
6664   Additionally, the packed library file contains an index of all include
6665  modules and symbols that significantly speeds up the linking process.
6666  To display a list of options supported by sdcclib type:
6667 \newline
6668
6669 \end_layout
6670
6671 \begin_layout Standard
6672
6673 \family sans
6674 \series bold
6675 sdcclib -?
6676 \begin_inset LatexCommand index
6677 name "sdcclib"
6678
6679 \end_inset
6680
6681
6682 \newline
6683
6684 \newline
6685
6686 \family default
6687 \series default
6688 To create a new library file, start by compiling all the required modules.
6689  For example:
6690 \newline
6691
6692 \end_layout
6693
6694 \begin_layout Standard
6695
6696 \family sans
6697 \series bold
6698 sdcc -c _divsint.c
6699 \end_layout
6700
6701 \begin_layout Standard
6702
6703 \family sans
6704 \series bold
6705 sdcc -c _divuint.c
6706 \end_layout
6707
6708 \begin_layout Standard
6709
6710 \family sans
6711 \series bold
6712 sdcc -c _modsint.c
6713 \end_layout
6714
6715 \begin_layout Standard
6716
6717 \family sans
6718 \series bold
6719 sdcc -c _moduint.c
6720 \end_layout
6721
6722 \begin_layout Standard
6723
6724 \family sans
6725 \series bold
6726 sdcc -c _mulint.c
6727 \newline
6728
6729 \end_layout
6730
6731 \begin_layout Standard
6732 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6733  and _mulint.rel.
6734  The next step is to add the .rel files to the library file:
6735 \newline
6736
6737 \end_layout
6738
6739 \begin_layout Standard
6740
6741 \family sans
6742 \series bold
6743 sdcclib libint.lib _divsint.rel
6744 \family default
6745
6746 \begin_inset LatexCommand index
6747 name "sdcclib"
6748
6749 \end_inset
6750
6751
6752 \end_layout
6753
6754 \begin_layout Standard
6755
6756 \family sans
6757 \series bold
6758 sdcclib libint.lib _divuint.rel
6759 \end_layout
6760
6761 \begin_layout Standard
6762
6763 \family sans
6764 \series bold
6765 sdcclib libint.lib _modsint.rel
6766 \end_layout
6767
6768 \begin_layout Standard
6769
6770 \family sans
6771 \series bold
6772 sdcclib libint.lib _moduint.rel
6773 \end_layout
6774
6775 \begin_layout Standard
6776
6777 \family sans
6778 \series bold
6779 sdcclib libint.lib _mulint.rel
6780 \family default
6781 \series default
6782
6783 \newline
6784
6785 \end_layout
6786
6787 \begin_layout Standard
6788 Or, if you preffer:
6789 \family sans
6790 \series bold
6791
6792 \newline
6793
6794 \end_layout
6795
6796 \begin_layout Standard
6797
6798 \family sans
6799 \series bold
6800 sdcclib libint.lib _divsint.rel _divuint.rel _modsint.rel _moduint.rel _mulint.rel
6801 \family default
6802 \series default
6803
6804 \newline
6805
6806 \end_layout
6807
6808 \begin_layout Standard
6809 If the file already exists in the library, it will be replaced.
6810  If a list of .rel files is available, you can tell sdcclib to add those
6811  files to a library.
6812  For example, if the file 'myliblist.txt' contains
6813 \family sans
6814 \series bold
6815
6816 \newline
6817
6818 \end_layout
6819
6820 \begin_layout Standard
6821
6822 \family sans
6823 \series bold
6824 _divsint.rel
6825 \end_layout
6826
6827 \begin_layout Standard
6828
6829 \family sans
6830 \series bold
6831 _divuint.rel
6832 \end_layout
6833
6834 \begin_layout Standard
6835
6836 \family sans
6837 \series bold
6838 _modsint.rel
6839 \end_layout
6840
6841 \begin_layout Standard
6842
6843 \family sans
6844 \series bold
6845 _moduint.rel
6846 \end_layout
6847
6848 \begin_layout Standard
6849
6850 \family sans
6851 \series bold
6852 _mulint.rel
6853 \family default
6854 \series default
6855
6856 \newline
6857
6858 \end_layout
6859
6860 \begin_layout Standard
6861 Use
6862 \family sans
6863 \series bold
6864
6865 \newline
6866
6867 \end_layout
6868
6869 \begin_layout Standard
6870
6871 \family sans
6872 \series bold
6873 sdcclib -l libint.lib myliblist.txt
6874 \family default
6875 \series default
6876
6877 \newline
6878
6879 \end_layout
6880
6881 \begin_layout Standard
6882 Additionally, you can instruct sdcclib to compiles the files before adding
6883  them to the library.
6884  This is achieved using the environment variables SDCCLIB_CC and/or SDCCLIB_AS.
6885  For example:
6886 \family sans
6887 \series bold
6888
6889 \newline
6890
6891 \end_layout
6892
6893 \begin_layout Standard
6894
6895 \family sans
6896 \series bold
6897 set SDCCLIB_CC=sdcc -c
6898 \end_layout
6899
6900 \begin_layout Standard
6901
6902 \family sans
6903 \series bold
6904 sdcclib -l libint.lib myliblist.txt
6905 \family default
6906 \series default
6907
6908 \newline
6909
6910 \end_layout
6911
6912 \begin_layout Standard
6913 To see what modules and symbols are included in the library, options -s
6914  and -m are available.
6915  For example:
6916 \newline
6917
6918 \newline
6919
6920 \family sans
6921 \series bold
6922 sdcclib -s libint.lib
6923 \family default
6924
6925 \begin_inset LatexCommand index
6926 name "sdcclib"
6927
6928 \end_inset
6929
6930
6931 \newline
6932
6933 \family typewriter
6934 \series default
6935 _divsint.rel:
6936 \end_layout
6937
6938 \begin_layout Standard
6939
6940 \family typewriter
6941 __divsint_a_1_1
6942 \end_layout
6943
6944 \begin_layout Standard
6945
6946 \family typewriter
6947 __divsint_PARM_2
6948 \end_layout
6949
6950 \begin_layout Standard
6951
6952 \family typewriter
6953 __divsint
6954 \newline
6955 _divuint.rel:
6956 \end_layout
6957
6958 \begin_layout Standard
6959
6960 \family typewriter
6961 __divuint_a_1_1
6962 \end_layout
6963
6964 \begin_layout Standard
6965
6966 \family typewriter
6967 __divuint_PARM_2
6968 \end_layout
6969
6970 \begin_layout Standard
6971
6972 \family typewriter
6973 __divuint_reste_1_1
6974 \end_layout
6975
6976 \begin_layout Standard
6977
6978 \family typewriter
6979 __divuint_count_1_1
6980 \end_layout
6981
6982 \begin_layout Standard
6983
6984 \family typewriter
6985 __divuint
6986 \newline
6987 _modsint.rel:
6988 \end_layout
6989
6990 \begin_layout Standard
6991
6992 \family typewriter
6993 __modsint_a_1_1
6994 \end_layout
6995
6996 \begin_layout Standard
6997
6998 \family typewriter
6999 __modsint_PARM_2
7000 \end_layout
7001
7002 \begin_layout Standard
7003
7004 \family typewriter
7005 __modsint
7006 \newline
7007 _moduint.rel:
7008 \end_layout
7009
7010 \begin_layout Standard
7011
7012 \family typewriter
7013 __moduint_a_1_1
7014 \end_layout
7015
7016 \begin_layout Standard
7017
7018 \family typewriter
7019 __moduint_PARM_2
7020 \end_layout
7021
7022 \begin_layout Standard
7023
7024 \family typewriter
7025 __moduint_count_1_1
7026 \end_layout
7027
7028 \begin_layout Standard
7029
7030 \family typewriter
7031 __moduint
7032 \newline
7033 _mulint.rel:
7034 \end_layout
7035
7036 \begin_layout Standard
7037
7038 \family typewriter
7039 __mulint_PARM_2
7040 \end_layout
7041
7042 \begin_layout Standard
7043
7044 \family typewriter
7045 __mulint
7046 \family default
7047 \series bold
7048
7049 \newline
7050
7051 \end_layout
7052
7053 \begin_layout Standard
7054 If the source files are compiled using -
7055 \begin_inset ERT
7056 status collapsed
7057
7058 \begin_layout Standard
7059
7060
7061 \backslash
7062 /
7063 \end_layout
7064
7065 \end_inset
7066
7067 -debug
7068 \begin_inset LatexCommand index
7069 name "-\\/-debug"
7070
7071 \end_inset
7072
7073 , the corresponding debug information file .adb will be include in the library
7074  file as well.
7075  The library files created with sdcclib are plain text files, so they can
7076  be viewed with a text editor.
7077  It is not recommended to modify a library file created with sdcclib using
7078  a text editor, as there are file indexes numbers located across the file
7079  used by the linker to quickly locate the required module to link.
7080  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
7081  it can be safely deleted, since all the information required for linking
7082  is embedded in the library file itself.
7083  Library files created using sdcclib are used as described in the preceding
7084  sections.
7085 \begin_inset VSpace bigskip
7086 \end_inset
7087
7088
7089 \end_layout
7090
7091 \begin_layout Section
7092 Command Line Options
7093 \begin_inset LatexCommand index
7094 name "Command Line Options"
7095
7096 \end_inset
7097
7098
7099 \begin_inset LatexCommand label
7100 name "sec:Command-Line-Options"
7101
7102 \end_inset
7103
7104
7105 \end_layout
7106
7107 \begin_layout Subsection
7108 Processor Selection Options
7109 \begin_inset LatexCommand index
7110 name "Options processor selection"
7111
7112 \end_inset
7113
7114
7115 \begin_inset LatexCommand index
7116 name "Processor selection options"
7117
7118 \end_inset
7119
7120
7121 \end_layout
7122
7123 \begin_layout List
7124 \labelwidthstring 00.00.0000
7125
7126 \series bold
7127 -mmcs51
7128 \begin_inset LatexCommand index
7129 name "-mmcs51"
7130
7131 \end_inset
7132
7133
7134 \series default
7135  Generate code for the Intel MCS51
7136 \begin_inset LatexCommand index
7137 name "MCS51"
7138
7139 \end_inset
7140
7141  family of processors.
7142  This is the default processor target.
7143 \end_layout
7144
7145 \begin_layout List
7146 \labelwidthstring 00.00.0000
7147
7148 \series bold
7149 -mds390
7150 \begin_inset LatexCommand index
7151 name "-mds390"
7152
7153 \end_inset
7154
7155
7156 \series default
7157  Generate code for the Dallas DS80C390
7158 \begin_inset LatexCommand index
7159 name "DS80C390"
7160
7161 \end_inset
7162
7163  processor.
7164 \end_layout
7165
7166 \begin_layout List
7167 \labelwidthstring 00.00.0000
7168
7169 \series bold
7170 -mds400
7171 \begin_inset LatexCommand index
7172 name "-mds400"
7173
7174 \end_inset
7175
7176
7177 \series default
7178  Generate code for the Dallas DS80C400
7179 \begin_inset LatexCommand index
7180 name "DS80C400"
7181
7182 \end_inset
7183
7184  processor.
7185 \end_layout
7186
7187 \begin_layout List
7188 \labelwidthstring 00.00.0000
7189
7190 \series bold
7191 -mhc08
7192 \begin_inset LatexCommand index
7193 name "-mhc08"
7194
7195 \end_inset
7196
7197
7198 \series default
7199  Generate code for the Freescale/Motorola HC08
7200 \begin_inset LatexCommand index
7201 name "HC08"
7202
7203 \end_inset
7204
7205  family of processors.
7206 \end_layout
7207
7208 \begin_layout List
7209 \labelwidthstring 00.00.0000
7210
7211 \series bold
7212 -mz80
7213 \begin_inset LatexCommand index
7214 name "-mz80"
7215
7216 \end_inset
7217
7218
7219 \series default
7220  Generate code for the Zilog Z80
7221 \begin_inset LatexCommand index
7222 name "Z80"
7223
7224 \end_inset
7225
7226  family of processors.
7227 \end_layout
7228
7229 \begin_layout List
7230 \labelwidthstring 00.00.0000
7231
7232 \series bold
7233 -mgbz80
7234 \begin_inset LatexCommand index
7235 name "-mgbz80"
7236
7237 \end_inset
7238
7239
7240 \series default
7241  Generate code for the GameBoy Z80
7242 \begin_inset LatexCommand index
7243 name "gbz80 (GameBoy Z80)"
7244
7245 \end_inset
7246
7247  processor (Not actively maintained).
7248 \end_layout
7249
7250 \begin_layout List
7251 \labelwidthstring 00.00.0000
7252
7253 \series bold
7254 -mavr
7255 \begin_inset LatexCommand index
7256 name "-mavr"
7257
7258 \end_inset
7259
7260
7261 \series default
7262  Generate code for the Atmel AVR
7263 \begin_inset LatexCommand index
7264 name "AVR"
7265
7266 \end_inset
7267
7268  processor (Not maintained, not complete).
7269  AVR users should probably have a look at winavr 
7270 \begin_inset LatexCommand url
7271 target "http://sourceforge.net/projects/winavr"
7272
7273 \end_inset
7274
7275  or 
7276 \begin_inset LatexCommand url
7277 target "http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index"
7278
7279 \end_inset
7280
7281 , which is based on AVR-port of the gcc compiler.
7282 \end_layout
7283
7284 \begin_layout Standard
7285 \begin_inset Note Note
7286 status collapsed
7287
7288 \begin_layout Standard
7289 I think it is fair to direct users there for now.
7290  Open source is also about avoiding unnecessary work .
7291  But I didn't find the 'official' link.
7292 \end_layout
7293
7294 \end_inset
7295
7296
7297 \end_layout
7298
7299 \begin_layout List
7300 \labelwidthstring 00.00.0000
7301
7302 \series bold
7303 -mpic14
7304 \begin_inset LatexCommand index
7305 name "-mpic14"
7306
7307 \end_inset
7308
7309
7310 \series default
7311  Generate code for the Microchip PIC 14
7312 \begin_inset LatexCommand index
7313 name "PIC14"
7314
7315 \end_inset
7316
7317 -bit processors (p16f84 and variants.
7318  In development, not complete).
7319 \end_layout
7320
7321 \begin_layout Standard
7322 \begin_inset Note Note
7323 status collapsed
7324
7325 \begin_layout Standard
7326 p16f627 p16f628 p16f84 p16f873 p16f877?
7327 \end_layout
7328
7329 \end_inset
7330
7331
7332 \end_layout
7333
7334 \begin_layout List
7335 \labelwidthstring 00.00.0000
7336
7337 \series bold
7338 -mpic16
7339 \begin_inset LatexCommand index
7340 name "-mpic16"
7341
7342 \end_inset
7343
7344
7345 \series default
7346  Generate code for the Microchip PIC 16
7347 \begin_inset LatexCommand index
7348 name "PIC16"
7349
7350 \end_inset
7351
7352 -bit processors (p18f452 and variants.
7353  In development, not complete).
7354 \end_layout
7355
7356 \begin_layout List
7357 \labelwidthstring 00.00.0000
7358
7359 \series bold
7360 -mtlcs900h
7361 \series default
7362  Generate code for the Toshiba TLCS-900H
7363 \begin_inset LatexCommand index
7364 name "TLCS-900H"
7365
7366 \end_inset
7367
7368  processor (Not maintained, not complete).
7369 \end_layout
7370
7371 \begin_layout List
7372 \labelwidthstring 00.00.0000
7373
7374 \series bold
7375 -mxa51
7376 \begin_inset LatexCommand index
7377 name "-mxa51"
7378
7379 \end_inset
7380
7381
7382 \series default
7383  Generate code for the Phillips XA51
7384 \begin_inset LatexCommand index
7385 name "XA51"
7386
7387 \end_inset
7388
7389  processor (Not maintained, not complete).
7390 \end_layout
7391
7392 \begin_layout Standard
7393 \begin_inset VSpace bigskip
7394 \end_inset
7395
7396
7397 \end_layout
7398
7399 \begin_layout Subsection
7400 Preprocessor Options
7401 \begin_inset LatexCommand index
7402 name "Options preprocessor"
7403
7404 \end_inset
7405
7406
7407 \begin_inset LatexCommand index
7408 name "Preprocessor options"
7409
7410 \end_inset
7411
7412
7413 \begin_inset LatexCommand index
7414 name "sdcpp (preprocessor)"
7415
7416 \end_inset
7417
7418
7419 \end_layout
7420
7421 \begin_layout List
7422 \labelwidthstring 00.00.0000
7423
7424 \series bold
7425 -I<path>
7426 \begin_inset LatexCommand index
7427 name "-I<path>"
7428
7429 \end_inset
7430
7431
7432 \series default
7433  The additional location where the preprocessor will look for <..h> or 
7434 \begin_inset Quotes eld
7435 \end_inset
7436
7437 ..h
7438 \begin_inset Quotes erd
7439 \end_inset
7440
7441  files.
7442 \end_layout
7443
7444 \begin_layout List
7445 \labelwidthstring 00.00.0000
7446
7447 \series bold
7448 -D<macro[=value]>
7449 \begin_inset LatexCommand index
7450 name "-D<macro[=value]>"
7451
7452 \end_inset
7453
7454
7455 \series default
7456  Command line definition of macros.
7457  Passed to the preprocessor.
7458 \end_layout
7459
7460 \begin_layout List
7461 \labelwidthstring 00.00.0000
7462
7463 \series bold
7464 -M
7465 \begin_inset LatexCommand index
7466 name "-M"
7467
7468 \end_inset
7469
7470
7471 \series default
7472  Tell the preprocessor to output a rule suitable for make describing the
7473  dependencies of each object file.
7474  For each source file, the preprocessor outputs one make-rule whose target
7475  is the object file name for that source file and whose dependencies are
7476  all the files `#include'd in it.
7477  This rule may be a single line or may be continued with `
7478 \backslash
7479 '-newline if it is long.
7480  The list of rules is printed on standard output instead of the preprocessed
7481  C program.
7482  `-M' implies `-E
7483 \begin_inset LatexCommand index
7484 name "-E"
7485
7486 \end_inset
7487
7488 '.
7489 \end_layout
7490
7491 \begin_layout List
7492 \labelwidthstring 00.00.0000
7493
7494 \series bold
7495 -C
7496 \begin_inset LatexCommand index
7497 name "-C"
7498
7499 \end_inset
7500
7501
7502 \series default
7503  Tell the preprocessor not to discard comments.
7504  Used with the `-E' option.
7505 \end_layout
7506
7507 \begin_layout List
7508 \labelwidthstring 00.00.0000
7509
7510 \series bold
7511 -MM
7512 \begin_inset LatexCommand index
7513 name "-MM"
7514
7515 \end_inset
7516
7517
7518 \series default
7519 \size large
7520  
7521 \size default
7522 Like `-M' but the output mentions only the user header files included with
7523  `#include 
7524 \begin_inset Quotes eld
7525 \end_inset
7526
7527 file"'.
7528  System header files included with `#include <file>' are omitted.
7529 \end_layout
7530
7531 \begin_layout List
7532 \labelwidthstring 00.00.0000
7533
7534 \series bold
7535 -Aquestion(answer)
7536 \begin_inset LatexCommand index
7537 name "-Aquestion(answer)"
7538
7539 \end_inset
7540
7541
7542 \series default
7543  Assert the answer answer for question, in case it is tested with a preprocessor
7544  conditional such as `#if #question(answer)'.
7545  `-A-' disables the standard assertions that normally describe the target
7546  machine.
7547 \end_layout
7548
7549 \begin_layout List
7550 \labelwidthstring 00.00.0000
7551
7552 \series bold
7553 -Umacro
7554 \begin_inset LatexCommand index
7555 name "-Umacro"
7556
7557 \end_inset
7558
7559
7560 \series default
7561  Undefine macro macro.
7562  `-U' options are evaluated after all `-D' options, but before any `-include'
7563  and `-imacros' options.
7564 \end_layout
7565
7566 \begin_layout List
7567 \labelwidthstring 00.00.0000
7568
7569 \series bold
7570 -dM
7571 \begin_inset LatexCommand index
7572 name "-dM"
7573
7574 \end_inset
7575
7576
7577 \series default
7578  Tell the preprocessor to output only a list of the macro definitions that
7579  are in effect at the end of preprocessing.
7580  Used with the `-E' option.
7581 \end_layout
7582
7583 \begin_layout List
7584 \labelwidthstring 00.00.0000
7585
7586 \series bold
7587 -dD
7588 \begin_inset LatexCommand index
7589 name "-dD"
7590
7591 \end_inset
7592
7593
7594 \series default
7595  Tell the preprocessor to pass all macro definitions into the output, in
7596  their proper sequence in the rest of the output.
7597 \end_layout
7598
7599 \begin_layout List
7600 \labelwidthstring 00.00.0000
7601
7602 \series bold
7603 -dN
7604 \begin_inset LatexCommand index
7605 name "-dN"
7606
7607 \end_inset
7608
7609
7610 \series default
7611 \size large
7612  
7613 \size default
7614 Like `-dD' except that the macro arguments and contents are omitted.
7615  Only `#define name' is included in the output.
7616 \end_layout
7617
7618 \begin_layout List
7619 \labelwidthstring 00.00.0000
7620
7621 \series bold
7622 -pedantic-parse-number
7623 \begin_inset LatexCommand index
7624 name "pedantic"
7625
7626 \end_inset
7627
7628
7629 \begin_inset LatexCommand index
7630 name "-pedantic-parse-number"
7631
7632 \end_inset
7633
7634
7635 \size large
7636 \bar under
7637
7638 \begin_inset LatexCommand label
7639 name "lyx:-pedantic-parse-number"
7640
7641 \end_inset
7642
7643
7644 \series default
7645 \bar default
7646  
7647 \size default
7648 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
7649  and the macro LO_B(3) gets expanded.
7650  See also #pragma pedantic_parse_number 
7651 \begin_inset LatexCommand vpageref
7652 reference "ite:pedantic_parse_number"
7653
7654 \end_inset
7655
7656  in section
7657 \begin_inset LatexCommand ref
7658 reference "sec:Pragmas"
7659
7660 \end_inset
7661
7662  
7663 \emph on
7664 Note: this functionality is not in conformance with C99 standard!
7665 \end_layout
7666
7667 \begin_layout List
7668 \labelwidthstring 00.00.0000
7669
7670 \series bold
7671 -Wp\InsetSpace ~
7672 preprocessorOption[,preprocessorOption]
7673 \series default
7674
7675 \begin_inset LatexCommand index
7676 name "-Wp preprocessorOption[,preprocessorOption]"
7677
7678 \end_inset
7679
7680 ...
7681  Pass the preprocessorOption to the preprocessor 
7682 \family typewriter
7683 sdcpp
7684 \family default
7685
7686 \begin_inset LatexCommand index
7687 name "sdcpp (preprocessor)"
7688
7689 \end_inset
7690
7691 .
7692  SDCC uses an adapted version of the preprocessor 
7693 \emph on
7694 cpp
7695 \emph default
7696  of the GNU Compiler Collection
7697 \begin_inset LatexCommand index
7698 name "gcc (GNU Compiler Collection)"
7699
7700 \end_inset
7701
7702  (
7703 \emph on
7704 gcc
7705 \emph default
7706  
7707 \begin_inset LatexCommand url
7708 target "http://gcc.gnu.org/"
7709
7710 \end_inset
7711
7712 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7713 4.1.1\InsetSpace ~
7714 CPP\InsetSpace ~
7715 Manual
7716  at 
7717 \begin_inset LatexCommand htmlurl
7718 target "http://www.gnu.org/software/gcc/onlinedocs/"
7719
7720 \end_inset
7721
7722 .
7723 \end_layout
7724
7725 \begin_layout Standard
7726 \begin_inset VSpace bigskip
7727 \end_inset
7728
7729
7730 \end_layout
7731
7732 \begin_layout Subsection
7733 Linker Options
7734 \begin_inset LatexCommand index
7735 name "Options linker"
7736
7737 \end_inset
7738
7739
7740 \begin_inset LatexCommand index
7741 name "Linker options"
7742
7743 \end_inset
7744
7745
7746 \end_layout
7747
7748 \begin_layout List
7749 \labelwidthstring 00.00.0000
7750
7751 \series bold
7752 -L\InsetSpace ~
7753 -
7754 \series default
7755
7756 \begin_inset ERT
7757 status collapsed
7758
7759 \begin_layout Standard
7760
7761
7762 \backslash
7763 /
7764 \end_layout
7765
7766 \end_inset
7767
7768
7769 \series bold
7770 -lib-path
7771 \begin_inset LatexCommand index
7772 name "-\\/-lib-path <path>"
7773
7774 \end_inset
7775
7776
7777 \begin_inset LatexCommand index
7778 name "-L -\\/-lib-path"
7779
7780 \end_inset
7781
7782
7783 \series default
7784 \InsetSpace ~
7785 <absolute path to additional libraries> This option is passed to the linkage
7786  editor's additional libraries
7787 \begin_inset LatexCommand index
7788 name "Libraries"
7789
7790 \end_inset
7791
7792  search path.
7793  The path name must be absolute.
7794  Additional library files may be specified in the command line.
7795  See section Compiling programs for more details.
7796 \end_layout
7797
7798 \begin_layout List
7799 \labelwidthstring 00.00.0000
7800
7801 \series bold
7802 -
7803 \begin_inset ERT
7804 status collapsed
7805
7806 \begin_layout Standard
7807
7808
7809 \backslash
7810 /
7811 \end_layout
7812
7813 \end_inset
7814
7815 -xram-loc
7816 \series default
7817
7818 \begin_inset LatexCommand index
7819 name "-\\/-xram-loc <Value>"
7820
7821 \end_inset
7822
7823 \InsetSpace ~
7824 <Value> The start location of the external ram
7825 \begin_inset LatexCommand index
7826 name "xdata (mcs51, ds390 storage class)"
7827
7828 \end_inset
7829
7830 , default value is 0.
7831  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7832 \begin_inset ERT
7833 status collapsed
7834
7835 \begin_layout Standard
7836
7837
7838 \backslash
7839 /
7840 \end_layout
7841
7842 \end_inset
7843
7844 -xram-loc 0x8000 or -
7845 \begin_inset ERT
7846 status collapsed
7847
7848 \begin_layout Standard
7849
7850
7851 \backslash
7852 /
7853 \end_layout
7854
7855 \end_inset
7856
7857 -xram-loc 32768.
7858 \end_layout
7859
7860 \begin_layout List
7861 \labelwidthstring 00.00.0000
7862
7863 \series bold
7864 -
7865 \begin_inset ERT
7866 status collapsed
7867
7868 \begin_layout Standard
7869
7870
7871 \backslash
7872 /
7873 \end_layout
7874
7875 \end_inset
7876
7877 -code-loc
7878 \series default
7879
7880 \begin_inset LatexCommand index
7881 name "-\\/-code-loc <Value>"
7882
7883 \end_inset
7884
7885 \InsetSpace ~
7886 <Value> The start location of the code
7887 \begin_inset LatexCommand index
7888 name "code"
7889
7890 \end_inset
7891
7892  segment, default value 0.
7893  Note when this option is used the interrupt vector table
7894 \begin_inset LatexCommand index
7895 name "interrupt vector table"
7896
7897 \end_inset
7898
7899  is also relocated to the given address.
7900  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7901 \begin_inset ERT
7902 status collapsed
7903
7904 \begin_layout Standard
7905
7906
7907 \backslash
7908 /
7909 \end_layout
7910
7911 \end_inset
7912
7913 -code-loc 0x8000 or -
7914 \begin_inset ERT
7915 status collapsed
7916
7917 \begin_layout Standard
7918
7919
7920 \backslash
7921 /
7922 \end_layout
7923
7924 \end_inset
7925
7926 -code-loc 32768.
7927 \end_layout
7928
7929 \begin_layout List
7930 \labelwidthstring 00.00.0000
7931
7932 \series bold
7933 -
7934 \begin_inset ERT
7935 status collapsed
7936
7937 \begin_layout Standard
7938
7939
7940 \backslash
7941 /
7942 \end_layout
7943
7944 \end_inset
7945
7946 -stack-loc
7947 \series default
7948
7949 \begin_inset LatexCommand index
7950 name "-\\/-stack-loc <Value>"
7951
7952 \end_inset
7953
7954 \InsetSpace ~
7955 <Value> By default the stack
7956 \begin_inset LatexCommand index
7957 name "stack"
7958
7959 \end_inset
7960
7961  is placed after the data segment.
7962  Using this option the stack can be placed anywhere in the internal memory
7963  space of the 8051.
7964  The value entered can be in Hexadecimal or Decimal format, e.g.
7965  -
7966 \begin_inset ERT
7967 status collapsed
7968
7969 \begin_layout Standard
7970
7971
7972 \backslash
7973 /
7974 \end_layout
7975
7976 \end_inset
7977
7978 -stack-loc 0x20 or -
7979 \begin_inset ERT
7980 status collapsed
7981
7982 \begin_layout Standard
7983
7984
7985 \backslash
7986 /
7987 \end_layout
7988
7989 \end_inset
7990
7991 -stack-loc 32.
7992  Since the sp register is incremented before a push or call, the initial
7993  sp will be set to one byte prior the provided value.
7994  The provided value should not overlap any other memory areas such as used
7995  register banks or the data segment and with enough space for the current
7996  application.
7997  The 
7998 \series bold
7999 -
8000 \begin_inset ERT
8001 status collapsed
8002
8003 \begin_layout Standard
8004
8005
8006 \backslash
8007 /
8008 \end_layout
8009
8010 \end_inset
8011
8012 -pack-iram
8013 \series default
8014 \InsetSpace ~
8015
8016 \begin_inset LatexCommand index
8017 name "-\\/-pack-iram"
8018
8019 \end_inset
8020
8021  option (which is now a default setting) will override this setting, so
8022  you should also specify the 
8023 \series bold
8024 -
8025 \begin_inset ERT
8026 status collapsed
8027
8028 \begin_layout Standard
8029
8030
8031 \backslash
8032 /
8033 \end_layout
8034
8035 \end_inset
8036
8037 -no-pack-iram
8038 \series default
8039 \InsetSpace ~
8040
8041 \begin_inset LatexCommand index
8042 name "-\\/-no-pack-iram"
8043
8044 \end_inset
8045
8046  option if you need to manually place the stack.
8047 \end_layout
8048
8049 \begin_layout List
8050 \labelwidthstring 00.00.0000
8051
8052 \series bold
8053 -
8054 \begin_inset ERT
8055 status collapsed
8056
8057 \begin_layout Standard
8058
8059
8060 \backslash
8061 /
8062 \end_layout
8063
8064 \end_inset
8065
8066 -xstack-loc
8067 \series default
8068
8069 \begin_inset LatexCommand index
8070 name "-\\/-xstack-loc <Value>"
8071
8072 \end_inset
8073
8074 \InsetSpace ~
8075 <Value> By default the external stack
8076 \begin_inset LatexCommand index
8077 name "xstack"
8078
8079 \end_inset
8080
8081  is placed after the pdata
8082 \begin_inset LatexCommand index
8083 name "pdata (mcs51, ds390 storage class)"
8084
8085 \end_inset
8086
8087  segment.
8088  Using this option the xstack can be placed anywhere in the external memory
8089  space of the 8051.
8090  The value entered can be in Hexadecimal or Decimal format, e.g.
8091  -
8092 \begin_inset ERT
8093 status collapsed
8094
8095 \begin_layout Standard
8096
8097
8098 \backslash
8099 /
8100 \end_layout
8101
8102 \end_inset
8103
8104 -xstack-loc 0x8000 or -
8105 \begin_inset ERT
8106 status collapsed
8107
8108 \begin_layout Standard
8109
8110
8111 \backslash
8112 /
8113 \end_layout
8114
8115 \end_inset
8116
8117 -stack-loc 32768.
8118  The provided value should not overlap any other memory areas such as the
8119  pdata or xdata segment and with enough space for the current application.
8120 \end_layout
8121
8122 \begin_layout List
8123 \labelwidthstring 00.00.0000
8124
8125 \series bold
8126 -
8127 \begin_inset ERT
8128 status collapsed
8129
8130 \begin_layout Standard
8131
8132
8133 \backslash
8134 /
8135 \end_layout
8136
8137 \end_inset
8138
8139 -data-loc
8140 \series default
8141
8142 \begin_inset LatexCommand index
8143 name "-\\/-data-loc <Value>"
8144
8145 \end_inset
8146
8147 \InsetSpace ~
8148 <Value> The start location of the internal ram data
8149 \begin_inset LatexCommand index
8150 name "data (mcs51, ds390 storage class)"
8151
8152 \end_inset
8153
8154  segment.
8155  The value entered can be in Hexadecimal or Decimal format, eg.
8156  -
8157 \begin_inset ERT
8158 status collapsed
8159
8160 \begin_layout Standard
8161
8162
8163 \backslash
8164 /
8165 \end_layout
8166
8167 \end_inset
8168
8169 -data-loc 0x20 or -
8170 \begin_inset ERT
8171 status collapsed
8172
8173 \begin_layout Standard
8174
8175
8176 \backslash
8177 /
8178 \end_layout
8179
8180 \end_inset
8181
8182 -data-loc 32.
8183  (By default, the start location of the internal ram data segment  is set
8184  as low as possible in memory, taking into account the used register banks
8185  and the bit segment at address 0x20.
8186  For example if register banks 0 and 1 are used without bit variables, the
8187  data segment will be set, if -
8188 \begin_inset ERT
8189 status collapsed
8190
8191 \begin_layout Standard
8192
8193
8194 \backslash
8195 /
8196 \end_layout
8197
8198 \end_inset
8199
8200 -data-loc is not used, to location 0x10.)
8201 \end_layout
8202
8203 \begin_layout List
8204 \labelwidthstring 00.00.0000
8205
8206 \series bold
8207 -
8208 \begin_inset ERT
8209 status collapsed
8210
8211 \begin_layout Standard
8212
8213
8214 \backslash
8215 /
8216 \end_layout
8217
8218 \end_inset
8219
8220 -idata-loc
8221 \series default
8222
8223 \begin_inset LatexCommand index
8224 name "-\\/-idata-loc <Value>"
8225
8226 \end_inset
8227
8228 \InsetSpace ~
8229 <Value> The start location of the indirectly addressable internal ram
8230 \begin_inset LatexCommand index
8231 name "idata (mcs51, ds390 storage class)"
8232
8233 \end_inset
8234
8235  of the 8051, default value is 0x80.
8236  The value entered can be in Hexadecimal or Decimal format, eg.
8237  -
8238 \begin_inset ERT
8239 status collapsed
8240
8241 \begin_layout Standard
8242
8243
8244 \backslash
8245 /
8246 \end_layout
8247
8248 \end_inset
8249
8250 -idata-loc 0x88 or -
8251 \begin_inset ERT
8252 status collapsed
8253
8254 \begin_layout Standard
8255
8256
8257 \backslash
8258 /
8259 \end_layout
8260
8261 \end_inset
8262
8263 -idata-loc 136.
8264 \end_layout
8265
8266 \begin_layout List
8267 \labelwidthstring 00.00.0000
8268
8269 \series bold
8270 -
8271 \begin_inset ERT
8272 status collapsed
8273
8274 \begin_layout Standard
8275
8276
8277 \backslash
8278 /
8279 \end_layout
8280
8281 \end_inset
8282
8283 -bit-loc
8284 \series default
8285 \InsetSpace ~
8286 <Value> The start location of the bit
8287 \begin_inset LatexCommand index
8288 name "bit"
8289
8290 \end_inset
8291
8292  addressable internal ram of the 8051.
8293  This is 
8294 \emph on
8295 not
8296 \emph default
8297  implemented yet.
8298  Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
8299 -bBSEG=<Value>.
8300 \end_layout
8301
8302 \begin_layout List
8303 \labelwidthstring 00.00.0000
8304
8305 \series bold
8306 -
8307 \begin_inset ERT
8308 status collapsed
8309
8310 \begin_layout Standard
8311
8312
8313 \backslash
8314 /
8315 \end_layout
8316
8317 \end_inset
8318
8319 -out-fmt-ihx
8320 \begin_inset LatexCommand index
8321 name "-\\/-out-fmt-ihx"
8322
8323 \end_inset
8324
8325  
8326 \series default
8327 The linker output (final object code) is in Intel Hex format.
8328 \begin_inset LatexCommand index
8329 name "Intel hex format"
8330
8331 \end_inset
8332
8333  This is the default option.
8334  The format itself is documented in the documentation of srecord
8335 \begin_inset LatexCommand index
8336 name "srecord (bin, hex, ... tool)"
8337
8338 \end_inset
8339
8340 .
8341 \end_layout
8342
8343 \begin_layout List
8344 \labelwidthstring 00.00.0000
8345
8346 \series bold
8347 -
8348 \begin_inset ERT
8349 status collapsed
8350
8351 \begin_layout Standard
8352
8353
8354 \backslash
8355 /
8356 \end_layout
8357
8358 \end_inset
8359
8360 -out-fmt-s19
8361 \begin_inset LatexCommand index
8362 name "-\\/-out-fmt-s19"
8363
8364 \end_inset
8365
8366  
8367 \series default
8368 The linker output (final object code) is in Motorola S19 format
8369 \begin_inset LatexCommand index
8370 name "Motorola S19 format"
8371
8372 \end_inset
8373
8374 .
8375  The format itself is documented in the documentation of srecord.
8376 \end_layout
8377
8378 \begin_layout List
8379 \labelwidthstring 00.00.0000
8380
8381 \series bold
8382 -
8383 \begin_inset ERT
8384 status collapsed
8385
8386 \begin_layout Standard
8387
8388
8389 \backslash
8390 /
8391 \end_layout
8392
8393 \end_inset
8394
8395 -out-fmt-elf
8396 \begin_inset LatexCommand index
8397 name "-\\/-out-fmt-s19"
8398
8399 \end_inset
8400
8401
8402 \begin_inset LatexCommand index
8403 name "HC08!Options!-\\/-out-fmt-elf"
8404
8405 \end_inset
8406
8407  
8408 \series default
8409 The linker output (final object code) is in ELF format
8410 \begin_inset LatexCommand index
8411 name "ELF format"
8412
8413 \end_inset
8414
8415 .
8416  (Currently only supported for the HC08
8417 \begin_inset LatexCommand index
8418 name "HC08"
8419
8420 \end_inset
8421
8422  processors)
8423 \end_layout
8424
8425 \begin_layout List
8426 \labelwidthstring 00.00.0000
8427
8428 \series bold
8429 -Wl\InsetSpace ~
8430 linkOption[,linkOption]
8431 \series default
8432
8433 \begin_inset LatexCommand index
8434 name "-Wl linkOption[,linkOption]"
8435
8436 \end_inset
8437
8438
8439 \begin_inset LatexCommand label
8440 name "lyx:-Wl option"
8441
8442 \end_inset
8443
8444 ...
8445  Pass the linkOption to the linker.
8446  If a bootloader is used an option like 
8447 \begin_inset Quotes sld
8448 \end_inset
8449
8450 -Wl\InsetSpace ~
8451 -bCSEG=0x1000
8452 \begin_inset Quotes srd
8453 \end_inset
8454
8455  would be typical to set the start of the code segment.
8456  Either use the double quotes around this option or use no space (e.g.
8457  -Wl-bCSEG=0x1000).
8458  See also #pragma constseg and #pragma codeseg in section 
8459 \begin_inset LatexCommand ref
8460 reference "sec:Pragmas"
8461
8462 \end_inset
8463
8464  .
8465  File sdcc/as/doc/asxhtm.html has more on linker options.
8466 \end_layout
8467
8468 \begin_layout Standard
8469 \begin_inset VSpace bigskip
8470 \end_inset
8471
8472
8473 \end_layout
8474
8475 \begin_layout Subsection
8476 MCS51 Options
8477 \begin_inset LatexCommand index
8478 name "Options MCS51"
8479
8480 \end_inset
8481
8482
8483 \begin_inset LatexCommand index
8484 name "MCS51 options"
8485
8486 \end_inset
8487
8488
8489 \end_layout
8490
8491 \begin_layout List
8492 \labelwidthstring 00.00.0000
8493
8494 \series bold
8495 -
8496 \begin_inset ERT
8497 status collapsed
8498
8499 \begin_layout Standard
8500
8501
8502 \backslash
8503 /
8504 \end_layout
8505
8506 \end_inset
8507
8508 -model-small
8509 \begin_inset LatexCommand index
8510 name "-\\/-model-small"
8511
8512 \end_inset
8513
8514
8515 \series default
8516 \size large
8517  
8518 \size default
8519 Generate code for Small Model programs, see section Memory Models for more
8520  details.
8521  This is the default model.
8522 \end_layout
8523
8524 \begin_layout List
8525 \labelwidthstring 00.00.0000
8526
8527 \series bold
8528 -
8529 \begin_inset ERT
8530 status collapsed
8531
8532 \begin_layout Standard
8533
8534
8535 \backslash
8536 /
8537 \end_layout
8538
8539 \end_inset
8540
8541 -model-medium
8542 \begin_inset LatexCommand index
8543 name "-\\/-model-medium"
8544
8545 \end_inset
8546
8547
8548 \series default
8549  Generate code for Medium model programs, see section Memory Models for
8550  more details.
8551  If this option is used all source files in the project have to be compiled
8552  with this option.
8553  It must also be used when invoking the linker.
8554 \end_layout
8555
8556 \begin_layout List
8557 \labelwidthstring 00.00.0000
8558
8559 \series bold
8560 -
8561 \begin_inset ERT
8562 status collapsed
8563
8564 \begin_layout Standard
8565
8566
8567 \backslash
8568 /
8569 \end_layout
8570
8571 \end_inset
8572
8573 -model-large
8574 \begin_inset LatexCommand index
8575 name "-\\/-model-large"
8576
8577 \end_inset
8578
8579
8580 \series default
8581  Generate code for Large model programs, see section Memory Models for more
8582  details.
8583  If this option is used all source files in the project have to be compiled
8584  with this option.
8585  It must also be used when invoking the linker.
8586 \end_layout
8587
8588 \begin_layout List
8589 \labelwidthstring 00.00.0000
8590
8591 \series bold
8592 -
8593 \begin_inset ERT
8594 status collapsed
8595
8596 \begin_layout Standard
8597
8598
8599 \backslash
8600 /
8601 \end_layout
8602
8603 \end_inset
8604
8605 -xstack
8606 \begin_inset LatexCommand index
8607 name "-\\/-xstack"
8608
8609 \end_inset
8610
8611
8612 \series default
8613  Uses a pseudo stack in the pdata
8614 \begin_inset LatexCommand index
8615 name "pdata (mcs51, ds390 storage class)"
8616
8617 \end_inset
8618
8619  area (usually the first 256 bytes in the external ram) for allocating variables
8620  and passing parameters.
8621  See section 
8622 \begin_inset LatexCommand ref
8623 reference "sub:External-Stack"
8624
8625 \end_inset
8626
8627 \InsetSpace ~
8628  External Stack for more details.
8629 \end_layout
8630
8631 \begin_layout List
8632 \labelwidthstring 00.00.0000
8633
8634 \series bold
8635 -
8636 \begin_inset ERT
8637 status collapsed
8638
8639 \begin_layout Standard
8640
8641
8642 \backslash
8643 /
8644 \end_layout
8645
8646 \end_inset
8647
8648 -iram-size
8649 \series default
8650 \InsetSpace ~
8651 <Value>
8652 \begin_inset LatexCommand index
8653 name "-\\/-iram-size <Value>"
8654
8655 \end_inset
8656
8657  Causes the linker to check if the internal ram usage is within limits of
8658  the given value.
8659 \end_layout
8660
8661 \begin_layout List
8662 \labelwidthstring 00.00.0000
8663
8664 \series bold
8665 -
8666 \begin_inset ERT
8667 status collapsed
8668
8669 \begin_layout Standard
8670
8671
8672 \backslash
8673 /
8674 \end_layout
8675
8676 \end_inset
8677
8678 -xram-size
8679 \series default
8680 \InsetSpace ~
8681 <Value>
8682 \begin_inset LatexCommand index
8683 name "-\\/-xram-size <Value>"
8684
8685 \end_inset
8686
8687  Causes the linker to check if the external ram usage is within limits of
8688  the given value.
8689 \end_layout
8690
8691 \begin_layout List
8692 \labelwidthstring 00.00.0000
8693
8694 \series bold
8695 -
8696 \begin_inset ERT
8697 status collapsed
8698
8699 \begin_layout Standard
8700
8701
8702 \backslash
8703 /
8704 \end_layout
8705
8706 \end_inset
8707
8708 -code-size
8709 \series default
8710 \InsetSpace ~
8711 <Value>
8712 \begin_inset LatexCommand index
8713 name "-\\/-code-size <Value>"
8714
8715 \end_inset
8716
8717  Causes the linker to check if the code memory usage is within limits of
8718  the given value.
8719 \end_layout
8720
8721 \begin_layout List
8722 \labelwidthstring 00.00.0000
8723
8724 \series bold
8725 -
8726 \begin_inset ERT
8727 status collapsed
8728
8729 \begin_layout Standard
8730
8731
8732 \backslash
8733 /
8734 \end_layout
8735
8736 \end_inset
8737
8738 -stack-size
8739 \series default
8740 \InsetSpace ~
8741 <Value>
8742 \begin_inset LatexCommand index
8743 name "-\\/-stack-size <Value>"
8744
8745 \end_inset
8746
8747  Causes the linker to check if there is at minimum <Value> bytes for stack.
8748 \end_layout
8749
8750 \begin_layout List
8751 \labelwidthstring 00.00.0000
8752
8753 \series bold
8754 -
8755 \begin_inset ERT
8756 status collapsed
8757
8758 \begin_layout Standard
8759
8760
8761 \backslash
8762 /
8763 \end_layout
8764
8765 \end_inset
8766
8767 -pack-iram
8768 \series default
8769 \InsetSpace ~
8770
8771 \begin_inset LatexCommand index
8772 name "-\\/-pack-iram"
8773
8774 \end_inset
8775
8776  Causes the linker to use unused register banks for data variables and pack
8777  data, idata and stack together.
8778  This is the default now.
8779 \end_layout
8780
8781 \begin_layout List
8782 \labelwidthstring 00.00.0000
8783
8784 \series bold
8785 -
8786 \begin_inset ERT
8787 status collapsed
8788
8789 \begin_layout Standard
8790
8791
8792 \backslash
8793 /
8794 \end_layout
8795
8796 \end_inset
8797
8798 -no-pack-iram
8799 \series default
8800 \InsetSpace ~
8801
8802 \begin_inset LatexCommand index
8803 name "-\\/-no-pack-iram"
8804
8805 \end_inset
8806
8807  Causes the linker to use old style for allocating memory areas.
8808 \end_layout
8809
8810 \begin_layout List
8811 \labelwidthstring 00.00.0000
8812
8813 \series bold
8814 -
8815 \begin_inset ERT
8816 status collapsed
8817
8818 \begin_layout Standard
8819
8820
8821 \backslash
8822 /
8823 \end_layout
8824
8825 \end_inset
8826
8827 -acall-ajmp
8828 \series default
8829 \InsetSpace ~
8830
8831 \begin_inset LatexCommand index
8832 name "-\\/-acall-ajmp"
8833
8834 \end_inset
8835
8836  Replaces the three byte instructions lcall/ljmp with the two byte instructions
8837  acall/ajmp.
8838  Only use this option if your code is in the same 2k block of memory.
8839  You may need to use this option for some 8051 derivatives which lack the
8840  lcall/ljmp instructions..
8841 \end_layout
8842
8843 \begin_layout Standard
8844 \begin_inset VSpace bigskip
8845 \end_inset
8846
8847
8848 \end_layout
8849
8850 \begin_layout Subsection
8851 DS390 / DS400 Options
8852 \begin_inset LatexCommand index
8853 name "Options DS390"
8854
8855 \end_inset
8856
8857
8858 \begin_inset LatexCommand index
8859 name "DS390"
8860
8861 \end_inset
8862
8863
8864 \end_layout
8865
8866 \begin_layout List
8867 \labelwidthstring 00.00.0000
8868
8869 \series bold
8870 -
8871 \begin_inset ERT
8872 status collapsed
8873
8874 \begin_layout Standard
8875
8876
8877 \backslash
8878 /
8879 \end_layout
8880
8881 \end_inset
8882
8883 -model-flat24
8884 \series default
8885
8886 \begin_inset LatexCommand index
8887 name "DS390!Options!-\\/-model-flat24"
8888
8889 \end_inset
8890
8891
8892 \size large
8893  
8894 \size default
8895 Generate 24-bit flat mode code.
8896  This is the one and only that the ds390 code generator supports right now
8897  and is default when using 
8898 \emph on
8899 -mds390
8900 \emph default
8901 .
8902  See section Memory Models for more details.
8903 \end_layout
8904
8905 \begin_layout List
8906 \labelwidthstring 00.00.0000
8907
8908 \series bold
8909 -
8910 \begin_inset ERT
8911 status collapsed
8912
8913 \begin_layout Standard
8914
8915
8916 \backslash
8917 /
8918 \end_layout
8919
8920 \end_inset
8921
8922 -protect-sp-update
8923 \begin_inset LatexCommand index
8924 name "DS390!Options!-\\/-protect-sp-update"
8925
8926 \end_inset
8927
8928
8929 \series default
8930  disable interrupts during ESP:SP updates.
8931 \end_layout
8932
8933 \begin_layout List
8934 \labelwidthstring 00.00.0000
8935
8936 \series bold
8937 -
8938 \begin_inset ERT
8939 status collapsed
8940
8941 \begin_layout Standard
8942
8943
8944 \backslash
8945 /
8946 \end_layout
8947
8948 \end_inset
8949
8950 -stack-10bit
8951 \series default
8952
8953 \begin_inset LatexCommand index
8954 name "DS390!Options!-\\/-stack-10bit"
8955
8956 \end_inset
8957
8958  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8959  This is the one and only that the ds390 code generator supports right now
8960  and is default when using 
8961 \emph on
8962 -mds390
8963 \emph default
8964 .
8965  In this mode, the stack is located in the lower 1K of the internal RAM,
8966  which is mapped to 0x400000.
8967  Note that the support is incomplete, since it still uses a single byte
8968  as the stack pointer.
8969  This means that only the lower 256 bytes of the potential 1K stack space
8970  will actually be used.
8971  However, this does allow you to reclaim the precious 256 bytes of low RAM
8972  for use for the DATA and IDATA segments.
8973  The compiler will not generate any code to put the processor into 10 bit
8974  stack mode.
8975  It is important to ensure that the processor is in this mode before calling
8976  any re-entrant functions compiled with this option.
8977  In principle, this should work with the 
8978 \emph on
8979 -
8980 \begin_inset ERT
8981 status collapsed
8982
8983 \begin_layout Standard
8984
8985
8986 \backslash
8987 /
8988 \end_layout
8989
8990 \end_inset
8991
8992 -stack-auto
8993 \begin_inset LatexCommand index
8994 name "-\\/-stack-auto"
8995
8996 \end_inset
8997
8998
8999 \emph default
9000  option, but that has not been tested.
9001  It is incompatible with the 
9002 \emph on
9003 -
9004 \begin_inset ERT
9005 status collapsed
9006
9007 \begin_layout Standard
9008
9009
9010 \backslash
9011 /
9012 \end_layout
9013
9014 \end_inset
9015
9016 -xstack
9017 \begin_inset LatexCommand index
9018 name "-\\/-xstack"
9019
9020 \end_inset
9021
9022
9023 \emph default
9024  option.
9025  It also only makes sense if the processor is in 24 bit contiguous addressing
9026  mode (see the 
9027 \emph on
9028 -
9029 \begin_inset ERT
9030 status collapsed
9031
9032 \begin_layout Standard
9033
9034
9035 \backslash
9036 /
9037 \end_layout
9038
9039 \end_inset
9040
9041 -model-flat24 option
9042 \emph default
9043 ).
9044 \series bold
9045
9046 \begin_inset Note Note
9047 status collapsed
9048
9049 \begin_layout List
9050 \labelwidthstring 00.00.0000
9051
9052 \series bold
9053 -
9054 \begin_inset ERT
9055 status open
9056
9057 \begin_layout Standard
9058
9059
9060 \backslash
9061 /
9062 \end_layout
9063
9064 \end_inset
9065
9066 -stack-8-bit - switches off the 10-bit mode
9067 \end_layout
9068
9069 \end_inset
9070
9071
9072 \end_layout
9073
9074 \begin_layout List
9075 \labelwidthstring 00.00.0000
9076
9077 \series bold
9078 -
9079 \begin_inset ERT
9080 status collapsed
9081
9082 \begin_layout Standard
9083
9084
9085 \backslash
9086 /
9087 \end_layout
9088
9089 \end_inset
9090
9091 -stack-probe
9092 \begin_inset LatexCommand index
9093 name "DS390!Options!-\\/-stack-probe"
9094
9095 \end_inset
9096
9097
9098 \series default
9099  insert call to function __stack_probe at each function prologue.
9100 \end_layout
9101
9102 \begin_layout List
9103 \labelwidthstring 00.00.0000
9104
9105 \series bold
9106 -
9107 \begin_inset ERT
9108 status open
9109
9110 \begin_layout Standard
9111
9112
9113 \backslash
9114 /
9115 \end_layout
9116
9117 \end_inset
9118
9119 -tini-libid
9120 \begin_inset LatexCommand index
9121 name "DS390!Options!-\\/-tini-libid"
9122
9123 \end_inset
9124
9125
9126 \series default
9127  <nnnn> LibraryID used in -mTININative.
9128  
9129 \end_layout
9130
9131 \begin_layout List
9132 \labelwidthstring 00.00.0000
9133
9134 \series bold
9135 -
9136 \begin_inset ERT
9137 status collapsed
9138
9139 \begin_layout Standard
9140
9141
9142 \backslash
9143 /
9144 \end_layout
9145
9146 \end_inset
9147
9148 -use-accelerator
9149 \begin_inset LatexCommand index
9150 name "DS390!Options!-\\/-use-accelerator"
9151
9152 \end_inset
9153
9154
9155 \series default
9156  generate code for DS390 Arithmetic Accelerator.
9157  
9158 \end_layout
9159
9160 \begin_layout Standard
9161 \begin_inset VSpace bigskip
9162 \end_inset
9163
9164
9165 \end_layout
9166
9167 \begin_layout Subsection
9168 Z80 Options
9169 \begin_inset LatexCommand index
9170 name "Options Z80"
9171
9172 \end_inset
9173
9174
9175 \begin_inset LatexCommand index
9176 name "Z80"
9177
9178 \end_inset
9179
9180
9181 \end_layout
9182
9183 \begin_layout List
9184 \labelwidthstring 00.00.0000
9185
9186 \series bold
9187 -
9188 \begin_inset ERT
9189 status collapsed
9190
9191 \begin_layout Standard
9192
9193
9194 \backslash
9195 /
9196 \end_layout
9197
9198 \end_inset
9199
9200 -callee-saves-bc
9201 \series default
9202
9203 \begin_inset LatexCommand index
9204 name "Z80!Options!-\\/-callee-saves-bc"
9205
9206 \end_inset
9207
9208
9209 \size large
9210  
9211 \size default
9212 Force a called function to always save BC.
9213 \end_layout
9214
9215 \begin_layout List
9216 \labelwidthstring 00.00.0000
9217
9218 \series bold
9219 -
9220 \begin_inset ERT
9221 status collapsed
9222
9223 \begin_layout Standard
9224
9225
9226 \backslash
9227 /
9228 \end_layout
9229
9230 \end_inset
9231
9232 -no-std-crt0
9233 \series default
9234
9235 \begin_inset LatexCommand index
9236 name "Z80!Options!-\\/-no-std-crt0"
9237
9238 \end_inset
9239
9240  When linking, skip the standard crt0.o object file.
9241  You must provide your own crt0.o for your system when linking.
9242 \end_layout
9243
9244 \begin_layout List
9245 \labelwidthstring 00.00.0000
9246
9247 \series bold
9248 -
9249 \begin_inset ERT
9250 status collapsed
9251
9252 \begin_layout Standard
9253
9254
9255 \backslash
9256 /
9257 \end_layout
9258
9259 \end_inset
9260
9261 -portmode=
9262 \series default
9263 <Value>
9264 \begin_inset LatexCommand index
9265 name "Z80!Options!-\\/-portmode=<Value>"
9266
9267 \end_inset
9268
9269  Determinate PORT I/O mode (<Value> is z80 or z180).
9270 \end_layout
9271
9272 \begin_layout List
9273 \labelwidthstring 00.00.0000
9274
9275 \series bold
9276 -
9277 \begin_inset ERT
9278 status collapsed
9279
9280 \begin_layout Standard
9281
9282
9283 \backslash
9284 /
9285 \end_layout
9286
9287 \end_inset
9288
9289 -asm=
9290 \series default
9291 <Value>
9292 \begin_inset LatexCommand index
9293 name "Z80!Options!-\\/-asm=<Value>"
9294
9295 \end_inset
9296
9297  Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
9298 \end_layout
9299
9300 \begin_layout List
9301 \labelwidthstring 00.00.0000
9302
9303 \series bold
9304 -
9305 \begin_inset ERT
9306 status collapsed
9307
9308 \begin_layout Standard
9309
9310
9311 \backslash
9312 /
9313 \end_layout
9314
9315 \end_inset
9316
9317 -codeseg
9318 \series default
9319 \InsetSpace ~
9320 <Value>
9321 \begin_inset LatexCommand index
9322 name "Z80!Options!-\\/-codeseg <Value>"
9323
9324 \end_inset
9325
9326  Use <Value> for the code segment name.
9327 \end_layout
9328
9329 \begin_layout List
9330 \labelwidthstring 00.00.0000
9331
9332 \series bold
9333 -
9334 \begin_inset ERT
9335 status collapsed
9336
9337 \begin_layout Standard
9338
9339
9340 \backslash
9341 /
9342 \end_layout
9343
9344 \end_inset
9345
9346 -constseg
9347 \series default
9348 \InsetSpace ~
9349 <Value>
9350 \begin_inset LatexCommand index
9351 name "Z80!Options!-\\/-constseg <Value>"
9352
9353 \end_inset
9354
9355  Use <Value> for the const segment name.
9356 \end_layout
9357
9358 \begin_layout List
9359 \labelwidthstring 00.00.0000
9360 \begin_inset VSpace bigskip
9361 \end_inset
9362
9363
9364 \end_layout
9365
9366 \begin_layout Subsection
9367 GBZ80 Options
9368 \begin_inset LatexCommand index
9369 name "Options GBZ80"
9370
9371 \end_inset
9372
9373
9374 \begin_inset LatexCommand index
9375 name "GBZ80"
9376
9377 \end_inset
9378
9379
9380 \end_layout
9381
9382 \begin_layout List
9383 \labelwidthstring 00.00.0000
9384
9385 \series bold
9386 -
9387 \begin_inset ERT
9388 status collapsed
9389
9390 \begin_layout Standard
9391
9392
9393 \backslash
9394 /
9395 \end_layout
9396
9397 \end_inset
9398
9399 -callee-saves-bc
9400 \series default
9401
9402 \begin_inset LatexCommand index
9403 name "GBZ80!Options!-\\/-callee-saves-bc"
9404
9405 \end_inset
9406
9407
9408 \size large
9409  
9410 \size default
9411 Force a called function to always save BC.
9412 \end_layout
9413
9414 \begin_layout List
9415 \labelwidthstring 00.00.0000
9416
9417 \series bold
9418 -
9419 \begin_inset ERT
9420 status collapsed
9421
9422 \begin_layout Standard
9423
9424
9425 \backslash
9426 /
9427 \end_layout
9428
9429 \end_inset
9430
9431 -no-std-crt0
9432 \series default
9433
9434 \begin_inset LatexCommand index
9435 name "Z80!Options!-\\/-no-std-crt0"
9436
9437 \end_inset
9438
9439  When linking, skip the standard crt0.o object file.
9440  You must provide your own crt0.o for your system when linking.
9441 \end_layout
9442
9443 \begin_layout List
9444 \labelwidthstring 00.00.0000
9445
9446 \series bold
9447 -bo
9448 \series default
9449 \InsetSpace ~
9450 <Num>
9451 \begin_inset LatexCommand index
9452 name "GBZ80!Options!-bo <Num>"
9453
9454 \end_inset
9455
9456  Use code bank <Num>.
9457 \end_layout
9458
9459 \begin_layout List
9460 \labelwidthstring 00.00.0000
9461
9462 \series bold
9463 -ba
9464 \series default
9465 \InsetSpace ~
9466 <Num>
9467 \begin_inset LatexCommand index
9468 name "GBZ80!Options!-ba <Num>"
9469
9470 \end_inset
9471
9472  Use data bank <Num>.
9473 \end_layout
9474
9475 \begin_layout List
9476 \labelwidthstring 00.00.0000
9477
9478 \series bold
9479 -
9480 \begin_inset ERT
9481 status collapsed
9482
9483 \begin_layout Standard
9484
9485
9486 \backslash
9487 /
9488 \end_layout
9489
9490 \end_inset
9491
9492 -codeseg
9493 \series default
9494 \InsetSpace ~
9495 <Value>
9496 \begin_inset LatexCommand index
9497 name "GBZ80!Options!-\\/-codeseg <Value>"
9498
9499 \end_inset
9500
9501  Use <Value> for the code segment name.
9502 \end_layout
9503
9504 \begin_layout List
9505 \labelwidthstring 00.00.0000
9506
9507 \series bold
9508 -
9509 \begin_inset ERT
9510 status collapsed
9511
9512 \begin_layout Standard
9513
9514
9515 \backslash
9516 /
9517 \end_layout
9518
9519 \end_inset
9520
9521 -constseg
9522 \series default
9523 \InsetSpace ~
9524 <Value>
9525 \begin_inset LatexCommand index
9526 name "GBZ80!Options!-\\/-constseg <Value>"
9527
9528 \end_inset
9529
9530  Use <Value> for the const segment name.
9531 \end_layout
9532
9533 \begin_layout Standard
9534 \begin_inset VSpace bigskip
9535 \end_inset
9536
9537
9538 \end_layout
9539
9540 \begin_layout Subsection
9541 Optimization Options
9542 \begin_inset LatexCommand index
9543 name "Options optimization"
9544
9545 \end_inset
9546
9547
9548 \begin_inset LatexCommand index
9549 name "Optimization options"
9550
9551 \end_inset
9552
9553
9554 \end_layout
9555
9556 \begin_layout List
9557 \labelwidthstring 00.00.0000
9558
9559 \series bold
9560 -
9561 \begin_inset ERT
9562 status collapsed
9563
9564 \begin_layout Standard
9565
9566
9567 \backslash
9568 /
9569 \end_layout
9570
9571 \end_inset
9572
9573 -nogcse
9574 \begin_inset LatexCommand index
9575 name "-\\/-nogcse"
9576
9577 \end_inset
9578
9579
9580 \series default
9581  Will not do global subexpression elimination, this option may be used when
9582  the compiler creates undesirably large stack/data spaces to store compiler
9583  temporaries (
9584 \emph on
9585 s
9586 \emph default
9587 pill 
9588 \emph on
9589 loc
9590 \emph default
9591 ations, sloc
9592 \begin_inset LatexCommand index
9593 name "sloc (spill location)"
9594
9595 \end_inset
9596
9597 ).
9598  A warning message will be generated when this happens and the compiler
9599  will indicate the number of extra bytes it allocated.
9600  It is recommended that this option NOT be used, #pragma\InsetSpace ~
9601 nogcse
9602 \begin_inset LatexCommand index
9603 name "\\#pragma nogcse"
9604
9605 \end_inset
9606
9607  can be used to turn off global subexpression elimination
9608 \begin_inset LatexCommand index
9609 name "Subexpression elimination"
9610
9611 \end_inset
9612
9613  for a given function only.
9614 \end_layout
9615
9616 \begin_layout List
9617 \labelwidthstring 00.00.0000
9618
9619 \series bold
9620 -
9621 \begin_inset ERT
9622 status collapsed
9623
9624 \begin_layout Standard
9625
9626
9627 \backslash
9628 /
9629 \end_layout
9630
9631 \end_inset
9632
9633 -noinvariant
9634 \begin_inset LatexCommand index
9635 name "-\\/-noinvariant"
9636
9637 \end_inset
9638
9639
9640 \series default
9641  Will not do loop invariant optimizations, this may be turned off for reasons
9642  explained for the previous option.
9643  For more details of loop optimizations performed see Loop Invariants in
9644  section 
9645 \begin_inset LatexCommand ref
9646 reference "sub:Loop-Optimizations"
9647
9648 \end_inset
9649
9650 .
9651  It is recommended that this option NOT be used, #pragma\InsetSpace ~
9652 noinvariant
9653 \begin_inset LatexCommand index
9654 name "\\#pragma noinvariant"
9655
9656 \end_inset
9657
9658  can be used to turn off invariant optimizations for a given function only.
9659 \end_layout
9660
9661 \begin_layout List
9662 \labelwidthstring 00.00.0000
9663
9664 \series bold
9665 -
9666 \begin_inset ERT
9667 status collapsed
9668
9669 \begin_layout Standard
9670
9671
9672 \backslash
9673 /
9674 \end_layout
9675
9676 \end_inset
9677
9678 -noinduction
9679 \begin_inset LatexCommand index
9680 name "-\\/-noinduction"
9681
9682 \end_inset
9683
9684
9685 \series default
9686  Will not do loop induction optimizations, see section strength reduction
9687  for more details.
9688  It is recommended that this option is NOT used, #pragma\InsetSpace ~
9689 noinduction
9690 \begin_inset LatexCommand index
9691 name "\\#pragma noinduction"
9692
9693 \end_inset
9694
9695  can be used to turn off induction optimizations for a given function only.
9696 \end_layout
9697
9698 \begin_layout List
9699 \labelwidthstring 00.00.0000
9700
9701 \series bold
9702 -
9703 \begin_inset ERT
9704 status collapsed
9705
9706 \begin_layout Standard
9707
9708
9709 \backslash
9710 /
9711 \end_layout
9712
9713 \end_inset
9714
9715 -nojtbound
9716 \begin_inset LatexCommand index
9717 name "-\\/-nojtbound"
9718
9719 \end_inset
9720
9721
9722 \size large
9723  
9724 \series default
9725 \size default
9726  Will not generate boundary condition check when switch statements
9727 \begin_inset LatexCommand index
9728 name "switch statement"
9729
9730 \end_inset
9731
9732  are implemented using jump-tables.
9733  See section 
9734 \begin_inset LatexCommand ref
9735 reference "sub:'switch'-Statements"
9736
9737 \end_inset
9738
9739 \InsetSpace ~
9740 Switch Statements for more details.
9741  It is recommended that this option is NOT used, #pragma\InsetSpace ~
9742 nojtbound
9743 \begin_inset LatexCommand index
9744 name "\\#pragma nojtbound"
9745
9746 \end_inset
9747
9748  can be used to turn off boundary checking for jump tables for a given function
9749  only.
9750 \end_layout
9751
9752 \begin_layout List
9753 \labelwidthstring 00.00.0000
9754
9755 \series bold
9756 -
9757 \begin_inset ERT
9758 status collapsed
9759
9760 \begin_layout Standard
9761
9762
9763 \backslash
9764 /
9765 \end_layout
9766
9767 \end_inset
9768
9769 -noloopreverse
9770 \begin_inset LatexCommand index
9771 name "-\\/-noloopreverse"
9772
9773 \end_inset
9774
9775
9776 \series default
9777 \size large
9778  
9779 \size default
9780 Will not do loop reversal 
9781 \begin_inset LatexCommand index
9782 name "Loop reversing"
9783
9784 \end_inset
9785
9786 optimization.
9787 \end_layout
9788
9789 \begin_layout List
9790 \labelwidthstring 00.00.0000
9791 -
9792 \begin_inset ERT
9793 status collapsed
9794
9795 \begin_layout Standard
9796
9797
9798 \backslash
9799 /
9800 \end_layout
9801
9802 \end_inset
9803
9804 -
9805 \series bold
9806 nolabelopt
9807 \series default
9808  
9809 \begin_inset LatexCommand index
9810 name "-\\/-nolabelopt "
9811
9812 \end_inset
9813
9814 Will not optimize labels (makes the dumpfiles more readable).
9815 \end_layout
9816
9817 \begin_layout List
9818 \labelwidthstring 00.00.0000
9819
9820 \series bold
9821 -
9822 \begin_inset ERT
9823 status collapsed
9824
9825 \begin_layout Standard
9826
9827
9828 \backslash
9829 /
9830 \end_layout
9831
9832 \end_inset
9833
9834 -no-xinit-opt
9835 \begin_inset LatexCommand index
9836 name "-\\/-no-xinit-opt"
9837
9838 \end_inset
9839
9840
9841 \series default
9842  Will not memcpy initialized data from code space into xdata space.
9843  This saves a few bytes in code space if you don't have initialized data
9844 \begin_inset LatexCommand index
9845 name "Variable initialization"
9846
9847 \end_inset
9848
9849 .
9850 \end_layout
9851
9852 \begin_layout List
9853 \labelwidthstring 00.00.0000
9854
9855 \series bold
9856 -
9857 \begin_inset ERT
9858 status collapsed
9859
9860 \begin_layout Standard
9861
9862
9863 \backslash
9864 /
9865 \end_layout
9866
9867 \end_inset
9868
9869 -nooverlay
9870 \begin_inset LatexCommand index
9871 name "-\\/-nooverlay"
9872
9873 \end_inset
9874
9875
9876 \series default
9877   The compiler will not overlay parameters and local variables of any function,
9878  see section Parameters and local variables for more details.
9879 \end_layout
9880
9881 \begin_layout List
9882 \labelwidthstring 00.00.0000
9883
9884 \series bold
9885 -
9886 \begin_inset ERT
9887 status collapsed
9888
9889 \begin_layout Standard
9890
9891
9892 \backslash
9893 /
9894 \end_layout
9895
9896 \end_inset
9897
9898 -no-peep
9899 \begin_inset LatexCommand index
9900 name "-\\/-no-peep"
9901
9902 \end_inset
9903
9904
9905 \series default
9906  Disable peep-hole optimization with built-in rules.
9907 \end_layout
9908
9909 \begin_layout List
9910 \labelwidthstring 00.00.0000
9911
9912 \series bold
9913 -
9914 \begin_inset ERT
9915 status collapsed
9916
9917 \begin_layout Standard
9918
9919
9920 \backslash
9921 /
9922 \end_layout
9923
9924 \end_inset
9925
9926 -peep-file
9927 \series default
9928
9929 \begin_inset LatexCommand index
9930 name "-\\/-peep-file"
9931
9932 \end_inset
9933
9934 \InsetSpace ~
9935 <filename> This option can be used to use additional rules to be used by
9936  the peep hole optimizer.
9937  See section 
9938 \begin_inset LatexCommand ref
9939 reference "sub:Peephole-Optimizer"
9940
9941 \end_inset
9942
9943 \InsetSpace ~
9944 Peep Hole optimizations for details on how to write these rules.
9945 \end_layout
9946
9947 \begin_layout List
9948 \labelwidthstring 00.00.0000
9949
9950 \series bold
9951 -
9952 \begin_inset ERT
9953 status collapsed
9954
9955 \begin_layout Standard
9956
9957
9958 \backslash
9959 /
9960 \end_layout
9961
9962 \end_inset
9963
9964 -peep-asm
9965 \begin_inset LatexCommand index
9966 name "-\\/-peep-asm"
9967
9968 \end_inset
9969
9970
9971 \series default
9972  Pass the inline assembler code through the peep hole optimizer.
9973  This can cause unexpected changes to inline assembler code, please go through
9974  the peephole optimizer
9975 \begin_inset LatexCommand index
9976 name "Peephole optimizer"
9977
9978 \end_inset
9979
9980  rules defined in the source file tree '<target>/peeph.def' before using
9981  this option.
9982 \end_layout
9983
9984 \begin_layout List
9985 \labelwidthstring 00.00.0000
9986
9987 \series bold
9988 -
9989 \begin_inset ERT
9990 status collapsed
9991
9992 \begin_layout Standard
9993
9994
9995 \backslash
9996 /
9997 \end_layout
9998
9999 \end_inset
10000
10001 -opt-code-speed
10002 \begin_inset LatexCommand index
10003 name "-\\/-opt-code-speed"
10004
10005 \end_inset
10006
10007
10008 \series default
10009  The compiler will optimize code generation towards fast code, possibly
10010  at the expense of code size.
10011 \end_layout
10012
10013 \begin_layout List
10014 \labelwidthstring 00.00.0000
10015
10016 \series bold
10017 -
10018 \begin_inset ERT
10019 status collapsed
10020
10021 \begin_layout Standard
10022
10023
10024 \backslash
10025 /
10026 \end_layout
10027
10028 \end_inset
10029
10030 -opt-code-size
10031 \begin_inset LatexCommand index
10032 name "-\\/-opt-code-size"
10033
10034 \end_inset
10035
10036
10037 \series default
10038  The compiler will optimize code generation towards compact code, possibly
10039  at the expense of code speed.
10040 \end_layout
10041
10042 \begin_layout Standard
10043 \begin_inset VSpace bigskip
10044 \end_inset
10045
10046
10047 \end_layout
10048
10049 \begin_layout Subsection
10050 Other Options
10051 \begin_inset LatexCommand index
10052 name "Options other"
10053
10054 \end_inset
10055
10056
10057 \end_layout
10058
10059 \begin_layout List
10060 \labelwidthstring 00.00.0000
10061
10062 \series bold
10063 -c\InsetSpace ~
10064 -
10065 \begin_inset ERT
10066 status collapsed
10067
10068 \begin_layout Standard
10069
10070
10071 \backslash
10072 /
10073 \end_layout
10074
10075 \end_inset
10076
10077 -compile-only
10078 \begin_inset LatexCommand index
10079 name "-\\/-compile-only"
10080
10081 \end_inset
10082
10083
10084 \begin_inset LatexCommand index
10085 name "-c -\\/-compile-only"
10086
10087 \end_inset
10088
10089
10090 \series default
10091  will compile and assemble the source, but will not call the linkage editor.
10092 \end_layout
10093
10094 \begin_layout List
10095 \labelwidthstring 00.00.0000
10096
10097 \series bold
10098 -
10099 \series default
10100
10101 \begin_inset ERT
10102 status collapsed
10103
10104 \begin_layout Standard
10105
10106
10107 \backslash
10108 /
10109 \end_layout
10110
10111 \end_inset
10112
10113
10114 \series bold
10115 -c1mode
10116 \begin_inset LatexCommand index
10117 name "-\\/-c1mode"
10118
10119 \end_inset
10120
10121
10122 \series default
10123  reads the preprocessed source from standard input and compiles it.
10124  The file name for the assembler output must be specified using the -o option.
10125 \end_layout
10126
10127 \begin_layout List
10128 \labelwidthstring 00.00.0000
10129
10130 \series bold
10131 -E
10132 \begin_inset LatexCommand index
10133 name "-E"
10134
10135 \end_inset
10136
10137
10138 \series default
10139  Run only the C preprocessor.
10140  Preprocess all the C source files specified and output the results to standard
10141  output.
10142 \end_layout
10143
10144 \begin_layout List
10145 \labelwidthstring 00.00.0000
10146
10147 \series bold
10148 -o\InsetSpace ~
10149 <path/file>
10150 \begin_inset LatexCommand index
10151 name "-o <path/file>"
10152
10153 \end_inset
10154
10155
10156 \series default
10157  The output path where everything will be placed or the file name used for
10158  all generated output files.
10159  If the parameter is a path, it must have a trailing slash (or backslash
10160  for the Windows binaries) to be recognized as a path.
10161  Note for Windows users: if the path contains spaces, it should be surrounded
10162  by quotes.
10163  The trailing backslash should be doubled in order to prevent escaping the
10164  final quote, for example: 
10165 \emph on
10166 -o 
10167 \begin_inset Quotes sld
10168 \end_inset
10169
10170 F:
10171 \backslash
10172 Projects
10173 \backslash
10174 test3
10175 \backslash
10176 output 1
10177 \backslash
10178
10179 \backslash
10180
10181 \begin_inset Quotes srd
10182 \end_inset
10183
10184
10185 \emph default
10186  or put after the final quote, for example: 
10187 \emph on
10188 -o 
10189 \begin_inset Quotes sld
10190 \end_inset
10191
10192 F:
10193 \backslash
10194 Projects
10195 \backslash
10196 test3
10197 \backslash
10198 output 1
10199 \begin_inset Quotes srd
10200 \end_inset
10201
10202
10203 \backslash
10204
10205 \emph default
10206 .
10207  The path using slashes for directory delimiters can be used too, for example:
10208  
10209 \emph on
10210 -o 
10211 \begin_inset Quotes sld
10212 \end_inset
10213
10214 F:/Projects/test3/output 1/
10215 \begin_inset Quotes srd
10216 \end_inset
10217
10218
10219 \emph default
10220 .
10221 \end_layout
10222
10223 \begin_layout List
10224 \labelwidthstring 00.00.0000
10225
10226 \series bold
10227 -
10228 \begin_inset ERT
10229 status collapsed
10230
10231 \begin_layout Standard
10232
10233
10234 \backslash
10235 /
10236 \end_layout
10237
10238 \end_inset
10239
10240 -stack-auto
10241 \begin_inset LatexCommand index
10242 name "-\\/-stack-auto"
10243
10244 \end_inset
10245
10246
10247 \series default
10248 \size large
10249  
10250 \size default
10251 All functions in the source file will be compiled as 
10252 \emph on
10253 reentrant
10254 \emph default
10255
10256 \begin_inset LatexCommand index
10257 name "reentrant"
10258
10259 \end_inset
10260
10261 , i.e.
10262  the parameters and local variables will be allocated on the stack
10263 \begin_inset LatexCommand index
10264 name "stack"
10265
10266 \end_inset
10267
10268 .
10269  See section 
10270 \begin_inset LatexCommand ref
10271 reference "sec:Parameters-and-Local-Variables"
10272
10273 \end_inset
10274
10275  Parameters and Local Variables for more details.
10276  If this option is used all source files in the project should be compiled
10277  with this option.
10278  It automatically implies -
10279 \series bold
10280
10281 \begin_inset ERT
10282 status open
10283
10284 \begin_layout Standard
10285
10286
10287 \backslash
10288 /
10289 \end_layout
10290
10291 \end_inset
10292
10293
10294 \series default
10295 -int-long-reent and -
10296 \series bold
10297
10298 \begin_inset ERT
10299 status open
10300
10301 \begin_layout Standard
10302
10303
10304 \backslash
10305 /
10306 \end_layout
10307
10308 \end_inset
10309
10310
10311 \series default
10312 -float-reent.
10313  
10314 \end_layout
10315
10316 \begin_layout List
10317 \labelwidthstring 00.00.0000
10318
10319 \series bold
10320 -
10321 \begin_inset ERT
10322 status collapsed
10323
10324 \begin_layout Standard
10325
10326
10327 \backslash
10328 /
10329 \end_layout
10330
10331 \end_inset
10332
10333 -callee-saves
10334 \begin_inset LatexCommand index
10335 name "-\\/-callee-saves"
10336
10337 \end_inset
10338
10339  
10340 \begin_inset LatexCommand label
10341 name "lyx:--callee-saves-function1[,function2][,function3]..."
10342
10343 \end_inset
10344
10345 function1[,function2][,function3]....
10346
10347 \series default
10348  The compiler by default uses a caller saves convention for register saving
10349  across function calls, however this can cause unnecessary register pushing
10350  and popping when calling small functions from larger functions.
10351  This option can be used to switch the register saving convention for the
10352  function names specified.
10353  The compiler will not save registers when calling these functions, no extra
10354  code will be generated at the entry and exit (function prologue
10355 \series bold
10356
10357 \begin_inset LatexCommand index
10358 name "function prologue"
10359
10360 \end_inset
10361
10362
10363 \series default
10364  and epilogue
10365 \series bold
10366
10367 \begin_inset LatexCommand index
10368 name "function epilogue"
10369
10370 \end_inset
10371
10372
10373 \series default
10374 ) for these functions to save and restore the registers used by these functions,
10375  this can SUBSTANTIALLY reduce code and improve run time performance of
10376  the generated code.
10377  In the future the compiler (with inter procedural analysis) will be able
10378  to determine the appropriate scheme to use for each function call.
10379  DO NOT use this option for built-in functions such as _mulint..., if this
10380  option is used for a library function the appropriate library function
10381  needs to be recompiled with the same option.
10382  If the project consists of multiple source files then all the source file
10383  should be compiled with the same -
10384 \begin_inset ERT
10385 status collapsed
10386
10387 \begin_layout Standard
10388
10389
10390 \backslash
10391 /
10392 \end_layout
10393
10394 \end_inset
10395
10396 -callee-saves option string.
10397  Also see #pragma\InsetSpace ~
10398 callee_saves 
10399 \begin_inset LatexCommand index
10400 name "\\#pragma callee\\_saves"
10401
10402 \end_inset
10403
10404  
10405 \begin_inset LatexCommand vpageref
10406 reference "ite:callee_saves-function1[,function2[,function3...]]--"
10407
10408 \end_inset
10409
10410 .
10411 \end_layout
10412
10413 \begin_layout List
10414 \labelwidthstring 00.00.0000
10415
10416 \series bold
10417 -
10418 \begin_inset ERT
10419 status collapsed
10420
10421 \begin_layout Standard
10422
10423
10424 \backslash
10425 /
10426 \end_layout
10427
10428 \end_inset
10429
10430 -all-callee-saves
10431 \begin_inset LatexCommand index
10432 name "-\\/-all-callee-saves"
10433
10434 \end_inset
10435
10436
10437 \series default
10438  Function of -
10439 \begin_inset ERT
10440 status collapsed
10441
10442 \begin_layout Standard
10443
10444
10445 \backslash
10446 /
10447 \end_layout
10448
10449 \end_inset
10450
10451 -callee-saves will be applied to all functions by default.
10452 \end_layout
10453
10454 \begin_layout List
10455 \labelwidthstring 00.00.0000
10456
10457 \series bold
10458 -
10459 \begin_inset ERT
10460 status collapsed
10461
10462 \begin_layout Standard
10463
10464
10465 \backslash
10466 /
10467 \end_layout
10468
10469 \end_inset
10470
10471 -debug
10472 \begin_inset LatexCommand index
10473 name "-\\/-debug"
10474
10475 \end_inset
10476
10477  
10478 \series default
10479 When this option is used the compiler will generate debug information.
10480  The debug information collected in a file with .cdb extension can be used
10481  with the SDCDB.
10482  For more information see documentation for SDCDB.
10483  Another file with no extension contains debug information in AOMF or AOMF51
10484 \begin_inset LatexCommand index
10485 name "AOMF, AOMF51"
10486
10487 \end_inset
10488
10489  format which is commonly used by third party tools.
10490 \end_layout
10491
10492 \begin_layout List
10493 \labelwidthstring 00.00.0000
10494
10495 \series bold
10496 -S
10497 \begin_inset LatexCommand index
10498 name "-S"
10499
10500 \end_inset
10501
10502
10503 \series default
10504 \size large
10505  
10506 \size default
10507 Stop after the stage of compilation proper; do not assemble.
10508  The output is an assembler code file for the input file specified.
10509 \end_layout
10510
10511 \begin_layout List
10512 \labelwidthstring 00.00.0000
10513
10514 \series bold
10515 -
10516 \begin_inset ERT
10517 status collapsed
10518
10519 \begin_layout Standard
10520
10521
10522 \backslash
10523 /
10524 \end_layout
10525
10526 \end_inset
10527
10528 -int-long-reent
10529 \begin_inset LatexCommand index
10530 name "-\\/-int-long-reent"
10531
10532 \end_inset
10533
10534
10535 \series default
10536  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
10537  Note by default these libraries are compiled as non-reentrant.
10538  See section Installation for more details.
10539 \end_layout
10540
10541 \begin_layout List
10542 \labelwidthstring 00.00.0000
10543
10544 \series bold
10545 -
10546 \begin_inset ERT
10547 status collapsed
10548
10549 \begin_layout Standard
10550
10551
10552 \backslash
10553 /
10554 \end_layout
10555
10556 \end_inset
10557
10558 -cyclomatic
10559 \begin_inset LatexCommand index
10560 name "-\\/-cyclomatic"
10561
10562 \end_inset
10563
10564  
10565 \series default
10566 This option will cause the compiler to generate an information message for
10567  each function in the source file.
10568  The message contains some 
10569 \emph on
10570 important
10571 \emph default
10572  information about the function.
10573  The number of edges and nodes the compiler detected in the control flow
10574  graph of the function, and most importantly the 
10575 \emph on
10576 cyclomatic complexity
10577 \begin_inset LatexCommand index
10578 name "Cyclomatic complexity"
10579
10580 \end_inset
10581
10582
10583 \emph default
10584  see section on Cyclomatic Complexity for more details.
10585 \end_layout
10586
10587 \begin_layout List
10588 \labelwidthstring 00.00.0000
10589
10590 \series bold
10591 -
10592 \begin_inset ERT
10593 status collapsed
10594
10595 \begin_layout Standard
10596
10597
10598 \backslash
10599 /
10600 \end_layout
10601
10602 \end_inset
10603
10604 -float-reent
10605 \begin_inset LatexCommand index
10606 name "-\\/-float-reent"
10607
10608 \end_inset
10609
10610
10611 \series default
10612  Floating point library is compiled as reentrant
10613 \begin_inset LatexCommand index
10614 name "reentrant"
10615
10616 \end_inset
10617
10618 .
10619  See section Installation for more details.
10620 \end_layout
10621
10622 \begin_layout List
10623 \labelwidthstring 00.00.0000
10624
10625 \series bold
10626 -
10627 \begin_inset ERT
10628 status collapsed
10629
10630 \begin_layout Standard
10631
10632
10633 \backslash
10634 /
10635 \end_layout
10636
10637 \end_inset
10638
10639 -funsigned-char
10640 \begin_inset LatexCommand index
10641 name "-\\/-funsigned-char"
10642
10643 \end_inset
10644
10645
10646 \series default
10647  The default signedness for every type is 
10648 \family typewriter
10649 signed
10650 \family default
10651 .
10652  In some embedded environments the default signedness of 
10653 \family typewriter
10654 char
10655 \family default
10656  is 
10657 \family typewriter
10658 unsigned
10659 \family default
10660 .
10661  To set the signess for characters to unsigned, use the option -
10662 \series bold
10663
10664 \begin_inset ERT
10665 status open
10666
10667 \begin_layout Standard
10668
10669
10670 \backslash
10671 /
10672 \end_layout
10673
10674 \end_inset
10675
10676
10677 \series default
10678 -funsigned-char.
10679  If this option is set and no signedness keyword (unsigned/signed) is given,
10680  a char will be signed.
10681  All other types are unaffected.
10682 \end_layout
10683
10684 \begin_layout List
10685 \labelwidthstring 00.00.0000
10686
10687 \series bold
10688 -
10689 \begin_inset ERT
10690 status collapsed
10691
10692 \begin_layout Standard
10693
10694
10695 \backslash
10696 /
10697 \end_layout
10698
10699 \end_inset
10700
10701 -main-return
10702 \begin_inset LatexCommand index
10703 name "-\\/-main-return"
10704
10705 \end_inset
10706
10707
10708 \series default
10709  This option can be used if the code generated is called by a monitor program
10710  or if the main routine includes an endless loop.
10711  This option results in slightly smaller code and saves two bytes of stack
10712  space.
10713  The return from the 'main'
10714 \begin_inset LatexCommand index
10715 name "main return"
10716
10717 \end_inset
10718
10719  function will return to the function calling main.
10720  The default setting is to lock up i.e.
10721  generate a '
10722 \family typewriter
10723 sjmp .
10724 \family default
10725 '.
10726 \end_layout
10727
10728 \begin_layout List
10729 \labelwidthstring 00.00.0000
10730
10731 \series bold
10732 -
10733 \begin_inset ERT
10734 status collapsed
10735
10736 \begin_layout Standard
10737
10738
10739 \backslash
10740 /
10741 \end_layout
10742
10743 \end_inset
10744
10745 -nostdinc
10746 \begin_inset LatexCommand index
10747 name "-\\/-nostdinc"
10748
10749 \end_inset
10750
10751
10752 \series default
10753  This will prevent the compiler from passing on the default include path
10754  to the preprocessor.
10755 \end_layout
10756
10757 \begin_layout List
10758 \labelwidthstring 00.00.0000
10759
10760 \series bold
10761 -
10762 \begin_inset ERT
10763 status collapsed
10764
10765 \begin_layout Standard
10766
10767
10768 \backslash
10769 /
10770 \end_layout
10771
10772 \end_inset
10773
10774 -nostdlib
10775 \begin_inset LatexCommand index
10776 name "-\\/-nostdlib"
10777
10778 \end_inset
10779
10780
10781 \series default
10782  This will prevent the compiler from passing on the default library
10783 \begin_inset LatexCommand index
10784 name "Libraries"
10785
10786 \end_inset
10787
10788  path to the linker.
10789 \end_layout
10790
10791 \begin_layout List
10792 \labelwidthstring 00.00.0000
10793
10794 \series bold
10795 -
10796 \begin_inset ERT
10797 status collapsed
10798
10799 \begin_layout Standard
10800
10801
10802 \backslash
10803 /
10804 \end_layout
10805
10806 \end_inset
10807
10808 -verbose
10809 \begin_inset LatexCommand index
10810 name "-\\/-verbose"
10811
10812 \end_inset
10813
10814
10815 \series default
10816  Shows the various actions the compiler is performing.
10817 \end_layout
10818
10819 \begin_layout List
10820 \labelwidthstring 00.00.0000
10821
10822 \series bold
10823 -V
10824 \begin_inset LatexCommand index
10825 name "-V"
10826
10827 \end_inset
10828
10829
10830 \series default
10831  Shows the actual commands the compiler is executing.
10832 \end_layout
10833
10834 \begin_layout List
10835 \labelwidthstring 00.00.0000
10836
10837 \series bold
10838 -
10839 \begin_inset ERT
10840 status collapsed
10841
10842 \begin_layout Standard
10843
10844
10845 \backslash
10846 /
10847 \end_layout
10848
10849 \end_inset
10850
10851 -no-c-code-in-asm
10852 \begin_inset LatexCommand index
10853 name "-\\/-no-c-code-in-asm"
10854
10855 \end_inset
10856
10857
10858 \series default
10859  Hides your ugly and inefficient c-code from the asm file, so you can always
10860  blame the compiler :)
10861 \end_layout
10862
10863 \begin_layout List
10864 \labelwidthstring 00.00.0000
10865
10866 \series bold
10867 -
10868 \begin_inset ERT
10869 status collapsed
10870
10871 \begin_layout Standard
10872
10873
10874 \backslash
10875 /
10876 \end_layout
10877
10878 \end_inset
10879
10880 -fverbose-asm
10881 \begin_inset LatexCommand index
10882 name "-\\/-no-gen-comments"
10883
10884 \end_inset
10885
10886
10887 \series default
10888  Include code generator and peep-hole comments in the generated asm files.
10889 \end_layout
10890
10891 \begin_layout List
10892 \labelwidthstring 00.00.0000
10893
10894 \series bold
10895 -
10896 \begin_inset ERT
10897 status collapsed
10898
10899 \begin_layout Standard
10900
10901
10902 \backslash
10903 /
10904 \end_layout
10905
10906 \end_inset
10907
10908 -no-peep-comments
10909 \begin_inset LatexCommand index
10910 name "-\\/-no-peep-comments"
10911
10912 \end_inset
10913
10914
10915 \series default
10916  Don't include peep-hole comments in the generated asm files even if -
10917 \series bold
10918
10919 \begin_inset ERT
10920 status open
10921
10922 \begin_layout Standard
10923
10924
10925 \backslash
10926 /
10927 \end_layout
10928
10929 \end_inset
10930
10931
10932 \series default
10933 -fverbose-asm option is specified.
10934 \end_layout
10935
10936 \begin_layout List
10937 \labelwidthstring 00.00.0000
10938
10939 \series bold
10940 -
10941 \begin_inset ERT
10942 status collapsed
10943
10944 \begin_layout Standard
10945
10946
10947 \backslash
10948 /
10949 \end_layout
10950
10951 \end_inset
10952
10953 -i-code-in-asm
10954 \begin_inset LatexCommand index
10955 name "-\\/-i-code-in-asm"
10956
10957 \end_inset
10958
10959
10960 \series default
10961  Include i-codes in the asm file.
10962  Sounds like noise but is most helpful for debugging the compiler itself.
10963 \end_layout
10964
10965 \begin_layout List
10966 \labelwidthstring 00.00.0000
10967
10968 \series bold
10969 -
10970 \begin_inset ERT
10971 status collapsed
10972
10973 \begin_layout Standard
10974
10975
10976 \backslash
10977 /
10978 \end_layout
10979
10980 \end_inset
10981
10982 -less-pedantic
10983 \begin_inset LatexCommand index
10984 name "pedantic"
10985
10986 \end_inset
10987
10988
10989 \begin_inset LatexCommand index
10990 name "-\\/-less-pedantic"
10991
10992 \end_inset
10993
10994
10995 \series default
10996
10997 \begin_inset LatexCommand label
10998 name "lyx:--less-pedantic"
10999
11000 \end_inset
11001
11002  Disable some of the more pedantic warnings
11003 \begin_inset LatexCommand index
11004 name "Warnings"
11005
11006 \end_inset
11007
11008 .
11009  For more details, see the less_pedantic pragma 
11010 \begin_inset LatexCommand vpageref
11011 reference "ite:less_pedantic"
11012
11013 \end_inset
11014
11015 .
11016 \end_layout
11017
11018 \begin_layout List
11019 \labelwidthstring 00.00.0000
11020
11021 \series bold
11022 -
11023 \begin_inset ERT
11024 status collapsed
11025
11026 \begin_layout Standard
11027
11028
11029 \backslash
11030 /
11031 \end_layout
11032
11033 \end_inset
11034
11035 -disable-warning\InsetSpace ~
11036 <nnnn>
11037 \begin_inset LatexCommand index
11038 name "-\\/-disable-warning"
11039
11040 \end_inset
11041
11042
11043 \series default
11044  Disable specific warning with number <nnnn>.
11045 \end_layout
11046
11047 \begin_layout List
11048 \labelwidthstring 00.00.0000
11049
11050 \series bold
11051 -
11052 \begin_inset ERT
11053 status collapsed
11054
11055 \begin_layout Standard
11056
11057
11058 \backslash
11059 /
11060 \end_layout
11061
11062 \end_inset
11063
11064 -Werror
11065 \begin_inset LatexCommand index
11066 name "-\\/-Werror"
11067
11068 \end_inset
11069
11070
11071 \series default
11072  Treat all warnings as errors.
11073 \end_layout
11074
11075 \begin_layout List
11076 \labelwidthstring 00.00.0000
11077
11078 \series bold
11079 -
11080 \begin_inset ERT
11081 status collapsed
11082
11083 \begin_layout Standard
11084
11085
11086 \backslash
11087 /
11088 \end_layout
11089
11090 \end_inset
11091
11092 -print-search-dirs
11093 \begin_inset LatexCommand index
11094 name "-\\/-print-search-dirs"
11095
11096 \end_inset
11097
11098
11099 \series default
11100  Display the directories in the compiler's search path
11101 \end_layout
11102
11103 \begin_layout List
11104 \labelwidthstring 00.00.0000
11105
11106 \series bold
11107 -
11108 \begin_inset ERT
11109 status collapsed
11110
11111 \begin_layout Standard
11112
11113
11114 \backslash
11115 /
11116 \end_layout
11117
11118 \end_inset
11119
11120 -vc
11121 \begin_inset LatexCommand index
11122 name "-\\/-vc"
11123
11124 \end_inset
11125
11126
11127 \series default
11128  Display errors and warnings using MSVC style, so you can use SDCC with
11129  the visual studio IDE
11130 \begin_inset LatexCommand index
11131 name "IDE"
11132
11133 \end_inset
11134
11135 .
11136  With SDCC both offering a GCC-like (the default) and a MSVC-like
11137 \begin_inset LatexCommand index
11138 name "MSVC output style"
11139
11140 \end_inset
11141
11142  output style, integration into most programming editors should be straightforwa
11143 rd.
11144 \end_layout
11145
11146 \begin_layout List
11147 \labelwidthstring 00.00.0000
11148
11149 \series bold
11150 -
11151 \begin_inset ERT
11152 status collapsed
11153
11154 \begin_layout Standard
11155
11156
11157 \backslash
11158 /
11159 \end_layout
11160
11161 \end_inset
11162
11163 -use-stdout
11164 \begin_inset LatexCommand index
11165 name "-\\/-use-stdout"
11166
11167 \end_inset
11168
11169
11170 \series default
11171  Send errors and warnings to stdout instead of stderr.
11172 \end_layout
11173
11174 \begin_layout List
11175 \labelwidthstring 00.00.0000
11176
11177 \series bold
11178 -Wa\InsetSpace ~
11179 asmOption[,asmOption]
11180 \series default
11181
11182 \begin_inset LatexCommand index
11183 name "-Wa asmOption[,asmOption]"
11184
11185 \end_inset
11186
11187 ...
11188  Pass the asmOption to the assembler
11189 \begin_inset LatexCommand index
11190 name "Options assembler"
11191
11192 \end_inset
11193
11194
11195 \begin_inset LatexCommand index
11196 name "Assembler options"
11197
11198 \end_inset
11199
11200 .
11201  See file sdcc/as/doc/asxhtm.html for assembler options.cd
11202 \end_layout
11203
11204 \begin_layout List
11205 \labelwidthstring 00.00.0000
11206
11207 \series bold
11208 -
11209 \begin_inset ERT
11210 status collapsed
11211
11212 \begin_layout Standard
11213
11214
11215 \backslash
11216 /
11217 \end_layout
11218
11219 \end_inset
11220
11221 -std-sdcc89
11222 \begin_inset LatexCommand index
11223 name "-\\/-std-sdcc89"
11224
11225 \end_inset
11226
11227
11228 \series default
11229  Generally follow the C89 standard, but allow SDCC features that conflict
11230  with the standard (default).
11231 \end_layout
11232
11233 \begin_layout List
11234 \labelwidthstring 00.00.0000
11235
11236 \series bold
11237 -
11238 \begin_inset ERT
11239 status collapsed
11240
11241 \begin_layout Standard
11242
11243
11244 \backslash
11245 /
11246 \end_layout
11247
11248 \end_inset
11249
11250 -std-c89
11251 \begin_inset LatexCommand index
11252 name "-\\/-std-c89"
11253
11254 \end_inset
11255
11256
11257 \series default
11258  Follow the C89 standard and disable SDCC features that conflict with the
11259  standard.
11260 \end_layout
11261
11262 \begin_layout List
11263 \labelwidthstring 00.00.0000
11264
11265 \series bold
11266 -
11267 \begin_inset ERT
11268 status collapsed
11269
11270 \begin_layout Standard
11271
11272
11273 \backslash
11274 /
11275 \end_layout
11276
11277 \end_inset
11278
11279 -std-sdcc99
11280 \begin_inset LatexCommand index
11281 name "-\\/-std-sdcc99"
11282
11283 \end_inset
11284
11285
11286 \series default
11287  Generally follow the C99 standard, but allow SDCC features that conflict
11288  with the standard (incomplete support).
11289 \end_layout
11290
11291 \begin_layout List
11292 \labelwidthstring 00.00.0000
11293
11294 \series bold
11295 -
11296 \begin_inset ERT
11297 status collapsed
11298
11299 \begin_layout Standard
11300
11301
11302 \backslash
11303 /
11304 \end_layout
11305
11306 \end_inset
11307
11308 -std-c99
11309 \begin_inset LatexCommand index
11310 name "-\\/-std-sdcc99"
11311
11312 \end_inset
11313
11314
11315 \series default
11316  Follow the C99 standard and disable SDCC features that conflict with the
11317  standard (incomplete support).
11318 \end_layout
11319
11320 \begin_layout List
11321 \labelwidthstring 00.00.0000
11322
11323 \series bold
11324 -
11325 \begin_inset ERT
11326 status collapsed
11327
11328 \begin_layout Standard
11329
11330
11331 \backslash
11332 /
11333 \end_layout
11334
11335 \end_inset
11336
11337 -codeseg
11338 \series default
11339
11340 \begin_inset LatexCommand index
11341 name "-\\/-codeseg <Value>"
11342
11343 \end_inset
11344
11345
11346 \begin_inset LatexCommand label
11347 name "lyx:-codeseg"
11348
11349 \end_inset
11350
11351 \InsetSpace ~
11352 <Name> The name to be used for the code
11353 \begin_inset LatexCommand index
11354 name "code"
11355
11356 \end_inset
11357
11358  segment, default CSEG.
11359  This is useful if you need to tell the compiler to put the code in a special
11360  segment so you can later on tell the linker to put this segment in a special
11361  place in memory.
11362  Can be used for instance when using bank switching to put the code in a
11363  bank.
11364 \end_layout
11365
11366 \begin_layout List
11367 \labelwidthstring 00.00.0000
11368
11369 \series bold
11370 -
11371 \begin_inset ERT
11372 status collapsed
11373
11374 \begin_layout Standard
11375
11376
11377 \backslash
11378 /
11379 \end_layout
11380
11381 \end_inset
11382
11383 -constseg
11384 \series default
11385
11386 \begin_inset LatexCommand index
11387 name "-\\/-constseg <Value>"
11388
11389 \end_inset
11390
11391 \InsetSpace ~
11392 <Name> The name to be used for the const
11393 \begin_inset LatexCommand index
11394 name "const"
11395
11396 \end_inset
11397
11398  segment, default CONST.
11399  This is useful if you need to tell the compiler to put the const data in
11400  a special segment so you can later on tell the linker to put this segment
11401  in a special place in memory.
11402  Can be used for instance when using bank switching to put the const data
11403  in a bank.
11404 \end_layout
11405
11406 \begin_layout List
11407 \labelwidthstring 00.00.0000
11408
11409 \series bold
11410 -
11411 \begin_inset ERT
11412 status collapsed
11413
11414 \begin_layout Standard
11415
11416
11417 \backslash
11418 /
11419 \end_layout
11420
11421 \end_inset
11422
11423 -fdollars-in-identifiers
11424 \begin_inset LatexCommand index
11425 name "-\\/-fdollars-in-identifiers"
11426
11427 \end_inset
11428
11429
11430 \series default
11431  Permit '$' as an identifier character.
11432 \end_layout
11433
11434 \begin_layout List
11435 \labelwidthstring 00.00.0000
11436
11437 \series bold
11438 -
11439 \begin_inset ERT
11440 status collapsed
11441
11442 \begin_layout Standard
11443
11444
11445 \backslash
11446 /
11447 \end_layout
11448
11449 \end_inset
11450
11451 -more-pedantic
11452 \series default
11453
11454 \begin_inset LatexCommand index
11455 name "-\\/-more-pedantic"
11456
11457 \end_inset
11458
11459
11460 \begin_inset LatexCommand index
11461 name "pedantic"
11462
11463 \end_inset
11464
11465  Actually this is 
11466 \series bold
11467 \emph on
11468 not
11469 \series default
11470 \emph default
11471  a SDCC compiler option but if you want 
11472 \emph on
11473 more
11474 \emph default
11475  warnings you can use a separate tool dedicated to syntax checking like
11476  splint
11477 \begin_inset LatexCommand label
11478 name "lyx:more-pedantic-SPLINT"
11479
11480 \end_inset
11481
11482
11483 \begin_inset LatexCommand index
11484 name "lint (syntax checking tool)"
11485
11486 \end_inset
11487
11488  
11489 \begin_inset LatexCommand url
11490 target "http://www.splint.org"
11491
11492 \end_inset
11493
11494 .
11495  To make your source files parseable by splint you will have to include
11496  
11497 \family sans
11498 lint.h
11499 \family default
11500
11501 \begin_inset LatexCommand index
11502 name "splint (syntax checking tool)"
11503
11504 \end_inset
11505
11506  in your source file and add brackets around extended keywords (like 
11507 \family sans
11508
11509 \begin_inset Quotes sld
11510 \end_inset
11511
11512 __at\InsetSpace ~
11513
11514 \series bold
11515 (
11516 \series default
11517 0xab
11518 \series bold
11519 )
11520 \series default
11521
11522 \begin_inset Quotes srd
11523 \end_inset
11524
11525
11526 \family default
11527  and 
11528 \family sans
11529
11530 \begin_inset Quotes sld
11531 \end_inset
11532
11533 __interrupt\InsetSpace ~
11534 (2)
11535 \begin_inset Quotes srd
11536 \end_inset
11537
11538
11539 \family default
11540 ).
11541  
11542 \newline
11543 Splint has an excellent on line manual at 
11544 \begin_inset LatexCommand url
11545 target "http://www.splint.org/manual/"
11546
11547 \end_inset
11548
11549  and it's capabilities go beyond pure syntax checking.
11550  You'll need to tell splint the location of SDCC's include files so a typical
11551  command line could look like this: 
11552 \newline
11553
11554 \family sans
11555 splint\InsetSpace ~
11556 -I\InsetSpace ~
11557 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
11558 \InsetSpace ~
11559 myprogram.c
11560 \end_layout
11561
11562 \begin_layout List
11563 \labelwidthstring 00.00.0000
11564
11565 \series bold
11566 -
11567 \begin_inset ERT
11568 status collapsed
11569
11570 \begin_layout Standard
11571
11572
11573 \backslash
11574 /
11575 \end_layout
11576
11577 \end_inset
11578
11579 -short-is-8bits
11580 \series default
11581
11582 \begin_inset LatexCommand index
11583 name "-\\/-short-is-8bits"
11584
11585 \end_inset
11586
11587
11588 \begin_inset LatexCommand label
11589 name "lyx:--short-is-8bits"
11590
11591 \end_inset
11592
11593  Treat short as 8-bit (for backward compatibility with older versions of
11594  compiler - see section 
11595 \begin_inset LatexCommand ref
11596 reference "sec:Compatibility-with-previous"
11597
11598 \end_inset
11599
11600 )
11601 \end_layout
11602
11603 \begin_layout Standard
11604 \begin_inset VSpace bigskip
11605 \end_inset
11606
11607
11608 \end_layout
11609
11610 \begin_layout Subsection
11611 Intermediate Dump Options
11612 \begin_inset LatexCommand label
11613 name "sub:Intermediate-Dump-Options"
11614
11615 \end_inset
11616
11617
11618 \begin_inset LatexCommand index
11619 name "Options intermediate dump"
11620
11621 \end_inset
11622
11623
11624 \begin_inset LatexCommand index
11625 name "Intermediate dump options"
11626
11627 \end_inset
11628
11629
11630 \end_layout
11631
11632 \begin_layout Standard
11633 The following options are provided for the purpose of retargetting and debugging
11634  the compiler.
11635  They provide a means to dump the intermediate code (iCode
11636 \begin_inset LatexCommand index
11637 name "iCode"
11638
11639 \end_inset
11640
11641 ) generated by the compiler in human readable form at various stages of
11642  the compilation process.
11643  More on iCodes see chapter 
11644 \begin_inset LatexCommand ref
11645 reference "sub:The-anatomy-of"
11646
11647 \end_inset
11648
11649  
11650 \begin_inset Quotes srd
11651 \end_inset
11652
11653 The anatomy of the compiler
11654 \begin_inset Quotes srd
11655 \end_inset
11656
11657 .
11658 \end_layout
11659
11660 \begin_layout List
11661 \labelwidthstring 00.00.0000
11662
11663 \series bold
11664 -
11665 \begin_inset ERT
11666 status collapsed
11667
11668 \begin_layout Standard
11669
11670
11671 \backslash
11672 /
11673 \end_layout
11674
11675 \end_inset
11676
11677 -dumpraw
11678 \begin_inset LatexCommand index
11679 name "-\\/-dumpraw"
11680
11681 \end_inset
11682
11683
11684 \series default
11685  This option will cause the compiler to dump the intermediate code into
11686  a file of named 
11687 \emph on
11688 <source filename>.dumpraw
11689 \emph default
11690  just after the intermediate code has been generated for a function, i.e.
11691  before any optimizations are done.
11692  The basic blocks
11693 \begin_inset LatexCommand index
11694 name "Basic blocks"
11695
11696 \end_inset
11697
11698  at this stage ordered in the depth first number, so they may not be in
11699  sequence of execution.
11700 \end_layout
11701
11702 \begin_layout List
11703 \labelwidthstring 00.00.0000
11704
11705 \series bold
11706 -
11707 \begin_inset ERT
11708 status collapsed
11709
11710 \begin_layout Standard
11711
11712
11713 \backslash
11714 /
11715 \end_layout
11716
11717 \end_inset
11718
11719 -dumpgcse
11720 \begin_inset LatexCommand index
11721 name "-\\/-dumpgcse"
11722
11723 \end_inset
11724
11725
11726 \series default
11727  Will create a dump of iCodes, after global subexpression elimination
11728 \begin_inset LatexCommand index
11729 name "Global subexpression elimination"
11730
11731 \end_inset
11732
11733 , into a file named 
11734 \emph on
11735 <source filename>.dumpgcse.
11736 \end_layout
11737
11738 \begin_layout List
11739 \labelwidthstring 00.00.0000
11740
11741 \series bold
11742 -
11743 \begin_inset ERT
11744 status collapsed
11745
11746 \begin_layout Standard
11747
11748
11749 \backslash
11750 /
11751 \end_layout
11752
11753 \end_inset
11754
11755 -dumpdeadcode
11756 \begin_inset LatexCommand index
11757 name "-\\/-dumpdeadcode"
11758
11759 \end_inset
11760
11761
11762 \series default
11763  Will create a dump of iCodes, after deadcode elimination
11764 \begin_inset LatexCommand index
11765 name "Dead-code elimination"
11766
11767 \end_inset
11768
11769 , into a file named 
11770 \emph on
11771 <source filename>.dumpdeadcode.
11772 \end_layout
11773
11774 \begin_layout List
11775 \labelwidthstring 00.00.0000
11776
11777 \series bold
11778 -
11779 \begin_inset ERT
11780 status collapsed
11781
11782 \begin_layout Standard
11783
11784
11785 \backslash
11786 /
11787 \end_layout
11788
11789 \end_inset
11790
11791 -dumploop
11792 \begin_inset LatexCommand index
11793 name "-\\/-dumploop"
11794
11795 \end_inset
11796
11797
11798 \series default
11799 \size large
11800  
11801 \size default
11802 Will create a dump of iCodes, after loop optimizations
11803 \begin_inset LatexCommand index
11804 name "Loop optimization"
11805
11806 \end_inset
11807
11808 , into a file named 
11809 \emph on
11810 <source filename>.dumploop.
11811 \end_layout
11812
11813 \begin_layout List
11814 \labelwidthstring 00.00.0000
11815
11816 \series bold
11817 -
11818 \begin_inset ERT
11819 status collapsed
11820
11821 \begin_layout Standard
11822
11823
11824 \backslash
11825 /
11826 \end_layout
11827
11828 \end_inset
11829
11830 -dumprange
11831 \begin_inset LatexCommand index
11832 name "-\\/-dumprange"
11833
11834 \end_inset
11835
11836
11837 \series default
11838 \size large
11839  
11840 \size default
11841 Will create a dump of iCodes, after live range analysis
11842 \begin_inset LatexCommand index
11843 name "Live range analysis"
11844
11845 \end_inset
11846
11847 , into a file named 
11848 \emph on
11849 <source filename>.dumprange.
11850 \end_layout
11851
11852 \begin_layout List
11853 \labelwidthstring 00.00.0000
11854
11855 \series bold
11856 -
11857 \begin_inset ERT
11858 status collapsed
11859
11860 \begin_layout Standard
11861
11862
11863 \backslash
11864 /
11865 \end_layout
11866
11867 \end_inset
11868
11869 -dumlrange
11870 \begin_inset LatexCommand index
11871 name "-\\/-dumlrange"
11872
11873 \end_inset
11874
11875
11876 \series default
11877  Will dump the life ranges
11878 \begin_inset LatexCommand index
11879 name "Live range analysis"
11880
11881 \end_inset
11882
11883  for all symbols.
11884 \end_layout
11885
11886 \begin_layout List
11887 \labelwidthstring 00.00.0000
11888
11889 \series bold
11890 -
11891 \begin_inset ERT
11892 status collapsed
11893
11894 \begin_layout Standard
11895
11896
11897 \backslash
11898 /
11899 \end_layout
11900
11901 \end_inset
11902
11903 -dumpregassign
11904 \begin_inset LatexCommand index
11905 name "-\\/-dumpregassign"
11906
11907 \end_inset
11908
11909  
11910 \series default
11911 Will create a dump of iCodes, after register assignment
11912 \begin_inset LatexCommand index
11913 name "Register assignment"
11914
11915 \end_inset
11916
11917 , into a file named 
11918 \emph on
11919 <source filename>.dumprassgn.
11920 \end_layout
11921
11922 \begin_layout List
11923 \labelwidthstring 00.00.0000
11924
11925 \series bold
11926 -
11927 \begin_inset ERT
11928 status collapsed
11929
11930 \begin_layout Standard
11931
11932
11933 \backslash
11934 /
11935 \end_layout
11936
11937 \end_inset
11938
11939 -dumplrange
11940 \begin_inset LatexCommand index
11941 name "-\\/-dumplrange"
11942
11943 \end_inset
11944
11945
11946 \series default
11947  Will create a dump of the live ranges of iTemp's
11948 \end_layout
11949
11950 \begin_layout List
11951 \labelwidthstring 00.00.0000
11952
11953 \series bold
11954 -
11955 \begin_inset ERT
11956 status collapsed
11957
11958 \begin_layout Standard
11959
11960
11961 \backslash
11962 /
11963 \end_layout
11964
11965 \end_inset
11966
11967 -dumpall
11968 \begin_inset LatexCommand index
11969 name "-\\/-dumpall"
11970
11971 \end_inset
11972
11973
11974 \size large
11975  
11976 \series default
11977 \size default
11978 Will cause all the above mentioned dumps to be created.
11979 \end_layout
11980
11981 \begin_layout Standard
11982 \begin_inset VSpace bigskip
11983 \end_inset
11984
11985
11986 \end_layout
11987
11988 \begin_layout Subsection
11989 Redirecting output on Windows Shells
11990 \end_layout
11991
11992 \begin_layout Standard
11993 By default SDCC writes its error messages to 
11994 \begin_inset Quotes sld
11995 \end_inset
11996
11997 standard error
11998 \begin_inset Quotes srd
11999 \end_inset
12000
12001 .
12002  To force all messages to 
12003 \begin_inset Quotes sld
12004 \end_inset
12005
12006 standard output
12007 \begin_inset Quotes srd
12008 \end_inset
12009
12010  use 
12011 \series bold
12012 -
12013 \series default
12014 \emph on
12015
12016 \begin_inset ERT
12017 status collapsed
12018
12019 \begin_layout Standard
12020
12021
12022 \backslash
12023 /
12024 \end_layout
12025
12026 \end_inset
12027
12028
12029 \series bold
12030 \emph default
12031 -
12032 \series default
12033 use-stdout
12034 \begin_inset LatexCommand index
12035 name "-\\/-use-stdout"
12036
12037 \end_inset
12038
12039 .
12040  Additionally, if you happen to have visual studio installed in your windows
12041  machine, you can use it to compile your sources using a custom build and
12042  the SDCC -
12043 \emph on
12044
12045 \begin_inset ERT
12046 status collapsed
12047
12048 \begin_layout Standard
12049
12050
12051 \backslash
12052 /
12053 \end_layout
12054
12055 \end_inset
12056
12057
12058 \emph default
12059 -vc
12060 \begin_inset LatexCommand index
12061 name "-\\/-vc"
12062
12063 \end_inset
12064
12065  option.
12066  Something like this should work:
12067 \newline
12068
12069 \newline
12070
12071 \series bold
12072 c:
12073 \backslash
12074 sdcc
12075 \backslash
12076 bin
12077 \backslash
12078 sdcc.exe -
12079 \series default
12080 \emph on
12081
12082 \begin_inset ERT
12083 status collapsed
12084
12085 \begin_layout Standard
12086
12087
12088 \backslash
12089 /
12090 \end_layout
12091
12092 \end_inset
12093
12094
12095 \series bold
12096 \emph default
12097 -vc -
12098 \series default
12099 \emph on
12100
12101 \begin_inset ERT
12102 status collapsed
12103
12104 \begin_layout Standard
12105
12106
12107 \backslash
12108 /
12109 \end_layout
12110
12111 \end_inset
12112
12113
12114 \series bold
12115 \emph default
12116 -model-large -c $(InputPath)
12117 \series default
12118
12119 \begin_inset VSpace bigskip
12120 \end_inset
12121
12122
12123 \end_layout
12124
12125 \begin_layout Section
12126 Environment variables
12127 \begin_inset LatexCommand index
12128 name "Environment variables"
12129
12130 \end_inset
12131
12132
12133 \end_layout
12134
12135 \begin_layout Standard
12136 SDCC recognizes the following environment variables:
12137 \end_layout
12138
12139 \begin_layout List
12140 \labelwidthstring 00.00.0000
12141
12142 \series bold
12143 SDCC_LEAVE_SIGNALS
12144 \begin_inset LatexCommand index
12145 name "SDCC\\_LEAVE\\_SIGNALS"
12146
12147 \end_inset
12148
12149
12150 \series default
12151  SDCC installs a signal handler
12152 \begin_inset LatexCommand index
12153 name "signal handler"
12154
12155 \end_inset
12156
12157  to be able to delete temporary files after an user break (^C) or an exception.
12158  If this environment variable is set, SDCC won't install the signal handler
12159  in order to be able to debug SDCC.
12160 \end_layout
12161
12162 \begin_layout List
12163 \labelwidthstring 00.00.0000
12164
12165 \series bold
12166 TMP,\InsetSpace ~
12167 TEMP,\InsetSpace ~
12168 TMPDIR
12169 \begin_inset LatexCommand index
12170 name "TMP, TEMP, TMPDIR"
12171
12172 \end_inset
12173
12174
12175 \series default
12176  Path, where temporary files will be created.
12177  The order of the variables is the search order.
12178  In a standard *nix environment these variables are not set, and there's
12179  no need to set them.
12180  On Windows it's recommended to set one of them.
12181 \end_layout
12182
12183 \begin_layout List
12184 \labelwidthstring 00.00.0000
12185
12186 \series bold
12187 SDCC_HOME
12188 \begin_inset LatexCommand index
12189 name "SDCC\\_HOME"
12190
12191 \end_inset
12192
12193
12194 \series default
12195  Path, see section 
12196 \begin_inset LatexCommand ref
12197 reference "sub:Install-paths"
12198
12199 \end_inset
12200
12201 \InsetSpace ~
12202
12203 \begin_inset Quotes sld
12204 \end_inset
12205
12206  Install Paths
12207 \begin_inset Quotes srd
12208 \end_inset
12209
12210 .
12211 \end_layout
12212
12213 \begin_layout List
12214 \labelwidthstring 00.00.0000
12215
12216 \series bold
12217 SDCC_INCLUDE
12218 \begin_inset LatexCommand index
12219 name "SDCC\\_INCLUDE"
12220
12221 \end_inset
12222
12223
12224 \series default
12225  Path, see section 
12226 \begin_inset LatexCommand ref
12227 reference "sub:Search-Paths"
12228
12229 \end_inset
12230
12231 \InsetSpace ~
12232
12233 \begin_inset Quotes sld
12234 \end_inset
12235
12236 Search Paths
12237 \begin_inset Quotes srd
12238 \end_inset
12239
12240 .
12241 \end_layout
12242
12243 \begin_layout List
12244 \labelwidthstring 00.00.0000
12245
12246 \series bold
12247 SDCC_LIB
12248 \begin_inset LatexCommand index
12249 name "SDCC\\_LIB"
12250
12251 \end_inset
12252
12253
12254 \series default
12255  Path, see section 
12256 \begin_inset LatexCommand ref
12257 reference "sub:Search-Paths"
12258
12259 \end_inset
12260
12261 \InsetSpace ~
12262
12263 \begin_inset Quotes sld
12264 \end_inset
12265
12266 Search Paths
12267 \begin_inset Quotes srd
12268 \end_inset
12269
12270 ..
12271 \end_layout
12272
12273 \begin_layout Standard
12274 There are some more environment variables recognized by SDCC, but these
12275  are solely used for debugging purposes.
12276  They can change or disappear very quickly, and will never be documented.
12277 \begin_inset VSpace bigskip
12278 \end_inset
12279
12280
12281 \end_layout
12282
12283 \begin_layout Section
12284 Storage Class Language Extensions
12285 \end_layout
12286
12287 \begin_layout Subsection
12288 MCS51/DS390 Storage Class
12289 \begin_inset LatexCommand index
12290 name "Storage class"
12291
12292 \end_inset
12293
12294  Language Extensions
12295 \end_layout
12296
12297 \begin_layout Standard
12298 In addition to the ANSI storage classes SDCC allows the following MCS51
12299  specific storage classes:
12300 \end_layout
12301
12302 \begin_layout Subsubsection
12303 data
12304 \begin_inset LatexCommand index
12305 name "data (mcs51, ds390 storage class)"
12306
12307 \end_inset
12308
12309
12310 \begin_inset LatexCommand index
12311 name "\\_\\_data (mcs51, ds390 storage class)"
12312
12313 \end_inset
12314
12315  / near
12316 \begin_inset LatexCommand index
12317 name "near (storage class)"
12318
12319 \end_inset
12320
12321
12322 \begin_inset LatexCommand index
12323 name "\\_\\_near (storage class)"
12324
12325 \end_inset
12326
12327
12328 \end_layout
12329
12330 \begin_layout Standard
12331 This is the 
12332 \series bold
12333 default
12334 \series default
12335  storage class for the Small Memory model (
12336 \emph on
12337 data
12338 \emph default
12339  and 
12340 \emph on
12341 near
12342 \emph default
12343  or the more ANSI-C compliant forms 
12344 \emph on
12345 __data
12346 \emph default
12347  and 
12348 \emph on
12349 __near
12350 \emph default
12351  can be used synonymously).
12352  Variables declared with this storage class will be allocated in the directly
12353  addressable portion of the internal RAM of a 8051, e.g.:
12354 \end_layout
12355
12356 \begin_layout Verse
12357
12358 \family typewriter
12359 __data unsigned char test_data;
12360 \end_layout
12361
12362 \begin_layout Standard
12363 Writing 0x01 to this variable generates the assembly code:
12364 \end_layout
12365
12366 \begin_layout Verse
12367
12368 \family typewriter
12369 75*00 01\InsetSpace ~
12370 \InsetSpace ~
12371 \InsetSpace ~
12372 mov\InsetSpace ~
12373 \InsetSpace ~
12374 _test_data,#0x01
12375 \end_layout
12376
12377 \begin_layout Subsubsection
12378 xdata
12379 \begin_inset LatexCommand index
12380 name "xdata (mcs51, ds390 storage class)"
12381
12382 \end_inset
12383
12384
12385 \begin_inset LatexCommand index
12386 name "\\_\\_xdata (mcs51, ds390 storage class)"
12387
12388 \end_inset
12389
12390  / far
12391 \begin_inset LatexCommand index
12392 name "far (storage class)"
12393
12394 \end_inset
12395
12396
12397 \begin_inset LatexCommand index
12398 name "\\_\\_far (storage class)"
12399
12400 \end_inset
12401
12402
12403 \end_layout
12404
12405 \begin_layout Standard
12406 Variables declared with this storage class will be placed in the external
12407  RAM.
12408  This is the 
12409 \series bold
12410 default
12411 \series default
12412  storage class for the Large Memory model, e.g.:
12413 \end_layout
12414
12415 \begin_layout Verse
12416
12417 \family typewriter
12418 __xdata unsigned char test_xdata;
12419 \end_layout
12420
12421 \begin_layout Standard
12422 Writing 0x01 to this variable generates the assembly code:
12423 \end_layout
12424
12425 \begin_layout Verse
12426
12427 \family typewriter
12428 90s00r00\InsetSpace ~
12429 \InsetSpace ~
12430 \InsetSpace ~
12431 mov\InsetSpace ~
12432 \InsetSpace ~
12433 dptr,#_test_xdata 
12434 \newline
12435 74\InsetSpace ~
12436 01\InsetSpace ~
12437 \InsetSpace ~
12438 \InsetSpace ~
12439 \InsetSpace ~
12440 \InsetSpace ~
12441 \InsetSpace ~
12442 mov\InsetSpace ~
12443 \InsetSpace ~
12444 a,#0x01 
12445 \newline
12446 F0\InsetSpace ~
12447 \InsetSpace ~
12448 \InsetSpace ~
12449 \InsetSpace ~
12450 \InsetSpace ~
12451 \InsetSpace ~
12452 \InsetSpace ~
12453 \InsetSpace ~
12454 \InsetSpace ~
12455 movx\InsetSpace ~
12456 @dptr,a 
12457 \end_layout
12458
12459 \begin_layout Subsubsection
12460 idata
12461 \begin_inset LatexCommand index
12462 name "idata (mcs51, ds390 storage class)"
12463
12464 \end_inset
12465
12466
12467 \begin_inset LatexCommand index
12468 name "\\_\\_idata (mcs51, ds390 storage class)"
12469
12470 \end_inset
12471
12472
12473 \end_layout
12474
12475 \begin_layout Standard
12476 Variables declared with this storage class will be allocated into the indirectly
12477  addressable portion of the internal ram of a 8051, e.g.:
12478 \end_layout
12479
12480 \begin_layout Verse
12481
12482 \family typewriter
12483 __idata unsigned char test_idata;
12484 \end_layout
12485
12486 \begin_layout Standard
12487 Writing 0x01 to this variable generates the assembly code:
12488 \end_layout
12489
12490 \begin_layout Verse
12491
12492 \family typewriter
12493 78r00\InsetSpace ~
12494 \InsetSpace ~
12495 \InsetSpace ~
12496 \InsetSpace ~
12497 \InsetSpace ~
12498 \InsetSpace ~
12499 \InsetSpace ~
12500 mov\InsetSpace ~
12501 \InsetSpace ~
12502 r0,#_test_idata
12503 \newline
12504 76\InsetSpace ~
12505 01\InsetSpace ~
12506 \InsetSpace ~
12507 \InsetSpace ~
12508 \InsetSpace ~
12509 \InsetSpace ~
12510 \InsetSpace ~
12511 \InsetSpace ~
12512 mov\InsetSpace ~
12513 \InsetSpace ~
12514 @r0,#0x01
12515 \end_layout
12516
12517 \begin_layout Standard
12518 Please note, the first 128 byte of idata physically access the same RAM
12519  as the data memory.
12520  The original 8051 had 128 byte idata memory, nowadays most devices have
12521  256 byte idata memory.
12522  The stack
12523 \begin_inset LatexCommand index
12524 name "stack"
12525
12526 \end_inset
12527
12528  is located in idata memory.
12529 \end_layout
12530
12531 \begin_layout Subsubsection
12532 pdata
12533 \begin_inset LatexCommand index
12534 name "pdata (mcs51, ds390 storage class)"
12535
12536 \end_inset
12537
12538
12539 \begin_inset LatexCommand index
12540 name "\\_\\_pdata (mcs51, ds390 storage class)"
12541
12542 \end_inset
12543
12544
12545 \end_layout
12546
12547 \begin_layout Standard
12548 Paged xdata access is just as straightforward as using the other addressing
12549  modes of a 8051.
12550  It is typically located at the start of xdata and has a maximum size of
12551  256 bytes.
12552  The following example writes 0x01 to the pdata variable.
12553  Please note, pdata access physically accesses xdata memory.
12554  The high byte of the address is determined by port P2 
12555 \begin_inset LatexCommand index
12556 name "P2 (mcs51 sfr)"
12557
12558 \end_inset
12559
12560 (or in case of some 8051 variants by a separate Special Function Register,
12561  see section 
12562 \begin_inset LatexCommand ref
12563 reference "sub:MCS51-variants"
12564
12565 \end_inset
12566
12567 ).
12568  This is the 
12569 \series bold
12570 default
12571 \series default
12572  storage class for the Medium Memory model, e.g.:
12573 \end_layout
12574
12575 \begin_layout Verse
12576
12577 \family typewriter
12578 __pdata unsigned char test_pdata;
12579 \end_layout
12580
12581 \begin_layout Standard
12582 Writing 0x01 to this variable generates the assembly code:
12583 \end_layout
12584
12585 \begin_layout Verse
12586
12587 \family typewriter
12588 78r00\InsetSpace ~
12589 \InsetSpace ~
12590 \InsetSpace ~
12591 \InsetSpace ~
12592 \InsetSpace ~
12593 \InsetSpace ~
12594 mov r0,#_test_pdata
12595 \newline
12596 74 01\InsetSpace ~
12597 \InsetSpace ~
12598 \InsetSpace ~
12599 \InsetSpace ~
12600 \InsetSpace ~
12601 \InsetSpace ~
12602 mov a,#0x01 
12603 \newline
12604 F2\InsetSpace ~
12605 \InsetSpace ~
12606 \InsetSpace ~
12607 \InsetSpace ~
12608 \InsetSpace ~
12609 \InsetSpace ~
12610 \InsetSpace ~
12611 \InsetSpace ~
12612 \InsetSpace ~
12613 movx @r0,a
12614 \end_layout
12615
12616 \begin_layout Standard
12617 If the -
12618 \begin_inset ERT
12619 status collapsed
12620
12621 \begin_layout Standard
12622
12623
12624 \backslash
12625 /
12626 \end_layout
12627
12628 \end_inset
12629
12630 -xstack
12631 \begin_inset LatexCommand index
12632 name "-\\/-xstack"
12633
12634 \end_inset
12635
12636  option is used the pdata memory area is followed by the xstack memory area
12637  and the sum of their sizes is limited to 256 bytes.
12638 \end_layout
12639
12640 \begin_layout Subsubsection
12641 code
12642 \begin_inset LatexCommand index
12643 name "code"
12644
12645 \end_inset
12646
12647
12648 \begin_inset LatexCommand index
12649 name "\\_\\_code"
12650
12651 \end_inset
12652
12653
12654 \end_layout
12655
12656 \begin_layout Standard
12657 'Variables' declared with this storage class will be placed in the code
12658  memory:
12659 \end_layout
12660
12661 \begin_layout Verse
12662
12663 \family typewriter
12664 __code unsigned char test_code;
12665 \end_layout
12666
12667 \begin_layout Standard
12668 Read access to this variable generates the assembly code:
12669 \end_layout
12670
12671 \begin_layout Verse
12672
12673 \family typewriter
12674 90s00r6F\InsetSpace ~
12675 \InsetSpace ~
12676 \InsetSpace ~
12677 mov dptr,#_test_code
12678 \newline
12679 E4\InsetSpace ~
12680 \InsetSpace ~
12681 \InsetSpace ~
12682 \InsetSpace ~
12683 \InsetSpace ~
12684 \InsetSpace ~
12685 \InsetSpace ~
12686 \InsetSpace ~
12687 \InsetSpace ~
12688 clr a
12689 \newline
12690 93\InsetSpace ~
12691 \InsetSpace ~
12692 \InsetSpace ~
12693 \InsetSpace ~
12694 \InsetSpace ~
12695 \InsetSpace ~
12696 \InsetSpace ~
12697 \InsetSpace ~
12698 \InsetSpace ~
12699 movc a,@a+dptr 
12700 \end_layout
12701
12702 \begin_layout Standard
12703
12704 \family typewriter
12705 char
12706 \family default
12707  indexed arrays of characters in code memory can be accessed efficiently:
12708 \end_layout
12709
12710 \begin_layout Verse
12711
12712 \family typewriter
12713 __code char test_array[] = {'c','h','e','a','p'}; 
12714 \end_layout
12715
12716 \begin_layout Standard
12717 Read access to this array using an 8-bit unsigned index generates the assembly
12718  code:
12719 \end_layout
12720
12721 \begin_layout Verse
12722
12723 \family typewriter
12724 E5*00\InsetSpace ~
12725 \InsetSpace ~
12726 \InsetSpace ~
12727 \InsetSpace ~
12728 \InsetSpace ~
12729 \InsetSpace ~
12730 mov a,_index 
12731 \end_layout
12732
12733 \begin_layout Verse
12734
12735 \family typewriter
12736 90s00r41\InsetSpace ~
12737 \InsetSpace ~
12738 \InsetSpace ~
12739 mov dptr,#_test_array
12740 \end_layout
12741
12742 \begin_layout Verse
12743
12744 \family typewriter
12745 93\InsetSpace ~
12746 \InsetSpace ~
12747 \InsetSpace ~
12748 \InsetSpace ~
12749 \InsetSpace ~
12750 \InsetSpace ~
12751 \InsetSpace ~
12752 \InsetSpace ~
12753 \InsetSpace ~
12754 movc a,@a+dptr 
12755 \end_layout
12756
12757 \begin_layout Subsubsection
12758 bit
12759 \begin_inset LatexCommand index
12760 name "bit"
12761
12762 \end_inset
12763
12764
12765 \begin_inset LatexCommand index
12766 name "\\_\\_bit"
12767
12768 \end_inset
12769
12770
12771 \end_layout
12772
12773 \begin_layout Standard
12774 This is a data-type and a storage class specifier.
12775  When a variable is declared as a bit, it is allocated into the bit addressable
12776  memory of 8051, e.g.:
12777 \end_layout
12778
12779 \begin_layout Verse
12780
12781 \family typewriter
12782 __bit test_bit;
12783 \end_layout
12784
12785 \begin_layout Standard
12786 Writing 1 to this variable generates the assembly code:
12787 \end_layout
12788
12789 \begin_layout Verse
12790
12791 \family typewriter
12792 D2*00\InsetSpace ~
12793 \InsetSpace ~
12794 \InsetSpace ~
12795 \InsetSpace ~
12796 \InsetSpace ~
12797 \InsetSpace ~
12798 \InsetSpace ~
12799 setb\InsetSpace ~
12800 _test_bit
12801 \end_layout
12802
12803 \begin_layout Standard
12804 The bit addressable memory consists of 128 bits which are located from 0x20
12805  to 0x2f in data memory.
12806  
12807 \newline
12808 Apart from this 8051 specific storage class most architectures support
12809  ANSI-C bitfields
12810 \begin_inset LatexCommand index
12811 name "bitfields"
12812
12813 \end_inset
12814
12815
12816 \begin_inset Foot
12817 status open
12818
12819 \begin_layout Standard
12820 Not really meant as examples, but nevertheless showing what bitfields are
12821  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
12822 \end_layout
12823
12824 \end_inset
12825
12826 .
12827  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
12828  signed modifier are implemented as unsigned.
12829 \end_layout
12830
12831 \begin_layout Subsubsection
12832 sfr
12833 \begin_inset LatexCommand index
12834 name "sfr"
12835
12836 \end_inset
12837
12838
12839 \begin_inset LatexCommand index
12840 name "\\_\\_sfr"
12841
12842 \end_inset
12843
12844  / sfr16
12845 \begin_inset LatexCommand index
12846 name "sfr16"
12847
12848 \end_inset
12849
12850
12851 \begin_inset LatexCommand index
12852 name "\\_\\_sfr16"
12853
12854 \end_inset
12855
12856  / sfr32
12857 \begin_inset LatexCommand index
12858 name "sfr32"
12859
12860 \end_inset
12861
12862
12863 \begin_inset LatexCommand index
12864 name "\\_\\_sfr32"
12865
12866 \end_inset
12867
12868  / sbit
12869 \begin_inset LatexCommand index
12870 name "\\_\\_sbit"
12871
12872 \end_inset
12873
12874
12875 \begin_inset LatexCommand index
12876 name "sbit"
12877
12878 \end_inset
12879
12880
12881 \end_layout
12882
12883 \begin_layout Standard
12884 Like the bit keyword, 
12885 \emph on
12886 sfr / sfr16 / sfr32 / sbit
12887 \emph default
12888  signify both a data-type and storage class, they are used to describe the
12889  
12890 \emph on
12891 s
12892 \emph default
12893 pecial 
12894 \emph on
12895 f
12896 \emph default
12897 unction 
12898 \emph on
12899 r
12900 \emph default
12901 egisters and 
12902 \emph on
12903 s
12904 \emph default
12905 pecial 
12906 \emph on
12907 bit
12908 \emph default
12909  variables of a 8051, eg:
12910 \end_layout
12911
12912 \begin_layout Verse
12913
12914 \family typewriter
12915 __sfr __at
12916 \begin_inset LatexCommand index
12917 name "at"
12918
12919 \end_inset
12920
12921
12922 \begin_inset LatexCommand index
12923 name "\\_\\_at"
12924
12925 \end_inset
12926
12927  (0x80) P0;\InsetSpace ~
12928  /* special function register P0 at location 0x80 */
12929 \newline
12930
12931 \newline
12932 /* 16 bit
12933  special function register combination for timer 0
12934 \newline
12935 \InsetSpace ~
12936 \InsetSpace ~
12937  with the high byte at
12938  location 0x8C and the low byte at location 0x8A */
12939 \newline
12940 __sfr16 __at (0x8C8A)
12941  TMR0;
12942 \newline
12943
12944 \newline
12945 __sbit __at
12946 \begin_inset LatexCommand index
12947 name "at"
12948
12949 \end_inset
12950
12951
12952 \begin_inset LatexCommand index
12953 name "\\_\\_at"
12954
12955 \end_inset
12956
12957  (0xd7) CY;\InsetSpace ~
12958  /* CY (Carry Flag
12959 \begin_inset LatexCommand index
12960 name "Flags"
12961
12962 \end_inset
12963
12964
12965 \begin_inset LatexCommand index
12966 name "Carry flag"
12967
12968 \end_inset
12969
12970 ) */
12971 \end_layout
12972
12973 \begin_layout Standard
12974 Special function registers which are located on an address dividable by
12975  8 are bit-addressable, an 
12976 \emph on
12977 sbit
12978 \emph default
12979  addresses a specific bit within these sfr.
12980 \newline
12981 16 Bit and 32 bit special function
12982  register combinations which require a certain access order are better not
12983  declared using 
12984 \emph on
12985 sfr16
12986 \emph default
12987  or 
12988 \emph on
12989 sfr32.
12990
12991 \emph default
12992  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
12993  this is not guaranteed.
12994 \newline
12995
12996 \end_layout
12997
12998 \begin_layout Standard
12999 Please note, if you use a header file which was written for another compiler
13000  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
13001  likely be 
13002 \emph on
13003 not
13004 \emph default
13005  compatible.
13006  Specifically the syntax 
13007 \family typewriter
13008 \InsetSpace ~
13009 sfr P0 = 0x80;\InsetSpace ~
13010
13011 \family default
13012  is compiled 
13013 \emph on
13014 without warning
13015 \emph default
13016  by SDCC to an assignment of 0x80 to a variable called P0 
13017 \family typewriter
13018
13019 \begin_inset Marginal
13020 status collapsed
13021
13022 \begin_layout Standard
13023
13024 \series bold
13025 \InsetSpace ~
13026 !
13027 \end_layout
13028
13029 \end_inset
13030
13031 .
13032
13033 \family default
13034  
13035 \series bold
13036 Nevertheless it is possible to write header files
13037 \begin_inset LatexCommand index
13038 name "Header files"
13039
13040 \end_inset
13041
13042
13043 \begin_inset LatexCommand index
13044 name "Include files"
13045
13046 \end_inset
13047
13048  which can be shared among different compilers (see section 
13049 \begin_inset LatexCommand ref
13050 reference "sec:Porting-code-to-other-compilers"
13051
13052 \end_inset
13053
13054 ).
13055  
13056 \end_layout
13057
13058 \begin_layout Subsubsection
13059 Pointers
13060 \begin_inset LatexCommand index
13061 name "Pointer"
13062
13063 \end_inset
13064
13065  to MCS51/DS390 specific memory spaces
13066 \end_layout
13067
13068 \begin_layout Standard
13069 SDCC allows (via language extensions) pointers to explicitly point to any
13070  of the memory spaces
13071 \begin_inset LatexCommand index
13072 name "Memory model"
13073
13074 \end_inset
13075
13076  of the 8051.
13077  In addition to the explicit pointers, the compiler uses (by default) generic
13078  pointers which can be used to point to any of the memory spaces.
13079 \newline
13080
13081 \newline
13082 Pointer
13083  declaration examples:
13084 \end_layout
13085
13086 \begin_layout Verse
13087
13088 \family typewriter
13089 /* pointer physically in internal ram pointing to object in external ram
13090  */ 
13091 \newline
13092 __xdata unsigned char * __data p;
13093 \newline
13094
13095 \newline
13096 /* pointer physically in external ram
13097  pointing to object in internal ram */ 
13098 \newline
13099 __data unsigned char * __xdata p;
13100 \newline
13101
13102 \newline
13103 /*
13104  pointer physically in code rom pointing to data in xdata space */ 
13105 \newline
13106 __xdata
13107  unsigned char * __code p;
13108 \newline
13109
13110 \newline
13111 /* pointer physically in code space pointing to
13112  data in code space */ 
13113 \newline
13114 __code unsigned char * __code p;
13115 \newline
13116
13117 \newline
13118 /* generic pointer
13119  physically located in xdata space */
13120 \newline
13121 unsigned char * __xdata p;
13122 \newline
13123
13124 \newline
13125 /* generic
13126  pointer physically located in default memory space */
13127 \newline
13128 unsigned char * p;
13129 \newline
13130
13131 \newline
13132 /*
13133  the following is a function pointer
13134 \begin_inset LatexCommand index
13135 name "function pointer"
13136
13137 \end_inset
13138
13139  physically located in data space */
13140 \newline
13141 char (* __data fp)(void);
13142 \end_layout
13143
13144 \begin_layout Standard
13145 Well you get the idea.
13146  
13147 \newline
13148
13149 \newline
13150 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
13151 \emph on
13152 generic
13153 \emph default
13154  pointers.
13155  
13156 \size small
13157
13158 \newline
13159
13160 \newline
13161
13162 \size default
13163 The highest order byte of the 
13164 \emph on
13165 generic
13166 \emph default
13167  pointers contains the data space information.
13168  Assembler support routines are called whenever data is stored or retrieved
13169  using 
13170 \emph on
13171 generic
13172 \emph default
13173  pointers.
13174  These are useful for developing reusable library
13175 \begin_inset LatexCommand index
13176 name "Libraries"
13177
13178 \end_inset
13179
13180  routines.
13181  Explicitly specifying the pointer
13182 \begin_inset LatexCommand index
13183 name "pointer"
13184
13185 \end_inset
13186
13187  type will generate the most efficient code.
13188 \end_layout
13189
13190 \begin_layout Subsubsection
13191 Notes on MCS51 memory
13192 \begin_inset LatexCommand index
13193 name "MCS51 memory"
13194
13195 \end_inset
13196
13197  layout
13198 \end_layout
13199
13200 \begin_layout Standard
13201 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
13202  RAM memory which is structured as follows:
13203 \newline
13204
13205 \newline
13206 - Bytes 00-1F - 32 bytes to hold
13207  up to 4 banks of the registers R0 to R7, 
13208 \newline
13209 - Bytes 20-2F - 16 bytes to hold
13210  128 bit
13211 \begin_inset LatexCommand index
13212 name "bit"
13213
13214 \end_inset
13215
13216  variables and, 
13217 \newline
13218 - Bytes 30-7F - 80 bytes for general purpose use.
13219 \newline
13220
13221 \end_layout
13222
13223 \begin_layout Standard
13224 Additionally some members of the MCS51 family may have up to 128 bytes of
13225  additional, indirectly addressable, internal RAM memory (
13226 \emph on
13227 idata
13228 \emph default
13229
13230 \begin_inset LatexCommand index
13231 name "idata (mcs51, ds390 storage class)"
13232
13233 \end_inset
13234
13235
13236 \begin_inset LatexCommand index
13237 name "\\_\\_idata (mcs51, ds390 storage class)"
13238
13239 \end_inset
13240
13241 ).
13242  Furthermore, some chips may have some built in external memory (
13243 \emph on
13244 xdata
13245 \emph default
13246
13247 \begin_inset LatexCommand index
13248 name "xdata (mcs51, ds390 storage class)"
13249
13250 \end_inset
13251
13252
13253 \begin_inset LatexCommand index
13254 name "\\_\\_xdata (mcs51, ds390 storage class)"
13255
13256 \end_inset
13257
13258 ) which should not be confused with the internal, directly addressable RAM
13259  memory (
13260 \emph on
13261 data
13262 \emph default
13263
13264 \begin_inset LatexCommand index
13265 name "data (mcs51, ds390 storage class)"
13266
13267 \end_inset
13268
13269
13270 \begin_inset LatexCommand index
13271 name "\\_\\_data (mcs51, ds390 storage class)"
13272
13273 \end_inset
13274
13275 ).
13276  Sometimes this built in 
13277 \emph on
13278 xdata
13279 \emph default
13280  memory has to be activated before using it (you can probably find this
13281  information on the datasheet of the microcontroller your are using, see
13282  also section 
13283 \begin_inset LatexCommand ref
13284 reference "sub:Startup-Code"
13285
13286 \end_inset
13287
13288 \InsetSpace ~
13289 Startup-Code).
13290 \end_layout
13291
13292 \begin_layout Standard
13293 Normally SDCC will only use the first bank
13294 \begin_inset LatexCommand index
13295 name "register bank (mcs51, ds390)"
13296
13297 \end_inset
13298
13299  of registers (register bank 0), but it is possible to specify that other
13300  banks of registers (keyword 
13301 \emph on
13302 using
13303 \emph default
13304  
13305 \emph on
13306
13307 \begin_inset LatexCommand index
13308 name "using (mcs51, ds390 register bank)"
13309
13310 \end_inset
13311
13312
13313 \begin_inset LatexCommand index
13314 name "\\_\\_using (mcs51, ds390 register bank)"
13315
13316 \end_inset
13317
13318
13319 \emph default
13320 ) should be used for example in interrupt
13321 \begin_inset LatexCommand index
13322 name "interrupt"
13323
13324 \end_inset
13325
13326
13327 \begin_inset LatexCommand index
13328 name "\\_\\_interrupt"
13329
13330 \end_inset
13331
13332  routines.
13333  By default, the compiler will place the stack after the last byte of allocated
13334  memory for variables.
13335  For example, if the first 2 banks of registers are used, and only four
13336  bytes are used for 
13337 \emph on
13338 data
13339 \emph default
13340  variables, it will position the base of the internal stack at address 20
13341  (0x14).
13342  This implies that as the stack
13343 \begin_inset LatexCommand index
13344 name "stack"
13345
13346 \end_inset
13347
13348  grows, it will use up the remaining register banks, and the 16 bytes used
13349  by the 128 bit variables, and 80 bytes for general purpose use.
13350  If any bit variables are used, the data variables will be placed in unused
13351  register banks and after the byte holding the last bit variable.
13352  For example, if register banks 0 and 1 are used, and there are 9 bit variables
13353  (two bytes used), 
13354 \emph on
13355 data
13356 \emph default
13357  variables will be placed starting from address 0x10 to 0x20 and continue
13358  at address 0x22.
13359  You can also use -
13360 \begin_inset ERT
13361 status collapsed
13362
13363 \begin_layout Standard
13364
13365
13366 \backslash
13367 /
13368 \end_layout
13369
13370 \end_inset
13371
13372 -data-loc
13373 \begin_inset LatexCommand index
13374 name "-\\/-data-loc <Value>"
13375
13376 \end_inset
13377
13378  to specify the start address of the 
13379 \emph on
13380 data
13381 \emph default
13382  and -
13383 \begin_inset ERT
13384 status collapsed
13385
13386 \begin_layout Standard
13387
13388
13389 \backslash
13390 /
13391 \end_layout
13392
13393 \end_inset
13394
13395 -iram-size
13396 \begin_inset LatexCommand index
13397 name "-\\/-iram-size <Value>"
13398
13399 \end_inset
13400
13401  to specify the size of the total internal RAM (
13402 \emph on
13403 data
13404 \emph default
13405 +
13406 \emph on
13407 idata
13408 \emph default
13409 ).
13410  
13411 \newline
13412
13413 \end_layout
13414
13415 \begin_layout Standard
13416 By default the 8051 linker will place the stack after the last byte of (i)data
13417  variables.
13418  Option -
13419 \begin_inset ERT
13420 status collapsed
13421
13422 \begin_layout Standard
13423
13424
13425 \backslash
13426 /
13427 \end_layout
13428
13429 \end_inset
13430
13431 -stack-loc
13432 \begin_inset LatexCommand index
13433 name "-\\/-stack-loc <Value>"
13434
13435 \end_inset
13436
13437  allows you to specify the start of the stack, i.e.
13438  you could start it after any data in the general purpose area.
13439  If your microcontroller has additional indirectly addressable internal
13440  RAM (
13441 \emph on
13442 idata
13443 \emph default
13444 ) you can place the stack on it.
13445  You may also need to use -
13446 \begin_inset ERT
13447 status collapsed
13448
13449 \begin_layout Standard
13450
13451
13452 \backslash
13453 /
13454 \end_layout
13455
13456 \end_inset
13457
13458 -xdata-loc
13459 \begin_inset LatexCommand index
13460 name "-\\/-xdata-loc<Value>"
13461
13462 \end_inset
13463
13464  to set the start address of the external RAM (
13465 \emph on
13466 xdata
13467 \emph default
13468 ) and -
13469 \begin_inset ERT
13470 status collapsed
13471
13472 \begin_layout Standard
13473
13474
13475 \backslash
13476 /
13477 \end_layout
13478
13479 \end_inset
13480
13481 -xram-size
13482 \begin_inset LatexCommand index
13483 name "-\\/-xram-size <Value>"
13484
13485 \end_inset
13486
13487  to specify its size.
13488  Same goes for the code memory, using -
13489 \begin_inset ERT
13490 status collapsed
13491
13492 \begin_layout Standard
13493
13494
13495 \backslash
13496 /
13497 \end_layout
13498
13499 \end_inset
13500
13501 -code-loc
13502 \begin_inset LatexCommand index
13503 name "-\\/-code-loc <Value>"
13504
13505 \end_inset
13506
13507  and -
13508 \begin_inset ERT
13509 status collapsed
13510
13511 \begin_layout Standard
13512
13513
13514 \backslash
13515 /
13516 \end_layout
13517
13518 \end_inset
13519
13520 -code-size
13521 \begin_inset LatexCommand index
13522 name "-\\/-code-size <Value>"
13523
13524 \end_inset
13525
13526 .
13527  If in doubt, don't specify any options and see if the resulting memory
13528  layout is appropriate, then you can adjust it.
13529 \end_layout
13530
13531 \begin_layout Standard
13532 The linker generates two files with memory allocation information.
13533  The first, with extension .map
13534 \begin_inset LatexCommand index
13535 name "<file>.map"
13536
13537 \end_inset
13538
13539  shows all the variables and segments.
13540  The second with extension .mem
13541 \begin_inset LatexCommand index
13542 name "<file>.mem"
13543
13544 \end_inset
13545
13546  shows the final memory layout.
13547  The linker will complain either if memory segments overlap, there is not
13548  enough memory, or there is not enough space for stack.
13549  If you get any linking warnings and/or errors related to stack or segments
13550  allocation, take a look at either the .map or .mem files to find out what
13551  the problem is.
13552  The .mem file may even suggest a solution to the problem.
13553 \begin_inset VSpace bigskip
13554 \end_inset
13555
13556
13557 \end_layout
13558
13559 \begin_layout Subsection
13560 Z80/Z180 Storage Class
13561 \begin_inset LatexCommand index
13562 name "Z80!Storage class"
13563
13564 \end_inset
13565
13566  Language Extensions
13567 \end_layout
13568
13569 \begin_layout Subsubsection
13570 sfr
13571 \begin_inset LatexCommand index
13572 name "sfr"
13573
13574 \end_inset
13575
13576
13577 \begin_inset LatexCommand index
13578 name "\\_\\_sfr"
13579
13580 \end_inset
13581
13582  (in/out to 8-bit addresses)
13583 \end_layout
13584
13585 \begin_layout Standard
13586 The Z80
13587 \begin_inset LatexCommand index
13588 name "Z80"
13589
13590 \end_inset
13591
13592  family has separate address spaces for memory and 
13593 \emph on
13594 i
13595 \emph default
13596 nput/
13597 \emph on
13598 o
13599 \emph default
13600 utput memory.
13601  I/O memory
13602 \begin_inset LatexCommand index
13603 name "I/O memory (Z80, Z180)"
13604
13605 \end_inset
13606
13607
13608 \begin_inset LatexCommand index
13609 name "Z80!I/O memory"
13610
13611 \end_inset
13612
13613
13614 \begin_inset LatexCommand index
13615 name "Z180!I/O memory"
13616
13617 \end_inset
13618
13619  is accessed with special instructions, e.g.:
13620 \end_layout
13621
13622 \begin_layout Verse
13623
13624 \family typewriter
13625 sfr at 0x78 IoPort;\InsetSpace ~
13626 \InsetSpace ~
13627 /* define a var in I/O space at 78h called IoPort */
13628  
13629 \end_layout
13630
13631 \begin_layout Standard
13632 Writing 0x01 to this variable generates the assembly code:
13633 \end_layout
13634
13635 \begin_layout Verse
13636
13637 \family typewriter
13638 3E 01\InsetSpace ~
13639 \InsetSpace ~
13640 \InsetSpace ~
13641 \InsetSpace ~
13642 \InsetSpace ~
13643 \InsetSpace ~
13644 ld a,#0x01
13645 \newline
13646 D3 78\InsetSpace ~
13647 \InsetSpace ~
13648 \InsetSpace ~
13649 \InsetSpace ~
13650 \InsetSpace ~
13651 \InsetSpace ~
13652 out (_IoPort),a 
13653 \end_layout
13654
13655 \begin_layout Subsubsection
13656 banked sfr
13657 \begin_inset LatexCommand index
13658 name "sfr"
13659
13660 \end_inset
13661
13662
13663 \begin_inset LatexCommand index
13664 name "\\_\\_sfr"
13665
13666 \end_inset
13667
13668  (in/out to 16-bit addresses)
13669 \end_layout
13670
13671 \begin_layout Standard
13672 The keyword 
13673 \emph on
13674 banked
13675 \emph default
13676  is used to support 16 bit addresses in I/O memory e.g.:
13677 \end_layout
13678
13679 \begin_layout Verse
13680
13681 \family typewriter
13682 sfr banked at
13683 \begin_inset LatexCommand index
13684 name "at"
13685
13686 \end_inset
13687
13688
13689 \begin_inset LatexCommand index
13690 name "\\_\\_at"
13691
13692 \end_inset
13693
13694  0x123 IoPort; 
13695 \end_layout
13696
13697 \begin_layout Standard
13698 Writing 0x01 to this variable generates the assembly code:
13699 \end_layout
13700
13701 \begin_layout Verse
13702
13703 \family typewriter
13704 01 23 01\InsetSpace ~
13705 \InsetSpace ~
13706 \InsetSpace ~
13707 ld bc,#_IoPort
13708 \newline
13709 3E 01\InsetSpace ~
13710 \InsetSpace ~
13711 \InsetSpace ~
13712 \InsetSpace ~
13713 \InsetSpace ~
13714 \InsetSpace ~
13715 ld a,#0x01 
13716 \newline
13717 ED 79\InsetSpace ~
13718 \InsetSpace ~
13719 \InsetSpace ~
13720 \InsetSpace ~
13721 \InsetSpace ~
13722 \InsetSpace ~
13723 out (c),a 
13724 \end_layout
13725
13726 \begin_layout Subsubsection
13727 sfr
13728 \begin_inset LatexCommand index
13729 name "sfr"
13730
13731 \end_inset
13732
13733
13734 \begin_inset LatexCommand index
13735 name "\\_\\_sfr"
13736
13737 \end_inset
13738
13739  (in0/out0 to 8 bit addresses on Z180
13740 \begin_inset LatexCommand index
13741 name "Z180"
13742
13743 \end_inset
13744
13745 /HD64180
13746 \begin_inset LatexCommand index
13747 name "HD64180 (see Z180)"
13748
13749 \end_inset
13750
13751 )
13752 \end_layout
13753
13754 \begin_layout Standard
13755 The compiler option -
13756 \begin_inset ERT
13757 status collapsed
13758
13759 \begin_layout Standard
13760
13761
13762 \backslash
13763 /
13764 \end_layout
13765
13766 \end_inset
13767
13768 -portmode
13769 \begin_inset LatexCommand index
13770 name "Z180!Options!-\\/-portmode"
13771
13772 \end_inset
13773
13774 =180 (80) and a compiler #pragma\InsetSpace ~
13775 portmode
13776 \begin_inset LatexCommand index
13777 name "Z180!Pragmas!\\#pragma portmode"
13778
13779 \end_inset
13780
13781  z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
13782 ns 
13783 \family typewriter
13784 in0/out0
13785 \family default
13786  instead of 
13787 \family typewriter
13788 in/out
13789 \family default
13790 .
13791  If you include the file z180.h this will be set automatically.
13792 \begin_inset VSpace bigskip
13793 \end_inset
13794
13795
13796 \end_layout
13797
13798 \begin_layout Subsection
13799 HC08 Storage Class
13800 \begin_inset LatexCommand index
13801 name "HC08!Storage class"
13802
13803 \end_inset
13804
13805  Language Extensions
13806 \end_layout
13807
13808 \begin_layout Subsubsection
13809 data
13810 \begin_inset LatexCommand index
13811 name "data (hc08 storage class)"
13812
13813 \end_inset
13814
13815
13816 \begin_inset LatexCommand index
13817 name "\\_\\_data (hc08 storage class)"
13818
13819 \end_inset
13820
13821  
13822 \end_layout
13823
13824 \begin_layout Standard
13825 The data storage class declares a variable that resides in the first 256
13826  bytes of memory (the direct page).
13827  The HC08
13828 \begin_inset LatexCommand index
13829 name "HC08"
13830
13831 \end_inset
13832
13833  is most efficient at accessing variables (especially pointers) stored here.
13834 \end_layout
13835
13836 \begin_layout Subsubsection
13837 xdata
13838 \begin_inset LatexCommand index
13839 name "xdata (hc08 storage class)"
13840
13841 \end_inset
13842
13843
13844 \begin_inset LatexCommand index
13845 name "\\_\\_xdata (hc08 storage class)"
13846
13847 \end_inset
13848
13849  
13850 \end_layout
13851
13852 \begin_layout Standard
13853 The xdata storage class declares a variable that can reside anywhere in
13854  memory.
13855  This is the default if no storage class is specified.
13856  
13857 \begin_inset VSpace bigskip
13858 \end_inset
13859
13860
13861 \end_layout
13862
13863 \begin_layout Section
13864 Other SDCC language extensions
13865 \begin_inset LatexCommand index
13866 name "Other SDCC language extensions"
13867
13868 \end_inset
13869
13870
13871 \end_layout
13872
13873 \begin_layout Subsection
13874 Binary constants
13875 \end_layout
13876
13877 \begin_layout Standard
13878 SDCC supports the use of binary constants, such as 0b01100010.
13879  This feature is only enabled when the compiler is invoked using --std-sdccxx.
13880 \end_layout
13881
13882 \begin_layout Standard
13883 \begin_inset VSpace bigskip
13884 \end_inset
13885
13886
13887 \end_layout
13888
13889 \begin_layout Section
13890 Absolute Addressing
13891 \begin_inset LatexCommand index
13892 name "Absolute addressing"
13893
13894 \end_inset
13895
13896
13897 \end_layout
13898
13899 \begin_layout Standard
13900 Data items can be assigned an absolute address with the 
13901 \emph on
13902 at
13903 \begin_inset LatexCommand index
13904 name "at"
13905
13906 \end_inset
13907
13908
13909 \begin_inset LatexCommand index
13910 name "\\_\\_at"
13911
13912 \end_inset
13913
13914  <address>
13915 \emph default
13916  keyword, in addition to a storage class, e.g.:
13917 \end_layout
13918
13919 \begin_layout Verse
13920
13921 \family typewriter
13922 xdata
13923 \begin_inset LatexCommand index
13924 name "xdata (mcs51, ds390 storage class)"
13925
13926 \end_inset
13927
13928
13929 \begin_inset LatexCommand index
13930 name "\\_\\_xdata (mcs51, ds390 storage class)"
13931
13932 \end_inset
13933
13934  at
13935 \begin_inset LatexCommand index
13936 name "at"
13937
13938 \end_inset
13939
13940
13941 \begin_inset LatexCommand index
13942 name "\\_\\_at"
13943
13944 \end_inset
13945
13946  0x7ffe unsigned int chksum;
13947 \end_layout
13948
13949 \begin_layout Standard
13950 or, better conforming to ISO/IEC 9899 C:
13951 \end_layout
13952
13953 \begin_layout Verse
13954
13955 \family typewriter
13956 __xdata __at (0x7ffe) unsigned int chksum;
13957 \end_layout
13958
13959 \begin_layout Standard
13960 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
13961  of the external ram.
13962  The compiler does 
13963 \emph on
13964 not
13965 \emph default
13966  reserve any space for variables declared in this way
13967 \begin_inset Marginal
13968 status collapsed
13969
13970 \begin_layout Standard
13971
13972 \series bold
13973 \InsetSpace ~
13974 !
13975 \end_layout
13976
13977 \end_inset
13978
13979  (they are implemented with an equate in the assembler).
13980  Thus it is left to the programmer to make sure there are no overlaps with
13981  other variables that are declared without the absolute address.
13982  The assembler listing file (.lst
13983 \begin_inset LatexCommand index
13984 name "<file>.lst"
13985
13986 \end_inset
13987
13988 ) and the linker output files (.rst
13989 \begin_inset LatexCommand index
13990 name "<file>.rst"
13991
13992 \end_inset
13993
13994 ) and (.map
13995 \begin_inset LatexCommand index
13996 name "<file>.map"
13997
13998 \end_inset
13999
14000 ) are good places to look for such overlaps.
14001 \end_layout
14002
14003 \begin_layout Standard
14004 If however you provide an initializer
14005 \begin_inset LatexCommand index
14006 name "Variable initialization"
14007
14008 \end_inset
14009
14010  actual memory allocation will take place and overlaps will be detected
14011  by the linker.
14012  E.g.:
14013 \end_layout
14014
14015 \begin_layout Verse
14016
14017 \family typewriter
14018 __code __at (0x7ff0) char Id[5] = 
14019 \begin_inset Quotes sld
14020 \end_inset
14021
14022 SDCC
14023 \begin_inset Quotes srd
14024 \end_inset
14025
14026 ;
14027 \end_layout
14028
14029 \begin_layout Standard
14030 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
14031  in code memory.
14032 \end_layout
14033
14034 \begin_layout Standard
14035 In case of memory mapped I/O devices the keyword 
14036 \emph on
14037 volatile
14038 \emph default
14039  has to be used to tell the compiler that accesses might not be removed:
14040 \end_layout
14041
14042 \begin_layout Verse
14043
14044 \family typewriter
14045 volatile
14046 \begin_inset LatexCommand index
14047 name "volatile"
14048
14049 \end_inset
14050
14051  __xdata
14052 \begin_inset LatexCommand index
14053 name "xdata (mcs51, ds390 storage class)"
14054
14055 \end_inset
14056
14057  __at
14058 \begin_inset LatexCommand index
14059 name "at"
14060
14061 \end_inset
14062
14063  (0x8000) unsigned char PORTA_8255;
14064 \end_layout
14065
14066 \begin_layout Standard
14067 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
14068 r) array
14069 \family typewriter
14070 \size footnotesize
14071
14072 \begin_inset LatexCommand index
14073 name "Aligned array"
14074
14075 \end_inset
14076
14077
14078 \family default
14079 \size default
14080  starts at a block (256 byte) boundary
14081 \begin_inset LatexCommand index
14082 name "block boundary"
14083
14084 \end_inset
14085
14086  (section 
14087 \begin_inset LatexCommand ref
14088 reference "sub:A-Step-by Assembler Introduction"
14089
14090 \end_inset
14091
14092  has an example).
14093 \newline
14094 Absolute addresses can be specified for variables in all
14095  storage classes, e.g.:
14096 \end_layout
14097
14098 \begin_layout Verse
14099
14100 \family typewriter
14101 __bit
14102 \begin_inset LatexCommand index
14103 name "bit"
14104
14105 \end_inset
14106
14107  __at
14108 \begin_inset LatexCommand index
14109 name "at"
14110
14111 \end_inset
14112
14113  (0x02) bvar;
14114 \end_layout
14115
14116 \begin_layout Standard
14117 The above example will allocate the variable at offset 0x02 in the bit-addressab
14118 le space.
14119  There is no real advantage to assigning absolute addresses to variables
14120  in this manner, unless you want strict control over all the variables allocated.
14121  One possible use would be to write hardware portable code.
14122  For example, if you have a routine that uses one or more of the microcontroller
14123  I/O pins, and such pins are different for two different hardwares, you
14124  can declare the I/O pins in your routine using:
14125 \end_layout
14126
14127 \begin_layout Verse
14128
14129 \family typewriter
14130 extern volatile
14131 \begin_inset LatexCommand index
14132 name "volatile"
14133
14134 \end_inset
14135
14136  __bit MOSI;\InsetSpace ~
14137 \InsetSpace ~
14138 \InsetSpace ~
14139 \InsetSpace ~
14140 /* master out, slave in */
14141 \newline
14142 extern volatile __bit MISO;\InsetSpace ~
14143 \InsetSpace ~
14144 \InsetSpace ~
14145 \InsetSpace ~
14146 /* master
14147  in, slave out */
14148 \newline
14149 extern volatile __bit MCLK;\InsetSpace ~
14150 \InsetSpace ~
14151 \InsetSpace ~
14152 \InsetSpace ~
14153 /* master clock */
14154 \newline
14155
14156 \newline
14157 /* Input and
14158  Output of a byte on a 3-wire serial bus.
14159 \newline
14160 \InsetSpace ~
14161 \InsetSpace ~
14162 \InsetSpace ~
14163 If needed adapt polarity of clock,
14164  polarity of data and bit order
14165 \newline
14166 \InsetSpace ~
14167 */
14168 \newline
14169 unsigned char spi_io(unsigned char out_byte)
14170  
14171 \newline
14172
14173 \newline
14174 \InsetSpace ~
14175 \InsetSpace ~
14176 \InsetSpace ~
14177 \InsetSpace ~
14178 unsigned char i=8;
14179 \newline
14180 \InsetSpace ~
14181 \InsetSpace ~
14182 \InsetSpace ~
14183 \InsetSpace ~
14184 do { 
14185 \newline
14186 \InsetSpace ~
14187 \InsetSpace ~
14188 \InsetSpace ~
14189 \InsetSpace ~
14190 \InsetSpace ~
14191 \InsetSpace ~
14192 \InsetSpace ~
14193 \InsetSpace ~
14194 MOSI = out_byte & 0x80; 
14195 \newline
14196 \InsetSpace ~
14197 \InsetSpace ~
14198 \InsetSpace ~
14199 \InsetSpace ~
14200 \InsetSpace ~
14201 \InsetSpace ~
14202 \InsetSpace ~
14203 \InsetSpace ~
14204 out_byte <<= 1;
14205 \newline
14206 \InsetSpace ~
14207 \InsetSpace ~
14208 \InsetSpace ~
14209 \InsetSpace ~
14210 \InsetSpace ~
14211 \InsetSpace ~
14212 \InsetSpace ~
14213 \InsetSpace ~
14214 MCLK =
14215  1; 
14216 \newline
14217 \InsetSpace ~
14218 \InsetSpace ~
14219 \InsetSpace ~
14220 \InsetSpace ~
14221 \InsetSpace ~
14222 \InsetSpace ~
14223 \InsetSpace ~
14224 \InsetSpace ~
14225 /* _asm nop _endasm; */\InsetSpace ~
14226 \InsetSpace ~
14227 \InsetSpace ~
14228 \InsetSpace ~
14229 \InsetSpace ~
14230 \InsetSpace ~
14231 \InsetSpace ~
14232 \InsetSpace ~
14233 /* for slow peripherals */
14234 \newline
14235 \InsetSpace ~
14236 \InsetSpace ~
14237 \InsetSpace ~
14238 \InsetSpace ~
14239 \InsetSpace ~
14240 \InsetSpace ~
14241 \InsetSpace ~
14242 \InsetSpace ~
14243 if(MISO) 
14244 \newline
14245 \InsetSpace ~
14246 \InsetSpace ~
14247 \InsetSpace ~
14248 \InsetSpace ~
14249 \InsetSpace ~
14250 \InsetSpace ~
14251 \InsetSpace ~
14252 \InsetSpace ~
14253 \InsetSpace ~
14254 \InsetSpace ~
14255 \InsetSpace ~
14256 \InsetSpace ~
14257 out_byte +=
14258  1; 
14259 \newline
14260 \InsetSpace ~
14261 \InsetSpace ~
14262 \InsetSpace ~
14263 \InsetSpace ~
14264 \InsetSpace ~
14265 \InsetSpace ~
14266 \InsetSpace ~
14267 \InsetSpace ~
14268 MCLK = 0; 
14269 \newline
14270 \InsetSpace ~
14271 \InsetSpace ~
14272 \InsetSpace ~
14273 \InsetSpace ~
14274 } while(--i);
14275 \newline
14276 \InsetSpace ~
14277 \InsetSpace ~
14278 \InsetSpace ~
14279 \InsetSpace ~
14280 return out_byte; 
14281 \newline
14282 }
14283 \end_layout
14284
14285 \begin_layout Standard
14286 Then, someplace in the code for the first hardware you would use
14287 \end_layout
14288
14289 \begin_layout Verse
14290
14291 \family typewriter
14292 __bit __at
14293 \begin_inset LatexCommand index
14294 name "at"
14295
14296 \end_inset
14297
14298
14299 \begin_inset LatexCommand index
14300 name "\\_\\_at"
14301
14302 \end_inset
14303
14304  (0x80) MOSI;\InsetSpace ~
14305 \InsetSpace ~
14306 \InsetSpace ~
14307 \InsetSpace ~
14308 /* I/O port 0, bit 0 */
14309 \newline
14310 __bit __at (0x81) MISO;\InsetSpace ~
14311 \InsetSpace ~
14312 \InsetSpace ~
14313 \InsetSpace ~
14314 /* I/O port 0,
14315  bit 1 */
14316 \newline
14317 __bit __at (0x82) MCLK;\InsetSpace ~
14318 \InsetSpace ~
14319 \InsetSpace ~
14320 \InsetSpace ~
14321 /* I/O port 0, bit 2 */
14322 \end_layout
14323
14324 \begin_layout Standard
14325 Similarly, for the second hardware you would use
14326 \end_layout
14327
14328 \begin_layout Verse
14329
14330 \family typewriter
14331 __bit __at (0x83) MOSI;\InsetSpace ~
14332 \InsetSpace ~
14333 \InsetSpace ~
14334 \InsetSpace ~
14335 /* I/O port 0, bit 3 */
14336 \newline
14337 __bit __at (0x91) MISO;\InsetSpace ~
14338 \InsetSpace ~
14339 \InsetSpace ~
14340 \InsetSpace ~
14341 /*
14342  I/O port 1, bit 1 */
14343 \newline
14344 __bit
14345 \begin_inset LatexCommand index
14346 name "bit"
14347
14348 \end_inset
14349
14350  __at (0x92) MCLK;\InsetSpace ~
14351 \InsetSpace ~
14352 \InsetSpace ~
14353 \InsetSpace ~
14354 /* I/O port 1, bit 2 */
14355 \end_layout
14356
14357 \begin_layout Standard
14358 and you can use the same hardware dependent routine without changes, as
14359  for example in a library.
14360  This is somehow similar to sbit, but only one absolute address has to be
14361  specified in the whole project.
14362 \begin_inset VSpace bigskip
14363 \end_inset
14364
14365
14366 \end_layout
14367
14368 \begin_layout Section
14369 Parameters
14370 \begin_inset LatexCommand index
14371 name "Parameters"
14372
14373 \end_inset
14374
14375
14376 \begin_inset LatexCommand index
14377 name "function parameter"
14378
14379 \end_inset
14380
14381  & Local Variables
14382 \begin_inset LatexCommand index
14383 name "local variables"
14384
14385 \end_inset
14386
14387
14388 \begin_inset LatexCommand label
14389 name "sec:Parameters-and-Local-Variables"
14390
14391 \end_inset
14392
14393
14394 \end_layout
14395
14396 \begin_layout Standard
14397 Automatic (local) variables and parameters to functions can either be placed
14398  on the stack or in data-space.
14399  The default action of the compiler is to place these variables in the internal
14400  RAM (for small model) or external RAM (for medium or large model).
14401  This in fact makes them similar to 
14402 \emph on
14403 static
14404 \begin_inset LatexCommand index
14405 name "static"
14406
14407 \end_inset
14408
14409
14410 \emph default
14411  so by default functions are non-reentrant
14412 \begin_inset LatexCommand index
14413 name "reentrant"
14414
14415 \end_inset
14416
14417 .
14418  
14419 \newline
14420
14421 \newline
14422 They can be placed on the stack
14423 \begin_inset LatexCommand index
14424 name "stack"
14425
14426 \end_inset
14427
14428  by using the 
14429 \emph on
14430 -
14431 \begin_inset ERT
14432 status collapsed
14433
14434 \begin_layout Standard
14435
14436
14437 \backslash
14438 /
14439 \end_layout
14440
14441 \end_inset
14442
14443 -stack-auto
14444 \begin_inset LatexCommand index
14445 name "-\\/-stack-auto"
14446
14447 \end_inset
14448
14449
14450 \emph default
14451  option, by using 
14452 \emph on
14453 #pragma\InsetSpace ~
14454 stackauto
14455 \emph default
14456
14457 \begin_inset LatexCommand index
14458 name "\\#pragma stackauto"
14459
14460 \end_inset
14461
14462  or by using the 
14463 \emph on
14464 reentrant
14465 \begin_inset LatexCommand index
14466 name "reentrant"
14467
14468 \end_inset
14469
14470
14471 \emph default
14472  keyword in the function declaration, e.g.:
14473 \end_layout
14474
14475 \begin_layout Verse
14476
14477 \family typewriter
14478 unsigned char foo(char i) __reentrant 
14479 \newline
14480
14481 \newline
14482 \InsetSpace ~
14483 \InsetSpace ~
14484 \InsetSpace ~
14485 \InsetSpace ~
14486 ...
14487  
14488 \newline
14489 }
14490 \end_layout
14491
14492 \begin_layout Standard
14493 Since stack space on 8051 is limited, the 
14494 \emph on
14495 reentrant
14496 \emph default
14497  keyword or the 
14498 \emph on
14499 -
14500 \begin_inset ERT
14501 status collapsed
14502
14503 \begin_layout Standard
14504
14505
14506 \backslash
14507 /
14508 \end_layout
14509
14510 \end_inset
14511
14512 -stack-auto
14513 \emph default
14514  option should be used sparingly.
14515  Note that the reentrant keyword just means that the parameters & local
14516  variables will be allocated to the stack, it 
14517 \emph on
14518 does not
14519 \emph default
14520  mean that the function is register bank
14521 \begin_inset LatexCommand index
14522 name "register bank (mcs51, ds390)"
14523
14524 \end_inset
14525
14526  independent.
14527 \newline
14528
14529 \newline
14530 Local variables
14531 \begin_inset LatexCommand index
14532 name "local variables"
14533
14534 \end_inset
14535
14536  can be assigned storage classes and absolute
14537 \begin_inset LatexCommand index
14538 name "Absolute addressing"
14539
14540 \end_inset
14541
14542  addresses, e.g.: 
14543 \end_layout
14544
14545 \begin_layout Verse
14546
14547 \family typewriter
14548 unsigned char foo() 
14549 \newline
14550 {
14551 \newline
14552 \InsetSpace ~
14553 \InsetSpace ~
14554 \InsetSpace ~
14555 \InsetSpace ~
14556 __xdata unsigned char i;
14557 \newline
14558 \InsetSpace ~
14559 \InsetSpace ~
14560 \InsetSpace ~
14561 \InsetSpace ~
14562 __bit bvar;
14563 \newline
14564 \InsetSpace ~
14565 \InsetSpace ~
14566 \InsetSpace ~
14567 \InsetSpace ~
14568 __data __at
14569 \begin_inset LatexCommand index
14570 name "at"
14571
14572 \end_inset
14573
14574  (0x31) unsigned char j;
14575 \newline
14576 \InsetSpace ~
14577 \InsetSpace ~
14578 \InsetSpace ~
14579 \InsetSpace ~
14580 ...
14581  
14582 \newline
14583 }
14584 \end_layout
14585
14586 \begin_layout Standard
14587 In the above example the variable 
14588 \emph on
14589 i
14590 \emph default
14591  will be allocated in the external ram, 
14592 \emph on
14593 bvar
14594 \emph default
14595  in bit addressable space and 
14596 \emph on
14597 j
14598 \emph default
14599  in internal ram.
14600  When compiled with 
14601 \emph on
14602 -
14603 \begin_inset ERT
14604 status collapsed
14605
14606 \begin_layout Standard
14607
14608
14609 \backslash
14610 /
14611 \end_layout
14612
14613 \end_inset
14614
14615 -stack-auto
14616 \emph default
14617  or when a function is declared as 
14618 \emph on
14619 reentrant
14620 \emph default
14621  this should only be done for static variables.
14622 \end_layout
14623
14624 \begin_layout Standard
14625 Parameters
14626 \begin_inset LatexCommand index
14627 name "function parameter"
14628
14629 \end_inset
14630
14631  however are not allowed any storage class
14632 \begin_inset LatexCommand index
14633 name "Storage class"
14634
14635 \end_inset
14636
14637 , (storage classes for parameters will be ignored), their allocation is
14638  governed by the memory model in use, and the reentrancy options.
14639 \end_layout
14640
14641 \begin_layout Standard
14642 It is however allowed to use bit parameters in reentrant functions and also
14643  non-static local bit variables are supported.
14644  Efficient use is limited to 8 semi-bitregisters in bit space.
14645  They are pushed and popped to stack
14646 \begin_inset LatexCommand index
14647 name "stack"
14648
14649 \end_inset
14650
14651  as a single byte just like the normal registers.
14652 \end_layout
14653
14654 \begin_layout Section
14655 Overlaying
14656 \begin_inset LatexCommand label
14657 name "sub:Overlaying"
14658
14659 \end_inset
14660
14661
14662 \begin_inset LatexCommand index
14663 name "Overlaying"
14664
14665 \end_inset
14666
14667
14668 \end_layout
14669
14670 \begin_layout Standard
14671 For non-reentrant
14672 \begin_inset LatexCommand index
14673 name "reentrant"
14674
14675 \end_inset
14676
14677  functions SDCC will try to reduce internal ram space usage by overlaying
14678  parameters and local variables of a function (if possible).
14679  Parameters and local variables
14680 \begin_inset LatexCommand index
14681 name "local variables"
14682
14683 \end_inset
14684
14685  of a function will be allocated to an overlayable segment if the function
14686  has 
14687 \emph on
14688 no other function calls and the function is non-reentrant and the memory
14689  model
14690 \begin_inset LatexCommand index
14691 name "Memory model"
14692
14693 \end_inset
14694
14695  is small.
14696
14697 \emph default
14698  If an explicit storage class
14699 \begin_inset LatexCommand index
14700 name "Storage class"
14701
14702 \end_inset
14703
14704  is specified for a local variable, it will NOT be overlaid.
14705 \end_layout
14706
14707 \begin_layout Standard
14708 Note that the compiler (not the linkage editor) makes the decision for overlayin
14709 g the data items.
14710  Functions that are called from an interrupt service routine
14711 \begin_inset Marginal
14712 status collapsed
14713
14714 \begin_layout Standard
14715
14716 \series bold
14717 !
14718 \end_layout
14719
14720 \end_inset
14721
14722  should be preceded by a #pragma\InsetSpace ~
14723 nooverlay
14724 \begin_inset LatexCommand index
14725 name "\\#pragma nooverlay"
14726
14727 \end_inset
14728
14729  if they are not reentrant.
14730 \end_layout
14731
14732 \begin_layout Standard
14733 Also note that the compiler does not do any processing of inline assembler
14734  code, so the compiler might incorrectly assign local variables and parameters
14735  of a function into the overlay segment if the inline assembler code calls
14736  other c-functions that might use the overlay.
14737  In that case the #pragma\InsetSpace ~
14738 nooverlay should be used.
14739 \end_layout
14740
14741 \begin_layout Standard
14742 Parameters and local variables of functions that contain 16 or 32 bit multiplica
14743 tion
14744 \begin_inset LatexCommand index
14745 name "Multiplication"
14746
14747 \end_inset
14748
14749  or division
14750 \begin_inset LatexCommand index
14751 name "Division"
14752
14753 \end_inset
14754
14755  will NOT be overlaid since these are implemented using external functions,
14756  e.g.:
14757 \end_layout
14758
14759 \begin_layout Verse
14760
14761 \family typewriter
14762 #pragma save 
14763 \newline
14764 #pragma nooverlay
14765 \begin_inset LatexCommand index
14766 name "\\#pragma nooverlay"
14767
14768 \end_inset
14769
14770  
14771 \newline
14772 void set_error(unsigned char errcd) 
14773 \newline
14774 {
14775 \newline
14776 \InsetSpace ~
14777 \InsetSpace ~
14778 \InsetSpace ~
14779 \InsetSpace ~
14780 P3 = errcd;
14781 \newline
14782
14783 \newline
14784 #pragma restore 
14785 \newline
14786
14787 \newline
14788 void
14789  some_isr () __interrupt
14790 \begin_inset LatexCommand index
14791 name "interrupt"
14792
14793 \end_inset
14794
14795  (2)
14796 \newline
14797 {
14798 \newline
14799 \InsetSpace ~
14800 \InsetSpace ~
14801 \InsetSpace ~
14802 \InsetSpace ~
14803 ...
14804 \newline
14805 \InsetSpace ~
14806 \InsetSpace ~
14807 \InsetSpace ~
14808 \InsetSpace ~
14809 set_error(10);
14810 \newline
14811 \InsetSpace ~
14812 \InsetSpace ~
14813 \InsetSpace ~
14814 \InsetSpace ~
14815 ...
14816  
14817 \newline
14818 }
14819 \end_layout
14820
14821 \begin_layout Standard
14822 In the above example the parameter 
14823 \emph on
14824 errcd
14825 \emph default
14826  for the function 
14827 \emph on
14828 set_error
14829 \emph default
14830  would be assigned to the overlayable segment if the #pragma\InsetSpace ~
14831 nooverlay was
14832  not present, this could cause unpredictable runtime behavior when called
14833  from an interrupt service routine.
14834  The #pragma\InsetSpace ~
14835 nooverlay ensures that the parameters and local variables for
14836  the function are NOT overlaid.
14837 \begin_inset VSpace bigskip
14838 \end_inset
14839
14840
14841 \end_layout
14842
14843 \begin_layout Section
14844 Interrupt Service Routines
14845 \begin_inset LatexCommand label
14846 name "sub:Interrupt-Service-Routines"
14847
14848 \end_inset
14849
14850
14851 \end_layout
14852
14853 \begin_layout Subsection
14854 General Information
14855 \end_layout
14856
14857 \begin_layout Standard
14858 SDCC allows 
14859 \emph on
14860 i
14861 \emph default
14862 nterrupt 
14863 \emph on
14864 s
14865 \emph default
14866 ervice 
14867 \emph on
14868 r
14869 \emph default
14870 outines to be coded in C, with some extended keywords.
14871 \end_layout
14872
14873 \begin_layout Verse
14874
14875 \family typewriter
14876 void timer_isr (void) __interrupt (1) __using (1) 
14877 \newline
14878
14879 \newline
14880 \InsetSpace ~
14881 \InsetSpace ~
14882 \InsetSpace ~
14883 \InsetSpace ~
14884 ...
14885  
14886 \newline
14887 }
14888 \end_layout
14889
14890 \begin_layout Standard
14891 The optional number following the 
14892 \emph on
14893 interrupt
14894 \begin_inset LatexCommand index
14895 name "interrupt"
14896
14897 \end_inset
14898
14899
14900 \begin_inset LatexCommand index
14901 name "\\_\\_interrupt"
14902
14903 \end_inset
14904
14905
14906 \emph default
14907  keyword is the interrupt number this routine will service.
14908  When present, the compiler will insert a call to this routine in the interrupt
14909  vector table
14910 \begin_inset LatexCommand index
14911 name "interrupt vector table"
14912
14913 \end_inset
14914
14915  for the interrupt number specified.
14916  If you have multiple source files in your project, interrupt service routines
14917  can be present in any of them, but a prototype of the isr MUST be present
14918  or included in the file that contains the function 
14919 \emph on
14920 main
14921 \emph default
14922 .
14923  The optional (8051 specific) keyword 
14924 \emph on
14925 using
14926 \begin_inset LatexCommand index
14927 name "using (mcs51, ds390 register bank)"
14928
14929 \end_inset
14930
14931
14932 \begin_inset LatexCommand index
14933 name "\\_\\_using (mcs51, ds390 register bank)"
14934
14935 \end_inset
14936
14937
14938 \emph default
14939  can be used to tell the compiler to use the specified register bank when
14940  generating code for this function.
14941  
14942 \newline
14943 Interrupt service routines open the door for some very interesting bugs:
14944 \end_layout
14945
14946 \begin_layout Subsubsection
14947 \begin_inset LatexCommand label
14948 name "sub:Common-interrupt-pitfall-volatile"
14949
14950 \end_inset
14951
14952 Common interrupt pitfall: variable not declared 
14953 \emph on
14954 volatile
14955 \end_layout
14956
14957 \begin_layout Standard
14958 If an interrupt service routine changes variables which are accessed by
14959  other functions these variables have to be declared 
14960 \emph on
14961 volatile
14962 \emph default
14963
14964 \begin_inset LatexCommand index
14965 name "volatile"
14966
14967 \end_inset
14968
14969 .
14970  See 
14971 \begin_inset LatexCommand url
14972 target "http://en.wikipedia.org/wiki/Volatile_variable"
14973
14974 \end_inset
14975
14976  .
14977 \end_layout
14978
14979 \begin_layout Subsubsection
14980 \begin_inset LatexCommand label
14981 name "sub:Common-interrupt-pitfall-non-atomic"
14982
14983 \end_inset
14984
14985 Common interrupt pitfall: 
14986 \emph on
14987 non-atomic access
14988 \end_layout
14989
14990 \begin_layout Standard
14991 If the access to these variables is not 
14992 \emph on
14993 atomic
14994 \begin_inset LatexCommand index
14995 name "atomic"
14996
14997 \end_inset
14998
14999
15000 \emph default
15001  (i.e.
15002  the processor needs more than one instruction for the access and could
15003  be interrupted while accessing the variable) the interrupt must be disabled
15004  during the access to avoid inconsistent data.
15005  
15006 \newline
15007 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
15008  and should be protected by disabling interrupts.
15009  You're not automatically on the safe side if you use 8 bit variables though.
15010  We need an example here: f.e.
15011  on the 8051 the harmless looking 
15012 \begin_inset Quotes srd
15013 \end_inset
15014
15015
15016 \family typewriter
15017 flags\InsetSpace ~
15018 |=\InsetSpace ~
15019 0x80;
15020 \family default
15021
15022 \begin_inset Quotes sld
15023 \end_inset
15024
15025  is not atomic if 
15026 \family typewriter
15027 flags
15028 \family default
15029  resides in xdata.
15030  Setting 
15031 \begin_inset Quotes srd
15032 \end_inset
15033
15034
15035 \family typewriter
15036 flags\InsetSpace ~
15037 |=\InsetSpace ~
15038 0x40;
15039 \family default
15040
15041 \begin_inset Quotes sld
15042 \end_inset
15043
15044  from within an interrupt routine might get lost if the interrupt occurs
15045  at the wrong time.
15046  
15047 \begin_inset Quotes sld
15048 \end_inset
15049
15050
15051 \family typewriter
15052 counter\InsetSpace ~
15053 +=\InsetSpace ~
15054 8;
15055 \family default
15056
15057 \begin_inset Quotes srd
15058 \end_inset
15059
15060  is not atomic on the 8051 even if 
15061 \family typewriter
15062 counter
15063 \family default
15064  is located in data memory.
15065 \newline
15066 Bugs like these are hard to reproduce and can
15067  cause a lot of trouble.
15068  
15069 \end_layout
15070
15071 \begin_layout Subsubsection
15072 \begin_inset LatexCommand label
15073 name "sub:Common-interrupt-pitfall-stack-overflow"
15074
15075 \end_inset
15076
15077 Common interrupt pitfall: 
15078 \emph on
15079 stack overflow
15080 \end_layout
15081
15082 \begin_layout Standard
15083 The return address and the registers used in the interrupt service routine
15084  are saved on the stack
15085 \begin_inset LatexCommand index
15086 name "stack"
15087
15088 \end_inset
15089
15090  so there must be sufficient stack space.
15091  If there isn't variables or registers (or even the return address itself)
15092  will be corrupted.
15093  This 
15094 \emph on
15095 stack overflow
15096 \emph default
15097
15098 \begin_inset LatexCommand index
15099 name "stack overflow"
15100
15101 \end_inset
15102
15103  is most likely to happen if the interrupt occurs during the 
15104 \begin_inset Quotes sld
15105 \end_inset
15106
15107 deepest
15108 \begin_inset Quotes srd
15109 \end_inset
15110
15111  subroutine when the stack is already in use for f.e.
15112  many return addresses.
15113 \end_layout
15114
15115 \begin_layout Subsubsection
15116 \begin_inset LatexCommand label
15117 name "sub:Common-interrupt-pitfall-non-reentrant"
15118
15119 \end_inset
15120
15121 Common interrupt pitfall: 
15122 \emph on
15123 use of non-reentrant functions
15124 \end_layout
15125
15126 \begin_layout Standard
15127 A special note here, int (16 bit) and long (32 bit) integer division
15128 \begin_inset LatexCommand index
15129 name "Division"
15130
15131 \end_inset
15132
15133 , multiplication
15134 \begin_inset LatexCommand index
15135 name "Multiplication"
15136
15137 \end_inset
15138
15139  & modulus
15140 \begin_inset LatexCommand index
15141 name "Modulus"
15142
15143 \end_inset
15144
15145  and floating-point
15146 \begin_inset LatexCommand index
15147 name "Floating point support"
15148
15149 \end_inset
15150
15151  operations are implemented using external support routines.
15152  If an interrupt service routine needs to do any of these operations then
15153  the support routines (as mentioned in a following section) will have to
15154  be recompiled using the 
15155 \emph on
15156 -
15157 \begin_inset ERT
15158 status collapsed
15159
15160 \begin_layout Standard
15161
15162
15163 \backslash
15164 /
15165 \end_layout
15166
15167 \end_inset
15168
15169 -stack-auto
15170 \begin_inset LatexCommand index
15171 name "-\\/-stack-auto"
15172
15173 \end_inset
15174
15175
15176 \emph default
15177  option and the source file will need to be compiled using the 
15178 \emph on
15179 -
15180 \begin_inset ERT
15181 status collapsed
15182
15183 \begin_layout Standard
15184
15185
15186 \backslash
15187 /
15188 \end_layout
15189
15190 \end_inset
15191
15192 -int-long-reent
15193 \emph default
15194
15195 \begin_inset LatexCommand index
15196 name "-\\/-int-long-reent"
15197
15198 \end_inset
15199
15200  compiler option.
15201  
15202 \newline
15203 Note, the type promotion
15204 \begin_inset LatexCommand index
15205 name "type promotion"
15206
15207 \end_inset
15208
15209  required by ANSI C can cause 16 bit routines to be used
15210 \begin_inset Marginal
15211 status collapsed
15212
15213 \begin_layout Standard
15214
15215 \series bold
15216 \InsetSpace ~
15217 !
15218 \end_layout
15219
15220 \end_inset
15221
15222  without the programmer being aware of it.
15223  See f.e.
15224  the cast 
15225 \family typewriter
15226 \series bold
15227 (unsigned char)(tail-1)
15228 \family default
15229 \series default
15230  
15231 \series bold
15232 within the if clause in section 
15233 \begin_inset LatexCommand ref
15234 reference "sub:A-Step-by Assembler Introduction"
15235
15236 \end_inset
15237
15238 .
15239 \end_layout
15240
15241 \begin_layout Standard
15242 Calling other functions from an interrupt service routine is not recommended,
15243  avoid it if possible.
15244  Note that when some function is called from an interrupt service routine
15245  it should be preceded by a #pragma\InsetSpace ~
15246 nooverlay
15247 \begin_inset LatexCommand index
15248 name "\\#pragma nooverlay"
15249
15250 \end_inset
15251
15252  if it is not reentrant.
15253  Furthermore nonreentrant functions should not be called from the main program
15254  while the interrupt service routine might be active.
15255  They also must not be called from low priority interrupt service routines
15256  while a high priority interrupt service routine might be active.
15257  You could use semaphores or make the function 
15258 \emph on
15259 critical
15260 \emph default
15261  if all parameters are passed in registers.
15262 \newline
15263  Also see section 
15264 \begin_inset LatexCommand ref
15265 reference "sub:Overlaying"
15266
15267 \end_inset
15268
15269 \InsetSpace ~
15270 about Overlaying and section 
15271 \begin_inset LatexCommand ref
15272 reference "sub:Functions-using-private-banks"
15273
15274 \end_inset
15275
15276 \InsetSpace ~
15277 about Functions using private register banks.
15278 \begin_inset VSpace bigskip
15279 \end_inset
15280
15281
15282 \end_layout
15283
15284 \begin_layout Subsection
15285 MCS51/DS390 Interrupt Service Routines
15286 \end_layout
15287
15288 \begin_layout Standard
15289 Interrupt
15290 \begin_inset LatexCommand index
15291 name "interrupt"
15292
15293 \end_inset
15294
15295  numbers and the corresponding address & descriptions for the Standard 8051/8052
15296  are listed below.
15297  SDCC will automatically adjust the 
15298 \begin_inset LatexCommand index
15299 name "interrupt vector table"
15300
15301 \end_inset
15302
15303  to the maximum interrupt number specified.
15304 \newline
15305
15306 \end_layout
15307
15308 \begin_layout Standard
15309 \align center
15310 \begin_inset Tabular
15311 <lyxtabular version="3" rows="9" columns="3">
15312 <features>
15313 <column alignment="center" valignment="top" leftline="true" width="0in">
15314 <column alignment="left" valignment="top" leftline="true" width="0in">
15315 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
15316 <row topline="true" bottomline="true">
15317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15318 \begin_inset Text
15319
15320 \begin_layout Standard
15321 Interrupt #
15322 \end_layout
15323
15324 \end_inset
15325 </cell>
15326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15327 \begin_inset Text
15328
15329 \begin_layout Standard
15330 Description
15331 \end_layout
15332
15333 \end_inset
15334 </cell>
15335 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15336 \begin_inset Text
15337
15338 \begin_layout Standard
15339 Vector Address
15340 \end_layout
15341
15342 \end_inset
15343 </cell>
15344 </row>
15345 <row topline="true">
15346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15347 \begin_inset Text
15348
15349 \begin_layout Standard
15350 0
15351 \end_layout
15352
15353 \end_inset
15354 </cell>
15355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15356 \begin_inset Text
15357
15358 \begin_layout Standard
15359 External 0
15360 \end_layout
15361
15362 \end_inset
15363 </cell>
15364 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15365 \begin_inset Text
15366
15367 \begin_layout Standard
15368 0x0003
15369 \end_layout
15370
15371 \end_inset
15372 </cell>
15373 </row>
15374 <row topline="true">
15375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15376 \begin_inset Text
15377
15378 \begin_layout Standard
15379 1
15380 \end_layout
15381
15382 \end_inset
15383 </cell>
15384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15385 \begin_inset Text
15386
15387 \begin_layout Standard
15388 Timer 0
15389 \end_layout
15390
15391 \end_inset
15392 </cell>
15393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15394 \begin_inset Text
15395
15396 \begin_layout Standard
15397 0x000b
15398 \end_layout
15399
15400 \end_inset
15401 </cell>
15402 </row>
15403 <row topline="true">
15404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15405 \begin_inset Text
15406
15407 \begin_layout Standard
15408 2
15409 \end_layout
15410
15411 \end_inset
15412 </cell>
15413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15414 \begin_inset Text
15415
15416 \begin_layout Standard
15417 External 1
15418 \end_layout
15419
15420 \end_inset
15421 </cell>
15422 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15423 \begin_inset Text
15424
15425 \begin_layout Standard
15426 0x0013
15427 \end_layout
15428
15429 \end_inset
15430 </cell>
15431 </row>
15432 <row topline="true">
15433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15434 \begin_inset Text
15435
15436 \begin_layout Standard
15437 3
15438 \end_layout
15439
15440 \end_inset
15441 </cell>
15442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15443 \begin_inset Text
15444
15445 \begin_layout Standard
15446 Timer 1
15447 \end_layout
15448
15449 \end_inset
15450 </cell>
15451 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15452 \begin_inset Text
15453
15454 \begin_layout Standard
15455 0x001b
15456 \end_layout
15457
15458 \end_inset
15459 </cell>
15460 </row>
15461 <row topline="true">
15462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15463 \begin_inset Text
15464
15465 \begin_layout Standard
15466 4
15467 \end_layout
15468
15469 \end_inset
15470 </cell>
15471 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15472 \begin_inset Text
15473
15474 \begin_layout Standard
15475 Serial
15476 \end_layout
15477
15478 \end_inset
15479 </cell>
15480 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15481 \begin_inset Text
15482
15483 \begin_layout Standard
15484 0x0023
15485 \end_layout
15486
15487 \end_inset
15488 </cell>
15489 </row>
15490 <row topline="true">
15491 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15492 \begin_inset Text
15493
15494 \begin_layout Standard
15495 5
15496 \end_layout
15497
15498 \end_inset
15499 </cell>
15500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15501 \begin_inset Text
15502
15503 \begin_layout Standard
15504 Timer 2 (8052)
15505 \end_layout
15506
15507 \end_inset
15508 </cell>
15509 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15510 \begin_inset Text
15511
15512 \begin_layout Standard
15513 0x002b
15514 \end_layout
15515
15516 \end_inset
15517 </cell>
15518 </row>
15519 <row topline="true">
15520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15521 \begin_inset Text
15522
15523 \begin_layout Standard
15524 ...
15525 \end_layout
15526
15527 \end_inset
15528 </cell>
15529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15530 \begin_inset Text
15531
15532 \begin_layout Standard
15533
15534 \end_layout
15535
15536 \end_inset
15537 </cell>
15538 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15539 \begin_inset Text
15540
15541 \begin_layout Standard
15542 ...
15543 \end_layout
15544
15545 \end_inset
15546 </cell>
15547 </row>
15548 <row topline="true" bottomline="true">
15549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15550 \begin_inset Text
15551
15552 \begin_layout Standard
15553 n
15554 \end_layout
15555
15556 \end_inset
15557 </cell>
15558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15559 \begin_inset Text
15560
15561 \begin_layout Standard
15562
15563 \end_layout
15564
15565 \end_inset
15566 </cell>
15567 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15568 \begin_inset Text
15569
15570 \begin_layout Standard
15571 0x0003 + 8*n
15572 \end_layout
15573
15574 \end_inset
15575 </cell>
15576 </row>
15577 </lyxtabular>
15578
15579 \end_inset
15580
15581
15582 \newline
15583
15584 \end_layout
15585
15586 \begin_layout Standard
15587 If the interrupt service routine is defined without 
15588 \emph on
15589 using
15590 \begin_inset LatexCommand index
15591 name "using (mcs51, ds390 register bank)"
15592
15593 \end_inset
15594
15595
15596 \begin_inset LatexCommand index
15597 name "\\_\\_using (mcs51, ds390 register bank)"
15598
15599 \end_inset
15600
15601
15602 \emph default
15603  a register bank or with register bank 0 (
15604 \emph on
15605 using
15606 \emph default
15607  0), the compiler will save the registers used by itself on the stack upon
15608  entry and restore them at exit, however if such an interrupt service routine
15609  calls another function then the entire register bank will be saved on the
15610  stack.
15611  This scheme may be advantageous for small interrupt service routines which
15612  have low register usage.
15613 \end_layout
15614
15615 \begin_layout Standard
15616 If the interrupt service routine is defined to be using a specific register
15617  bank then only 
15618 \emph on
15619 a, b, dptr
15620 \emph default
15621  & psw are saved and restored, if such an interrupt service routine calls
15622  another function (using another register bank) then the entire register
15623  bank of the called function will be saved on the stack
15624 \begin_inset LatexCommand index
15625 name "stack"
15626
15627 \end_inset
15628
15629 .
15630  This scheme is recommended for larger interrupt service routines.
15631 \begin_inset VSpace bigskip
15632 \end_inset
15633
15634
15635 \end_layout
15636
15637 \begin_layout Subsection
15638 HC08
15639 \begin_inset LatexCommand index
15640 name "HC08"
15641
15642 \end_inset
15643
15644  Interrupt Service Routines
15645 \end_layout
15646
15647 \begin_layout Standard
15648 Since the number of interrupts
15649 \begin_inset LatexCommand index
15650 name "HC08!interrupt"
15651
15652 \end_inset
15653
15654  available is chip specific and the interrupt vector table always ends at
15655  the last byte of memory, the interrupt numbers corresponds to the interrupt
15656  vectors in reverse order of address.
15657  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
15658  2 will use the interrupt vector at 0xfffa, and so on.
15659  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
15660  this way; instead see section 
15661 \begin_inset LatexCommand ref
15662 reference "sub:Startup-Code"
15663
15664 \end_inset
15665
15666  for details on customizing startup.
15667 \begin_inset VSpace bigskip
15668 \end_inset
15669
15670
15671 \end_layout
15672
15673 \begin_layout Subsection
15674 Z80 Interrupt Service Routines
15675 \end_layout
15676
15677 \begin_layout Standard
15678 The Z80
15679 \begin_inset LatexCommand index
15680 name "Z80"
15681
15682 \end_inset
15683
15684  uses several different methods for determining the correct interrupt
15685 \begin_inset LatexCommand index
15686 name "Z80!interrupt"
15687
15688 \end_inset
15689
15690  vector depending on the hardware implementation.
15691  Therefore, SDCC ignores the optional interrupt number and does not attempt
15692  to generate an interrupt vector table.
15693 \end_layout
15694
15695 \begin_layout Standard
15696 By default, SDCC generates code for a maskable interrupt, which uses a RETI
15697  instruction to return from the interrupt.
15698  To write an interrupt handler for the non-maskable interrupt, which needs
15699  a RETN instruction instead, add the 
15700 \emph on
15701 critical
15702 \emph default
15703  keyword:
15704 \end_layout
15705
15706 \begin_layout Verse
15707
15708 \family typewriter
15709 void nmi_isr (void) critical interrupt
15710 \newline
15711
15712 \newline
15713 \InsetSpace ~
15714 \InsetSpace ~
15715 \InsetSpace ~
15716 \InsetSpace ~
15717 ...
15718  
15719 \newline
15720 }
15721 \end_layout
15722
15723 \begin_layout Standard
15724 However if you need to create a non-interruptable interrupt service routine
15725  you would also require the 
15726 \emph on
15727 critical
15728 \emph default
15729  keyword.
15730  To distinguish between this and an nmi_isr you must provide an interrupt
15731  number.
15732 \begin_inset VSpace bigskip
15733 \end_inset
15734
15735
15736 \end_layout
15737
15738 \begin_layout Section
15739 Enabling and Disabling Interrupts
15740 \end_layout
15741
15742 \begin_layout Subsection
15743 Critical Functions and Critical Statements
15744 \end_layout
15745
15746 \begin_layout Standard
15747 A special keyword may be associated with a block or a function declaring
15748  it as 
15749 \emph on
15750 critical
15751 \emph default
15752 .
15753  SDCC will generate code to disable all interrupts
15754 \begin_inset LatexCommand index
15755 name "interrupt"
15756
15757 \end_inset
15758
15759  upon entry to a critical function and restore the interrupt enable to the
15760  previous state before returning.
15761  Nesting critical functions will need one additional byte on the stack
15762 \begin_inset LatexCommand index
15763 name "stack"
15764
15765 \end_inset
15766
15767  for each call.
15768 \end_layout
15769
15770 \begin_layout Verse
15771
15772 \family typewriter
15773 int foo () __critical
15774 \begin_inset LatexCommand index
15775 name "critical"
15776
15777 \end_inset
15778
15779
15780 \begin_inset LatexCommand index
15781 name "\\_\\_critical"
15782
15783 \end_inset
15784
15785  
15786 \newline
15787
15788 \newline
15789 \InsetSpace ~
15790 \InsetSpace ~
15791 \InsetSpace ~
15792 \InsetSpace ~
15793 ...
15794  
15795 \newline
15796 \InsetSpace ~
15797 \InsetSpace ~
15798 \InsetSpace ~
15799 \InsetSpace ~
15800 ...
15801  
15802 \newline
15803 }
15804 \end_layout
15805
15806 \begin_layout Standard
15807 The critical attribute maybe used with other attributes like 
15808 \emph on
15809 reentrant.
15810 \emph default
15811
15812 \newline
15813 The keyword 
15814 \emph on
15815 critical
15816 \emph default
15817  may also be used to disable interrupts more locally:
15818 \end_layout
15819
15820 \begin_layout Verse
15821
15822 \family typewriter
15823 __critical{ i++; }
15824 \end_layout
15825
15826 \begin_layout Standard
15827 More than one statement could have been included in the block.
15828 \end_layout
15829
15830 \begin_layout Subsection
15831 Enabling and Disabling Interrupts directly
15832 \end_layout
15833
15834 \begin_layout Standard
15835 Interrupts
15836 \begin_inset LatexCommand index
15837 name "interrupt"
15838
15839 \end_inset
15840
15841  can also be disabled and enabled directly (8051):
15842 \end_layout
15843
15844 \begin_layout Verse
15845
15846 \family typewriter
15847 EA = 0;\InsetSpace ~
15848 \InsetSpace ~
15849 \InsetSpace ~
15850 \InsetSpace ~
15851 \InsetSpace ~
15852 \InsetSpace ~
15853 \InsetSpace ~
15854 \InsetSpace ~
15855 \InsetSpace ~
15856 \InsetSpace ~
15857 \InsetSpace ~
15858 \InsetSpace ~
15859 or:\InsetSpace ~
15860 \InsetSpace ~
15861 \InsetSpace ~
15862 \InsetSpace ~
15863 \InsetSpace ~
15864 \InsetSpace ~
15865 \InsetSpace ~
15866 \InsetSpace ~
15867 \InsetSpace ~
15868 \InsetSpace ~
15869 \InsetSpace ~
15870 EA_SAVE = EA;
15871 \end_layout
15872
15873 \begin_layout Verse
15874
15875 \family typewriter
15876 ...\InsetSpace ~
15877 \InsetSpace ~
15878 \InsetSpace ~
15879 \InsetSpace ~
15880 \InsetSpace ~
15881 \InsetSpace ~
15882 \InsetSpace ~
15883 \InsetSpace ~
15884 \InsetSpace ~
15885 \InsetSpace ~
15886 \InsetSpace ~
15887 \InsetSpace ~
15888 \InsetSpace ~
15889 \InsetSpace ~
15890 \InsetSpace ~
15891 \InsetSpace ~
15892 \InsetSpace ~
15893 \InsetSpace ~
15894 \InsetSpace ~
15895 \InsetSpace ~
15896 \InsetSpace ~
15897 \InsetSpace ~
15898 \InsetSpace ~
15899 \InsetSpace ~
15900 \InsetSpace ~
15901 \InsetSpace ~
15902 \InsetSpace ~
15903 \InsetSpace ~
15904 \InsetSpace ~
15905 \InsetSpace ~
15906 EA = 0;
15907 \end_layout
15908
15909 \begin_layout Verse
15910
15911 \family typewriter
15912 EA = 1;\InsetSpace ~
15913 \InsetSpace ~
15914 \InsetSpace ~
15915 \InsetSpace ~
15916 \InsetSpace ~
15917 \InsetSpace ~
15918 \InsetSpace ~
15919 \InsetSpace ~
15920 \InsetSpace ~
15921 \InsetSpace ~
15922 \InsetSpace ~
15923 \InsetSpace ~
15924 \InsetSpace ~
15925 \InsetSpace ~
15926 \InsetSpace ~
15927 \InsetSpace ~
15928 \InsetSpace ~
15929 \InsetSpace ~
15930 \InsetSpace ~
15931 \InsetSpace ~
15932 \InsetSpace ~
15933 \InsetSpace ~
15934 \InsetSpace ~
15935 \InsetSpace ~
15936 \InsetSpace ~
15937 \InsetSpace ~
15938 ...
15939 \end_layout
15940
15941 \begin_layout Verse
15942
15943 \family typewriter
15944 \InsetSpace ~
15945 \InsetSpace ~
15946 \InsetSpace ~
15947 \InsetSpace ~
15948 \InsetSpace ~
15949 \InsetSpace ~
15950 \InsetSpace ~
15951 \InsetSpace ~
15952 \InsetSpace ~
15953 \InsetSpace ~
15954 \InsetSpace ~
15955 \InsetSpace ~
15956 \InsetSpace ~
15957 \InsetSpace ~
15958 \InsetSpace ~
15959 \InsetSpace ~
15960 \InsetSpace ~
15961 \InsetSpace ~
15962 \InsetSpace ~
15963 \InsetSpace ~
15964 \InsetSpace ~
15965 \InsetSpace ~
15966 \InsetSpace ~
15967 \InsetSpace ~
15968 \InsetSpace ~
15969 \InsetSpace ~
15970 \InsetSpace ~
15971 \InsetSpace ~
15972 \InsetSpace ~
15973 \InsetSpace ~
15974 \InsetSpace ~
15975 \InsetSpace ~
15976 \InsetSpace ~
15977 EA = EA_SAVE;
15978 \end_layout
15979
15980 \begin_layout Standard
15981 On other architectures which have separate opcodes for enabling and disabling
15982  interrupts you might want to make use of defines with inline assembly
15983 \begin_inset LatexCommand index
15984 name "Assembler routines"
15985
15986 \end_inset
15987
15988  (HC08
15989 \begin_inset LatexCommand index
15990 name "HC08!interrupt"
15991
15992 \end_inset
15993
15994 ):
15995 \end_layout
15996
15997 \begin_layout Verse
15998
15999 \family typewriter
16000 #define CLI _asm
16001 \begin_inset LatexCommand index
16002 name "\\_asm"
16003
16004 \end_inset
16005
16006 \InsetSpace ~
16007 \InsetSpace ~
16008 cli\InsetSpace ~
16009 \InsetSpace ~
16010 _endasm
16011 \begin_inset LatexCommand index
16012 name "\\_endasm"
16013
16014 \end_inset
16015
16016
16017 \end_layout
16018
16019 \begin_layout Verse
16020
16021 \family typewriter
16022 #define SEI _asm\InsetSpace ~
16023 \InsetSpace ~
16024 sei\InsetSpace ~
16025 \InsetSpace ~
16026 _endasm; 
16027 \end_layout
16028
16029 \begin_layout Verse
16030
16031 \family typewriter
16032 ...
16033 \end_layout
16034
16035 \begin_layout Standard
16036 Note: it is sometimes sufficient to disable only a specific interrupt source
16037  like f.e.
16038  a timer or serial interrupt by manipulating an 
16039 \emph on
16040 interrupt mask
16041 \begin_inset LatexCommand index
16042 name "interrupt mask"
16043
16044 \end_inset
16045
16046
16047 \emph default
16048  register.
16049  
16050 \end_layout
16051
16052 \begin_layout Standard
16053 Usually the time during which interrupts are disabled should be kept as
16054  short as possible.
16055  This minimizes both 
16056 \emph on
16057 interrupt latency
16058 \emph default
16059
16060 \begin_inset LatexCommand index
16061 name "interrupt latency"
16062
16063 \end_inset
16064
16065  (the time between the occurrence of the interrupt and the execution of
16066  the first code in the interrupt routine) and 
16067 \emph on
16068 interrupt jitter
16069 \emph default
16070
16071 \begin_inset LatexCommand index
16072 name "interrupt jitter"
16073
16074 \end_inset
16075
16076  (the difference between the shortest and the longest interrupt latency).
16077  These really are something different, f.e.
16078  a serial interrupt has to be served before its buffer overruns so it cares
16079  for the maximum interrupt latency, whereas it does not care about jitter.
16080  On a loudspeaker driven via a digital to analog converter which is fed
16081  by an interrupt a latency of a few milliseconds might be tolerable, whereas
16082  a much smaller jitter will be very audible.
16083 \end_layout
16084
16085 \begin_layout Standard
16086 You can reenable interrupts within an interrupt routine and on some architecture
16087 s you can make use of two (or more) levels of 
16088 \emph on
16089 interrupt priorities
16090 \emph default
16091
16092 \begin_inset LatexCommand index
16093 name "interrupt priority"
16094
16095 \end_inset
16096
16097 .
16098  On some architectures which don't support interrupt priorities these can
16099  be implemented by manipulating the interrupt mask and reenabling interrupts
16100  within the interrupt routine.
16101  Check there is sufficient space on the stack
16102 \begin_inset LatexCommand index
16103 name "stack"
16104
16105 \end_inset
16106
16107  and don't add complexity unless you have to.
16108  
16109 \end_layout
16110
16111 \begin_layout Subsection
16112 Semaphore
16113 \begin_inset LatexCommand index
16114 name "semaphore"
16115
16116 \end_inset
16117
16118  locking (mcs51/ds390)
16119 \end_layout
16120
16121 \begin_layout Standard
16122 Some architectures (mcs51/ds390) have an atomic
16123 \begin_inset LatexCommand index
16124 name "atomic"
16125
16126 \end_inset
16127
16128  bit test and clear instruction.
16129  These type of instructions are typically used in preemptive multitasking
16130  systems, where a routine f.e.
16131  claims the use of a data structure ('acquires a lock
16132 \begin_inset LatexCommand index
16133 name "lock"
16134
16135 \end_inset
16136
16137  on it'), makes some modifications and then releases the lock when the data
16138  structure is consistent again.
16139  The instruction may also be used if interrupt and non-interrupt code have
16140  to compete for a resource.
16141  With the atomic bit test and clear instruction interrupts
16142 \begin_inset LatexCommand index
16143 name "interrupt"
16144
16145 \end_inset
16146
16147  don't have to be disabled for the locking operation.
16148  
16149 \end_layout
16150
16151 \begin_layout Standard
16152 SDCC generates this instruction if the source follows this pattern:
16153 \end_layout
16154
16155 \begin_layout Verse
16156
16157 \family typewriter
16158 volatile
16159 \begin_inset LatexCommand index
16160 name "volatile"
16161
16162 \end_inset
16163
16164  bit resource_is_free; 
16165 \newline
16166
16167 \newline
16168 if (resource_is_free) 
16169 \newline
16170 \InsetSpace ~
16171 \InsetSpace ~
16172
16173 \newline
16174 \InsetSpace ~
16175 \InsetSpace ~
16176 \InsetSpace ~
16177 \InsetSpace ~
16178 resource_is_free=0; 
16179 \newline
16180 \InsetSpace ~
16181 \InsetSpace ~
16182 \InsetSpace ~
16183 \InsetSpace ~
16184 ...
16185  
16186 \newline
16187 \InsetSpace ~
16188 \InsetSpace ~
16189 \InsetSpace ~
16190 \InsetSpace ~
16191 resource_is_free=1;
16192 \newline
16193 \InsetSpace ~
16194 \InsetSpace ~
16195
16196 \end_layout
16197
16198 \begin_layout Standard
16199 Note, mcs51 and ds390 support only an atomic
16200 \begin_inset LatexCommand index
16201 name "atomic"
16202
16203 \end_inset
16204
16205  bit test and 
16206 \emph on
16207 clear
16208 \emph default
16209  instruction (as opposed to atomic bit test and 
16210 \emph on
16211 set).
16212 \end_layout
16213
16214 \begin_layout Section
16215 Functions using private register banks
16216 \begin_inset LatexCommand label
16217 name "sub:Functions-using-private-banks"
16218
16219 \end_inset
16220
16221  (mcs51/ds390)
16222 \end_layout
16223
16224 \begin_layout Standard
16225 Some architectures have support for quickly changing register sets.
16226  SDCC supports this feature with the 
16227 \emph on
16228 using
16229 \begin_inset LatexCommand index
16230 name "using (mcs51, ds390 register bank)"
16231
16232 \end_inset
16233
16234
16235 \begin_inset LatexCommand index
16236 name "\\_\\_using (mcs51, ds390 register bank)"
16237
16238 \end_inset
16239
16240
16241 \emph default
16242  attribute (which tells the compiler to use a register bank
16243 \begin_inset LatexCommand index
16244 name "register bank (mcs51, ds390)"
16245
16246 \end_inset
16247
16248  other than the default bank zero).
16249  It should only be applied to 
16250 \emph on
16251 interrupt
16252 \begin_inset LatexCommand index
16253 name "interrupt"
16254
16255 \end_inset
16256
16257
16258 \emph default
16259  functions (see footnote below).
16260  This will in most circumstances make the generated ISR code more efficient
16261  since it will not have to save registers on the stack.
16262 \end_layout
16263
16264 \begin_layout Standard
16265 The 
16266 \emph on
16267 using
16268 \emph default
16269  attribute will have no effect on the generated code for a 
16270 \emph on
16271 non-interrupt
16272 \emph default
16273  function (but may occasionally be useful anyway
16274 \begin_inset Foot
16275 status open
16276
16277 \begin_layout Standard
16278 possible exception: if a function is called ONLY from 'interrupt' functions
16279  using a particular bank, it can be declared with the same 'using' attribute
16280  as the calling 'interrupt' functions.
16281  For instance, if you have several ISRs using bank one, and all of them
16282  call memcpy(), it might make sense to create a specialized version of memcpy()
16283  'using 1', since this would prevent the ISR from having to save bank zero
16284  to the stack on entry and switch to bank zero before calling the function
16285 \end_layout
16286
16287 \end_inset
16288
16289 ).
16290 \newline
16291
16292 \emph on
16293 (pending: Note, nowadays the
16294 \emph default
16295  using 
16296 \emph on
16297 attribute has an effect on
16298 \emph default
16299  
16300 \emph on
16301 the generated code for a
16302 \emph default
16303  non-interrupt 
16304 \emph on
16305 function
16306 \emph default
16307 .
16308 \emph on
16309 )
16310 \end_layout
16311
16312 \begin_layout Standard
16313 An 
16314 \emph on
16315 interrupt
16316 \emph default
16317  function using a non-zero bank will assume that it can trash that register
16318  bank, and will not save it.
16319  Since high-priority interrupts
16320 \begin_inset LatexCommand index
16321 name "interrupts"
16322
16323 \end_inset
16324
16325
16326 \begin_inset LatexCommand index
16327 name "interrupt priority"
16328
16329 \end_inset
16330
16331  can interrupt low-priority ones on the 8051 and friends, this means that
16332  if a high-priority ISR 
16333 \emph on
16334 using
16335 \emph default
16336  a particular bank occurs while processing a low-priority ISR 
16337 \emph on
16338 using
16339 \emph default
16340  the same bank, terrible and bad things can happen.
16341  To prevent this, no single register bank should be 
16342 \emph on
16343 used
16344 \emph default
16345  by both a high priority and a low priority ISR.
16346  This is probably most easily done by having all high priority ISRs use
16347  one bank and all low priority ISRs use another.
16348  If you have an ISR which can change priority at runtime, you're on your
16349  own: I suggest using the default bank zero and taking the small performance
16350  hit.
16351 \end_layout
16352
16353 \begin_layout Standard
16354 It is most efficient if your ISR calls no other functions.
16355  If your ISR must call other functions, it is most efficient if those functions
16356  use the same bank as the ISR (see note 1 below); the next best is if the
16357  called functions use bank zero.
16358  It is very inefficient to call a function using a different, non-zero bank
16359  from an ISR.
16360  
16361 \begin_inset VSpace bigskip
16362 \end_inset
16363
16364
16365 \end_layout
16366
16367 \begin_layout Section
16368 Startup Code
16369 \begin_inset LatexCommand label
16370 name "sub:Startup-Code"
16371
16372 \end_inset
16373
16374
16375 \begin_inset LatexCommand index
16376 name "Startup code"
16377
16378 \end_inset
16379
16380
16381 \end_layout
16382
16383 \begin_layout Subsection
16384 MCS51/DS390 Startup Code
16385 \end_layout
16386
16387 \begin_layout Standard
16388 The compiler triggers the linker to link certain initialization modules
16389  from the runtime library
16390 \begin_inset LatexCommand index
16391 name "Runtime library"
16392
16393 \end_inset
16394
16395  called crt<something>.
16396  Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
16397  GSINIT5) is not linked unless the -
16398 \series bold
16399
16400 \begin_inset ERT
16401 status open
16402
16403 \begin_layout Standard
16404
16405
16406 \backslash
16407 /
16408 \end_layout
16409
16410 \end_inset
16411
16412
16413 \series default
16414 -xstack option is used.
16415  These modules are highly entangled by the use of special segments/areas,
16416  but a common layout is shown below:
16417 \end_layout
16418
16419 \begin_layout Verse
16420
16421 \family typewriter
16422 \series bold
16423 \size footnotesize
16424 (main.asm)
16425 \end_layout
16426
16427 \begin_layout Verse
16428
16429 \family typewriter
16430 \size footnotesize
16431 \InsetSpace ~
16432 \InsetSpace ~
16433 \InsetSpace ~
16434 \InsetSpace ~
16435 \InsetSpace ~
16436 \InsetSpace ~
16437 \InsetSpace ~
16438 \InsetSpace ~
16439 .area HOME (CODE)
16440 \newline
16441 __interrupt_vect:
16442 \newline
16443 \InsetSpace ~
16444 \InsetSpace ~
16445 \InsetSpace ~
16446 \InsetSpace ~
16447 \InsetSpace ~
16448 \InsetSpace ~
16449 \InsetSpace ~
16450 \InsetSpace ~
16451 ljmp __sdcc_gsinit_startup
16452 \end_layout
16453
16454 \begin_layout Verse
16455
16456 \family typewriter
16457 \series bold
16458 \size footnotesize
16459 (crtstart.asm)
16460 \end_layout
16461
16462 \begin_layout Verse
16463
16464 \family typewriter
16465 \size footnotesize
16466 \InsetSpace ~
16467 \InsetSpace ~
16468 \InsetSpace ~
16469 \InsetSpace ~
16470 \InsetSpace ~
16471 \InsetSpace ~
16472 \InsetSpace ~
16473 \InsetSpace ~
16474 .area GSINIT0 (CODE)
16475 \newline
16476 __sdcc_gsinit_startup::
16477 \newline
16478 \InsetSpace ~
16479 \InsetSpace ~
16480 \InsetSpace ~
16481 \InsetSpace ~
16482 \InsetSpace ~
16483 \InsetSpace ~
16484 \InsetSpace ~
16485 \InsetSpace ~
16486 mov sp,#__start__stack - 1
16487 \end_layout
16488
16489 \begin_layout Verse
16490
16491 \family typewriter
16492 \series bold
16493 \size footnotesize
16494 (crtxstack.asm)
16495 \end_layout
16496
16497 \begin_layout Verse
16498
16499 \family typewriter
16500 \size footnotesize
16501 \InsetSpace ~
16502 \InsetSpace ~
16503 \InsetSpace ~
16504 \InsetSpace ~
16505 \InsetSpace ~
16506 \InsetSpace ~
16507 \InsetSpace ~
16508 \InsetSpace ~
16509 .area GSINIT1 (CODE)
16510 \newline
16511 __sdcc_init_xstack::
16512 \newline
16513 ; Need to initialize in GSINIT1 in
16514  case the user's __sdcc_external_startup uses the xstack.
16515 \newline
16516 \InsetSpace ~
16517 \InsetSpace ~
16518 \InsetSpace ~
16519 \InsetSpace ~
16520 \InsetSpace ~
16521 \InsetSpace ~
16522 \InsetSpace ~
16523 \InsetSpace ~
16524 mov __XPAGE,#(__start__x
16525 stack >> 8)
16526 \newline
16527 \InsetSpace ~
16528 \InsetSpace ~
16529 \InsetSpace ~
16530 \InsetSpace ~
16531 \InsetSpace ~
16532 \InsetSpace ~
16533 \InsetSpace ~
16534 \InsetSpace ~
16535 mov _spx,#__start__xstack
16536 \end_layout
16537
16538 \begin_layout Verse
16539
16540 \family typewriter
16541 \series bold
16542 \size footnotesize
16543 (crtstart.asm)
16544 \end_layout
16545
16546 \begin_layout Verse
16547
16548 \family typewriter
16549 \size footnotesize
16550 \InsetSpace ~
16551 \InsetSpace ~
16552 \InsetSpace ~
16553 \InsetSpace ~
16554 \InsetSpace ~
16555 \InsetSpace ~
16556 \InsetSpace ~
16557 \InsetSpace ~
16558 .area GSINIT2 (CODE)
16559 \newline
16560 \InsetSpace ~
16561 \InsetSpace ~
16562 \InsetSpace ~
16563 \InsetSpace ~
16564 \InsetSpace ~
16565 \InsetSpace ~
16566 \InsetSpace ~
16567 \InsetSpace ~
16568 lcall __sdcc_external_startup
16569 \newline
16570 \InsetSpace ~
16571 \InsetSpace ~
16572 \InsetSpace ~
16573 \InsetSpace ~
16574 \InsetSpace ~
16575 \InsetSpace ~
16576 \InsetSpace ~
16577 \InsetSpace ~
16578 mov a,dpl
16579 \newline
16580 \InsetSpace ~
16581 \InsetSpace ~
16582 \InsetSpace ~
16583 \InsetSpace ~
16584 \InsetSpace ~
16585 \InsetSpace ~
16586 \InsetSpace ~
16587 \InsetSpace ~
16588 jz __sdcc_init_data
16589 \newline
16590 \InsetSpace ~
16591 \InsetSpace ~
16592 \InsetSpace ~
16593 \InsetSpace ~
16594 \InsetSpace ~
16595 \InsetSpace ~
16596 \InsetSpace ~
16597 \InsetSpace ~
16598 ljmp
16599  __sdcc_program_startup
16600 \newline
16601 __sdcc_init_data:
16602 \end_layout
16603
16604 \begin_layout Verse
16605
16606 \family typewriter
16607 \series bold
16608 \size footnotesize
16609 (crtxinit.asm)
16610 \end_layout
16611
16612 \begin_layout Verse
16613
16614 \family typewriter
16615 \size footnotesize
16616 \InsetSpace ~
16617 \InsetSpace ~
16618 \InsetSpace ~
16619 \InsetSpace ~
16620 \InsetSpace ~
16621 \InsetSpace ~
16622 \InsetSpace ~
16623 \InsetSpace ~
16624 .area GSINIT3 (CODE)
16625 \newline
16626 __mcs51_genXINIT::
16627 \newline
16628 \InsetSpace ~
16629 \InsetSpace ~
16630 \InsetSpace ~
16631 \InsetSpace ~
16632 \InsetSpace ~
16633 \InsetSpace ~
16634 \InsetSpace ~
16635 \InsetSpace ~
16636 mov r1,#l_XINIT
16637 \newline
16638 \InsetSpace ~
16639 \InsetSpace ~
16640 \InsetSpace ~
16641 \InsetSpace ~
16642 \InsetSpace ~
16643 \InsetSpace ~
16644 \InsetSpace ~
16645 \InsetSpace ~
16646 mov a,r1
16647 \newline
16648 \InsetSpace ~
16649 \InsetSpace ~
16650 \InsetSpace ~
16651 \InsetSpace ~
16652 \InsetSpace ~
16653 \InsetSpace ~
16654 \InsetSpace ~
16655 \InsetSpace ~
16656 orl a,#(l_XINIT
16657  >> 8)
16658 \newline
16659 \InsetSpace ~
16660 \InsetSpace ~
16661 \InsetSpace ~
16662 \InsetSpace ~
16663 \InsetSpace ~
16664 \InsetSpace ~
16665 \InsetSpace ~
16666 \InsetSpace ~
16667 jz 00003$
16668 \newline
16669 \InsetSpace ~
16670 \InsetSpace ~
16671 \InsetSpace ~
16672 \InsetSpace ~
16673 \InsetSpace ~
16674 \InsetSpace ~
16675 \InsetSpace ~
16676 \InsetSpace ~
16677 mov r2,#((l_XINIT+255) >> 8)
16678 \newline
16679 \InsetSpace ~
16680 \InsetSpace ~
16681 \InsetSpace ~
16682 \InsetSpace ~
16683 \InsetSpace ~
16684 \InsetSpace ~
16685 \InsetSpace ~
16686 \InsetSpace ~
16687 mov dptr,#s_XINIT
16688 \newline
16689 \InsetSpace ~
16690 \InsetSpace ~
16691 \InsetSpace ~
16692 \InsetSpace ~
16693 \InsetSpace ~
16694 \InsetSpace ~
16695 \InsetSpace ~
16696 \InsetSpace ~
16697 mov r0,#s_XISEG
16698 \newline
16699 \InsetSpace ~
16700 \InsetSpace ~
16701 \InsetSpace ~
16702 \InsetSpace ~
16703 \InsetSpace ~
16704 \InsetSpace ~
16705 \InsetSpace ~
16706 \InsetSpace ~
16707 mov
16708  __XPAGE,#(s_XISEG >> 8)
16709 \newline
16710 00001$:\InsetSpace ~
16711 clr a
16712 \newline
16713 \InsetSpace ~
16714 \InsetSpace ~
16715 \InsetSpace ~
16716 \InsetSpace ~
16717 \InsetSpace ~
16718 \InsetSpace ~
16719 \InsetSpace ~
16720 \InsetSpace ~
16721 movc a,@a+dptr
16722 \newline
16723 \InsetSpace ~
16724 \InsetSpace ~
16725 \InsetSpace ~
16726 \InsetSpace ~
16727 \InsetSpace ~
16728 \InsetSpace ~
16729 \InsetSpace ~
16730 \InsetSpace ~
16731 movx @r0,a
16732 \newline
16733 \InsetSpace ~
16734 \InsetSpace ~
16735 \InsetSpace ~
16736 \InsetSpace ~
16737 \InsetSpace ~
16738 \InsetSpace ~
16739 \InsetSpace ~
16740 \InsetSpace ~
16741 inc dptr
16742 \newline
16743 \InsetSpace ~
16744 \InsetSpace ~
16745 \InsetSpace ~
16746 \InsetSpace ~
16747 \InsetSpace ~
16748 \InsetSpace ~
16749 \InsetSpace ~
16750 \InsetSpace ~
16751 inc
16752  r0
16753 \newline
16754 \InsetSpace ~
16755 \InsetSpace ~
16756 \InsetSpace ~
16757 \InsetSpace ~
16758 \InsetSpace ~
16759 \InsetSpace ~
16760 \InsetSpace ~
16761 \InsetSpace ~
16762 cjne r0,#0,00002$
16763 \newline
16764 \InsetSpace ~
16765 \InsetSpace ~
16766 \InsetSpace ~
16767 \InsetSpace ~
16768 \InsetSpace ~
16769 \InsetSpace ~
16770 \InsetSpace ~
16771 \InsetSpace ~
16772 inc __XPAGE
16773 \newline
16774 00002$:\InsetSpace ~
16775 djnz r1,00001$
16776 \newline
16777 \InsetSpace ~
16778 \InsetSpace ~
16779 \InsetSpace ~
16780 \InsetSpace ~
16781 \InsetSpace ~
16782 \InsetSpace ~
16783 \InsetSpace ~
16784 \InsetSpace ~
16785 djnz r2,00001$
16786 \newline
16787 \InsetSpace ~
16788 \InsetSpace ~
16789 \InsetSpace ~
16790 \InsetSpace ~
16791 \InsetSpace ~
16792 \InsetSpace ~
16793 \InsetSpace ~
16794 \InsetSpace ~
16795 mov __XPAGE,#0
16796 xFF
16797 \newline
16798 00003$:
16799 \end_layout
16800
16801 \begin_layout Verse
16802
16803 \family typewriter
16804 \series bold
16805 \size footnotesize
16806 (crtclear.asm)
16807 \end_layout
16808
16809 \begin_layout Verse
16810
16811 \family typewriter
16812 \size footnotesize
16813 \InsetSpace ~
16814 \InsetSpace ~
16815 \InsetSpace ~
16816 \InsetSpace ~
16817 \InsetSpace ~
16818 \InsetSpace ~
16819 \InsetSpace ~
16820 \InsetSpace ~
16821 .area GSINIT4 (CODE)
16822 \newline
16823 __mcs51_genRAMCLEAR::
16824 \newline
16825 \InsetSpace ~
16826 \InsetSpace ~
16827 \InsetSpace ~
16828 \InsetSpace ~
16829 \InsetSpace ~
16830 \InsetSpace ~
16831 \InsetSpace ~
16832 \InsetSpace ~
16833 clr a
16834 \newline
16835 \InsetSpace ~
16836 \InsetSpace ~
16837 \InsetSpace ~
16838 \InsetSpace ~
16839 \InsetSpace ~
16840 \InsetSpace ~
16841 \InsetSpace ~
16842 \InsetSpace ~
16843 mov r0,#(l_IRAM-1)
16844 \newline
16845 00004$:\InsetSpace ~
16846 mov
16847  @r0,a
16848 \newline
16849 \InsetSpace ~
16850 \InsetSpace ~
16851 \InsetSpace ~
16852 \InsetSpace ~
16853 \InsetSpace ~
16854 \InsetSpace ~
16855 \InsetSpace ~
16856 \InsetSpace ~
16857 djnz r0,00004$
16858 \newline
16859 ; _mcs51_genRAMCLEAR() end
16860 \end_layout
16861
16862 \begin_layout Verse
16863
16864 \family typewriter
16865 \series bold
16866 \size footnotesize
16867 (crtxclear.asm)
16868 \end_layout
16869
16870 \begin_layout Verse
16871
16872 \family typewriter
16873 \size footnotesize
16874 \InsetSpace ~
16875 \InsetSpace ~
16876 \InsetSpace ~
16877 \InsetSpace ~
16878 \InsetSpace ~
16879 \InsetSpace ~
16880 \InsetSpace ~
16881 \InsetSpace ~
16882 .area GSINIT4 (CODE)
16883 \newline
16884 __mcs51_genXRAMCLEAR::
16885 \newline
16886 \InsetSpace ~
16887 \InsetSpace ~
16888 \InsetSpace ~
16889 \InsetSpace ~
16890 \InsetSpace ~
16891 \InsetSpace ~
16892 \InsetSpace ~
16893 \InsetSpace ~
16894 mov r0,#l_PSEG
16895 \newline
16896 \InsetSpace ~
16897 \InsetSpace ~
16898 \InsetSpace ~
16899 \InsetSpace ~
16900 \InsetSpace ~
16901 \InsetSpace ~
16902 \InsetSpace ~
16903 \InsetSpace ~
16904 mov a,r0
16905 \newline
16906 \InsetSpace ~
16907 \InsetSpace ~
16908 \InsetSpace ~
16909 \InsetSpace ~
16910 \InsetSpace ~
16911 \InsetSpace ~
16912 \InsetSpace ~
16913 \InsetSpace ~
16914 orl a,#(l_PSEG
16915  >> 8)
16916 \newline
16917 \InsetSpace ~
16918 \InsetSpace ~
16919 \InsetSpace ~
16920 \InsetSpace ~
16921 \InsetSpace ~
16922 \InsetSpace ~
16923 \InsetSpace ~
16924 \InsetSpace ~
16925 jz 00006$
16926 \newline
16927 \InsetSpace ~
16928 \InsetSpace ~
16929 \InsetSpace ~
16930 \InsetSpace ~
16931 \InsetSpace ~
16932 \InsetSpace ~
16933 \InsetSpace ~
16934 \InsetSpace ~
16935 mov r1,#s_PSEG
16936 \newline
16937 \InsetSpace ~
16938 \InsetSpace ~
16939 \InsetSpace ~
16940 \InsetSpace ~
16941 \InsetSpace ~
16942 \InsetSpace ~
16943 \InsetSpace ~
16944 \InsetSpace ~
16945 mov __XPAGE,#(s_PSEG >> 8)
16946 \newline
16947 \InsetSpace ~
16948 \InsetSpace ~
16949 \InsetSpace ~
16950 \InsetSpace ~
16951 \InsetSpace ~
16952 \InsetSpace ~
16953 \InsetSpace ~
16954 \InsetSpace ~
16955 clr a
16956 \newline
16957 00005$:\InsetSpace ~
16958 movx
16959  @r1,a
16960 \newline
16961 \InsetSpace ~
16962 \InsetSpace ~
16963 \InsetSpace ~
16964 \InsetSpace ~
16965 \InsetSpace ~
16966 \InsetSpace ~
16967 \InsetSpace ~
16968 \InsetSpace ~
16969 inc r1
16970 \newline
16971 \InsetSpace ~
16972 \InsetSpace ~
16973 \InsetSpace ~
16974 \InsetSpace ~
16975 \InsetSpace ~
16976 \InsetSpace ~
16977 \InsetSpace ~
16978 \InsetSpace ~
16979 djnz r0,00005$
16980 \newline
16981 00006$:
16982 \newline
16983 \InsetSpace ~
16984 \InsetSpace ~
16985 \InsetSpace ~
16986 \InsetSpace ~
16987 \InsetSpace ~
16988 \InsetSpace ~
16989 \InsetSpace ~
16990 \InsetSpace ~
16991 mov r0,#l_XSEG
16992 \newline
16993 \InsetSpace ~
16994 \InsetSpace ~
16995 \InsetSpace ~
16996 \InsetSpace ~
16997 \InsetSpace ~
16998 \InsetSpace ~
16999 \InsetSpace ~
17000 \InsetSpace ~
17001 mov a,r0
17002 \newline
17003 \InsetSpace ~
17004 \InsetSpace ~
17005 \InsetSpace ~
17006 \InsetSpace ~
17007 \InsetSpace ~
17008 \InsetSpace ~
17009 \InsetSpace ~
17010 \InsetSpace ~
17011 orl a,#(l_XSEG >>
17012  8)
17013 \newline
17014 \InsetSpace ~
17015 \InsetSpace ~
17016 \InsetSpace ~
17017 \InsetSpace ~
17018 \InsetSpace ~
17019 \InsetSpace ~
17020 \InsetSpace ~
17021 \InsetSpace ~
17022 jz 00008$
17023 \newline
17024 \InsetSpace ~
17025 \InsetSpace ~
17026 \InsetSpace ~
17027 \InsetSpace ~
17028 \InsetSpace ~
17029 \InsetSpace ~
17030 \InsetSpace ~
17031 \InsetSpace ~
17032 mov r1,#((l_XSEG + 255) >> 8)
17033 \newline
17034 \InsetSpace ~
17035 \InsetSpace ~
17036 \InsetSpace ~
17037 \InsetSpace ~
17038 \InsetSpace ~
17039 \InsetSpace ~
17040 \InsetSpace ~
17041 \InsetSpace ~
17042 mov dptr,#s_XSEG
17043 \newline
17044 \InsetSpace ~
17045 \InsetSpace ~
17046 \InsetSpace ~
17047 \InsetSpace ~
17048 \InsetSpace ~
17049 \InsetSpace ~
17050 \InsetSpace ~
17051 \InsetSpace ~
17052 clr a
17053 \newline
17054 00007$:\InsetSpace ~
17055 movx
17056  @dptr,a
17057 \newline
17058 \InsetSpace ~
17059 \InsetSpace ~
17060 \InsetSpace ~
17061 \InsetSpace ~
17062 \InsetSpace ~
17063 \InsetSpace ~
17064 \InsetSpace ~
17065 \InsetSpace ~
17066 inc dptr
17067 \newline
17068 \InsetSpace ~
17069 \InsetSpace ~
17070 \InsetSpace ~
17071 \InsetSpace ~
17072 \InsetSpace ~
17073 \InsetSpace ~
17074 \InsetSpace ~
17075 \InsetSpace ~
17076 djnz r0,00007$
17077 \newline
17078 \InsetSpace ~
17079 \InsetSpace ~
17080 \InsetSpace ~
17081 \InsetSpace ~
17082 \InsetSpace ~
17083 \InsetSpace ~
17084 \InsetSpace ~
17085 \InsetSpace ~
17086 djnz r1,00007$
17087 \newline
17088 00008$:
17089 \end_layout
17090
17091 \begin_layout Verse
17092
17093 \family typewriter
17094 \series bold
17095 \size footnotesize
17096 (crtxstack.asm)
17097 \end_layout
17098
17099 \begin_layout Verse
17100
17101 \family typewriter
17102 \size footnotesize
17103 \InsetSpace ~
17104 \InsetSpace ~
17105 \InsetSpace ~
17106 \InsetSpace ~
17107 \InsetSpace ~
17108 \InsetSpace ~
17109 \InsetSpace ~
17110 \InsetSpace ~
17111 .area GSINIT5 (CODE)
17112 \newline
17113 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
17114  modifies __XPAGE
17115 \newline
17116 ; and __mcs51_genRAMCLEAR modifies _spx.
17117 \newline
17118 \InsetSpace ~
17119 \InsetSpace ~
17120 \InsetSpace ~
17121 \InsetSpace ~
17122 \InsetSpace ~
17123 \InsetSpace ~
17124 \InsetSpace ~
17125 \InsetSpace ~
17126 mov __XPAGE,#(__start__x
17127 stack >> 8)
17128 \newline
17129 \InsetSpace ~
17130 \InsetSpace ~
17131 \InsetSpace ~
17132 \InsetSpace ~
17133 \InsetSpace ~
17134 \InsetSpace ~
17135 \InsetSpace ~
17136 \InsetSpace ~
17137 mov _spx,#__start__xstack
17138 \end_layout
17139
17140 \begin_layout Verse
17141
17142 \family typewriter
17143 \series bold
17144 \size footnotesize
17145 (application modules)
17146 \end_layout
17147
17148 \begin_layout Verse
17149
17150 \family typewriter
17151 \size footnotesize
17152 \InsetSpace ~
17153 \InsetSpace ~
17154 \InsetSpace ~
17155 \InsetSpace ~
17156 \InsetSpace ~
17157 \InsetSpace ~
17158 \InsetSpace ~
17159 \InsetSpace ~
17160 .area GSINIT (CODE)
17161 \end_layout
17162
17163 \begin_layout Verse
17164
17165 \family typewriter
17166 \series bold
17167 \size footnotesize
17168 (main.asm)
17169 \end_layout
17170
17171 \begin_layout Verse
17172
17173 \family typewriter
17174 \size footnotesize
17175 \InsetSpace ~
17176 \InsetSpace ~
17177 \InsetSpace ~
17178 \InsetSpace ~
17179 \InsetSpace ~
17180 \InsetSpace ~
17181 \InsetSpace ~
17182 \InsetSpace ~
17183 .area GSFINAL (CODE)
17184 \newline
17185 \InsetSpace ~
17186 \InsetSpace ~
17187 \InsetSpace ~
17188 \InsetSpace ~
17189 \InsetSpace ~
17190 \InsetSpace ~
17191 \InsetSpace ~
17192 \InsetSpace ~
17193 ljmp __sdcc_program_startup
17194 \newline
17195 ;---------------------------------
17196 -----------------------
17197 \newline
17198 ; Home
17199 \newline
17200 ;--------------------------------------------------
17201 ------
17202 \newline
17203 \InsetSpace ~
17204 \InsetSpace ~
17205 \InsetSpace ~
17206 \InsetSpace ~
17207 \InsetSpace ~
17208 \InsetSpace ~
17209 \InsetSpace ~
17210 \InsetSpace ~
17211 .area HOME (CODE)
17212 \newline
17213 \InsetSpace ~
17214 \InsetSpace ~
17215 \InsetSpace ~
17216 \InsetSpace ~
17217 \InsetSpace ~
17218 \InsetSpace ~
17219 \InsetSpace ~
17220 \InsetSpace ~
17221 .area CSEG (CODE)
17222 \newline
17223 __sdcc_program_startup:
17224 \newline
17225 \InsetSpace ~
17226 \InsetSpace ~
17227 \InsetSpace ~
17228 \InsetSpace ~
17229 \InsetSpace ~
17230 \InsetSpace ~
17231 \InsetSpace ~
17232 \InsetSpace ~
17233 lcall _main
17234 \newline
17235 ;
17236  return from main will lock up
17237 \newline
17238 \InsetSpace ~
17239 \InsetSpace ~
17240 \InsetSpace ~
17241 \InsetSpace ~
17242 \InsetSpace ~
17243 \InsetSpace ~
17244 \InsetSpace ~
17245 \InsetSpace ~
17246 sjmp .
17247 \end_layout
17248
17249 \begin_layout Standard
17250 One of these modules (crtstart.asm) contains a call to the C routine 
17251 \emph on
17252 _sdcc_external_startup()
17253 \begin_inset LatexCommand index
17254 name "\\_sdcc\\_external\\_startup()"
17255
17256 \end_inset
17257
17258
17259 \emph default
17260  at the start of the CODE area.
17261  This routine is also in the runtime library
17262 \begin_inset LatexCommand index
17263 name "Runtime library"
17264
17265 \end_inset
17266
17267  and returns 0 by default.
17268  If this routine returns a non-zero value, the static & global variable
17269  initialization will be skipped and the function main will be invoked.
17270  Otherwise static & global variables will be initialized before the function
17271  main is invoked.
17272  You could add an 
17273 \emph on
17274 _sdcc_external_startup()
17275 \emph default
17276  routine to your program to override the default if you need to setup hardware
17277  or perform some other critical operation prior to static & global variable
17278  initialization
17279 \begin_inset LatexCommand index
17280 name "Variable initialization"
17281
17282 \end_inset
17283
17284 .
17285  On some mcs51 variants xdata
17286 \begin_inset LatexCommand index
17287 name "xdata (mcs51, ds390 storage class)"
17288
17289 \end_inset
17290
17291  memory has to be explicitly enabled before it can be accessed or if the
17292  watchdog
17293 \begin_inset LatexCommand index
17294 name "watchdog"
17295
17296 \end_inset
17297
17298  needs to be disabled, this is the place to do it.
17299  The startup code clears all internal data memory, 256 bytes by default,
17300  but from 0 to n-1 if 
17301 \emph on
17302 -
17303 \begin_inset ERT
17304 status collapsed
17305
17306 \begin_layout Standard
17307
17308
17309 \backslash
17310 /
17311 \end_layout
17312
17313 \end_inset
17314
17315 -iram-size
17316 \begin_inset LatexCommand index
17317 name "-\\/-iram-size <Value>"
17318
17319 \end_inset
17320
17321 n
17322 \emph default
17323  is used.
17324  (recommended for Chipcon CC1010).
17325 \end_layout
17326
17327 \begin_layout Standard
17328 See also the compiler options 
17329 \emph on
17330 -
17331 \begin_inset ERT
17332 status collapsed
17333
17334 \begin_layout Standard
17335
17336
17337 \backslash
17338 /
17339 \end_layout
17340
17341 \end_inset
17342
17343 -no-xinit
17344 \emph default
17345 -
17346 \emph on
17347 opt
17348 \emph default
17349
17350 \begin_inset LatexCommand index
17351 name "-\\/-no-xinit-opt"
17352
17353 \end_inset
17354
17355
17356 \emph on
17357 -
17358 \begin_inset ERT
17359 status collapsed
17360
17361 \begin_layout Standard
17362
17363
17364 \backslash
17365 /
17366 \end_layout
17367
17368 \end_inset
17369
17370 -main-return
17371 \emph default
17372
17373 \begin_inset LatexCommand index
17374 name "-\\/-main-return"
17375
17376 \end_inset
17377
17378  and section 
17379 \begin_inset LatexCommand ref
17380 reference "sub:MCS51-variants"
17381
17382 \end_inset
17383
17384  about MCS51-variants.
17385 \newline
17386
17387 \end_layout
17388
17389 \begin_layout Standard
17390 While these initialization modules are meant as generic startup code there
17391  might be the need for customization.
17392  Let's assume the return value of 
17393 \emph on
17394 _sdcc_external_startup()
17395 \emph default
17396  in 
17397 \emph on
17398 crtstart.asm
17399 \emph default
17400  should not be checked (or 
17401 \emph on
17402 _sdcc_external_startup()
17403 \emph default
17404  should not be called at all).
17405  The recommended way would be to copy 
17406 \emph on
17407 crtstart.asm
17408 \emph default
17409  (f.e.
17410  from 
17411 \begin_inset LatexCommand url
17412 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/device/lib/mcs51/crtstart.asm"
17413
17414 \end_inset
17415
17416 ) into the source directory, adapt it there, then assemble it with 
17417 \emph on
17418 asx8051 -plosgff
17419 \begin_inset Foot
17420 status open
17421
17422 \begin_layout Standard
17423 \begin_inset Quotes sld
17424 \end_inset
17425
17426 -plosgff
17427 \begin_inset Quotes srd
17428 \end_inset
17429
17430  are the assembler options used in 
17431 \begin_inset LatexCommand url
17432 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/lib/mcs51/Makefile.in?view=markup "
17433
17434 \end_inset
17435
17436
17437 \end_layout
17438
17439 \end_inset
17440
17441  crtstart.asm
17442 \emph default
17443  and when linking your project explicitly specify 
17444 \emph on
17445 crtstart.rel
17446 \emph default
17447 .
17448  As a bonus a listing of the relocated object file 
17449 \emph on
17450 crtstart.rst
17451 \emph default
17452  is generated.
17453 \end_layout
17454
17455 \begin_layout Standard
17456 \begin_inset VSpace bigskip
17457 \end_inset
17458
17459
17460 \end_layout
17461
17462 \begin_layout Subsection
17463 HC08 Startup Code
17464 \end_layout
17465
17466 \begin_layout Standard
17467 The HC08
17468 \begin_inset LatexCommand index
17469 name "HC08"
17470
17471 \end_inset
17472
17473  startup code follows the same scheme as the MCS51 startup code.
17474 \begin_inset VSpace bigskip
17475 \end_inset
17476
17477
17478 \end_layout
17479
17480 \begin_layout Subsection
17481 Z80 Startup Code
17482 \end_layout
17483
17484 \begin_layout Standard
17485 On the Z80
17486 \begin_inset LatexCommand index
17487 name "Z80"
17488
17489 \end_inset
17490
17491  the startup code is inserted by linking with crt0.o which is generated from
17492  sdcc/device/lib/z80/crt0.s.
17493  If you need a different startup code you can use the compiler option 
17494 \emph on
17495 -
17496 \series bold
17497 \emph default
17498
17499 \begin_inset ERT
17500 status collapsed
17501
17502 \begin_layout Standard
17503
17504
17505 \backslash
17506 /
17507 \end_layout
17508
17509 \end_inset
17510
17511
17512 \series default
17513 \emph on
17514 -no-std-crt0
17515 \emph default
17516
17517 \begin_inset LatexCommand index
17518 name "-\\/-no-std-crt0"
17519
17520 \end_inset
17521
17522  and provide your own crt0.o.
17523  
17524 \begin_inset VSpace bigskip
17525 \end_inset
17526
17527
17528 \end_layout
17529
17530 \begin_layout Section
17531 Inline Assembler Code
17532 \begin_inset LatexCommand index
17533 name "Assembler routines"
17534
17535 \end_inset
17536
17537
17538 \end_layout
17539
17540 \begin_layout Subsection
17541 A Step by Step Introduction
17542 \begin_inset LatexCommand label
17543 name "sub:A-Step-by Assembler Introduction"
17544
17545 \end_inset
17546
17547
17548 \end_layout
17549
17550 \begin_layout Standard
17551 Starting from a small snippet of c-code this example shows for the MCS51
17552  how to use inline assembly, access variables, a function parameter and
17553  an array in xdata memory.
17554  The example uses an MCS51 here but is easily adapted for other architectures.
17555  This is a buffer routine which should be optimized:
17556 \end_layout
17557
17558 \begin_layout Verse
17559
17560 \family typewriter
17561 \size footnotesize
17562 unsigned char __far
17563 \begin_inset LatexCommand index
17564 name "far (storage class)"
17565
17566 \end_inset
17567
17568
17569 \begin_inset LatexCommand index
17570 name "\\_\\_far (storage class)"
17571
17572 \end_inset
17573
17574  __at
17575 \begin_inset LatexCommand index
17576 name "at"
17577
17578 \end_inset
17579
17580
17581 \begin_inset LatexCommand index
17582 name "\\_\\_at"
17583
17584 \end_inset
17585
17586 (0x7f00) buf[0x100];
17587 \begin_inset LatexCommand index
17588 name "Aligned array"
17589
17590 \end_inset
17591
17592
17593 \newline
17594 unsigned char head, tail;\InsetSpace ~
17595 \InsetSpace ~
17596 \InsetSpace ~
17597 \InsetSpace ~
17598 \InsetSpace ~
17599 \InsetSpace ~
17600 \InsetSpace ~
17601 \InsetSpace ~
17602 \InsetSpace ~
17603 \InsetSpace ~
17604 \InsetSpace ~
17605 \InsetSpace ~
17606 \InsetSpace ~
17607 \InsetSpace ~
17608 \InsetSpace ~
17609 \InsetSpace ~
17610 \InsetSpace ~
17611 /* if interrupts
17612 \begin_inset LatexCommand index
17613 name "interrupt"
17614
17615 \end_inset
17616
17617  are involved see
17618 \newline
17619 \InsetSpace ~
17620 \InsetSpace ~
17621 \InsetSpace ~
17622 \InsetSpace ~
17623 \InsetSpace ~
17624 \InsetSpace ~
17625 \InsetSpace ~
17626 \InsetSpace ~
17627 \InsetSpace ~
17628 \InsetSpace ~
17629 \InsetSpace ~
17630 \InsetSpace ~
17631 \InsetSpace ~
17632 \InsetSpace ~
17633 \InsetSpace ~
17634 \InsetSpace ~
17635 \InsetSpace ~
17636 \InsetSpace ~
17637 \InsetSpace ~
17638 \InsetSpace ~
17639 \InsetSpace ~
17640 \InsetSpace ~
17641 \InsetSpace ~
17642 \InsetSpace ~
17643 \InsetSpace ~
17644 \InsetSpace ~
17645 \InsetSpace ~
17646 \InsetSpace ~
17647 \InsetSpace ~
17648 \InsetSpace ~
17649 \InsetSpace ~
17650 \InsetSpace ~
17651 \InsetSpace ~
17652 \InsetSpace ~
17653 \InsetSpace ~
17654 \InsetSpace ~
17655 \InsetSpace ~
17656 \InsetSpace ~
17657 \InsetSpace ~
17658 \InsetSpace ~
17659 \InsetSpace ~
17660 \InsetSpace ~
17661 \InsetSpace ~
17662 \InsetSpace ~
17663 \InsetSpace ~
17664 section 
17665 \begin_inset LatexCommand ref
17666 reference "sub:Common-interrupt-pitfall-volatile"
17667
17668 \end_inset
17669
17670  about
17671 \family default
17672  
17673 \family typewriter
17674 \series bold
17675 volatile
17676 \family default
17677 \series default
17678  
17679 \family typewriter
17680 */
17681 \newline
17682
17683 \newline
17684 void to_buffer( unsigned char c ) 
17685 \newline
17686 {
17687 \newline
17688 \InsetSpace ~
17689 \InsetSpace ~
17690 \InsetSpace ~
17691 \InsetSpace ~
17692 if( head != (unsigned char)(tail-1)
17693  )\InsetSpace ~
17694 /* cast
17695 \family default
17696  
17697 \family typewriter
17698 \series bold
17699 needed
17700 \family default
17701 \series default
17702  
17703 \family typewriter
17704 to avoid promotion
17705 \begin_inset LatexCommand index
17706 name "promotion to signed int"
17707
17708 \end_inset
17709
17710
17711 \begin_inset LatexCommand index
17712 name "type promotion"
17713
17714 \end_inset
17715
17716  to integer */
17717 \begin_inset Marginal
17718 status collapsed
17719
17720 \begin_layout Standard
17721
17722 \series bold
17723 \InsetSpace ~
17724 !
17725 \end_layout
17726
17727 \end_inset
17728
17729
17730 \newline
17731 \InsetSpace ~
17732 \InsetSpace ~
17733 \InsetSpace ~
17734 \InsetSpace ~
17735 \InsetSpace ~
17736 \InsetSpace ~
17737 \InsetSpace ~
17738 \InsetSpace ~
17739 buf[ head++ ] = c;\InsetSpace ~
17740 \InsetSpace ~
17741 \InsetSpace ~
17742 \InsetSpace ~
17743 \InsetSpace ~
17744 \InsetSpace ~
17745 \InsetSpace ~
17746 \InsetSpace ~
17747 \InsetSpace ~
17748 \InsetSpace ~
17749 \InsetSpace ~
17750 \InsetSpace ~
17751 \InsetSpace ~
17752 \InsetSpace ~
17753 \InsetSpace ~
17754 \InsetSpace ~
17755 /* access to a 256 byte aligned array */
17756 \newline
17757
17758 \end_layout
17759
17760 \begin_layout Standard
17761 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
17762  then a corresponding buffer.asm file is generated.
17763  We define a new function 
17764 \family typewriter
17765 to_buffer_asm()
17766 \family default
17767  in file buffer.c in which we cut and paste the generated code, removing
17768  unwanted comments and some ':'.
17769  Then add 
17770 \begin_inset Quotes sld
17771 \end_inset
17772
17773
17774 \series bold
17775 _asm
17776 \series default
17777
17778 \begin_inset Quotes srd
17779 \end_inset
17780
17781  and 
17782 \begin_inset Quotes sld
17783 \end_inset
17784
17785
17786 \series bold
17787 _endasm;
17788 \series default
17789
17790 \begin_inset Quotes srd
17791 \end_inset
17792
17793
17794 \begin_inset Foot
17795 status open
17796
17797 \begin_layout Standard
17798 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
17799  and for C-99 compatibility, the double-underscore form (__asm and __endasm)
17800  has to be used.
17801  The latter is also used in the library functions.
17802 \end_layout
17803
17804 \end_inset
17805
17806  to the beginning and the end of the function body:
17807 \end_layout
17808
17809 \begin_layout Verse
17810
17811 \family typewriter
17812 \size footnotesize
17813 /* With a cut and paste from the .asm file, we have something to start with.
17814 \newline
17815 \InsetSpace ~
17816 \InsetSpace ~
17817 \InsetSpace ~
17818 The
17819  function is not yet OK! (registers aren't saved) */ 
17820 \newline
17821 void to_buffer_asm(
17822  unsigned char c ) 
17823 \newline
17824
17825 \newline
17826 \InsetSpace ~
17827 \InsetSpace ~
17828 \InsetSpace ~
17829 \InsetSpace ~
17830 _asm
17831 \begin_inset LatexCommand index
17832 name "\\_asm"
17833
17834 \end_inset
17835
17836
17837 \begin_inset LatexCommand index
17838 name "\\_\\_asm"
17839
17840 \end_inset
17841
17842
17843 \newline
17844 \InsetSpace ~
17845 \InsetSpace ~
17846 \InsetSpace ~
17847 \InsetSpace ~
17848 mov\InsetSpace ~
17849 \InsetSpace ~
17850 r2,dpl 
17851 \newline
17852 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
17853 /* cast
17854 \family default
17855  
17856 \family typewriter
17857 \series bold
17858 needed
17859 \family default
17860 \series default
17861  
17862 \family typewriter
17863 to avoid promotion
17864 \begin_inset LatexCommand index
17865 name "promotion to signed int"
17866
17867 \end_inset
17868
17869
17870 \begin_inset LatexCommand index
17871 name "type promotion"
17872
17873 \end_inset
17874
17875  to integer */
17876 \newline
17877 \InsetSpace ~
17878 \InsetSpace ~
17879 \InsetSpace ~
17880 \InsetSpace ~
17881 mov\InsetSpace ~
17882 \InsetSpace ~
17883 a,_tail 
17884 \newline
17885 \InsetSpace ~
17886 \InsetSpace ~
17887 \InsetSpace ~
17888 \InsetSpace ~
17889 dec\InsetSpace ~
17890 \InsetSpace ~
17891
17892 \newline
17893 \InsetSpace ~
17894 \InsetSpace ~
17895 \InsetSpace ~
17896 \InsetSpace ~
17897 mov\InsetSpace ~
17898 \InsetSpace ~
17899 r3,a 
17900 \newline
17901 \InsetSpace ~
17902 \InsetSpace ~
17903 \InsetSpace ~
17904 \InsetSpace ~
17905 mov\InsetSpace ~
17906 \InsetSpace ~
17907 a,_head 
17908 \newline
17909 \InsetSpace ~
17910 \InsetSpace ~
17911 \InsetSpace ~
17912 \InsetSpace ~
17913 cjne a,ar3,00106$ 
17914 \newline
17915 \InsetSpace ~
17916 \InsetSpace ~
17917 \InsetSpace ~
17918 \InsetSpace ~
17919 ret
17920 \newline
17921 00106$:
17922  
17923 \newline
17924 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
17925 \begin_inset LatexCommand index
17926 name "Aligned array"
17927
17928 \end_inset
17929
17930
17931 \newline
17932 \InsetSpace ~
17933 \InsetSpace ~
17934 \InsetSpace ~
17935 \InsetSpace ~
17936 mov\InsetSpace ~
17937 \InsetSpace ~
17938 r3,_head 
17939 \newline
17940 \InsetSpace ~
17941 \InsetSpace ~
17942 \InsetSpace ~
17943 \InsetSpace ~
17944 inc\InsetSpace ~
17945 \InsetSpace ~
17946 _head 
17947 \newline
17948 \InsetSpace ~
17949 \InsetSpace ~
17950 \InsetSpace ~
17951 \InsetSpace ~
17952 mov\InsetSpace ~
17953 \InsetSpace ~
17954 dpl,r3 
17955 \newline
17956 \InsetSpace ~
17957 \InsetSpace ~
17958 \InsetSpace ~
17959 \InsetSpace ~
17960 mov\InsetSpace ~
17961 \InsetSpace ~
17962 dph,#(_buf >> 8) 
17963 \newline
17964 \InsetSpace ~
17965 \InsetSpace ~
17966 \InsetSpace ~
17967 \InsetSpace ~
17968 mov\InsetSpace ~
17969 \InsetSpace ~
17970 a,r2 
17971 \newline
17972 \InsetSpace ~
17973 \InsetSpace ~
17974 \InsetSpace ~
17975 \InsetSpace ~
17976 movx @dptr,a
17977  
17978 \newline
17979 00103$: 
17980 \newline
17981 \InsetSpace ~
17982 \InsetSpace ~
17983 \InsetSpace ~
17984 \InsetSpace ~
17985 ret
17986 \newline
17987 \InsetSpace ~
17988 \InsetSpace ~
17989 \InsetSpace ~
17990 \InsetSpace ~
17991 _endasm
17992 \begin_inset LatexCommand index
17993 name "\\_endasm"
17994
17995 \end_inset
17996
17997
17998 \begin_inset LatexCommand index
17999 name "\\_\\_endasm"
18000
18001 \end_inset
18002
18003 ;
18004 \newline
18005
18006 \end_layout
18007
18008 \begin_layout Standard
18009 The new file buffer.c should compile with only one warning about the unreferenced
18010  function argument 'c'.
18011  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
18012  (1) and finally have:
18013 \end_layout
18014
18015 \begin_layout Verse
18016
18017 \family typewriter
18018 \size footnotesize
18019 unsigned char __far __at(0x7f00) buf[0x100];
18020 \newline
18021 unsigned char head, tail;
18022 \newline
18023 #define
18024  USE_ASSEMBLY (1)
18025 \newline
18026
18027 \newline
18028 #if !USE_ASSEMBLY
18029 \newline
18030
18031 \newline
18032 void to_buffer( unsigned char c )
18033 \newline
18034 {
18035 \newline
18036 \InsetSpace ~
18037 \InsetSpace ~
18038 \InsetSpace ~
18039 \InsetSpace ~
18040 if(
18041  head != (unsigned char)(tail-1) )
18042 \newline
18043 \InsetSpace ~
18044 \InsetSpace ~
18045 \InsetSpace ~
18046 \InsetSpace ~
18047 \InsetSpace ~
18048 \InsetSpace ~
18049 \InsetSpace ~
18050 \InsetSpace ~
18051 buf[ head++ ] = c;
18052 \newline
18053 }
18054 \newline
18055
18056 \newline
18057 #else
18058 \newline
18059
18060 \newline
18061 void to_buffer(
18062  unsigned char c )
18063 \newline
18064 {
18065 \newline
18066 \InsetSpace ~
18067 \InsetSpace ~
18068 \InsetSpace ~
18069 \InsetSpace ~
18070 c; // to avoid warning: unreferenced function argument
18071 \newline
18072 \InsetSpace ~
18073 \InsetSpace ~
18074 \InsetSpace ~
18075 \InsetSpace ~
18076 _asm
18077 \begin_inset LatexCommand index
18078 name "\\_asm"
18079
18080 \end_inset
18081
18082
18083 \begin_inset LatexCommand index
18084 name "\\_\\_asm"
18085
18086 \end_inset
18087
18088
18089 \newline
18090 \InsetSpace ~
18091 \InsetSpace ~
18092 \InsetSpace ~
18093 \InsetSpace ~
18094 \InsetSpace ~
18095 \InsetSpace ~
18096 \InsetSpace ~
18097 \InsetSpace ~
18098 ; save used registers here.
18099  
18100 \newline
18101 \InsetSpace ~
18102 \InsetSpace ~
18103 \InsetSpace ~
18104 \InsetSpace ~
18105 \InsetSpace ~
18106 \InsetSpace ~
18107 \InsetSpace ~
18108 \InsetSpace ~
18109 ; If we were still using r2,r3 we would have to push them here.
18110  
18111 \newline
18112 ; if( head != (unsigned char)(tail-1) )
18113 \newline
18114 \InsetSpace ~
18115 \InsetSpace ~
18116 \InsetSpace ~
18117 \InsetSpace ~
18118 \InsetSpace ~
18119 \InsetSpace ~
18120 \InsetSpace ~
18121 \InsetSpace ~
18122 mov\InsetSpace ~
18123  a,_tail
18124 \newline
18125 \InsetSpace ~
18126 \InsetSpace ~
18127 \InsetSpace ~
18128 \InsetSpace ~
18129 \InsetSpace ~
18130 \InsetSpace ~
18131 \InsetSpace ~
18132 \InsetSpace ~
18133 dec\InsetSpace ~
18134  a
18135 \newline
18136 \InsetSpace ~
18137 \InsetSpace ~
18138 \InsetSpace ~
18139 \InsetSpace ~
18140 \InsetSpace ~
18141 \InsetSpace ~
18142 \InsetSpace ~
18143 \InsetSpace ~
18144 xrl\InsetSpace ~
18145  a,_head
18146 \newline
18147 \InsetSpace ~
18148 \InsetSpace ~
18149 \InsetSpace ~
18150 \InsetSpace ~
18151 \InsetSpace ~
18152 \InsetSpace ~
18153 \InsetSpace ~
18154 \InsetSpace ~
18155 ; we
18156  could do an ANL a,#0x0f here to use a smaller buffer (see below)
18157 \newline
18158 \InsetSpace ~
18159 \InsetSpace ~
18160 \InsetSpace ~
18161 \InsetSpace ~
18162 \InsetSpace ~
18163 \InsetSpace ~
18164 \InsetSpace ~
18165 \InsetSpace ~
18166 jz\InsetSpace ~
18167 \InsetSpace ~
18168  t_b_end$
18169 \newline
18170 \InsetSpace ~
18171 \InsetSpace ~
18172 \InsetSpace ~
18173 \InsetSpace ~
18174 \InsetSpace ~
18175 \InsetSpace ~
18176 \InsetSpace ~
18177 \InsetSpace ~
18178 ;
18179 \newline
18180 ;
18181  buf[ head++ ] = c;
18182 \newline
18183 \InsetSpace ~
18184 \InsetSpace ~
18185 \InsetSpace ~
18186 \InsetSpace ~
18187 \InsetSpace ~
18188 \InsetSpace ~
18189 \InsetSpace ~
18190 \InsetSpace ~
18191 mov\InsetSpace ~
18192  a,dpl \InsetSpace ~
18193 \InsetSpace ~
18194 \InsetSpace ~
18195 \InsetSpace ~
18196 \InsetSpace ~
18197 \InsetSpace ~
18198 \InsetSpace ~
18199 ; dpl holds lower byte of function argument
18200 \newline
18201 \InsetSpace ~
18202 \InsetSpace ~
18203 \InsetSpace ~
18204 \InsetSpace ~
18205 \InsetSpace ~
18206 \InsetSpace ~
18207 \InsetSpace ~
18208 \InsetSpace ~
18209 mov\InsetSpace ~
18210
18211  dpl,_head \InsetSpace ~
18212 \InsetSpace ~
18213 \InsetSpace ~
18214 ; buf is 0x100 byte aligned so head can be used directly
18215 \newline
18216 \InsetSpace ~
18217 \InsetSpace ~
18218 \InsetSpace ~
18219 \InsetSpace ~
18220 \InsetSpace ~
18221 \InsetSpace ~
18222 \InsetSpace ~
18223 \InsetSpace ~
18224 mov\InsetSpace ~
18225  dph,#(_bu
18226 f>>8)
18227 \newline
18228 \InsetSpace ~
18229 \InsetSpace ~
18230 \InsetSpace ~
18231 \InsetSpace ~
18232 \InsetSpace ~
18233 \InsetSpace ~
18234 \InsetSpace ~
18235 \InsetSpace ~
18236 movx @dptr,a
18237 \newline
18238 \InsetSpace ~
18239 \InsetSpace ~
18240 \InsetSpace ~
18241 \InsetSpace ~
18242 \InsetSpace ~
18243 \InsetSpace ~
18244 \InsetSpace ~
18245 \InsetSpace ~
18246 inc \InsetSpace ~
18247 _head
18248 \newline
18249 \InsetSpace ~
18250 \InsetSpace ~
18251 \InsetSpace ~
18252 \InsetSpace ~
18253 \InsetSpace ~
18254 \InsetSpace ~
18255 \InsetSpace ~
18256 \InsetSpace ~
18257 ; we could do an ANL _head,#0x0f here to use a
18258  smaller buffer (see above)
18259 \newline
18260 t_b_end$:
18261 \newline
18262 \InsetSpace ~
18263 \InsetSpace ~
18264 \InsetSpace ~
18265 \InsetSpace ~
18266 \InsetSpace ~
18267 \InsetSpace ~
18268 \InsetSpace ~
18269 \InsetSpace ~
18270 ; restore used registers here 
18271 \newline
18272 \InsetSpace ~
18273 \InsetSpace ~
18274 \InsetSpace ~
18275 \InsetSpace ~
18276 _endasm
18277 \begin_inset LatexCommand index
18278 name "\\_endasm"
18279
18280 \end_inset
18281
18282
18283 \begin_inset LatexCommand index
18284 name "\\_\\_endasm"
18285
18286 \end_inset
18287
18288 ;
18289 \newline
18290 }
18291 \newline
18292 #endif
18293 \end_layout
18294
18295 \begin_layout Standard
18296 The inline assembler code can contain any valid code understood by the assembler
18297 , this includes any assembler directives and comment lines.
18298  The assembler does not like some characters like ':' or ''' in comments.
18299  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
18300 \begin_inset LatexCommand index
18301 name "asXXXX (as-gbz80, as-hc08, asx8051, as-z80)"
18302
18303 \end_inset
18304
18305
18306 \begin_inset LatexCommand index
18307 name "Assembler documentation"
18308
18309 \end_inset
18310
18311  or online at 
18312 \begin_inset LatexCommand url
18313 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html"
18314
18315 \end_inset
18316
18317 \InsetSpace ~
18318 .
18319 \end_layout
18320
18321 \begin_layout Standard
18322 The compiler does not do any validation of the code within the 
18323 \family typewriter
18324 _asm
18325 \begin_inset LatexCommand index
18326 name "\\_asm"
18327
18328 \end_inset
18329
18330
18331 \begin_inset LatexCommand index
18332 name "\\_\\_asm"
18333
18334 \end_inset
18335
18336  ...
18337  _endasm
18338 \size footnotesize
18339
18340 \begin_inset LatexCommand index
18341 name "\\_endasm"
18342
18343 \end_inset
18344
18345
18346 \begin_inset LatexCommand index
18347 name "\\_\\_endasm"
18348
18349 \end_inset
18350
18351
18352 \size default
18353 ;
18354 \family default
18355  keyword pair.
18356  Specifically it will not know which registers are used and thus register
18357  pushing/popping
18358 \begin_inset LatexCommand index
18359 name "push/pop"
18360
18361 \end_inset
18362
18363  has to be done manually.
18364  
18365 \end_layout
18366
18367 \begin_layout Standard
18368 It is recommended that each assembly instruction (including labels) be placed
18369  in a separate line (as the example shows).
18370  When the -
18371 \begin_inset ERT
18372 status collapsed
18373
18374 \begin_layout Standard
18375
18376
18377 \backslash
18378 /
18379 \end_layout
18380
18381 \end_inset
18382
18383 -
18384 \emph on
18385 peep-asm
18386 \begin_inset LatexCommand index
18387 name "-\\/-peep-asm"
18388
18389 \end_inset
18390
18391
18392 \emph default
18393  command line option is used, the inline assembler code will be passed through
18394  the peephole optimizer
18395 \begin_inset LatexCommand index
18396 name "Peephole optimizer"
18397
18398 \end_inset
18399
18400 .
18401  There are only a few (if any) cases where this option makes sense, it might
18402  cause some unexpected changes in the inline assembler code.
18403  Please go through the peephole optimizer rules defined in file 
18404 \emph on
18405 SDCCpeeph.def
18406 \emph default
18407  before using this option.
18408 \end_layout
18409
18410 \begin_layout Subsection
18411 Naked Functions
18412 \begin_inset LatexCommand label
18413 name "sub:Naked-Functions"
18414
18415 \end_inset
18416
18417
18418 \begin_inset LatexCommand index
18419 name "Naked functions"
18420
18421 \end_inset
18422
18423
18424 \end_layout
18425
18426 \begin_layout Standard
18427 A special keyword may be associated with a function declaring it as 
18428 \emph on
18429 _naked
18430 \begin_inset LatexCommand index
18431 name "\\_naked"
18432
18433 \end_inset
18434
18435
18436 \begin_inset LatexCommand index
18437 name "\\_\\_naked"
18438
18439 \end_inset
18440
18441 .
18442
18443 \emph default
18444  The 
18445 \emph on
18446 _naked
18447 \emph default
18448  function modifier attribute prevents the compiler from generating prologue
18449 \begin_inset LatexCommand index
18450 name "function prologue"
18451
18452 \end_inset
18453
18454  and epilogue
18455 \begin_inset LatexCommand index
18456 name "function epilogue"
18457
18458 \end_inset
18459
18460  code for that function.
18461  This means that the user is entirely responsible for such things as saving
18462  any registers that may need to be preserved, selecting the proper register
18463  bank, generating the 
18464 \emph on
18465 return
18466 \emph default
18467  instruction at the end, etc.
18468  Practically, this means that the contents of the function must be written
18469  in inline assembler.
18470  This is particularly useful for interrupt functions, which can have a large
18471  (and often unnecessary) prologue/epilogue.
18472  For example, compare the code generated by these two functions:
18473 \end_layout
18474
18475 \begin_layout Verse
18476
18477 \family typewriter
18478 volatile
18479 \begin_inset LatexCommand index
18480 name "volatile"
18481
18482 \end_inset
18483
18484  data unsigned char counter;
18485 \newline
18486
18487 \newline
18488 void simpleInterrupt(void) __interrupt
18489 \begin_inset LatexCommand index
18490 name "interrupt"
18491
18492 \end_inset
18493
18494
18495 \begin_inset LatexCommand index
18496 name "\\_\\_interrupt"
18497
18498 \end_inset
18499
18500  (1)
18501 \newline
18502 {
18503 \newline
18504 \InsetSpace ~
18505 \InsetSpace ~
18506 \InsetSpace ~
18507 \InsetSpace ~
18508 counter++;
18509 \newline
18510 }
18511 \newline
18512
18513 \newline
18514 void nakedInterrupt(void) __interrupt (2) __naked
18515 \newline
18516 {
18517 \newline
18518 \InsetSpace ~
18519 \InsetSpace ~
18520 \InsetSpace ~
18521 \InsetSpace ~
18522 _asm
18523 \begin_inset LatexCommand index
18524 name "\\_asm"
18525
18526 \end_inset
18527
18528
18529 \begin_inset LatexCommand index
18530 name "\\_\\_asm"
18531
18532 \end_inset
18533
18534
18535 \newline
18536 \InsetSpace ~
18537 \InsetSpace ~
18538 \InsetSpace ~
18539 \InsetSpace ~
18540 \InsetSpace ~
18541 \InsetSpace ~
18542 inc\InsetSpace ~
18543 \InsetSpace ~
18544 \InsetSpace ~
18545 \InsetSpace ~
18546 \InsetSpace ~
18547 _counter ; does not change flags, no need to save psw
18548 \newline
18549 \InsetSpace ~
18550 \InsetSpace ~
18551 \InsetSpace ~
18552 \InsetSpace ~
18553 \InsetSpace ~
18554 \InsetSpace ~
18555 reti\InsetSpace ~
18556 \InsetSpace ~
18557 \InsetSpace ~
18558 \InsetSpace ~
18559 ; MUST explicitly
18560  include ret or reti in _naked function.
18561 \newline
18562 \InsetSpace ~
18563 \InsetSpace ~
18564 \InsetSpace ~
18565 \InsetSpace ~
18566 _endasm
18567 \begin_inset LatexCommand index
18568 name "\\_endasm"
18569
18570 \end_inset
18571
18572
18573 \begin_inset LatexCommand index
18574 name "\\_\\_endasm"
18575
18576 \end_inset
18577
18578 ;
18579 \newline
18580 }
18581 \end_layout
18582
18583 \begin_layout Standard
18584 For an 8051 target, the generated simpleInterrupt looks like:
18585 \end_layout
18586
18587 \begin_layout Verse
18588
18589 \family typewriter
18590 Note, this is an
18591 \family default
18592  
18593 \family typewriter
18594 \emph on
18595 outdated
18596 \family default
18597 \emph default
18598  
18599 \family typewriter
18600 example, recent versions of SDCC generate
18601 \newline
18602 the
18603 \family default
18604  
18605 \family typewriter
18606 \emph on
18607 same
18608 \family default
18609 \emph default
18610  
18611 \family typewriter
18612 code for simpleInterrupt() and nakedInterrupt()!
18613 \newline
18614
18615 \newline
18616 _simpleInterrupt:
18617 \newline
18618 \InsetSpace ~
18619 \InsetSpace ~
18620 \InsetSpace ~
18621 \InsetSpace ~
18622 push\InsetSpace ~
18623 \InsetSpace ~
18624 \InsetSpace ~
18625 \InsetSpace ~
18626 acc
18627 \newline
18628 \InsetSpace ~
18629 \InsetSpace ~
18630 \InsetSpace ~
18631 \InsetSpace ~
18632 push\InsetSpace ~
18633 \InsetSpace ~
18634 \InsetSpace ~
18635 \InsetSpace ~
18636 b
18637 \newline
18638 \InsetSpace ~
18639 \InsetSpace ~
18640 \InsetSpace ~
18641 \InsetSpace ~
18642 pus
18643 h\InsetSpace ~
18644 \InsetSpace ~
18645 \InsetSpace ~
18646 \InsetSpace ~
18647 dpl
18648 \newline
18649 \InsetSpace ~
18650 \InsetSpace ~
18651 \InsetSpace ~
18652 \InsetSpace ~
18653 push\InsetSpace ~
18654 \InsetSpace ~
18655 \InsetSpace ~
18656 \InsetSpace ~
18657 dph
18658 \newline
18659 \InsetSpace ~
18660 \InsetSpace ~
18661 \InsetSpace ~
18662 \InsetSpace ~
18663 push\InsetSpace ~
18664 \InsetSpace ~
18665 \InsetSpace ~
18666 \InsetSpace ~
18667 psw
18668 \newline
18669 \InsetSpace ~
18670 \InsetSpace ~
18671 \InsetSpace ~
18672 \InsetSpace ~
18673 mov\InsetSpace ~
18674 \InsetSpace ~
18675 \InsetSpace ~
18676 \InsetSpace ~
18677 \InsetSpace ~
18678 psw,#0x00
18679 \newline
18680 \InsetSpace ~
18681 \InsetSpace ~
18682 \InsetSpace ~
18683 \InsetSpace ~
18684 inc\InsetSpace ~
18685 \InsetSpace ~
18686 \InsetSpace ~
18687 \InsetSpace ~
18688 \InsetSpace ~
18689 _counter
18690 \newline
18691 \InsetSpace ~
18692 \InsetSpace ~
18693 \InsetSpace ~
18694 \InsetSpace ~
18695 pop\InsetSpace ~
18696 \InsetSpace ~
18697 \InsetSpace ~
18698 \InsetSpace ~
18699 \InsetSpace ~
18700 psw
18701 \newline
18702 \InsetSpace ~
18703 \InsetSpace ~
18704 \InsetSpace ~
18705 \InsetSpace ~
18706 pop\InsetSpace ~
18707 \InsetSpace ~
18708 \InsetSpace ~
18709 \InsetSpace ~
18710 \InsetSpace ~
18711 dph
18712 \newline
18713 \InsetSpace ~
18714 \InsetSpace ~
18715 \InsetSpace ~
18716 \InsetSpace ~
18717 pop\InsetSpace ~
18718 \InsetSpace ~
18719 \InsetSpace ~
18720 \InsetSpace ~
18721 \InsetSpace ~
18722 dpl
18723 \newline
18724 \InsetSpace ~
18725 \InsetSpace ~
18726 \InsetSpace ~
18727 \InsetSpace ~
18728 pop\InsetSpace ~
18729 \InsetSpace ~
18730 \InsetSpace ~
18731 \InsetSpace ~
18732 \InsetSpace ~
18733 b
18734 \newline
18735 \InsetSpace ~
18736 \InsetSpace ~
18737 \InsetSpace ~
18738 \InsetSpace ~
18739 pop\InsetSpace ~
18740 \InsetSpace ~
18741 \InsetSpace ~
18742 \InsetSpace ~
18743 \InsetSpace ~
18744 acc
18745 \newline
18746 \InsetSpace ~
18747 \InsetSpace ~
18748 \InsetSpace ~
18749 \InsetSpace ~
18750 reti
18751 \end_layout
18752
18753 \begin_layout Standard
18754 whereas nakedInterrupt looks like:
18755 \end_layout
18756
18757 \begin_layout Verse
18758
18759 \family typewriter
18760 _nakedInterrupt:
18761 \newline
18762 \InsetSpace ~
18763 \InsetSpace ~
18764 \InsetSpace ~
18765 \InsetSpace ~
18766 inc\InsetSpace ~
18767 \InsetSpace ~
18768 \InsetSpace ~
18769 \InsetSpace ~
18770 _counter ; does not change flags, no need to save psw
18771 \newline
18772 \InsetSpace ~
18773 \InsetSpace ~
18774 \InsetSpace ~
18775 \InsetSpace ~
18776 reti\InsetSpace ~
18777 \InsetSpace ~
18778 \InsetSpace ~
18779 \InsetSpace ~
18780 \InsetSpace ~
18781 \InsetSpace ~
18782 \InsetSpace ~
18783 \InsetSpace ~
18784 \InsetSpace ~
18785 \InsetSpace ~
18786 \InsetSpace ~
18787 \InsetSpace ~
18788 ;
18789  MUST explicitly include ret or reti in _naked function
18790 \end_layout
18791
18792 \begin_layout Standard
18793 The related directive #pragma exclude
18794 \begin_inset LatexCommand index
18795 name "\\#pragma exclude"
18796
18797 \end_inset
18798
18799  allows a more fine grained control over pushing & popping
18800 \begin_inset LatexCommand index
18801 name "push/pop"
18802
18803 \end_inset
18804
18805  the registers.
18806 \end_layout
18807
18808 \begin_layout Standard
18809 While there is nothing preventing you from writing C code inside a 
18810 \family typewriter
18811 _naked
18812 \family default
18813  function, there are many ways to shoot yourself in the foot doing this,
18814  and it is recommended that you stick to inline assembler.
18815 \end_layout
18816
18817 \begin_layout Subsection
18818 Use of Labels within Inline Assembler
18819 \end_layout
18820
18821 \begin_layout Standard
18822 SDCC allows the use of in-line assembler with a few restrictions regarding
18823  labels.
18824  All labels defined within inline assembler code have to be of the form
18825  
18826 \emph on
18827 nnnnn$
18828 \emph default
18829  where nnnnn is a number less than 100 (which implies a limit of utmost
18830  100 inline assembler labels 
18831 \emph on
18832 per function
18833 \emph default
18834 \noun on
18835 )
18836 \noun default
18837 .
18838 \begin_inset Foot
18839 status open
18840
18841 \begin_layout Standard
18842 This is a slightly more stringent rule than absolutely necessary, but stays
18843  always on the safe side.
18844  Labels in the form of nnnnn$ are local labels in the assembler, locality
18845  of which is confined within two labels of the standard form.
18846  The compiler uses the same form for labels within a function (but starting
18847  from nnnnn=00100); and places always a standard label at the beginning
18848  of a function, thus limiting the locality of labels within the scope of
18849  the function.
18850  So, if the inline assembler part would be embedded into C-code, an improperly
18851  placed non-local label in the assembler would break up the reference space
18852  for labels created by the compiler for the C-code, leading to an assembling
18853  error.
18854 \end_layout
18855
18856 \begin_layout Standard
18857 The numeric part of local labels does not need to have 5 digits (although
18858  this is the form of labels output by the compiler), any valid integer will
18859  do.
18860  Please refer to the assemblers documentation for further details.
18861 \end_layout
18862
18863 \end_inset
18864
18865  
18866 \end_layout
18867
18868 \begin_layout Verse
18869
18870 \family typewriter
18871 _asm
18872 \begin_inset LatexCommand index
18873 name "\\_asm"
18874
18875 \end_inset
18876
18877
18878 \begin_inset LatexCommand index
18879 name "\\_\\_asm"
18880
18881 \end_inset
18882
18883  
18884 \newline
18885 \InsetSpace ~
18886 \InsetSpace ~
18887 \InsetSpace ~
18888 \InsetSpace ~
18889 mov\InsetSpace ~
18890 \InsetSpace ~
18891 \InsetSpace ~
18892 \InsetSpace ~
18893 \InsetSpace ~
18894 b,#10 
18895 \newline
18896 00001$: 
18897 \newline
18898 \InsetSpace ~
18899 \InsetSpace ~
18900 \InsetSpace ~
18901 \InsetSpace ~
18902 djnz\InsetSpace ~
18903 \InsetSpace ~
18904 \InsetSpace ~
18905 \InsetSpace ~
18906 b,00001$ 
18907 \newline
18908 _endasm
18909 \begin_inset LatexCommand index
18910 name "\\_endasm"
18911
18912 \end_inset
18913
18914
18915 \begin_inset LatexCommand index
18916 name "\\_\\_endasm"
18917
18918 \end_inset
18919
18920  ;
18921 \end_layout
18922
18923 \begin_layout Standard
18924 Inline assembler code cannot reference any C-labels, however it can reference
18925  labels
18926 \begin_inset LatexCommand index
18927 name "Labels"
18928
18929 \end_inset
18930
18931  defined by the inline assembler, e.g.:
18932 \end_layout
18933
18934 \begin_layout Verse
18935
18936 \family typewriter
18937 foo() { 
18938 \newline
18939 \InsetSpace ~
18940 \InsetSpace ~
18941 \InsetSpace ~
18942 \InsetSpace ~
18943 /* some c code */ 
18944 \newline
18945 \InsetSpace ~
18946 \InsetSpace ~
18947 \InsetSpace ~
18948 \InsetSpace ~
18949 _asm 
18950 \newline
18951 \InsetSpace ~
18952 \InsetSpace ~
18953 \InsetSpace ~
18954 \InsetSpace ~
18955 \InsetSpace ~
18956 \InsetSpace ~
18957 ; some assembler code 
18958 \newline
18959 \InsetSpace ~
18960 \InsetSpace ~
18961 \InsetSpace ~
18962 \InsetSpace ~
18963 \InsetSpace ~
18964 \InsetSpace ~
18965 ljmp 0003$ 
18966 \newline
18967 \InsetSpace ~
18968 \InsetSpace ~
18969 \InsetSpace ~
18970 \InsetSpace ~
18971 _endasm;
18972  
18973 \newline
18974 \InsetSpace ~
18975 \InsetSpace ~
18976 \InsetSpace ~
18977 \InsetSpace ~
18978 /* some more c code */ 
18979 \newline
18980 clabel:\InsetSpace ~
18981 \InsetSpace ~
18982 /* inline assembler cannot reference this
18983  label */ 
18984 \begin_inset Foot
18985 status open
18986
18987 \begin_layout Standard
18988 Here, the C-label 
18989 \family typewriter
18990 clabel
18991 \family default
18992  is translated by the compiler into a local label, so the locality of labels
18993  within the function is not broken.
18994 \end_layout
18995
18996 \end_inset
18997
18998
18999 \newline
19000 \InsetSpace ~
19001 \InsetSpace ~
19002 \InsetSpace ~
19003 \InsetSpace ~
19004 _asm
19005 \newline
19006 \InsetSpace ~
19007 \InsetSpace ~
19008 \InsetSpace ~
19009 \InsetSpace ~
19010 0003$: ;label (can be referenced by inline assembler only) 
19011 \newline
19012 \InsetSpace ~
19013 \InsetSpace ~
19014 \InsetSpace ~
19015 \InsetSpace ~
19016 _endasm
19017 \begin_inset LatexCommand index
19018 name "\\_endasm"
19019
19020 \end_inset
19021
19022
19023 \begin_inset LatexCommand index
19024 name "\\_\\_endasm"
19025
19026 \end_inset
19027
19028  ; 
19029 \newline
19030 \InsetSpace ~
19031 \InsetSpace ~
19032 \InsetSpace ~
19033 \InsetSpace ~
19034 /* some more c code */
19035 \newline
19036 }
19037 \end_layout
19038
19039 \begin_layout Standard
19040 In other words inline assembly code can access labels defined in inline
19041  assembly within the scope of the function.
19042  The same goes the other way, i.e.
19043  labels defines in inline assembly can not be accessed by C statements.
19044 \end_layout
19045
19046 \begin_layout Section
19047 Interfacing with Assembler Code
19048 \begin_inset LatexCommand index
19049 name "Assembler routines"
19050
19051 \end_inset
19052
19053
19054 \end_layout
19055
19056 \begin_layout Subsection
19057 Global Registers used for Parameter Passing
19058 \begin_inset LatexCommand index
19059 name "Parameter passing"
19060
19061 \end_inset
19062
19063
19064 \end_layout
19065
19066 \begin_layout Standard
19067 The compiler always uses the global registers 
19068 \emph on
19069 DPL, DPH
19070 \begin_inset LatexCommand index
19071 name "DPTR, DPH, DPL"
19072
19073 \end_inset
19074
19075
19076 \begin_inset LatexCommand index
19077 name "DPTR"
19078
19079 \end_inset
19080
19081 , B
19082 \begin_inset LatexCommand index
19083 name "B (mcs51, ds390 register)"
19084
19085 \end_inset
19086
19087
19088 \emph default
19089  and 
19090 \emph on
19091 ACC
19092 \begin_inset LatexCommand index
19093 name "ACC (mcs51, ds390 register)"
19094
19095 \end_inset
19096
19097
19098 \emph default
19099  to pass the first (non-bit) parameter to a function, and also to pass the
19100  return value 
19101 \begin_inset LatexCommand index
19102 name "return value"
19103
19104 \end_inset
19105
19106 of function; according to the following scheme: one byte return value in
19107  
19108 \emph on
19109 DPL
19110 \emph default
19111 , two byte value in 
19112 \emph on
19113 DPL
19114 \emph default
19115  (LSB) and 
19116 \emph on
19117 DPH
19118 \emph default
19119  (MSB).
19120  three byte values (generic pointers) in 
19121 \emph on
19122 DPH
19123 \emph default
19124
19125 \emph on
19126 DPL
19127 \emph default
19128  and 
19129 \emph on
19130 B
19131 \emph default
19132 , and four byte values in 
19133 \emph on
19134 DPH
19135 \emph default
19136
19137 \emph on
19138 DPL
19139 \emph default
19140
19141 \emph on
19142 B
19143 \emph default
19144  and 
19145 \emph on
19146 ACC
19147 \emph default
19148 .
19149  Generic pointers
19150 \begin_inset LatexCommand index
19151 name "generic pointer"
19152
19153 \end_inset
19154
19155  contain type of accessed memory in 
19156 \emph on
19157 B
19158 \emph default
19159
19160 \series bold
19161 0x00
19162 \series default
19163  -- xdata/far, 
19164 \series bold
19165 0x40
19166 \series default
19167  -- idata/near -- , 
19168 \series bold
19169 0x60
19170 \series default
19171  -- pdata, 
19172 \series bold
19173 0x80
19174 \series default
19175  -- code
19176 \begin_inset Note Note
19177 status collapsed
19178
19179 \begin_layout Standard
19180 This might not be the case of certain memory models (medium???)
19181 \end_layout
19182
19183 \end_inset
19184
19185 .
19186 \end_layout
19187
19188 \begin_layout Standard
19189 The second parameter onwards is either allocated on the stack (for reentrant
19190  routines or if -
19191 \begin_inset ERT
19192 status collapsed
19193
19194 \begin_layout Standard
19195
19196
19197 \backslash
19198 /
19199 \end_layout
19200
19201 \end_inset
19202
19203 -stack-auto is used) or in data/xdata memory (depending on the memory model).
19204 \end_layout
19205
19206 \begin_layout Standard
19207 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
19208  space for reentrant functions or allocated directly in bit memory otherwise.
19209 \end_layout
19210
19211 \begin_layout Standard
19212 Functions (with two or more parameters or bit parameters) that are called
19213  through function pointers
19214 \begin_inset LatexCommand index
19215 name "function pointers"
19216
19217 \end_inset
19218
19219  must therefor be reentrant so the compiler knows how to pass the parameters.
19220 \end_layout
19221
19222 \begin_layout Subsection
19223 Registers usage
19224 \end_layout
19225
19226 \begin_layout Standard
19227 Unless the called function is declared as 
19228 \family typewriter
19229 _naked
19230 \family default
19231
19232 \begin_inset LatexCommand index
19233 name "naked"
19234
19235 \end_inset
19236
19237 , or the -
19238 \begin_inset ERT
19239 status collapsed
19240
19241 \begin_layout Standard
19242
19243
19244 \backslash
19245 /
19246 \end_layout
19247
19248 \end_inset
19249
19250 -callee-saves
19251 \begin_inset LatexCommand index
19252 name "-\\/-callee-saves"
19253
19254 \end_inset
19255
19256 /-
19257 \begin_inset ERT
19258 status collapsed
19259
19260 \begin_layout Standard
19261
19262
19263 \backslash
19264 /
19265 \end_layout
19266
19267 \end_inset
19268
19269 -all-callee-saves command line option or the corresponding callee_saves
19270  pragma are used, the caller will save the registers (
19271 \emph on
19272 R0-R7
19273 \emph default
19274 ) around the call, so the called function can destroy they content freely.
19275 \end_layout
19276
19277 \begin_layout Standard
19278 If the called function is not declared as 
19279 \family typewriter
19280 _naked
19281 \family default
19282 , the caller will swap register banks around the call, if caller and callee
19283  use different register banks (having them defined by the 
19284 \family typewriter
19285 _using
19286 \family default
19287  modifier).
19288  
19289 \end_layout
19290
19291 \begin_layout Standard
19292 The called function can also use 
19293 \emph on
19294 DPL
19295 \emph default
19296
19297 \emph on
19298 DPH
19299 \emph default
19300
19301 \emph on
19302 B
19303 \emph default
19304  and 
19305 \emph on
19306 ACC
19307 \emph default
19308  observing that they are used for parameter/return value passing.
19309 \end_layout
19310
19311 \begin_layout Subsection
19312 Assembler Routine (non-reentrant)
19313 \end_layout
19314
19315 \begin_layout Standard
19316 In the following example
19317 \begin_inset LatexCommand index
19318 name "reentrant"
19319
19320 \end_inset
19321
19322
19323 \begin_inset LatexCommand index
19324 name "Assembler routines (non-reentrant)"
19325
19326 \end_inset
19327
19328  the function c_func calls an assembler routine asm_func, which takes two
19329  parameters
19330 \begin_inset LatexCommand index
19331 name "function parameter"
19332
19333 \end_inset
19334
19335 .
19336 \end_layout
19337
19338 \begin_layout Verse
19339
19340 \family typewriter
19341 extern int asm_func(unsigned char, unsigned char);
19342 \newline
19343
19344 \newline
19345 int c_func (unsigned char
19346  i, unsigned char j)
19347 \newline
19348 {
19349 \newline
19350 \InsetSpace ~
19351 \InsetSpace ~
19352 \InsetSpace ~
19353 \InsetSpace ~
19354 return asm_func(i,j);
19355 \newline
19356 }
19357 \newline
19358
19359 \newline
19360 int main()
19361 \newline
19362 {
19363 \newline
19364 \InsetSpace ~
19365 \InsetSpace ~
19366 \InsetSpace ~
19367 \InsetSpace ~
19368 return c_func(10,9);
19369 \newline
19370 }
19371 \end_layout
19372
19373 \begin_layout Standard
19374 The corresponding assembler function is:
19375 \end_layout
19376
19377 \begin_layout Verse
19378
19379 \family typewriter
19380 .globl _asm_func_PARM_2 
19381 \newline
19382 \InsetSpace ~
19383 \InsetSpace ~
19384 \InsetSpace ~
19385 \InsetSpace ~
19386 \InsetSpace ~
19387 \InsetSpace ~
19388 \InsetSpace ~
19389 \InsetSpace ~
19390 .globl _asm_func 
19391 \newline
19392 \InsetSpace ~
19393 \InsetSpace ~
19394 \InsetSpace ~
19395 \InsetSpace ~
19396 \InsetSpace ~
19397 \InsetSpace ~
19398 \InsetSpace ~
19399 \InsetSpace ~
19400 .area OSEG 
19401 \newline
19402 _asm_func_PARM_2:
19403 \newline
19404 \InsetSpace ~
19405 \InsetSpace ~
19406 \InsetSpace ~
19407 \InsetSpace ~
19408 \InsetSpace ~
19409 \InsetSpace ~
19410 \InsetSpace ~
19411 \InsetSpace ~
19412 .ds   
19413  1 
19414 \newline
19415 \InsetSpace ~
19416 \InsetSpace ~
19417 \InsetSpace ~
19418 \InsetSpace ~
19419 \InsetSpace ~
19420 \InsetSpace ~
19421 \InsetSpace ~
19422 \InsetSpace ~
19423 .area CSEG 
19424 \newline
19425 _asm_func: 
19426 \newline
19427 \InsetSpace ~
19428 \InsetSpace ~
19429 \InsetSpace ~
19430 \InsetSpace ~
19431 \InsetSpace ~
19432 \InsetSpace ~
19433 \InsetSpace ~
19434 \InsetSpace ~
19435 mov\InsetSpace ~
19436 \InsetSpace ~
19437 \InsetSpace ~
19438 \InsetSpace ~
19439 a,dpl 
19440 \newline
19441 \InsetSpace ~
19442 \InsetSpace ~
19443 \InsetSpace ~
19444 \InsetSpace ~
19445 \InsetSpace ~
19446 \InsetSpace ~
19447 \InsetSpace ~
19448 \InsetSpace ~
19449 add\InsetSpace ~
19450 \InsetSpace ~
19451 \InsetSpace ~
19452 \InsetSpace ~
19453 a,_asm_func_PARM_2 
19454 \newline
19455 \InsetSpace ~
19456 \InsetSpace ~
19457 \InsetSpace ~
19458 \InsetSpace ~
19459 \InsetSpace ~
19460 \InsetSpace ~
19461 \InsetSpace ~
19462 \InsetSpace ~
19463 mov\InsetSpace ~
19464 \InsetSpace ~
19465 \InsetSpace ~
19466 \InsetSpace ~
19467 dpl,a 
19468 \newline
19469 \InsetSpace ~
19470 \InsetSpace ~
19471 \InsetSpace ~
19472 \InsetSpace ~
19473 \InsetSpace ~
19474 \InsetSpace ~
19475 \InsetSpace ~
19476 \InsetSpace ~
19477 mov\InsetSpace ~
19478 \InsetSpace ~
19479 \InsetSpace ~
19480 \InsetSpace ~
19481 dph
19482 \begin_inset LatexCommand index
19483 name "DPTR, DPH, DPL"
19484
19485 \end_inset
19486
19487 ,#0x00 
19488 \newline
19489 \InsetSpace ~
19490 \InsetSpace ~
19491 \InsetSpace ~
19492 \InsetSpace ~
19493 \InsetSpace ~
19494 \InsetSpace ~
19495 \InsetSpace ~
19496 \InsetSpace ~
19497 ret
19498 \end_layout
19499
19500 \begin_layout Standard
19501 The parameter naming convention is _<function_name>_PARM_<n>, where n is
19502  the parameter number starting from 1, and counting from the left.
19503  The first parameter is passed in 
19504 \emph on
19505 DPH
19506 \emph default
19507
19508 \emph on
19509 DPL
19510 \emph default
19511
19512 \emph on
19513 B
19514 \emph default
19515  and 
19516 \emph on
19517 ACC
19518 \emph default
19519  according to the description above.
19520  The variable name for the second parameter will be _<function_name>_PARM_2.
19521 \newline
19522
19523 \newline
19524 Assem
19525 ble the assembler routine with the following command:
19526 \newline
19527
19528 \newline
19529
19530 \family sans
19531 \series bold
19532 asx8051 -losg asmfunc.asm
19533 \newline
19534
19535 \newline
19536
19537 \family default
19538 \series default
19539 Then compile and link the assembler routine to the C source file with the
19540  following command:
19541 \newline
19542
19543 \newline
19544
19545 \family sans
19546 \series bold
19547 sdcc cfunc.c asmfunc.rel
19548 \end_layout
19549
19550 \begin_layout Subsection
19551 Assembler Routine (reentrant)
19552 \end_layout
19553
19554 \begin_layout Standard
19555 In this case
19556 \begin_inset LatexCommand index
19557 name "reentrant"
19558
19559 \end_inset
19560
19561
19562 \begin_inset LatexCommand index
19563 name "Assembler routines (reentrant)"
19564
19565 \end_inset
19566
19567  the second parameter
19568 \begin_inset LatexCommand index
19569 name "function parameter"
19570
19571 \end_inset
19572
19573  onwards will be passed on the stack, the parameters are pushed from right
19574  to left i.e.
19575  before the call the second leftmost parameter will be on the top of the
19576  stack (the leftmost parameter is passed in registers).
19577  Here is an example:
19578 \end_layout
19579
19580 \begin_layout Verse
19581
19582 \family typewriter
19583 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
19584 \newline
19585
19586 \newline
19587 int
19588  c_func (unsigned char i, unsigned char j, unsigned char k) reentrant 
19589 \newline
19590 {
19591  
19592 \newline
19593 \InsetSpace ~
19594 \InsetSpace ~
19595 \InsetSpace ~
19596 \InsetSpace ~
19597 return asm_func(i,j,k); 
19598 \newline
19599
19600 \newline
19601
19602 \newline
19603 int main() 
19604 \newline
19605
19606 \newline
19607 \InsetSpace ~
19608 \InsetSpace ~
19609 \InsetSpace ~
19610 \InsetSpace ~
19611 return c_func(10,9,8); 
19612 \newline
19613 }
19614 \end_layout
19615
19616 \begin_layout Standard
19617 The corresponding (unoptimized) assembler routine is:
19618 \end_layout
19619
19620 \begin_layout Verse
19621
19622 \family typewriter
19623 .globl _asm_func 
19624 \newline
19625 _asm_func: 
19626 \newline
19627 \InsetSpace ~
19628 \InsetSpace ~
19629 \InsetSpace ~
19630 \InsetSpace ~
19631 push\InsetSpace ~
19632 _bp 
19633 \newline
19634 \InsetSpace ~
19635 \InsetSpace ~
19636 \InsetSpace ~
19637 \InsetSpace ~
19638 mov\InsetSpace ~
19639 \InsetSpace ~
19640 _bp,sp\InsetSpace ~
19641 \InsetSpace ~
19642 \InsetSpace ~
19643 \InsetSpace ~
19644 \InsetSpace ~
19645 \InsetSpace ~
19646 ;stack contains: _bp, return
19647  address, second parameter, third parameter
19648 \newline
19649 \InsetSpace ~
19650 \InsetSpace ~
19651 \InsetSpace ~
19652 \InsetSpace ~
19653 mov\InsetSpace ~
19654 \InsetSpace ~
19655 r2,dpl
19656 \newline
19657 \InsetSpace ~
19658 \InsetSpace ~
19659 \InsetSpace ~
19660 \InsetSpace ~
19661 mov\InsetSpace ~
19662 \InsetSpace ~
19663 a,_bp
19664 \newline
19665 \InsetSpace ~
19666 \InsetSpace ~
19667 \InsetSpace ~
19668 \InsetSpace ~
19669 add\InsetSpace ~
19670 \InsetSpace ~
19671 a,#0xfd\InsetSpace ~
19672 \InsetSpace ~
19673 \InsetSpace ~
19674 \InsetSpace ~
19675 \InsetSpace ~
19676 ;calculate
19677  pointer to the second parameter
19678 \newline
19679 \InsetSpace ~
19680 \InsetSpace ~
19681 \InsetSpace ~
19682 \InsetSpace ~
19683 mov\InsetSpace ~
19684 \InsetSpace ~
19685 r0,a 
19686 \newline
19687 \InsetSpace ~
19688 \InsetSpace ~
19689 \InsetSpace ~
19690 \InsetSpace ~
19691 mov\InsetSpace ~
19692 \InsetSpace ~
19693 a,_bp 
19694 \newline
19695 \InsetSpace ~
19696 \InsetSpace ~
19697 \InsetSpace ~
19698 \InsetSpace ~
19699 add\InsetSpace ~
19700 \InsetSpace ~
19701 a,#0xfc\InsetSpace ~
19702 \InsetSpace ~
19703 \InsetSpace ~
19704 \InsetSpace ~
19705 \InsetSpace ~
19706 ;calculate pointer
19707  to the rightmost parameter
19708 \newline
19709 \InsetSpace ~
19710 \InsetSpace ~
19711 \InsetSpace ~
19712 \InsetSpace ~
19713 mov\InsetSpace ~
19714 \InsetSpace ~
19715 r1,a 
19716 \newline
19717 \InsetSpace ~
19718 \InsetSpace ~
19719 \InsetSpace ~
19720 \InsetSpace ~
19721 mov\InsetSpace ~
19722 \InsetSpace ~
19723 a,@r0
19724 \newline
19725 \InsetSpace ~
19726 \InsetSpace ~
19727 \InsetSpace ~
19728 \InsetSpace ~
19729 add\InsetSpace ~
19730 \InsetSpace ~
19731 a,@r1
19732 \newline
19733 \InsetSpace ~
19734 \InsetSpace ~
19735 \InsetSpace ~
19736 \InsetSpace ~
19737 add\InsetSpace ~
19738 \InsetSpace ~
19739 a,r2\InsetSpace ~
19740 \InsetSpace ~
19741 \InsetSpace ~
19742 \InsetSpace ~
19743 \InsetSpace ~
19744 \InsetSpace ~
19745 \InsetSpace ~
19746 \InsetSpace ~
19747 ;calculate the
19748  result (= sum of all three parameters)
19749 \newline
19750 \InsetSpace ~
19751 \InsetSpace ~
19752 \InsetSpace ~
19753 \InsetSpace ~
19754 mov\InsetSpace ~
19755 \InsetSpace ~
19756 dpl,a\InsetSpace ~
19757 \InsetSpace ~
19758 \InsetSpace ~
19759 \InsetSpace ~
19760 \InsetSpace ~
19761 \InsetSpace ~
19762 \InsetSpace ~
19763 ;return value goes into dptr
19764  (cast into int)
19765 \newline
19766 \InsetSpace ~
19767 \InsetSpace ~
19768 \InsetSpace ~
19769 \InsetSpace ~
19770 mov\InsetSpace ~
19771 \InsetSpace ~
19772 dph,#0x00 
19773 \newline
19774 \InsetSpace ~
19775 \InsetSpace ~
19776 \InsetSpace ~
19777 \InsetSpace ~
19778 mov\InsetSpace ~
19779 \InsetSpace ~
19780 sp,_bp 
19781 \newline
19782 \InsetSpace ~
19783 \InsetSpace ~
19784 \InsetSpace ~
19785 \InsetSpace ~
19786 pop\InsetSpace ~
19787 \InsetSpace ~
19788 _bp 
19789 \newline
19790 \InsetSpace ~
19791 \InsetSpace ~
19792 \InsetSpace ~
19793 \InsetSpace ~
19794 ret
19795 \end_layout
19796
19797 \begin_layout Standard
19798 The compiling and linking procedure remains the same, however note the extra
19799  entry & exit linkage required for the assembler code, _bp is the stack
19800  frame pointer and is used to compute the offset into the stack for parameters
19801  and local variables.
19802 \begin_inset VSpace bigskip
19803 \end_inset
19804
19805
19806 \end_layout
19807
19808 \begin_layout Section
19809 int (16 bit)
19810 \begin_inset LatexCommand index
19811 name "int (16 bit)"
19812
19813 \end_inset
19814
19815  and long (32 bit)
19816 \begin_inset LatexCommand index
19817 name "long (32 bit)"
19818
19819 \end_inset
19820
19821  Support
19822 \end_layout
19823
19824 \begin_layout Standard
19825 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
19826  multiplication and modulus operations are implemented by support routines.
19827  These support routines are all developed in ANSI-C to facilitate porting
19828  to other MCUs, although some model specific assembler optimizations are
19829  used.
19830  The following files contain the described routines, all of them can be
19831  found in <installdir>/share/sdcc/lib.
19832 \newline
19833
19834 \end_layout
19835
19836 \begin_layout Standard
19837 \align center
19838 \begin_inset Tabular
19839 <lyxtabular version="3" rows="11" columns="2">
19840 <features>
19841 <column alignment="left" valignment="top" leftline="true" width="0">
19842 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19843 <row topline="true" bottomline="true">
19844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19845 \begin_inset Text
19846
19847 \begin_layout Standard
19848
19849 \series bold
19850 Function
19851 \end_layout
19852
19853 \end_inset
19854 </cell>
19855 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19856 \begin_inset Text
19857
19858 \begin_layout Standard
19859
19860 \series bold
19861 Description
19862 \end_layout
19863
19864 \end_inset
19865 </cell>
19866 </row>
19867 <row topline="true">
19868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19869 \begin_inset Text
19870
19871 \begin_layout Standard
19872 _mulint.c 
19873 \end_layout
19874
19875 \end_inset
19876 </cell>
19877 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19878 \begin_inset Text
19879
19880 \begin_layout Standard
19881 16 bit multiplication
19882 \end_layout
19883
19884 \end_inset
19885 </cell>
19886 </row>
19887 <row topline="true">
19888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19889 \begin_inset Text
19890
19891 \begin_layout Standard
19892 _divsint.c 
19893 \end_layout
19894
19895 \end_inset
19896 </cell>
19897 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19898 \begin_inset Text
19899
19900 \begin_layout Standard
19901  signed 16 bit division (calls _divuint)
19902 \end_layout
19903
19904 \end_inset
19905 </cell>
19906 </row>
19907 <row topline="true">
19908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19909 \begin_inset Text
19910
19911 \begin_layout Standard
19912 _divuint.c 
19913 \end_layout
19914
19915 \end_inset
19916 </cell>
19917 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19918 \begin_inset Text
19919
19920 \begin_layout Standard
19921  unsigned 16 bit division
19922 \end_layout
19923
19924 \end_inset
19925 </cell>
19926 </row>
19927 <row topline="true">
19928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19929 \begin_inset Text
19930
19931 \begin_layout Standard
19932 _modsint.c
19933 \end_layout
19934
19935 \end_inset
19936 </cell>
19937 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19938 \begin_inset Text
19939
19940 \begin_layout Standard
19941 signed 16 bit modulus (calls _moduint)
19942 \end_layout
19943
19944 \end_inset
19945 </cell>
19946 </row>
19947 <row topline="true">
19948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19949 \begin_inset Text
19950
19951 \begin_layout Standard
19952 _moduint.c
19953 \end_layout
19954
19955 \end_inset
19956 </cell>
19957 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19958 \begin_inset Text
19959
19960 \begin_layout Standard
19961 unsigned 16 bit modulus
19962 \end_layout
19963
19964 \end_inset
19965 </cell>
19966 </row>
19967 <row topline="true">
19968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19969 \begin_inset Text
19970
19971 \begin_layout Standard
19972 _mullong.c
19973 \end_layout
19974
19975 \end_inset
19976 </cell>
19977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19978 \begin_inset Text
19979
19980 \begin_layout Standard
19981 32 bit multiplication
19982 \end_layout
19983
19984 \end_inset
19985 </cell>
19986 </row>
19987 <row topline="true">
19988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19989 \begin_inset Text
19990
19991 \begin_layout Standard
19992 _divslong.c 
19993 \end_layout
19994
19995 \end_inset
19996 </cell>
19997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19998 \begin_inset Text
19999
20000 \begin_layout Standard
20001  signed 32 division (calls _divulong)
20002 \end_layout
20003
20004 \end_inset
20005 </cell>
20006 </row>
20007 <row topline="true">
20008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20009 \begin_inset Text
20010
20011 \begin_layout Standard
20012 _divulong.c 
20013 \end_layout
20014
20015 \end_inset
20016 </cell>
20017 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20018 \begin_inset Text
20019
20020 \begin_layout Standard
20021 unsigned 32 division
20022 \end_layout
20023
20024 \end_inset
20025 </cell>
20026 </row>
20027 <row topline="true">
20028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20029 \begin_inset Text
20030
20031 \begin_layout Standard
20032 _modslong.c
20033 \end_layout
20034
20035 \end_inset
20036 </cell>
20037 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20038 \begin_inset Text
20039
20040 \begin_layout Standard
20041  signed 32 bit modulus (calls _modulong)
20042 \end_layout
20043
20044 \end_inset
20045 </cell>
20046 </row>
20047 <row topline="true" bottomline="true">
20048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20049 \begin_inset Text
20050
20051 \begin_layout Standard
20052 _modulong.c
20053 \end_layout
20054
20055 \end_inset
20056 </cell>
20057 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20058 \begin_inset Text
20059
20060 \begin_layout Standard
20061 unsigned 32 bit modulus
20062 \end_layout
20063
20064 \end_inset
20065 </cell>
20066 </row>
20067 </lyxtabular>
20068
20069 \end_inset
20070
20071
20072 \newline
20073
20074 \end_layout
20075
20076 \begin_layout Standard
20077 Since they are compiled as 
20078 \emph on
20079 non-reentrant
20080 \emph default
20081
20082 \begin_inset LatexCommand index
20083 name "reentrant"
20084
20085 \end_inset
20086
20087 , interrupt
20088 \begin_inset LatexCommand index
20089 name "interrupt"
20090
20091 \end_inset
20092
20093  service routines should not do any of the above operations.
20094  If this is unavoidable then the above routines will need to be compiled
20095  with the 
20096 \emph on
20097 -
20098 \begin_inset ERT
20099 status collapsed
20100
20101 \begin_layout Standard
20102
20103
20104 \backslash
20105 /
20106 \end_layout
20107
20108 \end_inset
20109
20110 -stack-auto
20111 \begin_inset LatexCommand index
20112 name "-\\/-stack-auto"
20113
20114 \end_inset
20115
20116
20117 \emph default
20118  option, after which the source program will have to be compiled with 
20119 \emph on
20120 -
20121 \begin_inset ERT
20122 status collapsed
20123
20124 \begin_layout Standard
20125
20126
20127 \backslash
20128 /
20129 \end_layout
20130
20131 \end_inset
20132
20133 -int-long-reent
20134 \begin_inset LatexCommand index
20135 name "-\\/-int-long-reent"
20136
20137 \end_inset
20138
20139
20140 \emph default
20141  option.
20142  Notice that you don't have to call these routines directly.
20143  The compiler will use them automatically every time an integer operation
20144  is required.
20145 \end_layout
20146
20147 \begin_layout Section
20148 Floating Point Support
20149 \begin_inset LatexCommand index
20150 name "Floating point support"
20151
20152 \end_inset
20153
20154
20155 \end_layout
20156
20157 \begin_layout Standard
20158 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
20159  The floating point support routines are derived from gcc's floatlib.c and
20160  consist of the following routines:
20161 \newline
20162
20163 \end_layout
20164
20165 \begin_layout Standard
20166 \align center
20167
20168 \size footnotesize
20169 \begin_inset Tabular
20170 <lyxtabular version="3" rows="17" columns="2">
20171 <features>
20172 <column alignment="left" valignment="top" leftline="true" width="0">
20173 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
20174 <row topline="true" bottomline="true">
20175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20176 \begin_inset Text
20177
20178 \begin_layout Standard
20179
20180 \family roman
20181 \series medium
20182 \shape up
20183 \size normal
20184 \emph off
20185 \bar no
20186 \noun off
20187 \color none
20188 Function 
20189 \end_layout
20190
20191 \end_inset
20192 </cell>
20193 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20194 \begin_inset Text
20195
20196 \begin_layout Standard
20197 Description
20198 \end_layout
20199
20200 \end_inset
20201 </cell>
20202 </row>
20203 <row topline="true">
20204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20205 \begin_inset Text
20206
20207 \begin_layout Standard
20208
20209 \family roman
20210 \series medium
20211 \shape up
20212 \size normal
20213 \emph off
20214 \bar no
20215 \noun off
20216 \color none
20217 _fsadd.c
20218 \end_layout
20219
20220 \end_inset
20221 </cell>
20222 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20223 \begin_inset Text
20224
20225 \begin_layout Standard
20226
20227 \family roman
20228 \series medium
20229 \shape up
20230 \size normal
20231 \emph off
20232 \bar no
20233 \noun off
20234 \color none
20235 add floating point numbers
20236 \end_layout
20237
20238 \end_inset
20239 </cell>
20240 </row>
20241 <row topline="true">
20242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20243 \begin_inset Text
20244
20245 \begin_layout Standard
20246
20247 \family roman
20248 \series medium
20249 \shape up
20250 \size normal
20251 \emph off
20252 \bar no
20253 \noun off
20254 \color none
20255 _fssub.c 
20256 \end_layout
20257
20258 \end_inset
20259 </cell>
20260 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20261 \begin_inset Text
20262
20263 \begin_layout Standard
20264
20265 \family roman
20266 \series medium
20267 \shape up
20268 \size normal
20269 \emph off
20270 \bar no
20271 \noun off
20272 \color none
20273 subtract floating point numbers 
20274 \end_layout
20275
20276 \end_inset
20277 </cell>
20278 </row>
20279 <row topline="true">
20280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20281 \begin_inset Text
20282
20283 \begin_layout Standard
20284
20285 \family roman
20286 \series medium
20287 \shape up
20288 \size normal
20289 \emph off
20290 \bar no
20291 \noun off
20292 \color none
20293 _fsdiv.c 
20294 \end_layout
20295
20296 \end_inset
20297 </cell>
20298 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20299 \begin_inset Text
20300
20301 \begin_layout Standard
20302
20303 \family roman
20304 \series medium
20305 \shape up
20306 \size normal
20307 \emph off
20308 \bar no
20309 \noun off
20310 \color none
20311 divide floating point numbers 
20312 \end_layout
20313
20314 \end_inset
20315 </cell>
20316 </row>
20317 <row topline="true">
20318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20319 \begin_inset Text
20320
20321 \begin_layout Standard
20322
20323 \family roman
20324 \series medium
20325 \shape up
20326 \size normal
20327 \emph off
20328 \bar no
20329 \noun off
20330 \color none
20331 _fsmul.c 
20332 \end_layout
20333
20334 \end_inset
20335 </cell>
20336 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20337 \begin_inset Text
20338
20339 \begin_layout Standard
20340
20341 \family roman
20342 \series medium
20343 \shape up
20344 \size normal
20345 \emph off
20346 \bar no
20347 \noun off
20348 \color none
20349 multiply floating point numbers 
20350 \end_layout
20351
20352 \end_inset
20353 </cell>
20354 </row>
20355 <row topline="true">
20356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20357 \begin_inset Text
20358
20359 \begin_layout Standard
20360
20361 \family roman
20362 \series medium
20363 \shape up
20364 \size normal
20365 \emph off
20366 \bar no
20367 \noun off
20368 \color none
20369 _fs2uchar.c
20370 \end_layout
20371
20372 \end_inset
20373 </cell>
20374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20375 \begin_inset Text
20376
20377 \begin_layout Standard
20378
20379 \family roman
20380 \series medium
20381 \shape up
20382 \size normal
20383 \emph off
20384 \bar no
20385 \noun off
20386 \color none
20387 convert floating point to unsigned char
20388 \end_layout
20389
20390 \end_inset
20391 </cell>
20392 </row>
20393 <row topline="true">
20394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20395 \begin_inset Text
20396
20397 \begin_layout Standard
20398
20399 \family roman
20400 \series medium
20401 \shape up
20402 \size normal
20403 \emph off
20404 \bar no
20405 \noun off
20406 \color none
20407 _fs2char.c
20408 \end_layout
20409
20410 \end_inset
20411 </cell>
20412 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20413 \begin_inset Text
20414
20415 \begin_layout Standard
20416
20417 \family roman
20418 \series medium
20419 \shape up
20420 \size normal
20421 \emph off
20422 \bar no
20423 \noun off
20424 \color none
20425 convert floating point to signed char
20426 \end_layout
20427
20428 \end_inset
20429 </cell>
20430 </row>
20431 <row topline="true">
20432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20433 \begin_inset Text
20434
20435 \begin_layout Standard
20436
20437 \family roman
20438 \series medium
20439 \shape up
20440 \size normal
20441 \emph off
20442 \bar no
20443 \noun off
20444 \color none
20445 _fs2uint.c
20446 \end_layout
20447
20448 \end_inset
20449 </cell>
20450 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20451 \begin_inset Text
20452
20453 \begin_layout Standard
20454
20455 \family roman
20456 \series medium
20457 \shape up
20458 \size normal
20459 \emph off
20460 \bar no
20461 \noun off
20462 \color none
20463 convert floating point to unsigned int
20464 \end_layout
20465
20466 \end_inset
20467 </cell>
20468 </row>
20469 <row topline="true">
20470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20471 \begin_inset Text
20472
20473 \begin_layout Standard
20474
20475 \family roman
20476 \series medium
20477 \shape up
20478 \size normal
20479 \emph off
20480 \bar no
20481 \noun off
20482 \color none
20483 _fs2int.c
20484 \end_layout
20485
20486 \end_inset
20487 </cell>
20488 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20489 \begin_inset Text
20490
20491 \begin_layout Standard
20492
20493 \family roman
20494 \series medium
20495 \shape up
20496 \size normal
20497 \emph off
20498 \bar no
20499 \noun off
20500 \color none
20501 convert floating point to signed int
20502 \end_layout
20503
20504 \end_inset
20505 </cell>
20506 </row>
20507 <row topline="true">
20508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20509 \begin_inset Text
20510
20511 \begin_layout Standard
20512
20513 \family roman
20514 \series medium
20515 \shape up
20516 \size normal
20517 \emph off
20518 \bar no
20519 \noun off
20520 \color none
20521 _fs2ulong.
20522 \family default
20523 \series default
20524 \shape default
20525 \size default
20526 \emph default
20527 \bar default
20528 \noun default
20529 c
20530 \end_layout
20531
20532 \end_inset
20533 </cell>
20534 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20535 \begin_inset Text
20536
20537 \begin_layout Standard
20538
20539 \family roman
20540 \series medium
20541 \shape up
20542 \size normal
20543 \emph off
20544 \bar no
20545 \noun off
20546 \color none
20547 convert floating point to unsigned long
20548 \end_layout
20549
20550 \end_inset
20551 </cell>
20552 </row>
20553 <row topline="true">
20554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20555 \begin_inset Text
20556
20557 \begin_layout Standard
20558
20559 \family roman
20560 \series medium
20561 \shape up
20562 \size normal
20563 \emph off
20564 \bar no
20565 \noun off
20566 \color none
20567 _fs2long.c
20568 \end_layout
20569
20570 \end_inset
20571 </cell>
20572 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20573 \begin_inset Text
20574
20575 \begin_layout Standard
20576
20577 \family roman
20578 \series medium
20579 \shape up
20580 \size normal
20581 \emph off
20582 \bar no
20583 \noun off
20584 \color none
20585 convert floating point to signed long
20586 \end_layout
20587
20588 \end_inset
20589 </cell>
20590 </row>
20591 <row topline="true">
20592 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20593 \begin_inset Text
20594
20595 \begin_layout Standard
20596
20597 \family roman
20598 \series medium
20599 \shape up
20600 \size normal
20601 \emph off
20602 \bar no
20603 \noun off
20604 \color none
20605 _uchar2fs.c
20606 \end_layout
20607
20608 \end_inset
20609 </cell>
20610 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20611 \begin_inset Text
20612
20613 \begin_layout Standard
20614
20615 \family roman
20616 \series medium
20617 \shape up
20618 \size normal
20619 \emph off
20620 \bar no
20621 \noun off
20622 \color none
20623 convert unsigned char to floating point
20624 \end_layout
20625
20626 \end_inset
20627 </cell>
20628 </row>
20629 <row topline="true">
20630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20631 \begin_inset Text
20632
20633 \begin_layout Standard
20634
20635 \family roman
20636 \series medium
20637 \shape up
20638 \size normal
20639 \emph off
20640 \bar no
20641 \noun off
20642 \color none
20643 _char2fs.c
20644 \end_layout
20645
20646 \end_inset
20647 </cell>
20648 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20649 \begin_inset Text
20650
20651 \begin_layout Standard
20652
20653 \family roman
20654 \series medium
20655 \shape up
20656 \size normal
20657 \emph off
20658 \bar no
20659 \noun off
20660 \color none
20661 convert char to floating point number
20662 \end_layout
20663
20664 \end_inset
20665 </cell>
20666 </row>
20667 <row topline="true">
20668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20669 \begin_inset Text
20670
20671 \begin_layout Standard
20672
20673 \family roman
20674 \series medium
20675 \shape up
20676 \size normal
20677 \emph off
20678 \bar no
20679 \noun off
20680 \color none
20681 _uint2fs.c
20682 \end_layout
20683
20684 \end_inset
20685 </cell>
20686 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20687 \begin_inset Text
20688
20689 \begin_layout Standard
20690
20691 \family roman
20692 \series medium
20693 \shape up
20694 \size normal
20695 \emph off
20696 \bar no
20697 \noun off
20698 \color none
20699 convert unsigned int to floating point
20700 \end_layout
20701
20702 \end_inset
20703 </cell>
20704 </row>
20705 <row topline="true">
20706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20707 \begin_inset Text
20708
20709 \begin_layout Standard
20710
20711 \family roman
20712 \series medium
20713 \shape up
20714 \size normal
20715 \emph off
20716 \bar no
20717 \noun off
20718 \color none
20719 _int2fs.c
20720 \end_layout
20721
20722 \end_inset
20723 </cell>
20724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20725 \begin_inset Text
20726
20727 \begin_layout Standard
20728
20729 \family roman
20730 \series medium
20731 \shape up
20732 \size normal
20733 \emph off
20734 \bar no
20735 \noun off
20736 \color none
20737 convert int to floating point numbers
20738 \end_layout
20739
20740 \end_inset
20741 </cell>
20742 </row>
20743 <row topline="true">
20744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20745 \begin_inset Text
20746
20747 \begin_layout Standard
20748
20749 \family roman
20750 \series medium
20751 \shape up
20752 \size normal
20753 \emph off
20754 \bar no
20755 \noun off
20756 \color none
20757 _ulong2fs.c
20758 \end_layout
20759
20760 \end_inset
20761 </cell>
20762 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20763 \begin_inset Text
20764
20765 \begin_layout Standard
20766
20767 \family roman
20768 \series medium
20769 \shape up
20770 \size normal
20771 \emph off
20772 \bar no
20773 \noun off
20774 \color none
20775 convert unsigned long to floating point number
20776 \end_layout
20777
20778 \end_inset
20779 </cell>
20780 </row>
20781 <row topline="true" bottomline="true">
20782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20783 \begin_inset Text
20784
20785 \begin_layout Standard
20786
20787 \family roman
20788 \series medium
20789 \shape up
20790 \size normal
20791 \emph off
20792 \bar no
20793 \noun off
20794 \color none
20795 _long2fs.c
20796 \end_layout
20797
20798 \end_inset
20799 </cell>
20800 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20801 \begin_inset Text
20802
20803 \begin_layout Standard
20804
20805 \family roman
20806 \series medium
20807 \shape up
20808 \size normal
20809 \emph off
20810 \bar no
20811 \noun off
20812 \color none
20813 convert long to floating point number
20814 \end_layout
20815
20816 \end_inset
20817 </cell>
20818 </row>
20819 </lyxtabular>
20820
20821 \end_inset
20822
20823
20824 \newline
20825
20826 \end_layout
20827
20828 \begin_layout Standard
20829 These support routines are developed in ANSI-C so there is room for space
20830  and speed improvement
20831 \begin_inset Foot
20832 status open
20833
20834 \begin_layout Standard
20835 These floating point routines (
20836 \emph on
20837 not
20838 \emph default
20839  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
20840  
20841 \end_layout
20842
20843 \end_inset
20844
20845 .
20846  Note if all these routines are used simultaneously the data space might
20847  overflow.
20848  For serious floating point usage the large model might be needed.
20849  Also notice that you don't have to call this routines directly.
20850  The compiler will use them automatically every time a floating point operation
20851  is required.
20852 \begin_inset VSpace bigskip
20853 \end_inset
20854
20855
20856 \end_layout
20857
20858 \begin_layout Section
20859 Library Routines
20860 \begin_inset LatexCommand index
20861 name "Libraries"
20862
20863 \end_inset
20864
20865
20866 \end_layout
20867
20868 \begin_layout Standard
20869
20870 \emph on
20871 <pending: this is messy and incomplete - a little more information is in
20872  sdcc/doc/libdoc.txt
20873 \emph default
20874  >
20875 \end_layout
20876
20877 \begin_layout Subsection
20878 Compiler support routines (_gptrget, _mulint etc.)
20879 \end_layout
20880
20881 \begin_layout Subsection
20882 Stdclib functions (puts, printf, strcat etc.)
20883 \end_layout
20884
20885 \begin_layout Subsubsection
20886 <stdio.h>
20887 \end_layout
20888
20889 \begin_layout Paragraph
20890 getchar(), putchar()
20891 \end_layout
20892
20893 \begin_layout Standard
20894 \begin_inset LatexCommand index
20895 name "<stdio.h>"
20896
20897 \end_inset
20898
20899 As usual on embedded systems you have to provide your own 
20900 \family typewriter
20901 getchar()
20902 \begin_inset LatexCommand index
20903 name "getchar()"
20904
20905 \end_inset
20906
20907
20908 \family default
20909  and 
20910 \family typewriter
20911 putchar()
20912 \begin_inset LatexCommand index
20913 name "putchar()"
20914
20915 \end_inset
20916
20917
20918 \family default
20919  routines.
20920  SDCC does not know whether the system connects to a serial line with or
20921  without handshake, LCD, keyboard or other device.
20922  And whether a 
20923 \family typewriter
20924 lf
20925 \family default
20926  to 
20927 \family typewriter
20928 crlf
20929 \family default
20930  conversion within 
20931 \family typewriter
20932 putchar()
20933 \family default
20934  is intended.
20935  You'll find examples for serial routines f.e.
20936  in sdcc/device/lib.
20937  For the mcs51 this minimalistic polling 
20938 \family typewriter
20939 putchar()
20940 \family default
20941  routine might be a start:
20942 \end_layout
20943
20944 \begin_layout Verse
20945
20946 \family typewriter
20947 void putchar (char c) { 
20948 \newline
20949 \InsetSpace ~
20950 \InsetSpace ~
20951 \InsetSpace ~
20952 \InsetSpace ~
20953 while (!TI)\InsetSpace ~
20954 \InsetSpace ~
20955 \InsetSpace ~
20956  /* assumes UART is initialized */
20957 \newline
20958 \InsetSpace ~
20959 \InsetSpace ~
20960 \InsetSpace ~
20961 \InsetSpace ~
20962 \InsetSpace ~
20963 \InsetSpace ~
20964 \InsetSpace ~
20965 \InsetSpace ~
20966 ;
20967 \newline
20968 \InsetSpace ~
20969 \InsetSpace ~
20970 \InsetSpace ~
20971 \InsetSpace ~
20972 TI
20973  = 0;
20974 \newline
20975 \InsetSpace ~
20976 \InsetSpace ~
20977 \InsetSpace ~
20978 \InsetSpace ~
20979 SBUF = c;
20980 \newline
20981 }
20982 \end_layout
20983
20984 \begin_layout Paragraph
20985 printf()
20986 \end_layout
20987
20988 \begin_layout Standard
20989 The default 
20990 \family typewriter
20991 printf()
20992 \begin_inset LatexCommand index
20993 name "printf()"
20994
20995 \end_inset
20996
20997
20998 \family default
20999  implementation in 
21000 \family typewriter
21001 printf_large.c
21002 \family default
21003  does not support float (except on ds390).
21004  To enable this, recompile it with the option 
21005 \emph on
21006 -
21007 \begin_inset ERT
21008 status collapsed
21009
21010 \begin_layout Standard
21011
21012
21013 \backslash
21014 /
21015 \end_layout
21016
21017 \end_inset
21018
21019 DUSE_FLOATS=1
21020 \begin_inset LatexCommand index
21021 name "USE\\_FLOATS"
21022
21023 \end_inset
21024
21025
21026 \emph default
21027  on the command line.
21028  Use 
21029 \emph on
21030 -
21031 \begin_inset ERT
21032 status collapsed
21033
21034 \begin_layout Standard
21035
21036
21037 \backslash
21038 /
21039 \end_layout
21040
21041 \end_inset
21042
21043 -model-large
21044 \begin_inset LatexCommand index
21045 name "-\\/-model-large"
21046
21047 \end_inset
21048
21049
21050 \emph default
21051  for the mcs51 port, since this uses a lot of memory.
21052  To enable float support for the pic16 targets, see 
21053 \begin_inset LatexCommand ref
21054 reference "sub:pic16Libraries"
21055
21056 \end_inset
21057
21058 .
21059 \end_layout
21060
21061 \begin_layout Standard
21062 If you're short on code memory you might want to use 
21063 \family typewriter
21064 printf_small()
21065 \begin_inset LatexCommand index
21066 name "printf\\_small()"
21067
21068 \end_inset
21069
21070
21071 \family default
21072  
21073 \emph on
21074 instead
21075 \emph default
21076  of 
21077 \family typewriter
21078 printf().
21079
21080 \family default
21081  For the mcs51 there additionally are assembly versions 
21082 \family typewriter
21083 printf_tiny()
21084 \begin_inset LatexCommand index
21085 name "printf\\_tiny() (mcs51)"
21086
21087 \end_inset
21088
21089
21090 \family default
21091  (subset of printf using less than 270 bytes) and 
21092 \family typewriter
21093 printf_fast()
21094 \begin_inset LatexCommand index
21095 name "printf\\_fast() (mcs51)"
21096
21097 \end_inset
21098
21099
21100 \family default
21101  and 
21102 \family typewriter
21103 printf_fast_f()
21104 \begin_inset LatexCommand index
21105 name "printf\\_fast\\_f() (mcs51)"
21106
21107 \end_inset
21108
21109
21110 \family default
21111  (floating-point aware version of printf_fast) which should fit the requirements
21112  of many embedded systems (printf_fast() can be customized by unsetting
21113  #defines to 
21114 \emph on
21115 not
21116 \emph default
21117  support long variables and field widths).
21118  Be sure to use only one of these printf options within a project.
21119 \newline
21120
21121 \end_layout
21122
21123 \begin_layout Standard
21124 Feature matrix of different 
21125 \emph on
21126 printf
21127 \emph default
21128  options on mcs51.
21129 \end_layout
21130
21131 \begin_layout Standard
21132 \begin_inset Tabular
21133 <lyxtabular version="3" rows="14" columns="7">
21134 <features islongtable="true">
21135 <column alignment="left" valignment="middle" leftline="true" width="14col%">
21136 <column alignment="center" valignment="top" leftline="true" width="0">
21137 <column alignment="center" valignment="top" leftline="true" width="12col%">
21138 <column alignment="center" valignment="top" leftline="true" width="10col%">
21139 <column alignment="center" valignment="top" leftline="true" width="0">
21140 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
21141 <column alignment="center" valignment="top" rightline="true" width="0">
21142 <row topline="true" bottomline="true" endhead="true">
21143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21144 \begin_inset Text
21145
21146 \begin_layout Standard
21147
21148 \series bold
21149 \size large
21150 mcs51
21151 \end_layout
21152
21153 \end_inset
21154 </cell>
21155 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21156 \begin_inset Text
21157
21158 \begin_layout Standard
21159 printf
21160 \begin_inset LatexCommand index
21161 name "printf"
21162
21163 \end_inset
21164
21165
21166 \end_layout
21167
21168 \end_inset
21169 </cell>
21170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21171 \begin_inset Text
21172
21173 \begin_layout Standard
21174 printf 
21175 \size scriptsize
21176 USE_FLOATS=1
21177 \end_layout
21178
21179 \end_inset
21180 </cell>
21181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21182 \begin_inset Text
21183
21184 \begin_layout Standard
21185 printf_small
21186 \end_layout
21187
21188 \end_inset
21189 </cell>
21190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21191 \begin_inset Text
21192
21193 \begin_layout Standard
21194 printf_fast
21195 \end_layout
21196
21197 \end_inset
21198 </cell>
21199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21200 \begin_inset Text
21201
21202 \begin_layout Standard
21203 printf_fast_f
21204 \end_layout
21205
21206 \end_inset
21207 </cell>
21208 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21209 \begin_inset Text
21210
21211 \begin_layout Standard
21212 printf_tiny
21213 \end_layout
21214
21215 \end_inset
21216 </cell>
21217 </row>
21218 <row topline="true" endhead="true">
21219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21220 \begin_inset Text
21221
21222 \begin_layout Standard
21223 filename
21224 \end_layout
21225
21226 \end_inset
21227 </cell>
21228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21229 \begin_inset Text
21230
21231 \begin_layout Standard
21232
21233 \size scriptsize
21234 printf_large.c
21235 \end_layout
21236
21237 \end_inset
21238 </cell>
21239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21240 \begin_inset Text
21241
21242 \begin_layout Standard
21243
21244 \size scriptsize
21245 printf_large.c
21246 \end_layout
21247
21248 \end_inset
21249 </cell>
21250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21251 \begin_inset Text
21252
21253 \begin_layout Standard
21254
21255 \size scriptsize
21256 printfl.c
21257 \end_layout
21258
21259 \end_inset
21260 </cell>
21261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21262 \begin_inset Text
21263
21264 \begin_layout Standard
21265
21266 \size scriptsize
21267 printf_fast.c
21268 \end_layout
21269
21270 \end_inset
21271 </cell>
21272 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21273 \begin_inset Text
21274
21275 \begin_layout Standard
21276
21277 \size scriptsize
21278 printf_fast_f.c
21279 \end_layout
21280
21281 \end_inset
21282 </cell>
21283 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21284 \begin_inset Text
21285
21286 \begin_layout Standard
21287
21288 \size scriptsize
21289 printf_tiny.c
21290 \end_layout
21291
21292 \end_inset
21293 </cell>
21294 </row>
21295 <row topline="true" endhead="true">
21296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21297 \begin_inset Text
21298
21299 \begin_layout Standard
21300 \begin_inset Quotes sld
21301 \end_inset
21302
21303 Hello World
21304 \begin_inset Quotes srd
21305 \end_inset
21306
21307  size
21308 \end_layout
21309
21310 \begin_layout Standard
21311 small / large
21312 \end_layout
21313
21314 \end_inset
21315 </cell>
21316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21317 \begin_inset Text
21318
21319 \begin_layout Standard
21320 1.7k / 2.4k
21321 \end_layout
21322
21323 \end_inset
21324 </cell>
21325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21326 \begin_inset Text
21327
21328 \begin_layout Standard
21329 4.3k / 5.6k
21330 \end_layout
21331
21332 \end_inset
21333 </cell>
21334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21335 \begin_inset Text
21336
21337 \begin_layout Standard
21338 1.2k / 1.8k
21339 \end_layout
21340
21341 \end_inset
21342 </cell>
21343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21344 \begin_inset Text
21345
21346 \begin_layout Standard
21347 1.3k / 1.3k
21348 \end_layout
21349
21350 \end_inset
21351 </cell>
21352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21353 \begin_inset Text
21354
21355 \begin_layout Standard
21356 1.9k / 1.9k
21357 \end_layout
21358
21359 \end_inset
21360 </cell>
21361 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21362 \begin_inset Text
21363
21364 \begin_layout Standard
21365 0.44k / 0.44k
21366 \end_layout
21367
21368 \end_inset
21369 </cell>
21370 </row>
21371 <row topline="true" endhead="true">
21372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21373 \begin_inset Text
21374
21375 \begin_layout Standard
21376 code size
21377 \end_layout
21378
21379 \begin_layout Standard
21380 small / large
21381 \end_layout
21382
21383 \end_inset
21384 </cell>
21385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21386 \begin_inset Text
21387
21388 \begin_layout Standard
21389 1.4k / 2.0k
21390 \end_layout
21391
21392 \end_inset
21393 </cell>
21394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21395 \begin_inset Text
21396
21397 \begin_layout Standard
21398 2.8k / 3.7k
21399 \end_layout
21400
21401 \end_inset
21402 </cell>
21403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21404 \begin_inset Text
21405
21406 \begin_layout Standard
21407 0.45k / 0.47k (+ _ltoa)
21408 \end_layout
21409
21410 \end_inset
21411 </cell>
21412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21413 \begin_inset Text
21414
21415 \begin_layout Standard
21416 1.2k / 1.2k
21417 \end_layout
21418
21419 \end_inset
21420 </cell>
21421 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21422 \begin_inset Text
21423
21424 \begin_layout Standard
21425 1.6k / 1.6k
21426 \end_layout
21427
21428 \end_inset
21429 </cell>
21430 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21431 \begin_inset Text
21432
21433 \begin_layout Standard
21434 0.26k / 0.26k
21435 \end_layout
21436
21437 \end_inset
21438 </cell>
21439 </row>
21440 <row topline="true">
21441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21442 \begin_inset Text
21443
21444 \begin_layout Standard
21445 formats
21446 \end_layout
21447
21448 \end_inset
21449 </cell>
21450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21451 \begin_inset Text
21452
21453 \begin_layout Standard
21454 cdi
21455 \emph on
21456 o
21457 \emph default
21458 psux
21459 \end_layout
21460
21461 \end_inset
21462 </cell>
21463 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21464 \begin_inset Text
21465
21466 \begin_layout Standard
21467
21468 \family roman
21469 \series medium
21470 \shape up
21471 \size normal
21472 \emph off
21473 \bar no
21474 \noun off
21475 \color none
21476 cd
21477 \family default
21478 \series default
21479 \shape default
21480 \size default
21481 \emph default
21482 \bar default
21483 \noun default
21484 f
21485 \family roman
21486 \series medium
21487 \shape up
21488 \size normal
21489 \emph off
21490 \bar no
21491 \noun off
21492 i
21493 \family default
21494 \series default
21495 \shape default
21496 \size default
21497 \emph on
21498 \bar default
21499 \noun default
21500 o
21501 \family roman
21502 \series medium
21503 \shape up
21504 \size normal
21505 \emph off
21506 \bar no
21507 \noun off
21508 psux
21509 \end_layout
21510
21511 \end_inset
21512 </cell>
21513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21514 \begin_inset Text
21515
21516 \begin_layout Standard
21517 c
21518 \family roman
21519 \series medium
21520 \shape up
21521 \size normal
21522 \emph off
21523 \bar no
21524 \noun off
21525 \color none
21526 d
21527 \family default
21528 \series default
21529 \shape default
21530 \size default
21531 \emph on
21532 \bar default
21533 \noun default
21534 o
21535 \family roman
21536 \series medium
21537 \shape up
21538 \size normal
21539 \emph off
21540 \bar no
21541 \noun off
21542 s
21543 \family default
21544 \series default
21545 \shape default
21546 \size default
21547 \emph default
21548 \bar default
21549 \noun default
21550 x
21551 \end_layout
21552
21553 \end_inset
21554 </cell>
21555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21556 \begin_inset Text
21557
21558 \begin_layout Standard
21559 cdsux
21560 \end_layout
21561
21562 \end_inset
21563 </cell>
21564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21565 \begin_inset Text
21566
21567 \begin_layout Standard
21568 cdfsux
21569 \end_layout
21570
21571 \end_inset
21572 </cell>
21573 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21574 \begin_inset Text
21575
21576 \begin_layout Standard
21577 cdsux
21578 \end_layout
21579
21580 \end_inset
21581 </cell>
21582 </row>
21583 <row topline="true">
21584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21585 \begin_inset Text
21586
21587 \begin_layout Standard
21588 long (32 bit) support
21589 \end_layout
21590
21591 \end_inset
21592 </cell>
21593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21594 \begin_inset Text
21595
21596 \begin_layout Standard
21597 x
21598 \end_layout
21599
21600 \end_inset
21601 </cell>
21602 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21603 \begin_inset Text
21604
21605 \begin_layout Standard
21606 x
21607 \end_layout
21608
21609 \end_inset
21610 </cell>
21611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21612 \begin_inset Text
21613
21614 \begin_layout Standard
21615 x
21616 \end_layout
21617
21618 \end_inset
21619 </cell>
21620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21621 \begin_inset Text
21622
21623 \begin_layout Standard
21624 x
21625 \end_layout
21626
21627 \end_inset
21628 </cell>
21629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21630 \begin_inset Text
21631
21632 \begin_layout Standard
21633
21634 \family roman
21635 \series medium
21636 \shape up
21637 \size normal
21638 \emph off
21639 \bar no
21640 \noun off
21641 \color none
21642 x
21643 \end_layout
21644
21645 \end_inset
21646 </cell>
21647 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21648 \begin_inset Text
21649
21650 \begin_layout Standard
21651 -
21652 \end_layout
21653
21654 \end_inset
21655 </cell>
21656 </row>
21657 <row topline="true">
21658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21659 \begin_inset Text
21660
21661 \begin_layout Standard
21662 byte arguments on stack
21663 \end_layout
21664
21665 \end_inset
21666 </cell>
21667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21668 \begin_inset Text
21669
21670 \begin_layout Standard
21671 b
21672 \end_layout
21673
21674 \end_inset
21675 </cell>
21676 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21677 \begin_inset Text
21678
21679 \begin_layout Standard
21680 b
21681 \end_layout
21682
21683 \end_inset
21684 </cell>
21685 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21686 \begin_inset Text
21687
21688 \begin_layout Standard
21689 -
21690 \end_layout
21691
21692 \end_inset
21693 </cell>
21694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21695 \begin_inset Text
21696
21697 \begin_layout Standard
21698 -
21699 \end_layout
21700
21701 \end_inset
21702 </cell>
21703 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21704 \begin_inset Text
21705
21706 \begin_layout Standard
21707 -
21708 \end_layout
21709
21710 \end_inset
21711 </cell>
21712 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21713 \begin_inset Text
21714
21715 \begin_layout Standard
21716 -
21717 \end_layout
21718
21719 \end_inset
21720 </cell>
21721 </row>
21722 <row topline="true">
21723 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21724 \begin_inset Text
21725
21726 \begin_layout Standard
21727 float format
21728 \begin_inset LatexCommand index
21729 name "Floating point support"
21730
21731 \end_inset
21732
21733
21734 \end_layout
21735
21736 \end_inset
21737 </cell>
21738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21739 \begin_inset Text
21740
21741 \begin_layout Standard
21742 -
21743 \end_layout
21744
21745 \end_inset
21746 </cell>
21747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21748 \begin_inset Text
21749
21750 \begin_layout Standard
21751 %f
21752 \end_layout
21753
21754 \end_inset
21755 </cell>
21756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21757 \begin_inset Text
21758
21759 \begin_layout Standard
21760 -
21761 \end_layout
21762
21763 \end_inset
21764 </cell>
21765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21766 \begin_inset Text
21767
21768 \begin_layout Standard
21769 -
21770 \end_layout
21771
21772 \end_inset
21773 </cell>
21774 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21775 \begin_inset Text
21776
21777 \begin_layout Standard
21778 %f
21779 \begin_inset Foot
21780 status collapsed
21781
21782 \begin_layout Standard
21783 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
21784 \end_layout
21785
21786 \end_inset
21787
21788
21789 \end_layout
21790
21791 \end_inset
21792 </cell>
21793 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21794 \begin_inset Text
21795
21796 \begin_layout Standard
21797 -
21798 \end_layout
21799
21800 \end_inset
21801 </cell>
21802 </row>
21803 <row topline="true">
21804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21805 \begin_inset Text
21806
21807 \begin_layout Standard
21808 float formats %e %g
21809 \end_layout
21810
21811 \end_inset
21812 </cell>
21813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21814 \begin_inset Text
21815
21816 \begin_layout Standard
21817 -
21818 \end_layout
21819
21820 \end_inset
21821 </cell>
21822 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21823 \begin_inset Text
21824
21825 \begin_layout Standard
21826 -
21827 \end_layout
21828
21829 \end_inset
21830 </cell>
21831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21832 \begin_inset Text
21833
21834 \begin_layout Standard
21835 -
21836 \end_layout
21837
21838 \end_inset
21839 </cell>
21840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21841 \begin_inset Text
21842
21843 \begin_layout Standard
21844 -
21845 \end_layout
21846
21847 \end_inset
21848 </cell>
21849 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21850 \begin_inset Text
21851
21852 \begin_layout Standard
21853 -
21854 \end_layout
21855
21856 \end_inset
21857 </cell>
21858 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21859 \begin_inset Text
21860
21861 \begin_layout Standard
21862 -
21863 \end_layout
21864
21865 \end_inset
21866 </cell>
21867 </row>
21868 <row topline="true" bottomline="true">
21869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21870 \begin_inset Text
21871
21872 \begin_layout Standard
21873 field width
21874 \end_layout
21875
21876 \end_inset
21877 </cell>
21878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21879 \begin_inset Text
21880
21881 \begin_layout Standard
21882 x
21883 \end_layout
21884
21885 \end_inset
21886 </cell>
21887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21888 \begin_inset Text
21889
21890 \begin_layout Standard
21891 x
21892 \end_layout
21893
21894 \end_inset
21895 </cell>
21896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21897 \begin_inset Text
21898
21899 \begin_layout Standard
21900 -
21901 \end_layout
21902
21903 \end_inset
21904 </cell>
21905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21906 \begin_inset Text
21907
21908 \begin_layout Standard
21909 x
21910 \end_layout
21911
21912 \end_inset
21913 </cell>
21914 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21915 \begin_inset Text
21916
21917 \begin_layout Standard
21918 x
21919 \end_layout
21920
21921 \end_inset
21922 </cell>
21923 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21924 \begin_inset Text
21925
21926 \begin_layout Standard
21927 -
21928 \end_layout
21929
21930 \end_inset
21931 </cell>
21932 </row>
21933 <row bottomline="true">
21934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21935 \begin_inset Text
21936
21937 \begin_layout Standard
21938 string speed
21939 \begin_inset Foot
21940 status collapsed
21941
21942 \begin_layout Standard
21943 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
21944 \backslash
21945 r', '
21946 \backslash
21947 n'); standard 8051 @ 22.1184 MHz, empty putchar()
21948 \end_layout
21949
21950 \end_inset
21951
21952 ,
21953 \end_layout
21954
21955 \begin_layout Standard
21956 small / large
21957 \end_layout
21958
21959 \end_inset
21960 </cell>
21961 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21962 \begin_inset Text
21963
21964 \begin_layout Standard
21965 1.52 / 2.59 ms
21966 \end_layout
21967
21968 \end_inset
21969 </cell>
21970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21971 \begin_inset Text
21972
21973 \begin_layout Standard
21974 1.53 / 2.62 ms
21975 \end_layout
21976
21977 \end_inset
21978 </cell>
21979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21980 \begin_inset Text
21981
21982 \begin_layout Standard
21983 0.92 / 0.93 ms
21984 \end_layout
21985
21986 \end_inset
21987 </cell>
21988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21989 \begin_inset Text
21990
21991 \begin_layout Standard
21992 0.45 / 0.45 ms
21993 \end_layout
21994
21995 \end_inset
21996 </cell>
21997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21998 \begin_inset Text
21999
22000 \begin_layout Standard
22001 0.46 / 0.46 ms
22002 \end_layout
22003
22004 \end_inset
22005 </cell>
22006 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22007 \begin_inset Text
22008
22009 \begin_layout Standard
22010 0.45 / 0.45 ms
22011 \end_layout
22012
22013 \end_inset
22014 </cell>
22015 </row>
22016 <row bottomline="true">
22017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22018 \begin_inset Text
22019
22020 \begin_layout Standard
22021 int speed
22022 \begin_inset Foot
22023 status collapsed
22024
22025 \begin_layout Standard
22026 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
22027  putchar()
22028 \end_layout
22029
22030 \end_inset
22031
22032 ,
22033 \end_layout
22034
22035 \begin_layout Standard
22036 small / large
22037 \end_layout
22038
22039 \end_inset
22040 </cell>
22041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22042 \begin_inset Text
22043
22044 \begin_layout Standard
22045 3.01 / 3.61 ms
22046 \end_layout
22047
22048 \end_inset
22049 </cell>
22050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22051 \begin_inset Text
22052
22053 \begin_layout Standard
22054 3.01 / 3.61 ms
22055 \end_layout
22056
22057 \end_inset
22058 </cell>
22059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22060 \begin_inset Text
22061
22062 \begin_layout Standard
22063 3.51 / 18.13 ms
22064 \end_layout
22065
22066 \end_inset
22067 </cell>
22068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22069 \begin_inset Text
22070
22071 \begin_layout Standard
22072 0.22 / 0.22 ms
22073 \end_layout
22074
22075 \end_inset
22076 </cell>
22077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22078 \begin_inset Text
22079
22080 \begin_layout Standard
22081 0.23 / 0.23 ms
22082 \end_layout
22083
22084 \end_inset
22085 </cell>
22086 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22087 \begin_inset Text
22088
22089 \begin_layout Standard
22090 0.25 / 0.25 ms
22091 \begin_inset Foot
22092 status collapsed
22093
22094 \begin_layout Standard
22095 printf_tiny integer speed is data dependent, worst case is 0.33 ms
22096 \end_layout
22097
22098 \end_inset
22099
22100
22101 \end_layout
22102
22103 \end_inset
22104 </cell>
22105 </row>
22106 <row bottomline="true">
22107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22108 \begin_inset Text
22109
22110 \begin_layout Standard
22111 long speed
22112 \begin_inset Foot
22113 status collapsed
22114
22115 \begin_layout Standard
22116 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
22117  empty putchar()
22118 \end_layout
22119
22120 \end_inset
22121
22122 ,
22123 \end_layout
22124
22125 \begin_layout Standard
22126 small / large
22127 \end_layout
22128
22129 \end_inset
22130 </cell>
22131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22132 \begin_inset Text
22133
22134 \begin_layout Standard
22135 5.37 / 6.31 ms
22136 \end_layout
22137
22138 \end_inset
22139 </cell>
22140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22141 \begin_inset Text
22142
22143 \begin_layout Standard
22144 5.37 / 6.31 ms
22145 \end_layout
22146
22147 \end_inset
22148 </cell>
22149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22150 \begin_inset Text
22151
22152 \begin_layout Standard
22153 8.71 / 40.65 ms
22154 \end_layout
22155
22156 \end_inset
22157 </cell>
22158 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22159 \begin_inset Text
22160
22161 \begin_layout Standard
22162 0.40 / 0.40 ms
22163 \end_layout
22164
22165 \end_inset
22166 </cell>
22167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22168 \begin_inset Text
22169
22170 \begin_layout Standard
22171 0.40 / 0.40 ms
22172 \end_layout
22173
22174 \end_inset
22175 </cell>
22176 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22177 \begin_inset Text
22178
22179 \begin_layout Standard
22180 -
22181 \end_layout
22182
22183 \end_inset
22184 </cell>
22185 </row>
22186 <row bottomline="true">
22187 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22188 \begin_inset Text
22189
22190 \begin_layout Standard
22191 float speed
22192 \begin_inset Foot
22193 status collapsed
22194
22195 \begin_layout Standard
22196 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
22197  empty putchar()
22198 \end_layout
22199
22200 \end_inset
22201
22202 ,
22203 \end_layout
22204
22205 \begin_layout Standard
22206 small / large
22207 \end_layout
22208
22209 \end_inset
22210 </cell>
22211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22212 \begin_inset Text
22213
22214 \begin_layout Standard
22215 -
22216 \end_layout
22217
22218 \end_inset
22219 </cell>
22220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22221 \begin_inset Text
22222
22223 \begin_layout Standard
22224 7.49 / 22.47 ms
22225 \end_layout
22226
22227 \end_inset
22228 </cell>
22229 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22230 \begin_inset Text
22231
22232 \begin_layout Standard
22233 -
22234 \end_layout
22235
22236 \end_inset
22237 </cell>
22238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22239 \begin_inset Text
22240
22241 \begin_layout Standard
22242 -
22243 \end_layout
22244
22245 \end_inset
22246 </cell>
22247 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22248 \begin_inset Text
22249
22250 \begin_layout Standard
22251 1.04 / 1.04 ms
22252 \end_layout
22253
22254 \end_inset
22255 </cell>
22256 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22257 \begin_inset Text
22258
22259 \begin_layout Standard
22260 -
22261 \end_layout
22262
22263 \end_inset
22264 </cell>
22265 </row>
22266 </lyxtabular>
22267
22268 \end_inset
22269
22270
22271 \end_layout
22272
22273 \begin_layout Subsubsection
22274 <malloc.h>
22275 \begin_inset LatexCommand index
22276 name "malloc.h"
22277
22278 \end_inset
22279
22280
22281 \end_layout
22282
22283 \begin_layout Standard
22284 As of SDCC 2.6.2 you no longer need to call an initialization routine before
22285  using dynamic memory allocation
22286 \begin_inset LatexCommand index
22287 name "dynamic memory allocation (malloc)"
22288
22289 \end_inset
22290
22291  and a default heap
22292 \begin_inset LatexCommand index
22293 name "heap (malloc)"
22294
22295 \end_inset
22296
22297  space of 1024 bytes is provided for malloc to allocate memory from.
22298  If you need a different heap size you need to recompile _heap.c with the
22299  required size defined in HEAP_SIZE.
22300  It is recommended to make a copy of this file into your project directory
22301  and compile it there with:
22302 \end_layout
22303
22304 \begin_layout Verse
22305
22306 \family typewriter
22307 sdcc -c _heap.c -D HEAD_SIZE=2048
22308 \end_layout
22309
22310 \begin_layout Standard
22311 And then link it with:
22312 \end_layout
22313
22314 \begin_layout Verse
22315
22316 \family typewriter
22317 sdcc main.rel _heap.rel
22318 \end_layout
22319
22320 \begin_layout Subsection
22321 Math functions (sinf, powf, sqrtf etc.)
22322 \end_layout
22323
22324 \begin_layout Subsubsection
22325 <math.h>
22326 \end_layout
22327
22328 \begin_layout Standard
22329 See definitions in file <math.h>.
22330 \end_layout
22331
22332 \begin_layout Subsection
22333 Other libraries
22334 \end_layout
22335
22336 \begin_layout Standard
22337 Libraries
22338 \begin_inset LatexCommand index
22339 name "Libraries"
22340
22341 \end_inset
22342
22343  included in SDCC should have a license at least as liberal as the GNU Lesser
22344  General Public License
22345 \begin_inset LatexCommand index
22346 name "GNU Lesser General Public License, LGPL"
22347
22348 \end_inset
22349
22350  
22351 \emph on
22352 LGPL
22353 \emph default
22354 .
22355 \end_layout
22356
22357 \begin_layout Standard
22358 \begin_inset Note Note
22359 status collapsed
22360
22361 \begin_layout Standard
22362 license statements for the libraries are missing.
22363  sdcc/device/lib/ser_ir.c
22364 \end_layout
22365
22366 \begin_layout Standard
22367 or _decdptr f.e.
22368  come with a GPL (as opposed to LGPL) License - this will not be liberal
22369  enough for many embedded programmers.
22370 \end_layout
22371
22372 \end_inset
22373
22374
22375 \end_layout
22376
22377 \begin_layout Standard
22378 If you have ported some library or want to share experience about some code
22379  which f.e.
22380  falls into any of these categories Busses (I
22381 \begin_inset Formula $^{\textrm{2}}$
22382 \end_inset
22383
22384 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
22385  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
22386  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
22387 \begin_inset LatexCommand url
22388 target "http://sourceforge.net/mail/?group_id=599"
22389
22390 \end_inset
22391
22392 \InsetSpace ~
22393 would certainly like to hear about it.
22394 \end_layout
22395
22396 \begin_layout Standard
22397 Programmers coding for embedded systems are not especially famous for being
22398  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
22399 e these references are very valuable.
22400  Let's help to create a climate where information is shared.
22401 \begin_inset VSpace bigskip
22402 \end_inset
22403
22404
22405 \end_layout
22406
22407 \begin_layout Section
22408 Memory Models
22409 \end_layout
22410
22411 \begin_layout Subsection
22412 MCS51 Memory Models
22413 \begin_inset LatexCommand index
22414 name "Memory model"
22415
22416 \end_inset
22417
22418
22419 \begin_inset LatexCommand index
22420 name "MCS51 memory model"
22421
22422 \end_inset
22423
22424
22425 \end_layout
22426
22427 \begin_layout Subsubsection
22428 Small, Medium and Large
22429 \end_layout
22430
22431 \begin_layout Standard
22432 SDCC allows three memory models for MCS51 code, 
22433 \shape slanted
22434 small, medium
22435 \shape default
22436  and 
22437 \shape slanted
22438 large
22439 \shape default
22440 .
22441  Modules compiled with different memory models should 
22442 \emph on
22443 never
22444 \emph default
22445  be combined together or the results would be unpredictable.
22446  The library routines supplied with the compiler are compiled as small,
22447  medium and large.
22448  The compiled library modules are contained in separate directories as small,
22449  medium and large so that you can link to the appropriate set.
22450 \end_layout
22451
22452 \begin_layout Standard
22453 When the medium or large model is used all variables declared without a
22454  storage class will be allocated into the external ram, this includes all
22455  parameters and local variables (for non-reentrant
22456 \begin_inset LatexCommand index
22457 name "reentrant"
22458
22459 \end_inset
22460
22461  functions).
22462  When the small model is used variables without storage class are allocated
22463  in the internal ram.
22464 \end_layout
22465
22466 \begin_layout Standard
22467 Judicious usage of the processor specific storage classes
22468 \begin_inset LatexCommand index
22469 name "Storage class"
22470
22471 \end_inset
22472
22473  and the 'reentrant' function type will yield much more efficient code,
22474  than using the large model.
22475  Several optimizations are disabled when the program is compiled using the
22476  large model, it is therefore recommended that the small model be used unless
22477  absolutely required.
22478 \end_layout
22479
22480 \begin_layout Subsubsection
22481 External Stack
22482 \begin_inset LatexCommand label
22483 name "sub:External-Stack"
22484
22485 \end_inset
22486
22487
22488 \begin_inset LatexCommand index
22489 name "stack"
22490
22491 \end_inset
22492
22493
22494 \begin_inset LatexCommand index
22495 name "External stack (mcs51)"
22496
22497 \end_inset
22498
22499
22500 \end_layout
22501
22502 \begin_layout Standard
22503 The external stack (-
22504 \begin_inset ERT
22505 status collapsed
22506
22507 \begin_layout Standard
22508
22509
22510 \backslash
22511 /
22512 \end_layout
22513
22514 \end_inset
22515
22516 -xstack option
22517 \begin_inset LatexCommand index
22518 name "-\\/-xstack"
22519
22520 \end_inset
22521
22522 ) is located in pdata
22523 \begin_inset LatexCommand index
22524 name "pdata (mcs51, ds390 storage class)"
22525
22526 \end_inset
22527
22528  memory (usually at the start of the external ram segment) and uses all
22529  unused space in pdata (max.
22530  256 bytes).
22531  When -
22532 \begin_inset ERT
22533 status collapsed
22534
22535 \begin_layout Standard
22536
22537
22538 \backslash
22539 /
22540 \end_layout
22541
22542 \end_inset
22543
22544 -xstack option is used to compile the program, the parameters and local
22545  variables
22546 \begin_inset LatexCommand index
22547 name "local variables"
22548
22549 \end_inset
22550
22551  of all reentrant functions are allocated in this area.
22552  This option is provided for programs with large stack space requirements.
22553  When used with the -
22554 \begin_inset ERT
22555 status collapsed
22556
22557 \begin_layout Standard
22558
22559
22560 \backslash
22561 /
22562 \end_layout
22563
22564 \end_inset
22565
22566 -stack-auto
22567 \begin_inset LatexCommand index
22568 name "-\\/-stack-auto"
22569
22570 \end_inset
22571
22572  option, all parameters and local variables are allocated on the external
22573  stack (note: support libraries will need to be recompiled with the same
22574  options.
22575  There is a predefined target in the library makefile).
22576 \end_layout
22577
22578 \begin_layout Standard
22579 The compiler outputs the higher order address byte of the external ram segment
22580  into port P2
22581 \begin_inset LatexCommand index
22582 name "P2 (mcs51 sfr)"
22583
22584 \end_inset
22585
22586  (see also section 
22587 \begin_inset LatexCommand ref
22588 reference "sub:MCS51-variants"
22589
22590 \end_inset
22591
22592 ), therefore when using the External Stack option, this port 
22593 \emph on
22594 may not
22595 \emph default
22596  be used by the application program.
22597 \end_layout
22598
22599 \begin_layout Subsection
22600 DS390 Memory Model
22601 \begin_inset LatexCommand index
22602 name "Memory model"
22603
22604 \end_inset
22605
22606
22607 \begin_inset LatexCommand index
22608 name "DS390 memory model"
22609
22610 \end_inset
22611
22612
22613 \end_layout
22614
22615 \begin_layout Standard
22616 The only model supported is Flat 24
22617 \begin_inset LatexCommand index
22618 name "Flat 24 (DS390 memory model)"
22619
22620 \end_inset
22621
22622 .
22623  This generates code for the 24 bit contiguous addressing mode of the Dallas
22624  DS80C390 part.
22625  In this mode, up to four meg of external RAM or code space can be directly
22626  addressed.
22627  See the data sheets at www.dalsemi.com for further information on this part.
22628 \newline
22629
22630 \newline
22631 Note
22632  that the compiler does not generate any code to place the processor into
22633  24 bitmode (although 
22634 \emph on
22635 tinibios
22636 \emph default
22637  in the ds390 libraries will do that for you).
22638  If you don't use 
22639 \emph on
22640 tinibios
22641 \emph default
22642
22643 \begin_inset LatexCommand index
22644 name "Tinibios (DS390)"
22645
22646 \end_inset
22647
22648 , the boot loader or similar code must ensure that the processor is in 24
22649  bit contiguous addressing mode before calling the SDCC startup code.
22650 \newline
22651
22652 \newline
22653 Like
22654  the 
22655 \emph on
22656 -
22657 \begin_inset ERT
22658 status collapsed
22659
22660 \begin_layout Standard
22661
22662
22663 \backslash
22664 /
22665 \end_layout
22666
22667 \end_inset
22668
22669 -model-large
22670 \emph default
22671  option, variables will by default be placed into the XDATA segment.
22672  
22673 \newline
22674
22675 \newline
22676 Segments may be placed anywhere in the 4 meg address space using the usual
22677  -
22678 \begin_inset ERT
22679 status collapsed
22680
22681 \begin_layout Standard
22682
22683
22684 \backslash
22685 /
22686 \end_layout
22687
22688 \end_inset
22689
22690 -*-loc options.
22691  Note that if any segments are located above 64K, the -r flag must be passed
22692  to the linker to generate the proper segment relocations, and the Intel
22693  HEX output format must be used.
22694  The -r flag can be passed to the linker by using the option 
22695 \emph on
22696 -Wl-r
22697 \emph default
22698  on the SDCC command line.
22699  However, currently the linker can not handle code segments > 64k.
22700 \end_layout
22701
22702 \begin_layout Section
22703 Pragmas
22704 \begin_inset LatexCommand label
22705 name "sec:Pragmas"
22706
22707 \end_inset
22708
22709
22710 \begin_inset LatexCommand index
22711 name "Pragmas"
22712
22713 \end_inset
22714
22715
22716 \end_layout
22717
22718 \begin_layout Standard
22719 Pragmas are used to turn on and/or off certain compiler options.
22720  Some of them are closely related to corresponding command-line options
22721  (see section 
22722 \begin_inset LatexCommand vref
22723 reference "sec:Command-Line-Options"
22724
22725 \end_inset
22726
22727 ).
22728 \newline
22729 Pragmas should be placed before and/or after a function, placing pragmas
22730  inside a function body could have unpredictable results.
22731 \newline
22732
22733 \newline
22734 SDCC supports the
22735  following #pragma directives:
22736 \end_layout
22737
22738 \begin_layout Itemize
22739
22740 \series bold
22741 save
22742 \series default
22743
22744 \begin_inset LatexCommand index
22745 name "\\#pragma save"
22746
22747 \end_inset
22748
22749  - this will save most current options to the save/restore stack.
22750  See #pragma\InsetSpace ~
22751 restore.
22752 \end_layout
22753
22754 \begin_layout Itemize
22755
22756 \series bold
22757 restore
22758 \series default
22759
22760 \begin_inset LatexCommand index
22761 name "\\#pragma restore"
22762
22763 \end_inset
22764
22765  - will restore saved options from the last save.
22766  saves & restores can be nested.
22767  SDCC uses a save/restore stack: save pushes current options to the stack,
22768  restore pulls current options from the stack.
22769  See #pragma\InsetSpace ~
22770 save.
22771 \newline
22772
22773 \end_layout
22774
22775 \begin_layout Itemize
22776
22777 \series bold
22778 callee_saves
22779 \series default
22780
22781 \begin_inset LatexCommand index
22782 name "\\#pragma callee\\_saves"
22783
22784 \end_inset
22785
22786
22787 \begin_inset LatexCommand index
22788 name "function prologue"
22789
22790 \end_inset
22791
22792  function1[,function2[,function3...]] 
22793 \begin_inset LatexCommand label
22794 name "ite:callee_saves-function1[,function2[,function3...]]--"
22795
22796 \end_inset
22797
22798 - The compiler by default uses a caller saves convention for register saving
22799  across function calls, however this can cause unnecessary register pushing
22800  and popping
22801 \begin_inset LatexCommand index
22802 name "push/pop"
22803
22804 \end_inset
22805
22806  when calling small functions from larger functions.
22807  This option can be used to switch off the register saving convention for
22808  the function names specified.
22809  The compiler will not save registers when calling these functions, extra
22810  code need to be manually inserted at the entry and exit for these functions
22811  to save and restore the registers used by these functions, this can SUBSTANTIAL
22812 LY reduce code and improve run time performance of the generated code.
22813  In the future the compiler (with inter procedural analysis) may be able
22814  to determine the appropriate scheme to use for each function call.
22815  If -
22816 \begin_inset ERT
22817 status collapsed
22818
22819 \begin_layout Standard
22820
22821
22822 \backslash
22823 /
22824 \end_layout
22825
22826 \end_inset
22827
22828 -callee-saves command line option is used (see page 
22829 \begin_inset LatexCommand vpageref
22830 reference "lyx:--callee-saves-function1[,function2][,function3]..."
22831
22832 \end_inset
22833
22834 ), the function names specified in #pragma\InsetSpace ~
22835 callee_saves
22836 \begin_inset LatexCommand index
22837 name "\\#pragma callee\\_saves"
22838
22839 \end_inset
22840
22841  is appended to the list of functions specified in the command line.
22842 \end_layout
22843
22844 \begin_layout Itemize
22845
22846 \series bold
22847 exclude
22848 \series default
22849
22850 \begin_inset LatexCommand index
22851 name "\\#pragma exclude"
22852
22853 \end_inset
22854
22855  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
22856  of pairs of push/pop
22857 \begin_inset LatexCommand index
22858 name "push/pop"
22859
22860 \end_inset
22861
22862  instructions in 
22863 \emph on
22864 I
22865 \emph default
22866 nterrupt
22867 \begin_inset LatexCommand index
22868 name "interrupt"
22869
22870 \end_inset
22871
22872  
22873 \emph on
22874 S
22875 \emph default
22876 ervice 
22877 \emph on
22878 R
22879 \emph default
22880 outines.
22881  The directive should be placed immediately before the ISR function definition
22882  and it affects ALL ISR functions following it.
22883  To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
22884 exclude\InsetSpace ~
22885 none
22886 \begin_inset LatexCommand index
22887 name "\\#pragma exclude"
22888
22889 \end_inset
22890
22891 .
22892  See also the related keyword _naked
22893 \begin_inset LatexCommand index
22894 name "\\_naked"
22895
22896 \end_inset
22897
22898
22899 \begin_inset LatexCommand index
22900 name "\\_\\_naked"
22901
22902 \end_inset
22903
22904 .
22905 \end_layout
22906
22907 \begin_layout Itemize
22908
22909 \series bold
22910 less_pedantic
22911 \series default
22912
22913 \begin_inset LatexCommand index
22914 name "pedantic"
22915
22916 \end_inset
22917
22918
22919 \begin_inset LatexCommand index
22920 name "\\#pragma less\\_pedantic"
22921
22922 \end_inset
22923
22924  
22925 \begin_inset LatexCommand label
22926 name "ite:less_pedantic"
22927
22928 \end_inset
22929
22930 - the compiler will not warn you anymore for obvious mistakes, you're on
22931  your own now ;-( .
22932  See also the command line option -
22933 \begin_inset ERT
22934 status collapsed
22935
22936 \begin_layout Standard
22937
22938
22939 \backslash
22940 /
22941 \end_layout
22942
22943 \end_inset
22944
22945 -less-pedantic 
22946 \begin_inset LatexCommand vpageref
22947 reference "lyx:--less-pedantic"
22948
22949 \end_inset
22950
22951 .
22952  
22953 \newline
22954 More specifically, the following warnings will be disabled: 
22955 \shape italic
22956 comparison is always [true/false] due to limited range of data type
22957 \shape default
22958  (94); 
22959 \shape italic
22960 overflow in implicit constant conversion
22961 \shape default
22962  (158); [the (in)famous] 
22963 \shape italic
22964 conditional flow changed by optimizer: so said EVELYN the modified DOG
22965 \shape default
22966  (110); 
22967 \shape italic
22968 function '[function name]' must return value
22969 \shape default
22970  (59).
22971  
22972 \newline
22973 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
22974  level) are disabled, too, namely: 
22975 \shape italic
22976 constant value '[
22977 \begin_inset Note Note
22978 status collapsed
22979
22980 \begin_layout Standard
22981 dunno what comes here - this warning appears to be unused altogether
22982 \end_layout
22983
22984 \end_inset
22985
22986 ]', out of range
22987 \shape default
22988  (81); 
22989 \shape italic
22990 [left/right] shifting more than size of object changed to zero
22991 \shape default
22992  (116); 
22993 \shape italic
22994 unreachable code
22995 \shape default
22996  (126); 
22997 \shape italic
22998 integer overflow in expression
22999 \shape default
23000  (165); 
23001 \shape italic
23002 unmatched #pragma save and #pragma restore
23003 \shape default
23004  (170); 
23005 \shape italic
23006 comparison of 'signed char' with 'unsigned char' requires promotion to int
23007 \shape default
23008  (185); 
23009 \shape italic
23010 ISO C90 does not support flexible array members
23011 \shape default
23012  (187); 
23013 \shape italic
23014 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
23015 nam
23016 e]':\InsetSpace ~
23017 [
23018 \begin_inset Note Note
23019 status collapsed
23020
23021 \begin_layout Standard
23022 appears to be always blank - what was supposed to be here?
23023 \end_layout
23024
23025 \end_inset
23026
23027 ]
23028 \shape default
23029  (114); 
23030 \shape italic
23031 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
23032  complexity [number]
23033 \shape default
23034  (121).
23035 \end_layout
23036
23037 \begin_layout Itemize
23038
23039 \series bold
23040 disable_warning
23041 \series default
23042  <nnnn>
23043 \begin_inset LatexCommand index
23044 name "\\#pragma disable\\_warning"
23045
23046 \end_inset
23047
23048  - the compiler will not warn you anymore about warning number <nnnn>.
23049 \end_layout
23050
23051 \begin_layout Itemize
23052
23053 \series bold
23054 nogcse
23055 \series default
23056
23057 \begin_inset LatexCommand index
23058 name "\\#pragma nogcse"
23059
23060 \end_inset
23061
23062  - will stop global common subexpression elimination.
23063 \end_layout
23064
23065 \begin_layout Itemize
23066
23067 \series bold
23068 noinduction
23069 \series default
23070
23071 \begin_inset LatexCommand index
23072 name "\\#pragma noinduction"
23073
23074 \end_inset
23075
23076  - will stop loop induction optimizations.
23077 \end_layout
23078
23079 \begin_layout Itemize
23080
23081 \series bold
23082 noinvariant
23083 \series default
23084
23085 \begin_inset LatexCommand index
23086 name "\\#pragma noinvariant"
23087
23088 \end_inset
23089
23090  - will not do loop invariant optimizations.
23091  For more details see Loop Invariants in section
23092 \begin_inset LatexCommand ref
23093 reference "sub:Loop-Optimizations"
23094
23095 \end_inset
23096
23097 .
23098 \end_layout
23099
23100 \begin_layout Itemize
23101
23102 \series bold
23103 noiv
23104 \series default
23105
23106 \begin_inset LatexCommand index
23107 name "\\#pragma noiv"
23108
23109 \end_inset
23110
23111  - Do not generate interrupt
23112 \begin_inset LatexCommand index
23113 name "interrupt"
23114
23115 \end_inset
23116
23117  vector table
23118 \begin_inset LatexCommand index
23119 name "interrupt vector table"
23120
23121 \end_inset
23122
23123  entries for all ISR functions defined after the pragma.
23124  This is useful in cases where the interrupt vector table must be defined
23125  manually, or when there is a secondary, manually defined interrupt vector
23126  table (e.g.
23127  for the autovector feature of the Cypress EZ-USB FX2).
23128  More elegantly this can be achieved by omitting the optional interrupt
23129  number after the interrupt keyword, see section 
23130 \begin_inset LatexCommand ref
23131 reference "sub:Interrupt-Service-Routines"
23132
23133 \end_inset
23134
23135 \InsetSpace ~
23136 about interrupts.
23137 \end_layout
23138
23139 \begin_layout Itemize
23140
23141 \series bold
23142 nojtbound
23143 \series default
23144
23145 \begin_inset LatexCommand index
23146 name "\\#pragma nojtbound"
23147
23148 \end_inset
23149
23150  - will not generate code for boundary value checking, when switch statements
23151  are turned into jump-tables (dangerous).
23152  For more details see section 
23153 \begin_inset LatexCommand ref
23154 reference "sub:'switch'-Statements"
23155
23156 \end_inset
23157
23158 .
23159 \end_layout
23160
23161 \begin_layout Itemize
23162
23163 \series bold
23164 noloopreverse
23165 \series default
23166
23167 \begin_inset LatexCommand index
23168 name "\\#pragma noloopreverse"
23169
23170 \end_inset
23171
23172  - Will not do loop reversal optimization
23173 \end_layout
23174
23175 \begin_layout Itemize
23176
23177 \series bold
23178 nooverlay
23179 \series default
23180
23181 \begin_inset LatexCommand index
23182 name "\\#pragma nooverlay"
23183
23184 \end_inset
23185
23186  - the compiler will not overlay the parameters and local variables of a
23187  function.
23188 \end_layout
23189
23190 \begin_layout Itemize
23191
23192 \series bold
23193 stackauto
23194 \series default
23195
23196 \begin_inset LatexCommand index
23197 name "\\#pragma stackauto"
23198
23199 \end_inset
23200
23201 - See option -
23202 \begin_inset ERT
23203 status collapsed
23204
23205 \begin_layout Standard
23206
23207
23208 \backslash
23209 /
23210 \end_layout
23211
23212 \end_inset
23213
23214 -stack-auto
23215 \begin_inset LatexCommand index
23216 name "-\\/-stack-auto"
23217
23218 \end_inset
23219
23220  and section 
23221 \begin_inset LatexCommand ref
23222 reference "sec:Parameters-and-Local-Variables"
23223
23224 \end_inset
23225
23226  Parameters and Local Variables.
23227 \end_layout
23228
23229 \begin_layout Itemize
23230
23231 \series bold
23232 opt_code_speed
23233 \series default
23234  
23235 \begin_inset LatexCommand index
23236 name "\\#pragma opt\\_code\\_speed"
23237
23238 \end_inset
23239
23240 - The compiler will optimize code generation towards fast code, possibly
23241  at the expense of code size.
23242  Currently this has little effect.
23243 \end_layout
23244
23245 \begin_layout Itemize
23246
23247 \series bold
23248 opt_code_size
23249 \series default
23250  
23251 \begin_inset LatexCommand index
23252 name "\\#pragma opt\\_code\\_size"
23253
23254 \end_inset
23255
23256 - The compiler will optimize code generation towards compact code, possibly
23257  at the expense of code speed.
23258  Currently this has little effect.
23259 \end_layout
23260
23261 \begin_layout Itemize
23262
23263 \series bold
23264 opt_code_balanced
23265 \series default
23266  
23267 \begin_inset LatexCommand index
23268 name "\\#pragma opt\\_code\\_balanced"
23269
23270 \end_inset
23271
23272 - The compiler will attempt to generate code that is both compact and fast,
23273  as long as meeting one goal is not a detriment to the other (this is the
23274  default).
23275  
23276 \end_layout
23277
23278 \begin_layout Itemize
23279
23280 \series bold
23281 std_sdcc89
23282 \series default
23283  
23284 \begin_inset LatexCommand index
23285 name "\\#pragma std\\_sdcc89"
23286
23287 \end_inset
23288
23289 - Generally follow the C89 standard, but allow SDCC features that conflict
23290  with the standard (default).
23291 \end_layout
23292
23293 \begin_layout Itemize
23294
23295 \series bold
23296 std_c89
23297 \series default
23298  
23299 \begin_inset LatexCommand index
23300 name "\\#pragma std\\_c89"
23301
23302 \end_inset
23303
23304 - Follow the C89 standard and disable SDCC features that conflict with the
23305  standard.
23306 \end_layout
23307
23308 \begin_layout Itemize
23309
23310 \series bold
23311 std_sdcc99
23312 \series default
23313  
23314 \begin_inset LatexCommand index
23315 name "\\#pragma std\\_sdcc99"
23316
23317 \end_inset
23318
23319 - Generally follow the C99 standard, but allow SDCC features that conflict
23320  with the standard (incomplete support).
23321 \end_layout
23322
23323 \begin_layout Itemize
23324
23325 \series bold
23326 std_c99
23327 \series default
23328  
23329 \begin_inset LatexCommand index
23330 name "\\#pragma std\\_c99"
23331
23332 \end_inset
23333
23334 - Follow the C99 standard and disable SDCC features that conflict with the
23335  standard (incomplete support).
23336 \end_layout
23337
23338 \begin_layout Itemize
23339
23340 \series bold
23341 codeseg
23342 \series default
23343  <name>
23344 \begin_inset LatexCommand index
23345 name "\\#pragma codeseg"
23346
23347 \end_inset
23348
23349 - Use this name (max.
23350  8 characters) for the code segment.
23351  See option -
23352 \begin_inset ERT
23353 status collapsed
23354
23355 \begin_layout Standard
23356
23357
23358 \backslash
23359 /
23360 \end_layout
23361
23362 \end_inset
23363
23364 -codeseg.
23365 \end_layout
23366
23367 \begin_layout Itemize
23368
23369 \series bold
23370 constseg
23371 \series default
23372  <name>
23373 \begin_inset LatexCommand index
23374 name "\\#pragma constseg"
23375
23376 \end_inset
23377
23378 - Use this name (max.
23379  8 characters) for the const segment.
23380  See option -
23381 \begin_inset ERT
23382 status collapsed
23383
23384 \begin_layout Standard
23385
23386
23387 \backslash
23388 /
23389 \end_layout
23390
23391 \end_inset
23392
23393 -constseg.
23394 \end_layout
23395
23396 \begin_layout Standard
23397 The preprocessor SDCPP
23398 \begin_inset LatexCommand index
23399 name "sdcpp (preprocessor)"
23400
23401 \end_inset
23402
23403  supports the following #pragma directives:
23404 \end_layout
23405
23406 \begin_layout Itemize
23407
23408 \series bold
23409 pedantic_parse_number
23410 \series default
23411
23412 \begin_inset LatexCommand index
23413 name "pedantic"
23414
23415 \end_inset
23416
23417
23418 \begin_inset LatexCommand index
23419 name "\\#pragma pedantic\\_parse\\_number"
23420
23421 \end_inset
23422
23423  (+ | -) 
23424 \begin_inset LatexCommand label
23425 name "ite:pedantic_parse_number"
23426
23427 \end_inset
23428
23429 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
23430  properly and the macro LO_B(3) gets expanded.
23431  Default is off.
23432  See also the -
23433 \begin_inset ERT
23434 status collapsed
23435
23436 \begin_layout Standard
23437
23438
23439 \backslash
23440 /
23441 \end_layout
23442
23443 \end_inset
23444
23445 -pedantic-parse-number command line option 
23446 \begin_inset LatexCommand vpageref
23447 reference "lyx:-pedantic-parse-number"
23448
23449 \end_inset
23450
23451 .
23452  
23453 \newline
23454 Below is an example on how to use this pragma.
23455  
23456 \emph on
23457 Note: this functionality is not in conformance with standard!
23458 \end_layout
23459
23460 \begin_layout Verse
23461
23462 \family typewriter
23463 #pragma pedantic_parse_number +
23464 \begin_inset LatexCommand index
23465 name "\\#pragma pedantic\\_parse\\_number"
23466
23467 \end_inset
23468
23469
23470 \newline
23471
23472 \newline
23473 #define LO_B(x) ((x) & 0xff)
23474 \newline
23475
23476 \newline
23477 unsigned char foo(void)
23478 \newline
23479 {
23480 \newline
23481 \InsetSpace ~
23482 \InsetSpace ~
23483 \InsetSpace ~
23484 unsigned char c=0xfe-LO_B(3)
23485 ;
23486 \newline
23487
23488 \newline
23489 \InsetSpace ~
23490 \InsetSpace ~
23491 \InsetSpace ~
23492 return c;
23493 \newline
23494 }
23495 \newline
23496
23497 \end_layout
23498
23499 \begin_layout Itemize
23500
23501 \series bold
23502 preproc_asm
23503 \series default
23504
23505 \begin_inset LatexCommand index
23506 name "\\#pragma preproc\\_asm"
23507
23508 \end_inset
23509
23510  (+ | -) - switch _asm _endasm block preprocessing on / off.
23511  Default is on.
23512  You use this pragma to define multilines of assembly code.
23513  This will prevent the preprocessor from changing the formatting required
23514  by assembly code.
23515  Below is an example on how to use this pragma.
23516 \end_layout
23517
23518 \begin_layout Verse
23519
23520 \family typewriter
23521 #pragma preproc_asm -
23522 \begin_inset LatexCommand index
23523 name "\\#pragma preproc\\_asm"
23524
23525 \end_inset
23526
23527
23528 \newline
23529 #define MYDELAY _asm
23530 \newline
23531 \InsetSpace ~
23532 \InsetSpace ~
23533 \InsetSpace ~
23534 nop ;my assembly comment...
23535 \newline
23536 \InsetSpace ~
23537 \InsetSpace ~
23538 \InsetSpace ~
23539 nop
23540 \newline
23541 \InsetSpace ~
23542 \InsetSpace ~
23543 \InsetSpace ~
23544 nop
23545 \newline
23546 _endasm
23547 \newline
23548 #pragma preproc_asm
23549  +
23550 \newline
23551
23552 \newline
23553 void foo (void) 
23554 \newline
23555
23556 \newline
23557 \InsetSpace ~
23558 \InsetSpace ~
23559 \InsetSpace ~
23560  ...
23561  
23562 \newline
23563 \InsetSpace ~
23564 \InsetSpace ~
23565 \InsetSpace ~
23566  MYDELAY;
23567 \newline
23568 \InsetSpace ~
23569 \InsetSpace ~
23570 \InsetSpace ~
23571  ...
23572  
23573 \newline
23574
23575 \newline
23576
23577 \end_layout
23578
23579 \begin_layout Itemize
23580
23581 \series bold
23582 sdcc_hash
23583 \series default
23584
23585 \begin_inset LatexCommand index
23586 name "\\#pragma sdcc\\_hash"
23587
23588 \end_inset
23589
23590  (+ | -) - Allow "naked" hash in macro definition, for example:
23591 \newline
23592
23593 \family typewriter
23594 #define DIR_LO(x) #(x & 0xff)
23595 \family default
23596
23597 \newline
23598 Default is off.
23599  Below is an example on how to use this pragma.
23600 \end_layout
23601
23602 \begin_layout Verse
23603
23604 \family typewriter
23605 #pragma preproc_asm +
23606 \newline
23607 #pragma sdcc_hash +
23608 \begin_inset LatexCommand index
23609 name "\\#pragma sdcc\\_hash"
23610
23611 \end_inset
23612
23613
23614 \newline
23615
23616 \newline
23617 #define ROMCALL(x) 
23618 \backslash
23619
23620 \newline
23621 \InsetSpace ~
23622 \InsetSpace ~
23623 \InsetSpace ~
23624 mov R6_B3, #(x & 0xff) 
23625 \backslash
23626
23627 \newline
23628 \InsetSpace ~
23629 \InsetSpace ~
23630 \InsetSpace ~
23631 mov R7_B3, #((x >> 8) & 0xff) 
23632 \backslash
23633
23634 \newline
23635 \InsetSpace ~
23636 \InsetSpace ~
23637 \InsetSpace ~
23638 lcall __romcall
23639 \newline
23640
23641 \newline
23642 ...
23643 \newline
23644 _asm
23645 \newline
23646 ROMCALL(72)
23647 \newline
23648 _endasm;
23649 \newline
23650 ...
23651 \newline
23652
23653 \end_layout
23654
23655 \begin_layout Standard
23656 Some of the pragmas are intended to be used to turn-on or off certain optimizati
23657 ons which might cause the compiler to generate extra stack and/or data space
23658  to store compiler generated temporary variables.
23659  This usually happens in large functions.
23660  Pragma directives should be used as shown in the following example, they
23661  are used to control options and optimizations for a given function.
23662  
23663 \end_layout
23664
23665 \begin_layout Verse
23666
23667 \family typewriter
23668 #pragma save
23669 \begin_inset LatexCommand index
23670 name "\\#pragma save"
23671
23672 \end_inset
23673
23674  \InsetSpace ~
23675 \InsetSpace ~
23676 \InsetSpace ~
23677 \InsetSpace ~
23678 \InsetSpace ~
23679 \InsetSpace ~
23680 \InsetSpace ~
23681 /* save the current settings */ 
23682 \newline
23683 #pragma nogcse
23684 \begin_inset LatexCommand index
23685 name "\\#pragma nogcse"
23686
23687 \end_inset
23688
23689  \InsetSpace ~
23690 \InsetSpace ~
23691 \InsetSpace ~
23692 \InsetSpace ~
23693 \InsetSpace ~
23694 /* turnoff global subexpression elimination */ 
23695 \newline
23696 #pragma noinduction
23697 \begin_inset LatexCommand index
23698 name "\\#pragma noinduction"
23699
23700 \end_inset
23701
23702  /* turn off induction optimizations */ 
23703 \newline
23704 int foo () 
23705 \newline
23706
23707 \newline
23708 \InsetSpace ~
23709  \InsetSpace ~
23710  ...
23711  
23712 \newline
23713 \InsetSpace ~
23714  \InsetSpace ~
23715  /* large code */ 
23716 \newline
23717 \InsetSpace ~
23718  \InsetSpace ~
23719  ...
23720  
23721 \newline
23722
23723 \newline
23724 #pragma restore
23725 \begin_inset LatexCommand index
23726 name "\\#pragma restore"
23727
23728 \end_inset
23729
23730  /* turn the optimizations back on */
23731 \end_layout
23732
23733 \begin_layout Standard
23734 The compiler will generate a warning message when extra space is allocated.
23735  It is strongly recommended that the save and restore pragmas be used when
23736  changing options for a function.
23737 \newline
23738
23739 \newline
23740
23741 \newline
23742
23743 \end_layout
23744
23745 \begin_layout Section
23746 Defines Created by the Compiler
23747 \end_layout
23748
23749 \begin_layout Standard
23750 The compiler creates the following #defines
23751 \begin_inset LatexCommand index
23752 name "\\#defines"
23753
23754 \end_inset
23755
23756
23757 \begin_inset LatexCommand index
23758 name "Defines created by the compiler"
23759
23760 \end_inset
23761
23762 :
23763 \newline
23764
23765 \end_layout
23766
23767 \begin_layout Standard
23768 \begin_inset Tabular
23769 <lyxtabular version="3" rows="15" columns="2">
23770 <features>
23771 <column alignment="left" valignment="top" leftline="true" width="3in">
23772 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
23773 <row topline="true" bottomline="true">
23774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23775 \begin_inset Text
23776
23777 \begin_layout Standard
23778
23779 \series bold
23780 #define
23781 \end_layout
23782
23783 \end_inset
23784 </cell>
23785 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23786 \begin_inset Text
23787
23788 \begin_layout Standard
23789
23790 \series bold
23791 Description
23792 \end_layout
23793
23794 \end_inset
23795 </cell>
23796 </row>
23797 <row topline="true">
23798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23799 \begin_inset Text
23800
23801 \begin_layout Standard
23802 SDCC
23803 \begin_inset LatexCommand index
23804 name "SDCC"
23805
23806 \end_inset
23807
23808  
23809 \end_layout
23810
23811 \end_inset
23812 </cell>
23813 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23814 \begin_inset Text
23815
23816 \begin_layout Standard
23817 Always defined.
23818  Since version 2.5.6 the version number as an int (ex.
23819  256)
23820 \end_layout
23821
23822 \end_inset
23823 </cell>
23824 </row>
23825 <row topline="true">
23826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23827 \begin_inset Text
23828
23829 \begin_layout Standard
23830 SDCC_mcs51
23831 \begin_inset LatexCommand index
23832 name "SDCC\\_mcs51"
23833
23834 \end_inset
23835
23836  or SDCC_ds390
23837 \begin_inset LatexCommand index
23838 name "SDCC\\_ds390"
23839
23840 \end_inset
23841
23842  or SDCC_z80
23843 \begin_inset LatexCommand index
23844 name "SDCC\\_z80"
23845
23846 \end_inset
23847
23848 , etc.
23849 \end_layout
23850
23851 \end_inset
23852 </cell>
23853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23854 \begin_inset Text
23855
23856 \begin_layout Standard
23857 depending on the model used (e.g.: -mds390)
23858 \end_layout
23859
23860 \end_inset
23861 </cell>
23862 </row>
23863 <row topline="true">
23864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23865 \begin_inset Text
23866
23867 \begin_layout Standard
23868 __mcs51
23869 \begin_inset LatexCommand index
23870 name "\\_\\_mcs51"
23871
23872 \end_inset
23873
23874 , __ds390
23875 \begin_inset LatexCommand index
23876 name "\\_\\_ds390"
23877
23878 \end_inset
23879
23880 , __hc08
23881 \begin_inset LatexCommand index
23882 name "\\_\\_hc08"
23883
23884 \end_inset
23885
23886 , __z80
23887 \begin_inset LatexCommand index
23888 name "\\_\\_z80"
23889
23890 \end_inset
23891
23892 , etc
23893 \end_layout
23894
23895 \end_inset
23896 </cell>
23897 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23898 \begin_inset Text
23899
23900 \begin_layout Standard
23901 depending on the model used (e.g.
23902  -mz80)
23903 \end_layout
23904
23905 \end_inset
23906 </cell>
23907 </row>
23908 <row topline="true">
23909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23910 \begin_inset Text
23911
23912 \begin_layout Standard
23913 SDCC_STACK_AUTO
23914 \begin_inset LatexCommand index
23915 name "SDCC\\_STACK\\_AUTO"
23916
23917 \end_inset
23918
23919
23920 \end_layout
23921
23922 \end_inset
23923 </cell>
23924 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23925 \begin_inset Text
23926
23927 \begin_layout Standard
23928 when 
23929 \emph on
23930 -
23931 \begin_inset ERT
23932 status collapsed
23933
23934 \begin_layout Standard
23935
23936
23937 \backslash
23938 /
23939 \end_layout
23940
23941 \end_inset
23942
23943 -stack-auto
23944 \emph default
23945  option is used
23946 \end_layout
23947
23948 \end_inset
23949 </cell>
23950 </row>
23951 <row topline="true">
23952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23953 \begin_inset Text
23954
23955 \begin_layout Standard
23956 SDCC_MODEL_SMALL
23957 \begin_inset LatexCommand index
23958 name "SDCC\\_MODEL\\_SMALL"
23959
23960 \end_inset
23961
23962
23963 \end_layout
23964
23965 \end_inset
23966 </cell>
23967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23968 \begin_inset Text
23969
23970 \begin_layout Standard
23971 when 
23972 \emph on
23973 -
23974 \begin_inset ERT
23975 status collapsed
23976
23977 \begin_layout Standard
23978
23979
23980 \backslash
23981 /
23982 \end_layout
23983
23984 \end_inset
23985
23986 -model-small
23987 \emph default
23988  is used
23989 \end_layout
23990
23991 \end_inset
23992 </cell>
23993 </row>
23994 <row topline="true">
23995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23996 \begin_inset Text
23997
23998 \begin_layout Standard
23999 SDCC_MODEL_MEDIUM
24000 \begin_inset LatexCommand index
24001 name "SDCC\\_MODEL\\_MEDIUM"
24002
24003 \end_inset
24004
24005
24006 \end_layout
24007
24008 \end_inset
24009 </cell>
24010 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24011 \begin_inset Text
24012
24013 \begin_layout Standard
24014 when 
24015 \emph on
24016 -
24017 \begin_inset ERT
24018 status collapsed
24019
24020 \begin_layout Standard
24021
24022
24023 \backslash
24024 /
24025 \end_layout
24026
24027 \end_inset
24028
24029 -model-medium
24030 \emph default
24031  is used
24032 \end_layout
24033
24034 \end_inset
24035 </cell>
24036 </row>
24037 <row topline="true">
24038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24039 \begin_inset Text
24040
24041 \begin_layout Standard
24042 SDCC_MODEL_LARGE
24043 \begin_inset LatexCommand index
24044 name "SDCC\\_MODEL\\_LARGE"
24045
24046 \end_inset
24047
24048
24049 \end_layout
24050
24051 \end_inset
24052 </cell>
24053 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24054 \begin_inset Text
24055
24056 \begin_layout Standard
24057 when 
24058 \emph on
24059 -
24060 \begin_inset ERT
24061 status collapsed
24062
24063 \begin_layout Standard
24064
24065
24066 \backslash
24067 /
24068 \end_layout
24069
24070 \end_inset
24071
24072 -model-large
24073 \emph default
24074  is used
24075 \end_layout
24076
24077 \end_inset
24078 </cell>
24079 </row>
24080 <row topline="true">
24081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24082 \begin_inset Text
24083
24084 \begin_layout Standard
24085 SDCC_USE_XSTACK
24086 \begin_inset LatexCommand index
24087 name "SDCC\\_USE\\_XSTACK"
24088
24089 \end_inset
24090
24091
24092 \end_layout
24093
24094 \end_inset
24095 </cell>
24096 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24097 \begin_inset Text
24098
24099 \begin_layout Standard
24100 when 
24101 \emph on
24102 -
24103 \begin_inset ERT
24104 status collapsed
24105
24106 \begin_layout Standard
24107
24108
24109 \backslash
24110 /
24111 \end_layout
24112
24113 \end_inset
24114
24115 -xstack
24116 \emph default
24117  option is used
24118 \end_layout
24119
24120 \end_inset
24121 </cell>
24122 </row>
24123 <row topline="true">
24124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24125 \begin_inset Text
24126
24127 \begin_layout Standard
24128 SDCC_STACK_TENBIT
24129 \begin_inset LatexCommand index
24130 name "SDCC\\_STACK\\_TENBIT"
24131
24132 \end_inset
24133
24134  
24135 \end_layout
24136
24137 \end_inset
24138 </cell>
24139 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24140 \begin_inset Text
24141
24142 \begin_layout Standard
24143 when 
24144 \emph on
24145 -mds390
24146 \emph default
24147  is used
24148 \end_layout
24149
24150 \end_inset
24151 </cell>
24152 </row>
24153 <row topline="true">
24154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24155 \begin_inset Text
24156
24157 \begin_layout Standard
24158 SDCC_MODEL_FLAT24
24159 \begin_inset LatexCommand index
24160 name "SDCC\\_MODEL\\_FLAT24"
24161
24162 \end_inset
24163
24164
24165 \end_layout
24166
24167 \end_inset
24168 </cell>
24169 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24170 \begin_inset Text
24171
24172 \begin_layout Standard
24173 when 
24174 \emph on
24175 -mds390
24176 \emph default
24177  is used
24178 \end_layout
24179
24180 \end_inset
24181 </cell>
24182 </row>
24183 <row topline="true">
24184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24185 \begin_inset Text
24186
24187 \begin_layout Standard
24188 SDCC_REVISION
24189 \begin_inset LatexCommand index
24190 name "SDCC\\_REVISION"
24191
24192 \end_inset
24193
24194
24195 \end_layout
24196
24197 \end_inset
24198 </cell>
24199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24200 \begin_inset Text
24201
24202 \begin_layout Standard
24203 Always defined.
24204  SDCC svn revision number
24205 \end_layout
24206
24207 \end_inset
24208 </cell>
24209 </row>
24210 <row topline="true">
24211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24212 \begin_inset Text
24213
24214 \begin_layout Standard
24215 SDCC_PARMS_IN_BANK1
24216 \begin_inset LatexCommand index
24217 name "SDCC\\_PARMS\\_IN\\_BANK1"
24218
24219 \end_inset
24220
24221
24222 \end_layout
24223
24224 \end_inset
24225 </cell>
24226 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24227 \begin_inset Text
24228
24229 \begin_layout Standard
24230 when 
24231 \emph on
24232 -
24233 \begin_inset ERT
24234 status collapsed
24235
24236 \begin_layout Standard
24237
24238
24239 \backslash
24240 /
24241 \end_layout
24242
24243 \end_inset
24244
24245 -parms-in-bank1
24246 \emph default
24247  is used
24248 \end_layout
24249
24250 \end_inset
24251 </cell>
24252 </row>
24253 <row topline="true">
24254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24255 \begin_inset Text
24256
24257 \begin_layout Standard
24258 SDCC_FLOAT_REENT
24259 \begin_inset LatexCommand index
24260 name "SDCC\\_MODEL\\_FLAT24"
24261
24262 \end_inset
24263
24264
24265 \end_layout
24266
24267 \end_inset
24268 </cell>
24269 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24270 \begin_inset Text
24271
24272 \begin_layout Standard
24273 when 
24274 \emph on
24275 -
24276 \begin_inset ERT
24277 status collapsed
24278
24279 \begin_layout Standard
24280
24281
24282 \backslash
24283 /
24284 \end_layout
24285
24286 \end_inset
24287
24288 -float-reent
24289 \emph default
24290  is used
24291 \end_layout
24292
24293 \end_inset
24294 </cell>
24295 </row>
24296 <row topline="true" bottomline="true">
24297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24298 \begin_inset Text
24299
24300 \begin_layout Standard
24301 SDCC_INT_LONG_REENT
24302 \begin_inset LatexCommand index
24303 name "SDCC\\_INT\\_LONG\\_REENT"
24304
24305 \end_inset
24306
24307
24308 \end_layout
24309
24310 \end_inset
24311 </cell>
24312 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24313 \begin_inset Text
24314
24315 \begin_layout Standard
24316 when 
24317 \emph on
24318 -
24319 \begin_inset ERT
24320 status collapsed
24321
24322 \begin_layout Standard
24323
24324
24325 \backslash
24326 /
24327 \end_layout
24328
24329 \end_inset
24330
24331 -int-long-reent
24332 \emph default
24333  is used
24334 \end_layout
24335
24336 \end_inset
24337 </cell>
24338 </row>
24339 </lyxtabular>
24340
24341 \end_inset
24342
24343
24344 \end_layout
24345
24346 \begin_layout Chapter
24347 Notes on supported Processors
24348 \end_layout
24349
24350 \begin_layout Section
24351 MCS51 variants
24352 \begin_inset LatexCommand label
24353 name "sub:MCS51-variants"
24354
24355 \end_inset
24356
24357
24358 \begin_inset LatexCommand index
24359 name "MCS51 variants"
24360
24361 \end_inset
24362
24363
24364 \end_layout
24365
24366 \begin_layout Standard
24367 MCS51 processors are available from many vendors and come in many different
24368  flavours.
24369  While they might differ considerably in respect to Special Function Registers
24370  the core MCS51 is usually not modified or is kept compatible.
24371  
24372 \end_layout
24373
24374 \begin_layout Subsection
24375 pdata access by SFR 
24376 \end_layout
24377
24378 \begin_layout Standard
24379 With the upcome of devices with internal xdata and flash memory devices
24380  using port P2
24381 \begin_inset LatexCommand index
24382 name "P2 (mcs51 sfr)"
24383
24384 \end_inset
24385
24386  as dedicated I/O port is becoming more popular.
24387  Switching the high byte for pdata
24388 \begin_inset LatexCommand index
24389 name "pdata (mcs51, ds390 storage class)"
24390
24391 \end_inset
24392
24393  access which was formerly done by port P2 is then achieved by a Special
24394  Function Register
24395 \begin_inset LatexCommand index
24396 name "sfr"
24397
24398 \end_inset
24399
24400 .
24401  In well-established MCS51 tradition the address of this 
24402 \emph on
24403 sfr
24404 \emph default
24405  is where the chip designers decided to put it.
24406  Needless to say that they didn't agree on a common name either.
24407  So that the startup code can correctly initialize xdata variables, you
24408  should define an sfr with the name _XPAGE
24409 \family typewriter
24410
24411 \begin_inset LatexCommand index
24412 name "\\_XPAGE (mcs51)"
24413
24414 \end_inset
24415
24416
24417 \family default
24418  at the appropriate location if the default, port P2, is not used for this.
24419  Some examples are:
24420 \end_layout
24421
24422 \begin_layout Verse
24423
24424 \family typewriter
24425 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
24426  MPAGE */
24427 \end_layout
24428
24429 \begin_layout Verse
24430
24431 \family typewriter
24432 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
24433  a.k.a.
24434  MPAGE */
24435 \end_layout
24436
24437 \begin_layout Verse
24438
24439 \family typewriter
24440 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
24441  XPAGE */
24442 \end_layout
24443
24444 \begin_layout Verse
24445
24446 \family typewriter
24447 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
24448  EMI0CN */
24449 \end_layout
24450
24451 \begin_layout Verse
24452
24453 \family typewriter
24454 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
24455  EMI0CN */
24456 \end_layout
24457
24458 \begin_layout Standard
24459 For more exotic implementations further customizations may be needed.
24460  See section 
24461 \begin_inset LatexCommand ref
24462 reference "sub:Startup-Code"
24463
24464 \end_inset
24465
24466  for other possibilities.
24467 \end_layout
24468
24469 \begin_layout Subsection
24470 Other Features available by SFR
24471 \end_layout
24472
24473 \begin_layout Standard
24474 Some MCS51 variants offer features like Double DPTR
24475 \begin_inset LatexCommand index
24476 name "DPTR"
24477
24478 \end_inset
24479
24480 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
24481  These are currently not used for the MCS51 port.
24482  If you absolutely need them you can fall back to inline assembly or submit
24483  a patch to SDCC.
24484 \end_layout
24485
24486 \begin_layout Subsection
24487 Bankswitching
24488 \end_layout
24489
24490 \begin_layout Standard
24491 Bankswitching
24492 \begin_inset LatexCommand index
24493 name "Bankswitching"
24494
24495 \end_inset
24496
24497  (a.k.a.
24498  code banking
24499 \begin_inset LatexCommand index
24500 name "code banking"
24501
24502 \end_inset
24503
24504 ) is a technique to increase the code space above the 64k limit of the 8051.
24505 \end_layout
24506
24507 \begin_layout Subsubsection
24508 Hardware
24509 \end_layout
24510
24511 \begin_layout Standard
24512 \begin_inset Tabular
24513 <lyxtabular version="3" rows="3" columns="4">
24514 <features>
24515 <column alignment="center" valignment="top" width="0">
24516 <column alignment="center" valignment="top" leftline="true" width="0">
24517 <column alignment="center" valignment="top" leftline="true" width="0">
24518 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24519 <row topline="true" bottomline="true">
24520 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24521 \begin_inset Text
24522
24523 \begin_layout Standard
24524 8000-FFFF
24525 \end_layout
24526
24527 \end_inset
24528 </cell>
24529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24530 \begin_inset Text
24531
24532 \begin_layout Standard
24533 bank1
24534 \end_layout
24535
24536 \end_inset
24537 </cell>
24538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24539 \begin_inset Text
24540
24541 \begin_layout Standard
24542 bank2
24543 \end_layout
24544
24545 \end_inset
24546 </cell>
24547 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24548 \begin_inset Text
24549
24550 \begin_layout Standard
24551 bank3
24552 \end_layout
24553
24554 \end_inset
24555 </cell>
24556 </row>
24557 <row topline="true" bottomline="true">
24558 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24559 \begin_inset Text
24560
24561 \begin_layout Standard
24562 0000-7FFF
24563 \end_layout
24564
24565 \end_inset
24566 </cell>
24567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24568 \begin_inset Text
24569
24570 \begin_layout Standard
24571 common
24572 \end_layout
24573
24574 \end_inset
24575 </cell>
24576 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24577 \begin_inset Text
24578
24579 \begin_layout Standard
24580
24581 \end_layout
24582
24583 \end_inset
24584 </cell>
24585 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24586 \begin_inset Text
24587
24588 \begin_layout Standard
24589
24590 \end_layout
24591
24592 \end_inset
24593 </cell>
24594 </row>
24595 <row>
24596 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24597 \begin_inset Text
24598
24599 \begin_layout Standard
24600 SiLabs C8051F120 example
24601 \end_layout
24602
24603 \end_inset
24604 </cell>
24605 <cell multicolumn="2" alignment="center" valignment="top" usebox="none">
24606 \begin_inset Text
24607
24608 \begin_layout Standard
24609
24610 \end_layout
24611
24612 \end_inset
24613 </cell>
24614 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24615 \begin_inset Text
24616
24617 \begin_layout Standard
24618
24619 \end_layout
24620
24621 \end_inset
24622 </cell>
24623 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24624 \begin_inset Text
24625
24626 \begin_layout Standard
24627
24628 \end_layout
24629
24630 \end_inset
24631 </cell>
24632 </row>
24633 </lyxtabular>
24634
24635 \end_inset
24636
24637
24638 \newline
24639
24640 \newline
24641 Usually the hardware uses some sfr (an output port or an internal sfr) to
24642  select a bank and put it in the banked area of the memory map.
24643  The selected bank usually becomes active immediately upon assignment to
24644  this sfr and when running inside a bank it will switch out this code it
24645  is currently running.
24646  Therefor you cannot jump or call directly from one bank to another and
24647  need to use a so-called trampoline in the common area.
24648  For SDCC an example trampoline is in crtbank.asm and you may need to change
24649  it to your 8051 derivative or schematic.
24650  The presented code is written for the C8051F120.
24651 \newline
24652
24653 \newline
24654 When calling a banked function
24655  SDCC will put the LSB of the functions address in register R0, the MSB
24656  in R1 and the bank in R2 and then call this trampoline 
24657 \emph on
24658 __sdcc_banked_call
24659 \emph default
24660 .
24661  The current selected bank is saved on the stack, the new bank is selected
24662  and an indirect jump is made.
24663  When the banked function returns it jumps to 
24664 \emph on
24665 __sdcc_banked_ret
24666 \emph default
24667  which restores the previous bank and returns to the caller.
24668 \end_layout
24669
24670 \begin_layout Subsubsection
24671 Software
24672 \end_layout
24673
24674 \begin_layout Standard
24675 When writing banked software using SDCC you need to use some special keywords
24676  and options.
24677  You also need to take over a bit of work from the linker.
24678 \newline
24679
24680 \newline
24681 To create a function
24682  that can be called from another bank it requires the keyword 
24683 \emph on
24684 banked
24685 \emph default
24686
24687 \begin_inset LatexCommand index
24688 name "banked"
24689
24690 \end_inset
24691
24692 .
24693  The caller must see this in the prototype of the callee and the callee
24694  needs it for a proper return.
24695  Called functions within the same bank as the caller do not need the 
24696 \emph on
24697 banked
24698 \emph default
24699  keyword nor do functions in the common area.
24700  Beware: SDCC does not know or check if functions are in the same bank.
24701  This is your responsibility!
24702 \newline
24703
24704 \newline
24705 Normally all functions you write end up in
24706  the segment CSEG.
24707  If you want a function explicitly to reside in the common area put it in
24708  segment HOME.
24709  This applies for instance to interrupt service routines as they should
24710  not be banked.
24711 \end_layout
24712
24713 \begin_layout Standard
24714 Functions that need to be in a switched bank must be put in a named segment.
24715  The name can be mostly anything up to eight characters (e.g.
24716  BANK1).
24717  To do this you either use -
24718 \begin_inset ERT
24719 status collapsed
24720
24721 \begin_layout Standard
24722
24723
24724 \backslash
24725 /
24726 \end_layout
24727
24728 \end_inset
24729
24730 -codeseg BANK1 (See 
24731 \begin_inset LatexCommand ref
24732 reference "lyx:-codeseg"
24733
24734 \end_inset
24735
24736 ) on the command line when compiling or #pragma codeseg BANK1 (See 
24737 \begin_inset LatexCommand ref
24738 reference "sec:Pragmas"
24739
24740 \end_inset
24741
24742 ) at the top of the C source file.
24743  The segment name always applies to the whole source file and generated
24744  object so functions for different banks need to be defined in different
24745  source files.
24746 \newline
24747
24748 \newline
24749 When linking your objects you need to tell the linker where
24750  to put your segments.
24751  To do this you use the following command line option to SDCC: -Wl-b BANK1=0x180
24752 00 (See 
24753 \begin_inset LatexCommand ref
24754 reference "lyx:-Wl option"
24755
24756 \end_inset
24757
24758 ).
24759  This sets the virtual start address of this segment.
24760  It sets the banknumber to 0x01 and maps the bank to 0x8000 and up.
24761  The linker will not check for overflows, again this is your responsibility.
24762 \end_layout
24763
24764 \begin_layout Standard
24765 \begin_inset VSpace bigskip
24766 \end_inset
24767
24768
24769 \end_layout
24770
24771 \begin_layout Section
24772 DS400 port
24773 \end_layout
24774
24775 \begin_layout Standard
24776 The DS80C400
24777 \begin_inset LatexCommand index
24778 name "DS80C400"
24779
24780 \end_inset
24781
24782
24783 \begin_inset LatexCommand index
24784 name "DS400"
24785
24786 \end_inset
24787
24788  microcontroller has a rich set of peripherals.
24789  In its built-in ROM library it includes functions to access some of the
24790  features, among them is a TCP stack with IP4 and IP6 support.
24791  Library headers (currently in beta status) and other files are provided
24792  at 
24793 \size footnotesize
24794
24795 \begin_inset LatexCommand url
24796 target "ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html"
24797
24798 \end_inset
24799
24800 .
24801  
24802 \begin_inset VSpace bigskip
24803 \end_inset
24804
24805
24806 \end_layout
24807
24808 \begin_layout Section
24809 The Z80 and gbz80 port
24810 \end_layout
24811
24812 \begin_layout Standard
24813 SDCC can target both the Zilog Z80
24814 \begin_inset LatexCommand index
24815 name "Z80"
24816
24817 \end_inset
24818
24819  and the Nintendo Gameboy's Z80-like gbz80
24820 \begin_inset LatexCommand index
24821 name "gbz80 (GameBoy Z80)"
24822
24823 \end_inset
24824
24825 .
24826  The Z80 port is passed through the same 
24827 \emph on
24828 regressions tests
24829 \begin_inset LatexCommand index
24830 name "Regression test"
24831
24832 \end_inset
24833
24834
24835 \emph default
24836  (see section 
24837 \begin_inset LatexCommand ref
24838 reference "sec:Quality-control"
24839
24840 \end_inset
24841
24842 ) as the MCS51 and DS390 ports, so floating point support, support for long
24843  variables and bitfield support is fine.
24844  See mailing lists and forums about interrupt routines.
24845 \end_layout
24846
24847 \begin_layout Standard
24848 As always, the code is the authoritative reference - see z80/ralloc.c and
24849  z80/gen.c.
24850  The stack
24851 \begin_inset LatexCommand index
24852 name "Z80!stack"
24853
24854 \end_inset
24855
24856  frame is similar to that generated by the IAR Z80 compiler.
24857  IX is used as the base pointer, HL and IY are used as a temporary registers,
24858  and BC and DE are available for holding variables.
24859  Return values
24860 \begin_inset LatexCommand index
24861 name "Z80!return value"
24862
24863 \end_inset
24864
24865  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
24866  bytes).
24867  The gbz80 port use the same set of registers for the return values, but
24868  in a different order of significance: E (one byte), DE (two bytes), or
24869  HLDE (four bytes).
24870 \begin_inset VSpace bigskip
24871 \end_inset
24872
24873
24874 \end_layout
24875
24876 \begin_layout Section
24877 The HC08 port
24878 \end_layout
24879
24880 \begin_layout Standard
24881 The port to the Freescale/Motorola HC08
24882 \begin_inset LatexCommand index
24883 name "HC08"
24884
24885 \end_inset
24886
24887  family has been added in October 2003, and is still undergoing some basic
24888  development.
24889  The code generator is complete, but the register allocation is still quite
24890  unoptimized.
24891  Some of the SDCC's standard C library functions have embedded non-HC08
24892  inline assembly and so are not yet usable.
24893 \end_layout
24894
24895 \begin_layout Standard
24896 The HC08 port passes the regression test suite (see section 
24897 \begin_inset LatexCommand ref
24898 reference "sec:Quality-control"
24899
24900 \end_inset
24901
24902 ).
24903 \begin_inset VSpace bigskip
24904 \end_inset
24905
24906
24907 \end_layout
24908
24909 \begin_layout Section
24910 The PIC14
24911 \begin_inset LatexCommand index
24912 name "PIC14"
24913
24914 \end_inset
24915
24916  port
24917 \end_layout
24918
24919 \begin_layout Standard
24920 The PIC14 port adds support for Microchip
24921 \begin_inset LatexCommand index
24922 name "Microchip"
24923
24924 \end_inset
24925
24926
24927 \begin_inset Formula $^{\text{TM}}$
24928 \end_inset
24929
24930  PIC
24931 \begin_inset LatexCommand index
24932 name "PIC14"
24933
24934 \end_inset
24935
24936
24937 \begin_inset Formula $^{\text{TM}}$
24938 \end_inset
24939
24940  MCUs with 14 bit wide instructions.
24941  This port is not yet mature and still lacks many features.
24942  However, it can work for simple code.
24943 \end_layout
24944
24945 \begin_layout Standard
24946 \noindent
24947 Currently supported devices include:
24948 \end_layout
24949
24950 \begin_layout Standard
24951 12F: 629, 635, 675, 683
24952 \end_layout
24953
24954 \begin_layout Standard
24955 16C: 432, 433
24956 \end_layout
24957
24958 \begin_layout Standard
24959 16C: 554, 557, 558
24960 \end_layout
24961
24962 \begin_layout Standard
24963 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
24964 \end_layout
24965
24966 \begin_layout Standard
24967 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
24968  781, 782
24969 \end_layout
24970
24971 \begin_layout Standard
24972 16C: 925, 926
24973 \end_layout
24974
24975 \begin_layout Standard
24976 16CR: 620a, 73, 74, 76, 77
24977 \end_layout
24978
24979 \begin_layout Standard
24980 16F: 616, 627, 627a, 628, 628a, 630, 636, 639, 648, 648a, 676, 684, 685,
24981  687, 688, 689, 690
24982 \end_layout
24983
24984 \begin_layout Standard
24985 16F: 716, 72, 73, 737, 74, 747, 76, 767, 77, 777, 785
24986 \end_layout
24987
24988 \begin_layout Standard
24989 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
24990  877, 877a, 88, 886, 887
24991 \end_layout
24992
24993 \begin_layout Standard
24994 16F: 913, 914, 916, 917, 946
24995 \end_layout
24996
24997 \begin_layout Standard
24998 26HV: 626, 785
24999 \end_layout
25000
25001 \begin_layout Standard
25002 \noindent
25003 An up-to-date list of currently supported devices can be obtained via 
25004 \family typewriter
25005 sdcc -mpic14 -phelp foo.c
25006 \family default
25007  (foo.c must exist...).
25008 \end_layout
25009
25010 \begin_layout Subsection
25011 PIC Code Pages
25012 \begin_inset LatexCommand index
25013 name "code page (pic14)"
25014
25015 \end_inset
25016
25017  and Memory Banks
25018 \begin_inset LatexCommand index
25019 name "Memory bank (pic14)"
25020
25021 \end_inset
25022
25023
25024 \end_layout
25025
25026 \begin_layout Standard
25027 The linker organizes allocation for the code page and RAM banks.
25028  It does not have intimate knowledge of the code flow.
25029  It will put all the code section of a single .asm file into a single code
25030  page.
25031  In order to make use of multiple code pages, separate asm files must be
25032  used.
25033  The compiler assigns all 
25034 \emph on
25035 static
25036 \emph default
25037  functions of a single .c file into the same code page.
25038 \newline
25039
25040 \newline
25041 To get the best results,
25042  follow these guidelines:
25043 \end_layout
25044
25045 \begin_layout Enumerate
25046 Make local functions static, as non static functions require code page selection
25047  overhead.
25048 \newline
25049 Due to the way sdcc handles functions, place called functions prior
25050  to calling functions in the file wherever possible: Otherwise sdcc will
25051  insert unnecessary pagesel directives around the call, believing that the
25052  called function is externally defined.
25053 \end_layout
25054
25055 \begin_layout Enumerate
25056 For devices that have multiple code pages it is more efficient to use the
25057  same number of files as pages: Use up to 4 separate .c files for the 16F877,
25058  but only 2 files for the 16F874.
25059  This way the linker can put the code for each file into different code
25060  pages and there will be less page selection overhead.
25061 \end_layout
25062
25063 \begin_layout Enumerate
25064 And as for any 8 bit micro (especially for PIC14 as they have a very simple
25065  instruction set), use `unsigned char' wherever possible instead of `int'.
25066 \end_layout
25067
25068 \begin_layout Subsection
25069 Adding New Devices to the Port 
25070 \end_layout
25071
25072 \begin_layout Standard
25073 Adding support for a new 14
25074 \begin_inset ERT
25075 status open
25076
25077 \begin_layout Standard
25078
25079
25080 \backslash
25081 ,
25082 \end_layout
25083
25084 \end_inset
25085
25086 bit PIC MCU requires the following steps:
25087 \end_layout
25088
25089 \begin_layout Enumerate
25090 Create a new device description.
25091 \newline
25092 Each device is described in two files: pic16f*.h
25093  and pic16f*.c.
25094  These files primarily define SFRs, structs to access their bits, and symbolic
25095  configuration options.
25096  Both files can be generated from gputils' .inc files using the perl script
25097  
25098 \family typewriter
25099 support/scripts/inc2h.pl
25100 \family default
25101 .
25102  This file also contains further instructions on how to proceed.
25103 \end_layout
25104
25105 \begin_layout Enumerate
25106 Copy the .h file into SDCC's include path and either add the .c file to your
25107  project or copy it to 
25108 \family typewriter
25109 device/lib/pic/libdev
25110 \family default
25111 .
25112  Afterwards, rebuild and install the libraries.
25113 \end_layout
25114
25115 \begin_layout Enumerate
25116 Edit pic14devices.txt in SDCC's include path (
25117 \family typewriter
25118 device/include/pic/
25119 \family default
25120  in the source tree or 
25121 \family typewriter
25122 /usr/local/share/sdcc/include/pic
25123 \family default
25124  after installation).
25125 \newline
25126 You need to add a device specification here to make
25127  the memory layout (code banks, RAM, aliased memory regions, ...) known to
25128  the compiler.
25129  Probably you can copy and modify an existing entry.
25130  The file format is documented at the top of the file.
25131 \end_layout
25132
25133 \begin_layout Subsection
25134 Interrupt Code
25135 \end_layout
25136
25137 \begin_layout Standard
25138 For the interrupt function, use the keyword `__interrupt'
25139 \begin_inset LatexCommand index
25140 name "PIC14!interrupt"
25141
25142 \end_inset
25143
25144  with level number of 0 (PIC14 only has 1 interrupt so this number is only
25145  there to avoid a syntax error - it ought to be fixed).
25146  E.g.:
25147 \end_layout
25148
25149 \begin_layout Verse
25150
25151 \family typewriter
25152 void Intr(void) __interrupt 0
25153 \newline
25154 {
25155 \newline
25156 \InsetSpace ~
25157 \InsetSpace ~
25158 T0IF = 0; /* Clear timer interrupt */
25159 \newline
25160 }
25161 \end_layout
25162
25163 \begin_layout Subsection
25164 Linking and Assembling
25165 \end_layout
25166
25167 \begin_layout Standard
25168 For assembling you can use either GPUTILS'
25169 \begin_inset LatexCommand index
25170 name "gputils (pic tools)"
25171
25172 \end_inset
25173
25174  gpasm.exe or MPLAB's mpasmwin.exe.
25175  GPUTILS are available from 
25176 \begin_inset LatexCommand url
25177 target "http://sourceforge.net/projects/gputils"
25178
25179 \end_inset
25180
25181 .
25182  For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
25183  If you use MPLAB and an interrupt function then the linker script file
25184  vectors section will need to be enlarged to link with mplink.
25185 \newline
25186
25187 \newline
25188 Here is a 
25189 \family typewriter
25190 Makefile
25191 \family default
25192  using GPUTILS:
25193 \end_layout
25194
25195 \begin_layout Verse
25196
25197 \family typewriter
25198 .c.o:
25199 \newline
25200 \InsetSpace ~
25201 \InsetSpace ~
25202 \InsetSpace ~
25203 \InsetSpace ~
25204 \InsetSpace ~
25205 \InsetSpace ~
25206 \InsetSpace ~
25207 \InsetSpace ~
25208 sdcc -V -mpic14 -p16f877 -c $< 
25209 \newline
25210
25211 \newline
25212 $(PRJ).hex: $(OBJS) 
25213 \newline
25214 \InsetSpace ~
25215 \InsetSpace ~
25216 \InsetSpace ~
25217 \InsetSpace ~
25218 \InsetSpace ~
25219 \InsetSpace ~
25220 \InsetSpace ~
25221 \InsetSpace ~
25222 gplink -m -s $(PRJ).lkr
25223  -o $(PRJ).hex $(OBJS) libsdcc.lib
25224 \end_layout
25225
25226 \begin_layout Standard
25227 Here is a 
25228 \family typewriter
25229 Makefile
25230 \family default
25231  using MPLAB:
25232 \end_layout
25233
25234 \begin_layout Verse
25235
25236 \family typewriter
25237 .c.o: 
25238 \newline
25239 \InsetSpace ~
25240 \InsetSpace ~
25241 \InsetSpace ~
25242 \InsetSpace ~
25243 \InsetSpace ~
25244 \InsetSpace ~
25245 \InsetSpace ~
25246 \InsetSpace ~
25247 sdcc -S -V -mpic14 -p16f877 $< 
25248 \newline
25249 \InsetSpace ~
25250 \InsetSpace ~
25251 \InsetSpace ~
25252 \InsetSpace ~
25253 \InsetSpace ~
25254 \InsetSpace ~
25255 \InsetSpace ~
25256 \InsetSpace ~
25257 mpasmwin /q /o $*.asm
25258 \newline
25259
25260 \newline
25261 $(PRJ).hex: $(OBJS)
25262  
25263 \newline
25264 \InsetSpace ~
25265 \InsetSpace ~
25266 \InsetSpace ~
25267 \InsetSpace ~
25268 \InsetSpace ~
25269 \InsetSpace ~
25270 \InsetSpace ~
25271 \InsetSpace ~
25272 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
25273 \end_layout
25274
25275 \begin_layout Standard
25276 Please note that indentations within a 
25277 \family typewriter
25278 Makefile
25279 \family default
25280  have to be done with a tabulator character.
25281 \end_layout
25282
25283 \begin_layout Subsection
25284 Command-Line Options
25285 \end_layout
25286
25287 \begin_layout Standard
25288 Besides the switches common to all SDCC backends, the PIC14 port accepts
25289  the following options (for an updated list see sdcc -
25290 \begin_inset ERT
25291 status collapsed
25292
25293 \begin_layout Standard
25294
25295
25296 \backslash
25297 /
25298 \end_layout
25299
25300 \end_inset
25301
25302 -help):
25303 \end_layout
25304
25305 \begin_layout Description
25306 -
25307 \begin_inset ERT
25308 status collapsed
25309
25310 \begin_layout Standard
25311
25312
25313 \backslash
25314 /
25315 \end_layout
25316
25317 \end_inset
25318
25319 -debug-xtra
25320 \begin_inset LatexCommand index
25321 name "PIC14!Options!-\\/-debug-extra"
25322
25323 \end_inset
25324
25325  emit debug info in assembly output
25326 \end_layout
25327
25328 \begin_layout Description
25329 -
25330 \begin_inset ERT
25331 status collapsed
25332
25333 \begin_layout Standard
25334
25335
25336 \backslash
25337 /
25338 \end_layout
25339
25340 \end_inset
25341
25342 -no-pcode-opt
25343 \begin_inset LatexCommand index
25344 name "PIC14!Options!-\\/-no-pcode-opt"
25345
25346 \end_inset
25347
25348  disable (slightly faulty) optimization on pCode
25349 \end_layout
25350
25351 \begin_layout Description
25352 -
25353 \begin_inset ERT
25354 status collapsed
25355
25356 \begin_layout Standard
25357
25358
25359 \backslash
25360 /
25361 \end_layout
25362
25363 \end_inset
25364
25365 -stack-loc
25366 \begin_inset LatexCommand index
25367 name "PIC14!Options!-\\/-stack-loc"
25368
25369 \end_inset
25370
25371  sets the lowest address of the argument passing stack (defaults to a suitably
25372  large shared databank to reduce BANKSEL overhead)
25373 \end_layout
25374
25375 \begin_layout Description
25376 -
25377 \begin_inset ERT
25378 status collapsed
25379
25380 \begin_layout Standard
25381
25382
25383 \backslash
25384 /
25385 \end_layout
25386
25387 \end_inset
25388
25389 -stack-size
25390 \begin_inset LatexCommand index
25391 name "PIC14!Options!-\\/-stack-size"
25392
25393 \end_inset
25394
25395  sets the size if the argument passing stack (default: 16, minimum: 4)
25396 \end_layout
25397
25398 \begin_layout Subsection
25399 Environment Variables
25400 \end_layout
25401
25402 \begin_layout Standard
25403 The PIC14 port recognizes the following environment variables:
25404 \end_layout
25405
25406 \begin_layout Description
25407 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
25408  register (the ones called r0xNNNN) in a section of its own.
25409  By default (if this variable is unset), sdcc tries to cluster registers
25410  in sections in order to reduce the BANKSEL overhead when accessing them.
25411 \end_layout
25412
25413 \begin_layout Subsection
25414 The Library
25415 \end_layout
25416
25417 \begin_layout Standard
25418 The PIC14 library currently only contains support routines required by the
25419  compiler to implement multiplication, division, and floating point support.
25420  No libc-like replacement is available at the moment, though many of the
25421  common sdcc library sources (in 
25422 \family typewriter
25423 device/lib
25424 \family default
25425 ) should also compile with the PIC14 port.
25426 \end_layout
25427
25428 \begin_layout Subsubsection
25429 error: missing definition for symbol ``__gptrget1''
25430 \end_layout
25431
25432 \begin_layout Standard
25433 The PIC14 port uses library routines to provide more complex operations
25434  like multiplication, division/modulus and (generic) pointer dereferencing.
25435  In order to add these routines to your project, you must link with PIC14's
25436  
25437 \family typewriter
25438 libsdcc.lib
25439 \family default
25440 .
25441  For single source file projects this is done automatically, more complex
25442  projects must add 
25443 \family typewriter
25444 libsdcc.lib
25445 \family default
25446  to the linker's arguments.
25447  Make sure you also add an include path for the library (using the -I switch
25448  to the linker)!
25449 \end_layout
25450
25451 \begin_layout Subsubsection
25452 Processor mismatch in file ``XXX''.
25453 \end_layout
25454
25455 \begin_layout Standard
25456 This warning can usually be ignored due to the very good compatibility amongst
25457  14
25458 \begin_inset ERT
25459 status open
25460
25461 \begin_layout Standard
25462
25463
25464 \backslash
25465 ,
25466 \end_layout
25467
25468 \end_inset
25469
25470 bit PIC
25471 \begin_inset LatexCommand index
25472 name "PIC14"
25473
25474 \end_inset
25475
25476  devices.
25477 \end_layout
25478
25479 \begin_layout Standard
25480 You might also consider recompiling the library for your specific device
25481  by changing the ARCH=p16f877 (default target) entry in 
25482 \family typewriter
25483 device/lib/pic/Makefile.in
25484 \family default
25485  and 
25486 \family typewriter
25487 device/lib/pic/Makefile
25488 \family default
25489  to reflect your device.
25490  This might even improve performance for smaller devices as unnecessary
25491  BANKSELs might be removed.
25492 \end_layout
25493
25494 \begin_layout Subsection
25495 Known Bugs
25496 \end_layout
25497
25498 \begin_layout Subsubsection
25499 Function arguments
25500 \end_layout
25501
25502 \begin_layout Standard
25503 Functions with variable argument lists (like printf) are not yet supported.
25504  Similarly, taking the address of the first argument passed into a function
25505  does not work: It is currently passed in WREG and has no address...
25506 \end_layout
25507
25508 \begin_layout Subsubsection
25509 Regression tests fail
25510 \end_layout
25511
25512 \begin_layout Standard
25513 Though the small subset of regression tests in src/regression passes, SDCC
25514  regression test suite does not, indicating that there are still major bugs
25515  in the port.
25516  However, many smaller projects have successfully used SDCC in the past...
25517 \end_layout
25518
25519 \begin_layout Standard
25520
25521 \size footnotesize
25522
25523 \newpage
25524
25525 \end_layout
25526
25527 \begin_layout Section
25528 The PIC16
25529 \begin_inset LatexCommand index
25530 name "PIC16"
25531
25532 \end_inset
25533
25534  port
25535 \end_layout
25536
25537 \begin_layout Standard
25538 The PIC16 port adds support for Microchip
25539 \begin_inset LatexCommand index
25540 name "Microchip"
25541
25542 \end_inset
25543
25544
25545 \begin_inset Formula $^{\text{TM}}$
25546 \end_inset
25547
25548  PIC
25549 \begin_inset LatexCommand index
25550 name "PIC"
25551
25552 \end_inset
25553
25554
25555 \begin_inset Formula $^{\text{TM}}$
25556 \end_inset
25557
25558  MCUs with 16 bit wide instructions.
25559  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
25560 ; devices supported by the port include:
25561 \end_layout
25562
25563 \begin_layout Standard
25564 18F: 242, 248, 252, 258, 442, 448, 452, 458
25565 \end_layout
25566
25567 \begin_layout Standard
25568 18F: 1220, 1320
25569 \end_layout
25570
25571 \begin_layout Standard
25572 18F: 2220, 2221, 2320, 2321, 2331, 2410, 2420, 2423, 2431, 2450, 2455, 2480,
25573  24j10
25574 \end_layout
25575
25576 \begin_layout Standard
25577 18F: (2510,) 2515, 2520, 2523, 2525, 2550, 2580, 2585, 25j10, 2610, 2620,
25578  2680, 2682, 2685
25579 \end_layout
25580
25581 \begin_layout Standard
25582 18F: 4220, 4221, 4320, 4321, 4331, 4410, 4420, 4423, 4431, 4450, 4455, 4480,
25583  44j10
25584 \end_layout
25585
25586 \begin_layout Standard
25587 18F: 4510, 4515, 4520, 4523, 4525, 4550, 4580, 4585, 45j10, 4610, 4620,
25588  4680, 4682, 4685
25589 \end_layout
25590
25591 \begin_layout Standard
25592 18F: 6520, 6585, 6620, 6680, 66j60, 66j65, 6720, 67j60
25593 \end_layout
25594
25595 \begin_layout Standard
25596 18F: 8520, 8585, 8620, 8680, 86j60, 86j65, 8720, 87j60
25597 \end_layout
25598
25599 \begin_layout Standard
25600 18F: 96j60, 96j65, 97j60
25601 \end_layout
25602
25603 \begin_layout Standard
25604 \noindent
25605 An up-to-date list of supported devices is also available via '
25606 \family typewriter
25607 sdcc -mpic16 -plist
25608 \family default
25609 '.
25610 \end_layout
25611
25612 \begin_layout Subsection
25613 Global Options
25614 \end_layout
25615
25616 \begin_layout Standard
25617 PIC16 port supports the standard command line arguments as supposed, with
25618  the exception of certain cases that will be mentioned in the following
25619  list:
25620 \end_layout
25621
25622 \begin_layout Description
25623 -
25624 \begin_inset ERT
25625 status collapsed
25626
25627 \begin_layout Standard
25628
25629
25630 \backslash
25631 /
25632 \end_layout
25633
25634 \end_inset
25635
25636 -callee-saves
25637 \begin_inset LatexCommand index
25638 name "PIC16!Options!-\\/-callee-saves"
25639
25640 \end_inset
25641
25642  See -
25643 \begin_inset ERT
25644 status collapsed
25645
25646 \begin_layout Standard
25647
25648
25649 \backslash
25650 /
25651 \end_layout
25652
25653 \end_inset
25654
25655 -all-callee-saves
25656 \end_layout
25657
25658 \begin_layout Description
25659 -
25660 \begin_inset ERT
25661 status collapsed
25662
25663 \begin_layout Standard
25664
25665
25666 \backslash
25667 /
25668 \end_layout
25669
25670 \end_inset
25671
25672 -fommit-frame-pointer
25673 \begin_inset LatexCommand index
25674 name "PIC16!Options!-\\/-fommit-frame-pointer"
25675
25676 \end_inset
25677
25678  Frame pointer will be omitted when the function uses no local variables.
25679 \end_layout
25680
25681 \begin_layout Subsection
25682 Port Specific Options
25683 \begin_inset LatexCommand index
25684 name "Options PIC16"
25685
25686 \end_inset
25687
25688
25689 \end_layout
25690
25691 \begin_layout Standard
25692 The port specific options appear after the global options in the sdcc -
25693 \begin_inset ERT
25694 status collapsed
25695
25696 \begin_layout Standard
25697
25698
25699 \backslash
25700 /
25701 \end_layout
25702
25703 \end_inset
25704
25705 -help output.
25706 \end_layout
25707
25708 \begin_layout Subsubsection
25709 Code Generation Options
25710 \end_layout
25711
25712 \begin_layout Standard
25713 These options influence the generated assembler code.
25714 \end_layout
25715
25716 \begin_layout Description
25717 -
25718 \begin_inset ERT
25719 status collapsed
25720
25721 \begin_layout Standard
25722
25723
25724 \backslash
25725 /
25726 \end_layout
25727
25728 \end_inset
25729
25730 -pstack-model=[model] Used in conjunction with the command above.
25731  Defines the stack model to be used, valid stack models are:
25732 \end_layout
25733
25734 \begin_deeper
25735 \begin_layout List
25736 \labelwidthstring 00.00.0000
25737
25738 \emph on
25739 small
25740 \emph default
25741  Selects small stack model.
25742  8 bit stack and frame pointers.
25743  Supports 256 bytes stack size.
25744 \end_layout
25745
25746 \begin_layout List
25747 \labelwidthstring 00.00.0000
25748
25749 \emph on
25750 large
25751 \emph default
25752  Selects large stack model.
25753  16 bit stack and frame pointers.
25754  Supports 65536 bytes stack size.
25755 \end_layout
25756
25757 \end_deeper
25758 \begin_layout Description
25759 -
25760 \begin_inset ERT
25761 status collapsed
25762
25763 \begin_layout Standard
25764
25765
25766 \backslash
25767 /
25768 \end_layout
25769
25770 \end_inset
25771
25772 -pno-banksel Do not generate BANKSEL assembler directives.
25773 \end_layout
25774
25775 \begin_layout Description
25776 -
25777 \begin_inset ERT
25778 status collapsed
25779
25780 \begin_layout Standard
25781
25782
25783 \backslash
25784 /
25785 \end_layout
25786
25787 \end_inset
25788
25789 -extended Enable extended instruction set/literal offset addressing mode.
25790  Use with care!
25791 \end_layout
25792
25793 \begin_layout Subsubsection
25794 Optimization Options
25795 \end_layout
25796
25797 \begin_layout Description
25798 -
25799 \begin_inset ERT
25800 status collapsed
25801
25802 \begin_layout Standard
25803
25804
25805 \backslash
25806 /
25807 \end_layout
25808
25809 \end_inset
25810
25811 -obanksel=n Set optimization level for inserting BANKSELs.
25812 \newline
25813
25814 \end_layout
25815
25816 \begin_deeper
25817 \begin_layout List
25818 \labelwidthstring 00.00.0000
25819 0 no optimization
25820 \end_layout
25821
25822 \begin_layout List
25823 \labelwidthstring 00.00.0000
25824 1 checks previous used register and if it is the same then does not emit
25825  BANKSEL, accounts only for labels.
25826 \end_layout
25827
25828 \begin_layout List
25829 \labelwidthstring 00.00.0000
25830 2 tries to check the location of (even different) symbols and removes BANKSELs
25831  if they are in the same bank.
25832  
25833 \newline
25834
25835 \emph on
25836 Important: There might be problems if the linker script has data sections
25837  across bank borders!
25838 \end_layout
25839
25840 \end_deeper
25841 \begin_layout Description
25842 -
25843 \begin_inset ERT
25844 status collapsed
25845
25846 \begin_layout Standard
25847
25848
25849 \backslash
25850 /
25851 \end_layout
25852
25853 \end_inset
25854
25855 -denable-peeps Force the usage of peepholes.
25856  Use with care.
25857 \end_layout
25858
25859 \begin_layout Description
25860 -
25861 \begin_inset ERT
25862 status collapsed
25863
25864 \begin_layout Standard
25865
25866
25867 \backslash
25868 /
25869 \end_layout
25870
25871 \end_inset
25872
25873 -no-optimize-goto Do not use (conditional) BRA instead of GOTO.
25874 \end_layout
25875
25876 \begin_layout Description
25877 -
25878 \begin_inset ERT
25879 status collapsed
25880
25881 \begin_layout Standard
25882
25883
25884 \backslash
25885 /
25886 \end_layout
25887
25888 \end_inset
25889
25890 -optimize-cmp Try to optimize some compares.
25891 \end_layout
25892
25893 \begin_layout Description
25894 -
25895 \begin_inset ERT
25896 status collapsed
25897
25898 \begin_layout Standard
25899
25900
25901 \backslash
25902 /
25903 \end_layout
25904
25905 \end_inset
25906
25907 -optimize-df Analyze the dataflow of the generated code and improve it.
25908 \end_layout
25909
25910 \begin_layout Subsubsection
25911 Assembling Options
25912 \end_layout
25913
25914 \begin_layout Description
25915 -
25916 \begin_inset ERT
25917 status collapsed
25918
25919 \begin_layout Standard
25920
25921
25922 \backslash
25923 /
25924 \end_layout
25925
25926 \end_inset
25927
25928 -asm= Sets the full path and name of an external assembler to call.
25929 \end_layout
25930
25931 \begin_layout Description
25932 -
25933 \begin_inset ERT
25934 status collapsed
25935
25936 \begin_layout Standard
25937
25938
25939 \backslash
25940 /
25941 \end_layout
25942
25943 \end_inset
25944
25945 -mplab-comp MPLAB
25946 \begin_inset LatexCommand index
25947 name "PIC16!MPLAB"
25948
25949 \end_inset
25950
25951  compatibility option.
25952  Currently only suppresses special gpasm directives.
25953 \end_layout
25954
25955 \begin_layout Subsubsection
25956 Linking Options
25957 \end_layout
25958
25959 \begin_layout Description
25960 -
25961 \begin_inset ERT
25962 status collapsed
25963
25964 \begin_layout Standard
25965
25966
25967 \backslash
25968 /
25969 \end_layout
25970
25971 \end_inset
25972
25973 -link= Sets the full path and name of an external linker to call.
25974 \end_layout
25975
25976 \begin_layout Description
25977 -
25978 \begin_inset ERT
25979 status collapsed
25980
25981 \begin_layout Standard
25982
25983
25984 \backslash
25985 /
25986 \end_layout
25987
25988 \end_inset
25989
25990 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
25991  unitialized data variables with [kword].
25992  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
25993 \end_layout
25994
25995 \begin_layout Description
25996 -
25997 \begin_inset ERT
25998 status collapsed
25999
26000 \begin_layout Standard
26001
26002
26003 \backslash
26004 /
26005 \end_layout
26006
26007 \end_inset
26008
26009 -ivt-loc=n Place the interrupt vector table at address 
26010 \emph on
26011 n
26012 \emph default
26013 .
26014  Useful for bootloaders.
26015 \end_layout
26016
26017 \begin_layout Description
26018 -
26019 \begin_inset ERT
26020 status collapsed
26021
26022 \begin_layout Standard
26023
26024
26025 \backslash
26026 /
26027 \end_layout
26028
26029 \end_inset
26030
26031 -nodefaultlibs Do not link default libraries when linking.
26032 \end_layout
26033
26034 \begin_layout Description
26035 -
26036 \begin_inset ERT
26037 status collapsed
26038
26039 \begin_layout Standard
26040
26041
26042 \backslash
26043 /
26044 \end_layout
26045
26046 \end_inset
26047
26048 -use-crt= Use a custom run-time module instead of the defaults.
26049 \end_layout
26050
26051 \begin_layout Description
26052 -
26053 \begin_inset ERT
26054 status collapsed
26055
26056 \begin_layout Standard
26057
26058
26059 \backslash
26060 /
26061 \end_layout
26062
26063 \end_inset
26064
26065 -no-crt Don't link the default run-time modules
26066 \end_layout
26067
26068 \begin_layout Subsubsection
26069 Debugging Options
26070 \end_layout
26071
26072 \begin_layout Standard
26073 Debugging options enable extra debugging information in the output files.
26074 \end_layout
26075
26076 \begin_layout Description
26077 -
26078 \begin_inset ERT
26079 status collapsed
26080
26081 \begin_layout Standard
26082
26083
26084 \backslash
26085 /
26086 \end_layout
26087
26088 \end_inset
26089
26090 -debug-xtra Similar to -
26091 \begin_inset ERT
26092 status collapsed
26093
26094 \begin_layout Standard
26095
26096
26097 \backslash
26098 /
26099 \end_layout
26100
26101 \end_inset
26102
26103 -debug
26104 \begin_inset LatexCommand index
26105 name "-\\/-debug"
26106
26107 \end_inset
26108
26109 , but dumps more information.
26110 \end_layout
26111
26112 \begin_layout Description
26113 -
26114 \begin_inset ERT
26115 status collapsed
26116
26117 \begin_layout Standard
26118
26119
26120 \backslash
26121 /
26122 \end_layout
26123
26124 \end_inset
26125
26126 -debug-ralloc Force register allocator to dump <source>.d file with debugging
26127  information.
26128  <source> is the name of the file being compiled.
26129 \end_layout
26130
26131 \begin_layout Description
26132 -
26133 \begin_inset ERT
26134 status collapsed
26135
26136 \begin_layout Standard
26137
26138
26139 \backslash
26140 /
26141 \end_layout
26142
26143 \end_inset
26144
26145 -pcode-verbose Enable pcode debugging information in translation.
26146 \end_layout
26147
26148 \begin_layout Description
26149 -
26150 \begin_inset ERT
26151 status collapsed
26152
26153 \begin_layout Standard
26154
26155
26156 \backslash
26157 /
26158 \end_layout
26159
26160 \end_inset
26161
26162 -calltree Dump call tree in .calltree file.
26163 \end_layout
26164
26165 \begin_layout Description
26166 -
26167 \begin_inset ERT
26168 status collapsed
26169
26170 \begin_layout Standard
26171
26172
26173 \backslash
26174 /
26175 \end_layout
26176
26177 \end_inset
26178
26179 -gstack Trace push/pops for stack pointer overflow.
26180 \end_layout
26181
26182 \begin_layout Subsection
26183 Environment Variables
26184 \end_layout
26185
26186 \begin_layout Standard
26187 There is a number of environmental variables that can be used when running
26188  SDCC to enable certain optimizations or force a specific program behaviour.
26189  these variables are primarily for debugging purposes so they can be enabled/dis
26190 abled at will.
26191 \end_layout
26192
26193 \begin_layout Standard
26194 Currently there is only two such variables available:
26195 \end_layout
26196
26197 \begin_layout Description
26198 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
26199  bitfields is optimized by directly loading FSR0 with the address of the
26200  bitfield structure.
26201  Normally SDCC will cast the bitfield structure to a bitfield pointer and
26202  then load FSR0.
26203  This step saves data ram and code space for functions that make heavy use
26204  of bitfields.
26205  (i.e., 80 bytes of code space are saved when compiling malloc.c with this
26206  option).
26207  
26208 \end_layout
26209
26210 \begin_layout Description
26211 NO_REG_OPT Do not perform pCode registers optimization.
26212  This should be used for debugging purposes.
26213  If bugs in the pcode optimizer are found, users can benefit from temporarily
26214  disabling the optimizer until the bug is fixed.
26215 \end_layout
26216
26217 \begin_layout Subsection
26218 Preprocessor Macros
26219 \end_layout
26220
26221 \begin_layout Standard
26222 PIC16
26223 \begin_inset LatexCommand index
26224 name "PIC16"
26225
26226 \end_inset
26227
26228  port defines the following preprocessor macros while translating a source.
26229 \end_layout
26230
26231 \begin_layout Standard
26232 \align center
26233 \begin_inset Tabular
26234 <lyxtabular version="3" rows="6" columns="2">
26235 <features>
26236 <column alignment="center" valignment="top" leftline="true" width="0">
26237 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26238 <row topline="true" bottomline="true">
26239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26240 \begin_inset Text
26241
26242 \begin_layout Standard
26243 Macro
26244 \end_layout
26245
26246 \end_inset
26247 </cell>
26248 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26249 \begin_inset Text
26250
26251 \begin_layout Standard
26252 Description
26253 \end_layout
26254
26255 \end_inset
26256 </cell>
26257 </row>
26258 <row topline="true">
26259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26260 \begin_inset Text
26261
26262 \begin_layout Standard
26263 SDCC_pic16
26264 \end_layout
26265
26266 \end_inset
26267 </cell>
26268 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26269 \begin_inset Text
26270
26271 \begin_layout Standard
26272 Port identification
26273 \end_layout
26274
26275 \end_inset
26276 </cell>
26277 </row>
26278 <row topline="true">
26279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26280 \begin_inset Text
26281
26282 \begin_layout Standard
26283 _
26284 \begin_inset ERT
26285 status collapsed
26286
26287 \begin_layout Standard
26288
26289
26290 \backslash
26291 /
26292 \end_layout
26293
26294 \end_inset
26295
26296 _pic16
26297 \end_layout
26298
26299 \end_inset
26300 </cell>
26301 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26302 \begin_inset Text
26303
26304 \begin_layout Standard
26305 Port identification (same as above)
26306 \end_layout
26307
26308 \end_inset
26309 </cell>
26310 </row>
26311 <row topline="true">
26312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26313 \begin_inset Text
26314
26315 \begin_layout Standard
26316 pic18fxxxx
26317 \end_layout
26318
26319 \end_inset
26320 </cell>
26321 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26322 \begin_inset Text
26323
26324 \begin_layout Standard
26325 MCU Identification.
26326  
26327 \emph on
26328 xxxx
26329 \emph default
26330  is the microcontrol identification number, i.e.
26331  452, 6620, etc
26332 \end_layout
26333
26334 \end_inset
26335 </cell>
26336 </row>
26337 <row topline="true">
26338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26339 \begin_inset Text
26340
26341 \begin_layout Standard
26342 _
26343 \begin_inset ERT
26344 status collapsed
26345
26346 \begin_layout Standard
26347
26348
26349 \backslash
26350 /
26351 \end_layout
26352
26353 \end_inset
26354
26355 _18Fxxxx
26356 \end_layout
26357
26358 \end_inset
26359 </cell>
26360 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26361 \begin_inset Text
26362
26363 \begin_layout Standard
26364 MCU Identification (same as above)
26365 \end_layout
26366
26367 \end_inset
26368 </cell>
26369 </row>
26370 <row topline="true" bottomline="true">
26371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26372 \begin_inset Text
26373
26374 \begin_layout Standard
26375 STACK_MODEL_nnn
26376 \end_layout
26377
26378 \end_inset
26379 </cell>
26380 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26381 \begin_inset Text
26382
26383 \begin_layout Standard
26384 nnn = SMALL or LARGE respectively according to the stack model used
26385 \end_layout
26386
26387 \end_inset
26388 </cell>
26389 </row>
26390 </lyxtabular>
26391
26392 \end_inset
26393
26394
26395 \end_layout
26396
26397 \begin_layout Standard
26398 \noindent
26399 In addition the following macros are defined when calling assembler:
26400 \end_layout
26401
26402 \begin_layout Standard
26403 \align center
26404 \begin_inset Tabular
26405 <lyxtabular version="3" rows="4" columns="2">
26406 <features>
26407 <column alignment="center" valignment="top" leftline="true" width="0">
26408 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26409 <row topline="true" bottomline="true">
26410 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26411 \begin_inset Text
26412
26413 \begin_layout Standard
26414 Macro
26415 \end_layout
26416
26417 \end_inset
26418 </cell>
26419 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26420 \begin_inset Text
26421
26422 \begin_layout Standard
26423 Description
26424 \end_layout
26425
26426 \end_inset
26427 </cell>
26428 </row>
26429 <row topline="true">
26430 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26431 \begin_inset Text
26432
26433 \begin_layout Standard
26434 __18Fxxxx
26435 \end_layout
26436
26437 \end_inset
26438 </cell>
26439 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26440 \begin_inset Text
26441
26442 \begin_layout Standard
26443 MCU Identification.
26444  
26445 \emph on
26446 xxxx
26447 \emph default
26448  is the microcontrol identification number, i.e.
26449  452, 6620, etc
26450 \end_layout
26451
26452 \end_inset
26453 </cell>
26454 </row>
26455 <row topline="true">
26456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26457 \begin_inset Text
26458
26459 \begin_layout Standard
26460 SDCC_MODEL_nnn
26461 \end_layout
26462
26463 \end_inset
26464 </cell>
26465 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26466 \begin_inset Text
26467
26468 \begin_layout Standard
26469 nnn = SMALL or LARGE respectively according to the memory model used for
26470  SDCC
26471 \end_layout
26472
26473 \end_inset
26474 </cell>
26475 </row>
26476 <row topline="true" bottomline="true">
26477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26478 \begin_inset Text
26479
26480 \begin_layout Standard
26481 STACK_MODEL_nnn
26482 \end_layout
26483
26484 \end_inset
26485 </cell>
26486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26487 \begin_inset Text
26488
26489 \begin_layout Standard
26490 nnn = SMALL or LARGE respectively according to the stack model used
26491 \end_layout
26492
26493 \end_inset
26494 </cell>
26495 </row>
26496 </lyxtabular>
26497
26498 \end_inset
26499
26500
26501 \end_layout
26502
26503 \begin_layout Subsection
26504 Directories
26505 \end_layout
26506
26507 \begin_layout Standard
26508 PIC16
26509 \begin_inset LatexCommand index
26510 name "PIC16"
26511
26512 \end_inset
26513
26514  port uses the following directories for searching header files and libraries.
26515 \end_layout
26516
26517 \begin_layout Standard
26518 \align center
26519 \begin_inset Tabular
26520 <lyxtabular version="3" rows="3" columns="4">
26521 <features>
26522 <column alignment="center" valignment="top" leftline="true" width="0">
26523 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26524 <column alignment="center" valignment="top" width="0">
26525 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26526 <row topline="true" bottomline="true">
26527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26528 \begin_inset Text
26529
26530 \begin_layout Standard
26531 Directory
26532 \end_layout
26533
26534 \end_inset
26535 </cell>
26536 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26537 \begin_inset Text
26538
26539 \begin_layout Standard
26540 Description
26541 \end_layout
26542
26543 \end_inset
26544 </cell>
26545 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26546 \begin_inset Text
26547
26548 \begin_layout Standard
26549 Target
26550 \end_layout
26551
26552 \end_inset
26553 </cell>
26554 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26555 \begin_inset Text
26556
26557 \begin_layout Standard
26558 Command prefix
26559 \end_layout
26560
26561 \end_inset
26562 </cell>
26563 </row>
26564 <row topline="true">
26565 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26566 \begin_inset Text
26567
26568 \begin_layout Standard
26569 PREFIX/sdcc/include/pic16
26570 \end_layout
26571
26572 \end_inset
26573 </cell>
26574 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26575 \begin_inset Text
26576
26577 \begin_layout Standard
26578 PIC16 specific headers
26579 \end_layout
26580
26581 \end_inset
26582 </cell>
26583 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26584 \begin_inset Text
26585
26586 \begin_layout Standard
26587 Compiler
26588 \end_layout
26589
26590 \end_inset
26591 </cell>
26592 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26593 \begin_inset Text
26594
26595 \begin_layout Standard
26596 -I
26597 \end_layout
26598
26599 \end_inset
26600 </cell>
26601 </row>
26602 <row topline="true" bottomline="true">
26603 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26604 \begin_inset Text
26605
26606 \begin_layout Standard
26607 PREFIX/sdcc/lib/pic16
26608 \end_layout
26609
26610 \end_inset
26611 </cell>
26612 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26613 \begin_inset Text
26614
26615 \begin_layout Standard
26616 PIC16 specific libraries
26617 \end_layout
26618
26619 \end_inset
26620 </cell>
26621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26622 \begin_inset Text
26623
26624 \begin_layout Standard
26625 Linker
26626 \end_layout
26627
26628 \end_inset
26629 </cell>
26630 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26631 \begin_inset Text
26632
26633 \begin_layout Standard
26634 -L
26635 \end_layout
26636
26637 \end_inset
26638 </cell>
26639 </row>
26640 </lyxtabular>
26641
26642 \end_inset
26643
26644
26645 \end_layout
26646
26647 \begin_layout Subsection
26648 Pragmas
26649 \begin_inset LatexCommand label
26650 name "sub:PIC16_Pragmas"
26651
26652 \end_inset
26653
26654
26655 \end_layout
26656
26657 \begin_layout Standard
26658 The PIC16
26659 \begin_inset LatexCommand index
26660 name "PIC16"
26661
26662 \end_inset
26663
26664  port currently supports the following pragmas:
26665 \end_layout
26666
26667 \begin_layout Description
26668 stack
26669 \begin_inset LatexCommand index
26670 name "PIC16!Pragmas!\\#pragma stack"
26671
26672 \end_inset
26673
26674  This forces the code generator to initialize the stack & frame pointers
26675  at a specific address.
26676  This is an ad hoc solution for cases where no STACK directive is available
26677  in the linker script or gplink is not instructed to create a stack section.
26678 \newline
26679 The
26680  stack pragma should be used only once in a project.
26681  Multiple pragmas may result in indeterminate behaviour of the program.
26682 \begin_inset Foot
26683 status open
26684
26685 \begin_layout Standard
26686 The old format (ie.
26687  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
26688  cross page boundaries (or even exceed the available data RAM) and crash
26689  the program.
26690  Make sure that stack does not cross page boundaries when using the SMALL
26691  stack model.
26692 \end_layout
26693
26694 \end_inset
26695
26696
26697 \newline
26698 The format is as follows:
26699 \newline
26700
26701 \end_layout
26702
26703 \begin_layout LyX-Code
26704 #pragma stack bottom_address [stack_size]
26705 \newline
26706
26707 \end_layout
26708
26709 \begin_layout Standard
26710
26711 \emph on
26712 bottom_address
26713 \emph default
26714  is the lower bound of the stack section.
26715  The stack pointer initially will point at address (bottom_address+stack_size-1).
26716 \end_layout
26717
26718 \begin_layout LyX-Code
26719 Example:
26720 \end_layout
26721
26722 \begin_layout LyX-Code
26723
26724 \end_layout
26725
26726 \begin_layout LyX-Code
26727 /* initializes stack of 100 bytes at RAM address 0x200 */
26728 \end_layout
26729
26730 \begin_layout LyX-Code
26731 #pragma stack 0x200 100
26732 \end_layout
26733
26734 \begin_layout Standard
26735 If the stack_size field is omitted then a stack is created with the default
26736  size of 64.
26737  This size might be enough for most programs, but its not enough for operations
26738  with deep function nesting or excessive stack usage.
26739 \end_layout
26740
26741 \begin_layout Description
26742 code
26743 \begin_inset LatexCommand index
26744 name "PIC16!Pragmas!\\#pragma code"
26745
26746 \end_inset
26747
26748  Force a function to a static FLASH address.
26749 \end_layout
26750
26751 \begin_layout LyX-Code
26752 Example:
26753 \end_layout
26754
26755 \begin_layout LyX-Code
26756
26757 \end_layout
26758
26759 \begin_layout LyX-Code
26760 /* place function test_func at 0x4000 */
26761 \end_layout
26762
26763 \begin_layout LyX-Code
26764 #pragma code test_func 0x4000
26765 \end_layout
26766
26767 \begin_layout LyX-Code
26768
26769 \end_layout
26770
26771 \begin_layout Description
26772 library instructs the linker to use a library module.
26773 \newline
26774 Usage:
26775 \end_layout
26776
26777 \begin_layout LyX-Code
26778 #pragma library module_name
26779 \end_layout
26780
26781 \begin_layout Standard
26782
26783 \emph on
26784 module_name
26785 \emph default
26786  can be any library or object file (including its path).
26787  Note that there are four reserved keywords which have special meaning.
26788  These are:
26789 \end_layout
26790
26791 \begin_layout Standard
26792 \align center
26793 \begin_inset Tabular
26794 <lyxtabular version="3" rows="6" columns="3">
26795 <features>
26796 <column alignment="center" valignment="top" leftline="true" width="0">
26797 <column alignment="block" valignment="top" leftline="true" width="20page%">
26798 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
26799 <row topline="true" bottomline="true">
26800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26801 \begin_inset Text
26802
26803 \begin_layout Standard
26804 Keyword
26805 \end_layout
26806
26807 \end_inset
26808 </cell>
26809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26810 \begin_inset Text
26811
26812 \begin_layout Standard
26813 Description
26814 \end_layout
26815
26816 \end_inset
26817 </cell>
26818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26819 \begin_inset Text
26820
26821 \begin_layout Standard
26822 Module to link
26823 \end_layout
26824
26825 \end_inset
26826 </cell>
26827 </row>
26828 <row topline="true">
26829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26830 \begin_inset Text
26831
26832 \begin_layout Standard
26833
26834 \series bold
26835 ignore
26836 \end_layout
26837
26838 \end_inset
26839 </cell>
26840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26841 \begin_inset Text
26842
26843 \begin_layout Standard
26844 ignore all library pragmas
26845 \end_layout
26846
26847 \end_inset
26848 </cell>
26849 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26850 \begin_inset Text
26851
26852 \begin_layout Standard
26853
26854 \emph on
26855 (none)
26856 \end_layout
26857
26858 \end_inset
26859 </cell>
26860 </row>
26861 <row topline="true">
26862 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26863 \begin_inset Text
26864
26865 \begin_layout Standard
26866
26867 \series bold
26868 c
26869 \end_layout
26870
26871 \end_inset
26872 </cell>
26873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26874 \begin_inset Text
26875
26876 \begin_layout Standard
26877 link the C library
26878 \end_layout
26879
26880 \end_inset
26881 </cell>
26882 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26883 \begin_inset Text
26884
26885 \begin_layout Standard
26886
26887 \emph on
26888 libc18f
26889 \emph default
26890 .lib
26891 \end_layout
26892
26893 \end_inset
26894 </cell>
26895 </row>
26896 <row topline="true">
26897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26898 \begin_inset Text
26899
26900 \begin_layout Standard
26901
26902 \series bold
26903 math
26904 \end_layout
26905
26906 \end_inset
26907 </cell>
26908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26909 \begin_inset Text
26910
26911 \begin_layout Standard
26912 link the Math libarary
26913 \end_layout
26914
26915 \end_inset
26916 </cell>
26917 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26918 \begin_inset Text
26919
26920 \begin_layout Standard
26921
26922 \emph on
26923 libm18f
26924 \emph default
26925 .lib
26926 \end_layout
26927
26928 \end_inset
26929 </cell>
26930 </row>
26931 <row topline="true">
26932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26933 \begin_inset Text
26934
26935 \begin_layout Standard
26936
26937 \series bold
26938 io
26939 \end_layout
26940
26941 \end_inset
26942 </cell>
26943 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26944 \begin_inset Text
26945
26946 \begin_layout Standard
26947 link the I/O library
26948 \end_layout
26949
26950 \end_inset
26951 </cell>
26952 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26953 \begin_inset Text
26954
26955 \begin_layout Standard
26956
26957 \emph on
26958 libio18f*
26959 \emph default
26960 .lib
26961 \end_layout
26962
26963 \end_inset
26964 </cell>
26965 </row>
26966 <row topline="true" bottomline="true">
26967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26968 \begin_inset Text
26969
26970 \begin_layout Standard
26971
26972 \series bold
26973 debug
26974 \end_layout
26975
26976 \end_inset
26977 </cell>
26978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26979 \begin_inset Text
26980
26981 \begin_layout Standard
26982 link the debug library
26983 \end_layout
26984
26985 \end_inset
26986 </cell>
26987 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26988 \begin_inset Text
26989
26990 \begin_layout Standard
26991
26992 \emph on
26993 libdebug
26994 \emph default
26995 .lib
26996 \end_layout
26997
26998 \end_inset
26999 </cell>
27000 </row>
27001 </lyxtabular>
27002
27003 \end_inset
27004
27005
27006 \newline
27007 * is the device number, i.e.
27008  452 for PIC18F452 MCU.
27009 \end_layout
27010
27011 \begin_layout Standard
27012 \noindent
27013 This feature allows for linking with specific libraries without having to
27014  explicit name them in the command line.
27015  Note that the 
27016 \noun on
27017 ignore
27018 \noun default
27019  keyword will reject all modules specified by the library pragma.
27020 \end_layout
27021
27022 \begin_layout Description
27023 udata The pragma udata instructs the compiler to emit code so that linker
27024  will place a variable at a specific memory bank.
27025 \end_layout
27026
27027 \begin_layout LyX-Code
27028 Example:
27029 \end_layout
27030
27031 \begin_layout LyX-Code
27032
27033 \end_layout
27034
27035 \begin_layout LyX-Code
27036 /* places variable foo at bank2 */
27037 \end_layout
27038
27039 \begin_layout LyX-Code
27040 #pragma udata bank2 foo
27041 \end_layout
27042
27043 \begin_layout LyX-Code
27044 char foo;
27045 \end_layout
27046
27047 \begin_layout Standard
27048 In order for this pragma to work extra SECTION directives should be added
27049  in the .lkr script.
27050  In the following example a sample .lkr file is shown:
27051 \end_layout
27052
27053 \begin_layout LyX-Code
27054
27055 \end_layout
27056
27057 \begin_layout LyX-Code
27058 // Sample linker script for the PIC18F452 processor
27059 \end_layout
27060
27061 \begin_layout LyX-Code
27062 LIBPATH .
27063 \end_layout
27064
27065 \begin_layout LyX-Code
27066 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
27067 \end_layout
27068
27069 \begin_layout LyX-Code
27070 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
27071 \end_layout
27072
27073 \begin_layout LyX-Code
27074 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
27075 \end_layout
27076
27077 \begin_layout LyX-Code
27078 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
27079 \end_layout
27080
27081 \begin_layout LyX-Code
27082 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
27083 \end_layout
27084
27085 \begin_layout LyX-Code
27086 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
27087 \end_layout
27088
27089 \begin_layout LyX-Code
27090 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
27091 \end_layout
27092
27093 \begin_layout LyX-Code
27094
27095 \end_layout
27096
27097 \begin_layout LyX-Code
27098 DATABANK   NAME=gpr0       START=0x80           END=0xFF
27099 \end_layout
27100
27101 \begin_layout LyX-Code
27102 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
27103 \end_layout
27104
27105 \begin_layout LyX-Code
27106 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
27107 \end_layout
27108
27109 \begin_layout LyX-Code
27110 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
27111 \end_layout
27112
27113 \begin_layout LyX-Code
27114 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
27115 \end_layout
27116
27117 \begin_layout LyX-Code
27118 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
27119 \end_layout
27120
27121 \begin_layout LyX-Code
27122 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
27123 \end_layout
27124
27125 \begin_layout LyX-Code
27126
27127 \end_layout
27128
27129 \begin_layout LyX-Code
27130 SECTION    NAME=CONFIG     ROM=config
27131 \end_layout
27132
27133 \begin_layout LyX-Code
27134
27135 \end_layout
27136
27137 \begin_layout LyX-Code
27138 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
27139 \end_layout
27140
27141 \begin_layout LyX-Code
27142 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
27143 \end_layout
27144
27145 \begin_layout LyX-Code
27146 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
27147 \end_layout
27148
27149 \begin_layout LyX-Code
27150 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
27151 \end_layout
27152
27153 \begin_layout LyX-Code
27154 SECTION    NAME=bank4      RAM=gpr4
27155 \end_layout
27156
27157 \begin_layout LyX-Code
27158 SECTION    NAME=bank5      RAM=gpr5
27159 \end_layout
27160
27161 \begin_layout Standard
27162 The linker will recognise the section name set in the pragma statement and
27163  will position the variable at the memory bank set with the RAM field at
27164  the SECTION line in the linker script file.
27165 \end_layout
27166
27167 \begin_layout Subsection
27168 Header Files
27169 \begin_inset LatexCommand label
27170 name "sub:PIC16_Header-Files"
27171
27172 \end_inset
27173
27174
27175 \end_layout
27176
27177 \begin_layout Standard
27178 There is one main header file
27179 \begin_inset LatexCommand index
27180 name "PIC16!Header files"
27181
27182 \end_inset
27183
27184  that can be included to the source files using the pic16
27185 \begin_inset LatexCommand index
27186 name "PIC16"
27187
27188 \end_inset
27189
27190  port.
27191  That file is the 
27192 \series bold
27193 pic18fregs.h
27194 \series default
27195 .
27196  This header file contains the definitions for the processor special registers,
27197  so it is necessary if the source accesses them.
27198  It can be included by adding the following line in the beginning of the
27199  file:
27200 \end_layout
27201
27202 \begin_layout LyX-Code
27203 #include <pic18fregs.h>
27204 \end_layout
27205
27206 \begin_layout Standard
27207 The specific microcontroller is selected within the pic18fregs.h automatically,
27208  so the same source can be used with a variety of devices.
27209 \end_layout
27210
27211 \begin_layout Subsection
27212 Libraries
27213 \begin_inset LatexCommand label
27214 name "sub:pic16Libraries"
27215
27216 \end_inset
27217
27218
27219 \end_layout
27220
27221 \begin_layout Standard
27222 The libraries
27223 \begin_inset LatexCommand index
27224 name "PIC16!Libraries"
27225
27226 \end_inset
27227
27228  that PIC16
27229 \begin_inset LatexCommand index
27230 name "PIC16"
27231
27232 \end_inset
27233
27234  port depends on are the microcontroller device libraries which contain
27235  the symbol definitions for the microcontroller special function registers.
27236  These libraries have the format pic18fxxxx.lib, where 
27237 \emph on
27238 xxxx
27239 \emph default
27240  is the microcontroller identification number.
27241  The specific library is selected automatically by the compiler at link
27242  stage according to the selected device.
27243 \end_layout
27244
27245 \begin_layout Standard
27246 \noindent
27247 Libraries are created with gplib which is part of the gputils package 
27248 \begin_inset LatexCommand url
27249 target "http://sourceforge.net/projects/gputils"
27250
27251 \end_inset
27252
27253 .
27254 \end_layout
27255
27256 \begin_layout Subsubsection*
27257 Building the libraries
27258 \end_layout
27259
27260 \begin_layout Standard
27261 Before using SDCC/pic16 there are some libraries that need to be compiled.
27262  This process is done automatically if gputils are found at SDCC's compile
27263  time.
27264  Should you require to rebuild the pic16 libraries manually (e.g.
27265  in order to enable output of float values
27266 \begin_inset LatexCommand index
27267 name "Floating point support"
27268
27269 \end_inset
27270
27271  via 
27272 \family typewriter
27273 printf()
27274 \family default
27275 , see below), these are the steps required to do so under Linux or Mac OS
27276  X (cygwin might work as well, but is untested):
27277 \end_layout
27278
27279 \begin_layout LyX-Code
27280 cd device/lib/pic16
27281 \end_layout
27282
27283 \begin_layout LyX-Code
27284 ./configure.gnu
27285 \end_layout
27286
27287 \begin_layout LyX-Code
27288 cd ..
27289 \end_layout
27290
27291 \begin_layout LyX-Code
27292 make model-pic16
27293 \end_layout
27294
27295 \begin_layout LyX-Code
27296 su -c 'make install'     # install the libraries, you need the root password
27297 \end_layout
27298
27299 \begin_layout LyX-Code
27300 cd ../..
27301 \end_layout
27302
27303 \begin_layout Standard
27304 If you need to install the headers too, do:
27305 \end_layout
27306
27307 \begin_layout LyX-Code
27308 cd device/include
27309 \end_layout
27310
27311 \begin_layout LyX-Code
27312 su -c 'make install'     # install the headers, you need the root password
27313 \end_layout
27314
27315 \begin_layout Subsubsection*
27316 Output of float values via printf()
27317 \end_layout
27318
27319 \begin_layout Standard
27320 The library is normally built without support for displaying float values,
27321  only <NO FLOAT> will appear instead of the value.
27322  To change this, rebuild the library as stated above, but call 
27323 \family typewriter
27324 ./configure.gnu --enable-floats 
27325 \family default
27326 instead of just 
27327 \family typewriter
27328 ./configure.gnu
27329 \family default
27330 .
27331  Also make sure that at least 
27332 \family typewriter
27333 libc/stdio/vfprintf.c
27334 \family default
27335  is actually recompiled, e.g.
27336  by 
27337 \family typewriter
27338 touch
27339 \family default
27340 ing it after the 
27341 \family typewriter
27342 configure
27343 \family default
27344  run or deleting its 
27345 \family typewriter
27346 .o
27347 \family default
27348  file.
27349 \end_layout
27350
27351 \begin_layout Standard
27352 The more common appraoch of compiling 
27353 \family typewriter
27354 vfprintf.c
27355 \family default
27356  manually with 
27357 \family typewriter
27358 -DUSE_FLOATS=1
27359 \family default
27360  should also work, but is untested.
27361 \end_layout
27362
27363 \begin_layout Subsection
27364 Adding New Devices to the Port
27365 \end_layout
27366
27367 \begin_layout Standard
27368 Adding support for a new 16
27369 \begin_inset ERT
27370 status collapsed
27371
27372 \begin_layout Standard
27373
27374
27375 \backslash
27376 ,
27377 \end_layout
27378
27379 \end_inset
27380
27381 bit PIC MCU requires the following steps:
27382 \end_layout
27383
27384 \begin_layout Enumerate
27385 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
27386 \newline
27387
27388 \family typewriter
27389 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
27390 inc
27391 \end_layout
27392
27393 \begin_layout Enumerate
27394
27395 \family typewriter
27396 mv picDEVICE.h /path/to/sdcc/device/include/pic16
27397 \end_layout
27398
27399 \begin_layout Enumerate
27400
27401 \family typewriter
27402 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
27403 \end_layout
27404
27405 \begin_layout Enumerate
27406 Add DEVICE to 
27407 \family typewriter
27408 /path/to/sdcc/device/lib/pic16/pics.all
27409 \family default
27410
27411 \newline
27412 Note: No 18f prefix here!
27413 \end_layout
27414
27415 \begin_layout Enumerate
27416 Edit 
27417 \family typewriter
27418 /path/to/sdcc/device/include/pic16/adc.h
27419 \newline
27420
27421 \family default
27422 Add the new devices to the correct ADC style class (depending on the number
27423  of ADC channels).
27424 \newline
27425 Do not touch 
27426 \family typewriter
27427 adc.h
27428 \family default
27429  if the device does not offer any ADC at all.
27430 \end_layout
27431
27432 \begin_layout Enumerate
27433 Edit 
27434 \family typewriter
27435 /path/to/sdcc/device/include/pic16/pic18fregs.h
27436 \family default
27437
27438 \newline
27439 The file format is self-explanatory, just add
27440 \newline
27441
27442 \family typewriter
27443 #elif defined(picDEVICE)
27444 \newline
27445 #
27446 \begin_inset ERT
27447 status collapsed
27448
27449 \begin_layout Standard
27450
27451
27452 \backslash
27453  
27454 \backslash
27455  
27456 \end_layout
27457
27458 \end_inset
27459
27460 include <picDEVICE.h>
27461 \family default
27462
27463 \newline
27464 at the right place (keep the file sorted, please).
27465 \end_layout
27466
27467 \begin_layout Enumerate
27468 Edit 
27469 \family typewriter
27470 /path/to/sdcc/device/include/pic16devices.txt
27471 \newline
27472
27473 \family default
27474 Copy and modify an existing entry or create a new one and insert it at the
27475  correct place (keep the file sorted, please).
27476 \end_layout
27477
27478 \begin_layout Enumerate
27479 Add the device to 
27480 \family typewriter
27481 /path/to/sdcc/device/lib/pic16/libdev/Makefile.am
27482 \family default
27483
27484 \newline
27485 Copy an existing entry and adjust the device name.
27486 \end_layout
27487
27488 \begin_layout Enumerate
27489 Add the device to 
27490 \family typewriter
27491 /path/to/sdcc/device/lib/pic16/libio/Makefile.am
27492 \family default
27493
27494 \newline
27495 Copy the record from the 18f2220 and adjust the device name.
27496 \newline
27497 If the new device
27498  does not offer ADC, I
27499 \begin_inset Formula $^{\text{2}}$
27500 \end_inset
27501
27502 C, and/or (E)USART functionality as assumed by the library, remove the lines
27503  with references to 
27504 \family typewriter
27505 adc/*.c
27506 \family default
27507
27508 \family typewriter
27509 usart/*.c
27510 \family default
27511 , or 
27512 \family typewriter
27513 usart/*.c
27514 \family default
27515 , respectively.
27516 \end_layout
27517
27518 \begin_layout Enumerate
27519 Update 
27520 \family typewriter
27521 libdev/Makefile.in
27522 \family default
27523  and 
27524 \family typewriter
27525 libio/Makefile.in
27526 \family default
27527  using
27528 \newline
27529
27530 \family typewriter
27531 ./bootstrap.sh
27532 \family default
27533
27534 \newline
27535 in 
27536 \family typewriter
27537 /path/to/sdcc/device/lib/pic16
27538 \family default
27539 .
27540 \end_layout
27541
27542 \begin_layout Enumerate
27543 Recompile the pic16 libraries as described in 
27544 \begin_inset LatexCommand ref
27545 reference "sub:pic16Libraries"
27546
27547 \end_inset
27548
27549 .
27550 \end_layout
27551
27552 \begin_layout Subsection
27553 Memory Models
27554 \end_layout
27555
27556 \begin_layout Standard
27557 The following memory models are supported by the PIC16 port:
27558 \end_layout
27559
27560 \begin_layout Itemize
27561 small model
27562 \end_layout
27563
27564 \begin_layout Itemize
27565 large model
27566 \end_layout
27567
27568 \begin_layout Standard
27569 Memory model affects the default size of pointers within the source.
27570  The sizes are shown in the next table:
27571 \end_layout
27572
27573 \begin_layout Standard
27574 \align center
27575 \begin_inset Tabular
27576 <lyxtabular version="3" rows="3" columns="3">
27577 <features>
27578 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27579 <column alignment="center" valignment="top" leftline="true" width="0">
27580 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27581 <row topline="true" bottomline="true">
27582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27583 \begin_inset Text
27584
27585 \begin_layout Standard
27586 Pointer sizes according to memory model
27587 \end_layout
27588
27589 \end_inset
27590 </cell>
27591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27592 \begin_inset Text
27593
27594 \begin_layout Standard
27595 small model
27596 \end_layout
27597
27598 \end_inset
27599 </cell>
27600 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27601 \begin_inset Text
27602
27603 \begin_layout Standard
27604 large model
27605 \end_layout
27606
27607 \end_inset
27608 </cell>
27609 </row>
27610 <row topline="true" bottomline="true">
27611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27612 \begin_inset Text
27613
27614 \begin_layout Standard
27615 code pointers
27616 \end_layout
27617
27618 \end_inset
27619 </cell>
27620 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27621 \begin_inset Text
27622
27623 \begin_layout Standard
27624 16-bits
27625 \end_layout
27626
27627 \end_inset
27628 </cell>
27629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27630 \begin_inset Text
27631
27632 \begin_layout Standard
27633 24-bits
27634 \end_layout
27635
27636 \end_inset
27637 </cell>
27638 </row>
27639 <row topline="true" bottomline="true">
27640 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27641 \begin_inset Text
27642
27643 \begin_layout Standard
27644 data pointers
27645 \end_layout
27646
27647 \end_inset
27648 </cell>
27649 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
27650 \begin_inset Text
27651
27652 \begin_layout Standard
27653 16-bits
27654 \end_layout
27655
27656 \end_inset
27657 </cell>
27658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27659 \begin_inset Text
27660
27661 \begin_layout Standard
27662 16-bits
27663 \end_layout
27664
27665 \end_inset
27666 </cell>
27667 </row>
27668 </lyxtabular>
27669
27670 \end_inset
27671
27672
27673 \end_layout
27674
27675 \begin_layout Standard
27676 It is advisable that all sources within a project are compiled with the
27677  same memory model.
27678  If one wants to override the default memory model, this can be done by
27679  declaring a pointer as 
27680 \series bold
27681 far
27682 \series default
27683  or 
27684 \series bold
27685 near
27686 \series default
27687 .
27688  Far selects large memory model's pointers, while near selects small memory
27689  model's pointers.
27690 \end_layout
27691
27692 \begin_layout Standard
27693 The standard device libraries (see 
27694 \begin_inset LatexCommand ref
27695 reference "sub:PIC16_Header-Files"
27696
27697 \end_inset
27698
27699 ) contain no reference to pointers, so they can be used with both memory
27700  models.
27701 \end_layout
27702
27703 \begin_layout Subsection
27704 Stack
27705 \end_layout
27706
27707 \begin_layout Standard
27708 The stack
27709 \begin_inset LatexCommand index
27710 name "PIC16!stack"
27711
27712 \end_inset
27713
27714  implementation for the PIC16 port uses two indirect registers, FSR1 and
27715  FSR2.
27716 \end_layout
27717
27718 \begin_layout Description
27719 FSR1 is assigned as stack pointer
27720 \end_layout
27721
27722 \begin_layout Description
27723 FSR2 is assigned as frame pointer
27724 \end_layout
27725
27726 \begin_layout Standard
27727 The following stack models are supported by the PIC16 port
27728 \end_layout
27729
27730 \begin_layout Itemize
27731
27732 \noun on
27733 small
27734 \noun default
27735  model
27736 \end_layout
27737
27738 \begin_layout Itemize
27739
27740 \noun on
27741 large
27742 \noun default
27743  model
27744 \end_layout
27745
27746 \begin_layout Standard
27747
27748 \noun on
27749 Small
27750 \noun default
27751  model means that only the FSRxL byte is used to access stack and frame,
27752  while 
27753 \emph on
27754 \noun on
27755 large
27756 \emph default
27757 \noun default
27758  uses both FSRxL and FSRxH registers.
27759  The following table shows the stack/frame pointers sizes according to stack
27760  model and the maximum space they can address:
27761 \end_layout
27762
27763 \begin_layout Standard
27764 \align center
27765 \begin_inset Tabular
27766 <lyxtabular version="3" rows="3" columns="3">
27767 <features>
27768 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27769 <column alignment="center" valignment="top" leftline="true" width="0">
27770 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27771 <row topline="true" bottomline="true">
27772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27773 \begin_inset Text
27774
27775 \begin_layout Standard
27776 Stack & Frame pointer sizes according to stack model
27777 \end_layout
27778
27779 \end_inset
27780 </cell>
27781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27782 \begin_inset Text
27783
27784 \begin_layout Standard
27785 small
27786 \end_layout
27787
27788 \end_inset
27789 </cell>
27790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27791 \begin_inset Text
27792
27793 \begin_layout Standard
27794 large
27795 \end_layout
27796
27797 \end_inset
27798 </cell>
27799 </row>
27800 <row topline="true">
27801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27802 \begin_inset Text
27803
27804 \begin_layout Standard
27805 Stack pointer FSR1
27806 \end_layout
27807
27808 \end_inset
27809 </cell>
27810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27811 \begin_inset Text
27812
27813 \begin_layout Standard
27814 8-bits
27815 \end_layout
27816
27817 \end_inset
27818 </cell>
27819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27820 \begin_inset Text
27821
27822 \begin_layout Standard
27823 16-bits
27824 \end_layout
27825
27826 \end_inset
27827 </cell>
27828 </row>
27829 <row topline="true" bottomline="true">
27830 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27831 \begin_inset Text
27832
27833 \begin_layout Standard
27834 Frame pointer FSR2
27835 \end_layout
27836
27837 \end_inset
27838 </cell>
27839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27840 \begin_inset Text
27841
27842 \begin_layout Standard
27843 8-bits
27844 \end_layout
27845
27846 \end_inset
27847 </cell>
27848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27849 \begin_inset Text
27850
27851 \begin_layout Standard
27852 16-bits
27853 \end_layout
27854
27855 \end_inset
27856 </cell>
27857 </row>
27858 </lyxtabular>
27859
27860 \end_inset
27861
27862
27863 \end_layout
27864
27865 \begin_layout Standard
27866 \noindent
27867
27868 \noun on
27869 Large 
27870 \noun default
27871 stack model is currently not working properly throughout the code generator.
27872  So its use is not advised.
27873  Also there are some other points that need special care:
27874 \newline
27875
27876 \end_layout
27877
27878 \begin_layout Enumerate
27879 Do not create stack sections with size more than one physical bank (that
27880  is 256 bytes)
27881 \end_layout
27882
27883 \begin_layout Enumerate
27884 Stack sections should no cross physical bank limits (i.e.
27885  #pragma stack 0x50 0x100)
27886 \end_layout
27887
27888 \begin_layout Standard
27889 These limitations are caused by the fact that only FSRxL is modified when
27890  using SMALL stack model, so no more than 256 bytes of stack can be used.
27891  This problem will disappear after LARGE model is fully implemented.
27892 \end_layout
27893
27894 \begin_layout Subsection
27895 Functions
27896 \end_layout
27897
27898 \begin_layout Standard
27899 In addition to the standard SDCC function keywords, PIC16
27900 \begin_inset LatexCommand index
27901 name "PIC16"
27902
27903 \end_inset
27904
27905  port makes available two more:
27906 \end_layout
27907
27908 \begin_layout Description
27909 wparam
27910 \begin_inset LatexCommand index
27911 name "PIC16!wparam"
27912
27913 \end_inset
27914
27915  Use the WREG to pass one byte of the first function argument.
27916  This improves speed but you may not use this for functions with arguments
27917  that are called via function pointers, otherwise the first byte of the
27918  first parameter will get lost.
27919  Usage:
27920 \end_layout
27921
27922 \begin_layout LyX-Code
27923 void func_wparam(int a) wparam
27924 \end_layout
27925
27926 \begin_layout LyX-Code
27927 {
27928 \end_layout
27929
27930 \begin_layout LyX-Code
27931     /* WREG hold the lower part of a */
27932 \end_layout
27933
27934 \begin_layout LyX-Code
27935     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
27936  */
27937 \end_layout
27938
27939 \begin_layout LyX-Code
27940 ...
27941 \end_layout
27942
27943 \begin_layout LyX-Code
27944 }
27945 \end_layout
27946
27947 \begin_layout Description
27948 shadowregs
27949 \begin_inset LatexCommand index
27950 name "PIC16!shadowregs"
27951
27952 \end_inset
27953
27954  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
27955  hardware shadow registers which hold the values of WREG, STATUS and BSR
27956  registers.
27957  This can be done by adding the keyword 
27958 \emph on
27959 shadowregs
27960 \emph default
27961  before the 
27962 \emph on
27963 interrupt
27964 \emph default
27965  keyword in the function's header.
27966 \end_layout
27967
27968 \begin_layout LyX-Code
27969 void isr_shadow(void) shadowregs interrupt 1
27970 \end_layout
27971
27972 \begin_layout LyX-Code
27973 {
27974 \end_layout
27975
27976 \begin_layout LyX-Code
27977 ...
27978 \end_layout
27979
27980 \begin_layout LyX-Code
27981 }
27982 \end_layout
27983
27984 \begin_layout Standard
27985
27986 \emph on
27987 shadowregs
27988 \emph default
27989  instructs the code generator not to store/restore WREG, STATUS, BSR when
27990  entering/exiting the ISR.
27991 \end_layout
27992
27993 \begin_layout Subsection
27994 Function return values
27995 \end_layout
27996
27997 \begin_layout Standard
27998 Return values from functions are placed to the appropriate registers following
27999  a modified Microchip policy optimized for SDCC.
28000  The following table shows these registers:
28001 \end_layout
28002
28003 \begin_layout Standard
28004 \align center
28005 \begin_inset Tabular
28006 <lyxtabular version="3" rows="6" columns="2">
28007 <features>
28008 <column alignment="center" valignment="top" leftline="true" width="0">
28009 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28010 <row topline="true" bottomline="true">
28011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28012 \begin_inset Text
28013
28014 \begin_layout Standard
28015 size
28016 \end_layout
28017
28018 \end_inset
28019 </cell>
28020 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28021 \begin_inset Text
28022
28023 \begin_layout Standard
28024 destination register
28025 \end_layout
28026
28027 \end_inset
28028 </cell>
28029 </row>
28030 <row topline="true">
28031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28032 \begin_inset Text
28033
28034 \begin_layout Standard
28035 8 bits
28036 \end_layout
28037
28038 \end_inset
28039 </cell>
28040 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28041 \begin_inset Text
28042
28043 \begin_layout Standard
28044 WREG
28045 \end_layout
28046
28047 \end_inset
28048 </cell>
28049 </row>
28050 <row topline="true">
28051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28052 \begin_inset Text
28053
28054 \begin_layout Standard
28055 16 bits
28056 \end_layout
28057
28058 \end_inset
28059 </cell>
28060 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28061 \begin_inset Text
28062
28063 \begin_layout Standard
28064 PRODL:WREG
28065 \end_layout
28066
28067 \end_inset
28068 </cell>
28069 </row>
28070 <row topline="true">
28071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28072 \begin_inset Text
28073
28074 \begin_layout Standard
28075 24 bits
28076 \end_layout
28077
28078 \end_inset
28079 </cell>
28080 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28081 \begin_inset Text
28082
28083 \begin_layout Standard
28084 PRODH:PRODL:WREG
28085 \end_layout
28086
28087 \end_inset
28088 </cell>
28089 </row>
28090 <row topline="true">
28091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28092 \begin_inset Text
28093
28094 \begin_layout Standard
28095 32 bits
28096 \end_layout
28097
28098 \end_inset
28099 </cell>
28100 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28101 \begin_inset Text
28102
28103 \begin_layout Standard
28104 FSR0L:PRODH:PRODL:WREG
28105 \end_layout
28106
28107 \end_inset
28108 </cell>
28109 </row>
28110 <row topline="true" bottomline="true">
28111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28112 \begin_inset Text
28113
28114 \begin_layout Standard
28115 >32 bits
28116 \end_layout
28117
28118 \end_inset
28119 </cell>
28120 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28121 \begin_inset Text
28122
28123 \begin_layout Standard
28124 on stack, FSR0 points to the beginning
28125 \end_layout
28126
28127 \end_inset
28128 </cell>
28129 </row>
28130 </lyxtabular>
28131
28132 \end_inset
28133
28134
28135 \end_layout
28136
28137 \begin_layout Subsection
28138 Interrupts
28139 \end_layout
28140
28141 \begin_layout Standard
28142 An interrupt
28143 \begin_inset LatexCommand index
28144 name "PIC16!interrupt"
28145
28146 \end_inset
28147
28148  service routine (ISR) is declared using the 
28149 \emph on
28150 interrupt
28151 \emph default
28152  keyword.
28153 \end_layout
28154
28155 \begin_layout LyX-Code
28156 void isr(void) interrupt 
28157 \emph on
28158 n
28159 \end_layout
28160
28161 \begin_layout LyX-Code
28162 {
28163 \end_layout
28164
28165 \begin_layout LyX-Code
28166 ...
28167 \end_layout
28168
28169 \begin_layout LyX-Code
28170 }
28171 \end_layout
28172
28173 \begin_layout Standard
28174
28175 \emph on
28176 n
28177 \emph default
28178  is the interrupt number, which for PIC18F devices can be:
28179 \end_layout
28180
28181 \begin_layout Standard
28182 \align center
28183 \begin_inset Tabular
28184 <lyxtabular version="3" rows="4" columns="3">
28185 <features>
28186 <column alignment="center" valignment="top" leftline="true" width="0">
28187 <column alignment="center" valignment="top" leftline="true" width="0">
28188 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28189 <row topline="true" bottomline="true">
28190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28191 \begin_inset Text
28192
28193 \begin_layout Standard
28194
28195 \emph on
28196 n
28197 \end_layout
28198
28199 \end_inset
28200 </cell>
28201 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28202 \begin_inset Text
28203
28204 \begin_layout Standard
28205 Interrupt Vector
28206 \end_layout
28207
28208 \end_inset
28209 </cell>
28210 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28211 \begin_inset Text
28212
28213 \begin_layout Standard
28214 Interrupt Vector Address
28215 \end_layout
28216
28217 \end_inset
28218 </cell>
28219 </row>
28220 <row topline="true">
28221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28222 \begin_inset Text
28223
28224 \begin_layout Standard
28225 0
28226 \end_layout
28227
28228 \end_inset
28229 </cell>
28230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28231 \begin_inset Text
28232
28233 \begin_layout Standard
28234 RESET vector
28235 \end_layout
28236
28237 \end_inset
28238 </cell>
28239 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28240 \begin_inset Text
28241
28242 \begin_layout Standard
28243 0x000000
28244 \end_layout
28245
28246 \end_inset
28247 </cell>
28248 </row>
28249 <row topline="true">
28250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28251 \begin_inset Text
28252
28253 \begin_layout Standard
28254
28255 \family roman
28256 \series medium
28257 \shape up
28258 \size normal
28259 \emph off
28260 \bar no
28261 \noun off
28262 \color none
28263 1
28264 \end_layout
28265
28266 \end_inset
28267 </cell>
28268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28269 \begin_inset Text
28270
28271 \begin_layout Standard
28272
28273 \family roman
28274 \series medium
28275 \shape up
28276 \size normal
28277 \emph off
28278 \bar no
28279 \noun off
28280 \color none
28281 HIGH priority interrupts
28282 \end_layout
28283
28284 \end_inset
28285 </cell>
28286 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28287 \begin_inset Text
28288
28289 \begin_layout Standard
28290 0x000008
28291 \end_layout
28292
28293 \end_inset
28294 </cell>
28295 </row>
28296 <row topline="true" bottomline="true">
28297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28298 \begin_inset Text
28299
28300 \begin_layout Standard
28301 2
28302 \end_layout
28303
28304 \end_inset
28305 </cell>
28306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28307 \begin_inset Text
28308
28309 \begin_layout Standard
28310 LOW priority interrupts
28311 \end_layout
28312
28313 \end_inset
28314 </cell>
28315 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28316 \begin_inset Text
28317
28318 \begin_layout Standard
28319 0x000018
28320 \end_layout
28321
28322 \end_inset
28323 </cell>
28324 </row>
28325 </lyxtabular>
28326
28327 \end_inset
28328
28329
28330 \end_layout
28331
28332 \begin_layout Standard
28333 When generating assembly code for ISR the code generator places a 
28334 \noun on
28335 goto 
28336 \noun default
28337 instruction at the 
28338 \emph on
28339 Interrupt Vector Address
28340 \emph default
28341  which points at the generated ISR.
28342  This single GOTO instruction is part of an automatically generated 
28343 \emph on
28344 interrupt entry point
28345 \emph default
28346  function.
28347  The actuall ISR code is placed as normally would in the code space.
28348  Upon interrupt request, the GOTO instruction is executed which jumps to
28349  the ISR code.
28350  When declaring interrupt functions as _naked this GOTO instruction is 
28351 \series bold
28352 not
28353 \series default
28354  generated.
28355  The whole interrupt functions is therefore placed at the Interrupt Vector
28356  Address of the specific interrupt.
28357  This is not a problem for the LOW priority interrupts, but it is a problem
28358  for the RESET and the HIGH priority interrupts because code may be written
28359  at the next interrupt's vector address and cause indeterminate program
28360  behaviour if that interrupt is raised.
28361 \begin_inset Foot
28362 status open
28363
28364 \begin_layout Standard
28365 This is not a problem when
28366 \end_layout
28367
28368 \begin_layout Enumerate
28369 this is a HIGH interrupt ISR and LOW interrupts are 
28370 \emph on
28371 disabled
28372 \emph default
28373  or not used.
28374 \end_layout
28375
28376 \begin_layout Enumerate
28377 when the ISR is small enough not to reach the next interrupt's vector address.
28378 \end_layout
28379
28380 \end_inset
28381
28382
28383 \end_layout
28384
28385 \begin_layout Standard
28386
28387 \emph on
28388 n
28389 \emph default
28390  may be omitted.
28391  This way a function is generated similar to an ISR, but it is not assigned
28392  to any interrupt.
28393 \end_layout
28394
28395 \begin_layout Standard
28396 When entering an interrupt, currently the PIC16
28397 \begin_inset LatexCommand index
28398 name "PIC16"
28399
28400 \end_inset
28401
28402  port automatically saves the following registers:
28403 \end_layout
28404
28405 \begin_layout Itemize
28406 WREG
28407 \end_layout
28408
28409 \begin_layout Itemize
28410 STATUS
28411 \end_layout
28412
28413 \begin_layout Itemize
28414 BSR
28415 \end_layout
28416
28417 \begin_layout Itemize
28418 PROD (PRODL and PRODH)
28419 \end_layout
28420
28421 \begin_layout Itemize
28422 FSR0 (FSR0L and FSR0H)
28423 \end_layout
28424
28425 \begin_layout Standard
28426 These registers are restored upon return from the interrupt routine.
28427 \begin_inset Foot
28428 status open
28429
28430 \begin_layout Standard
28431 NOTE that when the _naked attribute is specified for an interrupt routine,
28432  then NO registers are stored or restored.
28433 \end_layout
28434
28435 \end_inset
28436
28437
28438 \end_layout
28439
28440 \begin_layout Subsection
28441 Generic Pointers
28442 \end_layout
28443
28444 \begin_layout Standard
28445 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
28446  There are 3 types of generic pointers currently implemented data, code
28447  and eeprom pointers.
28448  They are differentiated by the value of the 7th and 6th bits of the upper
28449  byte:
28450 \end_layout
28451
28452 \begin_layout Standard
28453 \align center
28454 \begin_inset Tabular
28455 <lyxtabular version="3" rows="5" columns="5">
28456 <features>
28457 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28458 <column alignment="center" valignment="top" width="0">
28459 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28460 <column alignment="center" valignment="top" width="0">
28461 <column alignment="left" valignment="top" rightline="true" width="0">
28462 <row topline="true" bottomline="true">
28463 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28464 \begin_inset Text
28465
28466 \begin_layout Standard
28467 pointer type
28468 \end_layout
28469
28470 \end_inset
28471 </cell>
28472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28473 \begin_inset Text
28474
28475 \begin_layout Standard
28476 7th bit
28477 \end_layout
28478
28479 \end_inset
28480 </cell>
28481 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28482 \begin_inset Text
28483
28484 \begin_layout Standard
28485 6th bit
28486 \end_layout
28487
28488 \end_inset
28489 </cell>
28490 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28491 \begin_inset Text
28492
28493 \begin_layout Standard
28494 rest of the pointer
28495 \end_layout
28496
28497 \end_inset
28498 </cell>
28499 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28500 \begin_inset Text
28501
28502 \begin_layout Standard
28503 description
28504 \end_layout
28505
28506 \end_inset
28507 </cell>
28508 </row>
28509 <row topline="true" bottomline="true">
28510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28511 \begin_inset Text
28512
28513 \begin_layout Standard
28514 data 
28515 \end_layout
28516
28517 \end_inset
28518 </cell>
28519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28520 \begin_inset Text
28521
28522 \begin_layout Standard
28523 1
28524 \end_layout
28525
28526 \end_inset
28527 </cell>
28528 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28529 \begin_inset Text
28530
28531 \begin_layout Standard
28532 0
28533 \end_layout
28534
28535 \end_inset
28536 </cell>
28537 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28538 \begin_inset Text
28539
28540 \begin_layout Standard
28541
28542 \family typewriter
28543 \shape slanted
28544 \emph on
28545 uuuuuu uuuuxxxx xxxxxxxx
28546 \end_layout
28547
28548 \end_inset
28549 </cell>
28550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28551 \begin_inset Text
28552
28553 \begin_layout Standard
28554 a 12-bit data pointer in data RAM memory
28555 \end_layout
28556
28557 \end_inset
28558 </cell>
28559 </row>
28560 <row bottomline="true">
28561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28562 \begin_inset Text
28563
28564 \begin_layout Standard
28565 code
28566 \end_layout
28567
28568 \end_inset
28569 </cell>
28570 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28571 \begin_inset Text
28572
28573 \begin_layout Standard
28574 0
28575 \end_layout
28576
28577 \end_inset
28578 </cell>
28579 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28580 \begin_inset Text
28581
28582 \begin_layout Standard
28583 0
28584 \end_layout
28585
28586 \end_inset
28587 </cell>
28588 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28589 \begin_inset Text
28590
28591 \begin_layout Standard
28592
28593 \family typewriter
28594 \shape slanted
28595 \emph on
28596 uxxxxx xxxxxxxx xxxxxxxx
28597 \end_layout
28598
28599 \end_inset
28600 </cell>
28601 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28602 \begin_inset Text
28603
28604 \begin_layout Standard
28605 a 21-bit code pointer in FLASH memory
28606 \end_layout
28607
28608 \end_inset
28609 </cell>
28610 </row>
28611 <row bottomline="true">
28612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28613 \begin_inset Text
28614
28615 \begin_layout Standard
28616 eeprom
28617 \end_layout
28618
28619 \end_inset
28620 </cell>
28621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28622 \begin_inset Text
28623
28624 \begin_layout Standard
28625 0
28626 \end_layout
28627
28628 \end_inset
28629 </cell>
28630 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28631 \begin_inset Text
28632
28633 \begin_layout Standard
28634 1
28635 \end_layout
28636
28637 \end_inset
28638 </cell>
28639 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28640 \begin_inset Text
28641
28642 \begin_layout Standard
28643
28644 \family typewriter
28645 \shape slanted
28646 \emph on
28647 uuuuuu uuuuuuxx xxxxxxxx
28648 \end_layout
28649
28650 \end_inset
28651 </cell>
28652 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28653 \begin_inset Text
28654
28655 \begin_layout Standard
28656 a 10-bit eeprom pointer in EEPROM memory
28657 \end_layout
28658
28659 \end_inset
28660 </cell>
28661 </row>
28662 <row bottomline="true">
28663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28664 \begin_inset Text
28665
28666 \begin_layout Standard
28667 (unimplemented)
28668 \end_layout
28669
28670 \end_inset
28671 </cell>
28672 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28673 \begin_inset Text
28674
28675 \begin_layout Standard
28676 1
28677 \end_layout
28678
28679 \end_inset
28680 </cell>
28681 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28682 \begin_inset Text
28683
28684 \begin_layout Standard
28685 1
28686 \end_layout
28687
28688 \end_inset
28689 </cell>
28690 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28691 \begin_inset Text
28692
28693 \begin_layout Standard
28694
28695 \family typewriter
28696 \shape slanted
28697 \emph on
28698 xxxxxx xxxxxxxx xxxxxxxx
28699 \end_layout
28700
28701 \end_inset
28702 </cell>
28703 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28704 \begin_inset Text
28705
28706 \begin_layout Standard
28707 unimplemented pointer type
28708 \end_layout
28709
28710 \end_inset
28711 </cell>
28712 </row>
28713 </lyxtabular>
28714
28715 \end_inset
28716
28717
28718 \end_layout
28719
28720 \begin_layout Standard
28721 \noindent
28722 Generic pointer are read and written with a set of library functions which
28723  read/write 1, 2, 3, 4 bytes.
28724 \end_layout
28725
28726 \begin_layout Subsection
28727 PIC16 C Libraries
28728 \end_layout
28729
28730 \begin_layout Subsubsection
28731 Standard I/O Streams
28732 \end_layout
28733
28734 \begin_layout Standard
28735 In the 
28736 \emph on
28737 stdio.h
28738 \emph default
28739  the type FILE is defined as:
28740 \end_layout
28741
28742 \begin_layout LyX-Code
28743 typedef char * FILE;
28744 \end_layout
28745
28746 \begin_layout Standard
28747 This type is the stream type implemented I/O in the PIC18F devices.
28748  Also the standard input and output streams are declared in stdio.h:
28749 \end_layout
28750
28751 \begin_layout LyX-Code
28752 extern FILE * stdin;
28753 \end_layout
28754
28755 \begin_layout LyX-Code
28756 extern FILE * stdout;
28757 \end_layout
28758
28759 \begin_layout Standard
28760 The FILE type is actually a generic pointer which defines one more type
28761  of generic pointers, the 
28762 \emph on
28763 stream
28764 \emph default
28765  pointer.
28766  This new type has the format:
28767 \end_layout
28768
28769 \begin_layout Standard
28770 \noindent
28771 \align center
28772 \begin_inset Tabular
28773 <lyxtabular version="3" rows="2" columns="7">
28774 <features>
28775 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28776 <column alignment="center" valignment="top" width="0">
28777 <column alignment="center" valignment="top" leftline="true" width="0">
28778 <column alignment="center" valignment="top" leftline="true" width="0">
28779 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28780 <column alignment="center" valignment="top" width="0">
28781 <column alignment="left" valignment="top" rightline="true" width="0">
28782 <row topline="true" bottomline="true">
28783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28784 \begin_inset Text
28785
28786 \begin_layout Standard
28787 pointer type
28788 \end_layout
28789
28790 \end_inset
28791 </cell>
28792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28793 \begin_inset Text
28794
28795 \begin_layout Standard
28796 <7:6>
28797 \end_layout
28798
28799 \end_inset
28800 </cell>
28801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28802 \begin_inset Text
28803
28804 \begin_layout Standard
28805 <5>
28806 \end_layout
28807
28808 \end_inset
28809 </cell>
28810 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28811 \begin_inset Text
28812
28813 \begin_layout Standard
28814 <4>
28815 \end_layout
28816
28817 \end_inset
28818 </cell>
28819 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28820 \begin_inset Text
28821
28822 \begin_layout Standard
28823 <3:0>
28824 \end_layout
28825
28826 \end_inset
28827 </cell>
28828 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28829 \begin_inset Text
28830
28831 \begin_layout Standard
28832 rest of the pointer
28833 \end_layout
28834
28835 \end_inset
28836 </cell>
28837 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28838 \begin_inset Text
28839
28840 \begin_layout Standard
28841 descrption
28842 \end_layout
28843
28844 \end_inset
28845 </cell>
28846 </row>
28847 <row topline="true" bottomline="true">
28848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28849 \begin_inset Text
28850
28851 \begin_layout Standard
28852 stream
28853 \end_layout
28854
28855 \end_inset
28856 </cell>
28857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28858 \begin_inset Text
28859
28860 \begin_layout Standard
28861 00
28862 \end_layout
28863
28864 \end_inset
28865 </cell>
28866 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28867 \begin_inset Text
28868
28869 \begin_layout Standard
28870 1
28871 \end_layout
28872
28873 \end_inset
28874 </cell>
28875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28876 \begin_inset Text
28877
28878 \begin_layout Standard
28879 0
28880 \end_layout
28881
28882 \end_inset
28883 </cell>
28884 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28885 \begin_inset Text
28886
28887 \begin_layout Standard
28888 nnnn
28889 \end_layout
28890
28891 \end_inset
28892 </cell>
28893 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28894 \begin_inset Text
28895
28896 \begin_layout Standard
28897
28898 \family typewriter
28899 \shape slanted
28900 \emph on
28901 uuuuuuuu uuuuuuuu
28902 \end_layout
28903
28904 \end_inset
28905 </cell>
28906 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28907 \begin_inset Text
28908
28909 \begin_layout Standard
28910 upper byte high nubble is 0x2n, the rest are zeroes
28911 \end_layout
28912
28913 \end_inset
28914 </cell>
28915 </row>
28916 </lyxtabular>
28917
28918 \end_inset
28919
28920
28921 \end_layout
28922
28923 \begin_layout Standard
28924 \noindent
28925 Currently implemented there are 3 types of streams defined:
28926 \end_layout
28927
28928 \begin_layout Standard
28929 \noindent
28930 \align center
28931 \begin_inset Tabular
28932 <lyxtabular version="3" rows="4" columns="4">
28933 <features>
28934 <column alignment="center" valignment="top" leftline="true" width="0">
28935 <column alignment="center" valignment="top" leftline="true" width="0">
28936 <column alignment="center" valignment="top" leftline="true" width="0">
28937 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28938 <row topline="true" bottomline="true">
28939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28940 \begin_inset Text
28941
28942 \begin_layout Standard
28943 stream type
28944 \end_layout
28945
28946 \end_inset
28947 </cell>
28948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28949 \begin_inset Text
28950
28951 \begin_layout Standard
28952 value
28953 \end_layout
28954
28955 \end_inset
28956 </cell>
28957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28958 \begin_inset Text
28959
28960 \begin_layout Standard
28961 module
28962 \end_layout
28963
28964 \end_inset
28965 </cell>
28966 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28967 \begin_inset Text
28968
28969 \begin_layout Standard
28970 description
28971 \end_layout
28972
28973 \end_inset
28974 </cell>
28975 </row>
28976 <row topline="true">
28977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28978 \begin_inset Text
28979
28980 \begin_layout Standard
28981 STREAM_USART
28982 \end_layout
28983
28984 \end_inset
28985 </cell>
28986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28987 \begin_inset Text
28988
28989 \begin_layout Standard
28990
28991 \family typewriter
28992 0x200000UL
28993 \end_layout
28994
28995 \end_inset
28996 </cell>
28997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28998 \begin_inset Text
28999
29000 \begin_layout Standard
29001 USART
29002 \end_layout
29003
29004 \end_inset
29005 </cell>
29006 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29007 \begin_inset Text
29008
29009 \begin_layout Standard
29010 Writes/Reads characters via the USART peripheral
29011 \end_layout
29012
29013 \end_inset
29014 </cell>
29015 </row>
29016 <row topline="true">
29017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29018 \begin_inset Text
29019
29020 \begin_layout Standard
29021 STREAM_MSSP
29022 \end_layout
29023
29024 \end_inset
29025 </cell>
29026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29027 \begin_inset Text
29028
29029 \begin_layout Standard
29030
29031 \family typewriter
29032 0x210000UL
29033 \end_layout
29034
29035 \end_inset
29036 </cell>
29037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29038 \begin_inset Text
29039
29040 \begin_layout Standard
29041 MSSP
29042 \end_layout
29043
29044 \end_inset
29045 </cell>
29046 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29047 \begin_inset Text
29048
29049 \begin_layout Standard
29050 Writes/Reads characters via the MSSP peripheral
29051 \end_layout
29052
29053 \end_inset
29054 </cell>
29055 </row>
29056 <row topline="true" bottomline="true">
29057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29058 \begin_inset Text
29059
29060 \begin_layout Standard
29061 STREAM_USER
29062 \end_layout
29063
29064 \end_inset
29065 </cell>
29066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29067 \begin_inset Text
29068
29069 \begin_layout Standard
29070
29071 \family typewriter
29072 0x2f0000UL
29073 \end_layout
29074
29075 \end_inset
29076 </cell>
29077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29078 \begin_inset Text
29079
29080 \begin_layout Standard
29081 (none)
29082 \end_layout
29083
29084 \end_inset
29085 </cell>
29086 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29087 \begin_inset Text
29088
29089 \begin_layout Standard
29090 Writes/Reads characters via used defined functions
29091 \end_layout
29092
29093 \end_inset
29094 </cell>
29095 </row>
29096 </lyxtabular>
29097
29098 \end_inset
29099
29100
29101 \end_layout
29102
29103 \begin_layout Standard
29104 \noindent
29105 The stream identifiers are declared as macros in the stdio.h header.
29106 \end_layout
29107
29108 \begin_layout Standard
29109 \noindent
29110 In the libc library there exist the functions that are used to write to
29111  each of the above streams.
29112  These are
29113 \end_layout
29114
29115 \begin_layout Description
29116 _
29117 \begin_inset ERT
29118 status collapsed
29119
29120 \begin_layout Standard
29121
29122
29123 \backslash
29124 /
29125 \end_layout
29126
29127 \end_inset
29128
29129 _stream_usart_putchar writes a character at the USART stream
29130 \end_layout
29131
29132 \begin_layout Description
29133 _
29134 \begin_inset ERT
29135 status collapsed
29136
29137 \begin_layout Standard
29138
29139
29140 \backslash
29141 /
29142 \end_layout
29143
29144 \end_inset
29145
29146 _stream_mssp_putchar writes a character at the MSSP stream
29147 \end_layout
29148
29149 \begin_layout Description
29150 putchar dummy function.
29151  This writes a character to a user specified manner.
29152 \end_layout
29153
29154 \begin_layout Standard
29155 In order to increase performance 
29156 \emph on
29157 putchar
29158 \emph default
29159  is declared in stdio.h as having its parameter in WREG (it has the wparam
29160  keyword).
29161  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
29162  in a user-friendly way.
29163  
29164 \emph on
29165 arg
29166 \emph default
29167  is the name of the variable that holds the character to print.
29168  An example follows:
29169 \end_layout
29170
29171 \begin_layout LyX-Code
29172 #include <pic18fregs.h>
29173 \newline
29174 #include <stdio.h>
29175 \newline
29176
29177 \newline
29178 PUTCHAR( c )
29179 \end_layout
29180
29181 \begin_layout LyX-Code
29182 {
29183 \end_layout
29184
29185 \begin_layout LyX-Code
29186     PORTA = c;    /* dump character c to PORTA */
29187 \end_layout
29188
29189 \begin_layout LyX-Code
29190
29191 \newline
29192
29193 \newline
29194 void main(void)
29195 \end_layout
29196
29197 \begin_layout LyX-Code
29198 {
29199 \end_layout
29200
29201 \begin_layout LyX-Code
29202     stdout = STREAM_USER;    /* this is not necessary, since stdout points
29203 \end_layout
29204
29205 \begin_layout LyX-Code
29206                               * by default to STREAM_USER */
29207 \end_layout
29208
29209 \begin_layout LyX-Code
29210     printf (
29211 \begin_inset Quotes sld
29212 \end_inset
29213
29214 This is a printf test
29215 \backslash
29216 n
29217 \begin_inset Quotes srd
29218 \end_inset
29219
29220 );
29221 \end_layout
29222
29223 \begin_layout LyX-Code
29224 }
29225 \end_layout
29226
29227 \begin_layout LyX-Code
29228
29229 \end_layout
29230
29231 \begin_layout Subsubsection
29232 Printing functions
29233 \end_layout
29234
29235 \begin_layout Standard
29236 PIC16 contains an implementation of the printf-family of functions.
29237  There exist the following functions:
29238 \end_layout
29239
29240 \begin_layout LyX-Code
29241 extern unsigned int sprintf(char *buf, char *fmt, ...);
29242 \end_layout
29243
29244 \begin_layout LyX-Code
29245 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
29246 \end_layout
29247
29248 \begin_layout LyX-Code
29249
29250 \end_layout
29251
29252 \begin_layout LyX-Code
29253 extern unsigned int printf(char *fmt, ...);
29254 \end_layout
29255
29256 \begin_layout LyX-Code
29257 extern unsigned int vprintf(char *fmt, va_lista ap);
29258 \end_layout
29259
29260 \begin_layout LyX-Code
29261
29262 \end_layout
29263
29264 \begin_layout LyX-Code
29265 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
29266 \end_layout
29267
29268 \begin_layout LyX-Code
29269 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
29270 \end_layout
29271
29272 \begin_layout Standard
29273 For sprintf and vsprintf 
29274 \emph on
29275 buf
29276 \emph default
29277  should normally be a data pointer where the resulting string will be placed.
29278  No range checking is done so the user should allocate the necessary buffer.
29279  For fprintf and vfprintf 
29280 \emph on
29281 fp
29282 \emph default
29283  should be a stream pointer (i.e.
29284  stdout, STREAM_MSSP, etc...).
29285 \end_layout
29286
29287 \begin_layout Subsubsection
29288 Signals
29289 \end_layout
29290
29291 \begin_layout Standard
29292 The PIC18F family of microcontrollers supports a number of interrupt sources.
29293  A list of these interrupts is shown in the following table:
29294 \end_layout
29295
29296 \begin_layout Standard
29297 \align center
29298 \begin_inset Tabular
29299 <lyxtabular version="3" rows="11" columns="4">
29300 <features>
29301 <column alignment="left" valignment="top" leftline="true" width="0">
29302 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
29303 <column alignment="left" valignment="top" leftline="true" width="0">
29304 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
29305 <row topline="true" bottomline="true">
29306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29307 \begin_inset Text
29308
29309 \begin_layout Standard
29310 signal name
29311 \end_layout
29312
29313 \end_inset
29314 </cell>
29315 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29316 \begin_inset Text
29317
29318 \begin_layout Standard
29319 description
29320 \end_layout
29321
29322 \end_inset
29323 </cell>
29324 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29325 \begin_inset Text
29326
29327 \begin_layout Standard
29328 signal name
29329 \end_layout
29330
29331 \end_inset
29332 </cell>
29333 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29334 \begin_inset Text
29335
29336 \begin_layout Standard
29337 description
29338 \end_layout
29339
29340 \end_inset
29341 </cell>
29342 </row>
29343 <row topline="true">
29344 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29345 \begin_inset Text
29346
29347 \begin_layout Standard
29348 SIG_RB
29349 \end_layout
29350
29351 \end_inset
29352 </cell>
29353 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29354 \begin_inset Text
29355
29356 \begin_layout Standard
29357 PORTB change interrupt
29358 \end_layout
29359
29360 \end_inset
29361 </cell>
29362 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29363 \begin_inset Text
29364
29365 \begin_layout Standard
29366 SIG_EE
29367 \end_layout
29368
29369 \end_inset
29370 </cell>
29371 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29372 \begin_inset Text
29373
29374 \begin_layout Standard
29375 EEPROM/FLASH write complete interrupt
29376 \end_layout
29377
29378 \end_inset
29379 </cell>
29380 </row>
29381 <row topline="true">
29382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29383 \begin_inset Text
29384
29385 \begin_layout Standard
29386 SIG_INT0
29387 \end_layout
29388
29389 \end_inset
29390 </cell>
29391 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29392 \begin_inset Text
29393
29394 \begin_layout Standard
29395 INT0 external interrupt
29396 \end_layout
29397
29398 \end_inset
29399 </cell>
29400 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29401 \begin_inset Text
29402
29403 \begin_layout Standard
29404 SIG_BCOL
29405 \end_layout
29406
29407 \end_inset
29408 </cell>
29409 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29410 \begin_inset Text
29411
29412 \begin_layout Standard
29413 Bus collision interrupt
29414 \end_layout
29415
29416 \end_inset
29417 </cell>
29418 </row>
29419 <row topline="true">
29420 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29421 \begin_inset Text
29422
29423 \begin_layout Standard
29424 SIG_INT1
29425 \end_layout
29426
29427 \end_inset
29428 </cell>
29429 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29430 \begin_inset Text
29431
29432 \begin_layout Standard
29433 INT1 external interrupt
29434 \end_layout
29435
29436 \end_inset
29437 </cell>
29438 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29439 \begin_inset Text
29440
29441 \begin_layout Standard
29442 SIG_LVD
29443 \end_layout
29444
29445 \end_inset
29446 </cell>
29447 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29448 \begin_inset Text
29449
29450 \begin_layout Standard
29451 Low voltage detect interrupt
29452 \end_layout
29453
29454 \end_inset
29455 </cell>
29456 </row>
29457 <row topline="true">
29458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29459 \begin_inset Text
29460
29461 \begin_layout Standard
29462 SIG_INT2
29463 \end_layout
29464
29465 \end_inset
29466 </cell>
29467 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29468 \begin_inset Text
29469
29470 \begin_layout Standard
29471 INT2 external interrupt
29472 \end_layout
29473
29474 \end_inset
29475 </cell>
29476 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29477 \begin_inset Text
29478
29479 \begin_layout Standard
29480 SIG_PSP
29481 \end_layout
29482
29483 \end_inset
29484 </cell>
29485 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29486 \begin_inset Text
29487
29488 \begin_layout Standard
29489 Parallel slave port interrupt
29490 \end_layout
29491
29492 \end_inset
29493 </cell>
29494 </row>
29495 <row topline="true">
29496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29497 \begin_inset Text
29498
29499 \begin_layout Standard
29500 SIG_CCP1
29501 \end_layout
29502
29503 \end_inset
29504 </cell>
29505 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29506 \begin_inset Text
29507
29508 \begin_layout Standard
29509 CCP1 module interrupt
29510 \end_layout
29511
29512 \end_inset
29513 </cell>
29514 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29515 \begin_inset Text
29516
29517 \begin_layout Standard
29518 SIG_AD
29519 \end_layout
29520
29521 \end_inset
29522 </cell>
29523 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29524 \begin_inset Text
29525
29526 \begin_layout Standard
29527 AD convertion complete interrupt
29528 \end_layout
29529
29530 \end_inset
29531 </cell>
29532 </row>
29533 <row topline="true">
29534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29535 \begin_inset Text
29536
29537 \begin_layout Standard
29538 SIG_CCP2
29539 \end_layout
29540
29541 \end_inset
29542 </cell>
29543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29544 \begin_inset Text
29545
29546 \begin_layout Standard
29547 CCP2 module interrupt
29548 \end_layout
29549
29550 \end_inset
29551 </cell>
29552 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29553 \begin_inset Text
29554
29555 \begin_layout Standard
29556 SIG_RC
29557 \end_layout
29558
29559 \end_inset
29560 </cell>
29561 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29562 \begin_inset Text
29563
29564 \begin_layout Standard
29565 USART receive interrupt
29566 \end_layout
29567
29568 \end_inset
29569 </cell>
29570 </row>
29571 <row topline="true">
29572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29573 \begin_inset Text
29574
29575 \begin_layout Standard
29576 SIG_TMR0
29577 \end_layout
29578
29579 \end_inset
29580 </cell>
29581 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29582 \begin_inset Text
29583
29584 \begin_layout Standard
29585 TMR0 overflow interrupt
29586 \end_layout
29587
29588 \end_inset
29589 </cell>
29590 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29591 \begin_inset Text
29592
29593 \begin_layout Standard
29594 SIG_TX
29595 \end_layout
29596
29597 \end_inset
29598 </cell>
29599 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29600 \begin_inset Text
29601
29602 \begin_layout Standard
29603 USART transmit interrupt
29604 \end_layout
29605
29606 \end_inset
29607 </cell>
29608 </row>
29609 <row topline="true">
29610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29611 \begin_inset Text
29612
29613 \begin_layout Standard
29614 SIG_TMR1
29615 \end_layout
29616
29617 \end_inset
29618 </cell>
29619 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29620 \begin_inset Text
29621
29622 \begin_layout Standard
29623 TMR1 overflow interrupt
29624 \end_layout
29625
29626 \end_inset
29627 </cell>
29628 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29629 \begin_inset Text
29630
29631 \begin_layout Standard
29632 SIG_MSSP
29633 \end_layout
29634
29635 \end_inset
29636 </cell>
29637 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29638 \begin_inset Text
29639
29640 \begin_layout Standard
29641 SSP receive/transmit interrupt
29642 \end_layout
29643
29644 \end_inset
29645 </cell>
29646 </row>
29647 <row topline="true">
29648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29649 \begin_inset Text
29650
29651 \begin_layout Standard
29652 SIG_TMR2
29653 \end_layout
29654
29655 \end_inset
29656 </cell>
29657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29658 \begin_inset Text
29659
29660 \begin_layout Standard
29661 TMR2 matches PR2 interrupt
29662 \end_layout
29663
29664 \end_inset
29665 </cell>
29666 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29667 \begin_inset Text
29668
29669 \begin_layout Standard
29670
29671 \end_layout
29672
29673 \end_inset
29674 </cell>
29675 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29676 \begin_inset Text
29677
29678 \begin_layout Standard
29679
29680 \end_layout
29681
29682 \end_inset
29683 </cell>
29684 </row>
29685 <row topline="true" bottomline="true">
29686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29687 \begin_inset Text
29688
29689 \begin_layout Standard
29690 SIG_TMR3
29691 \end_layout
29692
29693 \end_inset
29694 </cell>
29695 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29696 \begin_inset Text
29697
29698 \begin_layout Standard
29699 TMR3 overflow interrupt
29700 \end_layout
29701
29702 \end_inset
29703 </cell>
29704 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29705 \begin_inset Text
29706
29707 \begin_layout Standard
29708
29709 \end_layout
29710
29711 \end_inset
29712 </cell>
29713 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29714 \begin_inset Text
29715
29716 \begin_layout Standard
29717
29718 \end_layout
29719
29720 \end_inset
29721 </cell>
29722 </row>
29723 </lyxtabular>
29724
29725 \end_inset
29726
29727
29728 \end_layout
29729
29730 \begin_layout Standard
29731 \noindent
29732 The prototypes for these names are defined in the header file 
29733 \emph on
29734 signal.h
29735 \emph default
29736  .
29737 \end_layout
29738
29739 \begin_layout Standard
29740 \noindent
29741 In order to simplify signal handling, a number of macros is provided:
29742 \end_layout
29743
29744 \begin_layout List
29745 \labelwidthstring 00.00.0000
29746 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
29747  high priority interrupts.
29748  
29749 \emph on
29750 name
29751 \emph default
29752  is the function name to use.
29753 \end_layout
29754
29755 \begin_layout List
29756 \labelwidthstring 00.00.0000
29757 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
29758  low priority interrupt.
29759  
29760 \emph on
29761 name
29762 \emph default
29763  is the function name to use.
29764 \end_layout
29765
29766 \begin_layout List
29767 \labelwidthstring 00.00.0000
29768 DEF_HANDLER(sig,handler) define a handler for signal 
29769 \emph on
29770 sig.
29771 \end_layout
29772
29773 \begin_layout List
29774 \labelwidthstring 00.00.0000
29775 END_DEF end the declaration of the dispatch table.
29776 \end_layout
29777
29778 \begin_layout Standard
29779 Additionally there are two more macros to simplify the declaration of the
29780  signal handler:
29781 \end_layout
29782
29783 \begin_layout List
29784 \labelwidthstring 00.00.0000
29785
29786 \series medium
29787 SIGHANDLER(handler)
29788 \series default
29789  this declares the function prototype for the 
29790 \emph on
29791 handler
29792 \emph default
29793  function.
29794 \end_layout
29795
29796 \begin_layout List
29797 \labelwidthstring 00.00.0000
29798 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
29799 \end_layout
29800
29801 \begin_layout Standard
29802 An example of using the macros above is shown below:
29803 \end_layout
29804
29805 \begin_layout LyX-Code
29806 #include <pic18fregs.h>
29807 \end_layout
29808
29809 \begin_layout LyX-Code
29810 #include <signal.h>
29811 \newline
29812
29813 \newline
29814 DEF_INTHIGH(high_int)
29815 \end_layout
29816
29817 \begin_layout LyX-Code
29818 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
29819 \end_layout
29820
29821 \begin_layout LyX-Code
29822 DEF_HANDLER(SIG_BCOL, _bcol_handler)
29823 \end_layout
29824
29825 \begin_layout LyX-Code
29826 END_DEF
29827 \newline
29828
29829 \newline
29830 SIGHANDLER(_tmr0_handler)
29831 \end_layout
29832
29833 \begin_layout LyX-Code
29834 {
29835 \end_layout
29836
29837 \begin_layout LyX-Code
29838   /* action to be taken when timer 0 overflows */
29839 \end_layout
29840
29841 \begin_layout LyX-Code
29842 }
29843 \newline
29844
29845 \newline
29846 SIGHANDLERNAKED(_bcol_handler)
29847 \end_layout
29848
29849 \begin_layout LyX-Code
29850 {
29851 \end_layout
29852
29853 \begin_layout LyX-Code
29854   _asm
29855 \end_layout
29856
29857 \begin_layout LyX-Code
29858     /* action to be taken when bus collision occurs */
29859 \end_layout
29860
29861 \begin_layout LyX-Code
29862     retfie
29863 \end_layout
29864
29865 \begin_layout LyX-Code
29866  _endasm;
29867 \end_layout
29868
29869 \begin_layout LyX-Code
29870 }
29871 \end_layout
29872
29873 \begin_layout Standard
29874
29875 \series bold
29876 NOTES:
29877 \series default
29878  Special care should be taken when using the above scheme:
29879 \end_layout
29880
29881 \begin_layout Itemize
29882 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
29883 \end_layout
29884
29885 \begin_layout Itemize
29886 when declaring SIGHANDLERNAKED handler never forget to use 
29887 \emph on
29888 retfie
29889 \emph default
29890  for proper returning.
29891 \end_layout
29892
29893 \begin_layout Subsection
29894 PIC16 Port -- Tips
29895 \end_layout
29896
29897 \begin_layout Standard
29898 Here you can find some general tips for compiling programs with SDCC/pic16.
29899 \end_layout
29900
29901 \begin_layout Subsubsection
29902 Stack size
29903 \end_layout
29904
29905 \begin_layout Standard
29906 The default stack
29907 \begin_inset LatexCommand index
29908 name "PIC16!stack"
29909
29910 \end_inset
29911
29912  size (that is 64 bytes) probably is enough for many programs.
29913  One must take care that when there are many levels of function nesting,
29914  or there is excessive usage of stack, its size should be extended.
29915  An example of such a case is the printf/sprintf family of functions.
29916  If you encounter problems like not being able to print integers, then you
29917  need to set the stack size around the maximum (256 for small stack model).
29918  The following diagram shows what happens when calling printf to print an
29919  integer:
29920 \end_layout
29921
29922 \begin_layout LyX-Code
29923 printf () --> ltoa () --> ultoa () --> divschar ()
29924 \end_layout
29925
29926 \begin_layout Standard
29927 It is should be understood that stack is easily consumed when calling complicate
29928 d functions.
29929  Using command line arguments like -
29930 \begin_inset ERT
29931 status collapsed
29932
29933 \begin_layout Standard
29934
29935
29936 \backslash
29937 /
29938 \end_layout
29939
29940 \end_inset
29941
29942 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
29943  stack frames.
29944  Other ways to reduce stack usage may exist.
29945 \end_layout
29946
29947 \begin_layout Subsection
29948 Known Bugs
29949 \end_layout
29950
29951 \begin_layout Subsubsection
29952 Extended Instruction Set
29953 \end_layout
29954
29955 \begin_layout Standard
29956 The PIC16 port emits code which is incompatible with the extended instruction
29957  set available with many newer devices.
29958  Make sure to always explicitly disable it, usually using
29959 \end_layout
29960
29961 \begin_layout Standard
29962
29963 \family typewriter
29964 static __code char __at(__CONFIG4L) conf4l = /* more flags & */ _XINST_OFF_4L;
29965 \end_layout
29966
29967 \begin_layout Standard
29968 \noindent
29969 Some devices (namely 18f2455, 18f2550, 18f4455, and 18f4550) use _ENHCPU_OFF_4L
29970  instead of _XINST_OFF_4L.
29971 \end_layout
29972
29973 \begin_layout Subsubsection
29974 Regression Tests
29975 \end_layout
29976
29977 \begin_layout Standard
29978 The PIC16 port currently passes most but not all of the tests in SDCC's
29979  regression test
29980 \begin_inset LatexCommand index
29981 name "Regression test (PIC16)"
29982
29983 \end_inset
29984
29985  suite (see section 
29986 \begin_inset LatexCommand ref
29987 reference "sec:Quality-control"
29988
29989 \end_inset
29990
29991 ), thus no automatic regression tests are currently performed for the PIC16
29992  target.
29993 \end_layout
29994
29995 \begin_layout Chapter
29996 Debugging
29997 \end_layout
29998
29999 \begin_layout Standard
30000 There are several approaches to debugging your code.
30001  This chapter is meant to show your options and to give detail on some of
30002  them:
30003 \newline
30004
30005 \newline
30006 When writing your code:
30007 \end_layout
30008
30009 \begin_layout Itemize
30010 write your code with debugging in mind (avoid duplicating code, put conceptually
30011  similar variables into structs, use structured code, have strategic points
30012  within your code where all variables are consistent, ...)
30013 \end_layout
30014
30015 \begin_layout Itemize
30016 run a syntax-checking tool like splint
30017 \begin_inset LatexCommand index
30018 name "splint (syntax checking tool)"
30019
30020 \end_inset
30021
30022
30023 \begin_inset LatexCommand index
30024 name "lint (syntax checking tool)"
30025
30026 \end_inset
30027
30028  (see -
30029 \begin_inset ERT
30030 status collapsed
30031
30032 \begin_layout Standard
30033
30034
30035 \backslash
30036 /
30037 \end_layout
30038
30039 \end_inset
30040
30041 -more-pedantic 
30042 \begin_inset LatexCommand ref
30043 reference "lyx:more-pedantic-SPLINT"
30044
30045 \end_inset
30046
30047 ) over the code.
30048 \end_layout
30049
30050 \begin_layout Itemize
30051 for the high level code use a C-compiler (like f.e.
30052  GCC) to compile run and debug the code on your host.
30053  See (see -
30054 \begin_inset ERT
30055 status collapsed
30056
30057 \begin_layout Standard
30058
30059
30060 \backslash
30061 /
30062 \end_layout
30063
30064 \end_inset
30065
30066 -more-pedantic 
30067 \begin_inset LatexCommand ref
30068 reference "lyx:more-pedantic-SPLINT"
30069
30070 \end_inset
30071
30072 ) on how to handle syntax extensions like __xdata, __at(), ...
30073  
30074 \end_layout
30075
30076 \begin_layout Itemize
30077 use another C-compiler to compile code for your target.
30078  Always an option but not recommended:) And not very likely to help you.
30079  If you seriously consider walking this path you should at least occasionally
30080  check portability of your code.
30081  Most commercial compiler vendors will offer an evaluation version so you
30082  can test compile your code or snippets of your code.
30083 \end_layout
30084
30085 \begin_layout Standard
30086 Debugging on a simulator:
30087 \end_layout
30088
30089 \begin_layout Itemize
30090 there is a separate section about SDCDB (section 
30091 \begin_inset LatexCommand ref
30092 reference "cha:Debugging-with-SDCDB"
30093
30094 \end_inset
30095
30096 ) below.
30097 \end_layout
30098
30099 \begin_layout Itemize
30100 or (8051 specific) use a freeware/commercial simulator which interfaces
30101  to the AOMF
30102 \begin_inset LatexCommand index
30103 name "AOMF, AOMF51"
30104
30105 \end_inset
30106
30107  file (see 
30108 \begin_inset LatexCommand ref
30109 reference "OMF file"
30110
30111 \end_inset
30112
30113 ) optionally generated by SDCC.
30114 \end_layout
30115
30116 \begin_layout Standard
30117 Debugging On-target: 
30118 \end_layout
30119
30120 \begin_layout Itemize
30121 use a MCU port pin to serially output debug data to the RS232 port of your
30122  host.
30123  You'll probably want some level shifting device typically involving a MAX232
30124  or similar IC.
30125  If the hardware serial port of the MCU is not available search for 'Software
30126  UART' in your favourite search machine.
30127 \end_layout
30128
30129 \begin_layout Itemize
30130 use an on-target monitor.
30131  In this context a monitor is a small program which usually accepts commands
30132  via a serial line and allows to set program counter, to single step through
30133  a program and read/write memory locations.
30134  For the 8051 good examples of monitors are paulmon and cmon51 (see section
30135  
30136 \begin_inset LatexCommand ref
30137 reference "sec:Related-open-source-tools"
30138
30139 \end_inset
30140
30141 ).
30142 \end_layout
30143
30144 \begin_layout Itemize
30145 toggle MCU port pins at strategic points within your code and use an oscilloscop
30146 e.
30147  A 
30148 \emph on
30149 digital oscilloscope
30150 \emph default
30151
30152 \begin_inset LatexCommand index
30153 name "Oscilloscope"
30154
30155 \end_inset
30156
30157  with deep trace memory is really helpful especially if you have to debug
30158  a realtime application.
30159  If you need to monitor more pins than your oscilloscope provides you can
30160  sometimes get away with a small R-2R network.
30161  On a single channel oscilloscope you could f.e.
30162  monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
30163 k
30164 \begin_inset Formula $\Omega$
30165 \end_inset
30166
30167  resistor and the other one by a 5\InsetSpace ~
30168 k
30169 \begin_inset Formula $\Omega$
30170 \end_inset
30171
30172  resistor to the oscilloscope probe (check output drive capability of the
30173  pins you want to monitor).
30174  If you need to monitor many more pins a 
30175 \emph on
30176 logic analyzer
30177 \emph default
30178  will be handy.
30179 \end_layout
30180
30181 \begin_layout Itemize
30182 use an ICE (
30183 \emph on
30184 i
30185 \emph default
30186
30187 \emph on
30188 c
30189 \emph default
30190 ircuit 
30191 \emph on
30192 e
30193 \emph default
30194 mulator
30195 \begin_inset LatexCommand index
30196 name "ICE (in circuit emulator)"
30197
30198 \end_inset
30199
30200 ).
30201  Usually very expensive.
30202  And very nice to have too.
30203  And usually locks you (for years...) to the devices the ICE can emulate.
30204  
30205 \end_layout
30206
30207 \begin_layout Itemize
30208 use a remote debugger.
30209  In most 8-bit systems the symbol information is not available on the target,
30210  and a complete debugger is too bulky for the target system.
30211  Therefore usually a debugger on the host system connects to an on-target
30212  debugging stub which accepts only primitive commands.
30213  
30214 \newline
30215 Terms to enter into your favourite search engine could be 'remote debugging',
30216  'gdb stub' or 'inferior debugger'.
30217  (is there one?)
30218 \end_layout
30219
30220 \begin_layout Itemize
30221 use an on target hardware debugger.
30222  Some of the more modern MCUs include hardware support for setting break
30223  points and monitoring/changing variables by using dedicated hardware pins.
30224  This facility doesn't require additional code to run on the target and
30225  
30226 \emph on
30227 usually
30228 \emph default
30229  doesn't affect runtime behaviour until a breakpoint is hit.
30230  For the mcs51 most hardware debuggers use the AOMF
30231 \begin_inset LatexCommand index
30232 name "AOMF, AOMF51"
30233
30234 \end_inset
30235
30236  file (see 
30237 \begin_inset LatexCommand ref
30238 reference "OMF file"
30239
30240 \end_inset
30241
30242 ) as input file.
30243  
30244 \end_layout
30245
30246 \begin_layout Standard
30247 Last not least:
30248 \end_layout
30249
30250 \begin_layout Itemize
30251 if you are not familiar with any of the following terms you're likely to
30252  run into problems rather sooner than later: 
30253 \emph on
30254 volatile
30255 \emph default
30256
30257 \emph on
30258 atomic
30259 \emph default
30260
30261 \emph on
30262 memory map
30263 \emph default
30264
30265 \emph on
30266 overlay
30267 \emph default
30268 .
30269  As an embedded programmer you 
30270 \emph on
30271 have
30272 \emph default
30273  to know them so why not look them up 
30274 \emph on
30275 before
30276 \emph default
30277  you have problems?)
30278 \end_layout
30279
30280 \begin_layout Itemize
30281 tell someone else about your problem (actually this is a surprisingly effective
30282  means to hunt down the bug even if the listener is not familiar with your
30283  environment).
30284  As 'failure to communicate' is probably one of the job-induced deformations
30285  of an embedded programmer this is highly encouraged.
30286 \end_layout
30287
30288 \begin_layout Section
30289 Debugging with SDCDB
30290 \begin_inset LatexCommand label
30291 name "cha:Debugging-with-SDCDB"
30292
30293 \end_inset
30294
30295
30296 \begin_inset LatexCommand index
30297 name "SDCDB (debugger)"
30298
30299 \end_inset
30300
30301  
30302 \end_layout
30303
30304 \begin_layout Standard
30305 SDCC is distributed with a source level debugger
30306 \begin_inset LatexCommand index
30307 name "Debugger"
30308
30309 \end_inset
30310
30311 .
30312  The debugger uses a command line interface, the command repertoire of the
30313  debugger has been kept as close to gdb
30314 \begin_inset LatexCommand index
30315 name "gdb"
30316
30317 \end_inset
30318
30319  (the GNU debugger) as possible.
30320  The configuration and build process is part of the standard compiler installati
30321 on, which also builds and installs the debugger in the target directory
30322  specified during configuration.
30323  The debugger allows you debug BOTH at the C source and at the ASM source
30324  level.
30325 \end_layout
30326
30327 \begin_layout Subsection
30328 Compiling for Debugging
30329 \end_layout
30330
30331 \begin_layout Standard
30332 The -
30333 \begin_inset ERT
30334 status collapsed
30335
30336 \begin_layout Standard
30337
30338
30339 \backslash
30340 /
30341 \end_layout
30342
30343 \end_inset
30344
30345 -debug
30346 \begin_inset LatexCommand index
30347 name "-\\/-debug"
30348
30349 \end_inset
30350
30351  option must be specified for all files for which debug information is to
30352  be generated.
30353  The compiler generates a .adb file for each of these files.
30354  The linker creates the .cdb
30355 \begin_inset LatexCommand index
30356 name "<file>.cdb"
30357
30358 \end_inset
30359
30360  file from the .adb
30361 \begin_inset LatexCommand index
30362 name "<file>.adb"
30363
30364 \end_inset
30365
30366  files and the address information.
30367  This .cdb is used by the debugger.
30368 \end_layout
30369
30370 \begin_layout Subsection
30371 How the Debugger Works
30372 \end_layout
30373
30374 \begin_layout Standard
30375 When the -
30376 \begin_inset ERT
30377 status collapsed
30378
30379 \begin_layout Standard
30380
30381
30382 \backslash
30383 /
30384 \end_layout
30385
30386 \end_inset
30387
30388 -debug option is specified the compiler generates extra symbol information
30389  some of which are put into the assembler source and some are put into the
30390  .adb file.
30391  Then the linker creates the .cdb file from the individual .adb files with
30392  the address information for the symbols.
30393  The debugger reads the symbolic information generated by the compiler &
30394  the address information generated by the linker.
30395  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
30396  execution is controlled by the debugger.
30397  When a command is issued for the debugger, it translates it into appropriate
30398  commands for the simulator.
30399  (Currently SDCDM only connects to the simulator but 
30400 \emph on
30401 newcdb
30402 \emph default
30403  at 
30404 \begin_inset LatexCommand url
30405 target "http://ec2drv.sf.net/"
30406
30407 \end_inset
30408
30409  is an effort to connect directly to the hardware.) 
30410 \end_layout
30411
30412 \begin_layout Subsection
30413 Starting the Debugger SDCDB
30414 \end_layout
30415
30416 \begin_layout Standard
30417 The debugger can be started using the following command line.
30418  (Assume the file you are debugging has the file name foo).
30419 \newline
30420
30421 \newline
30422
30423 \family sans
30424 \series bold
30425 sdcdb foo
30426 \newline
30427
30428 \family default
30429 \series default
30430
30431 \newline
30432 The debugger will look for the following files.
30433 \end_layout
30434
30435 \begin_layout Itemize
30436 foo.c - the source file.
30437 \end_layout
30438
30439 \begin_layout Itemize
30440 foo.cdb - the debugger symbol information file.
30441 \end_layout
30442
30443 \begin_layout Itemize
30444 foo.ihx - the Intel hex format
30445 \begin_inset LatexCommand index
30446 name "Intel hex format"
30447
30448 \end_inset
30449
30450  object file.
30451 \end_layout
30452
30453 \begin_layout Subsection
30454 SDCDB Command Line Options
30455 \end_layout
30456
30457 \begin_layout Itemize
30458 -
30459 \begin_inset ERT
30460 status collapsed
30461
30462 \begin_layout Standard
30463
30464
30465 \backslash
30466 /
30467 \end_layout
30468
30469 \end_inset
30470
30471 -directory=<source file directory> this option can used to specify the directory
30472  search list.
30473  The debugger will look into the directory list specified for source, cdb
30474  & ihx files.
30475  The items in the directory list must be separated by ':', e.g.
30476  if the source files can be in the directories /home/src1 and /home/src2,
30477  the -
30478 \begin_inset ERT
30479 status collapsed
30480
30481 \begin_layout Standard
30482
30483
30484 \backslash
30485 /
30486 \end_layout
30487
30488 \end_inset
30489
30490 -directory option should be -
30491 \begin_inset ERT
30492 status collapsed
30493
30494 \begin_layout Standard
30495
30496
30497 \backslash
30498 /
30499 \end_layout
30500
30501 \end_inset
30502
30503 -directory=/home/src1:/home/src2.
30504  Note there can be no spaces in the option.
30505  
30506 \end_layout
30507
30508 \begin_layout Itemize
30509 -cd <directory> - change to the <directory>.
30510 \end_layout
30511
30512 \begin_layout Itemize
30513 -fullname - used by GUI front ends.
30514 \end_layout
30515
30516 \begin_layout Itemize
30517 -cpu <cpu-type> - this argument is passed to the simulator please see the
30518  simulator docs for details.
30519 \end_layout
30520
30521 \begin_layout Itemize
30522 -X <Clock frequency > this options is passed to the simulator please see
30523  the simulator docs for details.
30524 \end_layout
30525
30526 \begin_layout Itemize
30527 -s <serial port file> passed to simulator see the simulator docs for details.
30528 \end_layout
30529
30530 \begin_layout Itemize
30531 -S <serial in,out> passed to simulator see the simulator docs for details.
30532 \end_layout
30533
30534 \begin_layout Itemize
30535 -k <port number> passed to simulator see the simulator docs for details.
30536 \end_layout
30537
30538 \begin_layout Subsection
30539 SDCDB Debugger Commands
30540 \end_layout
30541
30542 \begin_layout Standard
30543 As mentioned earlier the command interface for the debugger has been deliberatel
30544 y kept as close the GNU debugger gdb, as possible.
30545  This will help the integration with existing graphical user interfaces
30546  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
30547  If you use a graphical user interface for the debugger you can skip this
30548  section.
30549 \end_layout
30550
30551 \begin_layout Subsubsection*
30552 break [line | file:line | function | file:function]
30553 \end_layout
30554
30555 \begin_layout Standard
30556 Set breakpoint at specified line or function:
30557 \newline
30558
30559 \newline
30560
30561 \family sans
30562 \series bold
30563 sdcdb>break 100 
30564 \newline
30565 sdcdb>break foo.c:100
30566 \newline
30567 sdcdb>break funcfoo
30568 \newline
30569 sdcdb>break foo.c:funcfoo
30570 \end_layout
30571
30572 \begin_layout Subsubsection*
30573 clear [line | file:line | function | file:function ]
30574 \end_layout
30575
30576 \begin_layout Standard
30577 Clear breakpoint at specified line or function:
30578 \newline
30579
30580 \newline
30581
30582 \family sans
30583 \series bold
30584 sdcdb>clear 100
30585 \newline
30586 sdcdb>clear foo.c:100
30587 \newline
30588 sdcdb>clear funcfoo
30589 \newline
30590 sdcdb>clear foo.c:funcfoo
30591 \end_layout
30592
30593 \begin_layout Subsubsection*
30594 continue
30595 \end_layout
30596
30597 \begin_layout Standard
30598 Continue program being debugged, after breakpoint.
30599 \end_layout
30600
30601 \begin_layout Subsubsection*
30602 finish
30603 \end_layout
30604
30605 \begin_layout Standard
30606 Execute till the end of the current function.
30607 \end_layout
30608
30609 \begin_layout Subsubsection*
30610 delete [n]
30611 \end_layout
30612
30613 \begin_layout Standard
30614 Delete breakpoint number 'n'.
30615  If used without any option clear ALL user defined break points.
30616 \end_layout
30617
30618 \begin_layout Subsubsection*
30619 info [break | stack | frame | registers ]
30620 \end_layout
30621
30622 \begin_layout Itemize
30623 info break - list all breakpoints
30624 \end_layout
30625
30626 \begin_layout Itemize
30627 info stack - show the function call stack.
30628 \end_layout
30629
30630 \begin_layout Itemize
30631 info frame - show information about the current execution frame.
30632 \end_layout
30633
30634 \begin_layout Itemize
30635 info registers - show content of all registers.
30636 \end_layout
30637
30638 \begin_layout Subsubsection*
30639 step
30640 \end_layout
30641
30642 \begin_layout Standard
30643 Step program until it reaches a different source line.
30644  Note: pressing <return> repeats the last command.
30645 \end_layout
30646
30647 \begin_layout Subsubsection*
30648 next
30649 \end_layout
30650
30651 \begin_layout Standard
30652 Step program, proceeding through subroutine calls.
30653 \end_layout
30654
30655 \begin_layout Subsubsection*
30656 run
30657 \end_layout
30658
30659 \begin_layout Standard
30660 Start debugged program.
30661 \end_layout
30662
30663 \begin_layout Subsubsection*
30664 ptype variable 
30665 \end_layout
30666
30667 \begin_layout Standard
30668 Print type information of the variable.
30669 \end_layout
30670
30671 \begin_layout Subsubsection*
30672 print variable
30673 \end_layout
30674
30675 \begin_layout Standard
30676 print value of variable.
30677 \end_layout
30678
30679 \begin_layout Subsubsection*
30680 file filename
30681 \end_layout
30682
30683 \begin_layout Standard
30684 load the given file name.
30685  Note this is an alternate method of loading file for debugging.
30686 \end_layout
30687
30688 \begin_layout Subsubsection*
30689 frame
30690 \end_layout
30691
30692 \begin_layout Standard
30693 print information about current frame.
30694 \end_layout
30695
30696 \begin_layout Subsubsection*
30697 set srcmode
30698 \end_layout
30699
30700 \begin_layout Standard
30701 Toggle between C source & assembly source.
30702 \end_layout
30703
30704 \begin_layout Subsubsection*
30705 ! simulator command
30706 \end_layout
30707
30708 \begin_layout Standard
30709 Send the string following '!' to the simulator, the simulator response is
30710  displayed.
30711  Note the debugger does not interpret the command being sent to the simulator,
30712  so if a command like 'go' is sent the debugger can loose its execution
30713  context and may display incorrect values.
30714 \end_layout
30715
30716 \begin_layout Subsubsection*
30717 quit
30718 \end_layout
30719
30720 \begin_layout Standard
30721 "Watch me now.
30722  Iam going Down.
30723  My name is Bobby Brown"
30724 \end_layout
30725
30726 \begin_layout Subsection
30727 Interfacing SDCDB with DDD
30728 \end_layout
30729
30730 \begin_layout Standard
30731 \begin_inset Note Note
30732 status collapsed
30733
30734 \begin_layout Standard
30735 The screenshot was converted from png to eps with: 
30736 \begin_inset Quotes sld
30737 \end_inset
30738
30739 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
30740 \begin_inset Quotes srd
30741 \end_inset
30742
30743  which produces a pretty compact eps file which is free from compression
30744  artifacts.
30745 \end_layout
30746
30747 \begin_layout Standard
30748 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
30749  as this broke the build system on Sourceforge (pdf-file was broken.
30750  pdflatex does not accept eps files).
30751 \end_layout
30752
30753 \end_inset
30754
30755
30756 \end_layout
30757
30758 \begin_layout Standard
30759 The 
30760 \emph on
30761 p
30762 \emph default
30763 ortable 
30764 \emph on
30765 n
30766 \emph default
30767 etwork 
30768 \emph on
30769 g
30770 \emph default
30771 raphics File 
30772 \size footnotesize
30773
30774 \begin_inset LatexCommand url
30775 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png"
30776
30777 \end_inset
30778
30779
30780 \size default
30781  shows a screenshot of a debugging session with DDD
30782 \begin_inset LatexCommand index
30783 name "DDD (debugger)"
30784
30785 \end_inset
30786
30787  (Unix only) on a simulated 8032.
30788  The debugging session might not run as smoothly as the screenshot suggests.
30789  The debugger allows setting of breakpoints, displaying and changing variables,
30790  single stepping through C and assembler code.
30791  
30792 \newline
30793 The source was compiled with 
30794 \family sans
30795 \series bold
30796
30797 \newline
30798
30799 \newline
30800 sdcc -
30801 \family default
30802 \series default
30803
30804 \begin_inset ERT
30805 status collapsed
30806
30807 \begin_layout Standard
30808
30809
30810 \backslash
30811 /
30812 \end_layout
30813
30814 \end_inset
30815
30816
30817 \family sans
30818 \series bold
30819 -debug ddd_example.c
30820 \family default
30821 \series default
30822  
30823 \family sans
30824 \series bold
30825
30826 \newline
30827
30828 \family default
30829 \series default
30830
30831 \newline
30832 and DDD was invoked with 
30833 \family sans
30834 \series bold
30835
30836 \newline
30837
30838 \newline
30839 ddd -debugger "sdcdb -cpu 8032 ddd_example"
30840 \end_layout
30841
30842 \begin_layout Standard
30843 \begin_inset Note Note
30844 status open
30845
30846 \begin_layout Standard
30847 Check that the double quotes or an apostrophe within the command line survive
30848  the LyX tool chain.
30849  Previously the apostrophes got slanted in the PDF output so a cut and paste
30850  did not work.
30851 \end_layout
30852
30853 \end_inset
30854
30855
30856 \end_layout
30857
30858 \begin_layout Subsection
30859 Interfacing SDCDB with XEmacs
30860 \begin_inset LatexCommand index
30861 name "XEmacs"
30862
30863 \end_inset
30864
30865
30866 \begin_inset LatexCommand index
30867 name "Emacs"
30868
30869 \end_inset
30870
30871
30872 \end_layout
30873
30874 \begin_layout Standard
30875 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
30876  sdcdb.el and sdcdbsrc.el.
30877  These two files can be found in the $(prefix)/bin directory after the installat
30878 ion is complete.
30879  These files need to be loaded into XEmacs for the interface to work.
30880  This can be done at XEmacs startup time by inserting the following into
30881  your '.xemacs' file (which can be found in your HOME directory): 
30882 \newline
30883
30884 \newline
30885
30886 \family typewriter
30887 (load-file sdcdbsrc.el)
30888 \family default
30889  
30890 \newline
30891
30892 \newline
30893 .xemacs is a lisp file so the () around the command is REQUIRED.
30894  The files can also be loaded dynamically while XEmacs is running, set the
30895  environment variable 'EMACSLOADPATH' to the installation bin directory
30896  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
30897  To start the interface enter the following command: 
30898 \newline
30899
30900 \newline
30901
30902 \family sans
30903 \series bold
30904 ESC-x sdcdbsrc
30905 \family default
30906 \series default
30907
30908 \newline
30909
30910 \newline
30911 You will prompted to enter the file name to be debugged.
30912  
30913 \newline
30914
30915 \newline
30916 The command line options that are passed to the simulator directly are
30917  bound to default values in the file sdcdbsrc.el.
30918  The variables are listed below, these values maybe changed as required.
30919 \end_layout
30920
30921 \begin_layout Itemize
30922 sdcdbsrc-cpu-type '51
30923 \end_layout
30924
30925 \begin_layout Itemize
30926 sdcdbsrc-frequency '11059200
30927 \end_layout
30928
30929 \begin_layout Itemize
30930 sdcdbsrc-serial nil
30931 \end_layout
30932
30933 \begin_layout Standard
30934 The following is a list of key mapping for the debugger interface.
30935 \end_layout
30936
30937 \begin_layout Standard
30938 \InsetSpace ~
30939
30940 \family typewriter
30941
30942 \newline
30943 ;;\InsetSpace ~
30944 Current Listing :: 
30945 \newline
30946 ;;key\InsetSpace ~
30947 \InsetSpace ~
30948 \InsetSpace ~
30949 \InsetSpace ~
30950 \InsetSpace ~
30951 \InsetSpace ~
30952 \InsetSpace ~
30953 \InsetSpace ~
30954 \InsetSpace ~
30955 \InsetSpace ~
30956 \InsetSpace ~
30957 \InsetSpace ~
30958 \InsetSpace ~
30959 \InsetSpace ~
30960 binding\InsetSpace ~
30961 \InsetSpace ~
30962 \InsetSpace ~
30963 \InsetSpace ~
30964 \InsetSpace ~
30965 \InsetSpace ~
30966 \InsetSpace ~
30967 \InsetSpace ~
30968 \InsetSpace ~
30969 \InsetSpace ~
30970 \InsetSpace ~
30971 \InsetSpace ~
30972 \InsetSpace ~
30973 \InsetSpace ~
30974 \InsetSpace ~
30975 \InsetSpace ~
30976 \InsetSpace ~
30977 \InsetSpace ~
30978 \InsetSpace ~
30979 \InsetSpace ~
30980 \InsetSpace ~
30981 \InsetSpace ~
30982 Comment 
30983 \newline
30984 ;;---\InsetSpace ~
30985 \InsetSpace ~
30986 \InsetSpace ~
30987 \InsetSpace ~
30988 \InsetSpace ~
30989 \InsetSpace ~
30990 \InsetSpace ~
30991 \InsetSpace ~
30992 \InsetSpace ~
30993 \InsetSpace ~
30994 \InsetSpace ~
30995 \InsetSpace ~
30996 \InsetSpace ~
30997 \InsetSpace ~
30998 -------\InsetSpace ~
30999 \InsetSpace ~
31000 \InsetSpace ~
31001 \InsetSpace ~
31002 \InsetSpace ~
31003 \InsetSpace ~
31004 \InsetSpace ~
31005 \InsetSpace ~
31006 \InsetSpace ~
31007 \InsetSpace ~
31008 \InsetSpace ~
31009 \InsetSpace ~
31010 \InsetSpace ~
31011 \InsetSpace ~
31012 \InsetSpace ~
31013 \InsetSpace ~
31014 \InsetSpace ~
31015 \InsetSpace ~
31016 \InsetSpace ~
31017 \InsetSpace ~
31018 \InsetSpace ~
31019 \InsetSpace ~
31020 -------
31021 \newline
31022 ;; 
31023 \newline
31024 ;;\InsetSpace ~
31025 n\InsetSpace ~
31026 \InsetSpace ~
31027 \InsetSpace ~
31028 \InsetSpace ~
31029 \InsetSpace ~
31030 \InsetSpace ~
31031 \InsetSpace ~
31032 \InsetSpace ~
31033 \InsetSpace ~
31034 \InsetSpace ~
31035 \InsetSpace ~
31036 \InsetSpace ~
31037 \InsetSpace ~
31038 \InsetSpace ~
31039 \InsetSpace ~
31040 sdcdb-next-fro
31041 m-src\InsetSpace ~
31042 \InsetSpace ~
31043 \InsetSpace ~
31044 \InsetSpace ~
31045 \InsetSpace ~
31046 \InsetSpace ~
31047 \InsetSpace ~
31048 \InsetSpace ~
31049 \InsetSpace ~
31050 \InsetSpace ~
31051 SDCDB next command 
31052 \newline
31053 ;;\InsetSpace ~
31054 b\InsetSpace ~
31055 \InsetSpace ~
31056 \InsetSpace ~
31057 \InsetSpace ~
31058 \InsetSpace ~
31059 \InsetSpace ~
31060 \InsetSpace ~
31061 \InsetSpace ~
31062 \InsetSpace ~
31063 \InsetSpace ~
31064 \InsetSpace ~
31065 \InsetSpace ~
31066 \InsetSpace ~
31067 \InsetSpace ~
31068 \InsetSpace ~
31069 sdcdb-back-from-src\InsetSpace ~
31070 \InsetSpace ~
31071 \InsetSpace ~
31072 \InsetSpace ~
31073 \InsetSpace ~
31074 \InsetSpace ~
31075 \InsetSpace ~
31076 \InsetSpace ~
31077 \InsetSpace ~
31078 \InsetSpace ~
31079 SDCDB back command 
31080 \newline
31081 ;;\InsetSpace ~
31082 c\InsetSpace ~
31083 \InsetSpace ~
31084 \InsetSpace ~
31085 \InsetSpace ~
31086 \InsetSpace ~
31087 \InsetSpace ~
31088 \InsetSpace ~
31089 \InsetSpace ~
31090 \InsetSpace ~
31091 \InsetSpace ~
31092 \InsetSpace ~
31093 \InsetSpace ~
31094 \InsetSpace ~
31095 \InsetSpace ~
31096 \InsetSpace ~
31097 sdcdb-cont-f
31098 rom-src\InsetSpace ~
31099 \InsetSpace ~
31100 \InsetSpace ~
31101 \InsetSpace ~
31102 \InsetSpace ~
31103 \InsetSpace ~
31104 \InsetSpace ~
31105 \InsetSpace ~
31106 \InsetSpace ~
31107 \InsetSpace ~
31108 SDCDB continue command
31109 \newline
31110 ;;\InsetSpace ~
31111 s\InsetSpace ~
31112 \InsetSpace ~
31113 \InsetSpace ~
31114 \InsetSpace ~
31115 \InsetSpace ~
31116 \InsetSpace ~
31117 \InsetSpace ~
31118 \InsetSpace ~
31119 \InsetSpace ~
31120 \InsetSpace ~
31121 \InsetSpace ~
31122 \InsetSpace ~
31123 \InsetSpace ~
31124 \InsetSpace ~
31125 \InsetSpace ~
31126 sdcdb-step-from-src\InsetSpace ~
31127 \InsetSpace ~
31128 \InsetSpace ~
31129 \InsetSpace ~
31130 \InsetSpace ~
31131 \InsetSpace ~
31132 \InsetSpace ~
31133 \InsetSpace ~
31134 \InsetSpace ~
31135 \InsetSpace ~
31136 SDCDB step command 
31137 \newline
31138 ;;\InsetSpace ~
31139 ?\InsetSpace ~
31140 \InsetSpace ~
31141 \InsetSpace ~
31142 \InsetSpace ~
31143 \InsetSpace ~
31144 \InsetSpace ~
31145 \InsetSpace ~
31146 \InsetSpace ~
31147 \InsetSpace ~
31148 \InsetSpace ~
31149 \InsetSpace ~
31150 \InsetSpace ~
31151 \InsetSpace ~
31152 \InsetSpace ~
31153 \InsetSpace ~
31154 sdcdb-w
31155 hatis-c-sexp\InsetSpace ~
31156 \InsetSpace ~
31157 \InsetSpace ~
31158 \InsetSpace ~
31159 \InsetSpace ~
31160 \InsetSpace ~
31161 \InsetSpace ~
31162 \InsetSpace ~
31163 \InsetSpace ~
31164 \InsetSpace ~
31165 SDCDB ptypecommand for data at 
31166 \newline
31167 ;;\InsetSpace ~
31168 \InsetSpace ~
31169 \InsetSpace ~
31170 \InsetSpace ~
31171 \InsetSpace ~
31172 \InsetSpace ~
31173 \InsetSpace ~
31174 \InsetSpace ~
31175 \InsetSpace ~
31176 \InsetSpace ~
31177 \InsetSpace ~
31178 \InsetSpace ~
31179 \InsetSpace ~
31180 \InsetSpace ~
31181 \InsetSpace ~
31182 \InsetSpace ~
31183 \InsetSpace ~
31184 \InsetSpace ~
31185 \InsetSpace ~
31186 \InsetSpace ~
31187 \InsetSpace ~
31188 \InsetSpace ~
31189 \InsetSpace ~
31190 \InsetSpace ~
31191 \InsetSpace ~
31192 \InsetSpace ~
31193 \InsetSpace ~
31194 \InsetSpace ~
31195 \InsetSpace ~
31196 \InsetSpace ~
31197 \InsetSpace ~
31198 \InsetSpace ~
31199 \InsetSpace ~
31200 \InsetSpace ~
31201 \InsetSpace ~
31202 \InsetSpace ~
31203 \InsetSpace ~
31204 \InsetSpace ~
31205 \InsetSpace ~
31206 \InsetSpace ~
31207 \InsetSpace ~
31208 \InsetSpace ~
31209 \InsetSpace ~
31210 \InsetSpace ~
31211 \InsetSpace ~
31212 \InsetSpace ~
31213 \InsetSpace ~
31214 buffer point 
31215 \newline
31216 ;;\InsetSpace ~
31217 x\InsetSpace ~
31218 \InsetSpace ~
31219 \InsetSpace ~
31220 \InsetSpace ~
31221 \InsetSpace ~
31222 \InsetSpace ~
31223 \InsetSpace ~
31224 \InsetSpace ~
31225 \InsetSpace ~
31226 \InsetSpace ~
31227 \InsetSpace ~
31228 \InsetSpace ~
31229 \InsetSpace ~
31230 \InsetSpace ~
31231 \InsetSpace ~
31232 sdcdbsrc-delete\InsetSpace ~
31233 \InsetSpace ~
31234 \InsetSpace ~
31235 \InsetSpace ~
31236 \InsetSpace ~
31237 \InsetSpace ~
31238 \InsetSpace ~
31239 \InsetSpace ~
31240 \InsetSpace ~
31241 \InsetSpace ~
31242 \InsetSpace ~
31243 \InsetSpace ~
31244 \InsetSpace ~
31245 \InsetSpace ~
31246 SDCD
31247 B Delete all breakpoints if no arg 
31248 \newline
31249 ;;\InsetSpace ~
31250 \InsetSpace ~
31251 \InsetSpace ~
31252 \InsetSpace ~
31253 \InsetSpace ~
31254 \InsetSpace ~
31255 \InsetSpace ~
31256 \InsetSpace ~
31257 \InsetSpace ~
31258 \InsetSpace ~
31259 \InsetSpace ~
31260 \InsetSpace ~
31261 \InsetSpace ~
31262 \InsetSpace ~
31263 \InsetSpace ~
31264 \InsetSpace ~
31265 \InsetSpace ~
31266 \InsetSpace ~
31267 \InsetSpace ~
31268 \InsetSpace ~
31269 \InsetSpace ~
31270 \InsetSpace ~
31271 \InsetSpace ~
31272 \InsetSpace ~
31273 \InsetSpace ~
31274 \InsetSpace ~
31275 \InsetSpace ~
31276 \InsetSpace ~
31277 \InsetSpace ~
31278 \InsetSpace ~
31279 \InsetSpace ~
31280 \InsetSpace ~
31281 \InsetSpace ~
31282 \InsetSpace ~
31283 \InsetSpace ~
31284 \InsetSpace ~
31285 \InsetSpace ~
31286 \InsetSpace ~
31287 \InsetSpace ~
31288 \InsetSpace ~
31289 \InsetSpace ~
31290 \InsetSpace ~
31291 \InsetSpace ~
31292 \InsetSpace ~
31293 \InsetSpace ~
31294 \InsetSpace ~
31295 \InsetSpace ~
31296 given or delete arg (C-u arg x) 
31297 \newline
31298 ;;\InsetSpace ~
31299 m\InsetSpace ~
31300 \InsetSpace ~
31301 \InsetSpace ~
31302 \InsetSpace ~
31303 \InsetSpace ~
31304 \InsetSpace ~
31305 \InsetSpace ~
31306 \InsetSpace ~
31307 \InsetSpace ~
31308 \InsetSpace ~
31309 \InsetSpace ~
31310 \InsetSpace ~
31311 \InsetSpace ~
31312 \InsetSpace ~
31313 \InsetSpace ~
31314 sdcdbsrc
31315 -frame\InsetSpace ~
31316 \InsetSpace ~
31317 \InsetSpace ~
31318 \InsetSpace ~
31319 \InsetSpace ~
31320 \InsetSpace ~
31321 \InsetSpace ~
31322 \InsetSpace ~
31323 \InsetSpace ~
31324 \InsetSpace ~
31325 \InsetSpace ~
31326 \InsetSpace ~
31327 \InsetSpace ~
31328 \InsetSpace ~
31329 \InsetSpace ~
31330 SDCDB Display current frame if no arg, 
31331 \newline
31332 ;;\InsetSpace ~
31333 \InsetSpace ~
31334 \InsetSpace ~
31335 \InsetSpace ~
31336 \InsetSpace ~
31337 \InsetSpace ~
31338 \InsetSpace ~
31339 \InsetSpace ~
31340 \InsetSpace ~
31341 \InsetSpace ~
31342 \InsetSpace ~
31343 \InsetSpace ~
31344 \InsetSpace ~
31345 \InsetSpace ~
31346 \InsetSpace ~
31347 \InsetSpace ~
31348 \InsetSpace ~
31349 \InsetSpace ~
31350 \InsetSpace ~
31351 \InsetSpace ~
31352 \InsetSpace ~
31353 \InsetSpace ~
31354 \InsetSpace ~
31355 \InsetSpace ~
31356 \InsetSpace ~
31357 \InsetSpace ~
31358 \InsetSpace ~
31359 \InsetSpace ~
31360 \InsetSpace ~
31361 \InsetSpace ~
31362 \InsetSpace ~
31363 \InsetSpace ~
31364 \InsetSpace ~
31365 \InsetSpace ~
31366 \InsetSpace ~
31367 \InsetSpace ~
31368 \InsetSpace ~
31369 \InsetSpace ~
31370 \InsetSpace ~
31371 \InsetSpace ~
31372 \InsetSpace ~
31373 \InsetSpace ~
31374 \InsetSpace ~
31375 \InsetSpace ~
31376 \InsetSpace ~
31377 \InsetSpace ~
31378 \InsetSpace ~
31379 given or display frame arg
31380  
31381 \newline
31382 ;;\InsetSpace ~
31383 \InsetSpace ~
31384 \InsetSpace ~
31385 \InsetSpace ~
31386 \InsetSpace ~
31387 \InsetSpace ~
31388 \InsetSpace ~
31389 \InsetSpace ~
31390 \InsetSpace ~
31391 \InsetSpace ~
31392 \InsetSpace ~
31393 \InsetSpace ~
31394 \InsetSpace ~
31395 \InsetSpace ~
31396 \InsetSpace ~
31397 \InsetSpace ~
31398 \InsetSpace ~
31399 \InsetSpace ~
31400 \InsetSpace ~
31401 \InsetSpace ~
31402 \InsetSpace ~
31403 \InsetSpace ~
31404 \InsetSpace ~
31405 \InsetSpace ~
31406 \InsetSpace ~
31407 \InsetSpace ~
31408 \InsetSpace ~
31409 \InsetSpace ~
31410 \InsetSpace ~
31411 \InsetSpace ~
31412 \InsetSpace ~
31413 \InsetSpace ~
31414 \InsetSpace ~
31415 \InsetSpace ~
31416 \InsetSpace ~
31417 \InsetSpace ~
31418 \InsetSpace ~
31419 \InsetSpace ~
31420 \InsetSpace ~
31421 \InsetSpace ~
31422 \InsetSpace ~
31423 \InsetSpace ~
31424 \InsetSpace ~
31425 \InsetSpace ~
31426 \InsetSpace ~
31427 \InsetSpace ~
31428 \InsetSpace ~
31429 buffer point 
31430 \newline
31431 ;;\InsetSpace ~
31432 !\InsetSpace ~
31433 \InsetSpace ~
31434 \InsetSpace ~
31435 \InsetSpace ~
31436 \InsetSpace ~
31437 \InsetSpace ~
31438 \InsetSpace ~
31439 \InsetSpace ~
31440 \InsetSpace ~
31441 \InsetSpace ~
31442 \InsetSpace ~
31443 \InsetSpace ~
31444 \InsetSpace ~
31445 \InsetSpace ~
31446 \InsetSpace ~
31447 sdcdbsrc-goto-sdcdb\InsetSpace ~
31448 \InsetSpace ~
31449 \InsetSpace ~
31450 \InsetSpace ~
31451 \InsetSpace ~
31452 \InsetSpace ~
31453 \InsetSpace ~
31454 \InsetSpace ~
31455 \InsetSpace ~
31456 \InsetSpace ~
31457 Goto the SDCDB output buffer 
31458 \newline
31459 ;;\InsetSpace ~
31460 p\InsetSpace ~
31461 \InsetSpace ~
31462 \InsetSpace ~
31463 \InsetSpace ~
31464 \InsetSpace ~
31465 \InsetSpace ~
31466 \InsetSpace ~
31467 \InsetSpace ~
31468 \InsetSpace ~
31469 \InsetSpace ~
31470 \InsetSpace ~
31471 \InsetSpace ~
31472 \InsetSpace ~
31473 \InsetSpace ~
31474 \InsetSpace ~
31475 sdcdb-prin
31476 t-c-sexp\InsetSpace ~
31477 \InsetSpace ~
31478 \InsetSpace ~
31479 \InsetSpace ~
31480 \InsetSpace ~
31481 \InsetSpace ~
31482 \InsetSpace ~
31483 \InsetSpace ~
31484 \InsetSpace ~
31485 \InsetSpace ~
31486 \InsetSpace ~
31487 SDCDB print command for data at 
31488 \newline
31489 ;;\InsetSpace ~
31490 \InsetSpace ~
31491 \InsetSpace ~
31492 \InsetSpace ~
31493 \InsetSpace ~
31494 \InsetSpace ~
31495 \InsetSpace ~
31496 \InsetSpace ~
31497 \InsetSpace ~
31498 \InsetSpace ~
31499 \InsetSpace ~
31500 \InsetSpace ~
31501 \InsetSpace ~
31502 \InsetSpace ~
31503 \InsetSpace ~
31504 \InsetSpace ~
31505 \InsetSpace ~
31506 \InsetSpace ~
31507 \InsetSpace ~
31508 \InsetSpace ~
31509 \InsetSpace ~
31510 \InsetSpace ~
31511 \InsetSpace ~
31512 \InsetSpace ~
31513 \InsetSpace ~
31514 \InsetSpace ~
31515 \InsetSpace ~
31516 \InsetSpace ~
31517 \InsetSpace ~
31518 \InsetSpace ~
31519 \InsetSpace ~
31520 \InsetSpace ~
31521 \InsetSpace ~
31522 \InsetSpace ~
31523 \InsetSpace ~
31524 \InsetSpace ~
31525 \InsetSpace ~
31526 \InsetSpace ~
31527 \InsetSpace ~
31528 \InsetSpace ~
31529 \InsetSpace ~
31530 \InsetSpace ~
31531 \InsetSpace ~
31532 \InsetSpace ~
31533 \InsetSpace ~
31534 \InsetSpace ~
31535 \InsetSpace ~
31536 buffer point 
31537 \newline
31538 ;;\InsetSpace ~
31539 g\InsetSpace ~
31540 \InsetSpace ~
31541 \InsetSpace ~
31542 \InsetSpace ~
31543 \InsetSpace ~
31544 \InsetSpace ~
31545 \InsetSpace ~
31546 \InsetSpace ~
31547 \InsetSpace ~
31548 \InsetSpace ~
31549 \InsetSpace ~
31550 \InsetSpace ~
31551 \InsetSpace ~
31552 \InsetSpace ~
31553 \InsetSpace ~
31554 sdcdbsrc-goto-sdcdb\InsetSpace ~
31555 \InsetSpace ~
31556 \InsetSpace ~
31557 \InsetSpace ~
31558 \InsetSpace ~
31559 \InsetSpace ~
31560 \InsetSpace ~
31561 \InsetSpace ~
31562 \InsetSpace ~
31563 \InsetSpace ~
31564 Got
31565 o the SDCDB output buffer 
31566 \newline
31567 ;;\InsetSpace ~
31568 t\InsetSpace ~
31569 \InsetSpace ~
31570 \InsetSpace ~
31571 \InsetSpace ~
31572 \InsetSpace ~
31573 \InsetSpace ~
31574 \InsetSpace ~
31575 \InsetSpace ~
31576 \InsetSpace ~
31577 \InsetSpace ~
31578 \InsetSpace ~
31579 \InsetSpace ~
31580 \InsetSpace ~
31581 \InsetSpace ~
31582 \InsetSpace ~
31583 sdcdbsrc-mode\InsetSpace ~
31584 \InsetSpace ~
31585 \InsetSpace ~
31586 \InsetSpace ~
31587 \InsetSpace ~
31588 \InsetSpace ~
31589 \InsetSpace ~
31590 \InsetSpace ~
31591 \InsetSpace ~
31592 \InsetSpace ~
31593 \InsetSpace ~
31594 \InsetSpace ~
31595 \InsetSpace ~
31596 \InsetSpace ~
31597 \InsetSpace ~
31598 \InsetSpace ~
31599 Toggles Sdcdbsrc mode (turns it
31600  off) 
31601 \newline
31602 ;; 
31603 \newline
31604 ;;\InsetSpace ~
31605 C-c\InsetSpace ~
31606 C-f\InsetSpace ~
31607 \InsetSpace ~
31608 \InsetSpace ~
31609 \InsetSpace ~
31610 \InsetSpace ~
31611 \InsetSpace ~
31612 \InsetSpace ~
31613 \InsetSpace ~
31614 \InsetSpace ~
31615 sdcdb-finish-from-src\InsetSpace ~
31616 \InsetSpace ~
31617 \InsetSpace ~
31618 \InsetSpace ~
31619 \InsetSpace ~
31620 \InsetSpace ~
31621 \InsetSpace ~
31622 \InsetSpace ~
31623 SDCDB finish command 
31624 \newline
31625 ;; 
31626 \newline
31627 ;;\InsetSpace ~
31628 C-x\InsetSpace ~
31629 SPC\InsetSpace ~
31630 \InsetSpace ~
31631 \InsetSpace ~
31632 \InsetSpace ~
31633 \InsetSpace ~
31634 \InsetSpace ~
31635 \InsetSpace ~
31636 \InsetSpace ~
31637 \InsetSpace ~
31638 sdcdb-brea
31639 k\InsetSpace ~
31640 \InsetSpace ~
31641 \InsetSpace ~
31642 \InsetSpace ~
31643 \InsetSpace ~
31644 \InsetSpace ~
31645 \InsetSpace ~
31646 \InsetSpace ~
31647 \InsetSpace ~
31648 \InsetSpace ~
31649 \InsetSpace ~
31650 \InsetSpace ~
31651 \InsetSpace ~
31652 \InsetSpace ~
31653 \InsetSpace ~
31654 \InsetSpace ~
31655 \InsetSpace ~
31656 \InsetSpace ~
31657 Set break for line with point 
31658 \newline
31659 ;;\InsetSpace ~
31660 ESC\InsetSpace ~
31661 t\InsetSpace ~
31662 \InsetSpace ~
31663 \InsetSpace ~
31664 \InsetSpace ~
31665 \InsetSpace ~
31666 \InsetSpace ~
31667 \InsetSpace ~
31668 \InsetSpace ~
31669 \InsetSpace ~
31670 \InsetSpace ~
31671 \InsetSpace ~
31672 sdcdbsrc-mode\InsetSpace ~
31673 \InsetSpace ~
31674 \InsetSpace ~
31675 \InsetSpace ~
31676 \InsetSpace ~
31677 \InsetSpace ~
31678 \InsetSpace ~
31679 \InsetSpace ~
31680 \InsetSpace ~
31681 \InsetSpace ~
31682 \InsetSpace ~
31683 \InsetSpace ~
31684 \InsetSpace ~
31685 \InsetSpace ~
31686 \InsetSpace ~
31687 \InsetSpace ~
31688 Toggle Sdcdbsrc mode 
31689 \newline
31690 ;;\InsetSpace ~
31691 ESC\InsetSpace ~
31692 m\InsetSpace ~
31693 \InsetSpace ~
31694 \InsetSpace ~
31695 \InsetSpace ~
31696 \InsetSpace ~
31697 \InsetSpace ~
31698 \InsetSpace ~
31699 \InsetSpace ~
31700 \InsetSpace ~
31701 \InsetSpace ~
31702 \InsetSpace ~
31703 sdc
31704 dbsrc-srcmode\InsetSpace ~
31705 \InsetSpace ~
31706 \InsetSpace ~
31707 \InsetSpace ~
31708 \InsetSpace ~
31709 \InsetSpace ~
31710 \InsetSpace ~
31711 \InsetSpace ~
31712 \InsetSpace ~
31713 \InsetSpace ~
31714 \InsetSpace ~
31715 \InsetSpace ~
31716 \InsetSpace ~
31717 Toggle list mode 
31718 \newline
31719 ;; 
31720 \newline
31721
31722 \family default
31723
31724 \newpage
31725
31726 \end_layout
31727
31728 \begin_layout Chapter
31729 TIPS
31730 \end_layout
31731
31732 \begin_layout Standard
31733 Here are a few guidelines that will help the compiler generate more efficient
31734  code, some of the tips are specific to this compiler others are generally
31735  good programming practice.
31736 \end_layout
31737
31738 \begin_layout Itemize
31739 Use the smallest data type to represent your data-value.
31740  If it is known in advance that the value is going to be less than 256 then
31741  use an 'unsigned char' instead of a 'short' or 'int'.
31742  Please note, that ANSI C requires both signed and unsigned chars to be
31743  promoted to 'signed int'
31744 \begin_inset LatexCommand index
31745 name "promotion to signed int"
31746
31747 \end_inset
31748
31749
31750 \begin_inset Marginal
31751 status collapsed
31752
31753 \begin_layout Standard
31754
31755 \series bold
31756 \InsetSpace ~
31757 !
31758 \end_layout
31759
31760 \end_inset
31761
31762  before doing any operation.
31763  This promotion
31764 \begin_inset LatexCommand index
31765 name "type promotion"
31766
31767 \end_inset
31768
31769
31770 \begin_inset LatexCommand label
31771 name "type promotion"
31772
31773 \end_inset
31774
31775  can be omitted, if the result is the same.
31776  The effect of the promotion rules together with the sign-extension is often
31777  surprising:
31778 \end_layout
31779
31780 \begin_deeper
31781 \begin_layout Verse
31782
31783 \family typewriter
31784 unsigned char uc = 0xfe;
31785 \newline
31786 if (uc * uc < 0) /* this is true! */
31787 \newline
31788 {
31789 \newline
31790 \InsetSpace ~
31791 \InsetSpace ~
31792 \InsetSpace ~
31793 \InsetSpace ~
31794 ....
31795 \newline
31796 }
31797 \end_layout
31798
31799 \begin_layout Standard
31800
31801 \family typewriter
31802 uc * uc
31803 \family default
31804  is evaluated as 
31805 \family typewriter
31806 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
31807 \family default
31808 .
31809  
31810 \newline
31811 Another one:
31812 \end_layout
31813
31814 \begin_layout Verse
31815
31816 \family typewriter
31817 (unsigned char) -12 / (signed char) -3 = ...
31818 \end_layout
31819
31820 \begin_layout Standard
31821 No, the result is not 4:
31822 \end_layout
31823
31824 \begin_layout Verse
31825
31826 \family typewriter
31827 (int) (unsigned char) -12 / (int) (signed char) -3 =
31828 \newline
31829 (int) (unsigned char)
31830  0xf4 / (int) (signed char) 0xfd =
31831 \newline
31832 (int) 0x00f4 / (int) 0xfffd =
31833 \newline
31834 (int) 0x00f4
31835  / (int) 0xfffd =
31836 \newline
31837 (int) 244 / (int) -3 =
31838 \newline
31839 (int) -81 = (int) 0xffaf;
31840 \end_layout
31841
31842 \begin_layout Standard
31843 Don't complain, that gcc gives you a different result.
31844  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
31845  Therefore the results are different.
31846 \newline
31847 From 
31848 \begin_inset Quotes sld
31849 \end_inset
31850
31851 comp.lang.c FAQ
31852 \begin_inset Quotes srd
31853 \end_inset
31854
31855 :
31856 \end_layout
31857
31858 \begin_layout Quote
31859
31860 \emph on
31861 If well-defined overflow characteristics are important and negative values
31862  are not, or if you want to steer clear of sign-extension problems when
31863  manipulating bits or bytes, use one of the corresponding unsigned types.
31864  (Beware when mixing signed and unsigned values in expressions, though.)
31865 \newline
31866 Although
31867  character types (especially unsigned char) can be used as "tiny" integers,
31868  doing so is sometimes more trouble than it's worth, due to unpredictable
31869  sign extension and increased code size.
31870 \end_layout
31871
31872 \end_deeper
31873 \begin_layout Itemize
31874 Use unsigned when it is known in advance that the value is not going to
31875  be negative.
31876  This helps especially if you are doing division or multiplication, bit-shifting
31877  or are using an array index.
31878 \end_layout
31879
31880 \begin_layout Itemize
31881 NEVER jump into a LOOP.
31882 \end_layout
31883
31884 \begin_layout Itemize
31885 Declare the variables to be local
31886 \begin_inset LatexCommand index
31887 name "local variables"
31888
31889 \end_inset
31890
31891  whenever possible, especially loop control variables (induction).
31892 \end_layout
31893
31894 \begin_layout Itemize
31895 Have a look at the assembly listing to get a 
31896 \begin_inset Quotes sld
31897 \end_inset
31898
31899 feeling
31900 \begin_inset Quotes srd
31901 \end_inset
31902
31903  for the code generation.
31904 \end_layout
31905
31906 \begin_layout Section
31907 Porting code from or to other compilers
31908 \begin_inset LatexCommand label
31909 name "sec:Porting-code-to-other-compilers"
31910
31911 \end_inset
31912
31913
31914 \end_layout
31915
31916 \begin_layout Itemize
31917 check whether endianness of the compilers differs and adapt where needed.
31918 \end_layout
31919
31920 \begin_layout Itemize
31921 check the device specific header files
31922 \begin_inset LatexCommand index
31923 name "Header files"
31924
31925 \end_inset
31926
31927
31928 \begin_inset LatexCommand index
31929 name "Include files"
31930
31931 \end_inset
31932
31933  for compiler specific syntax.
31934  Eventually include the file <compiler.h
31935 \begin_inset LatexCommand index
31936 name "compiler.h (include file)"
31937
31938 \end_inset
31939
31940
31941 \begin_inset LatexCommand url
31942 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup"
31943
31944 \end_inset
31945
31946  to allow using common header files.
31947  (see f.e.
31948  cc2510fx.h 
31949 \begin_inset LatexCommand url
31950 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup"
31951
31952 \end_inset
31953
31954 ).
31955 \end_layout
31956
31957 \begin_layout Itemize
31958 check whether the startup code contains the correct initialization (watchdog,
31959  peripherals).
31960 \end_layout
31961
31962 \begin_layout Itemize
31963 check whether the sizes of short, int, long match.
31964 \end_layout
31965
31966 \begin_layout Itemize
31967 check if some 16 or 32 bit hardware registers require a specific addressing
31968  order (least significant or most significant byte first) and adapt if needed
31969  (
31970 \emph on
31971 first
31972 \emph default
31973  and 
31974 \emph on
31975 last
31976 \emph default
31977  relate to time and not to lower/upper memory location here, so this is
31978  
31979 \emph on
31980 not
31981 \emph default
31982  the same as endianness).
31983 \end_layout
31984
31985 \begin_layout Itemize
31986 check whether the keyword 
31987 \emph on
31988 volatile
31989 \emph default
31990  is used where needed.
31991  The compilers might differ in their optimization characteristics (as different
31992  versions of the same compiler might also use more clever optimizations
31993  this is good idea anyway).
31994  See section 
31995 \begin_inset LatexCommand ref
31996 reference "sub:Common-interrupt-pitfall-volatile"
31997
31998 \end_inset
31999
32000 .
32001 \end_layout
32002
32003 \begin_layout Itemize
32004 check that the compilers are not told to suppress warnings.
32005 \end_layout
32006
32007 \begin_layout Itemize
32008 check and convert compiler specific extensions (interrupts, memory areas,
32009  pragmas etc.).
32010 \end_layout
32011
32012 \begin_layout Itemize
32013 check for differences in type promotion.
32014  Especially check for math operations on 
32015 \family typewriter
32016 char
32017 \family default
32018  or 
32019 \family typewriter
32020 unsigned char
32021 \family default
32022  variables.
32023  For the sake of C99 compatibility SDCC will probably promote these to 
32024 \family typewriter
32025 int
32026 \family default
32027  more often than other compilers.
32028  Eventually insert explicit casts to 
32029 \family typewriter
32030 (char)
32031 \family default
32032  or 
32033 \family typewriter
32034 (unsigned char)
32035 \family default
32036 .
32037  Also check that the ~\InsetSpace ~
32038 operator
32039 \begin_inset LatexCommand index
32040 name "\\~\\/ Operator"
32041
32042 \end_inset
32043
32044  is not used on 
32045 \family typewriter
32046 bit
32047 \begin_inset LatexCommand index
32048 name "bit"
32049
32050 \end_inset
32051
32052
32053 \family default
32054  variables, use the !\InsetSpace ~
32055 operator instead.
32056  See sections 
32057 \begin_inset LatexCommand ref
32058 reference "type promotion"
32059
32060 \end_inset
32061
32062  and 
32063 \begin_inset LatexCommand ref
32064 reference "sec:Compatibility-with-previous"
32065
32066 \end_inset
32067
32068 .
32069 \end_layout
32070
32071 \begin_layout Itemize
32072 check the assembly code generated for interrupt routines (f.e.
32073  for calls to possibly non-reentrant library functions).
32074 \end_layout
32075
32076 \begin_layout Itemize
32077 check whether timing loops result in proper timing (or preferably consider
32078  a rewrite of the code with timer based delays instead).
32079 \end_layout
32080
32081 \begin_layout Itemize
32082 check for differences in printf parameters (some compilers push (va_arg
32083 \begin_inset LatexCommand index
32084 name "vararg, va\\_arg"
32085
32086 \end_inset
32087
32088 ) char variables as 
32089 \family typewriter
32090 int
32091 \family default
32092  others push them as 
32093 \family typewriter
32094 char
32095 \family default
32096 .
32097  See section 
32098 \begin_inset LatexCommand ref
32099 reference "sec:Compatibility-with-previous"
32100
32101 \end_inset
32102
32103 ).
32104 \end_layout
32105
32106 \begin_layout Itemize
32107 check the resulting memory map
32108 \begin_inset LatexCommand index
32109 name "Memory map"
32110
32111 \end_inset
32112
32113 .
32114  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
32115 ly idata, pdata, xdata).
32116  Eventually check if unexpected library functions are included.
32117 \end_layout
32118
32119 \begin_layout Section
32120 Tools
32121 \begin_inset LatexCommand index
32122 name "Tools"
32123
32124 \end_inset
32125
32126  included in the distribution
32127 \end_layout
32128
32129 \begin_layout Standard
32130 \align left
32131 \begin_inset Tabular
32132 <lyxtabular version="3" rows="12" columns="3">
32133 <features>
32134 <column alignment="left" valignment="top" leftline="true" width="0pt">
32135 <column alignment="left" valignment="top" leftline="true" width="0pt">
32136 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
32137 <row topline="true" bottomline="true">
32138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32139 \begin_inset Text
32140
32141 \begin_layout Standard
32142
32143 \series bold
32144 Name
32145 \end_layout
32146
32147 \end_inset
32148 </cell>
32149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32150 \begin_inset Text
32151
32152 \begin_layout Standard
32153
32154 \series bold
32155 Purpose
32156 \end_layout
32157
32158 \end_inset
32159 </cell>
32160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32161 \begin_inset Text
32162
32163 \begin_layout Standard
32164
32165 \series bold
32166 Directory
32167 \end_layout
32168
32169 \end_inset
32170 </cell>
32171 </row>
32172 <row topline="true">
32173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32174 \begin_inset Text
32175
32176 \begin_layout Standard
32177 uCsim
32178 \begin_inset LatexCommand index
32179 name "uCsim"
32180
32181 \end_inset
32182
32183
32184 \end_layout
32185
32186 \end_inset
32187 </cell>
32188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32189 \begin_inset Text
32190
32191 \begin_layout Standard
32192 Simulator for various architectures
32193 \end_layout
32194
32195 \end_inset
32196 </cell>
32197 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32198 \begin_inset Text
32199
32200 \begin_layout Standard
32201 sdcc/sim/ucsim
32202 \end_layout
32203
32204 \end_inset
32205 </cell>
32206 </row>
32207 <row topline="true">
32208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32209 \begin_inset Text
32210
32211 \begin_layout Standard
32212 keil2sdcc.pl
32213 \end_layout
32214
32215 \end_inset
32216 </cell>
32217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32218 \begin_inset Text
32219
32220 \begin_layout Standard
32221 header file
32222 \begin_inset LatexCommand index
32223 name "Header files"
32224
32225 \end_inset
32226
32227
32228 \begin_inset LatexCommand index
32229 name "Include files"
32230
32231 \end_inset
32232
32233  conversion
32234 \end_layout
32235
32236 \end_inset
32237 </cell>
32238 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32239 \begin_inset Text
32240
32241 \begin_layout Standard
32242 sdcc/support/scripts
32243 \end_layout
32244
32245 \end_inset
32246 </cell>
32247 </row>
32248 <row topline="true">
32249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32250 \begin_inset Text
32251
32252 \begin_layout Standard
32253 mh2h.c
32254 \end_layout
32255
32256 \end_inset
32257 </cell>
32258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32259 \begin_inset Text
32260
32261 \begin_layout Standard
32262 header file conversion
32263 \end_layout
32264
32265 \end_inset
32266 </cell>
32267 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32268 \begin_inset Text
32269
32270 \begin_layout Standard
32271 sdcc/support/scripts
32272 \end_layout
32273
32274 \end_inset
32275 </cell>
32276 </row>
32277 <row topline="true">
32278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32279 \begin_inset Text
32280
32281 \begin_layout Standard
32282 as-gbz80
32283 \end_layout
32284
32285 \end_inset
32286 </cell>
32287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32288 \begin_inset Text
32289
32290 \begin_layout Standard
32291 Assembler
32292 \end_layout
32293
32294 \end_inset
32295 </cell>
32296 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32297 \begin_inset Text
32298
32299 \begin_layout Standard
32300
32301 \family roman
32302 \series medium
32303 \shape up
32304 \size normal
32305 \emph off
32306 \bar no
32307 \noun off
32308 \color none
32309 sdcc/bin
32310 \end_layout
32311
32312 \end_inset
32313 </cell>
32314 </row>
32315 <row topline="true">
32316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32317 \begin_inset Text
32318
32319 \begin_layout Standard
32320 as-z80
32321 \end_layout
32322
32323 \end_inset
32324 </cell>
32325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32326 \begin_inset Text
32327
32328 \begin_layout Standard
32329 Assembler
32330 \end_layout
32331
32332 \end_inset
32333 </cell>
32334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32335 \begin_inset Text
32336
32337 \begin_layout Standard
32338
32339 \family roman
32340 \series medium
32341 \shape up
32342 \size normal
32343 \emph off
32344 \bar no
32345 \noun off
32346 \color none
32347 sdcc/bin
32348 \end_layout
32349
32350 \end_inset
32351 </cell>
32352 </row>
32353 <row topline="true">
32354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32355 \begin_inset Text
32356
32357 \begin_layout Standard
32358 asx8051
32359 \end_layout
32360
32361 \end_inset
32362 </cell>
32363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32364 \begin_inset Text
32365
32366 \begin_layout Standard
32367 Assembler
32368 \end_layout
32369
32370 \end_inset
32371 </cell>
32372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32373 \begin_inset Text
32374
32375 \begin_layout Standard
32376
32377 \family roman
32378 \series medium
32379 \shape up
32380 \size normal
32381 \emph off
32382 \bar no
32383 \noun off
32384 \color none
32385 sdcc/bin
32386 \end_layout
32387
32388 \end_inset
32389 </cell>
32390 </row>
32391 <row topline="true">
32392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32393 \begin_inset Text
32394
32395 \begin_layout Standard
32396 SDCDB
32397 \end_layout
32398
32399 \end_inset
32400 </cell>
32401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32402 \begin_inset Text
32403
32404 \begin_layout Standard
32405 Simulator
32406 \end_layout
32407
32408 \end_inset
32409 </cell>
32410 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32411 \begin_inset Text
32412
32413 \begin_layout Standard
32414
32415 \family roman
32416 \series medium
32417 \shape up
32418 \size normal
32419 \emph off
32420 \bar no
32421 \noun off
32422 \color none
32423 sdcc/bin
32424 \end_layout
32425
32426 \end_inset
32427 </cell>
32428 </row>
32429 <row topline="true">
32430 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32431 \begin_inset Text
32432
32433 \begin_layout Standard
32434 aslink
32435 \end_layout
32436
32437 \end_inset
32438 </cell>
32439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32440 \begin_inset Text
32441
32442 \begin_layout Standard
32443 Linker
32444 \end_layout
32445
32446 \end_inset
32447 </cell>
32448 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32449 \begin_inset Text
32450
32451 \begin_layout Standard
32452
32453 \family roman
32454 \series medium
32455 \shape up
32456 \size normal
32457 \emph off
32458 \bar no
32459 \noun off
32460 \color none
32461 sdcc/bin
32462 \end_layout
32463
32464 \end_inset
32465 </cell>
32466 </row>
32467 <row topline="true">
32468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32469 \begin_inset Text
32470
32471 \begin_layout Standard
32472 link-z80
32473 \end_layout
32474
32475 \end_inset
32476 </cell>
32477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32478 \begin_inset Text
32479
32480 \begin_layout Standard
32481 Linker
32482 \end_layout
32483
32484 \end_inset
32485 </cell>
32486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32487 \begin_inset Text
32488
32489 \begin_layout Standard
32490
32491 \family roman
32492 \series medium
32493 \shape up
32494 \size normal
32495 \emph off
32496 \bar no
32497 \noun off
32498 \color none
32499 sdcc/bin
32500 \end_layout
32501
32502 \end_inset
32503 </cell>
32504 </row>
32505 <row topline="true">
32506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32507 \begin_inset Text
32508
32509 \begin_layout Standard
32510 link-gbz80
32511 \end_layout
32512
32513 \end_inset
32514 </cell>
32515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32516 \begin_inset Text
32517
32518 \begin_layout Standard
32519 Linker
32520 \end_layout
32521
32522 \end_inset
32523 </cell>
32524 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32525 \begin_inset Text
32526
32527 \begin_layout Standard
32528
32529 \family roman
32530 \series medium
32531 \shape up
32532 \size normal
32533 \emph off
32534 \bar no
32535 \noun off
32536 \color none
32537 sdcc/bin
32538 \end_layout
32539
32540 \end_inset
32541 </cell>
32542 </row>
32543 <row topline="true" bottomline="true">
32544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32545 \begin_inset Text
32546
32547 \begin_layout Standard
32548 packihx
32549 \end_layout
32550
32551 \end_inset
32552 </cell>
32553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32554 \begin_inset Text
32555
32556 \begin_layout Standard
32557 Intel Hex packer 
32558 \begin_inset LatexCommand index
32559 name "packihx (tool)"
32560
32561 \end_inset
32562
32563
32564 \end_layout
32565
32566 \end_inset
32567 </cell>
32568 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32569 \begin_inset Text
32570
32571 \begin_layout Standard
32572
32573 \family roman
32574 \series medium
32575 \shape up
32576 \size normal
32577 \emph off
32578 \bar no
32579 \noun off
32580 \color none
32581 sdcc/bin
32582 \end_layout
32583
32584 \end_inset
32585 </cell>
32586 </row>
32587 </lyxtabular>
32588
32589 \end_inset
32590
32591
32592 \newline
32593
32594 \end_layout
32595
32596 \begin_layout Section
32597 Documentation
32598 \begin_inset LatexCommand index
32599 name "Documentation"
32600
32601 \end_inset
32602
32603  included in the distribution
32604 \end_layout
32605
32606 \begin_layout Standard
32607 \align left
32608 \begin_inset Tabular
32609 <lyxtabular version="3" rows="10" columns="2">
32610 <features>
32611 <column alignment="block" valignment="top" leftline="true" width="40col%">
32612 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
32613 <row topline="true" bottomline="true" endhead="true">
32614 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32615 \begin_inset Text
32616
32617 \begin_layout Standard
32618
32619 \series bold
32620 Subject / Title
32621 \end_layout
32622
32623 \end_inset
32624 </cell>
32625 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32626 \begin_inset Text
32627
32628 \begin_layout Standard
32629
32630 \series bold
32631 Filename / Where to get
32632 \end_layout
32633
32634 \end_inset
32635 </cell>
32636 </row>
32637 <row topline="true">
32638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32639 \begin_inset Text
32640
32641 \begin_layout Standard
32642 SDCC Compiler User Guide
32643 \end_layout
32644
32645 \end_inset
32646 </cell>
32647 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32648 \begin_inset Text
32649
32650 \begin_layout Standard
32651 You're reading it right now 
32652 \emph on
32653 \InsetSpace ~
32654 \InsetSpace ~
32655 \InsetSpace ~
32656
32657 \hfill
32658 online at:
32659 \emph default
32660
32661 \newline
32662
32663 \begin_inset LatexCommand url
32664 target "http://sdcc.sourceforge.net/doc/sdccman.pdf"
32665
32666 \end_inset
32667
32668
32669 \end_layout
32670
32671 \end_inset
32672 </cell>
32673 </row>
32674 <row topline="true">
32675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32676 \begin_inset Text
32677
32678 \begin_layout Standard
32679 Changelog of SDCC
32680 \end_layout
32681
32682 \end_inset
32683 </cell>
32684 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32685 \begin_inset Text
32686
32687 \begin_layout Standard
32688 sdcc/Changelog 
32689 \emph on
32690 \InsetSpace ~
32691 \InsetSpace ~
32692 \InsetSpace ~
32693
32694 \hfill
32695 online at:
32696 \emph default
32697
32698 \newline
32699
32700 \begin_inset LatexCommand url
32701 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog"
32702
32703 \end_inset
32704
32705
32706 \end_layout
32707
32708 \end_inset
32709 </cell>
32710 </row>
32711 <row topline="true">
32712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32713 \begin_inset Text
32714
32715 \begin_layout Standard
32716 ASXXXX
32717 \begin_inset LatexCommand index
32718 name "asXXXX (as-gbz80, as-hc08, asx8051, as-z80)"
32719
32720 \end_inset
32721
32722
32723 \begin_inset LatexCommand index
32724 name "Assembler documentation"
32725
32726 \end_inset
32727
32728  Assemblers and
32729 \newline
32730 ASLINK
32731 \begin_inset LatexCommand index
32732 name "aslink"
32733
32734 \end_inset
32735
32736
32737 \begin_inset LatexCommand index
32738 name "Linker documentation"
32739
32740 \end_inset
32741
32742  Relocating Linker
32743 \end_layout
32744
32745 \end_inset
32746 </cell>
32747 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32748 \begin_inset Text
32749
32750 \begin_layout Standard
32751 sdcc/as/doc/asxhtm.html 
32752 \emph on
32753 \InsetSpace ~
32754 \InsetSpace ~
32755 \InsetSpace ~
32756
32757 \hfill
32758 online at:
32759 \emph default
32760
32761 \newline
32762
32763 \begin_inset LatexCommand url
32764 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html"
32765
32766 \end_inset
32767
32768
32769 \end_layout
32770
32771 \end_inset
32772 </cell>
32773 </row>
32774 <row topline="true">
32775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32776 \begin_inset Text
32777
32778 \begin_layout Standard
32779 SDCC regression test
32780 \begin_inset LatexCommand index
32781 name "Regression test"
32782
32783 \end_inset
32784
32785
32786 \end_layout
32787
32788 \end_inset
32789 </cell>
32790 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32791 \begin_inset Text
32792
32793 \begin_layout Standard
32794 sdcc/doc/test_suite_spec.pdf 
32795 \emph on
32796 \InsetSpace ~
32797 \InsetSpace ~
32798 \InsetSpace ~
32799
32800 \hfill
32801 online at:
32802 \emph default
32803
32804 \newline
32805
32806 \begin_inset LatexCommand url
32807 target "http://sdcc.sourceforge.net/doc/test_suite_spec.pdf"
32808
32809 \end_inset
32810
32811
32812 \end_layout
32813
32814 \end_inset
32815 </cell>
32816 </row>
32817 <row topline="true">
32818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32819 \begin_inset Text
32820
32821 \begin_layout Standard
32822 Various notes
32823 \end_layout
32824
32825 \end_inset
32826 </cell>
32827 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32828 \begin_inset Text
32829
32830 \begin_layout Standard
32831 sdcc/doc/* 
32832 \emph on
32833 \InsetSpace ~
32834 \InsetSpace ~
32835 \InsetSpace ~
32836
32837 \hfill
32838 online at:
32839 \emph default
32840
32841 \newline
32842
32843 \begin_inset LatexCommand url
32844 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/"
32845
32846 \end_inset
32847
32848
32849 \end_layout
32850
32851 \end_inset
32852 </cell>
32853 </row>
32854 <row topline="true">
32855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32856 \begin_inset Text
32857
32858 \begin_layout Standard
32859 Notes on debugging with SDCDB
32860 \begin_inset LatexCommand index
32861 name "SDCDB (debugger)"
32862
32863 \end_inset
32864
32865
32866 \end_layout
32867
32868 \end_inset
32869 </cell>
32870 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32871 \begin_inset Text
32872
32873 \begin_layout Standard
32874 sdcc/debugger/README 
32875 \emph on
32876 \InsetSpace ~
32877 \InsetSpace ~
32878 \InsetSpace ~
32879
32880 \hfill
32881 online at
32882 \emph default
32883 :
32884 \newline
32885
32886 \begin_inset LatexCommand url
32887 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README"
32888
32889 \end_inset
32890
32891
32892 \end_layout
32893
32894 \end_inset
32895 </cell>
32896 </row>
32897 <row topline="true">
32898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32899 \begin_inset Text
32900
32901 \begin_layout Standard
32902 uCsim
32903 \begin_inset LatexCommand index
32904 name "uCsim"
32905
32906 \end_inset
32907
32908  Software simulator for microcontrollers
32909 \end_layout
32910
32911 \end_inset
32912 </cell>
32913 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32914 \begin_inset Text
32915
32916 \begin_layout Standard
32917
32918 \family roman
32919 \series medium
32920 \shape up
32921 \size normal
32922 \emph off
32923 \bar no
32924 \noun off
32925 \color none
32926 sdcc/sim/ucsim/doc
32927 \family default
32928 \series default
32929 \shape default
32930 \size default
32931 \emph default
32932 \bar default
32933 \noun default
32934 /index.html 
32935 \emph on
32936 \InsetSpace ~
32937 \InsetSpace ~
32938 \InsetSpace ~
32939
32940 \hfill
32941 online at:
32942 \emph default
32943
32944 \newline
32945
32946 \begin_inset LatexCommand url
32947 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html"
32948
32949 \end_inset
32950
32951
32952 \end_layout
32953
32954 \end_inset
32955 </cell>
32956 </row>
32957 <row topline="true">
32958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32959 \begin_inset Text
32960
32961 \begin_layout Standard
32962 Temporary notes on the pic16
32963 \begin_inset LatexCommand index
32964 name "PIC16"
32965
32966 \end_inset
32967
32968  port
32969 \end_layout
32970
32971 \end_inset
32972 </cell>
32973 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32974 \begin_inset Text
32975
32976 \begin_layout Standard
32977 sdcc/src/pic16/NOTES 
32978 \emph on
32979 \InsetSpace ~
32980 \InsetSpace ~
32981 \InsetSpace ~
32982
32983 \hfill
32984 online at:
32985 \newline
32986
32987 \emph default
32988
32989 \begin_inset LatexCommand url
32990 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES"
32991
32992 \end_inset
32993
32994
32995 \end_layout
32996
32997 \end_inset
32998 </cell>
32999 </row>
33000 <row topline="true" bottomline="true">
33001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33002 \begin_inset Text
33003
33004 \begin_layout Standard
33005 SDCC internal documentation (debugging file format)
33006 \end_layout
33007
33008 \end_inset
33009 </cell>
33010 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33011 \begin_inset Text
33012
33013 \begin_layout Standard
33014 sdcc/doc/
33015 \family roman
33016 \series medium
33017 \shape up
33018 \size normal
33019 \emph off
33020 \bar no
33021 \noun off
33022 \color none
33023 cdbfileformat.pd
33024 \family default
33025 \series default
33026 \shape default
33027 \size default
33028 \emph default
33029 \bar default
33030 \noun default
33031
33032 \emph on
33033 \InsetSpace ~
33034 \InsetSpace ~
33035 \InsetSpace ~
33036
33037 \hfill
33038 online at:
33039 \emph default
33040
33041 \newline
33042
33043 \begin_inset LatexCommand url
33044 target "http://sdcc.sourceforge.net/doc/cdbfileformat.pdf"
33045
33046 \end_inset
33047
33048
33049 \end_layout
33050
33051 \end_inset
33052 </cell>
33053 </row>
33054 </lyxtabular>
33055
33056 \end_inset
33057
33058
33059 \newline
33060
33061 \end_layout
33062
33063 \begin_layout Section
33064 Related open source tools
33065 \begin_inset LatexCommand label
33066 name "sec:Related-open-source-tools"
33067
33068 \end_inset
33069
33070
33071 \begin_inset LatexCommand index
33072 name "Related tools"
33073
33074 \end_inset
33075
33076
33077 \end_layout
33078
33079 \begin_layout Standard
33080 \align left
33081 \begin_inset Tabular
33082 <lyxtabular version="3" rows="16" columns="3">
33083 <features>
33084 <column alignment="left" valignment="top" leftline="true" width="0pt">
33085 <column alignment="block" valignment="top" leftline="true" width="30line%">
33086 <column alignment="left" valignment="top" leftline="true" rightline="true" width="40col%">
33087 <row topline="true" bottomline="true">
33088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33089 \begin_inset Text
33090
33091 \begin_layout Standard
33092
33093 \series bold
33094 Name
33095 \end_layout
33096
33097 \end_inset
33098 </cell>
33099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33100 \begin_inset Text
33101
33102 \begin_layout Standard
33103
33104 \series bold
33105 Purpose
33106 \end_layout
33107
33108 \end_inset
33109 </cell>
33110 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33111 \begin_inset Text
33112
33113 \begin_layout Standard
33114
33115 \series bold
33116 Where to get
33117 \end_layout
33118
33119 \end_inset
33120 </cell>
33121 </row>
33122 <row topline="true">
33123 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33124 \begin_inset Text
33125
33126 \begin_layout Standard
33127 gpsim
33128 \begin_inset LatexCommand index
33129 name "gpsim (pic simulator)"
33130
33131 \end_inset
33132
33133
33134 \end_layout
33135
33136 \end_inset
33137 </cell>
33138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33139 \begin_inset Text
33140
33141 \begin_layout Standard
33142 PIC simulator
33143 \end_layout
33144
33145 \end_inset
33146 </cell>
33147 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33148 \begin_inset Text
33149
33150 \begin_layout Standard
33151 \begin_inset LatexCommand url
33152 target "http://www.dattalo.com/gnupic/gpsim.html"
33153
33154 \end_inset
33155
33156
33157 \end_layout
33158
33159 \end_inset
33160 </cell>
33161 </row>
33162 <row topline="true">
33163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33164 \begin_inset Text
33165
33166 \begin_layout Standard
33167 gputils
33168 \begin_inset LatexCommand index
33169 name "gputils (pic tools)"
33170
33171 \end_inset
33172
33173
33174 \end_layout
33175
33176 \end_inset
33177 </cell>
33178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33179 \begin_inset Text
33180
33181 \begin_layout Standard
33182 GNU PIC utilities
33183 \end_layout
33184
33185 \end_inset
33186 </cell>
33187 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33188 \begin_inset Text
33189
33190 \begin_layout Standard
33191 \begin_inset LatexCommand url
33192 target "http://sourceforge.net/projects/gputils"
33193
33194 \end_inset
33195
33196
33197 \end_layout
33198
33199 \end_inset
33200 </cell>
33201 </row>
33202 <row topline="true">
33203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33204 \begin_inset Text
33205
33206 \begin_layout Standard
33207 flP5
33208 \end_layout
33209
33210 \end_inset
33211 </cell>
33212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33213 \begin_inset Text
33214
33215 \begin_layout Standard
33216 PIC programmer
33217 \end_layout
33218
33219 \end_inset
33220 </cell>
33221 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33222 \begin_inset Text
33223
33224 \begin_layout Standard
33225 \begin_inset LatexCommand url
33226 target "http://freshmeat.net/projects/flp5/"
33227
33228 \end_inset
33229
33230
33231 \end_layout
33232
33233 \end_inset
33234 </cell>
33235 </row>
33236 <row topline="true">
33237 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33238 \begin_inset Text
33239
33240 \begin_layout Standard
33241 ec2drv/newcdb
33242 \end_layout
33243
33244 \end_inset
33245 </cell>
33246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33247 \begin_inset Text
33248
33249 \begin_layout Standard
33250 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
33251  (Unix only)
33252 \end_layout
33253
33254 \end_inset
33255 </cell>
33256 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33257 \begin_inset Text
33258
33259 \begin_layout Standard
33260 \begin_inset LatexCommand url
33261 target "http://sourceforge.net/projects/ec2drv"
33262
33263 \end_inset
33264
33265
33266 \end_layout
33267
33268 \end_inset
33269 </cell>
33270 </row>
33271 <row topline="true">
33272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33273 \begin_inset Text
33274
33275 \begin_layout Standard
33276 indent
33277 \begin_inset LatexCommand index
33278 name "indent (source formatting tool)"
33279
33280 \end_inset
33281
33282
33283 \end_layout
33284
33285 \end_inset
33286 </cell>
33287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33288 \begin_inset Text
33289
33290 \begin_layout Standard
33291 Formats C source - Master of the white spaces
33292 \end_layout
33293
33294 \end_inset
33295 </cell>
33296 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33297 \begin_inset Text
33298
33299 \begin_layout Standard
33300 \begin_inset LatexCommand url
33301 target "http://directory.fsf.org/GNU/indent.html"
33302
33303 \end_inset
33304
33305
33306 \end_layout
33307
33308 \end_inset
33309 </cell>
33310 </row>
33311 <row topline="true">
33312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33313 \begin_inset Text
33314
33315 \begin_layout Standard
33316 srecord
33317 \begin_inset LatexCommand index
33318 name "srecord (bin, hex, ... tool)"
33319
33320 \end_inset
33321
33322
33323 \end_layout
33324
33325 \end_inset
33326 </cell>
33327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33328 \begin_inset Text
33329
33330 \begin_layout Standard
33331 Object file conversion, checksumming, ...
33332 \end_layout
33333
33334 \end_inset
33335 </cell>
33336 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33337 \begin_inset Text
33338
33339 \begin_layout Standard
33340 \begin_inset LatexCommand url
33341 target "http://sourceforge.net/projects/srecord"
33342
33343 \end_inset
33344
33345
33346 \end_layout
33347
33348 \end_inset
33349 </cell>
33350 </row>
33351 <row topline="true">
33352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33353 \begin_inset Text
33354
33355 \begin_layout Standard
33356 objdump
33357 \begin_inset LatexCommand index
33358 name "objdump (tool)"
33359
33360 \end_inset
33361
33362
33363 \end_layout
33364
33365 \end_inset
33366 </cell>
33367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33368 \begin_inset Text
33369
33370 \begin_layout Standard
33371 Object file conversion, ...
33372 \end_layout
33373
33374 \end_inset
33375 </cell>
33376 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33377 \begin_inset Text
33378
33379 \begin_layout Standard
33380 Part of binutils (should be there anyway)
33381 \end_layout
33382
33383 \end_inset
33384 </cell>
33385 </row>
33386 <row topline="true">
33387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33388 \begin_inset Text
33389
33390 \begin_layout Standard
33391 cmon51
33392 \end_layout
33393
33394 \end_inset
33395 </cell>
33396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33397 \begin_inset Text
33398
33399 \begin_layout Standard
33400 8051 monitor (hex up-/download, single step, disassemble)
33401 \end_layout
33402
33403 \end_inset
33404 </cell>
33405 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33406 \begin_inset Text
33407
33408 \begin_layout Standard
33409 \begin_inset LatexCommand url
33410 target "http://sourceforge.net/projects/cmon51"
33411
33412 \end_inset
33413
33414
33415 \end_layout
33416
33417 \end_inset
33418 </cell>
33419 </row>
33420 <row topline="true">
33421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33422 \begin_inset Text
33423
33424 \begin_layout Standard
33425 doxygen
33426 \begin_inset LatexCommand index
33427 name "doxygen (source documentation tool)"
33428
33429 \end_inset
33430
33431
33432 \end_layout
33433
33434 \end_inset
33435 </cell>
33436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33437 \begin_inset Text
33438
33439 \begin_layout Standard
33440 Source code documentation system
33441 \end_layout
33442
33443 \end_inset
33444 </cell>
33445 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33446 \begin_inset Text
33447
33448 \begin_layout Standard
33449 \begin_inset LatexCommand url
33450 target "http://www.doxygen.org"
33451
33452 \end_inset
33453
33454
33455 \end_layout
33456
33457 \end_inset
33458 </cell>
33459 </row>
33460 <row topline="true">
33461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33462 \begin_inset Text
33463
33464 \begin_layout Standard
33465 kdevelop
33466 \end_layout
33467
33468 \end_inset
33469 </cell>
33470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33471 \begin_inset Text
33472
33473 \begin_layout Standard
33474 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
33475 \end_layout
33476
33477 \end_inset
33478 </cell>
33479 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33480 \begin_inset Text
33481
33482 \begin_layout Standard
33483 \begin_inset LatexCommand url
33484 target "http://www.kdevelop.org"
33485
33486 \end_inset
33487
33488
33489 \end_layout
33490
33491 \end_inset
33492 </cell>
33493 </row>
33494 <row topline="true">
33495 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33496 \begin_inset Text
33497
33498 \begin_layout Standard
33499 paulmon
33500 \end_layout
33501
33502 \end_inset
33503 </cell>
33504 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33505 \begin_inset Text
33506
33507 \begin_layout Standard
33508 8051 monitor (hex up-/download, single step, disassemble)
33509 \end_layout
33510
33511 \end_inset
33512 </cell>
33513 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33514 \begin_inset Text
33515
33516 \begin_layout Standard
33517 \begin_inset LatexCommand url
33518 target "http://www.pjrc.com/tech/8051/paulmon2.html"
33519
33520 \end_inset
33521
33522
33523 \end_layout
33524
33525 \end_inset
33526 </cell>
33527 </row>
33528 <row topline="true">
33529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33530 \begin_inset Text
33531
33532 \begin_layout Standard
33533 splint
33534 \begin_inset LatexCommand index
33535 name "splint (syntax checking tool)"
33536
33537 \end_inset
33538
33539
33540 \end_layout
33541
33542 \end_inset
33543 </cell>
33544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33545 \begin_inset Text
33546
33547 \begin_layout Standard
33548 Statically checks c sources (see 
33549 \begin_inset LatexCommand ref
33550 reference "lyx:more-pedantic-SPLINT"
33551
33552 \end_inset
33553
33554 )
33555 \end_layout
33556
33557 \end_inset
33558 </cell>
33559 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33560 \begin_inset Text
33561
33562 \begin_layout Standard
33563 \begin_inset LatexCommand url
33564 target "http://www.splint.org"
33565
33566 \end_inset
33567
33568
33569 \end_layout
33570
33571 \end_inset
33572 </cell>
33573 </row>
33574 <row topline="true" bottomline="true">
33575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33576 \begin_inset Text
33577
33578 \begin_layout Standard
33579 ddd
33580 \begin_inset LatexCommand index
33581 name "DDD (debugger)"
33582
33583 \end_inset
33584
33585
33586 \end_layout
33587
33588 \end_inset
33589 </cell>
33590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33591 \begin_inset Text
33592
33593 \begin_layout Standard
33594 Debugger, serves nicely as GUI to SDCDB
33595 \begin_inset LatexCommand index
33596 name "SDCDB (debugger)"
33597
33598 \end_inset
33599
33600  (Unix only)
33601 \end_layout
33602
33603 \end_inset
33604 </cell>
33605 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33606 \begin_inset Text
33607
33608 \begin_layout Standard
33609 \begin_inset LatexCommand url
33610 target "http://www.gnu.org/software/ddd/"
33611
33612 \end_inset
33613
33614
33615 \end_layout
33616
33617 \end_inset
33618 </cell>
33619 </row>
33620 <row bottomline="true">
33621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33622 \begin_inset Text
33623
33624 \begin_layout Standard
33625 d52
33626 \begin_inset LatexCommand index
33627 name "d52"
33628
33629 \end_inset
33630
33631
33632 \begin_inset LatexCommand index
33633 name "d52 (disassembler)"
33634
33635 \end_inset
33636
33637
33638 \end_layout
33639
33640 \end_inset
33641 </cell>
33642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33643 \begin_inset Text
33644
33645 \begin_layout Standard
33646 Disassembler, can count instruction cycles
33647 \begin_inset LatexCommand index
33648 name "instruction cycles (count)"
33649
33650 \end_inset
33651
33652 , use with options -pnd
33653 \end_layout
33654
33655 \end_inset
33656 </cell>
33657 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33658 \begin_inset Text
33659
33660 \begin_layout Standard
33661 \begin_inset LatexCommand url
33662 target "http://www.8052.com/users/disasm/"
33663
33664 \end_inset
33665
33666
33667 \end_layout
33668
33669 \end_inset
33670 </cell>
33671 </row>
33672 <row bottomline="true">
33673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33674 \begin_inset Text
33675
33676 \begin_layout Standard
33677 cmake
33678 \begin_inset LatexCommand index
33679 name "cmake"
33680
33681 \end_inset
33682
33683
33684 \end_layout
33685
33686 \end_inset
33687 </cell>
33688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33689 \begin_inset Text
33690
33691 \begin_layout Standard
33692 Cross platform build system, generates Makefiles
33693 \begin_inset LatexCommand index
33694 name "Makefile"
33695
33696 \end_inset
33697
33698  and project workspaces
33699 \begin_inset LatexCommand index
33700 name "project workspace"
33701
33702 \end_inset
33703
33704
33705 \end_layout
33706
33707 \end_inset
33708 </cell>
33709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33710 \begin_inset Text
33711
33712 \begin_layout Standard
33713 \begin_inset LatexCommand url
33714 target "http://www.cmake.org"
33715
33716 \end_inset
33717
33718  \InsetSpace ~
33719 \InsetSpace ~
33720 \InsetSpace ~
33721 \InsetSpace ~
33722 and a dedicated wiki entry: 
33723 \begin_inset LatexCommand url
33724 target "http://www.cmake.org/Wiki/CmakeSdcc"
33725
33726 \end_inset
33727
33728
33729 \end_layout
33730
33731 \end_inset
33732 </cell>
33733 </row>
33734 </lyxtabular>
33735
33736 \end_inset
33737
33738
33739 \newline
33740
33741 \end_layout
33742
33743 \begin_layout Section
33744 Related documentation / recommended reading
33745 \end_layout
33746
33747 \begin_layout Standard
33748 \align left
33749 \begin_inset Tabular
33750 <lyxtabular version="3" rows="7" columns="3">
33751 <features>
33752 <column alignment="left" valignment="top" leftline="true" width="0pt">
33753 <column alignment="left" valignment="top" leftline="true" width="0">
33754 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
33755 <row topline="true" bottomline="true">
33756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33757 \begin_inset Text
33758
33759 \begin_layout Standard
33760
33761 \series bold
33762 Name
33763 \end_layout
33764
33765 \end_inset
33766 </cell>
33767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33768 \begin_inset Text
33769
33770 \begin_layout Standard
33771
33772 \series bold
33773 Subject / Title
33774 \end_layout
33775
33776 \end_inset
33777 </cell>
33778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33779 \begin_inset Text
33780
33781 \begin_layout Standard
33782
33783 \series bold
33784 Where to get
33785 \end_layout
33786
33787 \end_inset
33788 </cell>
33789 </row>
33790 <row topline="true">
33791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33792 \begin_inset Text
33793
33794 \begin_layout Standard
33795
33796 \family roman
33797 \series medium
33798 \shape up
33799 \size normal
33800 \emph off
33801 \bar no
33802 \noun off
33803 \color none
33804 c-refcard.pdf
33805 \end_layout
33806
33807 \end_inset
33808 </cell>
33809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33810 \begin_inset Text
33811
33812 \begin_layout Standard
33813 C Reference Card
33814 \begin_inset LatexCommand index
33815 name "C Reference card"
33816
33817 \end_inset
33818
33819 , 2 pages
33820 \end_layout
33821
33822 \end_inset
33823 </cell>
33824 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33825 \begin_inset Text
33826
33827 \begin_layout Standard
33828 \begin_inset LatexCommand url
33829 target "http://refcards.com/refcards/c/index.html"
33830
33831 \end_inset
33832
33833
33834 \end_layout
33835
33836 \end_inset
33837 </cell>
33838 </row>
33839 <row topline="true">
33840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33841 \begin_inset Text
33842
33843 \begin_layout Standard
33844 c-faq
33845 \end_layout
33846
33847 \end_inset
33848 </cell>
33849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33850 \begin_inset Text
33851
33852 \begin_layout Standard
33853 C-FAQ
33854 \begin_inset LatexCommand index
33855 name "C FAQ"
33856
33857 \end_inset
33858
33859
33860 \end_layout
33861
33862 \end_inset
33863 </cell>
33864 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33865 \begin_inset Text
33866
33867 \begin_layout Standard
33868 \begin_inset LatexCommand url
33869 target "http://www.c-faq.com"
33870
33871 \end_inset
33872
33873
33874 \end_layout
33875
33876 \end_inset
33877 </cell>
33878 </row>
33879 <row topline="true">
33880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33881 \begin_inset Text
33882
33883 \begin_layout Standard
33884 ISO/IEC 9899:TC2
33885 \end_layout
33886
33887 \end_inset
33888 </cell>
33889 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33890 \begin_inset Text
33891
33892 \begin_layout Standard
33893 \begin_inset Quotes sld
33894 \end_inset
33895
33896 C-Standard
33897 \begin_inset Quotes srd
33898 \end_inset
33899
33900
33901 \end_layout
33902
33903 \end_inset
33904 </cell>
33905 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33906 \begin_inset Text
33907
33908 \begin_layout Standard
33909
33910 \size footnotesize
33911 \begin_inset LatexCommand url
33912 target "http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899"
33913
33914 \end_inset
33915
33916
33917 \end_layout
33918
33919 \end_inset
33920 </cell>
33921 </row>
33922 <row topline="true">
33923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33924 \begin_inset Text
33925
33926 \begin_layout Standard
33927 ISO/IEC DTR 18037
33928 \end_layout
33929
33930 \end_inset
33931 </cell>
33932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33933 \begin_inset Text
33934
33935 \begin_layout Standard
33936 \begin_inset Quotes sld
33937 \end_inset
33938
33939 Extensions for Embedded C
33940 \begin_inset Quotes srd
33941 \end_inset
33942
33943
33944 \end_layout
33945
33946 \end_inset
33947 </cell>
33948 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33949 \begin_inset Text
33950
33951 \begin_layout Standard
33952
33953 \size footnotesize
33954 \begin_inset LatexCommand url
33955 target "http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf"
33956
33957 \end_inset
33958
33959
33960 \end_layout
33961
33962 \end_inset
33963 </cell>
33964 </row>
33965 <row topline="true">
33966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33967 \begin_inset Text
33968
33969 \begin_layout Standard
33970
33971 \end_layout
33972
33973 \end_inset
33974 </cell>
33975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33976 \begin_inset Text
33977
33978 \begin_layout Standard
33979 Latest datasheet of target CPU
33980 \end_layout
33981
33982 \end_inset
33983 </cell>
33984 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33985 \begin_inset Text
33986
33987 \begin_layout Standard
33988 vendor
33989 \end_layout
33990
33991 \end_inset
33992 </cell>
33993 </row>
33994 <row topline="true" bottomline="true">
33995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33996 \begin_inset Text
33997
33998 \begin_layout Standard
33999
34000 \end_layout
34001
34002 \end_inset
34003 </cell>
34004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34005 \begin_inset Text
34006
34007 \begin_layout Standard
34008 Revision history of datasheet
34009 \end_layout
34010
34011 \end_inset
34012 </cell>
34013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34014 \begin_inset Text
34015
34016 \begin_layout Standard
34017 vendor
34018 \end_layout
34019
34020 \end_inset
34021 </cell>
34022 </row>
34023 </lyxtabular>
34024
34025 \end_inset
34026
34027
34028 \newline
34029
34030 \end_layout
34031
34032 \begin_layout Section
34033 Application notes specifically for SDCC
34034 \end_layout
34035
34036 \begin_layout Standard
34037 SDCC makes no claims about the completeness of this list and about up-to-datenes
34038 s or correctness of the application notes
34039 \begin_inset LatexCommand index
34040 name "Application notes"
34041
34042 \end_inset
34043
34044 .
34045 \end_layout
34046
34047 \begin_layout Standard
34048 \align left
34049
34050 \size footnotesize
34051 \begin_inset Tabular
34052 <lyxtabular version="3" rows="7" columns="3">
34053 <features>
34054 <column alignment="block" valignment="top" leftline="true" width="17col%">
34055 <column alignment="block" valignment="top" leftline="true" width="27col%">
34056 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
34057 <row topline="true" bottomline="true">
34058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34059 \begin_inset Text
34060
34061 \begin_layout Standard
34062
34063 \series bold
34064 \size footnotesize
34065 Vendor
34066 \end_layout
34067
34068 \end_inset
34069 </cell>
34070 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
34071 \begin_inset Text
34072
34073 \begin_layout Standard
34074
34075 \series bold
34076 \size footnotesize
34077 Subject / Title
34078 \end_layout
34079
34080 \end_inset
34081 </cell>
34082 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34083 \begin_inset Text
34084
34085 \begin_layout Standard
34086
34087 \series bold
34088 \size footnotesize
34089 Where to get
34090 \end_layout
34091
34092 \end_inset
34093 </cell>
34094 </row>
34095 <row topline="true">
34096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34097 \begin_inset Text
34098
34099 \begin_layout Standard
34100
34101 \size footnotesize
34102 Maxim / Dallas
34103 \end_layout
34104
34105 \end_inset
34106 </cell>
34107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34108 \begin_inset Text
34109
34110 \begin_layout Standard
34111
34112 \size footnotesize
34113 Using the SDCC Compiler for the DS80C400
34114 \begin_inset LatexCommand index
34115 name "DS80C400"
34116
34117 \end_inset
34118
34119
34120 \end_layout
34121
34122 \end_inset
34123 </cell>
34124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34125 \begin_inset Text
34126
34127 \begin_layout Standard
34128
34129 \size footnotesize
34130 \begin_inset LatexCommand url
34131 target "http://pdfserv.maxim-ic.com/en/an/AN3346.pdf"
34132
34133 \end_inset
34134
34135
34136 \end_layout
34137
34138 \end_inset
34139 </cell>
34140 </row>
34141 <row topline="true">
34142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34143 \begin_inset Text
34144
34145 \begin_layout Standard
34146
34147 \size footnotesize
34148 Maxim / Dallas
34149 \end_layout
34150
34151 \end_inset
34152 </cell>
34153 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
34154 \begin_inset Text
34155
34156 \begin_layout Standard
34157
34158 \size footnotesize
34159 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
34160 \begin_inset LatexCommand index
34161 name "DS89C4x0"
34162
34163 \end_inset
34164
34165  Family of Microcontrollers
34166 \end_layout
34167
34168 \end_inset
34169 </cell>
34170 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34171 \begin_inset Text
34172
34173 \begin_layout Standard
34174
34175 \size footnotesize
34176 \begin_inset LatexCommand url
34177 target "http://pdfserv.maxim-ic.com/en/an/AN3477.pdf"
34178
34179 \end_inset
34180
34181
34182 \end_layout
34183
34184 \end_inset
34185 </cell>
34186 </row>
34187 <row topline="true">
34188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34189 \begin_inset Text
34190
34191 \begin_layout Standard
34192
34193 \size footnotesize
34194 Silicon Laboratories / Cygnal
34195 \end_layout
34196
34197 \end_inset
34198 </cell>
34199 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34200 \begin_inset Text
34201
34202 \begin_layout Standard
34203
34204 \size footnotesize
34205 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
34206 \begin_inset LatexCommand index
34207 name "IDE"
34208
34209 \end_inset
34210
34211
34212 \end_layout
34213
34214 \end_inset
34215 </cell>
34216 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34217 \begin_inset Text
34218
34219 \begin_layout Standard
34220
34221 \size footnotesize
34222 \begin_inset LatexCommand url
34223 target "http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf"
34224
34225 \end_inset
34226
34227
34228 \end_layout
34229
34230 \end_inset
34231 </cell>
34232 </row>
34233 <row topline="true">
34234 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34235 \begin_inset Text
34236
34237 \begin_layout Standard
34238
34239 \size footnotesize
34240 Ramtron / Goal Semiconductor
34241 \end_layout
34242
34243 \end_inset
34244 </cell>
34245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34246 \begin_inset Text
34247
34248 \begin_layout Standard
34249
34250 \size footnotesize
34251 Interfacing SDCC to Syn and Textpad
34252 \end_layout
34253
34254 \end_inset
34255 </cell>
34256 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34257 \begin_inset Text
34258
34259 \begin_layout Standard
34260
34261 \size footnotesize
34262 \begin_inset LatexCommand url
34263 target "http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp"
34264
34265 \end_inset
34266
34267
34268 \end_layout
34269
34270 \end_inset
34271 </cell>
34272 </row>
34273 <row topline="true">
34274 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34275 \begin_inset Text
34276
34277 \begin_layout Standard
34278
34279 \size footnotesize
34280 Ramtron / Goal Semiconductor
34281 \end_layout
34282
34283 \end_inset
34284 </cell>
34285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34286 \begin_inset Text
34287
34288 \begin_layout Standard
34289
34290 \size footnotesize
34291 Installing and Configuring SDCC and Crimson Editor 
34292 \end_layout
34293
34294 \end_inset
34295 </cell>
34296 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34297 \begin_inset Text
34298
34299 \begin_layout Standard
34300
34301 \size footnotesize
34302 \begin_inset LatexCommand url
34303 target "http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp"
34304
34305 \end_inset
34306
34307
34308 \end_layout
34309
34310 \end_inset
34311 </cell>
34312 </row>
34313 <row topline="true" bottomline="true">
34314 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34315 \begin_inset Text
34316
34317 \begin_layout Standard
34318
34319 \size footnotesize
34320 Texas Instruments
34321 \end_layout
34322
34323 \end_inset
34324 </cell>
34325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34326 \begin_inset Text
34327
34328 \begin_layout Standard
34329
34330 \size footnotesize
34331 MSC12xx Programming with SDCC
34332 \end_layout
34333
34334 \end_inset
34335 </cell>
34336 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34337 \begin_inset Text
34338
34339 \begin_layout Standard
34340
34341 \size footnotesize
34342 \begin_inset LatexCommand url
34343 target "http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf"
34344
34345 \end_inset
34346
34347
34348 \end_layout
34349
34350 \end_inset
34351 </cell>
34352 </row>
34353 </lyxtabular>
34354
34355 \end_inset
34356
34357
34358 \end_layout
34359
34360 \begin_layout Section
34361 Some Questions
34362 \end_layout
34363
34364 \begin_layout Standard
34365 Some questions answered, some pointers given - it might be time to in turn
34366  ask 
34367 \emph on
34368 you
34369 \emph default
34370  some questions: 
34371 \end_layout
34372
34373 \begin_layout Itemize
34374 can you solve your project with the selected microcontroller? Would you
34375  find out early or rather late that your target is too small/slow/whatever?
34376  Can you switch to a slightly better device if it doesn't fit?
34377 \end_layout
34378
34379 \begin_layout Itemize
34380 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
34381  and/or another programming language be more adequate? Would an operating
34382  system on the target device help?
34383 \end_layout
34384
34385 \begin_layout Itemize
34386 if you solved the problem, will the marketing department be happy?
34387 \end_layout
34388
34389 \begin_layout Itemize
34390 if the marketing department is happy, will customers be happy?
34391 \end_layout
34392
34393 \begin_layout Itemize
34394 if you're the project manager, marketing department and maybe even the customer
34395  in one person, have you tried to see the project from the outside?
34396 \end_layout
34397
34398 \begin_layout Itemize
34399 is the project done if you think it is done? Or is just that other interface/pro
34400 tocol/feature/configuration/option missing? How about website, manual(s),
34401  internationali(z|s)ation, packaging, labels, 2nd source for components,
34402  electromagnetic compatability/interference, documentation for production,
34403  production test software, update mechanism, patent issues?
34404 \end_layout
34405
34406 \begin_layout Itemize
34407 is your project adequately positioned in that magic triangle: fame, fortune,
34408  fun?
34409 \end_layout
34410
34411 \begin_layout Standard
34412 Maybe not all answers to these questions are known and some answers may
34413  even be 
34414 \emph on
34415 no
34416 \emph default
34417 , nevertheless knowing these questions may help you to avoid burnout
34418 \begin_inset Foot
34419 status open
34420
34421 \begin_layout Standard
34422 burnout is bad for electronic devices, programmers and motorcycle tyres
34423 \end_layout
34424
34425 \end_inset
34426
34427 .
34428  Chances are you didn't want to hear some of them...
34429 \end_layout
34430
34431 \begin_layout Chapter
34432 Support
34433 \begin_inset LatexCommand index
34434 name "Support"
34435
34436 \end_inset
34437
34438
34439 \end_layout
34440
34441 \begin_layout Standard
34442 SDCC has grown to be a large project.
34443  The compiler alone (without the preprocessor, assembler and linker) is
34444  well over 150,000 lines of code (blank stripped).
34445  The open source nature of this project is a key to its continued growth
34446  and support.
34447  You gain the benefit and support of many active software developers and
34448  end users.
34449  Is SDCC perfect? No, that's why we need your help.
34450  The developers take pride in fixing reported bugs.
34451  You can help by reporting the bugs and helping other SDCC users.
34452  There are lots of ways to contribute, and we encourage you to take part
34453  in making SDCC a great software package.
34454  
34455 \end_layout
34456
34457 \begin_layout Standard
34458 The SDCC project is hosted on the SDCC sourceforge site at 
34459 \begin_inset LatexCommand htmlurl
34460 target "http://sourceforge.net/projects/sdcc"
34461
34462 \end_inset
34463
34464 .
34465  You'll find the complete set of mailing lists
34466 \begin_inset LatexCommand index
34467 name "Mailing list(s)"
34468
34469 \end_inset
34470
34471 , forums, bug reporting system, patch submission
34472 \begin_inset LatexCommand index
34473 name "Patch submission"
34474
34475 \end_inset
34476
34477  system, download
34478 \begin_inset LatexCommand index
34479 name "download"
34480
34481 \end_inset
34482
34483  area and Subversion code repository
34484 \begin_inset LatexCommand index
34485 name "Subversion code repository"
34486
34487 \end_inset
34488
34489  there.
34490 \end_layout
34491
34492 \begin_layout Section
34493 Reporting Bugs
34494 \begin_inset LatexCommand index
34495 name "Bug reporting"
34496
34497 \end_inset
34498
34499
34500 \begin_inset LatexCommand index
34501 name "Reporting bugs"
34502
34503 \end_inset
34504
34505
34506 \end_layout
34507
34508 \begin_layout Standard
34509 The recommended way of reporting bugs is using the infrastructure of the
34510  sourceforge site.
34511  You can follow the status of bug reports there and have an overview about
34512  the known bugs.
34513 \end_layout
34514
34515 \begin_layout Standard
34516 Bug reports are automatically forwarded to the developer mailing list and
34517  will be fixed ASAP.
34518  When reporting a bug, it is very useful to include a small test program
34519  (the smaller the better) which reproduces the problem.
34520  If you can isolate the problem by looking at the generated assembly code,
34521  this can be very helpful.
34522  Compiling your program with the -
34523 \begin_inset ERT
34524 status collapsed
34525
34526 \begin_layout Standard
34527
34528
34529 \backslash
34530 /
34531 \end_layout
34532
34533 \end_inset
34534
34535 -dumpall
34536 \begin_inset LatexCommand index
34537 name "-\\/-dumpall"
34538
34539 \end_inset
34540
34541  option can sometimes be useful in locating optimization problems.
34542  When reporting a bug please make sure you:
34543 \end_layout
34544
34545 \begin_layout Enumerate
34546 Attach the code you are compiling with SDCC.
34547  
34548 \end_layout
34549
34550 \begin_layout Enumerate
34551 Specify the exact command you use to run SDCC, or attach your Makefile.
34552  
34553 \end_layout
34554
34555 \begin_layout Enumerate
34556 Specify the SDCC version (type "
34557 \family sans
34558 \series bold
34559 sdcc -v
34560 \family default
34561 \series default
34562 "), your platform, and operating system.
34563  
34564 \end_layout
34565
34566 \begin_layout Enumerate
34567 Provide an exact copy of any error message or incorrect output.
34568  
34569 \end_layout
34570
34571 \begin_layout Enumerate
34572 Put something meaningful in the subject of your message.
34573 \end_layout
34574
34575 \begin_layout Standard
34576 Please attempt to include these 5 important parts, as applicable, in all
34577  requests for support or when reporting any problems or bugs with SDCC.
34578  Though this will make your message lengthy, it will greatly improve your
34579  chance that SDCC users and developers will be able to help you.
34580  Some SDCC developers are frustrated by bug reports without code provided
34581  that they can use to reproduce and ultimately fix the problem, so please
34582  be sure to provide sample code if you are reporting a bug! 
34583 \end_layout
34584
34585 \begin_layout Standard
34586 Please have a short check that you are using a recent version of SDCC and
34587  the bug is not yet known.
34588  This is the link for reporting bugs: 
34589 \begin_inset LatexCommand htmlurl
34590 target "http://sourceforge.net/tracker/?group_id=599&atid=100599"
34591
34592 \end_inset
34593
34594 .
34595  With SDCC on average having more than 200 downloads
34596 \begin_inset LatexCommand index
34597 name "download"
34598
34599 \end_inset
34600
34601  on sourceforge per day
34602 \begin_inset Foot
34603 status open
34604
34605 \begin_layout Standard
34606 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
34607  between 2002 and 2005.
34608  This does not include other methods of distribution.
34609 \end_layout
34610
34611 \end_inset
34612
34613  there must be some users.
34614  So it's not exactly easy to find a new bug.
34615  If you find one we need it: 
34616 \emph on
34617 reporting bugs is good
34618 \emph default
34619 .
34620 \end_layout
34621
34622 \begin_layout Section
34623 Requesting Features
34624 \begin_inset LatexCommand label
34625 name "sub:Requesting-Features"
34626
34627 \end_inset
34628
34629
34630 \begin_inset LatexCommand index
34631 name "Feature request"
34632
34633 \end_inset
34634
34635
34636 \begin_inset LatexCommand index
34637 name "Requesting features"
34638
34639 \end_inset
34640
34641
34642 \end_layout
34643
34644 \begin_layout Standard
34645 Like bug reports feature requests are forwarded to the developer mailing
34646  list.
34647  This is the link for requesting features: 
34648 \begin_inset LatexCommand htmlurl
34649 target "http://sourceforge.net/tracker/?group_id=599&atid=350599"
34650
34651 \end_inset
34652
34653 .
34654 \end_layout
34655
34656 \begin_layout Section
34657 Submitting patches
34658 \end_layout
34659
34660 \begin_layout Standard
34661 Like bug reports contributed patches are forwarded to the developer mailing
34662  list.
34663  This is the link for submitting patches
34664 \begin_inset LatexCommand index
34665 name "Patch submission"
34666
34667 \end_inset
34668
34669
34670 \begin_inset LatexCommand url
34671 target "http://sourceforge.net/tracker/?group_id=599&atid=300599"
34672
34673 \end_inset
34674
34675 .
34676 \end_layout
34677
34678 \begin_layout Standard
34679 You need to specify some parameters to the 
34680 \family typewriter
34681 diff
34682 \family default
34683  command for the patches to be useful.
34684  If you modified more than one file a patch created f.e.
34685  with 
34686 \family sans
34687 \series bold
34688
34689 \begin_inset Quotes sld
34690 \end_inset
34691
34692 diff -Naur unmodified_directory modified_directory >my_changes.patch
34693 \begin_inset Quotes srd
34694 \end_inset
34695
34696
34697 \family default
34698 \series default
34699  will be fine, otherwise 
34700 \family sans
34701 \series bold
34702
34703 \begin_inset Quotes sld
34704 \end_inset
34705
34706 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
34707 \begin_inset Quotes srd
34708 \end_inset
34709
34710
34711 \family default
34712 \series default
34713  will do.
34714 \end_layout
34715
34716 \begin_layout Section
34717 Getting Help
34718 \end_layout
34719
34720 \begin_layout Standard
34721 These links should take you directly to the 
34722 \begin_inset LatexCommand url
34723 name "Mailing lists"
34724 target "http://sourceforge.net/mail/?group_id=599"
34725
34726 \end_inset
34727
34728
34729 \begin_inset Foot
34730 status open
34731
34732 \begin_layout Standard
34733 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
34734  automated messages (mid 2003)
34735 \end_layout
34736
34737 \end_inset
34738
34739  and the 
34740 \begin_inset LatexCommand url
34741 name "Forums"
34742 target "http://sourceforge.net/forum/?group_id=599"
34743
34744 \end_inset
34745
34746 , lists
34747 \begin_inset LatexCommand index
34748 name "Mailing list(s)"
34749
34750 \end_inset
34751
34752  and forums are archived and searchable so if you are lucky someone already
34753  had a similar problem.
34754  While mails to the lists themselves are delivered promptly their web front
34755  end on sourceforge sometimes shows a severe time lag (up to several weeks),
34756  if you're seriously using SDCC please consider subscribing to the lists.
34757 \end_layout
34758
34759 \begin_layout Section
34760 ChangeLog
34761 \end_layout
34762
34763 \begin_layout Standard
34764 You can follow the status of the Subversion version
34765 \begin_inset LatexCommand index
34766 name "version"
34767
34768 \end_inset
34769
34770  of SDCC by watching the Changelog
34771 \begin_inset LatexCommand index
34772 name "Changelog"
34773
34774 \end_inset
34775
34776  in the Subversion repository
34777 \size footnotesize
34778  
34779 \begin_inset LatexCommand htmlurl
34780 target "http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog"
34781
34782 \end_inset
34783
34784 .
34785 \end_layout
34786
34787 \begin_layout Section
34788 Subversion Source Code Repository
34789 \end_layout
34790
34791 \begin_layout Standard
34792 The output of 
34793 \family sans
34794 \series bold
34795 sdcc -
34796 \family default
34797
34798 \begin_inset ERT
34799 status open
34800
34801 \begin_layout Standard
34802
34803
34804 \backslash
34805 /
34806 \end_layout
34807
34808 \end_inset
34809
34810
34811 \family sans
34812 -version
34813 \family default
34814 \series default
34815  or the filenames of the snapshot versions of SDCC include date and its
34816  Subversion
34817 \begin_inset LatexCommand index
34818 name "Subversion code repository"
34819
34820 \end_inset
34821
34822  number.
34823  Subversion allows to download the source of recent or previous versions
34824  
34825 \begin_inset LatexCommand url
34826 target "http://sourceforge.net/svn/?group_id=599"
34827
34828 \end_inset
34829
34830  (by number or by date).
34831  An on-line source code browser and detailled instructions are also available
34832  there.
34833  SDCC versions starting from 1999 up to now are available (currently the
34834  versions prior to the conversion from cvs
34835 \begin_inset LatexCommand index
34836 name "cvs|see{Subversion}"
34837
34838 \end_inset
34839
34840  to Subversion (April 2006) are either by accessible by Subversion or by
34841  cvs).
34842 \end_layout
34843
34844 \begin_layout Section
34845 Release policy
34846 \begin_inset LatexCommand index
34847 name "Release policy"
34848
34849 \end_inset
34850
34851
34852 \end_layout
34853
34854 \begin_layout Standard
34855 Historically there often were long delays between official releases and
34856  the sourceforge download area tends to get not updated at all.
34857  Excuses in the past might have referred to problems with live range analysis,
34858  but as this was fixed a while ago, the current problem is that another
34859  excuse has to be found.
34860  Kidding aside, we have to get better there! On the other hand there are
34861  daily snapshots available at 
34862 \begin_inset LatexCommand htmlurl
34863 name "snap"
34864 target "http://sdcc.sourceforge.net/snap.php"
34865
34866 \end_inset
34867
34868 , and you can always build the very last version (hopefully with many bugs
34869  fixed, and features added) from the source code available at 
34870 \begin_inset LatexCommand htmlurl
34871 name "Source"
34872 target "http://sdcc.sourceforge.net/snap.php#Source"
34873
34874 \end_inset
34875
34876 .
34877  The SDCC Wiki
34878 \begin_inset LatexCommand index
34879 name "wiki"
34880
34881 \end_inset
34882
34883
34884 \begin_inset LatexCommand index
34885 name "SDCC Wiki"
34886
34887 \end_inset
34888
34889  at 
34890 \begin_inset LatexCommand url
34891 target "http://sdcc.wiki.sourceforge.net/"
34892
34893 \end_inset
34894
34895  also holds some information about past and future releases.
34896 \end_layout
34897
34898 \begin_layout Section
34899 Examples
34900 \begin_inset LatexCommand index
34901 name "Examples"
34902
34903 \end_inset
34904
34905
34906 \end_layout
34907
34908 \begin_layout Standard
34909 You'll find some small examples in the directory 
34910 \emph on
34911 sdcc/device/examples/.
34912
34913 \emph default
34914  More examples and libraries are available at 
34915 \emph on
34916 The SDCC Open Knowledge Resource 
34917 \begin_inset LatexCommand url
34918 target "http://sdccokr.dl9sec.de/"
34919
34920 \end_inset
34921
34922
34923 \emph default
34924  web site or at 
34925 \begin_inset LatexCommand url
34926 target "http://www.pjrc.com/tech/8051/"
34927
34928 \end_inset
34929
34930 .
34931 \end_layout
34932
34933 \begin_layout Standard
34934 \begin_inset Note Note
34935 status collapsed
34936
34937 \begin_layout Standard
34938 I did insert a reference to Paul's web site here although it seems rather
34939  dedicated to a specific 8032 board (I think it's okay because it f.e.
34940  shows LCD/Harddisc interface and has a free 8051 monitor.
34941  Independent 8032 board vendors face hard competition of heavily subsidized
34942  development boards anyway).
34943 \end_layout
34944
34945 \begin_layout Standard
34946 Maybe we should include some links to real world applications.
34947  Preferably pointer to pointers (one for each architecture) so this stays
34948  manageable here?
34949 \end_layout
34950
34951 \end_inset
34952
34953
34954 \end_layout
34955
34956 \begin_layout Section
34957 Quality control
34958 \begin_inset LatexCommand label
34959 name "sec:Quality-control"
34960
34961 \end_inset
34962
34963
34964 \begin_inset LatexCommand index
34965 name "Quality control"
34966
34967 \end_inset
34968
34969
34970 \end_layout
34971
34972 \begin_layout Standard
34973 The compiler is passed through snaphot build compile and build checks.
34974  The so called 
34975 \shape italic
34976 regression tests
34977 \shape default
34978
34979 \begin_inset LatexCommand index
34980 name "Regression test"
34981
34982 \end_inset
34983
34984  check that SDCC itself compiles flawlessly on several host platforms (i386,
34985  Opteron, 64 bit Alpha, ppc64, Mac OS X on ppc and i386, Solaris on Sparc)
34986  and checks the quality of the code generated by SDCC by running the code
34987  for several target platforms through simulators.
34988  The regression test suite comprises more than 100 files which expand to
34989  more than 500 test cases which include more than 4500 tests.
34990  The results of these tests are published daily on SDCC's snapshot page
34991  (click on the red or green symbols on the right side of 
34992 \begin_inset LatexCommand url
34993 target "http://sdcc.sourceforge.net/snap.php"
34994
34995 \end_inset
34996
34997 ).
34998 \end_layout
34999
35000 \begin_layout Standard
35001 There is a separate document 
35002 \shape italic
35003 test_suite.pdf 
35004 \begin_inset LatexCommand index
35005 name "Test suite"
35006
35007 \end_inset
35008
35009
35010 \shape default
35011  
35012 \begin_inset LatexCommand url
35013 target "http://sdcc.sourceforge.net/doc/test_suite_spec.pdf"
35014
35015 \end_inset
35016
35017  about the regression test suite.
35018 \end_layout
35019
35020 \begin_layout Standard
35021 You'll find the test code in the directory 
35022 \shape italic
35023 sdcc/support/regression
35024 \shape default
35025 .
35026  You can run these tests manually by running 
35027 \family sans
35028 make
35029 \family default
35030  in this directory (or f.e.
35031  
35032 \family sans
35033 \series bold
35034
35035 \begin_inset Quotes sld
35036 \end_inset
35037
35038 make test-mcs51
35039 \begin_inset Quotes srd
35040 \end_inset
35041
35042
35043 \family default
35044 \series default
35045  if you don't want to run the complete tests).
35046  The test code might also be interesting if you want to look for examples
35047 \begin_inset LatexCommand index
35048 name "Examples"
35049
35050 \end_inset
35051
35052  checking corner cases of SDCC or if you plan to submit patches
35053 \begin_inset LatexCommand index
35054 name "Patch submission"
35055
35056 \end_inset
35057
35058 .
35059 \end_layout
35060
35061 \begin_layout Standard
35062 The PIC14 port uses a different set of regression tests 
35063 \begin_inset LatexCommand index
35064 name "Regression test (PIC14)"
35065
35066 \end_inset
35067
35068 , you'll find them in the directory 
35069 \shape italic
35070 sdcc/src/regression
35071 \shape default
35072 .
35073 \end_layout
35074
35075 \begin_layout Section
35076 Use of SDCC in Education
35077 \end_layout
35078
35079 \begin_layout Standard
35080 In short: 
35081 \emph on
35082 highly
35083 \emph default
35084  encouraged
35085 \begin_inset Foot
35086 status open
35087
35088 \begin_layout Standard
35089 the phrase "use in education" might evoke the association "
35090 \emph on
35091 only
35092 \emph default
35093  fit for use in education".
35094  This connotation is not intended but nevertheless risked as the licensing
35095  of SDCC makes it difficult to offer educational discounts
35096 \end_layout
35097
35098 \end_inset
35099
35100 .
35101  If your rationales are to:
35102 \end_layout
35103
35104 \begin_layout Enumerate
35105 give students a chance to understand the 
35106 \emph on
35107 complete
35108 \emph default
35109  steps of code generation
35110 \end_layout
35111
35112 \begin_layout Enumerate
35113 have a curriculum that can be extended for years.
35114  Then you could use an fpga board as target and your curriculum will seamlessly
35115  extend from logic synthesis (
35116 \begin_inset LatexCommand url
35117 name "http://www.opencores.org"
35118 target "opencores.org"
35119
35120 \end_inset
35121
35122
35123 \begin_inset LatexCommand url
35124 name "Oregano"
35125 target "http://www.oregano.at/ip/ip01.htm"
35126
35127 \end_inset
35128
35129 ), over assembly programming, to C to FPGA compilers (
35130 \begin_inset LatexCommand url
35131 name "FPGAC"
35132 target "http://sf.net/projects/fpgac"
35133
35134 \end_inset
35135
35136 ) and to C.
35137 \end_layout
35138
35139 \begin_layout Enumerate
35140 be able to insert excursions about skills like using a revision control
35141  system, submitting/applying patches, using a type-setting (as opposed to
35142  word-processing) engine LyX/LaTeX, using 
35143 \begin_inset LatexCommand url
35144 name "SourceForge"
35145 target "http://www.sf.net"
35146
35147 \end_inset
35148
35149 , following some 
35150 \begin_inset LatexCommand url
35151 name "netiquette"
35152 target "http://en.wikipedia.org/wiki/Netiquette"
35153
35154 \end_inset
35155
35156 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
35157  Source Software, CPU simulation, compiler regression tests
35158 \begin_inset LatexCommand index
35159 name "Regression test"
35160
35161 \end_inset
35162
35163 .
35164  
35165 \newline
35166 And if there should be a shortage of ideas then you can always point students
35167  to the ever-growing feature request list 
35168 \begin_inset LatexCommand htmlurl
35169 target "http://sourceforge.net/tracker/?group_id=599&atid=350599"
35170
35171 \end_inset
35172
35173 .
35174 \end_layout
35175
35176 \begin_layout Enumerate
35177 not tie students to a specific host platform and instead allow them to use
35178  a host platform of 
35179 \emph on
35180 their
35181 \emph default
35182  choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
35183  and eventually 
35184 \begin_inset LatexCommand url
35185 name "OLPC"
35186 target "http://www.laptop.org"
35187
35188 \end_inset
35189
35190 )
35191 \end_layout
35192
35193 \begin_layout Enumerate
35194 not encourage students to use illegal copies of educational software
35195 \end_layout
35196
35197 \begin_layout Enumerate
35198 be immune to licensing/availability/price changes of the chosen tool chain
35199 \end_layout
35200
35201 \begin_layout Enumerate
35202 be able to change to a new target platform without having to adopt a new
35203  tool chain
35204 \end_layout
35205
35206 \begin_layout Enumerate
35207 have complete control over and insight into the tool chain
35208 \end_layout
35209
35210 \begin_layout Enumerate
35211 make your students aware about the pros and cons of open source software
35212  development
35213 \end_layout
35214
35215 \begin_layout Enumerate
35216 give back to the public as you are probably at least partially publicly
35217  funded
35218 \end_layout
35219
35220 \begin_layout Enumerate
35221 give students a chance to publicly prove their skills and to possibly see
35222  a world wide impact
35223 \end_layout
35224
35225 \begin_layout Standard
35226 then SDCC is probably among the first choices.
35227  Well, probably SDCC might be the only choice.
35228 \newpage
35229
35230 \end_layout
35231
35232 \begin_layout Chapter
35233 SDCC Technical Data
35234 \end_layout
35235
35236 \begin_layout Section
35237 Optimizations
35238 \begin_inset LatexCommand index
35239 name "Optimizations"
35240
35241 \end_inset
35242
35243
35244 \end_layout
35245
35246 \begin_layout Standard
35247 SDCC performs a host of standard optimizations in addition to some MCU specific
35248  optimizations.
35249  
35250 \end_layout
35251
35252 \begin_layout Subsection
35253 Sub-expression Elimination
35254 \begin_inset LatexCommand index
35255 name "Subexpression elimination"
35256
35257 \end_inset
35258
35259
35260 \end_layout
35261
35262 \begin_layout Standard
35263 The compiler does local and 
35264 \emph on
35265 g
35266 \emph default
35267 lobal 
35268 \emph on
35269 c
35270 \emph default
35271 ommon 
35272 \emph on
35273 s
35274 \emph default
35275 ubexpression 
35276 \emph on
35277 e
35278 \emph default
35279 limination, e.g.: 
35280 \end_layout
35281
35282 \begin_layout Verse
35283
35284 \family typewriter
35285 i = x + y + 1; 
35286 \newline
35287 j = x + y;
35288 \end_layout
35289
35290 \begin_layout Standard
35291 will be translated to
35292 \end_layout
35293
35294 \begin_layout Verse
35295
35296 \family typewriter
35297 iTemp = x + y; 
35298 \newline
35299 i = iTemp + 1; 
35300 \newline
35301 j = iTemp;
35302 \end_layout
35303
35304 \begin_layout Standard
35305 Some subexpressions are not as obvious as the above example, e.g.:
35306 \end_layout
35307
35308 \begin_layout Verse
35309
35310 \family typewriter
35311 a->b[i].c = 10; 
35312 \newline
35313 a->b[i].d = 11;
35314 \end_layout
35315
35316 \begin_layout Standard
35317 In this case the address arithmetic a->b[i] will be computed only once;
35318  the equivalent code in C would be.
35319 \end_layout
35320
35321 \begin_layout Verse
35322
35323 \family typewriter
35324 iTemp = a->b[i]; 
35325 \newline
35326 iTemp.c = 10; 
35327 \newline
35328 iTemp.d = 11;
35329 \end_layout
35330
35331 \begin_layout Standard
35332 The compiler will try to keep these temporary variables in registers.
35333 \end_layout
35334
35335 \begin_layout Subsection
35336 Dead-Code Elimination
35337 \begin_inset LatexCommand index
35338 name "Dead-code elimination"
35339
35340 \end_inset
35341
35342
35343 \end_layout
35344
35345 \begin_layout Verse
35346
35347 \family typewriter
35348 int global;
35349 \newline
35350
35351 \newline
35352 void f () { 
35353 \newline
35354 \InsetSpace ~
35355 \InsetSpace ~
35356 int i; 
35357 \newline
35358 \InsetSpace ~
35359 \InsetSpace ~
35360 i = 1; \InsetSpace ~
35361 \InsetSpace ~
35362 \InsetSpace ~
35363 \InsetSpace ~
35364 \InsetSpace ~
35365 /* dead store */ 
35366 \newline
35367 \InsetSpace ~
35368 \InsetSpace ~
35369 global = 1;\InsetSpace ~
35370 /* dead
35371  store */ 
35372 \newline
35373 \InsetSpace ~
35374 \InsetSpace ~
35375 global = 2; 
35376 \newline
35377 \InsetSpace ~
35378 \InsetSpace ~
35379 return; 
35380 \newline
35381 \InsetSpace ~
35382 \InsetSpace ~
35383 global = 3;\InsetSpace ~
35384 /* unreachable */ 
35385 \newline
35386 }
35387 \end_layout
35388
35389 \begin_layout Standard
35390 will be changed to
35391 \end_layout
35392
35393 \begin_layout Verse
35394
35395 \family typewriter
35396 int global;
35397 \newline
35398
35399 \newline
35400 void f () {
35401 \newline
35402 \InsetSpace ~
35403 \InsetSpace ~
35404 global = 2; 
35405 \newline
35406 }
35407 \end_layout
35408
35409 \begin_layout Subsection
35410 Copy-Propagation
35411 \begin_inset LatexCommand index
35412 name "Copy propagation"
35413
35414 \end_inset
35415
35416
35417 \end_layout
35418
35419 \begin_layout Verse
35420
35421 \family typewriter
35422 int f() { 
35423 \newline
35424 \InsetSpace ~
35425 \InsetSpace ~
35426 int i, j; 
35427 \newline
35428 \InsetSpace ~
35429 \InsetSpace ~
35430 i = 10; 
35431 \newline
35432 \InsetSpace ~
35433 \InsetSpace ~
35434 j = i; 
35435 \newline
35436 \InsetSpace ~
35437 \InsetSpace ~
35438 return j; 
35439 \newline
35440 }
35441 \end_layout
35442
35443 \begin_layout Standard
35444 will be changed to 
35445 \end_layout
35446
35447 \begin_layout Verse
35448
35449 \family typewriter
35450 int f() { 
35451 \newline
35452 \InsetSpace ~
35453 \InsetSpace ~
35454 int i, j; 
35455 \newline
35456 \InsetSpace ~
35457 \InsetSpace ~
35458 i = 10; 
35459 \newline
35460 \InsetSpace ~
35461 \InsetSpace ~
35462 j = 10; 
35463 \newline
35464 \InsetSpace ~
35465 \InsetSpace ~
35466 return 10; 
35467 \newline
35468 }
35469 \end_layout
35470
35471 \begin_layout Standard
35472 Note: the dead stores created by this copy propagation will be eliminated
35473  by dead-code elimination.
35474 \end_layout
35475
35476 \begin_layout Subsection
35477 Loop Optimizations
35478 \begin_inset LatexCommand index
35479 name "Loop optimization"
35480
35481 \end_inset
35482
35483
35484 \begin_inset LatexCommand label
35485 name "sub:Loop-Optimizations"
35486
35487 \end_inset
35488
35489
35490 \end_layout
35491
35492 \begin_layout Standard
35493 Two types of loop optimizations are done by SDCC 
35494 \emph on
35495 loop invariant
35496 \emph default
35497  lifting and 
35498 \emph on
35499 strength reduction
35500 \emph default
35501  of loop induction variables.
35502  In addition to the strength reduction the optimizer marks the induction
35503  variables and the register allocator tries to keep the induction variables
35504  in registers for the duration of the loop.
35505  Because of this preference of the register allocator
35506 \begin_inset LatexCommand index
35507 name "Register allocation"
35508
35509 \end_inset
35510
35511 , loop induction optimization causes an increase in register pressure, which
35512  may cause unwanted spilling of other temporary variables into the stack
35513 \begin_inset LatexCommand index
35514 name "stack"
35515
35516 \end_inset
35517
35518  / data space.
35519  The compiler will generate a warning message when it is forced to allocate
35520  extra space either on the stack or data space.
35521  If this extra space allocation is undesirable then induction optimization
35522  can be eliminated either for the entire source file (with -
35523 \begin_inset ERT
35524 status collapsed
35525
35526 \begin_layout Standard
35527
35528
35529 \backslash
35530 /
35531 \end_layout
35532
35533 \end_inset
35534
35535 -noinduction option) or for a given function only using #pragma\InsetSpace ~
35536 noinduction
35537 \begin_inset LatexCommand index
35538 name "\\#pragma noinduction"
35539
35540 \end_inset
35541
35542 .
35543 \newline
35544
35545 \newline
35546 Loop Invariant:
35547 \end_layout
35548
35549 \begin_layout Verse
35550
35551 \family typewriter
35552 for (i = 0 ; i < 100 ; i ++) 
35553 \newline
35554 \InsetSpace ~
35555 \InsetSpace ~
35556 \InsetSpace ~
35557 \InsetSpace ~
35558 f += k + l;
35559 \end_layout
35560
35561 \begin_layout Standard
35562 changed to
35563 \end_layout
35564
35565 \begin_layout Verse
35566
35567 \family typewriter
35568 itemp = k + l; 
35569 \newline
35570 for (i = 0; i < 100; i++) 
35571 \newline
35572 \InsetSpace ~
35573 \InsetSpace ~
35574 \InsetSpace ~
35575 \InsetSpace ~
35576 f += itemp;
35577 \end_layout
35578
35579 \begin_layout Standard
35580 As mentioned previously some loop invariants are not as apparent, all static
35581  address computations are also moved out of the loop.
35582 \newline
35583
35584 \newline
35585 Strength Reduction
35586 \begin_inset LatexCommand index
35587 name "Strength reduction"
35588
35589 \end_inset
35590
35591 , this optimization substitutes an expression by a cheaper expression:
35592 \end_layout
35593
35594 \begin_layout Verse
35595
35596 \family typewriter
35597 for (i=0;i < 100; i++)
35598 \newline
35599 \InsetSpace ~
35600 \InsetSpace ~
35601 \InsetSpace ~
35602 \InsetSpace ~
35603 ar[i*5] = i*3;
35604 \end_layout
35605
35606 \begin_layout Standard
35607 changed to
35608 \end_layout
35609
35610 \begin_layout Verse
35611
35612 \family typewriter
35613 itemp1 = 0; 
35614 \newline
35615 itemp2 = 0; 
35616 \newline
35617 for (i=0;i< 100;i++) { 
35618 \newline
35619 \InsetSpace ~
35620 \InsetSpace ~
35621 \InsetSpace ~
35622 \InsetSpace ~
35623 ar[itemp1] = itemp2; 
35624 \newline
35625 \InsetSpace ~
35626 \InsetSpace ~
35627 \InsetSpace ~
35628 \InsetSpace ~
35629 itemp1
35630  += 5; 
35631 \newline
35632 \InsetSpace ~
35633 \InsetSpace ~
35634 \InsetSpace ~
35635 \InsetSpace ~
35636 itemp2 += 3; 
35637 \newline
35638 }
35639 \end_layout
35640
35641 \begin_layout Standard
35642 The more expensive multiplication
35643 \begin_inset LatexCommand index
35644 name "Multiplication"
35645
35646 \end_inset
35647
35648  is changed to a less expensive addition.
35649 \end_layout
35650
35651 \begin_layout Subsection
35652 Loop Reversing
35653 \begin_inset LatexCommand index
35654 name "Loop reversing"
35655
35656 \end_inset
35657
35658
35659 \end_layout
35660
35661 \begin_layout Standard
35662 This optimization is done to reduce the overhead of checking loop boundaries
35663  for every iteration.
35664  Some simple loops can be reversed and implemented using a 
35665 \begin_inset Quotes eld
35666 \end_inset
35667
35668 decrement and jump if not zero
35669 \begin_inset Quotes erd
35670 \end_inset
35671
35672  instruction.
35673  SDCC checks for the following criterion to determine if a loop is reversible
35674  (note: more sophisticated compilers use data-dependency analysis to make
35675  this determination, SDCC uses a more simple minded analysis).
35676 \end_layout
35677
35678 \begin_layout Itemize
35679 The 'for' loop is of the form 
35680 \newline
35681
35682 \newline
35683
35684 \family typewriter
35685 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
35686  += 1])
35687 \newline
35688 \InsetSpace ~
35689 \InsetSpace ~
35690 \InsetSpace ~
35691 \InsetSpace ~
35692 <for body>
35693 \end_layout
35694
35695 \begin_layout Itemize
35696 The <for body> does not contain 
35697 \begin_inset Quotes eld
35698 \end_inset
35699
35700 continue
35701 \begin_inset Quotes erd
35702 \end_inset
35703
35704  or 'break
35705 \begin_inset Quotes erd
35706 \end_inset
35707
35708 .
35709 \end_layout
35710
35711 \begin_layout Itemize
35712 All goto's are contained within the loop.
35713 \end_layout
35714
35715 \begin_layout Itemize
35716 No function calls within the loop.
35717 \end_layout
35718
35719 \begin_layout Itemize
35720 The loop control variable <sym> is not assigned any value within the loop
35721 \end_layout
35722
35723 \begin_layout Itemize
35724 The loop control variable does NOT participate in any arithmetic operation
35725  within the loop.
35726 \end_layout
35727
35728 \begin_layout Itemize
35729 There are NO switch statements in the loop.
35730 \end_layout
35731
35732 \begin_layout Subsection
35733 Algebraic Simplifications
35734 \end_layout
35735
35736 \begin_layout Standard
35737 SDCC does numerous algebraic simplifications, the following is a small sub-set
35738  of these optimizations.
35739 \end_layout
35740
35741 \begin_layout Verse
35742
35743 \family typewriter
35744 i = j + 0;\InsetSpace ~
35745 \InsetSpace ~
35746 \InsetSpace ~
35747 \InsetSpace ~
35748  /* changed to: */\InsetSpace ~
35749 \InsetSpace ~
35750 \InsetSpace ~
35751 \InsetSpace ~
35752  i = j; 
35753 \newline
35754 i /= 2;\InsetSpace ~
35755 \InsetSpace ~
35756 \InsetSpace ~
35757 \InsetSpace ~
35758 \InsetSpace ~
35759 \InsetSpace ~
35760 \InsetSpace ~
35761  /* changed to: */\InsetSpace ~
35762 \InsetSpace ~
35763 \InsetSpace ~
35764 \InsetSpace ~
35765  i >>= 1; 
35766 \newline
35767 i
35768  = j - j;\InsetSpace ~
35769 \InsetSpace ~
35770 \InsetSpace ~
35771 \InsetSpace ~
35772  /* changed to: */\InsetSpace ~
35773 \InsetSpace ~
35774 \InsetSpace ~
35775 \InsetSpace ~
35776  i = 0; 
35777 \newline
35778 i = j / 1;\InsetSpace ~
35779 \InsetSpace ~
35780 \InsetSpace ~
35781 \InsetSpace ~
35782  /* changed to: */\InsetSpace ~
35783 \InsetSpace ~
35784 \InsetSpace ~
35785 \InsetSpace ~
35786  i = j;
35787 \end_layout
35788
35789 \begin_layout Standard
35790 Note the subexpressions
35791 \begin_inset LatexCommand index
35792 name "Subexpression"
35793
35794 \end_inset
35795
35796  given above are generally introduced by macro expansions or as a result
35797  of copy/constant propagation.
35798 \end_layout
35799
35800 \begin_layout Subsection
35801 'switch' Statements
35802 \begin_inset LatexCommand label
35803 name "sub:'switch'-Statements"
35804
35805 \end_inset
35806
35807
35808 \begin_inset LatexCommand index
35809 name "switch statement"
35810
35811 \end_inset
35812
35813
35814 \end_layout
35815
35816 \begin_layout Standard
35817 SDCC can optimize switch statements to jump tables
35818 \begin_inset LatexCommand index
35819 name "jump tables"
35820
35821 \end_inset
35822
35823 .
35824  It makes the decision based on an estimate of the generated code size.
35825  SDCC is quite liberal in the requirements for jump table generation: 
35826 \end_layout
35827
35828 \begin_layout Itemize
35829 The labels need not be in order, and the starting number need not be one
35830  or zero, the case labels are in numerical sequence or not too many case
35831  labels are missing.
35832 \end_layout
35833
35834 \begin_deeper
35835 \begin_layout Verse
35836
35837 \family typewriter
35838 switch(i) {\InsetSpace ~
35839 \InsetSpace ~
35840 \InsetSpace ~
35841 \InsetSpace ~
35842 \InsetSpace ~
35843 \InsetSpace ~
35844 \InsetSpace ~
35845 \InsetSpace ~
35846 \InsetSpace ~
35847 \InsetSpace ~
35848 \InsetSpace ~
35849 \InsetSpace ~
35850 \InsetSpace ~
35851 \InsetSpace ~
35852 \InsetSpace ~
35853 \InsetSpace ~
35854 \InsetSpace ~
35855 \InsetSpace ~
35856 \InsetSpace ~
35857 \InsetSpace ~
35858 \InsetSpace ~
35859 \InsetSpace ~
35860 \InsetSpace ~
35861 \InsetSpace ~
35862 \InsetSpace ~
35863 \InsetSpace ~
35864 switch (i) { 
35865 \newline
35866 \InsetSpace ~
35867 \InsetSpace ~
35868 \InsetSpace ~
35869 case 4: ...\InsetSpace ~
35870 \InsetSpace ~
35871 \InsetSpace ~
35872 \InsetSpace ~
35873 \InsetSpace ~
35874 \InsetSpace ~
35875 \InsetSpace ~
35876 \InsetSpace ~
35877 \InsetSpace ~
35878 \InsetSpace ~
35879 \InsetSpace ~
35880 \InsetSpace ~
35881 \InsetSpace ~
35882 \InsetSpace ~
35883 \InsetSpace ~
35884 \InsetSpace ~
35885 \InsetSpace ~
35886 \InsetSpace ~
35887 \InsetSpace ~
35888 \InsetSpace ~
35889 \InsetSpace ~
35890 \InsetSpace ~
35891 \InsetSpace ~
35892 \InsetSpace ~
35893 \InsetSpace ~
35894 \InsetSpace ~
35895 case 0: ...
35896  
35897 \newline
35898 \InsetSpace ~
35899 \InsetSpace ~
35900 \InsetSpace ~
35901 case 5: ...\InsetSpace ~
35902 \InsetSpace ~
35903 \InsetSpace ~
35904 \InsetSpace ~
35905 \InsetSpace ~
35906 \InsetSpace ~
35907 \InsetSpace ~
35908 \InsetSpace ~
35909 \InsetSpace ~
35910 \InsetSpace ~
35911 \InsetSpace ~
35912 \InsetSpace ~
35913 \InsetSpace ~
35914 \InsetSpace ~
35915 \InsetSpace ~
35916 \InsetSpace ~
35917 \InsetSpace ~
35918 \InsetSpace ~
35919 \InsetSpace ~
35920 \InsetSpace ~
35921 \InsetSpace ~
35922 \InsetSpace ~
35923 \InsetSpace ~
35924 \InsetSpace ~
35925 \InsetSpace ~
35926 \InsetSpace ~
35927 case 1: ...
35928  
35929 \newline
35930 \InsetSpace ~
35931 \InsetSpace ~
35932 \InsetSpace ~
35933 case 3: ...\InsetSpace ~
35934 \InsetSpace ~
35935 \InsetSpace ~
35936 \InsetSpace ~
35937 \InsetSpace ~
35938 \InsetSpace ~
35939 \InsetSpace ~
35940 \InsetSpace ~
35941 \InsetSpace ~
35942 \InsetSpace ~
35943 \InsetSpace ~
35944 \InsetSpace ~
35945 \InsetSpace ~
35946 \InsetSpace ~
35947 \InsetSpace ~
35948 \InsetSpace ~
35949 \InsetSpace ~
35950 \InsetSpace ~
35951 \InsetSpace ~
35952 \InsetSpace ~
35953 \InsetSpace ~
35954 \InsetSpace ~
35955 \InsetSpace ~
35956 \InsetSpace ~
35957 \InsetSpace ~
35958 \InsetSpace ~
35959
35960 \newline
35961 \InsetSpace ~
35962 \InsetSpace ~
35963 \InsetSpace ~
35964 case 6: ...\InsetSpace ~
35965 \InsetSpace ~
35966 \InsetSpace ~
35967 \InsetSpace ~
35968 \InsetSpace ~
35969 \InsetSpace ~
35970 \InsetSpace ~
35971 \InsetSpace ~
35972 \InsetSpace ~
35973 \InsetSpace ~
35974 \InsetSpace ~
35975 \InsetSpace ~
35976 \InsetSpace ~
35977 \InsetSpace ~
35978 \InsetSpace ~
35979 \InsetSpace ~
35980 \InsetSpace ~
35981 \InsetSpace ~
35982 \InsetSpace ~
35983 \InsetSpace ~
35984 \InsetSpace ~
35985 \InsetSpace ~
35986 \InsetSpace ~
35987 \InsetSpace ~
35988 \InsetSpace ~
35989 \InsetSpace ~
35990 case 3: ...
35991  
35992 \newline
35993 \InsetSpace ~
35994 \InsetSpace ~
35995 \InsetSpace ~
35996 case 7: ...\InsetSpace ~
35997 \InsetSpace ~
35998 \InsetSpace ~
35999 \InsetSpace ~
36000 \InsetSpace ~
36001 \InsetSpace ~
36002 \InsetSpace ~
36003 \InsetSpace ~
36004 \InsetSpace ~
36005 \InsetSpace ~
36006 \InsetSpace ~
36007 \InsetSpace ~
36008 \InsetSpace ~
36009 \InsetSpace ~
36010 \InsetSpace ~
36011 \InsetSpace ~
36012 \InsetSpace ~
36013 \InsetSpace ~
36014 \InsetSpace ~
36015 \InsetSpace ~
36016 \InsetSpace ~
36017 \InsetSpace ~
36018 \InsetSpace ~
36019 \InsetSpace ~
36020 \InsetSpace ~
36021 \InsetSpace ~
36022 case 4: ...
36023  
36024 \newline
36025 \InsetSpace ~
36026 \InsetSpace ~
36027 \InsetSpace ~
36028 case 8: ...\InsetSpace ~
36029 \InsetSpace ~
36030 \InsetSpace ~
36031 \InsetSpace ~
36032 \InsetSpace ~
36033 \InsetSpace ~
36034 \InsetSpace ~
36035 \InsetSpace ~
36036 \InsetSpace ~
36037 \InsetSpace ~
36038 \InsetSpace ~
36039 \InsetSpace ~
36040 \InsetSpace ~
36041 \InsetSpace ~
36042 \InsetSpace ~
36043 \InsetSpace ~
36044 \InsetSpace ~
36045 \InsetSpace ~
36046 \InsetSpace ~
36047 \InsetSpace ~
36048 \InsetSpace ~
36049 \InsetSpace ~
36050 \InsetSpace ~
36051 \InsetSpace ~
36052 \InsetSpace ~
36053 \InsetSpace ~
36054 case 5: ...
36055  
36056 \newline
36057 \InsetSpace ~
36058 \InsetSpace ~
36059 \InsetSpace ~
36060 case 9: ...\InsetSpace ~
36061 \InsetSpace ~
36062 \InsetSpace ~
36063 \InsetSpace ~
36064 \InsetSpace ~
36065 \InsetSpace ~
36066 \InsetSpace ~
36067 \InsetSpace ~
36068 \InsetSpace ~
36069 \InsetSpace ~
36070 \InsetSpace ~
36071 \InsetSpace ~
36072 \InsetSpace ~
36073 \InsetSpace ~
36074 \InsetSpace ~
36075 \InsetSpace ~
36076 \InsetSpace ~
36077 \InsetSpace ~
36078 \InsetSpace ~
36079 \InsetSpace ~
36080 \InsetSpace ~
36081 \InsetSpace ~
36082 \InsetSpace ~
36083 \InsetSpace ~
36084 \InsetSpace ~
36085 \InsetSpace ~
36086 case 6: ...
36087  
36088 \newline
36089 \InsetSpace ~
36090 \InsetSpace ~
36091 \InsetSpace ~
36092 case 10: ...\InsetSpace ~
36093 \InsetSpace ~
36094 \InsetSpace ~
36095 \InsetSpace ~
36096 \InsetSpace ~
36097 \InsetSpace ~
36098 \InsetSpace ~
36099 \InsetSpace ~
36100 \InsetSpace ~
36101 \InsetSpace ~
36102 \InsetSpace ~
36103 \InsetSpace ~
36104 \InsetSpace ~
36105 \InsetSpace ~
36106 \InsetSpace ~
36107 \InsetSpace ~
36108 \InsetSpace ~
36109 \InsetSpace ~
36110 \InsetSpace ~
36111 \InsetSpace ~
36112 \InsetSpace ~
36113 \InsetSpace ~
36114 \InsetSpace ~
36115 \InsetSpace ~
36116 \InsetSpace ~
36117 case 7: ...
36118  
36119 \newline
36120 \InsetSpace ~
36121 \InsetSpace ~
36122 \InsetSpace ~
36123 case 11: ...\InsetSpace ~
36124 \InsetSpace ~
36125 \InsetSpace ~
36126 \InsetSpace ~
36127 \InsetSpace ~
36128 \InsetSpace ~
36129 \InsetSpace ~
36130 \InsetSpace ~
36131 \InsetSpace ~
36132 \InsetSpace ~
36133 \InsetSpace ~
36134 \InsetSpace ~
36135 \InsetSpace ~
36136 \InsetSpace ~
36137 \InsetSpace ~
36138 \InsetSpace ~
36139 \InsetSpace ~
36140 \InsetSpace ~
36141 \InsetSpace ~
36142 \InsetSpace ~
36143 \InsetSpace ~
36144 \InsetSpace ~
36145 \InsetSpace ~
36146 \InsetSpace ~
36147 \InsetSpace ~
36148 case 8: ...
36149  
36150 \newline
36151 }\InsetSpace ~
36152 \InsetSpace ~
36153 \InsetSpace ~
36154 \InsetSpace ~
36155 \InsetSpace ~
36156 \InsetSpace ~
36157 \InsetSpace ~
36158 \InsetSpace ~
36159 \InsetSpace ~
36160 \InsetSpace ~
36161 \InsetSpace ~
36162 \InsetSpace ~
36163 \InsetSpace ~
36164 \InsetSpace ~
36165 \InsetSpace ~
36166 \InsetSpace ~
36167 \InsetSpace ~
36168 \InsetSpace ~
36169 \InsetSpace ~
36170 \InsetSpace ~
36171 \InsetSpace ~
36172 \InsetSpace ~
36173 \InsetSpace ~
36174 \InsetSpace ~
36175 \InsetSpace ~
36176 \InsetSpace ~
36177 \InsetSpace ~
36178 \InsetSpace ~
36179 \InsetSpace ~
36180 \InsetSpace ~
36181 \InsetSpace ~
36182 \InsetSpace ~
36183 \InsetSpace ~
36184 \InsetSpace ~
36185 \InsetSpace ~
36186 \InsetSpace ~
36187 }
36188 \end_layout
36189
36190 \begin_layout Standard
36191 Both the above switch statements will be implemented using a jump-table.
36192  The example to the right side is slightly more efficient as the check for
36193  the lower boundary of the jump-table is not needed.
36194 \end_layout
36195
36196 \end_deeper
36197 \begin_layout Itemize
36198 The number of case labels is not larger than supported by the target architectur
36199 e.
36200 \end_layout
36201
36202 \begin_layout Itemize
36203 If the case labels are not in numerical sequence ('gaps' between cases)
36204  SDCC checks whether a jump table with additionally inserted dummy cases
36205  is still attractive.
36206  
36207 \end_layout
36208
36209 \begin_layout Itemize
36210 If the starting number is not zero and a check for the lower boundary of
36211  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
36212  ...
36213  .
36214 \end_layout
36215
36216 \begin_layout Standard
36217 Switch statements which have large gaps in the numeric sequence or those
36218  that have too many case labels can be split into more than one switch statement
36219  for efficient code generation, e.g.:
36220 \end_layout
36221
36222 \begin_layout Verse
36223
36224 \family typewriter
36225 switch (i) { 
36226 \newline
36227 \InsetSpace ~
36228 \InsetSpace ~
36229 case 1: ...
36230  
36231 \newline
36232 \InsetSpace ~
36233 \InsetSpace ~
36234 case 2: ...
36235  
36236 \newline
36237 \InsetSpace ~
36238 \InsetSpace ~
36239 case 3: ...
36240  
36241 \newline
36242 \InsetSpace ~
36243 \InsetSpace ~
36244 case 4: ...
36245  
36246 \newline
36247 \InsetSpace ~
36248 \InsetSpace ~
36249 case 5: ...
36250  
36251 \newline
36252 \InsetSpace ~
36253 \InsetSpace ~
36254 case 6: ...
36255  
36256 \newline
36257 \InsetSpace ~
36258 \InsetSpace ~
36259 case 7: ...
36260  
36261 \newline
36262 \InsetSpace ~
36263 \InsetSpace ~
36264 case 101: ...
36265  
36266 \newline
36267 \InsetSpace ~
36268 \InsetSpace ~
36269 case 102: ...
36270  
36271 \newline
36272 \InsetSpace ~
36273 \InsetSpace ~
36274 case 103: ...
36275  
36276 \newline
36277 \InsetSpace ~
36278 \InsetSpace ~
36279 case 104: ...
36280  
36281 \newline
36282 \InsetSpace ~
36283 \InsetSpace ~
36284 case 105: ...
36285  
36286 \newline
36287 \InsetSpace ~
36288 \InsetSpace ~
36289 case 106: ...
36290  
36291 \newline
36292 \InsetSpace ~
36293 \InsetSpace ~
36294 case 107: ...
36295  
36296 \newline
36297 }
36298 \end_layout
36299
36300 \begin_layout Standard
36301 If the above switch statement is broken down into two switch statements
36302 \end_layout
36303
36304 \begin_layout Verse
36305
36306 \family typewriter
36307 switch (i) { 
36308 \newline
36309 \InsetSpace ~
36310 \InsetSpace ~
36311 case 1: ...
36312  
36313 \newline
36314 \InsetSpace ~
36315 \InsetSpace ~
36316 case 2: ...
36317  
36318 \newline
36319 \InsetSpace ~
36320 \InsetSpace ~
36321 case 3: ...
36322  
36323 \newline
36324 \InsetSpace ~
36325 \InsetSpace ~
36326 case 4: ...
36327  
36328 \newline
36329 \InsetSpace ~
36330 \InsetSpace ~
36331 case 5: ...
36332  
36333 \newline
36334 \InsetSpace ~
36335 \InsetSpace ~
36336 case 6: ...
36337  
36338 \newline
36339 \InsetSpace ~
36340 \InsetSpace ~
36341 case 7: ...
36342  
36343 \newline
36344 }
36345 \end_layout
36346
36347 \begin_layout Standard
36348 and
36349 \end_layout
36350
36351 \begin_layout Verse
36352
36353 \family typewriter
36354 switch (i) { 
36355 \newline
36356 \InsetSpace ~
36357 \InsetSpace ~
36358 case 101: ...
36359  
36360 \newline
36361 \InsetSpace ~
36362 \InsetSpace ~
36363 case 102: ...
36364  
36365 \newline
36366 \InsetSpace ~
36367 \InsetSpace ~
36368 case 103: ...
36369  
36370 \newline
36371 \InsetSpace ~
36372 \InsetSpace ~
36373 case 104: ...
36374  
36375 \newline
36376 \InsetSpace ~
36377 \InsetSpace ~
36378 case 105: ...
36379  
36380 \newline
36381 \InsetSpace ~
36382 \InsetSpace ~
36383 case 106: ...
36384  
36385 \newline
36386 \InsetSpace ~
36387 \InsetSpace ~
36388 case 107: ...
36389  
36390 \newline
36391 }
36392 \end_layout
36393
36394 \begin_layout Standard
36395 then both the switch statements will be implemented using jump-tables whereas
36396  the unmodified switch statement will not be.
36397 \end_layout
36398
36399 \begin_layout Standard
36400 \begin_inset Note Note
36401 status collapsed
36402
36403 \begin_layout Standard
36404 There might be reasons which SDCC cannot know about to either favour or
36405  not favour jump tables.
36406  If the target system has to be as quick for the last switch case as for
36407  the first (pro jump table), or if the switch argument is known to be zero
36408  in the majority of the cases (contra jump table).
36409 \end_layout
36410
36411 \end_inset
36412
36413
36414 \end_layout
36415
36416 \begin_layout Standard
36417 The pragma nojtbound
36418 \begin_inset LatexCommand index
36419 name "\\#pragma nojtbound"
36420
36421 \end_inset
36422
36423  can be used to turn off checking the 
36424 \emph on
36425 j
36426 \emph default
36427 ump 
36428 \emph on
36429 t
36430 \emph default
36431 able 
36432 \emph on
36433 bound
36434 \emph default
36435 aries.
36436  It has no effect if a default label is supplied.
36437  Use of this pragma is dangerous: if the switch
36438 \begin_inset LatexCommand index
36439 name "switch statement"
36440
36441 \end_inset
36442
36443  argument is not matched by a case statement the processor will happily
36444  jump into Nirvana.
36445 \end_layout
36446
36447 \begin_layout Subsection
36448 Bit-shifting Operations
36449 \begin_inset LatexCommand index
36450 name "Bit shifting"
36451
36452 \end_inset
36453
36454 .
36455 \end_layout
36456
36457 \begin_layout Standard
36458 Bit shifting is one of the most frequently used operation in embedded programmin
36459 g.
36460  SDCC tries to implement bit-shift operations in the most efficient way
36461  possible, e.g.:
36462 \end_layout
36463
36464 \begin_layout Verse
36465
36466 \family typewriter
36467 unsigned char i;
36468 \newline
36469 ...
36470  
36471 \newline
36472 i >>= 4; 
36473 \newline
36474 ...
36475 \end_layout
36476
36477 \begin_layout Standard
36478 generates the following code:
36479 \end_layout
36480
36481 \begin_layout Verse
36482
36483 \family typewriter
36484 mov\InsetSpace ~
36485  a,_i 
36486 \newline
36487 swap a 
36488 \newline
36489 anl\InsetSpace ~
36490  a,#0x0f 
36491 \newline
36492 mov\InsetSpace ~
36493  _i,a
36494 \end_layout
36495
36496 \begin_layout Standard
36497 In general SDCC will never setup a loop if the shift count is known.
36498  Another example:
36499 \end_layout
36500
36501 \begin_layout Verse
36502
36503 \family typewriter
36504 unsigned int i; 
36505 \newline
36506 ...
36507  
36508 \newline
36509 i >>= 9; 
36510 \newline
36511 ...
36512 \end_layout
36513
36514 \begin_layout Standard
36515 will generate:
36516 \end_layout
36517
36518 \begin_layout Verse
36519
36520 \family typewriter
36521 mov\InsetSpace ~
36522 \InsetSpace ~
36523 a,(_i + 1) 
36524 \newline
36525 mov\InsetSpace ~
36526 \InsetSpace ~
36527 (_i + 1),#0x00 
36528 \newline
36529 clr\InsetSpace ~
36530 \InsetSpace ~
36531
36532 \newline
36533 rrc\InsetSpace ~
36534 \InsetSpace ~
36535
36536 \newline
36537 mov\InsetSpace ~
36538 \InsetSpace ~
36539 _i,a
36540 \end_layout
36541
36542 \begin_layout Subsection
36543 Bit-rotation
36544 \begin_inset LatexCommand index
36545 name "Bit rotation"
36546
36547 \end_inset
36548
36549
36550 \end_layout
36551
36552 \begin_layout Standard
36553 A special case of the bit-shift operation is bit rotation
36554 \begin_inset LatexCommand index
36555 name "rotating bits"
36556
36557 \end_inset
36558
36559 , SDCC recognizes the following expression to be a left bit-rotation:
36560 \end_layout
36561
36562 \begin_layout Verse
36563
36564 \family typewriter
36565 \series bold
36566 unsigned
36567 \series default
36568 \InsetSpace ~
36569 \InsetSpace ~
36570 char i;\InsetSpace ~
36571 \InsetSpace ~
36572 \InsetSpace ~
36573 \InsetSpace ~
36574 \InsetSpace ~
36575 \InsetSpace ~
36576 \InsetSpace ~
36577 \InsetSpace ~
36578 \InsetSpace ~
36579 \InsetSpace ~
36580 \InsetSpace ~
36581 /* unsigned is needed for rotation */ 
36582 \newline
36583 ...
36584  
36585 \newline
36586 i = ((i << 1) | (i >> 7));
36587 \family default
36588  
36589 \newline
36590
36591 \family typewriter
36592 ...
36593 \end_layout
36594
36595 \begin_layout Standard
36596 will generate the following code:
36597 \end_layout
36598
36599 \begin_layout Verse
36600
36601 \family typewriter
36602 mov\InsetSpace ~
36603 \InsetSpace ~
36604 a,_i 
36605 \newline
36606 rl\InsetSpace ~
36607 \InsetSpace ~
36608 \InsetSpace ~
36609
36610 \newline
36611 mov\InsetSpace ~
36612 \InsetSpace ~
36613 _i,a
36614 \end_layout
36615
36616 \begin_layout Standard
36617 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
36618 ns of this case will also be recognized as bit-rotation, i.e.: 
36619 \end_layout
36620
36621 \begin_layout Verse
36622
36623 \family typewriter
36624 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
36625 \end_layout
36626
36627 \begin_layout Subsection
36628 Nibble and Byte Swapping
36629 \end_layout
36630
36631 \begin_layout Standard
36632 Other special cases of the bit-shift operations are nibble or byte swapping
36633 \begin_inset LatexCommand index
36634 name "swapping nibbles/bytes"
36635
36636 \end_inset
36637
36638 , SDCC recognizes the following expressions:
36639 \end_layout
36640
36641 \begin_layout Verse
36642
36643 \family typewriter
36644 \series bold
36645 unsigned
36646 \series default
36647 \InsetSpace ~
36648 \InsetSpace ~
36649 char i; 
36650 \newline
36651
36652 \series bold
36653 unsigned
36654 \series default
36655 \InsetSpace ~
36656 \InsetSpace ~
36657 int j; 
36658 \newline
36659 ...
36660  
36661 \newline
36662 i = ((i << 4) | (i >> 4));
36663 \family default
36664  
36665 \newline
36666
36667 \family typewriter
36668 j = ((j << 8) | (j >> 8)); 
36669 \end_layout
36670
36671 \begin_layout Standard
36672 and generates a swap instruction for the nibble swapping
36673 \begin_inset LatexCommand index
36674 name "Nibble swapping"
36675
36676 \end_inset
36677
36678  or move instructions for the byte swapping
36679 \begin_inset LatexCommand index
36680 name "Byte swapping"
36681
36682 \end_inset
36683
36684 .
36685  The 
36686 \begin_inset Quotes sld
36687 \end_inset
36688
36689 j
36690 \begin_inset Quotes srd
36691 \end_inset
36692
36693  example can be used to convert from little to big-endian or vice versa.
36694  If you want to change the endianness of a 
36695 \emph on
36696 signed
36697 \emph default
36698  integer you have to cast to 
36699 \family typewriter
36700 (unsigned int)
36701 \family default
36702  first.
36703 \end_layout
36704
36705 \begin_layout Standard
36706 Note that SDCC stores numbers in little-endian
36707 \begin_inset Foot
36708 status open
36709
36710 \begin_layout Standard
36711 Usually 8-bit processors don't care much about endianness.
36712  This is not the case for the standard 8051 which only has an instruction
36713  to increment its 
36714 \emph on
36715 dptr
36716 \emph default
36717
36718 \begin_inset LatexCommand index
36719 name "DPTR"
36720
36721 \end_inset
36722
36723 -datapointer so little-endian is the more efficient byte order.
36724 \end_layout
36725
36726 \end_inset
36727
36728
36729 \begin_inset LatexCommand index
36730 name "little-endian"
36731
36732 \end_inset
36733
36734
36735 \begin_inset LatexCommand index
36736 name "Endianness"
36737
36738 \end_inset
36739
36740  format (i.e.
36741  lowest order first).
36742 \end_layout
36743
36744 \begin_layout Subsection
36745 Highest Order Bit
36746 \begin_inset LatexCommand index
36747 name "Highest Order Bit"
36748
36749 \end_inset
36750
36751  / Any Order Bit
36752 \begin_inset LatexCommand index
36753 name "Any Order Bit"
36754
36755 \end_inset
36756
36757
36758 \end_layout
36759
36760 \begin_layout Standard
36761 It is frequently required to obtain the highest order bit of an integral
36762  type (long, int, short or char types).
36763  Also obtaining any other order bit is not uncommon.
36764  SDCC recognizes the following expressions to yield the highest order bit
36765  and generates optimized code for it, e.g.:
36766 \end_layout
36767
36768 \begin_layout Verse
36769
36770 \family typewriter
36771 unsigned int gint; 
36772 \newline
36773
36774 \newline
36775 foo () { 
36776 \newline
36777 \InsetSpace ~
36778 \InsetSpace ~
36779 unsigned char hob1, aob1; 
36780 \newline
36781 \InsetSpace ~
36782 \InsetSpace ~
36783 bit hob2, hob3, aob2,
36784  aob3; 
36785 \newline
36786 \InsetSpace ~
36787 \InsetSpace ~
36788 ...
36789  
36790 \newline
36791 \InsetSpace ~
36792 \InsetSpace ~
36793 hob1 = (gint >> 15) & 1; 
36794 \newline
36795 \InsetSpace ~
36796 \InsetSpace ~
36797 hob2 = (gint >> 15) & 1; 
36798 \newline
36799 \InsetSpace ~
36800 \InsetSpace ~
36801 hob3 = gint & 0x8000;
36802  
36803 \newline
36804 \InsetSpace ~
36805 \InsetSpace ~
36806 aob1 = (gint >> 9) & 1; 
36807 \newline
36808 \InsetSpace ~
36809 \InsetSpace ~
36810 aob2 = (gint >> 8) & 1; 
36811 \newline
36812 \InsetSpace ~
36813 \InsetSpace ~
36814 aob3 = gint & 0x0800; 
36815 \newline
36816 \InsetSpace ~
36817 \InsetSpace ~
36818 ..
36819  
36820 \newline
36821 }
36822 \end_layout
36823
36824 \begin_layout Standard
36825 will generate the following code:
36826 \end_layout
36827
36828 \begin_layout Verse
36829
36830 \family typewriter
36831 \InsetSpace ~
36832 \InsetSpace ~
36833 \InsetSpace ~
36834 \InsetSpace ~
36835 \InsetSpace ~
36836 \InsetSpace ~
36837 \InsetSpace ~
36838 \InsetSpace ~
36839 \InsetSpace ~
36840 \InsetSpace ~
36841 \InsetSpace ~
36842 \InsetSpace ~
36843 \InsetSpace ~
36844 \InsetSpace ~
36845 \InsetSpace ~
36846 \InsetSpace ~
36847 \InsetSpace ~
36848 \InsetSpace ~
36849 \InsetSpace ~
36850 \InsetSpace ~
36851 \InsetSpace ~
36852 \InsetSpace ~
36853 \InsetSpace ~
36854 \InsetSpace ~
36855 \InsetSpace ~
36856  61 ;\InsetSpace ~
36857  hob.c 7 
36858 \newline
36859 000A E5*01\InsetSpace ~
36860 \InsetSpace ~
36861 \InsetSpace ~
36862 \InsetSpace ~
36863 \InsetSpace ~
36864 \InsetSpace ~
36865 \InsetSpace ~
36866 \InsetSpace ~
36867 \InsetSpace ~
36868 \InsetSpace ~
36869 \InsetSpace ~
36870 \InsetSpace ~
36871 \InsetSpace ~
36872 \InsetSpace ~
36873 \InsetSpace ~
36874  62\InsetSpace ~
36875 \InsetSpace ~
36876 \InsetSpace ~
36877 \InsetSpace ~
36878 \InsetSpace ~
36879 \InsetSpace ~
36880 \InsetSpace ~
36881 \InsetSpace ~
36882  mov\InsetSpace ~
36883 \InsetSpace ~
36884  a,(_gint + 1) 
36885 \newline
36886 000C 23\InsetSpace ~
36887 \InsetSpace ~
36888 \InsetSpace ~
36889 \InsetSpace ~
36890 \InsetSpace ~
36891 \InsetSpace ~
36892 \InsetSpace ~
36893 \InsetSpace ~
36894 \InsetSpace ~
36895 \InsetSpace ~
36896 \InsetSpace ~
36897 \InsetSpace ~
36898 \InsetSpace ~
36899 \InsetSpace ~
36900 \InsetSpace ~
36901 \InsetSpace ~
36902 \InsetSpace ~
36903 \InsetSpace ~
36904  63\InsetSpace ~
36905 \InsetSpace ~
36906 \InsetSpace ~
36907 \InsetSpace ~
36908 \InsetSpace ~
36909 \InsetSpace ~
36910 \InsetSpace ~
36911 \InsetSpace ~
36912  rl\InsetSpace ~
36913 \InsetSpace ~
36914 \InsetSpace ~
36915  a 
36916 \newline
36917 000D 54 01\InsetSpace ~
36918 \InsetSpace ~
36919 \InsetSpace ~
36920 \InsetSpace ~
36921 \InsetSpace ~
36922 \InsetSpace ~
36923 \InsetSpace ~
36924 \InsetSpace ~
36925 \InsetSpace ~
36926 \InsetSpace ~
36927 \InsetSpace ~
36928 \InsetSpace ~
36929 \InsetSpace ~
36930 \InsetSpace ~
36931 \InsetSpace ~
36932
36933  64\InsetSpace ~
36934 \InsetSpace ~
36935 \InsetSpace ~
36936 \InsetSpace ~
36937 \InsetSpace ~
36938 \InsetSpace ~
36939 \InsetSpace ~
36940 \InsetSpace ~
36941  anl\InsetSpace ~
36942 \InsetSpace ~
36943  a,#0x01 
36944 \newline
36945 000F F5*02\InsetSpace ~
36946 \InsetSpace ~
36947 \InsetSpace ~
36948 \InsetSpace ~
36949 \InsetSpace ~
36950 \InsetSpace ~
36951 \InsetSpace ~
36952 \InsetSpace ~
36953 \InsetSpace ~
36954 \InsetSpace ~
36955 \InsetSpace ~
36956 \InsetSpace ~
36957 \InsetSpace ~
36958 \InsetSpace ~
36959 \InsetSpace ~
36960  65\InsetSpace ~
36961 \InsetSpace ~
36962 \InsetSpace ~
36963 \InsetSpace ~
36964 \InsetSpace ~
36965 \InsetSpace ~
36966 \InsetSpace ~
36967 \InsetSpace ~
36968  mov\InsetSpace ~
36969 \InsetSpace ~
36970  _foo_hob1_1_1,a 
36971 \newline
36972 \InsetSpace ~
36973 \InsetSpace ~
36974 \InsetSpace ~
36975 \InsetSpace ~
36976 \InsetSpace ~
36977 \InsetSpace ~
36978 \InsetSpace ~
36979 \InsetSpace ~
36980 \InsetSpace ~
36981 \InsetSpace ~
36982 \InsetSpace ~
36983 \InsetSpace ~
36984 \InsetSpace ~
36985 \InsetSpace ~
36986 \InsetSpace ~
36987 \InsetSpace ~
36988 \InsetSpace ~
36989 \InsetSpace ~
36990 \InsetSpace ~
36991 \InsetSpace ~
36992 \InsetSpace ~
36993 \InsetSpace ~
36994 \InsetSpace ~
36995 \InsetSpace ~
36996 \InsetSpace ~
36997  66 ;\InsetSpace ~
36998  hob.c 8 
36999 \newline
37000 0011 E5*01\InsetSpace ~
37001 \InsetSpace ~
37002 \InsetSpace ~
37003 \InsetSpace ~
37004 \InsetSpace ~
37005 \InsetSpace ~
37006 \InsetSpace ~
37007 \InsetSpace ~
37008 \InsetSpace ~
37009 \InsetSpace ~
37010 \InsetSpace ~
37011 \InsetSpace ~
37012 \InsetSpace ~
37013 \InsetSpace ~
37014 \InsetSpace ~
37015
37016  67\InsetSpace ~
37017 \InsetSpace ~
37018 \InsetSpace ~
37019 \InsetSpace ~
37020 \InsetSpace ~
37021 \InsetSpace ~
37022 \InsetSpace ~
37023 \InsetSpace ~
37024  mov\InsetSpace ~
37025 \InsetSpace ~
37026  a,(_gint + 1) 
37027 \newline
37028 0013 33\InsetSpace ~
37029 \InsetSpace ~
37030 \InsetSpace ~
37031 \InsetSpace ~
37032 \InsetSpace ~
37033 \InsetSpace ~
37034 \InsetSpace ~
37035 \InsetSpace ~
37036 \InsetSpace ~
37037 \InsetSpace ~
37038 \InsetSpace ~
37039 \InsetSpace ~
37040 \InsetSpace ~
37041 \InsetSpace ~
37042 \InsetSpace ~
37043 \InsetSpace ~
37044 \InsetSpace ~
37045 \InsetSpace ~
37046  68\InsetSpace ~
37047 \InsetSpace ~
37048 \InsetSpace ~
37049 \InsetSpace ~
37050 \InsetSpace ~
37051 \InsetSpace ~
37052 \InsetSpace ~
37053 \InsetSpace ~
37054  rlc\InsetSpace ~
37055 \InsetSpace ~
37056  a 
37057 \newline
37058 0014 92*00\InsetSpace ~
37059 \InsetSpace ~
37060 \InsetSpace ~
37061 \InsetSpace ~
37062 \InsetSpace ~
37063 \InsetSpace ~
37064 \InsetSpace ~
37065 \InsetSpace ~
37066 \InsetSpace ~
37067 \InsetSpace ~
37068 \InsetSpace ~
37069 \InsetSpace ~
37070 \InsetSpace ~
37071 \InsetSpace ~
37072 \InsetSpace ~
37073  69\InsetSpace ~
37074 \InsetSpace ~
37075 \InsetSpace ~
37076 \InsetSpace ~
37077 \InsetSpace ~
37078 \InsetSpace ~
37079 \InsetSpace ~
37080 \InsetSpace ~
37081  mov\InsetSpace ~
37082 \InsetSpace ~
37083  _foo_hob2_1_1,c
37084  
37085 \newline
37086 \InsetSpace ~
37087 \InsetSpace ~
37088 \InsetSpace ~
37089 \InsetSpace ~
37090 \InsetSpace ~
37091 \InsetSpace ~
37092 \InsetSpace ~
37093 \InsetSpace ~
37094 \InsetSpace ~
37095 \InsetSpace ~
37096 \InsetSpace ~
37097 \InsetSpace ~
37098 \InsetSpace ~
37099 \InsetSpace ~
37100 \InsetSpace ~
37101 \InsetSpace ~
37102 \InsetSpace ~
37103 \InsetSpace ~
37104 \InsetSpace ~
37105 \InsetSpace ~
37106 \InsetSpace ~
37107 \InsetSpace ~
37108 \InsetSpace ~
37109 \InsetSpace ~
37110 \InsetSpace ~
37111  66 ;\InsetSpace ~
37112  hob.c 9 
37113 \newline
37114 0016 E5*01\InsetSpace ~
37115 \InsetSpace ~
37116 \InsetSpace ~
37117 \InsetSpace ~
37118 \InsetSpace ~
37119 \InsetSpace ~
37120 \InsetSpace ~
37121 \InsetSpace ~
37122 \InsetSpace ~
37123 \InsetSpace ~
37124 \InsetSpace ~
37125 \InsetSpace ~
37126 \InsetSpace ~
37127 \InsetSpace ~
37128 \InsetSpace ~
37129  67\InsetSpace ~
37130 \InsetSpace ~
37131 \InsetSpace ~
37132 \InsetSpace ~
37133 \InsetSpace ~
37134 \InsetSpace ~
37135 \InsetSpace ~
37136 \InsetSpace ~
37137  mov\InsetSpace ~
37138 \InsetSpace ~
37139  a,(_gint + 1) 
37140 \newline
37141 0018 33\InsetSpace ~
37142 \InsetSpace ~
37143 \InsetSpace ~
37144 \InsetSpace ~
37145 \InsetSpace ~
37146 \InsetSpace ~
37147 \InsetSpace ~
37148 \InsetSpace ~
37149 \InsetSpace ~
37150 \InsetSpace ~
37151 \InsetSpace ~
37152 \InsetSpace ~
37153 \InsetSpace ~
37154 \InsetSpace ~
37155 \InsetSpace ~
37156 \InsetSpace ~
37157 \InsetSpace ~
37158 \InsetSpace ~
37159  68\InsetSpace ~
37160 \InsetSpace ~
37161 \InsetSpace ~
37162 \InsetSpace ~
37163 \InsetSpace ~
37164 \InsetSpace ~
37165 \InsetSpace ~
37166 \InsetSpace ~
37167  rlc\InsetSpace ~
37168 \InsetSpace ~
37169  a 
37170 \newline
37171 0019 92*01\InsetSpace ~
37172 \InsetSpace ~
37173 \InsetSpace ~
37174 \InsetSpace ~
37175 \InsetSpace ~
37176 \InsetSpace ~
37177 \InsetSpace ~
37178 \InsetSpace ~
37179 \InsetSpace ~
37180 \InsetSpace ~
37181 \InsetSpace ~
37182 \InsetSpace ~
37183 \InsetSpace ~
37184 \InsetSpace ~
37185 \InsetSpace ~
37186
37187  69\InsetSpace ~
37188 \InsetSpace ~
37189 \InsetSpace ~
37190 \InsetSpace ~
37191 \InsetSpace ~
37192 \InsetSpace ~
37193 \InsetSpace ~
37194 \InsetSpace ~
37195  mov\InsetSpace ~
37196 \InsetSpace ~
37197  _foo_hob3_1_1,c 
37198 \newline
37199 \InsetSpace ~
37200 \InsetSpace ~
37201 \InsetSpace ~
37202 \InsetSpace ~
37203 \InsetSpace ~
37204 \InsetSpace ~
37205 \InsetSpace ~
37206 \InsetSpace ~
37207 \InsetSpace ~
37208 \InsetSpace ~
37209 \InsetSpace ~
37210 \InsetSpace ~
37211 \InsetSpace ~
37212 \InsetSpace ~
37213 \InsetSpace ~
37214 \InsetSpace ~
37215 \InsetSpace ~
37216 \InsetSpace ~
37217 \InsetSpace ~
37218 \InsetSpace ~
37219 \InsetSpace ~
37220 \InsetSpace ~
37221 \InsetSpace ~
37222 \InsetSpace ~
37223 \InsetSpace ~
37224  70 ;\InsetSpace ~
37225  hob.c 10 
37226 \newline
37227 001B E5*01\InsetSpace ~
37228 \InsetSpace ~
37229 \InsetSpace ~
37230 \InsetSpace ~
37231 \InsetSpace ~
37232 \InsetSpace ~
37233 \InsetSpace ~
37234 \InsetSpace ~
37235 \InsetSpace ~
37236 \InsetSpace ~
37237 \InsetSpace ~
37238 \InsetSpace ~
37239 \InsetSpace ~
37240 \InsetSpace ~
37241 \InsetSpace ~
37242  71\InsetSpace ~
37243 \InsetSpace ~
37244 \InsetSpace ~
37245 \InsetSpace ~
37246 \InsetSpace ~
37247 \InsetSpace ~
37248 \InsetSpace ~
37249 \InsetSpace ~
37250  mov\InsetSpace ~
37251 \InsetSpace ~
37252  a,(_gint + 1) 
37253 \newline
37254 001D
37255  03\InsetSpace ~
37256 \InsetSpace ~
37257 \InsetSpace ~
37258 \InsetSpace ~
37259 \InsetSpace ~
37260 \InsetSpace ~
37261 \InsetSpace ~
37262 \InsetSpace ~
37263 \InsetSpace ~
37264 \InsetSpace ~
37265 \InsetSpace ~
37266 \InsetSpace ~
37267 \InsetSpace ~
37268 \InsetSpace ~
37269 \InsetSpace ~
37270 \InsetSpace ~
37271 \InsetSpace ~
37272 \InsetSpace ~
37273  72\InsetSpace ~
37274 \InsetSpace ~
37275 \InsetSpace ~
37276 \InsetSpace ~
37277 \InsetSpace ~
37278 \InsetSpace ~
37279 \InsetSpace ~
37280 \InsetSpace ~
37281  rr\InsetSpace ~
37282 \InsetSpace ~
37283 \InsetSpace ~
37284  a 
37285 \newline
37286 001E 54 01\InsetSpace ~
37287 \InsetSpace ~
37288 \InsetSpace ~
37289 \InsetSpace ~
37290 \InsetSpace ~
37291 \InsetSpace ~
37292 \InsetSpace ~
37293 \InsetSpace ~
37294 \InsetSpace ~
37295 \InsetSpace ~
37296 \InsetSpace ~
37297 \InsetSpace ~
37298 \InsetSpace ~
37299 \InsetSpace ~
37300 \InsetSpace ~
37301  73\InsetSpace ~
37302 \InsetSpace ~
37303 \InsetSpace ~
37304 \InsetSpace ~
37305 \InsetSpace ~
37306 \InsetSpace ~
37307 \InsetSpace ~
37308 \InsetSpace ~
37309  anl\InsetSpace ~
37310 \InsetSpace ~
37311  a,#0x01 
37312 \newline
37313 0020 F5*03\InsetSpace ~
37314 \InsetSpace ~
37315 \InsetSpace ~
37316 \InsetSpace ~
37317 \InsetSpace ~
37318 \InsetSpace ~
37319 \InsetSpace ~
37320 \InsetSpace ~
37321 \InsetSpace ~
37322 \InsetSpace ~
37323 \InsetSpace ~
37324 \InsetSpace ~
37325 \InsetSpace ~
37326 \InsetSpace ~
37327 \InsetSpace ~
37328  74\InsetSpace ~
37329 \InsetSpace ~
37330 \InsetSpace ~
37331 \InsetSpace ~
37332 \InsetSpace ~
37333 \InsetSpace ~
37334 \InsetSpace ~
37335 \InsetSpace ~
37336  mov\InsetSpace ~
37337 \InsetSpace ~
37338  _foo_aob1_1_1,a
37339  
37340 \newline
37341 \InsetSpace ~
37342 \InsetSpace ~
37343 \InsetSpace ~
37344 \InsetSpace ~
37345 \InsetSpace ~
37346 \InsetSpace ~
37347 \InsetSpace ~
37348 \InsetSpace ~
37349 \InsetSpace ~
37350 \InsetSpace ~
37351 \InsetSpace ~
37352 \InsetSpace ~
37353 \InsetSpace ~
37354 \InsetSpace ~
37355 \InsetSpace ~
37356 \InsetSpace ~
37357 \InsetSpace ~
37358 \InsetSpace ~
37359 \InsetSpace ~
37360 \InsetSpace ~
37361 \InsetSpace ~
37362 \InsetSpace ~
37363 \InsetSpace ~
37364 \InsetSpace ~
37365 \InsetSpace ~
37366  75 ;\InsetSpace ~
37367  hob.c 11 
37368 \newline
37369 0022 E5*01\InsetSpace ~
37370 \InsetSpace ~
37371 \InsetSpace ~
37372 \InsetSpace ~
37373 \InsetSpace ~
37374 \InsetSpace ~
37375 \InsetSpace ~
37376 \InsetSpace ~
37377 \InsetSpace ~
37378 \InsetSpace ~
37379 \InsetSpace ~
37380 \InsetSpace ~
37381 \InsetSpace ~
37382 \InsetSpace ~
37383 \InsetSpace ~
37384  76\InsetSpace ~
37385 \InsetSpace ~
37386 \InsetSpace ~
37387 \InsetSpace ~
37388 \InsetSpace ~
37389 \InsetSpace ~
37390 \InsetSpace ~
37391 \InsetSpace ~
37392  mov\InsetSpace ~
37393 \InsetSpace ~
37394  a,(_gint + 1) 
37395 \newline
37396 0024 13\InsetSpace ~
37397 \InsetSpace ~
37398 \InsetSpace ~
37399 \InsetSpace ~
37400 \InsetSpace ~
37401 \InsetSpace ~
37402 \InsetSpace ~
37403 \InsetSpace ~
37404 \InsetSpace ~
37405 \InsetSpace ~
37406 \InsetSpace ~
37407 \InsetSpace ~
37408 \InsetSpace ~
37409 \InsetSpace ~
37410 \InsetSpace ~
37411 \InsetSpace ~
37412 \InsetSpace ~
37413 \InsetSpace ~
37414  77\InsetSpace ~
37415 \InsetSpace ~
37416 \InsetSpace ~
37417 \InsetSpace ~
37418 \InsetSpace ~
37419 \InsetSpace ~
37420 \InsetSpace ~
37421 \InsetSpace ~
37422  rrc\InsetSpace ~
37423 \InsetSpace ~
37424  a 
37425 \newline
37426 0025 92*02\InsetSpace ~
37427 \InsetSpace ~
37428 \InsetSpace ~
37429 \InsetSpace ~
37430 \InsetSpace ~
37431 \InsetSpace ~
37432 \InsetSpace ~
37433 \InsetSpace ~
37434 \InsetSpace ~
37435 \InsetSpace ~
37436 \InsetSpace ~
37437 \InsetSpace ~
37438 \InsetSpace ~
37439 \InsetSpace ~
37440 \InsetSpace ~
37441
37442  78\InsetSpace ~
37443 \InsetSpace ~
37444 \InsetSpace ~
37445 \InsetSpace ~
37446 \InsetSpace ~
37447 \InsetSpace ~
37448 \InsetSpace ~
37449 \InsetSpace ~
37450  mov\InsetSpace ~
37451 \InsetSpace ~
37452  _foo_aob2_1_1,c 
37453 \newline
37454 \InsetSpace ~
37455 \InsetSpace ~
37456 \InsetSpace ~
37457 \InsetSpace ~
37458 \InsetSpace ~
37459 \InsetSpace ~
37460 \InsetSpace ~
37461 \InsetSpace ~
37462 \InsetSpace ~
37463 \InsetSpace ~
37464 \InsetSpace ~
37465 \InsetSpace ~
37466 \InsetSpace ~
37467 \InsetSpace ~
37468 \InsetSpace ~
37469 \InsetSpace ~
37470 \InsetSpace ~
37471 \InsetSpace ~
37472 \InsetSpace ~
37473 \InsetSpace ~
37474 \InsetSpace ~
37475 \InsetSpace ~
37476 \InsetSpace ~
37477 \InsetSpace ~
37478 \InsetSpace ~
37479  79 ;\InsetSpace ~
37480  hob.c 12 
37481 \newline
37482 0027 E5*01\InsetSpace ~
37483 \InsetSpace ~
37484 \InsetSpace ~
37485 \InsetSpace ~
37486 \InsetSpace ~
37487 \InsetSpace ~
37488 \InsetSpace ~
37489 \InsetSpace ~
37490 \InsetSpace ~
37491 \InsetSpace ~
37492 \InsetSpace ~
37493 \InsetSpace ~
37494 \InsetSpace ~
37495 \InsetSpace ~
37496 \InsetSpace ~
37497  80\InsetSpace ~
37498 \InsetSpace ~
37499 \InsetSpace ~
37500 \InsetSpace ~
37501 \InsetSpace ~
37502 \InsetSpace ~
37503 \InsetSpace ~
37504 \InsetSpace ~
37505  mov\InsetSpace ~
37506 \InsetSpace ~
37507  a,(_gint + 1) 
37508 \newline
37509 0029
37510  A2 E3\InsetSpace ~
37511 \InsetSpace ~
37512 \InsetSpace ~
37513 \InsetSpace ~
37514 \InsetSpace ~
37515 \InsetSpace ~
37516 \InsetSpace ~
37517 \InsetSpace ~
37518 \InsetSpace ~
37519 \InsetSpace ~
37520 \InsetSpace ~
37521 \InsetSpace ~
37522 \InsetSpace ~
37523 \InsetSpace ~
37524 \InsetSpace ~
37525  81\InsetSpace ~
37526 \InsetSpace ~
37527 \InsetSpace ~
37528 \InsetSpace ~
37529 \InsetSpace ~
37530 \InsetSpace ~
37531 \InsetSpace ~
37532 \InsetSpace ~
37533  mov\InsetSpace ~
37534 \InsetSpace ~
37535  c,acc[3] 
37536 \newline
37537 002B 92*03\InsetSpace ~
37538 \InsetSpace ~
37539 \InsetSpace ~
37540 \InsetSpace ~
37541 \InsetSpace ~
37542 \InsetSpace ~
37543 \InsetSpace ~
37544 \InsetSpace ~
37545 \InsetSpace ~
37546 \InsetSpace ~
37547 \InsetSpace ~
37548 \InsetSpace ~
37549 \InsetSpace ~
37550 \InsetSpace ~
37551 \InsetSpace ~
37552  82\InsetSpace ~
37553 \InsetSpace ~
37554 \InsetSpace ~
37555 \InsetSpace ~
37556 \InsetSpace ~
37557 \InsetSpace ~
37558 \InsetSpace ~
37559 \InsetSpace ~
37560  mov\InsetSpace ~
37561 \InsetSpace ~
37562  _foo_aob3_1_1,c 
37563 \end_layout
37564
37565 \begin_layout Standard
37566 Other variations of these cases however will 
37567 \emph on
37568 not
37569 \emph default
37570  be recognized.
37571  They are standard C expressions, so I heartily recommend these be the only
37572  way to get the highest order bit, (it is portable).
37573  Of course it will be recognized even if it is embedded in other expressions,
37574  e.g.:
37575 \end_layout
37576
37577 \begin_layout Verse
37578
37579 \family typewriter
37580 xyz = gint + ((gint >> 15) & 1);
37581 \end_layout
37582
37583 \begin_layout Standard
37584 will still be recognized.
37585 \end_layout
37586
37587 \begin_layout Subsection
37588 Higher Order Byte
37589 \begin_inset LatexCommand index
37590 name "Higher Order Byte"
37591
37592 \end_inset
37593
37594  / Higher Order Word
37595 \begin_inset LatexCommand index
37596 name "Higher Order Word"
37597
37598 \end_inset
37599
37600
37601 \end_layout
37602
37603 \begin_layout Standard
37604 It is also frequently required to obtain a higher order byte or word of
37605  a larger integral type (long, int or short types).
37606  SDCC recognizes the following expressions to yield the higher order byte
37607  or word and generates optimized code for it, e.g.:
37608 \end_layout
37609
37610 \begin_layout Verse
37611
37612 \family typewriter
37613 unsigned int gint; 
37614 \newline
37615 unsigned long int glong; 
37616 \newline
37617
37618 \newline
37619 foo () { 
37620 \newline
37621 \InsetSpace ~
37622 \InsetSpace ~
37623 unsigned char hob1,
37624  hob2; 
37625 \newline
37626 \InsetSpace ~
37627 \InsetSpace ~
37628 unsigned int how1, how2; 
37629 \newline
37630 \InsetSpace ~
37631 \InsetSpace ~
37632 ...
37633  
37634 \newline
37635 \InsetSpace ~
37636 \InsetSpace ~
37637 hob1 = (gint >> 8) & 0xFF; 
37638 \newline
37639 \InsetSpace ~
37640 \InsetSpace ~
37641 hob2 = glong >> 24; 
37642 \newline
37643 \InsetSpace ~
37644 \InsetSpace ~
37645 how1 = (glong >> 16) & 0xFFFF;
37646  
37647 \newline
37648 \InsetSpace ~
37649 \InsetSpace ~
37650 how2 = glong >> 8; 
37651 \newline
37652 \InsetSpace ~
37653 \InsetSpace ~
37654 ..
37655  
37656 \newline
37657 }
37658 \end_layout
37659
37660 \begin_layout Standard
37661 will generate the following code:
37662 \end_layout
37663
37664 \begin_layout Verse
37665
37666 \family typewriter
37667 \InsetSpace ~
37668 \InsetSpace ~
37669 \InsetSpace ~
37670 \InsetSpace ~
37671 \InsetSpace ~
37672 \InsetSpace ~
37673 \InsetSpace ~
37674 \InsetSpace ~
37675 \InsetSpace ~
37676 \InsetSpace ~
37677 \InsetSpace ~
37678 \InsetSpace ~
37679 \InsetSpace ~
37680 \InsetSpace ~
37681 \InsetSpace ~
37682 \InsetSpace ~
37683 \InsetSpace ~
37684 \InsetSpace ~
37685 \InsetSpace ~
37686 \InsetSpace ~
37687 \InsetSpace ~
37688 \InsetSpace ~
37689 \InsetSpace ~
37690 \InsetSpace ~
37691 \InsetSpace ~
37692  91 ;\InsetSpace ~
37693  hob.c 15 
37694 \newline
37695 0037 85*01*06\InsetSpace ~
37696 \InsetSpace ~
37697 \InsetSpace ~
37698 \InsetSpace ~
37699 \InsetSpace ~
37700 \InsetSpace ~
37701 \InsetSpace ~
37702 \InsetSpace ~
37703 \InsetSpace ~
37704 \InsetSpace ~
37705 \InsetSpace ~
37706 \InsetSpace ~
37707  92\InsetSpace ~
37708 \InsetSpace ~
37709 \InsetSpace ~
37710 \InsetSpace ~
37711 \InsetSpace ~
37712 \InsetSpace ~
37713 \InsetSpace ~
37714 \InsetSpace ~
37715  mov\InsetSpace ~
37716 \InsetSpace ~
37717  _foo_hob1_1_1,(_gint + 1) 
37718 \newline
37719 \InsetSpace ~
37720 \InsetSpace ~
37721 \InsetSpace ~
37722 \InsetSpace ~
37723 \InsetSpace ~
37724 \InsetSpace ~
37725 \InsetSpace ~
37726 \InsetSpace ~
37727 \InsetSpace ~
37728 \InsetSpace ~
37729 \InsetSpace ~
37730 \InsetSpace ~
37731 \InsetSpace ~
37732 \InsetSpace ~
37733 \InsetSpace ~
37734 \InsetSpace ~
37735 \InsetSpace ~
37736 \InsetSpace ~
37737 \InsetSpace ~
37738 \InsetSpace ~
37739 \InsetSpace ~
37740 \InsetSpace ~
37741 \InsetSpace ~
37742 \InsetSpace ~
37743 \InsetSpace ~
37744  93 ;\InsetSpace ~
37745  hob.c
37746  16 
37747 \newline
37748 003A 85*05*07\InsetSpace ~
37749 \InsetSpace ~
37750 \InsetSpace ~
37751 \InsetSpace ~
37752 \InsetSpace ~
37753 \InsetSpace ~
37754 \InsetSpace ~
37755 \InsetSpace ~
37756 \InsetSpace ~
37757 \InsetSpace ~
37758 \InsetSpace ~
37759 \InsetSpace ~
37760  94\InsetSpace ~
37761 \InsetSpace ~
37762 \InsetSpace ~
37763 \InsetSpace ~
37764 \InsetSpace ~
37765 \InsetSpace ~
37766 \InsetSpace ~
37767 \InsetSpace ~
37768  mov\InsetSpace ~
37769 \InsetSpace ~
37770  _foo_hob2_1_1,(_glong + 3) 
37771 \newline
37772 \InsetSpace ~
37773 \InsetSpace ~
37774 \InsetSpace ~
37775 \InsetSpace ~
37776 \InsetSpace ~
37777 \InsetSpace ~
37778 \InsetSpace ~
37779 \InsetSpace ~
37780 \InsetSpace ~
37781 \InsetSpace ~
37782 \InsetSpace ~
37783 \InsetSpace ~
37784 \InsetSpace ~
37785 \InsetSpace ~
37786 \InsetSpace ~
37787 \InsetSpace ~
37788 \InsetSpace ~
37789 \InsetSpace ~
37790 \InsetSpace ~
37791 \InsetSpace ~
37792 \InsetSpace ~
37793 \InsetSpace ~
37794 \InsetSpace ~
37795 \InsetSpace ~
37796 \InsetSpace ~
37797  95 ;\InsetSpace ~
37798  hob.c 17 
37799 \newline
37800 003D 85*04*08\InsetSpace ~
37801 \InsetSpace ~
37802 \InsetSpace ~
37803 \InsetSpace ~
37804 \InsetSpace ~
37805 \InsetSpace ~
37806 \InsetSpace ~
37807 \InsetSpace ~
37808 \InsetSpace ~
37809 \InsetSpace ~
37810 \InsetSpace ~
37811 \InsetSpace ~
37812
37813  96\InsetSpace ~
37814 \InsetSpace ~
37815 \InsetSpace ~
37816 \InsetSpace ~
37817 \InsetSpace ~
37818 \InsetSpace ~
37819 \InsetSpace ~
37820 \InsetSpace ~
37821  mov\InsetSpace ~
37822 \InsetSpace ~
37823  _foo_how1_1_1,(_glong + 2) 
37824 \newline
37825 0040 85*05*09\InsetSpace ~
37826 \InsetSpace ~
37827 \InsetSpace ~
37828 \InsetSpace ~
37829 \InsetSpace ~
37830 \InsetSpace ~
37831 \InsetSpace ~
37832 \InsetSpace ~
37833 \InsetSpace ~
37834 \InsetSpace ~
37835 \InsetSpace ~
37836 \InsetSpace ~
37837  97\InsetSpace ~
37838 \InsetSpace ~
37839 \InsetSpace ~
37840 \InsetSpace ~
37841 \InsetSpace ~
37842 \InsetSpace ~
37843 \InsetSpace ~
37844 \InsetSpace ~
37845  mov\InsetSpace ~
37846 \InsetSpace ~
37847  (_foo_how1_1_1 +
37848  1),(_glong + 3) 
37849 \newline
37850 0043 85*03*0A\InsetSpace ~
37851 \InsetSpace ~
37852 \InsetSpace ~
37853 \InsetSpace ~
37854 \InsetSpace ~
37855 \InsetSpace ~
37856 \InsetSpace ~
37857 \InsetSpace ~
37858 \InsetSpace ~
37859 \InsetSpace ~
37860 \InsetSpace ~
37861 \InsetSpace ~
37862  98\InsetSpace ~
37863 \InsetSpace ~
37864 \InsetSpace ~
37865 \InsetSpace ~
37866 \InsetSpace ~
37867 \InsetSpace ~
37868 \InsetSpace ~
37869 \InsetSpace ~
37870  mov\InsetSpace ~
37871 \InsetSpace ~
37872  _foo_how2_1_1,(_glong + 1) 
37873 \newline
37874 0046 85*04*0B\InsetSpace ~
37875 \InsetSpace ~
37876 \InsetSpace ~
37877 \InsetSpace ~
37878 \InsetSpace ~
37879 \InsetSpace ~
37880 \InsetSpace ~
37881 \InsetSpace ~
37882 \InsetSpace ~
37883 \InsetSpace ~
37884 \InsetSpace ~
37885 \InsetSpace ~
37886
37887  99\InsetSpace ~
37888 \InsetSpace ~
37889 \InsetSpace ~
37890 \InsetSpace ~
37891 \InsetSpace ~
37892 \InsetSpace ~
37893 \InsetSpace ~
37894 \InsetSpace ~
37895  mov\InsetSpace ~
37896 \InsetSpace ~
37897  (_foo_how2_1_1 + 1),(_glong + 2) 
37898 \end_layout
37899
37900 \begin_layout Standard
37901 Again, variations of these cases may 
37902 \emph on
37903 not
37904 \emph default
37905  be recognized.
37906  They are standard C expressions, so I heartily recommend these be the only
37907  way to get the higher order byte/word, (it is portable).
37908  Of course it will be recognized even if it is embedded in other expressions,
37909  e.g.:
37910 \end_layout
37911
37912 \begin_layout Verse
37913
37914 \family typewriter
37915 xyz = gint + ((gint >> 8) & 0xFF);
37916 \end_layout
37917
37918 \begin_layout Standard
37919 will still be recognized.
37920 \end_layout
37921
37922 \begin_layout Subsection
37923 Peephole Optimizer
37924 \begin_inset LatexCommand label
37925 name "sub:Peephole-Optimizer"
37926
37927 \end_inset
37928
37929
37930 \begin_inset LatexCommand index
37931 name "Peephole optimizer"
37932
37933 \end_inset
37934
37935
37936 \end_layout
37937
37938 \begin_layout Standard
37939 The compiler uses a rule based, pattern matching and re-writing mechanism
37940  for peep-hole optimization.
37941  It is inspired by 
37942 \emph on
37943 copt
37944 \emph default
37945  a peep-hole optimizer by Christopher W.
37946  Fraser (cwfraser\InsetSpace ~
37947 @\InsetSpace ~
37948 microsoft.com).
37949  A default set of rules are compiled into the compiler, additional rules
37950  may be added with the 
37951 \emph on
37952 -
37953 \begin_inset ERT
37954 status collapsed
37955
37956 \begin_layout Standard
37957
37958
37959 \backslash
37960 /
37961 \end_layout
37962
37963 \end_inset
37964
37965 -peep-file
37966 \begin_inset LatexCommand index
37967 name "-\\/-peep-file"
37968
37969 \end_inset
37970
37971  <filename>
37972 \emph default
37973  option.
37974  The rule language is best illustrated with examples.
37975 \end_layout
37976
37977 \begin_layout Verse
37978
37979 \family typewriter
37980 replace { 
37981 \newline
37982 \InsetSpace ~
37983 \InsetSpace ~
37984 mov %1,a 
37985 \newline
37986 \InsetSpace ~
37987 \InsetSpace ~
37988 mov a,%1
37989 \newline
37990 } by {
37991 \newline
37992 \InsetSpace ~
37993 \InsetSpace ~
37994 mov %1,a
37995 \newline
37996 }
37997 \end_layout
37998
37999 \begin_layout Standard
38000 The above rule will change the following assembly
38001 \begin_inset LatexCommand index
38002 name "Assembler routines"
38003
38004 \end_inset
38005
38006  sequence:
38007 \end_layout
38008
38009 \begin_layout Verse
38010
38011 \family typewriter
38012 mov r1,a 
38013 \newline
38014 mov a,r1
38015 \end_layout
38016
38017 \begin_layout Standard
38018 to
38019 \end_layout
38020
38021 \begin_layout Verse
38022
38023 \family typewriter
38024 mov r1,a
38025 \end_layout
38026
38027 \begin_layout Standard
38028 Note: All occurrences of a 
38029 \emph on
38030 %n
38031 \emph default
38032  (pattern variable) must denote the same string.
38033  With the above rule, the assembly sequence:
38034 \end_layout
38035
38036 \begin_layout Verse
38037
38038 \family typewriter
38039 mov r1,a 
38040 \newline
38041 mov a,r2
38042 \end_layout
38043
38044 \begin_layout Standard
38045 will remain unmodified.
38046 \newline
38047
38048 \newline
38049 Other special case optimizations may be added by the
38050  user (via 
38051 \emph on
38052 -
38053 \begin_inset ERT
38054 status collapsed
38055
38056 \begin_layout Standard
38057
38058
38059 \backslash
38060 /
38061 \end_layout
38062
38063 \end_inset
38064
38065 -peep-file option
38066 \emph default
38067 ).
38068  E.g.
38069  some variants of the 8051 MCU
38070 \begin_inset LatexCommand index
38071 name "MCS51 variants"
38072
38073 \end_inset
38074
38075  allow only 
38076 \family typewriter
38077 ajmp
38078 \family default
38079  and 
38080 \family typewriter
38081 acall
38082 \family default
38083 .
38084  The following two rules will change all 
38085 \family typewriter
38086 ljmp
38087 \family default
38088  and 
38089 \family typewriter
38090 lcall
38091 \family default
38092  to 
38093 \family typewriter
38094 ajmp
38095 \family default
38096  and 
38097 \family typewriter
38098 acall
38099 \end_layout
38100
38101 \begin_layout Verse
38102
38103 \family typewriter
38104 replace { lcall %1 } by { acall %1 } 
38105 \newline
38106 replace { ljmp %1 } by { ajmp %1 }
38107 \end_layout
38108
38109 \begin_layout Standard
38110 (NOTE: from version 2.7.3 on, you can use option -
38111 \emph on
38112
38113 \begin_inset ERT
38114 status collapsed
38115
38116 \begin_layout Standard
38117
38118
38119 \backslash
38120 /
38121 \end_layout
38122
38123 \end_inset
38124
38125
38126 \emph default
38127 -acall-ajmp
38128 \begin_inset LatexCommand index
38129 name "-\\/-acall-ajmp"
38130
38131 \end_inset
38132
38133 , which also takes care of aligning the interrupt vectors properly.)
38134 \newline
38135
38136 \end_layout
38137
38138 \begin_layout Standard
38139 The 
38140 \emph on
38141 inline-assembler code
38142 \emph default
38143  is also passed through the peep hole optimizer, thus the peephole optimizer
38144  can also be used as an assembly level macro expander.
38145  The rules themselves are MCU dependent whereas the rule language infra-structur
38146 e is MCU independent.
38147  Peephole optimization rules for other MCU can be easily programmed using
38148  the rule language.
38149 \newline
38150
38151 \newline
38152 The syntax for a rule is as follows:
38153 \end_layout
38154
38155 \begin_layout Verse
38156
38157 \family typewriter
38158 rule := replace [ restart ] '{' <assembly sequence> '
38159 \backslash
38160 n' 
38161 \newline
38162 \InsetSpace ~
38163  \InsetSpace ~
38164  \InsetSpace ~
38165  \InsetSpace ~
38166  \InsetSpace ~
38167  \InsetSpace ~
38168  \InsetSpace ~
38169  \InsetSpace ~
38170  \InsetSpace ~
38171  \InsetSpace ~
38172  \InsetSpace ~
38173  \InsetSpace ~
38174  \InsetSpace ~
38175  \InsetSpace ~
38176  '}' by '{' '
38177 \backslash
38178 n' 
38179 \newline
38180 \InsetSpace ~
38181  \InsetSpace ~
38182  \InsetSpace ~
38183  \InsetSpace ~
38184  \InsetSpace ~
38185  \InsetSpace ~
38186  \InsetSpace ~
38187  \InsetSpace ~
38188  \InsetSpace ~
38189  \InsetSpace ~
38190  \InsetSpace ~
38191  \InsetSpace ~
38192  \InsetSpace ~
38193  \InsetSpace ~
38194  \InsetSpace ~
38195  \InsetSpace ~
38196  <assembly sequence> '
38197 \backslash
38198 n' 
38199 \newline
38200 \InsetSpace ~
38201  \InsetSpace ~
38202  \InsetSpace ~
38203  \InsetSpace ~
38204  \InsetSpace ~
38205  \InsetSpace ~
38206  \InsetSpace ~
38207  \InsetSpace ~
38208  \InsetSpace ~
38209  \InsetSpace ~
38210  \InsetSpace ~
38211  \InsetSpace ~
38212  \InsetSpace ~
38213  \InsetSpace ~
38214  '}' [if <functionName> ] '
38215 \backslash
38216 n' 
38217 \end_layout
38218
38219 \begin_layout Standard
38220 <assembly sequence> := assembly instruction (each instruction including
38221  labels must be on a separate line).
38222 \newline
38223
38224 \newline
38225 The optimizer will apply to the rules
38226  one by one from the top in the sequence of their appearance, it will terminate
38227  when all rules are exhausted.
38228  If the 'restart' option is specified, then the optimizer will start matching
38229  the rules again from the top, this option for a rule is expensive (performance)
38230 , it is intended to be used in situations where a transformation will trigger
38231  the same rule again.
38232  An example of this (not a good one, it has side effects) is the following
38233  rule:
38234 \end_layout
38235
38236 \begin_layout Verse
38237
38238 \family typewriter
38239 replace restart { 
38240 \newline
38241 \InsetSpace ~
38242 \InsetSpace ~
38243 pop %1 
38244 \newline
38245 \InsetSpace ~
38246 \InsetSpace ~
38247 push %1 } by { 
38248 \newline
38249 \InsetSpace ~
38250 \InsetSpace ~
38251 ; nop 
38252 \newline
38253 }
38254 \end_layout
38255
38256 \begin_layout Standard
38257 Note that the replace pattern cannot be a blank, but can be a comment line.
38258  Without the 'restart' option only the innermost 'pop' 'push' pair would
38259  be eliminated, i.e.:
38260 \end_layout
38261
38262 \begin_layout Verse
38263
38264 \family typewriter
38265 pop ar1 
38266 \newline
38267 pop ar2 
38268 \newline
38269 push ar2 
38270 \newline
38271 push ar1
38272 \end_layout
38273
38274 \begin_layout Standard
38275 would result in:
38276 \end_layout
38277
38278 \begin_layout Verse
38279
38280 \family typewriter
38281 pop ar1 
38282 \newline
38283 ; nop 
38284 \newline
38285 push ar1
38286 \end_layout
38287
38288 \begin_layout Standard
38289
38290 \emph on
38291 with
38292 \emph default
38293  the restart option the rule will be applied again to the resulting code
38294  and then all the pop-push pairs will be eliminated to yield:
38295 \end_layout
38296
38297 \begin_layout Verse
38298
38299 \family typewriter
38300 ; nop 
38301 \newline
38302 ; nop
38303 \end_layout
38304
38305 \begin_layout Standard
38306 A conditional function can be attached to a rule.
38307  Attaching rules are somewhat more involved, let me illustrate this with
38308  an example.
38309 \end_layout
38310
38311 \begin_layout Verse
38312
38313 \family typewriter
38314 replace { 
38315 \newline
38316 \InsetSpace ~
38317  \InsetSpace ~
38318  \InsetSpace ~
38319 ljmp %5 
38320 \newline
38321 %2:
38322 \newline
38323 } by { 
38324 \newline
38325 \InsetSpace ~
38326  \InsetSpace ~
38327  \InsetSpace ~
38328 sjmp %5 
38329 \newline
38330 %2:
38331 \newline
38332 } if labelInRange
38333 \end_layout
38334
38335 \begin_layout Standard
38336 The optimizer does a look-up of a function name table defined in function
38337  
38338 \emph on
38339 callFuncByName
38340 \emph default
38341  in the source file SDCCpeeph.c, with the name 
38342 \emph on
38343 labelInRange
38344 \emph default
38345 .
38346  If it finds a corresponding entry the function is called.
38347  Note there can be no parameters specified for these functions, in this
38348  case the use of 
38349 \emph on
38350 %5
38351 \emph default
38352  is crucial, since the function 
38353 \emph on
38354 labelInRange
38355 \emph default
38356  expects to find the label in that particular variable (the hash table containin
38357 g the variable bindings is passed as a parameter).
38358  If you want to code more such functions, take a close look at the function
38359  labelInRange and the calling mechanism in source file SDCCpeeph.c.
38360  Currently implemented are 
38361 \emph on
38362 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
38363  24bitMode, portIsDS390, 24bitModeAndPortDS390
38364 \emph default
38365  and 
38366 \emph on
38367 notVolatile
38368 \emph default
38369 .
38370 \end_layout
38371
38372 \begin_layout Standard
38373 I know this whole thing is a little kludgey, but maybe some day we will
38374  have some better means.
38375  If you are looking at this file, you will see the default rules that are
38376  compiled into the compiler, you can add your own rules in the default set
38377  there if you get tired of specifying the -
38378 \begin_inset ERT
38379 status collapsed
38380
38381 \begin_layout Standard
38382
38383
38384 \backslash
38385 /
38386 \end_layout
38387
38388 \end_inset
38389
38390 -peep-file option.
38391 \end_layout
38392
38393 \begin_layout Section
38394 ANSI-Compliance
38395 \begin_inset LatexCommand index
38396 name "ANSI-compliance"
38397
38398 \end_inset
38399
38400
38401 \begin_inset LatexCommand label
38402 name "sub:ANSI-Compliance"
38403
38404 \end_inset
38405
38406
38407 \end_layout
38408
38409 \begin_layout Standard
38410 The latest publicly available version of the standard 
38411 \emph on
38412 ISO/IEC 9899 - Programming languages - C
38413 \emph default
38414  should be available at: 
38415 \begin_inset LatexCommand url
38416 target "http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899"
38417
38418 \end_inset
38419
38420 .
38421 \newline
38422
38423 \end_layout
38424
38425 \begin_layout Standard
38426 Deviations from the compliance:
38427 \end_layout
38428
38429 \begin_layout Itemize
38430 functions are not reentrant
38431 \begin_inset LatexCommand index
38432 name "reentrant"
38433
38434 \end_inset
38435
38436  unless explicitly declared as such or the 
38437 \series bold
38438 -
38439 \begin_inset ERT
38440 status collapsed
38441
38442 \begin_layout Standard
38443
38444
38445 \backslash
38446 /
38447 \end_layout
38448
38449 \end_inset
38450
38451 -stack-auto
38452 \begin_inset LatexCommand index
38453 name "-\\/-stack-auto"
38454
38455 \end_inset
38456
38457
38458 \series default
38459  command line option is specified.
38460 \end_layout
38461
38462 \begin_layout Itemize
38463 structures
38464 \begin_inset LatexCommand index
38465 name "struct"
38466
38467 \end_inset
38468
38469  and unions
38470 \begin_inset LatexCommand index
38471 name "union"
38472
38473 \end_inset
38474
38475  cannot be assigned values directly, cannot be passed as function parameters
38476  or assigned to each other and cannot be a return value
38477 \begin_inset LatexCommand index
38478 name "return value"
38479
38480 \end_inset
38481
38482  from a function, e.g.:
38483 \end_layout
38484
38485 \begin_deeper
38486 \begin_layout Verse
38487
38488 \family typewriter
38489 struct s { ...
38490  }; 
38491 \newline
38492 struct s s1, s2; 
38493 \newline
38494 foo() 
38495 \newline
38496
38497 \newline
38498 \InsetSpace ~
38499 \InsetSpace ~
38500 \InsetSpace ~
38501 \InsetSpace ~
38502 ...
38503  
38504 \newline
38505 \InsetSpace ~
38506 \InsetSpace ~
38507 \InsetSpace ~
38508 \InsetSpace ~
38509 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
38510 \newline
38511 \InsetSpace ~
38512 \InsetSpace ~
38513 \InsetSpace ~
38514 \InsetSpace ~
38515 ...
38516  
38517 \newline
38518 }
38519 \newline
38520
38521 \series bold
38522 struct
38523 \family default
38524 \series default
38525  
38526 \family typewriter
38527 s foo1 (
38528 \series bold
38529 struct
38530 \family default
38531 \series default
38532  
38533 \family typewriter
38534 s parms) /* invalid in SDCC although allowed in ANSI */
38535 \newline
38536
38537 \newline
38538 \InsetSpace ~
38539 \InsetSpace ~
38540 \InsetSpace ~
38541 \InsetSpace ~
38542 struct s rets;
38543  
38544 \newline
38545 \InsetSpace ~
38546 \InsetSpace ~
38547 \InsetSpace ~
38548 \InsetSpace ~
38549 ...
38550  
38551 \newline
38552 \InsetSpace ~
38553 \InsetSpace ~
38554 \InsetSpace ~
38555 \InsetSpace ~
38556 return rets; /* is invalid in SDCC although allowed in ANSI */ 
38557 \newline
38558 }
38559 \end_layout
38560
38561 \end_deeper
38562 \begin_layout Itemize
38563 initialization of structure arrays must be fully braced.
38564 \end_layout
38565
38566 \begin_deeper
38567 \begin_layout Verse
38568
38569 \family typewriter
38570 struct s { char x } a[] = {1, 2};\InsetSpace ~
38571 \InsetSpace ~
38572 \InsetSpace ~
38573 \InsetSpace ~
38574 \InsetSpace ~
38575 /* invalid in SDCC */
38576 \newline
38577 struct s { char x
38578  } a[] = {{1}, {2}}; /* OK */
38579 \end_layout
38580
38581 \end_deeper
38582 \begin_layout Itemize
38583 'long long
38584 \begin_inset LatexCommand index
38585 name "long long (not supported)"
38586
38587 \end_inset
38588
38589 ' (64 bit integers
38590 \begin_inset LatexCommand index
38591 name "int (64 bit) (not supported)"
38592
38593 \end_inset
38594
38595 ) not supported.
38596 \end_layout
38597
38598 \begin_layout Itemize
38599 'double
38600 \begin_inset LatexCommand index
38601 name "double (not supported)"
38602
38603 \end_inset
38604
38605 ' precision floating point 
38606 \begin_inset LatexCommand index
38607 name "Floating point support"
38608
38609 \end_inset
38610
38611 not supported.
38612 \end_layout
38613
38614 \begin_layout Itemize
38615 Old K&R style
38616 \begin_inset LatexCommand index
38617 name "K\\&R style"
38618
38619 \end_inset
38620
38621  function declarations are NOT allowed.
38622 \end_layout
38623
38624 \begin_deeper
38625 \begin_layout Verse
38626
38627 \family typewriter
38628 foo(i,j) /* this old style of function declarations */ 
38629 \newline
38630 int i,j; /* is valid
38631  in ANSI but not valid in SDCC */ 
38632 \newline
38633
38634 \newline
38635 \InsetSpace ~
38636 \InsetSpace ~
38637 \InsetSpace ~
38638 \InsetSpace ~
38639 ...
38640  
38641 \newline
38642 }
38643 \end_layout
38644
38645 \end_deeper
38646 \begin_layout Itemize
38647 Most enhancements in C99 are not supported, e.g.:
38648 \end_layout
38649
38650 \begin_deeper
38651 \begin_layout Verse
38652
38653 \family typewriter
38654 for (
38655 \series bold
38656 int
38657 \family default
38658 \series default
38659  
38660 \family typewriter
38661 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
38662 \end_layout
38663
38664 \end_deeper
38665 \begin_layout Itemize
38666 But some have been added recently in SDCC 2.7.0.
38667  They must be considered alpha quality however.
38668 \end_layout
38669
38670 \begin_deeper
38671 \begin_layout Verse
38672
38673 \family typewriter
38674 \series bold
38675 inline
38676 \begin_inset LatexCommand index
38677 name "inline (not supported)"
38678
38679 \end_inset
38680
38681
38682 \family default
38683 \series default
38684  
38685 \family typewriter
38686 int increment (int a) { return a+1; } /* inlines the increment without function
38687  call overhead */
38688 \newline
38689 int *
38690 \family default
38691  
38692 \family typewriter
38693 \series bold
38694 restrict
38695 \begin_inset LatexCommand index
38696 name "inline (not supported)"
38697
38698 \end_inset
38699
38700
38701 \family default
38702 \series default
38703  
38704 \family typewriter
38705 p; /* accepted but ignored */
38706 \end_layout
38707
38708 \end_deeper
38709 \begin_layout Itemize
38710 Certain words that are valid identifiers in the standard may be reserved
38711  words in SDCC unless the 
38712 \series bold
38713 -
38714 \begin_inset ERT
38715 status collapsed
38716
38717 \begin_layout Standard
38718
38719
38720 \backslash
38721 /
38722 \end_layout
38723
38724 \end_inset
38725
38726 -std-c89
38727 \begin_inset LatexCommand index
38728 name "-\\/-std-c89"
38729
38730 \end_inset
38731
38732
38733 \series default
38734  or 
38735 \series bold
38736 -
38737 \begin_inset ERT
38738 status collapsed
38739
38740 \begin_layout Standard
38741
38742
38743 \backslash
38744 /
38745 \end_layout
38746
38747 \end_inset
38748
38749 -std-c99
38750 \begin_inset LatexCommand index
38751 name "-\\/-std-c99"
38752
38753 \end_inset
38754
38755
38756 \series default
38757  command line options are used.
38758  These may include (depending on the selected processor): 'at', 'banked',
38759  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
38760 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
38761  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
38762  '_naked'.
38763  Compliant equivalents of these keywords are always available in a form
38764  that begin with two underscores
38765 \begin_inset LatexCommand index
38766 name "\\_\\_ (prefix for extended keywords)"
38767
38768 \end_inset
38769
38770 , f.e.
38771  '__data' instead of 'data'.
38772 \end_layout
38773
38774 \begin_layout Itemize
38775 Integer promotion of variable arguments is not performed if the argument
38776  is explicitly taypecasted unless the 
38777 \series bold
38778 -
38779 \begin_inset ERT
38780 status collapsed
38781
38782 \begin_layout Standard
38783
38784
38785 \backslash
38786 /
38787 \end_layout
38788
38789 \end_inset
38790
38791 -std-c89
38792 \begin_inset LatexCommand index
38793 name "-\\/-std-c89"
38794
38795 \end_inset
38796
38797
38798 \series default
38799  or 
38800 \series bold
38801 -
38802 \begin_inset ERT
38803 status collapsed
38804
38805 \begin_layout Standard
38806
38807
38808 \backslash
38809 /
38810 \end_layout
38811
38812 \end_inset
38813
38814 -std-c99
38815 \begin_inset LatexCommand index
38816 name "-\\/-std-c99"
38817
38818 \end_inset
38819
38820
38821 \series default
38822  command line options are used.
38823 \end_layout
38824
38825 \begin_deeper
38826 \begin_layout Verse
38827
38828 \family typewriter
38829 void vararg_func (char *str, ...) { str; }
38830 \newline
38831
38832 \newline
38833 void main (void)
38834 \newline
38835 {
38836 \newline
38837 \InsetSpace ~
38838 \InsetSpace ~
38839 char c = 10;
38840 \newline
38841
38842 \newline
38843 \InsetSpace ~
38844 \InsetSpace ~
38845 /* argument
38846  u is promoted to int before
38847 \newline
38848 \InsetSpace ~
38849 \InsetSpace ~
38850 \InsetSpace ~
38851 * passing to function */
38852 \newline
38853 \InsetSpace ~
38854 \InsetSpace ~
38855 vararg_func ("%c", c);
38856 \newline
38857
38858 \newline
38859 \InsetSpace ~
38860 \InsetSpace ~
38861 /*
38862  argument u is not promoted to int,
38863 \newline
38864 \InsetSpace ~
38865 \InsetSpace ~
38866 \InsetSpace ~
38867 * it is passed as char to function
38868 \newline
38869 \InsetSpace ~
38870 \InsetSpace ~
38871 \InsetSpace ~
38872 * if
38873  --std-cXX is not defined;
38874 \newline
38875 \InsetSpace ~
38876 \InsetSpace ~
38877 \InsetSpace ~
38878 * is promoted to int before passing
38879 \newline
38880 \InsetSpace ~
38881 \InsetSpace ~
38882 \InsetSpace ~
38883 * to function
38884  if --std-cXX is defined */
38885 \newline
38886 \InsetSpace ~
38887 \InsetSpace ~
38888 vararg_func ("%bc", (char)u);
38889 \newline
38890 }
38891 \end_layout
38892
38893 \end_deeper
38894 \begin_layout Section
38895 Cyclomatic Complexity
38896 \begin_inset LatexCommand index
38897 name "Cyclomatic complexity"
38898
38899 \end_inset
38900
38901
38902 \end_layout
38903
38904 \begin_layout Standard
38905 Cyclomatic complexity of a function is defined as the number of independent
38906  paths the program can take during execution of the function.
38907  This is an important number since it defines the number test cases you
38908  have to generate to validate the function.
38909  The accepted industry standard for complexity number is 10, if the cyclomatic
38910  complexity reported by SDCC exceeds 10 you should think about simplification
38911  of the function logic.
38912  Note that the complexity level is not related to the number of lines of
38913  code in a function.
38914  Large functions can have low complexity, and small functions can have large
38915  complexity levels.
38916  
38917 \newline
38918
38919 \newline
38920 SDCC uses the following formula to compute the complexity:
38921 \newline
38922
38923 \end_layout
38924
38925 \begin_layout Standard
38926 complexity = (number of edges in control flow graph) - (number of nodes
38927  in control flow graph) + 2;
38928 \newline
38929
38930 \newline
38931 Having said that the industry standard is 10,
38932  you should be aware that in some cases it be may unavoidable to have a
38933  complexity level of less than 10.
38934  For example if you have switch statement with more than 10 case labels,
38935  each case label adds one to the complexity level.
38936  The complexity level is by no means an absolute measure of the algorithmic
38937  complexity of the function, it does however provide a good starting point
38938  for which functions you might look at for further optimization.
38939 \end_layout
38940
38941 \begin_layout Section
38942 Retargetting for other Processors
38943 \end_layout
38944
38945 \begin_layout Standard
38946 The issues for retargetting the compiler are far too numerous to be covered
38947  by this document.
38948  What follows is a brief description of each of the seven phases of the
38949  compiler and its MCU dependency.
38950 \end_layout
38951
38952 \begin_layout Itemize
38953 Parsing the source and building the annotated parse tree.
38954  This phase is largely MCU independent (except for the language extensions).
38955  Syntax & semantic checks are also done in this phase, along with some initial
38956  optimizations like back patching labels and the pattern matching optimizations
38957  like bit-rotation etc.
38958 \end_layout
38959
38960 \begin_layout Itemize
38961 The second phase involves generating an intermediate code which can be easy
38962  manipulated during the later phases.
38963  This phase is entirely MCU independent.
38964  The intermediate code generation assumes the target machine has unlimited
38965  number of registers, and designates them with the name iTemp.
38966  The compiler can be made to dump a human readable form of the code generated
38967  by using the -
38968 \begin_inset ERT
38969 status collapsed
38970
38971 \begin_layout Standard
38972
38973
38974 \backslash
38975 /
38976 \end_layout
38977
38978 \end_inset
38979
38980 -dumpraw option.
38981 \end_layout
38982
38983 \begin_layout Itemize
38984 This phase does the bulk of the standard optimizations and is also MCU independe
38985 nt.
38986  This phase can be broken down into several sub-phases:
38987 \newline
38988
38989 \newline
38990 Break down intermediate
38991  code (iCode) into basic blocks.
38992 \newline
38993 Do control flow & data flow analysis on the
38994  basic blocks.
38995 \newline
38996 Do local common subexpression elimination, then global subexpressio
38997 n elimination
38998 \newline
38999 Dead code elimination
39000 \newline
39001 Loop optimizations
39002 \newline
39003 If loop optimizations
39004  caused any changes then do 'global subexpression elimination' and 'dead
39005  code elimination' again.
39006 \end_layout
39007
39008 \begin_layout Itemize
39009 This phase determines the live-ranges; by live range I mean those iTemp
39010  variables defined by the compiler that still survive after all the optimization
39011 s.
39012  Live range analysis
39013 \begin_inset LatexCommand index
39014 name "Live range analysis"
39015
39016 \end_inset
39017
39018  is essential for register allocation, since these computation determines
39019  which of these iTemps will be assigned to registers, and for how long.
39020 \end_layout
39021
39022 \begin_layout Itemize
39023 Phase five is register allocation.
39024  There are two parts to this process.
39025 \newline
39026
39027 \newline
39028 The first part I call 'register packing'
39029  (for lack of a better term).
39030  In this case several MCU specific expression folding is done to reduce
39031  register pressure.
39032 \newline
39033
39034 \newline
39035 The second part is more MCU independent and deals with
39036  allocating registers to the remaining live ranges.
39037  A lot of MCU specific code does creep into this phase because of the limited
39038  number of index registers available in the 8051.
39039 \end_layout
39040
39041 \begin_layout Itemize
39042 The Code generation phase is (unhappily), entirely MCU dependent and very
39043  little (if any at all) of this code can be reused for other MCU.
39044  However the scheme for allocating a homogenized assembler operand for each
39045  iCode operand may be reused.
39046 \end_layout
39047
39048 \begin_layout Itemize
39049 As mentioned in the optimization section the peep-hole optimizer is rule
39050  based system, which can reprogrammed for other MCUs.
39051 \end_layout
39052
39053 \begin_layout Standard
39054 More information is available on SDCC Wiki
39055 \begin_inset LatexCommand index
39056 name "wiki"
39057
39058 \end_inset
39059
39060  (preliminary link 
39061 \begin_inset LatexCommand url
39062 target "http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting"
39063
39064 \end_inset
39065
39066 ) and in the thread 
39067 \begin_inset LatexCommand url
39068 target "http://sf.net/mailarchive/message.php?msg_id=13954144"
39069
39070 \end_inset
39071
39072  .
39073 \end_layout
39074
39075 \begin_layout Chapter
39076 Compiler internals
39077 \begin_inset LatexCommand index
39078 name "Compiler internals"
39079
39080 \end_inset
39081
39082
39083 \end_layout
39084
39085 \begin_layout Section
39086 The anatomy of the compiler
39087 \begin_inset LatexCommand label
39088 name "sub:The-anatomy-of"
39089
39090 \end_inset
39091
39092
39093 \end_layout
39094
39095 \begin_layout Standard
39096
39097 \shape italic
39098 This is an excerpt from an article published in Circuit Cellar Magazine
39099  in
39100 \shape default
39101  
39102 \series bold
39103 \shape italic
39104 August 2000
39105 \series default
39106 .
39107  It's a little outdated (the compiler is much more efficient now and user/develo
39108 per friendly), but pretty well exposes the guts of it all.
39109 \shape default
39110
39111 \newline
39112
39113 \newline
39114 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
39115  It is fairly easy to retarget for other 8-bit MCU.
39116  Here we take a look at some of the internals of the compiler.
39117  
39118 \end_layout
39119
39120 \begin_layout Paragraph*
39121 Parsing
39122 \begin_inset LatexCommand index
39123 name "Parsing"
39124
39125 \end_inset
39126
39127  
39128 \end_layout
39129
39130 \begin_layout Standard
39131 Parsing the input source file and creating an AST (Annotated Syntax Tree
39132 \begin_inset LatexCommand index
39133 name "Annotated syntax tree"
39134
39135 \end_inset
39136
39137 ).
39138  This phase also involves propagating types (annotating each node of the
39139  parse tree with type information) and semantic analysis.
39140  There are some MCU specific parsing rules.
39141  For example the storage classes, the extended storage classes are MCU specific
39142  while there may be a xdata storage class for 8051 there is no such storage
39143  class for z80 or Atmel AVR.
39144  SDCC allows MCU specific storage class extensions, i.e.
39145  xdata will be treated as a storage class specifier when parsing 8051 C
39146  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
39147  C code.
39148 \end_layout
39149
39150 \begin_layout Paragraph*
39151 Generating iCode
39152 \begin_inset LatexCommand index
39153 name "iCode"
39154
39155 \end_inset
39156
39157
39158 \end_layout
39159
39160 \begin_layout Standard
39161 Intermediate code generation.
39162  In this phase the AST is broken down into three-operand form (iCode).
39163  These three operand forms are represented as doubly linked lists.
39164  ICode is the term given to the intermediate form generated by the compiler.
39165  ICode example section shows some examples of iCode generated for some simple
39166  C source functions.
39167 \end_layout
39168
39169 \begin_layout Paragraph*
39170 Optimizations
39171 \begin_inset LatexCommand index
39172 name "Optimizations"
39173
39174 \end_inset
39175
39176 .
39177 \end_layout
39178
39179 \begin_layout Standard
39180 Bulk of the target independent optimizations is performed in this phase.
39181  The optimizations include constant propagation, common sub-expression eliminati
39182 on, loop invariant code movement, strength reduction of loop induction variables
39183  and dead-code elimination.
39184 \end_layout
39185
39186 \begin_layout Paragraph*
39187 Live range analysis
39188 \begin_inset LatexCommand index
39189 name "Live range analysis"
39190
39191 \end_inset
39192
39193
39194 \end_layout
39195
39196 \begin_layout Standard
39197 During intermediate code generation phase, the compiler assumes the target
39198  machine has infinite number of registers and generates a lot of temporary
39199  variables.
39200  The live range computation determines the lifetime of each of these compiler-ge
39201 nerated temporaries.
39202  A picture speaks a thousand words.
39203  ICode example sections show the live range annotations for each of the
39204  operand.
39205  It is important to note here, each iCode is assigned a number in the order
39206  of its execution in the function.
39207  The live ranges are computed in terms of these numbers.
39208  The from number is the number of the iCode which first defines the operand
39209  and the to number signifies the iCode which uses this operand last.
39210 \end_layout
39211
39212 \begin_layout Paragraph*
39213 Register Allocation
39214 \begin_inset LatexCommand index
39215 name "Register allocation"
39216
39217 \end_inset
39218
39219
39220 \end_layout
39221
39222 \begin_layout Standard
39223 The register allocation determines the type and number of registers needed
39224  by each operand.
39225  In most MCUs only a few registers can be used for indirect addressing.
39226  In case of 8051 for example the registers R0 & R1 can be used to indirectly
39227  address the internal ram and DPTR to indirectly address the external ram.
39228  The compiler will try to allocate the appropriate register to pointer variables
39229  if it can.
39230  ICode example section shows the operands annotated with the registers assigned
39231  to them.
39232  The compiler will try to keep operands in registers as much as possible;
39233  there are several schemes the compiler uses to do achieve this.
39234  When the compiler runs out of registers the compiler will check to see
39235  if there are any live operands which is not used or defined in the current
39236  basic block being processed, if there are any found then it will push that
39237  operand and use the registers in this block, the operand will then be popped
39238  at the end of the basic block.
39239  
39240 \end_layout
39241
39242 \begin_layout Standard
39243 There are other MCU specific considerations in this phase.
39244  Some MCUs have an accumulator; very short-lived operands could be assigned
39245  to the accumulator instead of a general-purpose register.
39246 \end_layout
39247
39248 \begin_layout Paragraph*
39249 Code generation
39250 \end_layout
39251
39252 \begin_layout Standard
39253 Figure II gives a table of iCode
39254 \begin_inset LatexCommand index
39255 name "iCode"
39256
39257 \end_inset
39258
39259  operations supported by the compiler.
39260  The code generation involves translating these operations into corresponding
39261  assembly code for the processor.
39262  This sounds overly simple but that is the essence of code generation.
39263  Some of the iCode operations are generated on a MCU specific manner for
39264  example, the z80 port does not use registers to pass parameters so the
39265  SEND and RECV iCode operations will not be generated, and it also does
39266  not support JUMPTABLES.
39267  
39268 \newline
39269
39270 \end_layout
39271
39272 \begin_layout Standard
39273
39274 \size footnotesize
39275 Figure II 
39276 \begin_inset Tabular
39277 <lyxtabular version="3" rows="39" columns="4">
39278 <features islongtable="true" headBottomDL="true">
39279 <column alignment="block" valignment="top" leftline="true" width="13col%">
39280 <column alignment="left" valignment="top" leftline="true" width="13col%">
39281 <column alignment="block" valignment="top" leftline="true" width="22col%">
39282 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
39283 <row topline="true" bottomline="true" endhead="true">
39284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39285 \begin_inset Text
39286
39287 \begin_layout Standard
39288
39289 \series bold
39290 iCode
39291 \series default
39292
39293 \begin_inset LatexCommand index
39294 name "iCode"
39295
39296 \end_inset
39297
39298
39299 \end_layout
39300
39301 \end_inset
39302 </cell>
39303 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39304 \begin_inset Text
39305
39306 \begin_layout Standard
39307
39308 \series bold
39309 Operands
39310 \end_layout
39311
39312 \end_inset
39313 </cell>
39314 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39315 \begin_inset Text
39316
39317 \begin_layout Standard
39318
39319 \series bold
39320 Description
39321 \end_layout
39322
39323 \end_inset
39324 </cell>
39325 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39326 \begin_inset Text
39327
39328 \begin_layout Standard
39329
39330 \series bold
39331 C Equivalent
39332 \end_layout
39333
39334 \end_inset
39335 </cell>
39336 </row>
39337 <row topline="true">
39338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39339 \begin_inset Text
39340
39341 \begin_layout Standard
39342
39343 \size footnotesize
39344 '!'
39345 \end_layout
39346
39347 \end_inset
39348 </cell>
39349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39350 \begin_inset Text
39351
39352 \begin_layout Standard
39353
39354 \size footnotesize
39355 IC_LEFT() IC_RESULT()
39356 \end_layout
39357
39358 \end_inset
39359 </cell>
39360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39361 \begin_inset Text
39362
39363 \begin_layout Standard
39364
39365 \size footnotesize
39366 NOT operation 
39367 \end_layout
39368
39369 \end_inset
39370 </cell>
39371 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39372 \begin_inset Text
39373
39374 \begin_layout Standard
39375
39376 \size footnotesize
39377 IC_RESULT = ! IC_LEFT;
39378 \end_layout
39379
39380 \end_inset
39381 </cell>
39382 </row>
39383 <row topline="true">
39384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39385 \begin_inset Text
39386
39387 \begin_layout Standard
39388
39389 \size footnotesize
39390 '~'
39391 \end_layout
39392
39393 \end_inset
39394 </cell>
39395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39396 \begin_inset Text
39397
39398 \begin_layout Standard
39399
39400 \size footnotesize
39401 IC_LEFT() IC_RESULT()
39402 \end_layout
39403
39404 \end_inset
39405 </cell>
39406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39407 \begin_inset Text
39408
39409 \begin_layout Standard
39410
39411 \size footnotesize
39412 Bitwise complement of 
39413 \end_layout
39414
39415 \end_inset
39416 </cell>
39417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39418 \begin_inset Text
39419
39420 \begin_layout Standard
39421
39422 \size footnotesize
39423 IC_RESULT = ~IC_LEFT;
39424 \end_layout
39425
39426 \end_inset
39427 </cell>
39428 </row>
39429 <row topline="true">
39430 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39431 \begin_inset Text
39432
39433 \begin_layout Standard
39434
39435 \size footnotesize
39436 RRC
39437 \end_layout
39438
39439 \end_inset
39440 </cell>
39441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39442 \begin_inset Text
39443
39444 \begin_layout Standard
39445
39446 \size footnotesize
39447 IC_LEFT() IC_RESULT()
39448 \end_layout
39449
39450 \end_inset
39451 </cell>
39452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39453 \begin_inset Text
39454
39455 \begin_layout Standard
39456
39457 \size footnotesize
39458 Rotate right with carry
39459 \end_layout
39460
39461 \end_inset
39462 </cell>
39463 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39464 \begin_inset Text
39465
39466 \begin_layout Standard
39467
39468 \size footnotesize
39469 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
39470 \end_layout
39471
39472 \end_inset
39473 </cell>
39474 </row>
39475 <row topline="true">
39476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39477 \begin_inset Text
39478
39479 \begin_layout Standard
39480
39481 \size footnotesize
39482 RLC
39483 \end_layout
39484
39485 \end_inset
39486 </cell>
39487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39488 \begin_inset Text
39489
39490 \begin_layout Standard
39491
39492 \size footnotesize
39493 IC_LEFT() IC_RESULT()
39494 \end_layout
39495
39496 \end_inset
39497 </cell>
39498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39499 \begin_inset Text
39500
39501 \begin_layout Standard
39502
39503 \size footnotesize
39504 Rotate left with carry
39505 \end_layout
39506
39507 \end_inset
39508 </cell>
39509 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39510 \begin_inset Text
39511
39512 \begin_layout Standard
39513
39514 \size footnotesize
39515 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
39516 \end_layout
39517
39518 \end_inset
39519 </cell>
39520 </row>
39521 <row topline="true">
39522 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39523 \begin_inset Text
39524
39525 \begin_layout Standard
39526
39527 \size footnotesize
39528 GETHBIT
39529 \end_layout
39530
39531 \end_inset
39532 </cell>
39533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39534 \begin_inset Text
39535
39536 \begin_layout Standard
39537
39538 \size footnotesize
39539 IC_LEFT() IC_RESULT()
39540 \end_layout
39541
39542 \end_inset
39543 </cell>
39544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39545 \begin_inset Text
39546
39547 \begin_layout Standard
39548
39549 \size footnotesize
39550 Get the highest order bit of IC_LEFT
39551 \end_layout
39552
39553 \end_inset
39554 </cell>
39555 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39556 \begin_inset Text
39557
39558 \begin_layout Standard
39559
39560 \size footnotesize
39561 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
39562 \end_layout
39563
39564 \end_inset
39565 </cell>
39566 </row>
39567 <row topline="true">
39568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39569 \begin_inset Text
39570
39571 \begin_layout Standard
39572
39573 \size footnotesize
39574 UNARYMINUS
39575 \end_layout
39576
39577 \end_inset
39578 </cell>
39579 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39580 \begin_inset Text
39581
39582 \begin_layout Standard
39583
39584 \size footnotesize
39585 IC_LEFT() IC_RESULT()
39586 \end_layout
39587
39588 \end_inset
39589 </cell>
39590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39591 \begin_inset Text
39592
39593 \begin_layout Standard
39594
39595 \size footnotesize
39596 Unary minus
39597 \end_layout
39598
39599 \end_inset
39600 </cell>
39601 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39602 \begin_inset Text
39603
39604 \begin_layout Standard
39605
39606 \size footnotesize
39607 IC_RESULT = - IC_LEFT;
39608 \end_layout
39609
39610 \end_inset
39611 </cell>
39612 </row>
39613 <row topline="true">
39614 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39615 \begin_inset Text
39616
39617 \begin_layout Standard
39618
39619 \size footnotesize
39620 IPUSH
39621 \end_layout
39622
39623 \end_inset
39624 </cell>
39625 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39626 \begin_inset Text
39627
39628 \begin_layout Standard
39629
39630 \size footnotesize
39631 IC_LEFT()
39632 \end_layout
39633
39634 \end_inset
39635 </cell>
39636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39637 \begin_inset Text
39638
39639 \begin_layout Standard
39640
39641 \size footnotesize
39642 Push the operand into stack
39643 \end_layout
39644
39645 \end_inset
39646 </cell>
39647 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39648 \begin_inset Text
39649
39650 \begin_layout Standard
39651
39652 \size footnotesize
39653 NONE
39654 \end_layout
39655
39656 \end_inset
39657 </cell>
39658 </row>
39659 <row topline="true">
39660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39661 \begin_inset Text
39662
39663 \begin_layout Standard
39664
39665 \size footnotesize
39666 IPOP
39667 \end_layout
39668
39669 \end_inset
39670 </cell>
39671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39672 \begin_inset Text
39673
39674 \begin_layout Standard
39675
39676 \size footnotesize
39677 IC_LEFT()
39678 \end_layout
39679
39680 \end_inset
39681 </cell>
39682 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39683 \begin_inset Text
39684
39685 \begin_layout Standard
39686
39687 \size footnotesize
39688 Pop the operand from the stack 
39689 \end_layout
39690
39691 \end_inset
39692 </cell>
39693 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39694 \begin_inset Text
39695
39696 \begin_layout Standard
39697
39698 \size footnotesize
39699 NONE
39700 \end_layout
39701
39702 \end_inset
39703 </cell>
39704 </row>
39705 <row topline="true">
39706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39707 \begin_inset Text
39708
39709 \begin_layout Standard
39710
39711 \size footnotesize
39712 CALL
39713 \end_layout
39714
39715 \end_inset
39716 </cell>
39717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39718 \begin_inset Text
39719
39720 \begin_layout Standard
39721
39722 \size footnotesize
39723 IC_LEFT() IC_RESULT()
39724 \end_layout
39725
39726 \end_inset
39727 </cell>
39728 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39729 \begin_inset Text
39730
39731 \begin_layout Standard
39732
39733 \size footnotesize
39734 Call the function represented by IC_LEFT 
39735 \end_layout
39736
39737 \end_inset
39738 </cell>
39739 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39740 \begin_inset Text
39741
39742 \begin_layout Standard
39743
39744 \size footnotesize
39745 IC_RESULT = IC_LEFT();
39746 \end_layout
39747
39748 \end_inset
39749 </cell>
39750 </row>
39751 <row topline="true">
39752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39753 \begin_inset Text
39754
39755 \begin_layout Standard
39756
39757 \size footnotesize
39758 PCALL
39759 \end_layout
39760
39761 \end_inset
39762 </cell>
39763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39764 \begin_inset Text
39765
39766 \begin_layout Standard
39767
39768 \size footnotesize
39769 IC_LEFT() IC_RESULT()
39770 \end_layout
39771
39772 \end_inset
39773 </cell>
39774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39775 \begin_inset Text
39776
39777 \begin_layout Standard
39778
39779 \size footnotesize
39780 Call via function pointer
39781 \end_layout
39782
39783 \end_inset
39784 </cell>
39785 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39786 \begin_inset Text
39787
39788 \begin_layout Standard
39789
39790 \size footnotesize
39791 IC_RESULT = (*IC_LEFT)();
39792 \end_layout
39793
39794 \end_inset
39795 </cell>
39796 </row>
39797 <row topline="true">
39798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39799 \begin_inset Text
39800
39801 \begin_layout Standard
39802
39803 \size footnotesize
39804 RETURN
39805 \end_layout
39806
39807 \end_inset
39808 </cell>
39809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39810 \begin_inset Text
39811
39812 \begin_layout Standard
39813
39814 \size footnotesize
39815 IC_LEFT()
39816 \end_layout
39817
39818 \end_inset
39819 </cell>
39820 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39821 \begin_inset Text
39822
39823 \begin_layout Standard
39824
39825 \size footnotesize
39826 Return the value in operand IC_LEFT 
39827 \end_layout
39828
39829 \end_inset
39830 </cell>
39831 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39832 \begin_inset Text
39833
39834 \begin_layout Standard
39835
39836 \size footnotesize
39837 return IC_LEFT;
39838 \end_layout
39839
39840 \end_inset
39841 </cell>
39842 </row>
39843 <row topline="true">
39844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39845 \begin_inset Text
39846
39847 \begin_layout Standard
39848
39849 \size footnotesize
39850 LABEL
39851 \end_layout
39852
39853 \end_inset
39854 </cell>
39855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39856 \begin_inset Text
39857
39858 \begin_layout Standard
39859
39860 \size footnotesize
39861 IC_LABEL() 
39862 \end_layout
39863
39864 \end_inset
39865 </cell>
39866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39867 \begin_inset Text
39868
39869 \begin_layout Standard
39870
39871 \size footnotesize
39872 Label
39873 \end_layout
39874
39875 \end_inset
39876 </cell>
39877 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39878 \begin_inset Text
39879
39880 \begin_layout Standard
39881
39882 \size footnotesize
39883 IC_LABEL:
39884 \end_layout
39885
39886 \end_inset
39887 </cell>
39888 </row>
39889 <row topline="true">
39890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39891 \begin_inset Text
39892
39893 \begin_layout Standard
39894
39895 \size footnotesize
39896 GOTO
39897 \end_layout
39898
39899 \end_inset
39900 </cell>
39901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39902 \begin_inset Text
39903
39904 \begin_layout Standard
39905
39906 \size footnotesize
39907 IC_LABEL() 
39908 \end_layout
39909
39910 \end_inset
39911 </cell>
39912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39913 \begin_inset Text
39914
39915 \begin_layout Standard
39916
39917 \size footnotesize
39918 Goto label
39919 \end_layout
39920
39921 \end_inset
39922 </cell>
39923 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39924 \begin_inset Text
39925
39926 \begin_layout Standard
39927
39928 \size footnotesize
39929 goto IC_LABEL();
39930 \end_layout
39931
39932 \end_inset
39933 </cell>
39934 </row>
39935 <row topline="true">
39936 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39937 \begin_inset Text
39938
39939 \begin_layout Standard
39940
39941 \size footnotesize
39942 '+'
39943 \end_layout
39944
39945 \end_inset
39946 </cell>
39947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39948 \begin_inset Text
39949
39950 \begin_layout Standard
39951
39952 \size footnotesize
39953 IC_LEFT() IC_RIGHT() IC_RESULT()
39954 \end_layout
39955
39956 \end_inset
39957 </cell>
39958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39959 \begin_inset Text
39960
39961 \begin_layout Standard
39962
39963 \size footnotesize
39964 Addition
39965 \end_layout
39966
39967 \end_inset
39968 </cell>
39969 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39970 \begin_inset Text
39971
39972 \begin_layout Standard
39973
39974 \size footnotesize
39975 IC_RESULT = IC_LEFT + IC_RIGHT
39976 \end_layout
39977
39978 \end_inset
39979 </cell>
39980 </row>
39981 <row topline="true">
39982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39983 \begin_inset Text
39984
39985 \begin_layout Standard
39986
39987 \size footnotesize
39988 '-'
39989 \end_layout
39990
39991 \end_inset
39992 </cell>
39993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39994 \begin_inset Text
39995
39996 \begin_layout Standard
39997
39998 \size footnotesize
39999 IC_LEFT() IC_RIGHT() IC_RESULT()
40000 \end_layout
40001
40002 \end_inset
40003 </cell>
40004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40005 \begin_inset Text
40006
40007 \begin_layout Standard
40008
40009 \size footnotesize
40010 Subtraction
40011 \end_layout
40012
40013 \end_inset
40014 </cell>
40015 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40016 \begin_inset Text
40017
40018 \begin_layout Standard
40019
40020 \size footnotesize
40021 IC_RESULT = IC_LEFT - IC_RIGHT 
40022 \end_layout
40023
40024 \end_inset
40025 </cell>
40026 </row>
40027 <row topline="true">
40028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40029 \begin_inset Text
40030
40031 \begin_layout Standard
40032
40033 \size footnotesize
40034 '*'
40035 \end_layout
40036
40037 \end_inset
40038 </cell>
40039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40040 \begin_inset Text
40041
40042 \begin_layout Standard
40043
40044 \size footnotesize
40045 IC_LEFT() IC_RIGHT() IC_RESULT()
40046 \end_layout
40047
40048 \end_inset
40049 </cell>
40050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40051 \begin_inset Text
40052
40053 \begin_layout Standard
40054
40055 \size footnotesize
40056 Multiplication 
40057 \end_layout
40058
40059 \end_inset
40060 </cell>
40061 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40062 \begin_inset Text
40063
40064 \begin_layout Standard
40065
40066 \size footnotesize
40067 IC_RESULT = IC_LEFT * IC_RIGHT;
40068 \end_layout
40069
40070 \end_inset
40071 </cell>
40072 </row>
40073 <row topline="true">
40074 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40075 \begin_inset Text
40076
40077 \begin_layout Standard
40078
40079 \size footnotesize
40080 '/'
40081 \end_layout
40082
40083 \end_inset
40084 </cell>
40085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40086 \begin_inset Text
40087
40088 \begin_layout Standard
40089
40090 \size footnotesize
40091 IC_LEFT() IC_RIGHT() IC_RESULT()
40092 \end_layout
40093
40094 \end_inset
40095 </cell>
40096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40097 \begin_inset Text
40098
40099 \begin_layout Standard
40100
40101 \size footnotesize
40102 Division
40103 \end_layout
40104
40105 \end_inset
40106 </cell>
40107 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40108 \begin_inset Text
40109
40110 \begin_layout Standard
40111
40112 \size footnotesize
40113 IC_RESULT = IC_LEFT / IC_RIGHT;
40114 \end_layout
40115
40116 \end_inset
40117 </cell>
40118 </row>
40119 <row topline="true">
40120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40121 \begin_inset Text
40122
40123 \begin_layout Standard
40124
40125 \size footnotesize
40126 '%'
40127 \end_layout
40128
40129 \end_inset
40130 </cell>
40131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40132 \begin_inset Text
40133
40134 \begin_layout Standard
40135
40136 \size footnotesize
40137 IC_LEFT() IC_RIGHT() IC_RESULT()
40138 \end_layout
40139
40140 \end_inset
40141 </cell>
40142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40143 \begin_inset Text
40144
40145 \begin_layout Standard
40146
40147 \size footnotesize
40148 Modulus
40149 \end_layout
40150
40151 \end_inset
40152 </cell>
40153 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40154 \begin_inset Text
40155
40156 \begin_layout Standard
40157
40158 \size footnotesize
40159 IC_RESULT = IC_LEFT % IC_RIGHT;
40160 \end_layout
40161
40162 \end_inset
40163 </cell>
40164 </row>
40165 <row topline="true">
40166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40167 \begin_inset Text
40168
40169 \begin_layout Standard
40170
40171 \size footnotesize
40172 '<'
40173 \end_layout
40174
40175 \end_inset
40176 </cell>
40177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40178 \begin_inset Text
40179
40180 \begin_layout Standard
40181
40182 \size footnotesize
40183 IC_LEFT() IC_RIGHT() IC_RESULT()
40184 \end_layout
40185
40186 \end_inset
40187 </cell>
40188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40189 \begin_inset Text
40190
40191 \begin_layout Standard
40192
40193 \size footnotesize
40194 Less than
40195 \end_layout
40196
40197 \end_inset
40198 </cell>
40199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40200 \begin_inset Text
40201
40202 \begin_layout Standard
40203
40204 \size footnotesize
40205 IC_RESULT = IC_LEFT < IC_RIGHT;
40206 \end_layout
40207
40208 \end_inset
40209 </cell>
40210 </row>
40211 <row topline="true">
40212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40213 \begin_inset Text
40214
40215 \begin_layout Standard
40216
40217 \size footnotesize
40218 '>'
40219 \end_layout
40220
40221 \end_inset
40222 </cell>
40223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40224 \begin_inset Text
40225
40226 \begin_layout Standard
40227
40228 \size footnotesize
40229 IC_LEFT() IC_RIGHT() IC_RESULT()
40230 \end_layout
40231
40232 \end_inset
40233 </cell>
40234 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40235 \begin_inset Text
40236
40237 \begin_layout Standard
40238
40239 \size footnotesize
40240 Greater than 
40241 \end_layout
40242
40243 \end_inset
40244 </cell>
40245 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40246 \begin_inset Text
40247
40248 \begin_layout Standard
40249
40250 \size footnotesize
40251 IC_RESULT = IC_LEFT > IC_RIGHT;
40252 \end_layout
40253
40254 \end_inset
40255 </cell>
40256 </row>
40257 <row topline="true">
40258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40259 \begin_inset Text
40260
40261 \begin_layout Standard
40262
40263 \size footnotesize
40264 EQ_OP
40265 \end_layout
40266
40267 \end_inset
40268 </cell>
40269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40270 \begin_inset Text
40271
40272 \begin_layout Standard
40273
40274 \size footnotesize
40275 IC_LEFT() IC_RIGHT() IC_RESULT()
40276 \end_layout
40277
40278 \end_inset
40279 </cell>
40280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40281 \begin_inset Text
40282
40283 \begin_layout Standard
40284
40285 \size footnotesize
40286 Equal to 
40287 \end_layout
40288
40289 \end_inset
40290 </cell>
40291 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40292 \begin_inset Text
40293
40294 \begin_layout Standard
40295
40296 \size footnotesize
40297 IC_RESULT = IC_LEFT == IC_RIGHT;
40298 \end_layout
40299
40300 \end_inset
40301 </cell>
40302 </row>
40303 <row topline="true">
40304 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40305 \begin_inset Text
40306
40307 \begin_layout Standard
40308
40309 \size footnotesize
40310 AND_OP
40311 \end_layout
40312
40313 \end_inset
40314 </cell>
40315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40316 \begin_inset Text
40317
40318 \begin_layout Standard
40319
40320 \size footnotesize
40321 IC_LEFT() IC_RIGHT() IC_RESULT() 
40322 \end_layout
40323
40324 \end_inset
40325 </cell>
40326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40327 \begin_inset Text
40328
40329 \begin_layout Standard
40330
40331 \size footnotesize
40332 Logical and operation
40333 \end_layout
40334
40335 \end_inset
40336 </cell>
40337 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40338 \begin_inset Text
40339
40340 \begin_layout Standard
40341
40342 \size footnotesize
40343 IC_RESULT = IC_LEFT && IC_RIGHT; 
40344 \end_layout
40345
40346 \end_inset
40347 </cell>
40348 </row>
40349 <row topline="true">
40350 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40351 \begin_inset Text
40352
40353 \begin_layout Standard
40354
40355 \size footnotesize
40356 OR_OP
40357 \end_layout
40358
40359 \end_inset
40360 </cell>
40361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40362 \begin_inset Text
40363
40364 \begin_layout Standard
40365
40366 \size footnotesize
40367 IC_LEFT() IC_RIGHT() IC_RESULT() 
40368 \end_layout
40369
40370 \end_inset
40371 </cell>
40372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40373 \begin_inset Text
40374
40375 \begin_layout Standard
40376
40377 \size footnotesize
40378 Logical or operation 
40379 \end_layout
40380
40381 \end_inset
40382 </cell>
40383 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40384 \begin_inset Text
40385
40386 \begin_layout Standard
40387
40388 \size footnotesize
40389 IC_RESULT = IC_LEFT || IC_RIGHT; 
40390 \end_layout
40391
40392 \end_inset
40393 </cell>
40394 </row>
40395 <row topline="true">
40396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40397 \begin_inset Text
40398
40399 \begin_layout Standard
40400
40401 \size footnotesize
40402 '^'
40403 \end_layout
40404
40405 \end_inset
40406 </cell>
40407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40408 \begin_inset Text
40409
40410 \begin_layout Standard
40411
40412 \size footnotesize
40413 IC_LEFT() IC_RIGHT() IC_RESULT() 
40414 \end_layout
40415
40416 \end_inset
40417 </cell>
40418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40419 \begin_inset Text
40420
40421 \begin_layout Standard
40422
40423 \size footnotesize
40424 Exclusive OR
40425 \end_layout
40426
40427 \end_inset
40428 </cell>
40429 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40430 \begin_inset Text
40431
40432 \begin_layout Standard
40433
40434 \size footnotesize
40435 IC_RESULT = IC_LEFT ^ IC_RIGHT;
40436 \end_layout
40437
40438 \end_inset
40439 </cell>
40440 </row>
40441 <row topline="true">
40442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40443 \begin_inset Text
40444
40445 \begin_layout Standard
40446
40447 \size footnotesize
40448 '|'
40449 \end_layout
40450
40451 \end_inset
40452 </cell>
40453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40454 \begin_inset Text
40455
40456 \begin_layout Standard
40457
40458 \size footnotesize
40459 IC_LEFT() IC_RIGHT() IC_RESULT() 
40460 \end_layout
40461
40462 \end_inset
40463 </cell>
40464 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40465 \begin_inset Text
40466
40467 \begin_layout Standard
40468
40469 \size footnotesize
40470 Bitwise OR 
40471 \end_layout
40472
40473 \end_inset
40474 </cell>
40475 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40476 \begin_inset Text
40477
40478 \begin_layout Standard
40479
40480 \size footnotesize
40481 IC_RESULT = IC_LEFT | IC_RIGHT;
40482 \end_layout
40483
40484 \end_inset
40485 </cell>
40486 </row>
40487 <row topline="true">
40488 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40489 \begin_inset Text
40490
40491 \begin_layout Standard
40492
40493 \size footnotesize
40494 BITWISEAND
40495 \end_layout
40496
40497 \end_inset
40498 </cell>
40499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40500 \begin_inset Text
40501
40502 \begin_layout Standard
40503
40504 \size footnotesize
40505 IC_LEFT() IC_RIGHT() IC_RESULT()
40506 \end_layout
40507
40508 \end_inset
40509 </cell>
40510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40511 \begin_inset Text
40512
40513 \begin_layout Standard
40514
40515 \size footnotesize
40516 Bitwise AND 
40517 \end_layout
40518
40519 \end_inset
40520 </cell>
40521 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40522 \begin_inset Text
40523
40524 \begin_layout Standard
40525
40526 \size footnotesize
40527 IC_RESULT = IC_LEFT & IC_RIGHT;
40528 \end_layout
40529
40530 \end_inset
40531 </cell>
40532 </row>
40533 <row topline="true">
40534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40535 \begin_inset Text
40536
40537 \begin_layout Standard
40538
40539 \size footnotesize
40540 LEFT_OP
40541 \end_layout
40542
40543 \end_inset
40544 </cell>
40545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40546 \begin_inset Text
40547
40548 \begin_layout Standard
40549
40550 \size footnotesize
40551 IC_LEFT() IC_RIGHT() IC_RESULT()
40552 \end_layout
40553
40554 \end_inset
40555 </cell>
40556 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40557 \begin_inset Text
40558
40559 \begin_layout Standard
40560
40561 \size footnotesize
40562 Left shift 
40563 \end_layout
40564
40565 \end_inset
40566 </cell>
40567 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40568 \begin_inset Text
40569
40570 \begin_layout Standard
40571
40572 \size footnotesize
40573 IC_RESULT = IC_LEFT << IC_RIGHT 
40574 \end_layout
40575
40576 \end_inset
40577 </cell>
40578 </row>
40579 <row topline="true">
40580 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40581 \begin_inset Text
40582
40583 \begin_layout Standard
40584
40585 \size footnotesize
40586 RIGHT_OP
40587 \end_layout
40588
40589 \end_inset
40590 </cell>
40591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40592 \begin_inset Text
40593
40594 \begin_layout Standard
40595
40596 \size footnotesize
40597 IC_LEFT() IC_RIGHT() IC_RESULT()
40598 \end_layout
40599
40600 \end_inset
40601 </cell>
40602 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40603 \begin_inset Text
40604
40605 \begin_layout Standard
40606
40607 \size footnotesize
40608 Right shift
40609 \end_layout
40610
40611 \end_inset
40612 </cell>
40613 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40614 \begin_inset Text
40615
40616 \begin_layout Standard
40617
40618 \size footnotesize
40619 IC_RESULT = IC_LEFT >> IC_RIGHT 
40620 \end_layout
40621
40622 \end_inset
40623 </cell>
40624 </row>
40625 <row topline="true">
40626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40627 \begin_inset Text
40628
40629 \begin_layout Standard
40630
40631 \size footnotesize
40632 GET_VALUE_
40633 \newline
40634 AT_ ADDRESS
40635 \end_layout
40636
40637 \end_inset
40638 </cell>
40639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40640 \begin_inset Text
40641
40642 \begin_layout Standard
40643
40644 \size footnotesize
40645 IC_LEFT() IC_RESULT()
40646 \end_layout
40647
40648 \end_inset
40649 </cell>
40650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40651 \begin_inset Text
40652
40653 \begin_layout Standard
40654
40655 \size footnotesize
40656 Indirect fetch 
40657 \end_layout
40658
40659 \end_inset
40660 </cell>
40661 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40662 \begin_inset Text
40663
40664 \begin_layout Standard
40665
40666 \size footnotesize
40667 IC_RESULT = (*IC_LEFT);
40668 \end_layout
40669
40670 \end_inset
40671 </cell>
40672 </row>
40673 <row topline="true">
40674 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40675 \begin_inset Text
40676
40677 \begin_layout Standard
40678
40679 \size footnotesize
40680 POINTER_SET
40681 \end_layout
40682
40683 \end_inset
40684 </cell>
40685 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40686 \begin_inset Text
40687
40688 \begin_layout Standard
40689
40690 \size footnotesize
40691 IC_RIGHT() IC_RESULT() 
40692 \end_layout
40693
40694 \end_inset
40695 </cell>
40696 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40697 \begin_inset Text
40698
40699 \begin_layout Standard
40700
40701 \size footnotesize
40702 Indirect set
40703 \end_layout
40704
40705 \end_inset
40706 </cell>
40707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40708 \begin_inset Text
40709
40710 \begin_layout Standard
40711
40712 \size footnotesize
40713 (*IC_RESULT) = IC_RIGHT;
40714 \end_layout
40715
40716 \end_inset
40717 </cell>
40718 </row>
40719 <row topline="true">
40720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40721 \begin_inset Text
40722
40723 \begin_layout Standard
40724
40725 \size footnotesize
40726 '='
40727 \end_layout
40728
40729 \end_inset
40730 </cell>
40731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40732 \begin_inset Text
40733
40734 \begin_layout Standard
40735
40736 \size footnotesize
40737 IC_RIGHT() IC_RESULT()
40738 \end_layout
40739
40740 \end_inset
40741 </cell>
40742 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40743 \begin_inset Text
40744
40745 \begin_layout Standard
40746
40747 \size footnotesize
40748 Assignment
40749 \end_layout
40750
40751 \end_inset
40752 </cell>
40753 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40754 \begin_inset Text
40755
40756 \begin_layout Standard
40757
40758 \size footnotesize
40759 IC_RESULT = IC_RIGHT;
40760 \end_layout
40761
40762 \end_inset
40763 </cell>
40764 </row>
40765 <row topline="true">
40766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40767 \begin_inset Text
40768
40769 \begin_layout Standard
40770
40771 \size footnotesize
40772 IFX
40773 \end_layout
40774
40775 \end_inset
40776 </cell>
40777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40778 \begin_inset Text
40779
40780 \begin_layout Standard
40781
40782 \size footnotesize
40783 IC_COND IC_TRUE IC_LABEL
40784 \end_layout
40785
40786 \end_inset
40787 </cell>
40788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40789 \begin_inset Text
40790
40791 \begin_layout Standard
40792
40793 \size footnotesize
40794 Conditional jump.
40795  If true label is present then jump to true label if condition is true else
40796  jump to false label if condition is false 
40797 \end_layout
40798
40799 \end_inset
40800 </cell>
40801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40802 \begin_inset Text
40803
40804 \begin_layout Standard
40805
40806 \size footnotesize
40807 if (IC_COND) goto IC_TRUE; 
40808 \newline
40809 \InsetSpace ~
40810 \InsetSpace ~
40811 Or 
40812 \newline
40813 If (!IC_COND) goto IC_FALSE;
40814 \end_layout
40815
40816 \end_inset
40817 </cell>
40818 </row>
40819 <row topline="true">
40820 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40821 \begin_inset Text
40822
40823 \begin_layout Standard
40824
40825 \size footnotesize
40826 ADDRESS_OF
40827 \end_layout
40828
40829 \end_inset
40830 </cell>
40831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40832 \begin_inset Text
40833
40834 \begin_layout Standard
40835
40836 \size footnotesize
40837 IC_LEFT() IC_RESULT()
40838 \end_layout
40839
40840 \end_inset
40841 </cell>
40842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40843 \begin_inset Text
40844
40845 \begin_layout Standard
40846
40847 \size footnotesize
40848 Address of 
40849 \end_layout
40850
40851 \end_inset
40852 </cell>
40853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40854 \begin_inset Text
40855
40856 \begin_layout Standard
40857
40858 \size footnotesize
40859 IC_RESULT = &IC_LEFT();
40860 \end_layout
40861
40862 \end_inset
40863 </cell>
40864 </row>
40865 <row topline="true">
40866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40867 \begin_inset Text
40868
40869 \begin_layout Standard
40870
40871 \size footnotesize
40872 JUMPTABLE
40873 \end_layout
40874
40875 \end_inset
40876 </cell>
40877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40878 \begin_inset Text
40879
40880 \begin_layout Standard
40881
40882 \size footnotesize
40883 IC_JTCOND IC_JTLABELS
40884 \end_layout
40885
40886 \end_inset
40887 </cell>
40888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40889 \begin_inset Text
40890
40891 \begin_layout Standard
40892
40893 \size footnotesize
40894 Jump to list of labels depending on the value of JTCOND
40895 \end_layout
40896
40897 \end_inset
40898 </cell>
40899 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40900 \begin_inset Text
40901
40902 \begin_layout Standard
40903
40904 \size footnotesize
40905 Switch statement
40906 \end_layout
40907
40908 \end_inset
40909 </cell>
40910 </row>
40911 <row topline="true">
40912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40913 \begin_inset Text
40914
40915 \begin_layout Standard
40916
40917 \size footnotesize
40918 CAST
40919 \end_layout
40920
40921 \end_inset
40922 </cell>
40923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40924 \begin_inset Text
40925
40926 \begin_layout Standard
40927
40928 \size footnotesize
40929 IC_RIGHT() IC_LEFT() IC_RESULT()
40930 \end_layout
40931
40932 \end_inset
40933 </cell>
40934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40935 \begin_inset Text
40936
40937 \begin_layout Standard
40938
40939 \size footnotesize
40940 Cast types 
40941 \end_layout
40942
40943 \end_inset
40944 </cell>
40945 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40946 \begin_inset Text
40947
40948 \begin_layout Standard
40949
40950 \size footnotesize
40951 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
40952 \end_layout
40953
40954 \end_inset
40955 </cell>
40956 </row>
40957 <row topline="true">
40958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40959 \begin_inset Text
40960
40961 \begin_layout Standard
40962
40963 \size footnotesize
40964 SEND
40965 \end_layout
40966
40967 \end_inset
40968 </cell>
40969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40970 \begin_inset Text
40971
40972 \begin_layout Standard
40973
40974 \size footnotesize
40975 IC_LEFT()
40976 \end_layout
40977
40978 \end_inset
40979 </cell>
40980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40981 \begin_inset Text
40982
40983 \begin_layout Standard
40984
40985 \size footnotesize
40986 This is used for passing parameters in registers; 
40987 \newline
40988 move IC_LEFT to the next
40989  available parameter register.
40990 \end_layout
40991
40992 \end_inset
40993 </cell>
40994 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40995 \begin_inset Text
40996
40997 \begin_layout Standard
40998
40999 \size footnotesize
41000 None
41001 \end_layout
41002
41003 \end_inset
41004 </cell>
41005 </row>
41006 <row topline="true">
41007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41008 \begin_inset Text
41009
41010 \begin_layout Standard
41011
41012 \size footnotesize
41013 RECV
41014 \end_layout
41015
41016 \end_inset
41017 </cell>
41018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41019 \begin_inset Text
41020
41021 \begin_layout Standard
41022
41023 \size footnotesize
41024 IC_RESULT()
41025 \end_layout
41026
41027 \end_inset
41028 </cell>
41029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41030 \begin_inset Text
41031
41032 \begin_layout Standard
41033
41034 \size footnotesize
41035 This is used for receiving parameters passed in registers;
41036 \newline
41037 Move the values
41038  in the next parameter register to IC_RESULT 
41039 \end_layout
41040
41041 \end_inset
41042 </cell>
41043 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41044 \begin_inset Text
41045
41046 \begin_layout Standard
41047
41048 \size footnotesize
41049 None
41050 \end_layout
41051
41052 \end_inset
41053 </cell>
41054 </row>
41055 <row topline="true" bottomline="true">
41056 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41057 \begin_inset Text
41058
41059 \begin_layout Standard
41060
41061 \shape slanted
41062 \size footnotesize
41063 (some more have been added)
41064 \end_layout
41065
41066 \end_inset
41067 </cell>
41068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41069 \begin_inset Text
41070
41071 \begin_layout Standard
41072
41073 \end_layout
41074
41075 \end_inset
41076 </cell>
41077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41078 \begin_inset Text
41079
41080 \begin_layout Standard
41081
41082 \end_layout
41083
41084 \end_inset
41085 </cell>
41086 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41087 \begin_inset Text
41088
41089 \begin_layout Standard
41090
41091 \shape slanted
41092 \size footnotesize
41093 see f.e.
41094
41095 \shape default
41096  
41097 \family typewriter
41098 \shape slanted
41099 gen51Code()
41100 \family default
41101 \shape default
41102  
41103 \shape slanted
41104 in
41105 \shape default
41106  
41107 \family typewriter
41108 \shape slanted
41109 src/mcs51/gen.c
41110 \end_layout
41111
41112 \end_inset
41113 </cell>
41114 </row>
41115 </lyxtabular>
41116
41117 \end_inset
41118
41119
41120 \end_layout
41121
41122 \begin_layout Standard
41123 \begin_inset Note Note
41124 status collapsed
41125
41126 \begin_layout Standard
41127 In the original article Figure II was announced to be downloadable on 
41128 \shape italic
41129 Circuit Cellar
41130 \shape default
41131 's web site.
41132  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
41133 \end_layout
41134
41135 \end_inset
41136
41137
41138 \end_layout
41139
41140 \begin_layout Paragraph*
41141 ICode Example
41142 \begin_inset LatexCommand index
41143 name "iCode"
41144
41145 \end_inset
41146
41147
41148 \end_layout
41149
41150 \begin_layout Standard
41151 This section shows some details of iCode.
41152  The example C code does not do anything useful; it is used as an example
41153  to illustrate the intermediate code generated by the compiler.
41154 \end_layout
41155
41156 \begin_layout Verse
41157
41158 \family typewriter
41159 1.\InsetSpace ~
41160 xdata int * p;
41161 \newline
41162 2.\InsetSpace ~
41163 int gint;
41164 \newline
41165 3.\InsetSpace ~
41166 /* This function does nothing useful.
41167  It is used
41168 \newline
41169 4.\InsetSpace ~
41170 \InsetSpace ~
41171 \InsetSpace ~
41172 \InsetSpace ~
41173 for the purpose of explaining iCode */
41174 \newline
41175 5.\InsetSpace ~
41176 short function (data
41177  int *x)
41178 \newline
41179 6.\InsetSpace ~
41180 {
41181 \newline
41182 7.\InsetSpace ~
41183 \InsetSpace ~
41184 \InsetSpace ~
41185 short i=10; \InsetSpace ~
41186 \InsetSpace ~
41187 /* dead initialization eliminated */
41188 \newline
41189 8.\InsetSpace ~
41190 \InsetSpace ~
41191 \InsetSpace ~
41192 short sum=10;
41193  /* dead initialization eliminated */
41194 \newline
41195 9.\InsetSpace ~
41196 \InsetSpace ~
41197 \InsetSpace ~
41198 short mul;
41199 \newline
41200 10.\InsetSpace ~
41201 \InsetSpace ~
41202 int j ;
41203 \newline
41204 11.\InsetSpace ~
41205 \InsetSpace ~
41206 while (*x) *x++
41207  = *p++; 
41208 \newline
41209 12.\InsetSpace ~
41210 \InsetSpace ~
41211 \InsetSpace ~
41212 \InsetSpace ~
41213 sum = 0 ; 
41214 \newline
41215 13.\InsetSpace ~
41216 \InsetSpace ~
41217 mul = 0;
41218 \newline
41219 14.\InsetSpace ~
41220 \InsetSpace ~
41221 /* compiler detects i,j to be induction
41222  variables */
41223 \newline
41224 15.\InsetSpace ~
41225 \InsetSpace ~
41226 for (i = 0, j = 10 ; i < 10 ; i++, j
41227 \family default
41228 -
41229 \begin_inset ERT
41230 status collapsed
41231
41232 \begin_layout Standard
41233
41234
41235 \backslash
41236 /
41237 \end_layout
41238
41239 \end_inset
41240
41241 -
41242 \family typewriter
41243 ) {
41244 \newline
41245 16.\InsetSpace ~
41246 \InsetSpace ~
41247 \InsetSpace ~
41248 \InsetSpace ~
41249 sum += i;
41250 \newline
41251 17.\InsetSpace ~
41252 \InsetSpace ~
41253 \InsetSpace ~
41254 \InsetSpace ~
41255 mul += i * 3; \InsetSpace ~
41256 \InsetSpace ~
41257 /* this multiplication remains */
41258 \newline
41259 18.\InsetSpace ~
41260 \InsetSpace ~
41261 \InsetSpace ~
41262 \InsetSpace ~
41263 gint +=
41264  j * 3;\InsetSpace ~
41265 \InsetSpace ~
41266 /* this multiplication changed to addition */
41267 \newline
41268 19.\InsetSpace ~
41269 \InsetSpace ~
41270 }
41271 \newline
41272 20.\InsetSpace ~
41273 \InsetSpace ~
41274 return sum+mul;
41275 \newline
41276 21.\InsetSpace ~
41277 }
41278 \end_layout
41279
41280 \begin_layout Standard
41281 In addition to the operands each iCode contains information about the filename
41282  and line it corresponds to in the source file.
41283  The first field in the listing should be interpreted as follows:
41284 \newline
41285
41286 \shape italic
41287 \size footnotesize
41288 Filename(linenumber: iCode Execution sequence number : ICode hash table
41289  key : loop depth of the iCode).
41290 \shape default
41291 \size default
41292
41293 \newline
41294 Then follows the human readable form of the ICode operation.
41295  Each operand of this triplet form can be of three basic types a) compiler
41296  generated temporary b) user defined variable c) a constant value.
41297  Note that local variables and parameters are replaced by compiler generated
41298  temporaries.
41299  Live ranges
41300 \begin_inset LatexCommand index
41301 name "Live range analysis"
41302
41303 \end_inset
41304
41305  are computed only for temporaries (i.e.
41306  live ranges are not computed for global variables).
41307  Registers
41308 \begin_inset LatexCommand index
41309 name "Register allocation"
41310
41311 \end_inset
41312
41313  are allocated for temporaries only.
41314  Operands are formatted in the following manner:
41315 \newline
41316
41317 \shape italic
41318 \size footnotesize
41319 Operand Name [lr live-from : live-to ] { type information } [ registers
41320  allocated ].
41321 \shape default
41322 \size default
41323
41324 \newline
41325 As mentioned earlier the live ranges are computed in terms of the execution
41326  sequence number of the iCodes, for example 
41327 \newline
41328 the iTemp0 is live from (i.e.
41329  first defined in iCode with execution sequence number 3, and is last used
41330  in the iCode with sequence number 5).
41331  For induction variables such as iTemp21 the live range computation extends
41332  the lifetime from the start to the end of the loop.
41333 \newline
41334 The register allocator
41335  used the live range information to allocate registers, the same registers
41336  may be used for different temporaries if their live ranges do not overlap,
41337  for example r0 is allocated to both iTemp6 and to iTemp17 since their live
41338  ranges do not overlap.
41339  In addition the allocator also takes into consideration the type and usage
41340  of a temporary, for example itemp6 is a pointer to near space and is used
41341  as to fetch data from (i.e.
41342  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
41343  Some short lived temporaries are allocated to special registers which have
41344  meaning to the code generator e.g.
41345  iTemp13 is allocated to a pseudo register CC which tells the back end that
41346  the temporary is used only for a conditional jump the code generation makes
41347  use of this information to optimize a compare and jump ICode.
41348 \newline
41349 There are several
41350  loop optimizations
41351 \begin_inset LatexCommand index
41352 name "Loop optimization"
41353
41354 \end_inset
41355
41356  performed by the compiler.
41357  It can detect induction variables iTemp21(i) and iTemp23(j).
41358  Also note the compiler does selective strength reduction
41359 \begin_inset LatexCommand index
41360 name "Strength reduction"
41361
41362 \end_inset
41363
41364 , i.e.
41365  the multiplication of an induction variable in line 18 (gint = j * 3) is
41366  changed to addition, a new temporary iTemp17 is allocated and assigned
41367  a initial value, a constant 3 is then added for each iteration of the loop.
41368  The compiler does not change the multiplication
41369 \begin_inset LatexCommand index
41370 name "Multiplication"
41371
41372 \end_inset
41373
41374  in line 17 however since the processor does support an 8 * 8 bit multiplication.
41375 \newline
41376
41377 Note the dead code elimination
41378 \begin_inset LatexCommand index
41379 name "Dead-code elimination"
41380
41381 \end_inset
41382
41383  optimization eliminated the dead assignments in line 7 & 8 to I and sum
41384  respectively.
41385 \newline
41386
41387 \end_layout
41388
41389 \begin_layout Standard
41390
41391 \size footnotesize
41392 Sample.c (5:1:0:0) _entry($9) :
41393 \end_layout
41394
41395 \begin_layout Standard
41396
41397 \size footnotesize
41398 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
41399 \end_layout
41400
41401 \begin_layout Standard
41402
41403 \size footnotesize
41404 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
41405 \end_layout
41406
41407 \begin_layout Standard
41408
41409 \size footnotesize
41410 Sample.c(11:4:53:0) preHeaderLbl0($11) :
41411 \end_layout
41412
41413 \begin_layout Standard
41414
41415 \size footnotesize
41416 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
41417  * int}[r2]
41418 \end_layout
41419
41420 \begin_layout Standard
41421
41422 \size footnotesize
41423 Sample.c(11:6:5:1) _whilecontinue_0($1) :
41424 \end_layout
41425
41426 \begin_layout Standard
41427
41428 \size footnotesize
41429 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
41430  int}[r0]]
41431 \end_layout
41432
41433 \begin_layout Standard
41434
41435 \size footnotesize
41436 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
41437 \end_layout
41438
41439 \begin_layout Standard
41440
41441 \size footnotesize
41442 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
41443  * int}
41444 \end_layout
41445
41446 \begin_layout Standard
41447
41448 \size footnotesize
41449 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
41450  {short}
41451 \end_layout
41452
41453 \begin_layout Standard
41454
41455 \size footnotesize
41456 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
41457  * int}[DPTR]]
41458 \end_layout
41459
41460 \begin_layout Standard
41461
41462 \size footnotesize
41463 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
41464 }[r2 r3]
41465 \end_layout
41466
41467 \begin_layout Standard
41468
41469 \size footnotesize
41470 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
41471  * int}[r0] + 0x2 {short}
41472 \end_layout
41473
41474 \begin_layout Standard
41475
41476 \size footnotesize
41477 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
41478 \end_layout
41479
41480 \begin_layout Standard
41481
41482 \size footnotesize
41483 Sample.c(11:17:21:0)_whilebreak_0($3) :
41484 \end_layout
41485
41486 \begin_layout Standard
41487
41488 \size footnotesize
41489 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
41490 \end_layout
41491
41492 \begin_layout Standard
41493
41494 \size footnotesize
41495 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
41496 \end_layout
41497
41498 \begin_layout Standard
41499
41500 \size footnotesize
41501 Sample.c(15:20:54:0)preHeaderLbl1($13) :
41502 \end_layout
41503
41504 \begin_layout Standard
41505
41506 \size footnotesize
41507 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
41508 \end_layout
41509
41510 \begin_layout Standard
41511
41512 \size footnotesize
41513 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
41514 \end_layout
41515
41516 \begin_layout Standard
41517
41518 \size footnotesize
41519 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
41520 \end_layout
41521
41522 \begin_layout Standard
41523
41524 \size footnotesize
41525 Sample.c(15:24:26:1)_forcond_0($4) :
41526 \end_layout
41527
41528 \begin_layout Standard
41529
41530 \size footnotesize
41531 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
41532  < 0xa {short}
41533 \end_layout
41534
41535 \begin_layout Standard
41536
41537 \size footnotesize
41538 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
41539 \end_layout
41540
41541 \begin_layout Standard
41542
41543 \size footnotesize
41544 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
41545  + ITemp21 [lr21:38]{short}[r4]
41546 \end_layout
41547
41548 \begin_layout Standard
41549
41550 \size footnotesize
41551 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
41552  * 0x3 {short}
41553 \end_layout
41554
41555 \begin_layout Standard
41556
41557 \size footnotesize
41558 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
41559  + iTemp15 [lr29:30]{short}[r1]
41560 \end_layout
41561
41562 \begin_layout Standard
41563
41564 \size footnotesize
41565 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
41566  r0]- 0x3 {short}
41567 \end_layout
41568
41569 \begin_layout Standard
41570
41571 \size footnotesize
41572 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
41573 int}[r7 r0]
41574 \end_layout
41575
41576 \begin_layout Standard
41577
41578 \size footnotesize
41579 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
41580  + 0x1 {short}
41581 \end_layout
41582
41583 \begin_layout Standard
41584
41585 \size footnotesize
41586 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
41587  r6]- 0x1 {short}
41588 \end_layout
41589
41590 \begin_layout Standard
41591
41592 \size footnotesize
41593 Sample.c(19:38:47:1) goto _forcond_0($4)
41594 \end_layout
41595
41596 \begin_layout Standard
41597
41598 \size footnotesize
41599 Sample.c(19:39:48:0)_forbreak_0($7) :
41600 \end_layout
41601
41602 \begin_layout Standard
41603
41604 \size footnotesize
41605 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
41606  + ITemp11 [lr19:40]{short}[r3]
41607 \end_layout
41608
41609 \begin_layout Standard
41610
41611 \size footnotesize
41612 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
41613 \end_layout
41614
41615 \begin_layout Standard
41616
41617 \size footnotesize
41618 Sample.c(20:42:51:0)_return($8) :
41619 \end_layout
41620
41621 \begin_layout Standard
41622
41623 \size footnotesize
41624 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
41625 \size default
41626
41627 \newline
41628
41629 \newline
41630 Finally the code generated for this function:
41631 \newline
41632
41633 \end_layout
41634
41635 \begin_layout Standard
41636
41637 \size footnotesize
41638 .area DSEG (DATA)
41639 \end_layout
41640
41641 \begin_layout Standard
41642
41643 \size footnotesize
41644 _p::
41645 \end_layout
41646
41647 \begin_layout Standard
41648
41649 \size footnotesize
41650 \InsetSpace ~
41651 \InsetSpace ~
41652 .ds 2
41653 \end_layout
41654
41655 \begin_layout Standard
41656
41657 \size footnotesize
41658 _gint::
41659 \end_layout
41660
41661 \begin_layout Standard
41662
41663 \size footnotesize
41664 \InsetSpace ~
41665 \InsetSpace ~
41666 .ds 2
41667 \end_layout
41668
41669 \begin_layout Standard
41670
41671 \size footnotesize
41672 ; sample.c 5
41673 \end_layout
41674
41675 \begin_layout Standard
41676
41677 \size footnotesize
41678 ; ----------------------------------------------
41679 \end_layout
41680
41681 \begin_layout Standard
41682
41683 \size footnotesize
41684 ; function function
41685 \end_layout
41686
41687 \begin_layout Standard
41688
41689 \size footnotesize
41690 ; ----------------------------------------------
41691 \end_layout
41692
41693 \begin_layout Standard
41694
41695 \size footnotesize
41696 _function:
41697 \end_layout
41698
41699 \begin_layout Standard
41700
41701 \size footnotesize
41702 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
41703 \end_layout
41704
41705 \begin_layout Standard
41706
41707 \size footnotesize
41708 \InsetSpace ~
41709 \InsetSpace ~
41710 mov r2,dpl
41711 \end_layout
41712
41713 \begin_layout Standard
41714
41715 \size footnotesize
41716 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
41717 \end_layout
41718
41719 \begin_layout Standard
41720
41721 \size footnotesize
41722 \InsetSpace ~
41723 \InsetSpace ~
41724 mov ar0,r2
41725 \end_layout
41726
41727 \begin_layout Standard
41728
41729 \size footnotesize
41730 ;_whilecontinue_0($1) :
41731 \end_layout
41732
41733 \begin_layout Standard
41734
41735 \size footnotesize
41736 00101$:
41737 \end_layout
41738
41739 \begin_layout Standard
41740
41741 \size footnotesize
41742 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
41743 \end_layout
41744
41745 \begin_layout Standard
41746
41747 \size footnotesize
41748 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
41749 \end_layout
41750
41751 \begin_layout Standard
41752
41753 \size footnotesize
41754 \InsetSpace ~
41755 \InsetSpace ~
41756 mov ar2,@r0
41757 \end_layout
41758
41759 \begin_layout Standard
41760
41761 \size footnotesize
41762 \InsetSpace ~
41763 \InsetSpace ~
41764 inc r0
41765 \end_layout
41766
41767 \begin_layout Standard
41768
41769 \size footnotesize
41770 \InsetSpace ~
41771 \InsetSpace ~
41772 mov ar3,@r0
41773 \end_layout
41774
41775 \begin_layout Standard
41776
41777 \size footnotesize
41778 \InsetSpace ~
41779 \InsetSpace ~
41780 dec r0
41781 \end_layout
41782
41783 \begin_layout Standard
41784
41785 \size footnotesize
41786 \InsetSpace ~
41787 \InsetSpace ~
41788 mov a,r2
41789 \end_layout
41790
41791 \begin_layout Standard
41792
41793 \size footnotesize
41794 \InsetSpace ~
41795 \InsetSpace ~
41796 orl a,r3
41797 \end_layout
41798
41799 \begin_layout Standard
41800
41801 \size footnotesize
41802 \InsetSpace ~
41803 \InsetSpace ~
41804 jz 00103$
41805 \end_layout
41806
41807 \begin_layout Standard
41808
41809 \size footnotesize
41810 00114$:
41811 \end_layout
41812
41813 \begin_layout Standard
41814
41815 \size footnotesize
41816 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
41817 \end_layout
41818
41819 \begin_layout Standard
41820
41821 \size footnotesize
41822 \InsetSpace ~
41823 \InsetSpace ~
41824 mov dpl,_p
41825 \end_layout
41826
41827 \begin_layout Standard
41828
41829 \size footnotesize
41830 \InsetSpace ~
41831 \InsetSpace ~
41832 mov dph,(_p + 1)
41833 \end_layout
41834
41835 \begin_layout Standard
41836
41837 \size footnotesize
41838 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
41839 \end_layout
41840
41841 \begin_layout Standard
41842
41843 \size footnotesize
41844 \InsetSpace ~
41845 \InsetSpace ~
41846 mov a,#0x02
41847 \end_layout
41848
41849 \begin_layout Standard
41850
41851 \size footnotesize
41852 \InsetSpace ~
41853 \InsetSpace ~
41854 add a,_p
41855 \end_layout
41856
41857 \begin_layout Standard
41858
41859 \size footnotesize
41860 \InsetSpace ~
41861 \InsetSpace ~
41862 mov _p,a
41863 \end_layout
41864
41865 \begin_layout Standard
41866
41867 \size footnotesize
41868 \InsetSpace ~
41869 \InsetSpace ~
41870 clr a
41871 \end_layout
41872
41873 \begin_layout Standard
41874
41875 \size footnotesize
41876 \InsetSpace ~
41877 \InsetSpace ~
41878 addc a,(_p + 1)
41879 \end_layout
41880
41881 \begin_layout Standard
41882
41883 \size footnotesize
41884 \InsetSpace ~
41885 \InsetSpace ~
41886 mov (_p + 1),a
41887 \end_layout
41888
41889 \begin_layout Standard
41890
41891 \size footnotesize
41892 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
41893 \end_layout
41894
41895 \begin_layout Standard
41896
41897 \size footnotesize
41898 \InsetSpace ~
41899 \InsetSpace ~
41900 movx a,@dptr
41901 \end_layout
41902
41903 \begin_layout Standard
41904
41905 \size footnotesize
41906 \InsetSpace ~
41907 \InsetSpace ~
41908 mov r2,a
41909 \end_layout
41910
41911 \begin_layout Standard
41912
41913 \size footnotesize
41914 \InsetSpace ~
41915 \InsetSpace ~
41916 inc dptr
41917 \end_layout
41918
41919 \begin_layout Standard
41920
41921 \size footnotesize
41922 \InsetSpace ~
41923 \InsetSpace ~
41924 movx a,@dptr
41925 \end_layout
41926
41927 \begin_layout Standard
41928
41929 \size footnotesize
41930 \InsetSpace ~
41931 \InsetSpace ~
41932 mov r3,a
41933 \end_layout
41934
41935 \begin_layout Standard
41936
41937 \size footnotesize
41938 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
41939 \end_layout
41940
41941 \begin_layout Standard
41942
41943 \size footnotesize
41944 \InsetSpace ~
41945 \InsetSpace ~
41946 mov @r0,ar2
41947 \end_layout
41948
41949 \begin_layout Standard
41950
41951 \size footnotesize
41952 \InsetSpace ~
41953 \InsetSpace ~
41954 inc r0
41955 \end_layout
41956
41957 \begin_layout Standard
41958
41959 \size footnotesize
41960 \InsetSpace ~
41961 \InsetSpace ~
41962 mov @r0,ar3
41963 \end_layout
41964
41965 \begin_layout Standard
41966
41967 \size footnotesize
41968 ; iTemp6 [lr5:16]{_near * int}[r0] = 
41969 \end_layout
41970
41971 \begin_layout Standard
41972
41973 \size footnotesize
41974 ; iTemp6 [lr5:16]{_near * int}[r0] + 
41975 \end_layout
41976
41977 \begin_layout Standard
41978
41979 \size footnotesize
41980 ; 0x2 {short}
41981 \end_layout
41982
41983 \begin_layout Standard
41984
41985 \size footnotesize
41986 \InsetSpace ~
41987 \InsetSpace ~
41988 inc r0
41989 \end_layout
41990
41991 \begin_layout Standard
41992
41993 \size footnotesize
41994 ; goto _whilecontinue_0($1)
41995 \end_layout
41996
41997 \begin_layout Standard
41998
41999 \size footnotesize
42000 \InsetSpace ~
42001 \InsetSpace ~
42002 sjmp 00101$
42003 \end_layout
42004
42005 \begin_layout Standard
42006
42007 \size footnotesize
42008 ; _whilebreak_0($3) :
42009 \end_layout
42010
42011 \begin_layout Standard
42012
42013 \size footnotesize
42014 00103$:
42015 \end_layout
42016
42017 \begin_layout Standard
42018
42019 \size footnotesize
42020 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
42021 \end_layout
42022
42023 \begin_layout Standard
42024
42025 \size footnotesize
42026 \InsetSpace ~
42027 \InsetSpace ~
42028 mov r2,#0x00
42029 \end_layout
42030
42031 \begin_layout Standard
42032
42033 \size footnotesize
42034 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
42035 \end_layout
42036
42037 \begin_layout Standard
42038
42039 \size footnotesize
42040 \InsetSpace ~
42041 \InsetSpace ~
42042 mov r3,#0x00
42043 \end_layout
42044
42045 \begin_layout Standard
42046
42047 \size footnotesize
42048 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
42049 \end_layout
42050
42051 \begin_layout Standard
42052
42053 \size footnotesize
42054 \InsetSpace ~
42055 \InsetSpace ~
42056 mov r4,#0x00
42057 \end_layout
42058
42059 \begin_layout Standard
42060
42061 \size footnotesize
42062 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
42063 \end_layout
42064
42065 \begin_layout Standard
42066
42067 \size footnotesize
42068 \InsetSpace ~
42069 \InsetSpace ~
42070 mov r5,#0x0A
42071 \end_layout
42072
42073 \begin_layout Standard
42074
42075 \size footnotesize
42076 \InsetSpace ~
42077 \InsetSpace ~
42078 mov r6,#0x00
42079 \end_layout
42080
42081 \begin_layout Standard
42082
42083 \size footnotesize
42084 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
42085 \end_layout
42086
42087 \begin_layout Standard
42088
42089 \size footnotesize
42090 \InsetSpace ~
42091 \InsetSpace ~
42092 mov r7,#0x1E
42093 \end_layout
42094
42095 \begin_layout Standard
42096
42097 \size footnotesize
42098 \InsetSpace ~
42099 \InsetSpace ~
42100 mov r0,#0x00
42101 \end_layout
42102
42103 \begin_layout Standard
42104
42105 \size footnotesize
42106 ; _forcond_0($4) :
42107 \end_layout
42108
42109 \begin_layout Standard
42110
42111 \size footnotesize
42112 00104$:
42113 \end_layout
42114
42115 \begin_layout Standard
42116
42117 \size footnotesize
42118 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
42119 \end_layout
42120
42121 \begin_layout Standard
42122
42123 \size footnotesize
42124 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
42125 \end_layout
42126
42127 \begin_layout Standard
42128
42129 \size footnotesize
42130 \InsetSpace ~
42131 \InsetSpace ~
42132 clr c
42133 \end_layout
42134
42135 \begin_layout Standard
42136
42137 \size footnotesize
42138 \InsetSpace ~
42139 \InsetSpace ~
42140 mov a,r4
42141 \end_layout
42142
42143 \begin_layout Standard
42144
42145 \size footnotesize
42146 \InsetSpace ~
42147 \InsetSpace ~
42148 xrl a,#0x80
42149 \end_layout
42150
42151 \begin_layout Standard
42152
42153 \size footnotesize
42154 \InsetSpace ~
42155 \InsetSpace ~
42156 subb a,#0x8a
42157 \end_layout
42158
42159 \begin_layout Standard
42160
42161 \size footnotesize
42162 \InsetSpace ~
42163 \InsetSpace ~
42164 jnc 00107$
42165 \end_layout
42166
42167 \begin_layout Standard
42168
42169 \size footnotesize
42170 00115$:
42171 \end_layout
42172
42173 \begin_layout Standard
42174
42175 \size footnotesize
42176 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
42177 \end_layout
42178
42179 \begin_layout Standard
42180
42181 \size footnotesize
42182 ; iTemp21 [lr21:38]{short}[r4]
42183 \end_layout
42184
42185 \begin_layout Standard
42186
42187 \size footnotesize
42188 \InsetSpace ~
42189 \InsetSpace ~
42190 mov a,r4
42191 \end_layout
42192
42193 \begin_layout Standard
42194
42195 \size footnotesize
42196 \InsetSpace ~
42197 \InsetSpace ~
42198 add a,r2
42199 \end_layout
42200
42201 \begin_layout Standard
42202
42203 \size footnotesize
42204 \InsetSpace ~
42205 \InsetSpace ~
42206 mov r2,a
42207 \end_layout
42208
42209 \begin_layout Standard
42210
42211 \size footnotesize
42212 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
42213 \end_layout
42214
42215 \begin_layout Standard
42216
42217 \size footnotesize
42218 \InsetSpace ~
42219 \InsetSpace ~
42220 mov b,#0x03
42221 \end_layout
42222
42223 \begin_layout Standard
42224
42225 \size footnotesize
42226 \InsetSpace ~
42227 \InsetSpace ~
42228 mov a,r4
42229 \end_layout
42230
42231 \begin_layout Standard
42232
42233 \size footnotesize
42234 \InsetSpace ~
42235 \InsetSpace ~
42236 mul ab
42237 \end_layout
42238
42239 \begin_layout Standard
42240
42241 \size footnotesize
42242 \InsetSpace ~
42243 \InsetSpace ~
42244 mov r1,a
42245 \end_layout
42246
42247 \begin_layout Standard
42248
42249 \size footnotesize
42250 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
42251 \end_layout
42252
42253 \begin_layout Standard
42254
42255 \size footnotesize
42256 ; iTemp15 [lr29:30]{short}[r1]
42257 \end_layout
42258
42259 \begin_layout Standard
42260
42261 \size footnotesize
42262 \InsetSpace ~
42263 \InsetSpace ~
42264 add a,r3
42265 \end_layout
42266
42267 \begin_layout Standard
42268
42269 \size footnotesize
42270 \InsetSpace ~
42271 \InsetSpace ~
42272 mov r3,a
42273 \end_layout
42274
42275 \begin_layout Standard
42276
42277 \size footnotesize
42278 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
42279 \end_layout
42280
42281 \begin_layout Standard
42282
42283 \size footnotesize
42284 \InsetSpace ~
42285 \InsetSpace ~
42286 mov a,r7
42287 \end_layout
42288
42289 \begin_layout Standard
42290
42291 \size footnotesize
42292 \InsetSpace ~
42293 \InsetSpace ~
42294 add a,#0xfd
42295 \end_layout
42296
42297 \begin_layout Standard
42298
42299 \size footnotesize
42300 \InsetSpace ~
42301 \InsetSpace ~
42302 mov r7,a
42303 \end_layout
42304
42305 \begin_layout Standard
42306
42307 \size footnotesize
42308 \InsetSpace ~
42309 \InsetSpace ~
42310 mov a,r0
42311 \end_layout
42312
42313 \begin_layout Standard
42314
42315 \size footnotesize
42316 \InsetSpace ~
42317 \InsetSpace ~
42318 addc a,#0xff
42319 \end_layout
42320
42321 \begin_layout Standard
42322
42323 \size footnotesize
42324 \InsetSpace ~
42325 \InsetSpace ~
42326 mov r0,a
42327 \end_layout
42328
42329 \begin_layout Standard
42330
42331 \size footnotesize
42332 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
42333 \end_layout
42334
42335 \begin_layout Standard
42336
42337 \size footnotesize
42338 \InsetSpace ~
42339 \InsetSpace ~
42340 mov a,r7
42341 \end_layout
42342
42343 \begin_layout Standard
42344
42345 \size footnotesize
42346 \InsetSpace ~
42347 \InsetSpace ~
42348 add a,_gint
42349 \end_layout
42350
42351 \begin_layout Standard
42352
42353 \size footnotesize
42354 \InsetSpace ~
42355 \InsetSpace ~
42356 mov _gint,a
42357 \end_layout
42358
42359 \begin_layout Standard
42360
42361 \size footnotesize
42362 \InsetSpace ~
42363 \InsetSpace ~
42364 mov a,r0
42365 \end_layout
42366
42367 \begin_layout Standard
42368
42369 \size footnotesize
42370 \InsetSpace ~
42371 \InsetSpace ~
42372 addc a,(_gint + 1)
42373 \end_layout
42374
42375 \begin_layout Standard
42376
42377 \size footnotesize
42378 \InsetSpace ~
42379 \InsetSpace ~
42380 mov (_gint + 1),a
42381 \end_layout
42382
42383 \begin_layout Standard
42384
42385 \size footnotesize
42386 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
42387 \end_layout
42388
42389 \begin_layout Standard
42390
42391 \size footnotesize
42392 \InsetSpace ~
42393 \InsetSpace ~
42394 inc r4
42395 \end_layout
42396
42397 \begin_layout Standard
42398
42399 \size footnotesize
42400 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
42401 \end_layout
42402
42403 \begin_layout Standard
42404
42405 \size footnotesize
42406 \InsetSpace ~
42407 \InsetSpace ~
42408 dec r5
42409 \end_layout
42410
42411 \begin_layout Standard
42412
42413 \size footnotesize
42414 \InsetSpace ~
42415 \InsetSpace ~
42416 cjne r5,#0xff,00104$
42417 \end_layout
42418
42419 \begin_layout Standard
42420
42421 \size footnotesize
42422 \InsetSpace ~
42423 \InsetSpace ~
42424 dec r6
42425 \end_layout
42426
42427 \begin_layout Standard
42428
42429 \size footnotesize
42430 ; goto _forcond_0($4)
42431 \end_layout
42432
42433 \begin_layout Standard
42434
42435 \size footnotesize
42436 \InsetSpace ~
42437 \InsetSpace ~
42438 sjmp 00104$
42439 \end_layout
42440
42441 \begin_layout Standard
42442
42443 \size footnotesize
42444 ; _forbreak_0($7) :
42445 \end_layout
42446
42447 \begin_layout Standard
42448
42449 \size footnotesize
42450 00107$:
42451 \end_layout
42452
42453 \begin_layout Standard
42454
42455 \size footnotesize
42456 ; ret iTemp24 [lr40:41]{short}
42457 \end_layout
42458
42459 \begin_layout Standard
42460
42461 \size footnotesize
42462 \InsetSpace ~
42463 \InsetSpace ~
42464 mov a,r3
42465 \end_layout
42466
42467 \begin_layout Standard
42468
42469 \size footnotesize
42470 \InsetSpace ~
42471 \InsetSpace ~
42472 add a,r2
42473 \end_layout
42474
42475 \begin_layout Standard
42476
42477 \size footnotesize
42478 \InsetSpace ~
42479 \InsetSpace ~
42480 mov dpl,a
42481 \end_layout
42482
42483 \begin_layout Standard
42484
42485 \size footnotesize
42486 ; _return($8) :
42487 \end_layout
42488
42489 \begin_layout Standard
42490
42491 \size footnotesize
42492 00108$:
42493 \end_layout
42494
42495 \begin_layout Standard
42496
42497 \size footnotesize
42498 \InsetSpace ~
42499 \InsetSpace ~
42500 ret
42501 \newline
42502
42503 \end_layout
42504
42505 \begin_layout Section
42506 A few words about basic block successors, predecessors and dominators
42507 \end_layout
42508
42509 \begin_layout Standard
42510 Successors are basic blocks
42511 \begin_inset LatexCommand index
42512 name "Basic blocks"
42513
42514 \end_inset
42515
42516  that might execute after this basic block.
42517 \newline
42518 Predecessors are basic blocks
42519  that might execute before reaching this basic block.
42520 \newline
42521 Dominators are basic
42522  blocks that WILL execute before reaching this basic block.
42523 \newline
42524
42525 \end_layout
42526
42527 \begin_layout Standard
42528 [basic block 1]
42529 \end_layout
42530
42531 \begin_layout Standard
42532 if (something)
42533 \end_layout
42534
42535 \begin_layout Standard
42536 \InsetSpace ~
42537 \InsetSpace ~
42538 \InsetSpace ~
42539 \InsetSpace ~
42540 [basic block 2]
42541 \end_layout
42542
42543 \begin_layout Standard
42544 else
42545 \end_layout
42546
42547 \begin_layout Standard
42548 \InsetSpace ~
42549 \InsetSpace ~
42550 \InsetSpace ~
42551 \InsetSpace ~
42552 [basic block 3]
42553 \end_layout
42554
42555 \begin_layout Standard
42556 [basic block 4]
42557 \newline
42558
42559 \end_layout
42560
42561 \begin_layout Standard
42562 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
42563 \end_layout
42564
42565 \begin_layout Standard
42566 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
42567 \end_layout
42568
42569 \begin_layout Standard
42570 c) domVect of [BB4] = BB1 ...
42571  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
42572  was executed.
42573 \end_layout
42574
42575 \begin_layout Chapter
42576 Acknowledgments
42577 \end_layout
42578
42579 \begin_layout Standard
42580 \begin_inset LatexCommand url
42581 target "http://sdcc.sourceforge.net/#Who"
42582
42583 \end_inset
42584
42585
42586 \newline
42587
42588 \newline
42589
42590 \emph on
42591 Thanks to all the other volunteer developers who have helped with coding,
42592  testing, web-page creation, distribution sets, etc.
42593  You know who you are :-)
42594 \emph default
42595
42596 \newline
42597
42598 \newline
42599
42600 \emph on
42601 Thanks to Sourceforge 
42602 \begin_inset LatexCommand url
42603 target "http://www.sf.net"
42604
42605 \end_inset
42606
42607  which has hosted the project since 1999 and donates significant download
42608  bandwidth.
42609 \emph default
42610
42611 \newline
42612
42613 \newline
42614
42615 \emph on
42616 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
42617  cycles and bandwidth for snapshot builds.
42618 \newline
42619
42620 \end_layout
42621
42622 \begin_layout Standard
42623 This document was initially written by Sandeep Dutta
42624 \end_layout
42625
42626 \begin_layout Standard
42627 All product names mentioned herein may be trademarks
42628 \begin_inset LatexCommand index
42629 name "Trademarks"
42630
42631 \end_inset
42632
42633  of their respective companies.
42634  
42635 \end_layout
42636
42637 \begin_layout Section*
42638 Alphabetical index
42639 \end_layout
42640
42641 \begin_layout Standard
42642 To avoid confusion, the installation and building options for SDCC itself
42643  (chapter 2) are not part of the index.
42644 \end_layout
42645
42646 \begin_layout Standard
42647 \begin_inset LatexCommand printindex
42648
42649 \end_inset
42650
42651
42652 \end_layout
42653
42654 \end_body
42655 \end_document