corrected ar title
[fw/sdcc] / doc / sdccman.lyx
1 #LyX 1.5.7 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$ 
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 \end_layout
7086
7087 \begin_layout Subsection
7088 Using ar to Create and Manage Libraries
7089 \begin_inset LatexCommand index
7090 name "ar"
7091
7092 \end_inset
7093
7094
7095 \end_layout
7096
7097 \begin_layout Standard
7098 Support for ar format libraries was introduced in sdcc 2.9.0.
7099  Ar is a standard archive managing utility on unices (Linux, Mac OS X, several
7100  unix flavors) so it is not included in the sdcc package.
7101 \series bold
7102
7103 \newline
7104
7105 \newline
7106
7107 \series default
7108 For Windows platform you can find ar utility in GNU binutils package included
7109  in several projects: Cygwin at 
7110 \begin_inset LatexCommand url
7111 target "http://www.cygwin.com/"
7112
7113 \end_inset
7114
7115 , MinGW at 
7116 \begin_inset LatexCommand url
7117 target "http://www.mingw.org/"
7118
7119 \end_inset
7120
7121 .
7122 \series bold
7123
7124 \newline
7125
7126 \newline
7127
7128 \series default
7129 Both the GNU and BSD ar format variants are suppurated by asxxxx linkers.
7130  Ar doesn't understand the asxxxx object file format, so there is a special
7131  version of ranlib distributed with sdcc, called asranlib, which produces
7132  the ar symbol lookup table.
7133 \series bold
7134
7135 \newline
7136
7137 \newline
7138
7139 \series default
7140 To create a library containing asxxxx object files, you should use the following
7141  sequence:
7142 \series bold
7143
7144 \newline
7145
7146 \end_layout
7147
7148 \begin_layout Standard
7149
7150 \family sans
7151 \series bold
7152 ar -Sq <library name>.lib <list of .rel files>
7153 \end_layout
7154
7155 \begin_layout Standard
7156
7157 \family sans
7158 \series bold
7159 asranlib <library name>.lib
7160 \end_layout
7161
7162 \begin_layout Standard
7163 \begin_inset VSpace bigskip
7164 \end_inset
7165
7166
7167 \end_layout
7168
7169 \begin_layout Section
7170 Command Line Options
7171 \begin_inset LatexCommand index
7172 name "Command Line Options"
7173
7174 \end_inset
7175
7176
7177 \begin_inset LatexCommand label
7178 name "sec:Command-Line-Options"
7179
7180 \end_inset
7181
7182
7183 \end_layout
7184
7185 \begin_layout Subsection
7186 Processor Selection Options
7187 \begin_inset LatexCommand index
7188 name "Options processor selection"
7189
7190 \end_inset
7191
7192
7193 \begin_inset LatexCommand index
7194 name "Processor selection options"
7195
7196 \end_inset
7197
7198
7199 \end_layout
7200
7201 \begin_layout List
7202 \labelwidthstring 00.00.0000
7203
7204 \series bold
7205 -mmcs51
7206 \begin_inset LatexCommand index
7207 name "-mmcs51"
7208
7209 \end_inset
7210
7211
7212 \series default
7213  Generate code for the Intel MCS51
7214 \begin_inset LatexCommand index
7215 name "MCS51"
7216
7217 \end_inset
7218
7219  family of processors.
7220  This is the default processor target.
7221 \end_layout
7222
7223 \begin_layout List
7224 \labelwidthstring 00.00.0000
7225
7226 \series bold
7227 -mds390
7228 \begin_inset LatexCommand index
7229 name "-mds390"
7230
7231 \end_inset
7232
7233
7234 \series default
7235  Generate code for the Dallas DS80C390
7236 \begin_inset LatexCommand index
7237 name "DS80C390"
7238
7239 \end_inset
7240
7241  processor.
7242 \end_layout
7243
7244 \begin_layout List
7245 \labelwidthstring 00.00.0000
7246
7247 \series bold
7248 -mds400
7249 \begin_inset LatexCommand index
7250 name "-mds400"
7251
7252 \end_inset
7253
7254
7255 \series default
7256  Generate code for the Dallas DS80C400
7257 \begin_inset LatexCommand index
7258 name "DS80C400"
7259
7260 \end_inset
7261
7262  processor.
7263 \end_layout
7264
7265 \begin_layout List
7266 \labelwidthstring 00.00.0000
7267
7268 \series bold
7269 -mhc08
7270 \begin_inset LatexCommand index
7271 name "-mhc08"
7272
7273 \end_inset
7274
7275
7276 \series default
7277  Generate code for the Freescale/Motorola HC08
7278 \begin_inset LatexCommand index
7279 name "HC08"
7280
7281 \end_inset
7282
7283  family of processors.
7284 \end_layout
7285
7286 \begin_layout List
7287 \labelwidthstring 00.00.0000
7288
7289 \series bold
7290 -mz80
7291 \begin_inset LatexCommand index
7292 name "-mz80"
7293
7294 \end_inset
7295
7296
7297 \series default
7298  Generate code for the Zilog Z80
7299 \begin_inset LatexCommand index
7300 name "Z80"
7301
7302 \end_inset
7303
7304  family of processors.
7305 \end_layout
7306
7307 \begin_layout List
7308 \labelwidthstring 00.00.0000
7309
7310 \series bold
7311 -mgbz80
7312 \begin_inset LatexCommand index
7313 name "-mgbz80"
7314
7315 \end_inset
7316
7317
7318 \series default
7319  Generate code for the GameBoy Z80
7320 \begin_inset LatexCommand index
7321 name "gbz80 (GameBoy Z80)"
7322
7323 \end_inset
7324
7325  processor (Not actively maintained).
7326 \end_layout
7327
7328 \begin_layout List
7329 \labelwidthstring 00.00.0000
7330
7331 \series bold
7332 -mavr
7333 \begin_inset LatexCommand index
7334 name "-mavr"
7335
7336 \end_inset
7337
7338
7339 \series default
7340  Generate code for the Atmel AVR
7341 \begin_inset LatexCommand index
7342 name "AVR"
7343
7344 \end_inset
7345
7346  processor (Not maintained, not complete).
7347  AVR users should probably have a look at winavr 
7348 \begin_inset LatexCommand url
7349 target "http://sourceforge.net/projects/winavr"
7350
7351 \end_inset
7352
7353  or 
7354 \begin_inset LatexCommand url
7355 target "http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index"
7356
7357 \end_inset
7358
7359 , which is based on AVR-port of the gcc compiler.
7360 \end_layout
7361
7362 \begin_layout Standard
7363 \begin_inset Note Note
7364 status collapsed
7365
7366 \begin_layout Standard
7367 I think it is fair to direct users there for now.
7368  Open source is also about avoiding unnecessary work .
7369  But I didn't find the 'official' link.
7370 \end_layout
7371
7372 \end_inset
7373
7374
7375 \end_layout
7376
7377 \begin_layout List
7378 \labelwidthstring 00.00.0000
7379
7380 \series bold
7381 -mpic14
7382 \begin_inset LatexCommand index
7383 name "-mpic14"
7384
7385 \end_inset
7386
7387
7388 \series default
7389  Generate code for the Microchip PIC 14
7390 \begin_inset LatexCommand index
7391 name "PIC14"
7392
7393 \end_inset
7394
7395 -bit processors (p16f84 and variants.
7396  In development, not complete).
7397 \end_layout
7398
7399 \begin_layout Standard
7400 \begin_inset Note Note
7401 status collapsed
7402
7403 \begin_layout Standard
7404 p16f627 p16f628 p16f84 p16f873 p16f877?
7405 \end_layout
7406
7407 \end_inset
7408
7409
7410 \end_layout
7411
7412 \begin_layout List
7413 \labelwidthstring 00.00.0000
7414
7415 \series bold
7416 -mpic16
7417 \begin_inset LatexCommand index
7418 name "-mpic16"
7419
7420 \end_inset
7421
7422
7423 \series default
7424  Generate code for the Microchip PIC 16
7425 \begin_inset LatexCommand index
7426 name "PIC16"
7427
7428 \end_inset
7429
7430 -bit processors (p18f452 and variants.
7431  In development, not complete).
7432 \end_layout
7433
7434 \begin_layout List
7435 \labelwidthstring 00.00.0000
7436
7437 \series bold
7438 -mtlcs900h
7439 \series default
7440  Generate code for the Toshiba TLCS-900H
7441 \begin_inset LatexCommand index
7442 name "TLCS-900H"
7443
7444 \end_inset
7445
7446  processor (Not maintained, not complete).
7447 \end_layout
7448
7449 \begin_layout List
7450 \labelwidthstring 00.00.0000
7451
7452 \series bold
7453 -mxa51
7454 \begin_inset LatexCommand index
7455 name "-mxa51"
7456
7457 \end_inset
7458
7459
7460 \series default
7461  Generate code for the Phillips XA51
7462 \begin_inset LatexCommand index
7463 name "XA51"
7464
7465 \end_inset
7466
7467  processor (Not maintained, not complete).
7468 \end_layout
7469
7470 \begin_layout Standard
7471 \begin_inset VSpace bigskip
7472 \end_inset
7473
7474
7475 \end_layout
7476
7477 \begin_layout Subsection
7478 Preprocessor Options
7479 \begin_inset LatexCommand index
7480 name "Options preprocessor"
7481
7482 \end_inset
7483
7484
7485 \begin_inset LatexCommand index
7486 name "Preprocessor options"
7487
7488 \end_inset
7489
7490
7491 \begin_inset LatexCommand index
7492 name "sdcpp (preprocessor)"
7493
7494 \end_inset
7495
7496
7497 \end_layout
7498
7499 \begin_layout List
7500 \labelwidthstring 00.00.0000
7501
7502 \series bold
7503 -I<path>
7504 \begin_inset LatexCommand index
7505 name "-I<path>"
7506
7507 \end_inset
7508
7509
7510 \series default
7511  The additional location where the preprocessor will look for <..h> or 
7512 \begin_inset Quotes eld
7513 \end_inset
7514
7515 ..h
7516 \begin_inset Quotes erd
7517 \end_inset
7518
7519  files.
7520 \end_layout
7521
7522 \begin_layout List
7523 \labelwidthstring 00.00.0000
7524
7525 \series bold
7526 -D<macro[=value]>
7527 \begin_inset LatexCommand index
7528 name "-D<macro[=value]>"
7529
7530 \end_inset
7531
7532
7533 \series default
7534  Command line definition of macros.
7535  Passed to the preprocessor.
7536 \end_layout
7537
7538 \begin_layout List
7539 \labelwidthstring 00.00.0000
7540
7541 \series bold
7542 -M
7543 \begin_inset LatexCommand index
7544 name "-M"
7545
7546 \end_inset
7547
7548
7549 \series default
7550  Tell the preprocessor to output a rule suitable for make describing the
7551  dependencies of each object file.
7552  For each source file, the preprocessor outputs one make-rule whose target
7553  is the object file name for that source file and whose dependencies are
7554  all the files `#include'd in it.
7555  This rule may be a single line or may be continued with `
7556 \backslash
7557 '-newline if it is long.
7558  The list of rules is printed on standard output instead of the preprocessed
7559  C program.
7560  `-M' implies `-E
7561 \begin_inset LatexCommand index
7562 name "-E"
7563
7564 \end_inset
7565
7566 '.
7567 \end_layout
7568
7569 \begin_layout List
7570 \labelwidthstring 00.00.0000
7571
7572 \series bold
7573 -C
7574 \begin_inset LatexCommand index
7575 name "-C"
7576
7577 \end_inset
7578
7579
7580 \series default
7581  Tell the preprocessor not to discard comments.
7582  Used with the `-E' option.
7583 \end_layout
7584
7585 \begin_layout List
7586 \labelwidthstring 00.00.0000
7587
7588 \series bold
7589 -MM
7590 \begin_inset LatexCommand index
7591 name "-MM"
7592
7593 \end_inset
7594
7595
7596 \series default
7597 \size large
7598  
7599 \size default
7600 Like `-M' but the output mentions only the user header files included with
7601  `#include 
7602 \begin_inset Quotes eld
7603 \end_inset
7604
7605 file"'.
7606  System header files included with `#include <file>' are omitted.
7607 \end_layout
7608
7609 \begin_layout List
7610 \labelwidthstring 00.00.0000
7611
7612 \series bold
7613 -Aquestion(answer)
7614 \begin_inset LatexCommand index
7615 name "-Aquestion(answer)"
7616
7617 \end_inset
7618
7619
7620 \series default
7621  Assert the answer answer for question, in case it is tested with a preprocessor
7622  conditional such as `#if #question(answer)'.
7623  `-A-' disables the standard assertions that normally describe the target
7624  machine.
7625 \end_layout
7626
7627 \begin_layout List
7628 \labelwidthstring 00.00.0000
7629
7630 \series bold
7631 -Umacro
7632 \begin_inset LatexCommand index
7633 name "-Umacro"
7634
7635 \end_inset
7636
7637
7638 \series default
7639  Undefine macro macro.
7640  `-U' options are evaluated after all `-D' options, but before any `-include'
7641  and `-imacros' options.
7642 \end_layout
7643
7644 \begin_layout List
7645 \labelwidthstring 00.00.0000
7646
7647 \series bold
7648 -dM
7649 \begin_inset LatexCommand index
7650 name "-dM"
7651
7652 \end_inset
7653
7654
7655 \series default
7656  Tell the preprocessor to output only a list of the macro definitions that
7657  are in effect at the end of preprocessing.
7658  Used with the `-E' option.
7659 \end_layout
7660
7661 \begin_layout List
7662 \labelwidthstring 00.00.0000
7663
7664 \series bold
7665 -dD
7666 \begin_inset LatexCommand index
7667 name "-dD"
7668
7669 \end_inset
7670
7671
7672 \series default
7673  Tell the preprocessor to pass all macro definitions into the output, in
7674  their proper sequence in the rest of the output.
7675 \end_layout
7676
7677 \begin_layout List
7678 \labelwidthstring 00.00.0000
7679
7680 \series bold
7681 -dN
7682 \begin_inset LatexCommand index
7683 name "-dN"
7684
7685 \end_inset
7686
7687
7688 \series default
7689 \size large
7690  
7691 \size default
7692 Like `-dD' except that the macro arguments and contents are omitted.
7693  Only `#define name' is included in the output.
7694 \end_layout
7695
7696 \begin_layout List
7697 \labelwidthstring 00.00.0000
7698
7699 \series bold
7700 -pedantic-parse-number
7701 \begin_inset LatexCommand index
7702 name "pedantic"
7703
7704 \end_inset
7705
7706
7707 \begin_inset LatexCommand index
7708 name "-pedantic-parse-number"
7709
7710 \end_inset
7711
7712
7713 \size large
7714 \bar under
7715
7716 \begin_inset LatexCommand label
7717 name "lyx:-pedantic-parse-number"
7718
7719 \end_inset
7720
7721
7722 \series default
7723 \bar default
7724  
7725 \size default
7726 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
7727  and the macro LO_B(3) gets expanded.
7728  See also #pragma pedantic_parse_number 
7729 \begin_inset LatexCommand vpageref
7730 reference "ite:pedantic_parse_number"
7731
7732 \end_inset
7733
7734  in section
7735 \begin_inset LatexCommand ref
7736 reference "sec:Pragmas"
7737
7738 \end_inset
7739
7740  
7741 \emph on
7742 Note: this functionality is not in conformance with C99 standard!
7743 \end_layout
7744
7745 \begin_layout List
7746 \labelwidthstring 00.00.0000
7747
7748 \series bold
7749 -Wp\InsetSpace ~
7750 preprocessorOption[,preprocessorOption]
7751 \series default
7752
7753 \begin_inset LatexCommand index
7754 name "-Wp preprocessorOption[,preprocessorOption]"
7755
7756 \end_inset
7757
7758 ...
7759  Pass the preprocessorOption to the preprocessor 
7760 \family typewriter
7761 sdcpp
7762 \family default
7763
7764 \begin_inset LatexCommand index
7765 name "sdcpp (preprocessor)"
7766
7767 \end_inset
7768
7769 .
7770  SDCC uses an adapted version of the preprocessor 
7771 \emph on
7772 cpp
7773 \emph default
7774  of the GNU Compiler Collection
7775 \begin_inset LatexCommand index
7776 name "gcc (GNU Compiler Collection)"
7777
7778 \end_inset
7779
7780  (
7781 \emph on
7782 gcc
7783 \emph default
7784  
7785 \begin_inset LatexCommand url
7786 target "http://gcc.gnu.org/"
7787
7788 \end_inset
7789
7790 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7791 4.1.1\InsetSpace ~
7792 CPP\InsetSpace ~
7793 Manual
7794  at 
7795 \begin_inset LatexCommand htmlurl
7796 target "http://www.gnu.org/software/gcc/onlinedocs/"
7797
7798 \end_inset
7799
7800 .
7801 \end_layout
7802
7803 \begin_layout Standard
7804 \begin_inset VSpace bigskip
7805 \end_inset
7806
7807
7808 \end_layout
7809
7810 \begin_layout Subsection
7811 Linker Options
7812 \begin_inset LatexCommand index
7813 name "Options linker"
7814
7815 \end_inset
7816
7817
7818 \begin_inset LatexCommand index
7819 name "Linker options"
7820
7821 \end_inset
7822
7823
7824 \end_layout
7825
7826 \begin_layout List
7827 \labelwidthstring 00.00.0000
7828
7829 \series bold
7830 -L\InsetSpace ~
7831 -
7832 \series default
7833
7834 \begin_inset ERT
7835 status collapsed
7836
7837 \begin_layout Standard
7838
7839
7840 \backslash
7841 /
7842 \end_layout
7843
7844 \end_inset
7845
7846
7847 \series bold
7848 -lib-path
7849 \begin_inset LatexCommand index
7850 name "-\\/-lib-path <path>"
7851
7852 \end_inset
7853
7854
7855 \begin_inset LatexCommand index
7856 name "-L -\\/-lib-path"
7857
7858 \end_inset
7859
7860
7861 \series default
7862 \InsetSpace ~
7863 <absolute path to additional libraries> This option is passed to the linkage
7864  editor's additional libraries
7865 \begin_inset LatexCommand index
7866 name "Libraries"
7867
7868 \end_inset
7869
7870  search path.
7871  The path name must be absolute.
7872  Additional library files may be specified in the command line.
7873  See section Compiling programs for more details.
7874 \end_layout
7875
7876 \begin_layout List
7877 \labelwidthstring 00.00.0000
7878
7879 \series bold
7880 -
7881 \begin_inset ERT
7882 status collapsed
7883
7884 \begin_layout Standard
7885
7886
7887 \backslash
7888 /
7889 \end_layout
7890
7891 \end_inset
7892
7893 -xram-loc
7894 \series default
7895
7896 \begin_inset LatexCommand index
7897 name "-\\/-xram-loc <Value>"
7898
7899 \end_inset
7900
7901 \InsetSpace ~
7902 <Value> The start location of the external ram
7903 \begin_inset LatexCommand index
7904 name "xdata (mcs51, ds390 storage class)"
7905
7906 \end_inset
7907
7908 , default value is 0.
7909  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7910 \begin_inset ERT
7911 status collapsed
7912
7913 \begin_layout Standard
7914
7915
7916 \backslash
7917 /
7918 \end_layout
7919
7920 \end_inset
7921
7922 -xram-loc 0x8000 or -
7923 \begin_inset ERT
7924 status collapsed
7925
7926 \begin_layout Standard
7927
7928
7929 \backslash
7930 /
7931 \end_layout
7932
7933 \end_inset
7934
7935 -xram-loc 32768.
7936 \end_layout
7937
7938 \begin_layout List
7939 \labelwidthstring 00.00.0000
7940
7941 \series bold
7942 -
7943 \begin_inset ERT
7944 status collapsed
7945
7946 \begin_layout Standard
7947
7948
7949 \backslash
7950 /
7951 \end_layout
7952
7953 \end_inset
7954
7955 -code-loc
7956 \series default
7957
7958 \begin_inset LatexCommand index
7959 name "-\\/-code-loc <Value>"
7960
7961 \end_inset
7962
7963 \InsetSpace ~
7964 <Value> The start location of the code
7965 \begin_inset LatexCommand index
7966 name "code"
7967
7968 \end_inset
7969
7970  segment, default value 0.
7971  Note when this option is used the interrupt vector table
7972 \begin_inset LatexCommand index
7973 name "interrupt vector table"
7974
7975 \end_inset
7976
7977  is also relocated to the given address.
7978  The value entered can be in Hexadecimal or Decimal format, e.g.: -
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 -code-loc 0x8000 or -
7992 \begin_inset ERT
7993 status collapsed
7994
7995 \begin_layout Standard
7996
7997
7998 \backslash
7999 /
8000 \end_layout
8001
8002 \end_inset
8003
8004 -code-loc 32768.
8005 \end_layout
8006
8007 \begin_layout List
8008 \labelwidthstring 00.00.0000
8009
8010 \series bold
8011 -
8012 \begin_inset ERT
8013 status collapsed
8014
8015 \begin_layout Standard
8016
8017
8018 \backslash
8019 /
8020 \end_layout
8021
8022 \end_inset
8023
8024 -stack-loc
8025 \series default
8026
8027 \begin_inset LatexCommand index
8028 name "-\\/-stack-loc <Value>"
8029
8030 \end_inset
8031
8032 \InsetSpace ~
8033 <Value> By default the stack
8034 \begin_inset LatexCommand index
8035 name "stack"
8036
8037 \end_inset
8038
8039  is placed after the data segment.
8040  Using this option the stack can be placed anywhere in the internal memory
8041  space of the 8051.
8042  The value entered can be in Hexadecimal or Decimal format, e.g.
8043  -
8044 \begin_inset ERT
8045 status collapsed
8046
8047 \begin_layout Standard
8048
8049
8050 \backslash
8051 /
8052 \end_layout
8053
8054 \end_inset
8055
8056 -stack-loc 0x20 or -
8057 \begin_inset ERT
8058 status collapsed
8059
8060 \begin_layout Standard
8061
8062
8063 \backslash
8064 /
8065 \end_layout
8066
8067 \end_inset
8068
8069 -stack-loc 32.
8070  Since the sp register is incremented before a push or call, the initial
8071  sp will be set to one byte prior the provided value.
8072  The provided value should not overlap any other memory areas such as used
8073  register banks or the data segment and with enough space for the current
8074  application.
8075  The 
8076 \series bold
8077 -
8078 \begin_inset ERT
8079 status collapsed
8080
8081 \begin_layout Standard
8082
8083
8084 \backslash
8085 /
8086 \end_layout
8087
8088 \end_inset
8089
8090 -pack-iram
8091 \series default
8092 \InsetSpace ~
8093
8094 \begin_inset LatexCommand index
8095 name "-\\/-pack-iram"
8096
8097 \end_inset
8098
8099  option (which is now a default setting) will override this setting, so
8100  you should also specify the 
8101 \series bold
8102 -
8103 \begin_inset ERT
8104 status collapsed
8105
8106 \begin_layout Standard
8107
8108
8109 \backslash
8110 /
8111 \end_layout
8112
8113 \end_inset
8114
8115 -no-pack-iram
8116 \series default
8117 \InsetSpace ~
8118
8119 \begin_inset LatexCommand index
8120 name "-\\/-no-pack-iram"
8121
8122 \end_inset
8123
8124  option if you need to manually place the stack.
8125 \end_layout
8126
8127 \begin_layout List
8128 \labelwidthstring 00.00.0000
8129
8130 \series bold
8131 -
8132 \begin_inset ERT
8133 status collapsed
8134
8135 \begin_layout Standard
8136
8137
8138 \backslash
8139 /
8140 \end_layout
8141
8142 \end_inset
8143
8144 -xstack-loc
8145 \series default
8146
8147 \begin_inset LatexCommand index
8148 name "-\\/-xstack-loc <Value>"
8149
8150 \end_inset
8151
8152 \InsetSpace ~
8153 <Value> By default the external stack
8154 \begin_inset LatexCommand index
8155 name "xstack"
8156
8157 \end_inset
8158
8159  is placed after the pdata
8160 \begin_inset LatexCommand index
8161 name "pdata (mcs51, ds390 storage class)"
8162
8163 \end_inset
8164
8165  segment.
8166  Using this option the xstack can be placed anywhere in the external memory
8167  space of the 8051.
8168  The value entered can be in Hexadecimal or Decimal format, e.g.
8169  -
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 -xstack-loc 0x8000 or -
8183 \begin_inset ERT
8184 status collapsed
8185
8186 \begin_layout Standard
8187
8188
8189 \backslash
8190 /
8191 \end_layout
8192
8193 \end_inset
8194
8195 -stack-loc 32768.
8196  The provided value should not overlap any other memory areas such as the
8197  pdata or xdata segment and with enough space for the current application.
8198 \end_layout
8199
8200 \begin_layout List
8201 \labelwidthstring 00.00.0000
8202
8203 \series bold
8204 -
8205 \begin_inset ERT
8206 status collapsed
8207
8208 \begin_layout Standard
8209
8210
8211 \backslash
8212 /
8213 \end_layout
8214
8215 \end_inset
8216
8217 -data-loc
8218 \series default
8219
8220 \begin_inset LatexCommand index
8221 name "-\\/-data-loc <Value>"
8222
8223 \end_inset
8224
8225 \InsetSpace ~
8226 <Value> The start location of the internal ram data
8227 \begin_inset LatexCommand index
8228 name "data (mcs51, ds390 storage class)"
8229
8230 \end_inset
8231
8232  segment.
8233  The value entered can be in Hexadecimal or Decimal format, eg.
8234  -
8235 \begin_inset ERT
8236 status collapsed
8237
8238 \begin_layout Standard
8239
8240
8241 \backslash
8242 /
8243 \end_layout
8244
8245 \end_inset
8246
8247 -data-loc 0x20 or -
8248 \begin_inset ERT
8249 status collapsed
8250
8251 \begin_layout Standard
8252
8253
8254 \backslash
8255 /
8256 \end_layout
8257
8258 \end_inset
8259
8260 -data-loc 32.
8261  (By default, the start location of the internal ram data segment  is set
8262  as low as possible in memory, taking into account the used register banks
8263  and the bit segment at address 0x20.
8264  For example if register banks 0 and 1 are used without bit variables, the
8265  data segment will be set, if -
8266 \begin_inset ERT
8267 status collapsed
8268
8269 \begin_layout Standard
8270
8271
8272 \backslash
8273 /
8274 \end_layout
8275
8276 \end_inset
8277
8278 -data-loc is not used, to location 0x10.)
8279 \end_layout
8280
8281 \begin_layout List
8282 \labelwidthstring 00.00.0000
8283
8284 \series bold
8285 -
8286 \begin_inset ERT
8287 status collapsed
8288
8289 \begin_layout Standard
8290
8291
8292 \backslash
8293 /
8294 \end_layout
8295
8296 \end_inset
8297
8298 -idata-loc
8299 \series default
8300
8301 \begin_inset LatexCommand index
8302 name "-\\/-idata-loc <Value>"
8303
8304 \end_inset
8305
8306 \InsetSpace ~
8307 <Value> The start location of the indirectly addressable internal ram
8308 \begin_inset LatexCommand index
8309 name "idata (mcs51, ds390 storage class)"
8310
8311 \end_inset
8312
8313  of the 8051, default value is 0x80.
8314  The value entered can be in Hexadecimal or Decimal format, eg.
8315  -
8316 \begin_inset ERT
8317 status collapsed
8318
8319 \begin_layout Standard
8320
8321
8322 \backslash
8323 /
8324 \end_layout
8325
8326 \end_inset
8327
8328 -idata-loc 0x88 or -
8329 \begin_inset ERT
8330 status collapsed
8331
8332 \begin_layout Standard
8333
8334
8335 \backslash
8336 /
8337 \end_layout
8338
8339 \end_inset
8340
8341 -idata-loc 136.
8342 \end_layout
8343
8344 \begin_layout List
8345 \labelwidthstring 00.00.0000
8346
8347 \series bold
8348 -
8349 \begin_inset ERT
8350 status collapsed
8351
8352 \begin_layout Standard
8353
8354
8355 \backslash
8356 /
8357 \end_layout
8358
8359 \end_inset
8360
8361 -bit-loc
8362 \series default
8363 \InsetSpace ~
8364 <Value> The start location of the bit
8365 \begin_inset LatexCommand index
8366 name "bit"
8367
8368 \end_inset
8369
8370  addressable internal ram of the 8051.
8371  This is 
8372 \emph on
8373 not
8374 \emph default
8375  implemented yet.
8376  Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
8377 -bBSEG=<Value>.
8378 \end_layout
8379
8380 \begin_layout List
8381 \labelwidthstring 00.00.0000
8382
8383 \series bold
8384 -
8385 \begin_inset ERT
8386 status collapsed
8387
8388 \begin_layout Standard
8389
8390
8391 \backslash
8392 /
8393 \end_layout
8394
8395 \end_inset
8396
8397 -out-fmt-ihx
8398 \begin_inset LatexCommand index
8399 name "-\\/-out-fmt-ihx"
8400
8401 \end_inset
8402
8403  
8404 \series default
8405 The linker output (final object code) is in Intel Hex format.
8406 \begin_inset LatexCommand index
8407 name "Intel hex format"
8408
8409 \end_inset
8410
8411  This is the default option.
8412  The format itself is documented in the documentation of srecord
8413 \begin_inset LatexCommand index
8414 name "srecord (bin, hex, ... tool)"
8415
8416 \end_inset
8417
8418 .
8419 \end_layout
8420
8421 \begin_layout List
8422 \labelwidthstring 00.00.0000
8423
8424 \series bold
8425 -
8426 \begin_inset ERT
8427 status collapsed
8428
8429 \begin_layout Standard
8430
8431
8432 \backslash
8433 /
8434 \end_layout
8435
8436 \end_inset
8437
8438 -out-fmt-s19
8439 \begin_inset LatexCommand index
8440 name "-\\/-out-fmt-s19"
8441
8442 \end_inset
8443
8444  
8445 \series default
8446 The linker output (final object code) is in Motorola S19 format
8447 \begin_inset LatexCommand index
8448 name "Motorola S19 format"
8449
8450 \end_inset
8451
8452 .
8453  The format itself is documented in the documentation of srecord.
8454 \end_layout
8455
8456 \begin_layout List
8457 \labelwidthstring 00.00.0000
8458
8459 \series bold
8460 -
8461 \begin_inset ERT
8462 status collapsed
8463
8464 \begin_layout Standard
8465
8466
8467 \backslash
8468 /
8469 \end_layout
8470
8471 \end_inset
8472
8473 -out-fmt-elf
8474 \begin_inset LatexCommand index
8475 name "-\\/-out-fmt-s19"
8476
8477 \end_inset
8478
8479
8480 \begin_inset LatexCommand index
8481 name "HC08!Options!-\\/-out-fmt-elf"
8482
8483 \end_inset
8484
8485  
8486 \series default
8487 The linker output (final object code) is in ELF format
8488 \begin_inset LatexCommand index
8489 name "ELF format"
8490
8491 \end_inset
8492
8493 .
8494  (Currently only supported for the HC08
8495 \begin_inset LatexCommand index
8496 name "HC08"
8497
8498 \end_inset
8499
8500  processors)
8501 \end_layout
8502
8503 \begin_layout List
8504 \labelwidthstring 00.00.0000
8505
8506 \series bold
8507 -Wl\InsetSpace ~
8508 linkOption[,linkOption]
8509 \series default
8510
8511 \begin_inset LatexCommand index
8512 name "-Wl linkOption[,linkOption]"
8513
8514 \end_inset
8515
8516
8517 \begin_inset LatexCommand label
8518 name "lyx:-Wl option"
8519
8520 \end_inset
8521
8522 ...
8523  Pass the linkOption to the linker.
8524  If a bootloader is used an option like 
8525 \begin_inset Quotes sld
8526 \end_inset
8527
8528 -Wl\InsetSpace ~
8529 -bCSEG=0x1000
8530 \begin_inset Quotes srd
8531 \end_inset
8532
8533  would be typical to set the start of the code segment.
8534  Either use the double quotes around this option or use no space (e.g.
8535  -Wl-bCSEG=0x1000).
8536  See also #pragma constseg and #pragma codeseg in section 
8537 \begin_inset LatexCommand ref
8538 reference "sec:Pragmas"
8539
8540 \end_inset
8541
8542  .
8543  File sdcc/as/doc/asxhtm.html has more on linker options.
8544 \end_layout
8545
8546 \begin_layout Standard
8547 \begin_inset VSpace bigskip
8548 \end_inset
8549
8550
8551 \end_layout
8552
8553 \begin_layout Subsection
8554 MCS51 Options
8555 \begin_inset LatexCommand index
8556 name "Options MCS51"
8557
8558 \end_inset
8559
8560
8561 \begin_inset LatexCommand index
8562 name "MCS51 options"
8563
8564 \end_inset
8565
8566
8567 \end_layout
8568
8569 \begin_layout List
8570 \labelwidthstring 00.00.0000
8571
8572 \series bold
8573 -
8574 \begin_inset ERT
8575 status collapsed
8576
8577 \begin_layout Standard
8578
8579
8580 \backslash
8581 /
8582 \end_layout
8583
8584 \end_inset
8585
8586 -model-small
8587 \begin_inset LatexCommand index
8588 name "-\\/-model-small"
8589
8590 \end_inset
8591
8592
8593 \series default
8594 \size large
8595  
8596 \size default
8597 Generate code for Small Model programs, see section Memory Models for more
8598  details.
8599  This is the default model.
8600 \end_layout
8601
8602 \begin_layout List
8603 \labelwidthstring 00.00.0000
8604
8605 \series bold
8606 -
8607 \begin_inset ERT
8608 status collapsed
8609
8610 \begin_layout Standard
8611
8612
8613 \backslash
8614 /
8615 \end_layout
8616
8617 \end_inset
8618
8619 -model-medium
8620 \begin_inset LatexCommand index
8621 name "-\\/-model-medium"
8622
8623 \end_inset
8624
8625
8626 \series default
8627  Generate code for Medium model programs, see section Memory Models for
8628  more details.
8629  If this option is used all source files in the project have to be compiled
8630  with this option.
8631  It must also be used when invoking the linker.
8632 \end_layout
8633
8634 \begin_layout List
8635 \labelwidthstring 00.00.0000
8636
8637 \series bold
8638 -
8639 \begin_inset ERT
8640 status collapsed
8641
8642 \begin_layout Standard
8643
8644
8645 \backslash
8646 /
8647 \end_layout
8648
8649 \end_inset
8650
8651 -model-large
8652 \begin_inset LatexCommand index
8653 name "-\\/-model-large"
8654
8655 \end_inset
8656
8657
8658 \series default
8659  Generate code for Large model programs, see section Memory Models for more
8660  details.
8661  If this option is used all source files in the project have to be compiled
8662  with this option.
8663  It must also be used when invoking the linker.
8664 \end_layout
8665
8666 \begin_layout List
8667 \labelwidthstring 00.00.0000
8668
8669 \series bold
8670 -
8671 \begin_inset ERT
8672 status collapsed
8673
8674 \begin_layout Standard
8675
8676
8677 \backslash
8678 /
8679 \end_layout
8680
8681 \end_inset
8682
8683 -xstack
8684 \begin_inset LatexCommand index
8685 name "-\\/-xstack"
8686
8687 \end_inset
8688
8689
8690 \series default
8691  Uses a pseudo stack in the pdata
8692 \begin_inset LatexCommand index
8693 name "pdata (mcs51, ds390 storage class)"
8694
8695 \end_inset
8696
8697  area (usually the first 256 bytes in the external ram) for allocating variables
8698  and passing parameters.
8699  See section 
8700 \begin_inset LatexCommand ref
8701 reference "sub:External-Stack"
8702
8703 \end_inset
8704
8705 \InsetSpace ~
8706  External Stack for more details.
8707 \end_layout
8708
8709 \begin_layout List
8710 \labelwidthstring 00.00.0000
8711
8712 \series bold
8713 -
8714 \begin_inset ERT
8715 status collapsed
8716
8717 \begin_layout Standard
8718
8719
8720 \backslash
8721 /
8722 \end_layout
8723
8724 \end_inset
8725
8726 -iram-size
8727 \series default
8728 \InsetSpace ~
8729 <Value>
8730 \begin_inset LatexCommand index
8731 name "-\\/-iram-size <Value>"
8732
8733 \end_inset
8734
8735  Causes the linker to check if the internal ram usage is within limits of
8736  the given value.
8737 \end_layout
8738
8739 \begin_layout List
8740 \labelwidthstring 00.00.0000
8741
8742 \series bold
8743 -
8744 \begin_inset ERT
8745 status collapsed
8746
8747 \begin_layout Standard
8748
8749
8750 \backslash
8751 /
8752 \end_layout
8753
8754 \end_inset
8755
8756 -xram-size
8757 \series default
8758 \InsetSpace ~
8759 <Value>
8760 \begin_inset LatexCommand index
8761 name "-\\/-xram-size <Value>"
8762
8763 \end_inset
8764
8765  Causes the linker to check if the external ram usage is within limits of
8766  the given value.
8767 \end_layout
8768
8769 \begin_layout List
8770 \labelwidthstring 00.00.0000
8771
8772 \series bold
8773 -
8774 \begin_inset ERT
8775 status collapsed
8776
8777 \begin_layout Standard
8778
8779
8780 \backslash
8781 /
8782 \end_layout
8783
8784 \end_inset
8785
8786 -code-size
8787 \series default
8788 \InsetSpace ~
8789 <Value>
8790 \begin_inset LatexCommand index
8791 name "-\\/-code-size <Value>"
8792
8793 \end_inset
8794
8795  Causes the linker to check if the code memory usage is within limits of
8796  the given value.
8797 \end_layout
8798
8799 \begin_layout List
8800 \labelwidthstring 00.00.0000
8801
8802 \series bold
8803 -
8804 \begin_inset ERT
8805 status collapsed
8806
8807 \begin_layout Standard
8808
8809
8810 \backslash
8811 /
8812 \end_layout
8813
8814 \end_inset
8815
8816 -stack-size
8817 \series default
8818 \InsetSpace ~
8819 <Value>
8820 \begin_inset LatexCommand index
8821 name "-\\/-stack-size <Value>"
8822
8823 \end_inset
8824
8825  Causes the linker to check if there is at minimum <Value> bytes for stack.
8826 \end_layout
8827
8828 \begin_layout List
8829 \labelwidthstring 00.00.0000
8830
8831 \series bold
8832 -
8833 \begin_inset ERT
8834 status collapsed
8835
8836 \begin_layout Standard
8837
8838
8839 \backslash
8840 /
8841 \end_layout
8842
8843 \end_inset
8844
8845 -pack-iram
8846 \series default
8847 \InsetSpace ~
8848
8849 \begin_inset LatexCommand index
8850 name "-\\/-pack-iram"
8851
8852 \end_inset
8853
8854  Causes the linker to use unused register banks for data variables and pack
8855  data, idata and stack together.
8856  This is the default now.
8857 \end_layout
8858
8859 \begin_layout List
8860 \labelwidthstring 00.00.0000
8861
8862 \series bold
8863 -
8864 \begin_inset ERT
8865 status collapsed
8866
8867 \begin_layout Standard
8868
8869
8870 \backslash
8871 /
8872 \end_layout
8873
8874 \end_inset
8875
8876 -no-pack-iram
8877 \series default
8878 \InsetSpace ~
8879
8880 \begin_inset LatexCommand index
8881 name "-\\/-no-pack-iram"
8882
8883 \end_inset
8884
8885  Causes the linker to use old style for allocating memory areas.
8886 \end_layout
8887
8888 \begin_layout List
8889 \labelwidthstring 00.00.0000
8890
8891 \series bold
8892 -
8893 \begin_inset ERT
8894 status collapsed
8895
8896 \begin_layout Standard
8897
8898
8899 \backslash
8900 /
8901 \end_layout
8902
8903 \end_inset
8904
8905 -acall-ajmp
8906 \series default
8907 \InsetSpace ~
8908
8909 \begin_inset LatexCommand index
8910 name "-\\/-acall-ajmp"
8911
8912 \end_inset
8913
8914  Replaces the three byte instructions lcall/ljmp with the two byte instructions
8915  acall/ajmp.
8916  Only use this option if your code is in the same 2k block of memory.
8917  You may need to use this option for some 8051 derivatives which lack the
8918  lcall/ljmp instructions..
8919 \end_layout
8920
8921 \begin_layout Standard
8922 \begin_inset VSpace bigskip
8923 \end_inset
8924
8925
8926 \end_layout
8927
8928 \begin_layout Subsection
8929 DS390 / DS400 Options
8930 \begin_inset LatexCommand index
8931 name "Options DS390"
8932
8933 \end_inset
8934
8935
8936 \begin_inset LatexCommand index
8937 name "DS390"
8938
8939 \end_inset
8940
8941
8942 \end_layout
8943
8944 \begin_layout List
8945 \labelwidthstring 00.00.0000
8946
8947 \series bold
8948 -
8949 \begin_inset ERT
8950 status collapsed
8951
8952 \begin_layout Standard
8953
8954
8955 \backslash
8956 /
8957 \end_layout
8958
8959 \end_inset
8960
8961 -model-flat24
8962 \series default
8963
8964 \begin_inset LatexCommand index
8965 name "DS390!Options!-\\/-model-flat24"
8966
8967 \end_inset
8968
8969
8970 \size large
8971  
8972 \size default
8973 Generate 24-bit flat mode code.
8974  This is the one and only that the ds390 code generator supports right now
8975  and is default when using 
8976 \emph on
8977 -mds390
8978 \emph default
8979 .
8980  See section Memory Models for more details.
8981 \end_layout
8982
8983 \begin_layout List
8984 \labelwidthstring 00.00.0000
8985
8986 \series bold
8987 -
8988 \begin_inset ERT
8989 status collapsed
8990
8991 \begin_layout Standard
8992
8993
8994 \backslash
8995 /
8996 \end_layout
8997
8998 \end_inset
8999
9000 -protect-sp-update
9001 \begin_inset LatexCommand index
9002 name "DS390!Options!-\\/-protect-sp-update"
9003
9004 \end_inset
9005
9006
9007 \series default
9008  disable interrupts during ESP:SP updates.
9009 \end_layout
9010
9011 \begin_layout List
9012 \labelwidthstring 00.00.0000
9013
9014 \series bold
9015 -
9016 \begin_inset ERT
9017 status collapsed
9018
9019 \begin_layout Standard
9020
9021
9022 \backslash
9023 /
9024 \end_layout
9025
9026 \end_inset
9027
9028 -stack-10bit
9029 \series default
9030
9031 \begin_inset LatexCommand index
9032 name "DS390!Options!-\\/-stack-10bit"
9033
9034 \end_inset
9035
9036  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
9037  This is the one and only that the ds390 code generator supports right now
9038  and is default when using 
9039 \emph on
9040 -mds390
9041 \emph default
9042 .
9043  In this mode, the stack is located in the lower 1K of the internal RAM,
9044  which is mapped to 0x400000.
9045  Note that the support is incomplete, since it still uses a single byte
9046  as the stack pointer.
9047  This means that only the lower 256 bytes of the potential 1K stack space
9048  will actually be used.
9049  However, this does allow you to reclaim the precious 256 bytes of low RAM
9050  for use for the DATA and IDATA segments.
9051  The compiler will not generate any code to put the processor into 10 bit
9052  stack mode.
9053  It is important to ensure that the processor is in this mode before calling
9054  any re-entrant functions compiled with this option.
9055  In principle, this should work with the 
9056 \emph on
9057 -
9058 \begin_inset ERT
9059 status collapsed
9060
9061 \begin_layout Standard
9062
9063
9064 \backslash
9065 /
9066 \end_layout
9067
9068 \end_inset
9069
9070 -stack-auto
9071 \begin_inset LatexCommand index
9072 name "-\\/-stack-auto"
9073
9074 \end_inset
9075
9076
9077 \emph default
9078  option, but that has not been tested.
9079  It is incompatible with the 
9080 \emph on
9081 -
9082 \begin_inset ERT
9083 status collapsed
9084
9085 \begin_layout Standard
9086
9087
9088 \backslash
9089 /
9090 \end_layout
9091
9092 \end_inset
9093
9094 -xstack
9095 \begin_inset LatexCommand index
9096 name "-\\/-xstack"
9097
9098 \end_inset
9099
9100
9101 \emph default
9102  option.
9103  It also only makes sense if the processor is in 24 bit contiguous addressing
9104  mode (see the 
9105 \emph on
9106 -
9107 \begin_inset ERT
9108 status collapsed
9109
9110 \begin_layout Standard
9111
9112
9113 \backslash
9114 /
9115 \end_layout
9116
9117 \end_inset
9118
9119 -model-flat24 option
9120 \emph default
9121 ).
9122 \series bold
9123
9124 \begin_inset Note Note
9125 status collapsed
9126
9127 \begin_layout List
9128 \labelwidthstring 00.00.0000
9129
9130 \series bold
9131 -
9132 \begin_inset ERT
9133 status open
9134
9135 \begin_layout Standard
9136
9137
9138 \backslash
9139 /
9140 \end_layout
9141
9142 \end_inset
9143
9144 -stack-8-bit - switches off the 10-bit mode
9145 \end_layout
9146
9147 \end_inset
9148
9149
9150 \end_layout
9151
9152 \begin_layout List
9153 \labelwidthstring 00.00.0000
9154
9155 \series bold
9156 -
9157 \begin_inset ERT
9158 status collapsed
9159
9160 \begin_layout Standard
9161
9162
9163 \backslash
9164 /
9165 \end_layout
9166
9167 \end_inset
9168
9169 -stack-probe
9170 \begin_inset LatexCommand index
9171 name "DS390!Options!-\\/-stack-probe"
9172
9173 \end_inset
9174
9175
9176 \series default
9177  insert call to function __stack_probe at each function prologue.
9178 \end_layout
9179
9180 \begin_layout List
9181 \labelwidthstring 00.00.0000
9182
9183 \series bold
9184 -
9185 \begin_inset ERT
9186 status open
9187
9188 \begin_layout Standard
9189
9190
9191 \backslash
9192 /
9193 \end_layout
9194
9195 \end_inset
9196
9197 -tini-libid
9198 \begin_inset LatexCommand index
9199 name "DS390!Options!-\\/-tini-libid"
9200
9201 \end_inset
9202
9203
9204 \series default
9205  <nnnn> LibraryID used in -mTININative.
9206  
9207 \end_layout
9208
9209 \begin_layout List
9210 \labelwidthstring 00.00.0000
9211
9212 \series bold
9213 -
9214 \begin_inset ERT
9215 status collapsed
9216
9217 \begin_layout Standard
9218
9219
9220 \backslash
9221 /
9222 \end_layout
9223
9224 \end_inset
9225
9226 -use-accelerator
9227 \begin_inset LatexCommand index
9228 name "DS390!Options!-\\/-use-accelerator"
9229
9230 \end_inset
9231
9232
9233 \series default
9234  generate code for DS390 Arithmetic Accelerator.
9235  
9236 \end_layout
9237
9238 \begin_layout Standard
9239 \begin_inset VSpace bigskip
9240 \end_inset
9241
9242
9243 \end_layout
9244
9245 \begin_layout Subsection
9246 Z80 Options
9247 \begin_inset LatexCommand index
9248 name "Options Z80"
9249
9250 \end_inset
9251
9252
9253 \begin_inset LatexCommand index
9254 name "Z80"
9255
9256 \end_inset
9257
9258
9259 \end_layout
9260
9261 \begin_layout List
9262 \labelwidthstring 00.00.0000
9263
9264 \series bold
9265 -
9266 \begin_inset ERT
9267 status collapsed
9268
9269 \begin_layout Standard
9270
9271
9272 \backslash
9273 /
9274 \end_layout
9275
9276 \end_inset
9277
9278 -callee-saves-bc
9279 \series default
9280
9281 \begin_inset LatexCommand index
9282 name "Z80!Options!-\\/-callee-saves-bc"
9283
9284 \end_inset
9285
9286
9287 \size large
9288  
9289 \size default
9290 Force a called function to always save BC.
9291 \end_layout
9292
9293 \begin_layout List
9294 \labelwidthstring 00.00.0000
9295
9296 \series bold
9297 -
9298 \begin_inset ERT
9299 status collapsed
9300
9301 \begin_layout Standard
9302
9303
9304 \backslash
9305 /
9306 \end_layout
9307
9308 \end_inset
9309
9310 -no-std-crt0
9311 \series default
9312
9313 \begin_inset LatexCommand index
9314 name "Z80!Options!-\\/-no-std-crt0"
9315
9316 \end_inset
9317
9318  When linking, skip the standard crt0.o object file.
9319  You must provide your own crt0.o for your system when linking.
9320 \end_layout
9321
9322 \begin_layout List
9323 \labelwidthstring 00.00.0000
9324
9325 \series bold
9326 -
9327 \begin_inset ERT
9328 status collapsed
9329
9330 \begin_layout Standard
9331
9332
9333 \backslash
9334 /
9335 \end_layout
9336
9337 \end_inset
9338
9339 -portmode=
9340 \series default
9341 <Value>
9342 \begin_inset LatexCommand index
9343 name "Z80!Options!-\\/-portmode=<Value>"
9344
9345 \end_inset
9346
9347  Determinate PORT I/O mode (<Value> is z80 or z180).
9348 \end_layout
9349
9350 \begin_layout List
9351 \labelwidthstring 00.00.0000
9352
9353 \series bold
9354 -
9355 \begin_inset ERT
9356 status collapsed
9357
9358 \begin_layout Standard
9359
9360
9361 \backslash
9362 /
9363 \end_layout
9364
9365 \end_inset
9366
9367 -asm=
9368 \series default
9369 <Value>
9370 \begin_inset LatexCommand index
9371 name "Z80!Options!-\\/-asm=<Value>"
9372
9373 \end_inset
9374
9375  Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
9376 \end_layout
9377
9378 \begin_layout List
9379 \labelwidthstring 00.00.0000
9380
9381 \series bold
9382 -
9383 \begin_inset ERT
9384 status collapsed
9385
9386 \begin_layout Standard
9387
9388
9389 \backslash
9390 /
9391 \end_layout
9392
9393 \end_inset
9394
9395 -codeseg
9396 \series default
9397 \InsetSpace ~
9398 <Value>
9399 \begin_inset LatexCommand index
9400 name "Z80!Options!-\\/-codeseg <Value>"
9401
9402 \end_inset
9403
9404  Use <Value> for the code segment name.
9405 \end_layout
9406
9407 \begin_layout List
9408 \labelwidthstring 00.00.0000
9409
9410 \series bold
9411 -
9412 \begin_inset ERT
9413 status collapsed
9414
9415 \begin_layout Standard
9416
9417
9418 \backslash
9419 /
9420 \end_layout
9421
9422 \end_inset
9423
9424 -constseg
9425 \series default
9426 \InsetSpace ~
9427 <Value>
9428 \begin_inset LatexCommand index
9429 name "Z80!Options!-\\/-constseg <Value>"
9430
9431 \end_inset
9432
9433  Use <Value> for the const segment name.
9434 \end_layout
9435
9436 \begin_layout List
9437 \labelwidthstring 00.00.0000
9438 \begin_inset VSpace bigskip
9439 \end_inset
9440
9441
9442 \end_layout
9443
9444 \begin_layout Subsection
9445 GBZ80 Options
9446 \begin_inset LatexCommand index
9447 name "Options GBZ80"
9448
9449 \end_inset
9450
9451
9452 \begin_inset LatexCommand index
9453 name "GBZ80"
9454
9455 \end_inset
9456
9457
9458 \end_layout
9459
9460 \begin_layout List
9461 \labelwidthstring 00.00.0000
9462
9463 \series bold
9464 -
9465 \begin_inset ERT
9466 status collapsed
9467
9468 \begin_layout Standard
9469
9470
9471 \backslash
9472 /
9473 \end_layout
9474
9475 \end_inset
9476
9477 -callee-saves-bc
9478 \series default
9479
9480 \begin_inset LatexCommand index
9481 name "GBZ80!Options!-\\/-callee-saves-bc"
9482
9483 \end_inset
9484
9485
9486 \size large
9487  
9488 \size default
9489 Force a called function to always save BC.
9490 \end_layout
9491
9492 \begin_layout List
9493 \labelwidthstring 00.00.0000
9494
9495 \series bold
9496 -
9497 \begin_inset ERT
9498 status collapsed
9499
9500 \begin_layout Standard
9501
9502
9503 \backslash
9504 /
9505 \end_layout
9506
9507 \end_inset
9508
9509 -no-std-crt0
9510 \series default
9511
9512 \begin_inset LatexCommand index
9513 name "Z80!Options!-\\/-no-std-crt0"
9514
9515 \end_inset
9516
9517  When linking, skip the standard crt0.o object file.
9518  You must provide your own crt0.o for your system when linking.
9519 \end_layout
9520
9521 \begin_layout List
9522 \labelwidthstring 00.00.0000
9523
9524 \series bold
9525 -bo
9526 \series default
9527 \InsetSpace ~
9528 <Num>
9529 \begin_inset LatexCommand index
9530 name "GBZ80!Options!-bo <Num>"
9531
9532 \end_inset
9533
9534  Use code bank <Num>.
9535 \end_layout
9536
9537 \begin_layout List
9538 \labelwidthstring 00.00.0000
9539
9540 \series bold
9541 -ba
9542 \series default
9543 \InsetSpace ~
9544 <Num>
9545 \begin_inset LatexCommand index
9546 name "GBZ80!Options!-ba <Num>"
9547
9548 \end_inset
9549
9550  Use data bank <Num>.
9551 \end_layout
9552
9553 \begin_layout List
9554 \labelwidthstring 00.00.0000
9555
9556 \series bold
9557 -
9558 \begin_inset ERT
9559 status collapsed
9560
9561 \begin_layout Standard
9562
9563
9564 \backslash
9565 /
9566 \end_layout
9567
9568 \end_inset
9569
9570 -codeseg
9571 \series default
9572 \InsetSpace ~
9573 <Value>
9574 \begin_inset LatexCommand index
9575 name "GBZ80!Options!-\\/-codeseg <Value>"
9576
9577 \end_inset
9578
9579  Use <Value> for the code segment name.
9580 \end_layout
9581
9582 \begin_layout List
9583 \labelwidthstring 00.00.0000
9584
9585 \series bold
9586 -
9587 \begin_inset ERT
9588 status collapsed
9589
9590 \begin_layout Standard
9591
9592
9593 \backslash
9594 /
9595 \end_layout
9596
9597 \end_inset
9598
9599 -constseg
9600 \series default
9601 \InsetSpace ~
9602 <Value>
9603 \begin_inset LatexCommand index
9604 name "GBZ80!Options!-\\/-constseg <Value>"
9605
9606 \end_inset
9607
9608  Use <Value> for the const segment name.
9609 \end_layout
9610
9611 \begin_layout Standard
9612 \begin_inset VSpace bigskip
9613 \end_inset
9614
9615
9616 \end_layout
9617
9618 \begin_layout Subsection
9619 Optimization Options
9620 \begin_inset LatexCommand index
9621 name "Options optimization"
9622
9623 \end_inset
9624
9625
9626 \begin_inset LatexCommand index
9627 name "Optimization options"
9628
9629 \end_inset
9630
9631
9632 \end_layout
9633
9634 \begin_layout List
9635 \labelwidthstring 00.00.0000
9636
9637 \series bold
9638 -
9639 \begin_inset ERT
9640 status collapsed
9641
9642 \begin_layout Standard
9643
9644
9645 \backslash
9646 /
9647 \end_layout
9648
9649 \end_inset
9650
9651 -nogcse
9652 \begin_inset LatexCommand index
9653 name "-\\/-nogcse"
9654
9655 \end_inset
9656
9657
9658 \series default
9659  Will not do global subexpression elimination, this option may be used when
9660  the compiler creates undesirably large stack/data spaces to store compiler
9661  temporaries (
9662 \emph on
9663 s
9664 \emph default
9665 pill 
9666 \emph on
9667 loc
9668 \emph default
9669 ations, sloc
9670 \begin_inset LatexCommand index
9671 name "sloc (spill location)"
9672
9673 \end_inset
9674
9675 ).
9676  A warning message will be generated when this happens and the compiler
9677  will indicate the number of extra bytes it allocated.
9678  It is recommended that this option NOT be used, #pragma\InsetSpace ~
9679 nogcse
9680 \begin_inset LatexCommand index
9681 name "\\#pragma nogcse"
9682
9683 \end_inset
9684
9685  can be used to turn off global subexpression elimination
9686 \begin_inset LatexCommand index
9687 name "Subexpression elimination"
9688
9689 \end_inset
9690
9691  for a given function only.
9692 \end_layout
9693
9694 \begin_layout List
9695 \labelwidthstring 00.00.0000
9696
9697 \series bold
9698 -
9699 \begin_inset ERT
9700 status collapsed
9701
9702 \begin_layout Standard
9703
9704
9705 \backslash
9706 /
9707 \end_layout
9708
9709 \end_inset
9710
9711 -noinvariant
9712 \begin_inset LatexCommand index
9713 name "-\\/-noinvariant"
9714
9715 \end_inset
9716
9717
9718 \series default
9719  Will not do loop invariant optimizations, this may be turned off for reasons
9720  explained for the previous option.
9721  For more details of loop optimizations performed see Loop Invariants in
9722  section 
9723 \begin_inset LatexCommand ref
9724 reference "sub:Loop-Optimizations"
9725
9726 \end_inset
9727
9728 .
9729  It is recommended that this option NOT be used, #pragma\InsetSpace ~
9730 noinvariant
9731 \begin_inset LatexCommand index
9732 name "\\#pragma noinvariant"
9733
9734 \end_inset
9735
9736  can be used to turn off invariant optimizations for a given function only.
9737 \end_layout
9738
9739 \begin_layout List
9740 \labelwidthstring 00.00.0000
9741
9742 \series bold
9743 -
9744 \begin_inset ERT
9745 status collapsed
9746
9747 \begin_layout Standard
9748
9749
9750 \backslash
9751 /
9752 \end_layout
9753
9754 \end_inset
9755
9756 -noinduction
9757 \begin_inset LatexCommand index
9758 name "-\\/-noinduction"
9759
9760 \end_inset
9761
9762
9763 \series default
9764  Will not do loop induction optimizations, see section strength reduction
9765  for more details.
9766  It is recommended that this option is NOT used, #pragma\InsetSpace ~
9767 noinduction
9768 \begin_inset LatexCommand index
9769 name "\\#pragma noinduction"
9770
9771 \end_inset
9772
9773  can be used to turn off induction optimizations for a given function only.
9774 \end_layout
9775
9776 \begin_layout List
9777 \labelwidthstring 00.00.0000
9778
9779 \series bold
9780 -
9781 \begin_inset ERT
9782 status collapsed
9783
9784 \begin_layout Standard
9785
9786
9787 \backslash
9788 /
9789 \end_layout
9790
9791 \end_inset
9792
9793 -nojtbound
9794 \begin_inset LatexCommand index
9795 name "-\\/-nojtbound"
9796
9797 \end_inset
9798
9799
9800 \size large
9801  
9802 \series default
9803 \size default
9804  Will not generate boundary condition check when switch statements
9805 \begin_inset LatexCommand index
9806 name "switch statement"
9807
9808 \end_inset
9809
9810  are implemented using jump-tables.
9811  See section 
9812 \begin_inset LatexCommand ref
9813 reference "sub:'switch'-Statements"
9814
9815 \end_inset
9816
9817 \InsetSpace ~
9818 Switch Statements for more details.
9819  It is recommended that this option is NOT used, #pragma\InsetSpace ~
9820 nojtbound
9821 \begin_inset LatexCommand index
9822 name "\\#pragma nojtbound"
9823
9824 \end_inset
9825
9826  can be used to turn off boundary checking for jump tables for a given function
9827  only.
9828 \end_layout
9829
9830 \begin_layout List
9831 \labelwidthstring 00.00.0000
9832
9833 \series bold
9834 -
9835 \begin_inset ERT
9836 status collapsed
9837
9838 \begin_layout Standard
9839
9840
9841 \backslash
9842 /
9843 \end_layout
9844
9845 \end_inset
9846
9847 -noloopreverse
9848 \begin_inset LatexCommand index
9849 name "-\\/-noloopreverse"
9850
9851 \end_inset
9852
9853
9854 \series default
9855 \size large
9856  
9857 \size default
9858 Will not do loop reversal 
9859 \begin_inset LatexCommand index
9860 name "Loop reversing"
9861
9862 \end_inset
9863
9864 optimization.
9865 \end_layout
9866
9867 \begin_layout List
9868 \labelwidthstring 00.00.0000
9869 -
9870 \begin_inset ERT
9871 status collapsed
9872
9873 \begin_layout Standard
9874
9875
9876 \backslash
9877 /
9878 \end_layout
9879
9880 \end_inset
9881
9882 -
9883 \series bold
9884 nolabelopt
9885 \series default
9886  
9887 \begin_inset LatexCommand index
9888 name "-\\/-nolabelopt "
9889
9890 \end_inset
9891
9892 Will not optimize labels (makes the dumpfiles more readable).
9893 \end_layout
9894
9895 \begin_layout List
9896 \labelwidthstring 00.00.0000
9897
9898 \series bold
9899 -
9900 \begin_inset ERT
9901 status collapsed
9902
9903 \begin_layout Standard
9904
9905
9906 \backslash
9907 /
9908 \end_layout
9909
9910 \end_inset
9911
9912 -no-xinit-opt
9913 \begin_inset LatexCommand index
9914 name "-\\/-no-xinit-opt"
9915
9916 \end_inset
9917
9918
9919 \series default
9920  Will not memcpy initialized data from code space into xdata space.
9921  This saves a few bytes in code space if you don't have initialized data
9922 \begin_inset LatexCommand index
9923 name "Variable initialization"
9924
9925 \end_inset
9926
9927 .
9928 \end_layout
9929
9930 \begin_layout List
9931 \labelwidthstring 00.00.0000
9932
9933 \series bold
9934 -
9935 \begin_inset ERT
9936 status collapsed
9937
9938 \begin_layout Standard
9939
9940
9941 \backslash
9942 /
9943 \end_layout
9944
9945 \end_inset
9946
9947 -nooverlay
9948 \begin_inset LatexCommand index
9949 name "-\\/-nooverlay"
9950
9951 \end_inset
9952
9953
9954 \series default
9955   The compiler will not overlay parameters and local variables of any function,
9956  see section Parameters and local variables for more details.
9957 \end_layout
9958
9959 \begin_layout List
9960 \labelwidthstring 00.00.0000
9961
9962 \series bold
9963 -
9964 \begin_inset ERT
9965 status collapsed
9966
9967 \begin_layout Standard
9968
9969
9970 \backslash
9971 /
9972 \end_layout
9973
9974 \end_inset
9975
9976 -no-peep
9977 \begin_inset LatexCommand index
9978 name "-\\/-no-peep"
9979
9980 \end_inset
9981
9982
9983 \series default
9984  Disable peep-hole optimization with built-in rules.
9985 \end_layout
9986
9987 \begin_layout List
9988 \labelwidthstring 00.00.0000
9989
9990 \series bold
9991 -
9992 \begin_inset ERT
9993 status collapsed
9994
9995 \begin_layout Standard
9996
9997
9998 \backslash
9999 /
10000 \end_layout
10001
10002 \end_inset
10003
10004 -peep-file
10005 \series default
10006
10007 \begin_inset LatexCommand index
10008 name "-\\/-peep-file"
10009
10010 \end_inset
10011
10012 \InsetSpace ~
10013 <filename> This option can be used to use additional rules to be used by
10014  the peep hole optimizer.
10015  See section 
10016 \begin_inset LatexCommand ref
10017 reference "sub:Peephole-Optimizer"
10018
10019 \end_inset
10020
10021 \InsetSpace ~
10022 Peep Hole optimizations for details on how to write these rules.
10023 \end_layout
10024
10025 \begin_layout List
10026 \labelwidthstring 00.00.0000
10027
10028 \series bold
10029 -
10030 \begin_inset ERT
10031 status collapsed
10032
10033 \begin_layout Standard
10034
10035
10036 \backslash
10037 /
10038 \end_layout
10039
10040 \end_inset
10041
10042 -peep-asm
10043 \begin_inset LatexCommand index
10044 name "-\\/-peep-asm"
10045
10046 \end_inset
10047
10048
10049 \series default
10050  Pass the inline assembler code through the peep hole optimizer.
10051  This can cause unexpected changes to inline assembler code, please go through
10052  the peephole optimizer
10053 \begin_inset LatexCommand index
10054 name "Peephole optimizer"
10055
10056 \end_inset
10057
10058  rules defined in the source file tree '<target>/peeph.def' before using
10059  this option.
10060 \end_layout
10061
10062 \begin_layout List
10063 \labelwidthstring 00.00.0000
10064
10065 \series bold
10066 -
10067 \begin_inset ERT
10068 status collapsed
10069
10070 \begin_layout Standard
10071
10072
10073 \backslash
10074 /
10075 \end_layout
10076
10077 \end_inset
10078
10079 -opt-code-speed
10080 \begin_inset LatexCommand index
10081 name "-\\/-opt-code-speed"
10082
10083 \end_inset
10084
10085
10086 \series default
10087  The compiler will optimize code generation towards fast code, possibly
10088  at the expense of code size.
10089 \end_layout
10090
10091 \begin_layout List
10092 \labelwidthstring 00.00.0000
10093
10094 \series bold
10095 -
10096 \begin_inset ERT
10097 status collapsed
10098
10099 \begin_layout Standard
10100
10101
10102 \backslash
10103 /
10104 \end_layout
10105
10106 \end_inset
10107
10108 -opt-code-size
10109 \begin_inset LatexCommand index
10110 name "-\\/-opt-code-size"
10111
10112 \end_inset
10113
10114
10115 \series default
10116  The compiler will optimize code generation towards compact code, possibly
10117  at the expense of code speed.
10118 \end_layout
10119
10120 \begin_layout Standard
10121 \begin_inset VSpace bigskip
10122 \end_inset
10123
10124
10125 \end_layout
10126
10127 \begin_layout Subsection
10128 Other Options
10129 \begin_inset LatexCommand index
10130 name "Options other"
10131
10132 \end_inset
10133
10134
10135 \end_layout
10136
10137 \begin_layout List
10138 \labelwidthstring 00.00.0000
10139
10140 \series bold
10141 -c\InsetSpace ~
10142 -
10143 \begin_inset ERT
10144 status collapsed
10145
10146 \begin_layout Standard
10147
10148
10149 \backslash
10150 /
10151 \end_layout
10152
10153 \end_inset
10154
10155 -compile-only
10156 \begin_inset LatexCommand index
10157 name "-\\/-compile-only"
10158
10159 \end_inset
10160
10161
10162 \begin_inset LatexCommand index
10163 name "-c -\\/-compile-only"
10164
10165 \end_inset
10166
10167
10168 \series default
10169  will compile and assemble the source, but will not call the linkage editor.
10170 \end_layout
10171
10172 \begin_layout List
10173 \labelwidthstring 00.00.0000
10174
10175 \series bold
10176 -
10177 \series default
10178
10179 \begin_inset ERT
10180 status collapsed
10181
10182 \begin_layout Standard
10183
10184
10185 \backslash
10186 /
10187 \end_layout
10188
10189 \end_inset
10190
10191
10192 \series bold
10193 -c1mode
10194 \begin_inset LatexCommand index
10195 name "-\\/-c1mode"
10196
10197 \end_inset
10198
10199
10200 \series default
10201  reads the preprocessed source from standard input and compiles it.
10202  The file name for the assembler output must be specified using the -o option.
10203 \end_layout
10204
10205 \begin_layout List
10206 \labelwidthstring 00.00.0000
10207
10208 \series bold
10209 -E
10210 \begin_inset LatexCommand index
10211 name "-E"
10212
10213 \end_inset
10214
10215
10216 \series default
10217  Run only the C preprocessor.
10218  Preprocess all the C source files specified and output the results to standard
10219  output.
10220 \end_layout
10221
10222 \begin_layout List
10223 \labelwidthstring 00.00.0000
10224
10225 \series bold
10226 -o\InsetSpace ~
10227 <path/file>
10228 \begin_inset LatexCommand index
10229 name "-o <path/file>"
10230
10231 \end_inset
10232
10233
10234 \series default
10235  The output path where everything will be placed or the file name used for
10236  all generated output files.
10237  If the parameter is a path, it must have a trailing slash (or backslash
10238  for the Windows binaries) to be recognized as a path.
10239  Note for Windows users: if the path contains spaces, it should be surrounded
10240  by quotes.
10241  The trailing backslash should be doubled in order to prevent escaping the
10242  final quote, for example: 
10243 \emph on
10244 -o 
10245 \begin_inset Quotes sld
10246 \end_inset
10247
10248 F:
10249 \backslash
10250 Projects
10251 \backslash
10252 test3
10253 \backslash
10254 output 1
10255 \backslash
10256
10257 \backslash
10258
10259 \begin_inset Quotes srd
10260 \end_inset
10261
10262
10263 \emph default
10264  or put after the final quote, for example: 
10265 \emph on
10266 -o 
10267 \begin_inset Quotes sld
10268 \end_inset
10269
10270 F:
10271 \backslash
10272 Projects
10273 \backslash
10274 test3
10275 \backslash
10276 output 1
10277 \begin_inset Quotes srd
10278 \end_inset
10279
10280
10281 \backslash
10282
10283 \emph default
10284 .
10285  The path using slashes for directory delimiters can be used too, for example:
10286  
10287 \emph on
10288 -o 
10289 \begin_inset Quotes sld
10290 \end_inset
10291
10292 F:/Projects/test3/output 1/
10293 \begin_inset Quotes srd
10294 \end_inset
10295
10296
10297 \emph default
10298 .
10299 \end_layout
10300
10301 \begin_layout List
10302 \labelwidthstring 00.00.0000
10303
10304 \series bold
10305 -
10306 \begin_inset ERT
10307 status collapsed
10308
10309 \begin_layout Standard
10310
10311
10312 \backslash
10313 /
10314 \end_layout
10315
10316 \end_inset
10317
10318 -stack-auto
10319 \begin_inset LatexCommand index
10320 name "-\\/-stack-auto"
10321
10322 \end_inset
10323
10324
10325 \series default
10326 \size large
10327  
10328 \size default
10329 All functions in the source file will be compiled as 
10330 \emph on
10331 reentrant
10332 \emph default
10333
10334 \begin_inset LatexCommand index
10335 name "reentrant"
10336
10337 \end_inset
10338
10339 , i.e.
10340  the parameters and local variables will be allocated on the stack
10341 \begin_inset LatexCommand index
10342 name "stack"
10343
10344 \end_inset
10345
10346 .
10347  See section 
10348 \begin_inset LatexCommand ref
10349 reference "sec:Parameters-and-Local-Variables"
10350
10351 \end_inset
10352
10353  Parameters and Local Variables for more details.
10354  If this option is used all source files in the project should be compiled
10355  with this option.
10356  It automatically implies -
10357 \series bold
10358
10359 \begin_inset ERT
10360 status open
10361
10362 \begin_layout Standard
10363
10364
10365 \backslash
10366 /
10367 \end_layout
10368
10369 \end_inset
10370
10371
10372 \series default
10373 -int-long-reent and -
10374 \series bold
10375
10376 \begin_inset ERT
10377 status open
10378
10379 \begin_layout Standard
10380
10381
10382 \backslash
10383 /
10384 \end_layout
10385
10386 \end_inset
10387
10388
10389 \series default
10390 -float-reent.
10391  
10392 \end_layout
10393
10394 \begin_layout List
10395 \labelwidthstring 00.00.0000
10396
10397 \series bold
10398 -
10399 \begin_inset ERT
10400 status collapsed
10401
10402 \begin_layout Standard
10403
10404
10405 \backslash
10406 /
10407 \end_layout
10408
10409 \end_inset
10410
10411 -callee-saves
10412 \begin_inset LatexCommand index
10413 name "-\\/-callee-saves"
10414
10415 \end_inset
10416
10417  
10418 \begin_inset LatexCommand label
10419 name "lyx:--callee-saves-function1[,function2][,function3]..."
10420
10421 \end_inset
10422
10423 function1[,function2][,function3]....
10424
10425 \series default
10426  The compiler by default uses a caller saves convention for register saving
10427  across function calls, however this can cause unnecessary register pushing
10428  and popping when calling small functions from larger functions.
10429  This option can be used to switch the register saving convention for the
10430  function names specified.
10431  The compiler will not save registers when calling these functions, no extra
10432  code will be generated at the entry and exit (function prologue
10433 \series bold
10434
10435 \begin_inset LatexCommand index
10436 name "function prologue"
10437
10438 \end_inset
10439
10440
10441 \series default
10442  and epilogue
10443 \series bold
10444
10445 \begin_inset LatexCommand index
10446 name "function epilogue"
10447
10448 \end_inset
10449
10450
10451 \series default
10452 ) for these functions to save and restore the registers used by these functions,
10453  this can SUBSTANTIALLY reduce code and improve run time performance of
10454  the generated code.
10455  In the future the compiler (with inter procedural analysis) will be able
10456  to determine the appropriate scheme to use for each function call.
10457  DO NOT use this option for built-in functions such as _mulint..., if this
10458  option is used for a library function the appropriate library function
10459  needs to be recompiled with the same option.
10460  If the project consists of multiple source files then all the source file
10461  should be compiled with the same -
10462 \begin_inset ERT
10463 status collapsed
10464
10465 \begin_layout Standard
10466
10467
10468 \backslash
10469 /
10470 \end_layout
10471
10472 \end_inset
10473
10474 -callee-saves option string.
10475  Also see #pragma\InsetSpace ~
10476 callee_saves 
10477 \begin_inset LatexCommand index
10478 name "\\#pragma callee\\_saves"
10479
10480 \end_inset
10481
10482  
10483 \begin_inset LatexCommand vpageref
10484 reference "ite:callee_saves-function1[,function2[,function3...]]--"
10485
10486 \end_inset
10487
10488 .
10489 \end_layout
10490
10491 \begin_layout List
10492 \labelwidthstring 00.00.0000
10493
10494 \series bold
10495 -
10496 \begin_inset ERT
10497 status collapsed
10498
10499 \begin_layout Standard
10500
10501
10502 \backslash
10503 /
10504 \end_layout
10505
10506 \end_inset
10507
10508 -all-callee-saves
10509 \begin_inset LatexCommand index
10510 name "-\\/-all-callee-saves"
10511
10512 \end_inset
10513
10514
10515 \series default
10516  Function of -
10517 \begin_inset ERT
10518 status collapsed
10519
10520 \begin_layout Standard
10521
10522
10523 \backslash
10524 /
10525 \end_layout
10526
10527 \end_inset
10528
10529 -callee-saves will be applied to all functions by default.
10530 \end_layout
10531
10532 \begin_layout List
10533 \labelwidthstring 00.00.0000
10534
10535 \series bold
10536 -
10537 \begin_inset ERT
10538 status collapsed
10539
10540 \begin_layout Standard
10541
10542
10543 \backslash
10544 /
10545 \end_layout
10546
10547 \end_inset
10548
10549 -debug
10550 \begin_inset LatexCommand index
10551 name "-\\/-debug"
10552
10553 \end_inset
10554
10555  
10556 \series default
10557 When this option is used the compiler will generate debug information.
10558  The debug information collected in a file with .cdb extension can be used
10559  with the SDCDB.
10560  For more information see documentation for SDCDB.
10561  Another file with no extension contains debug information in AOMF or AOMF51
10562 \begin_inset LatexCommand index
10563 name "AOMF, AOMF51"
10564
10565 \end_inset
10566
10567  format which is commonly used by third party tools.
10568 \end_layout
10569
10570 \begin_layout List
10571 \labelwidthstring 00.00.0000
10572
10573 \series bold
10574 -S
10575 \begin_inset LatexCommand index
10576 name "-S"
10577
10578 \end_inset
10579
10580
10581 \series default
10582 \size large
10583  
10584 \size default
10585 Stop after the stage of compilation proper; do not assemble.
10586  The output is an assembler code file for the input file specified.
10587 \end_layout
10588
10589 \begin_layout List
10590 \labelwidthstring 00.00.0000
10591
10592 \series bold
10593 -
10594 \begin_inset ERT
10595 status collapsed
10596
10597 \begin_layout Standard
10598
10599
10600 \backslash
10601 /
10602 \end_layout
10603
10604 \end_inset
10605
10606 -int-long-reent
10607 \begin_inset LatexCommand index
10608 name "-\\/-int-long-reent"
10609
10610 \end_inset
10611
10612
10613 \series default
10614  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
10615  Note by default these libraries are compiled as non-reentrant.
10616  See section Installation for more details.
10617 \end_layout
10618
10619 \begin_layout List
10620 \labelwidthstring 00.00.0000
10621
10622 \series bold
10623 -
10624 \begin_inset ERT
10625 status collapsed
10626
10627 \begin_layout Standard
10628
10629
10630 \backslash
10631 /
10632 \end_layout
10633
10634 \end_inset
10635
10636 -cyclomatic
10637 \begin_inset LatexCommand index
10638 name "-\\/-cyclomatic"
10639
10640 \end_inset
10641
10642  
10643 \series default
10644 This option will cause the compiler to generate an information message for
10645  each function in the source file.
10646  The message contains some 
10647 \emph on
10648 important
10649 \emph default
10650  information about the function.
10651  The number of edges and nodes the compiler detected in the control flow
10652  graph of the function, and most importantly the 
10653 \emph on
10654 cyclomatic complexity
10655 \begin_inset LatexCommand index
10656 name "Cyclomatic complexity"
10657
10658 \end_inset
10659
10660
10661 \emph default
10662  see section on Cyclomatic Complexity for more details.
10663 \end_layout
10664
10665 \begin_layout List
10666 \labelwidthstring 00.00.0000
10667
10668 \series bold
10669 -
10670 \begin_inset ERT
10671 status collapsed
10672
10673 \begin_layout Standard
10674
10675
10676 \backslash
10677 /
10678 \end_layout
10679
10680 \end_inset
10681
10682 -float-reent
10683 \begin_inset LatexCommand index
10684 name "-\\/-float-reent"
10685
10686 \end_inset
10687
10688
10689 \series default
10690  Floating point library is compiled as reentrant
10691 \begin_inset LatexCommand index
10692 name "reentrant"
10693
10694 \end_inset
10695
10696 .
10697  See section Installation for more details.
10698 \end_layout
10699
10700 \begin_layout List
10701 \labelwidthstring 00.00.0000
10702
10703 \series bold
10704 -
10705 \begin_inset ERT
10706 status collapsed
10707
10708 \begin_layout Standard
10709
10710
10711 \backslash
10712 /
10713 \end_layout
10714
10715 \end_inset
10716
10717 -funsigned-char
10718 \begin_inset LatexCommand index
10719 name "-\\/-funsigned-char"
10720
10721 \end_inset
10722
10723
10724 \series default
10725  The default signedness for every type is 
10726 \family typewriter
10727 signed
10728 \family default
10729 .
10730  In some embedded environments the default signedness of 
10731 \family typewriter
10732 char
10733 \family default
10734  is 
10735 \family typewriter
10736 unsigned
10737 \family default
10738 .
10739  To set the signess for characters to unsigned, use the option -
10740 \series bold
10741
10742 \begin_inset ERT
10743 status open
10744
10745 \begin_layout Standard
10746
10747
10748 \backslash
10749 /
10750 \end_layout
10751
10752 \end_inset
10753
10754
10755 \series default
10756 -funsigned-char.
10757  If this option is set and no signedness keyword (unsigned/signed) is given,
10758  a char will be signed.
10759  All other types are unaffected.
10760 \end_layout
10761
10762 \begin_layout List
10763 \labelwidthstring 00.00.0000
10764
10765 \series bold
10766 -
10767 \begin_inset ERT
10768 status collapsed
10769
10770 \begin_layout Standard
10771
10772
10773 \backslash
10774 /
10775 \end_layout
10776
10777 \end_inset
10778
10779 -main-return
10780 \begin_inset LatexCommand index
10781 name "-\\/-main-return"
10782
10783 \end_inset
10784
10785
10786 \series default
10787  This option can be used if the code generated is called by a monitor program
10788  or if the main routine includes an endless loop.
10789  This option results in slightly smaller code and saves two bytes of stack
10790  space.
10791  The return from the 'main'
10792 \begin_inset LatexCommand index
10793 name "main return"
10794
10795 \end_inset
10796
10797  function will return to the function calling main.
10798  The default setting is to lock up i.e.
10799  generate a '
10800 \family typewriter
10801 sjmp .
10802 \family default
10803 '.
10804 \end_layout
10805
10806 \begin_layout List
10807 \labelwidthstring 00.00.0000
10808
10809 \series bold
10810 -
10811 \begin_inset ERT
10812 status collapsed
10813
10814 \begin_layout Standard
10815
10816
10817 \backslash
10818 /
10819 \end_layout
10820
10821 \end_inset
10822
10823 -nostdinc
10824 \begin_inset LatexCommand index
10825 name "-\\/-nostdinc"
10826
10827 \end_inset
10828
10829
10830 \series default
10831  This will prevent the compiler from passing on the default include path
10832  to the preprocessor.
10833 \end_layout
10834
10835 \begin_layout List
10836 \labelwidthstring 00.00.0000
10837
10838 \series bold
10839 -
10840 \begin_inset ERT
10841 status collapsed
10842
10843 \begin_layout Standard
10844
10845
10846 \backslash
10847 /
10848 \end_layout
10849
10850 \end_inset
10851
10852 -nostdlib
10853 \begin_inset LatexCommand index
10854 name "-\\/-nostdlib"
10855
10856 \end_inset
10857
10858
10859 \series default
10860  This will prevent the compiler from passing on the default library
10861 \begin_inset LatexCommand index
10862 name "Libraries"
10863
10864 \end_inset
10865
10866  path to the linker.
10867 \end_layout
10868
10869 \begin_layout List
10870 \labelwidthstring 00.00.0000
10871
10872 \series bold
10873 -
10874 \begin_inset ERT
10875 status collapsed
10876
10877 \begin_layout Standard
10878
10879
10880 \backslash
10881 /
10882 \end_layout
10883
10884 \end_inset
10885
10886 -verbose
10887 \begin_inset LatexCommand index
10888 name "-\\/-verbose"
10889
10890 \end_inset
10891
10892
10893 \series default
10894  Shows the various actions the compiler is performing.
10895 \end_layout
10896
10897 \begin_layout List
10898 \labelwidthstring 00.00.0000
10899
10900 \series bold
10901 -V
10902 \begin_inset LatexCommand index
10903 name "-V"
10904
10905 \end_inset
10906
10907
10908 \series default
10909  Shows the actual commands the compiler is executing.
10910 \end_layout
10911
10912 \begin_layout List
10913 \labelwidthstring 00.00.0000
10914
10915 \series bold
10916 -
10917 \begin_inset ERT
10918 status collapsed
10919
10920 \begin_layout Standard
10921
10922
10923 \backslash
10924 /
10925 \end_layout
10926
10927 \end_inset
10928
10929 -no-c-code-in-asm
10930 \begin_inset LatexCommand index
10931 name "-\\/-no-c-code-in-asm"
10932
10933 \end_inset
10934
10935
10936 \series default
10937  Hides your ugly and inefficient c-code from the asm file, so you can always
10938  blame the compiler :)
10939 \end_layout
10940
10941 \begin_layout List
10942 \labelwidthstring 00.00.0000
10943
10944 \series bold
10945 -
10946 \begin_inset ERT
10947 status collapsed
10948
10949 \begin_layout Standard
10950
10951
10952 \backslash
10953 /
10954 \end_layout
10955
10956 \end_inset
10957
10958 -fverbose-asm
10959 \begin_inset LatexCommand index
10960 name "-\\/-no-gen-comments"
10961
10962 \end_inset
10963
10964
10965 \series default
10966  Include code generator and peep-hole comments in the generated asm files.
10967 \end_layout
10968
10969 \begin_layout List
10970 \labelwidthstring 00.00.0000
10971
10972 \series bold
10973 -
10974 \begin_inset ERT
10975 status collapsed
10976
10977 \begin_layout Standard
10978
10979
10980 \backslash
10981 /
10982 \end_layout
10983
10984 \end_inset
10985
10986 -no-peep-comments
10987 \begin_inset LatexCommand index
10988 name "-\\/-no-peep-comments"
10989
10990 \end_inset
10991
10992
10993 \series default
10994  Don't include peep-hole comments in the generated asm files even if -
10995 \series bold
10996
10997 \begin_inset ERT
10998 status open
10999
11000 \begin_layout Standard
11001
11002
11003 \backslash
11004 /
11005 \end_layout
11006
11007 \end_inset
11008
11009
11010 \series default
11011 -fverbose-asm option is specified.
11012 \end_layout
11013
11014 \begin_layout List
11015 \labelwidthstring 00.00.0000
11016
11017 \series bold
11018 -
11019 \begin_inset ERT
11020 status collapsed
11021
11022 \begin_layout Standard
11023
11024
11025 \backslash
11026 /
11027 \end_layout
11028
11029 \end_inset
11030
11031 -i-code-in-asm
11032 \begin_inset LatexCommand index
11033 name "-\\/-i-code-in-asm"
11034
11035 \end_inset
11036
11037
11038 \series default
11039  Include i-codes in the asm file.
11040  Sounds like noise but is most helpful for debugging the compiler itself.
11041 \end_layout
11042
11043 \begin_layout List
11044 \labelwidthstring 00.00.0000
11045
11046 \series bold
11047 -
11048 \begin_inset ERT
11049 status collapsed
11050
11051 \begin_layout Standard
11052
11053
11054 \backslash
11055 /
11056 \end_layout
11057
11058 \end_inset
11059
11060 -less-pedantic
11061 \begin_inset LatexCommand index
11062 name "pedantic"
11063
11064 \end_inset
11065
11066
11067 \begin_inset LatexCommand index
11068 name "-\\/-less-pedantic"
11069
11070 \end_inset
11071
11072
11073 \series default
11074
11075 \begin_inset LatexCommand label
11076 name "lyx:--less-pedantic"
11077
11078 \end_inset
11079
11080  Disable some of the more pedantic warnings
11081 \begin_inset LatexCommand index
11082 name "Warnings"
11083
11084 \end_inset
11085
11086 .
11087  For more details, see the less_pedantic pragma 
11088 \begin_inset LatexCommand vpageref
11089 reference "ite:less_pedantic"
11090
11091 \end_inset
11092
11093 .
11094 \end_layout
11095
11096 \begin_layout List
11097 \labelwidthstring 00.00.0000
11098
11099 \series bold
11100 -
11101 \begin_inset ERT
11102 status collapsed
11103
11104 \begin_layout Standard
11105
11106
11107 \backslash
11108 /
11109 \end_layout
11110
11111 \end_inset
11112
11113 -disable-warning\InsetSpace ~
11114 <nnnn>
11115 \begin_inset LatexCommand index
11116 name "-\\/-disable-warning"
11117
11118 \end_inset
11119
11120
11121 \series default
11122  Disable specific warning with number <nnnn>.
11123 \end_layout
11124
11125 \begin_layout List
11126 \labelwidthstring 00.00.0000
11127
11128 \series bold
11129 -
11130 \begin_inset ERT
11131 status collapsed
11132
11133 \begin_layout Standard
11134
11135
11136 \backslash
11137 /
11138 \end_layout
11139
11140 \end_inset
11141
11142 -Werror
11143 \begin_inset LatexCommand index
11144 name "-\\/-Werror"
11145
11146 \end_inset
11147
11148
11149 \series default
11150  Treat all warnings as errors.
11151 \end_layout
11152
11153 \begin_layout List
11154 \labelwidthstring 00.00.0000
11155
11156 \series bold
11157 -
11158 \begin_inset ERT
11159 status collapsed
11160
11161 \begin_layout Standard
11162
11163
11164 \backslash
11165 /
11166 \end_layout
11167
11168 \end_inset
11169
11170 -print-search-dirs
11171 \begin_inset LatexCommand index
11172 name "-\\/-print-search-dirs"
11173
11174 \end_inset
11175
11176
11177 \series default
11178  Display the directories in the compiler's search path
11179 \end_layout
11180
11181 \begin_layout List
11182 \labelwidthstring 00.00.0000
11183
11184 \series bold
11185 -
11186 \begin_inset ERT
11187 status collapsed
11188
11189 \begin_layout Standard
11190
11191
11192 \backslash
11193 /
11194 \end_layout
11195
11196 \end_inset
11197
11198 -vc
11199 \begin_inset LatexCommand index
11200 name "-\\/-vc"
11201
11202 \end_inset
11203
11204
11205 \series default
11206  Display errors and warnings using MSVC style, so you can use SDCC with
11207  the visual studio IDE
11208 \begin_inset LatexCommand index
11209 name "IDE"
11210
11211 \end_inset
11212
11213 .
11214  With SDCC both offering a GCC-like (the default) and a MSVC-like
11215 \begin_inset LatexCommand index
11216 name "MSVC output style"
11217
11218 \end_inset
11219
11220  output style, integration into most programming editors should be straightforwa
11221 rd.
11222 \end_layout
11223
11224 \begin_layout List
11225 \labelwidthstring 00.00.0000
11226
11227 \series bold
11228 -
11229 \begin_inset ERT
11230 status collapsed
11231
11232 \begin_layout Standard
11233
11234
11235 \backslash
11236 /
11237 \end_layout
11238
11239 \end_inset
11240
11241 -use-stdout
11242 \begin_inset LatexCommand index
11243 name "-\\/-use-stdout"
11244
11245 \end_inset
11246
11247
11248 \series default
11249  Send errors and warnings to stdout instead of stderr.
11250 \end_layout
11251
11252 \begin_layout List
11253 \labelwidthstring 00.00.0000
11254
11255 \series bold
11256 -Wa\InsetSpace ~
11257 asmOption[,asmOption]
11258 \series default
11259
11260 \begin_inset LatexCommand index
11261 name "-Wa asmOption[,asmOption]"
11262
11263 \end_inset
11264
11265 ...
11266  Pass the asmOption to the assembler
11267 \begin_inset LatexCommand index
11268 name "Options assembler"
11269
11270 \end_inset
11271
11272
11273 \begin_inset LatexCommand index
11274 name "Assembler options"
11275
11276 \end_inset
11277
11278 .
11279  See file sdcc/as/doc/asxhtm.html for assembler options.cd
11280 \end_layout
11281
11282 \begin_layout List
11283 \labelwidthstring 00.00.0000
11284
11285 \series bold
11286 -
11287 \begin_inset ERT
11288 status collapsed
11289
11290 \begin_layout Standard
11291
11292
11293 \backslash
11294 /
11295 \end_layout
11296
11297 \end_inset
11298
11299 -std-sdcc89
11300 \begin_inset LatexCommand index
11301 name "-\\/-std-sdcc89"
11302
11303 \end_inset
11304
11305
11306 \series default
11307  Generally follow the C89 standard, but allow SDCC features that conflict
11308  with the standard (default).
11309 \end_layout
11310
11311 \begin_layout List
11312 \labelwidthstring 00.00.0000
11313
11314 \series bold
11315 -
11316 \begin_inset ERT
11317 status collapsed
11318
11319 \begin_layout Standard
11320
11321
11322 \backslash
11323 /
11324 \end_layout
11325
11326 \end_inset
11327
11328 -std-c89
11329 \begin_inset LatexCommand index
11330 name "-\\/-std-c89"
11331
11332 \end_inset
11333
11334
11335 \series default
11336  Follow the C89 standard and disable SDCC features that conflict with the
11337  standard.
11338 \end_layout
11339
11340 \begin_layout List
11341 \labelwidthstring 00.00.0000
11342
11343 \series bold
11344 -
11345 \begin_inset ERT
11346 status collapsed
11347
11348 \begin_layout Standard
11349
11350
11351 \backslash
11352 /
11353 \end_layout
11354
11355 \end_inset
11356
11357 -std-sdcc99
11358 \begin_inset LatexCommand index
11359 name "-\\/-std-sdcc99"
11360
11361 \end_inset
11362
11363
11364 \series default
11365  Generally follow the C99 standard, but allow SDCC features that conflict
11366  with the standard (incomplete support).
11367 \end_layout
11368
11369 \begin_layout List
11370 \labelwidthstring 00.00.0000
11371
11372 \series bold
11373 -
11374 \begin_inset ERT
11375 status collapsed
11376
11377 \begin_layout Standard
11378
11379
11380 \backslash
11381 /
11382 \end_layout
11383
11384 \end_inset
11385
11386 -std-c99
11387 \begin_inset LatexCommand index
11388 name "-\\/-std-sdcc99"
11389
11390 \end_inset
11391
11392
11393 \series default
11394  Follow the C99 standard and disable SDCC features that conflict with the
11395  standard (incomplete support).
11396 \end_layout
11397
11398 \begin_layout List
11399 \labelwidthstring 00.00.0000
11400
11401 \series bold
11402 -
11403 \begin_inset ERT
11404 status collapsed
11405
11406 \begin_layout Standard
11407
11408
11409 \backslash
11410 /
11411 \end_layout
11412
11413 \end_inset
11414
11415 -codeseg
11416 \series default
11417
11418 \begin_inset LatexCommand index
11419 name "-\\/-codeseg <Value>"
11420
11421 \end_inset
11422
11423
11424 \begin_inset LatexCommand label
11425 name "lyx:-codeseg"
11426
11427 \end_inset
11428
11429 \InsetSpace ~
11430 <Name> The name to be used for the code
11431 \begin_inset LatexCommand index
11432 name "code"
11433
11434 \end_inset
11435
11436  segment, default CSEG.
11437  This is useful if you need to tell the compiler to put the code in a special
11438  segment so you can later on tell the linker to put this segment in a special
11439  place in memory.
11440  Can be used for instance when using bank switching to put the code in a
11441  bank.
11442 \end_layout
11443
11444 \begin_layout List
11445 \labelwidthstring 00.00.0000
11446
11447 \series bold
11448 -
11449 \begin_inset ERT
11450 status collapsed
11451
11452 \begin_layout Standard
11453
11454
11455 \backslash
11456 /
11457 \end_layout
11458
11459 \end_inset
11460
11461 -constseg
11462 \series default
11463
11464 \begin_inset LatexCommand index
11465 name "-\\/-constseg <Value>"
11466
11467 \end_inset
11468
11469 \InsetSpace ~
11470 <Name> The name to be used for the const
11471 \begin_inset LatexCommand index
11472 name "const"
11473
11474 \end_inset
11475
11476  segment, default CONST.
11477  This is useful if you need to tell the compiler to put the const data in
11478  a special segment so you can later on tell the linker to put this segment
11479  in a special place in memory.
11480  Can be used for instance when using bank switching to put the const data
11481  in a bank.
11482 \end_layout
11483
11484 \begin_layout List
11485 \labelwidthstring 00.00.0000
11486
11487 \series bold
11488 -
11489 \begin_inset ERT
11490 status collapsed
11491
11492 \begin_layout Standard
11493
11494
11495 \backslash
11496 /
11497 \end_layout
11498
11499 \end_inset
11500
11501 -fdollars-in-identifiers
11502 \begin_inset LatexCommand index
11503 name "-\\/-fdollars-in-identifiers"
11504
11505 \end_inset
11506
11507
11508 \series default
11509  Permit '$' as an identifier character.
11510 \end_layout
11511
11512 \begin_layout List
11513 \labelwidthstring 00.00.0000
11514
11515 \series bold
11516 -
11517 \begin_inset ERT
11518 status collapsed
11519
11520 \begin_layout Standard
11521
11522
11523 \backslash
11524 /
11525 \end_layout
11526
11527 \end_inset
11528
11529 -more-pedantic
11530 \series default
11531
11532 \begin_inset LatexCommand index
11533 name "-\\/-more-pedantic"
11534
11535 \end_inset
11536
11537
11538 \begin_inset LatexCommand index
11539 name "pedantic"
11540
11541 \end_inset
11542
11543  Actually this is 
11544 \series bold
11545 \emph on
11546 not
11547 \series default
11548 \emph default
11549  a SDCC compiler option but if you want 
11550 \emph on
11551 more
11552 \emph default
11553  warnings you can use a separate tool dedicated to syntax checking like
11554  splint
11555 \begin_inset LatexCommand label
11556 name "lyx:more-pedantic-SPLINT"
11557
11558 \end_inset
11559
11560
11561 \begin_inset LatexCommand index
11562 name "lint (syntax checking tool)"
11563
11564 \end_inset
11565
11566  
11567 \begin_inset LatexCommand url
11568 target "http://www.splint.org"
11569
11570 \end_inset
11571
11572 .
11573  To make your source files parseable by splint you will have to include
11574  
11575 \family sans
11576 lint.h
11577 \family default
11578
11579 \begin_inset LatexCommand index
11580 name "splint (syntax checking tool)"
11581
11582 \end_inset
11583
11584  in your source file and add brackets around extended keywords (like 
11585 \family sans
11586
11587 \begin_inset Quotes sld
11588 \end_inset
11589
11590 __at\InsetSpace ~
11591
11592 \series bold
11593 (
11594 \series default
11595 0xab
11596 \series bold
11597 )
11598 \series default
11599
11600 \begin_inset Quotes srd
11601 \end_inset
11602
11603
11604 \family default
11605  and 
11606 \family sans
11607
11608 \begin_inset Quotes sld
11609 \end_inset
11610
11611 __interrupt\InsetSpace ~
11612 (2)
11613 \begin_inset Quotes srd
11614 \end_inset
11615
11616
11617 \family default
11618 ).
11619  
11620 \newline
11621 Splint has an excellent on line manual at 
11622 \begin_inset LatexCommand url
11623 target "http://www.splint.org/manual/"
11624
11625 \end_inset
11626
11627  and it's capabilities go beyond pure syntax checking.
11628  You'll need to tell splint the location of SDCC's include files so a typical
11629  command line could look like this: 
11630 \newline
11631
11632 \family sans
11633 splint\InsetSpace ~
11634 -I\InsetSpace ~
11635 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
11636 \InsetSpace ~
11637 myprogram.c
11638 \end_layout
11639
11640 \begin_layout List
11641 \labelwidthstring 00.00.0000
11642
11643 \series bold
11644 -
11645 \begin_inset ERT
11646 status collapsed
11647
11648 \begin_layout Standard
11649
11650
11651 \backslash
11652 /
11653 \end_layout
11654
11655 \end_inset
11656
11657 -short-is-8bits
11658 \series default
11659
11660 \begin_inset LatexCommand index
11661 name "-\\/-short-is-8bits"
11662
11663 \end_inset
11664
11665
11666 \begin_inset LatexCommand label
11667 name "lyx:--short-is-8bits"
11668
11669 \end_inset
11670
11671  Treat short as 8-bit (for backward compatibility with older versions of
11672  compiler - see section 
11673 \begin_inset LatexCommand ref
11674 reference "sec:Compatibility-with-previous"
11675
11676 \end_inset
11677
11678 )
11679 \end_layout
11680
11681 \begin_layout Standard
11682 \begin_inset VSpace bigskip
11683 \end_inset
11684
11685
11686 \end_layout
11687
11688 \begin_layout Subsection
11689 Intermediate Dump Options
11690 \begin_inset LatexCommand label
11691 name "sub:Intermediate-Dump-Options"
11692
11693 \end_inset
11694
11695
11696 \begin_inset LatexCommand index
11697 name "Options intermediate dump"
11698
11699 \end_inset
11700
11701
11702 \begin_inset LatexCommand index
11703 name "Intermediate dump options"
11704
11705 \end_inset
11706
11707
11708 \end_layout
11709
11710 \begin_layout Standard
11711 The following options are provided for the purpose of retargetting and debugging
11712  the compiler.
11713  They provide a means to dump the intermediate code (iCode
11714 \begin_inset LatexCommand index
11715 name "iCode"
11716
11717 \end_inset
11718
11719 ) generated by the compiler in human readable form at various stages of
11720  the compilation process.
11721  More on iCodes see chapter 
11722 \begin_inset LatexCommand ref
11723 reference "sub:The-anatomy-of"
11724
11725 \end_inset
11726
11727  
11728 \begin_inset Quotes srd
11729 \end_inset
11730
11731 The anatomy of the compiler
11732 \begin_inset Quotes srd
11733 \end_inset
11734
11735 .
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 -dumpraw
11756 \begin_inset LatexCommand index
11757 name "-\\/-dumpraw"
11758
11759 \end_inset
11760
11761
11762 \series default
11763  This option will cause the compiler to dump the intermediate code into
11764  a file of named 
11765 \emph on
11766 <source filename>.dumpraw
11767 \emph default
11768  just after the intermediate code has been generated for a function, i.e.
11769  before any optimizations are done.
11770  The basic blocks
11771 \begin_inset LatexCommand index
11772 name "Basic blocks"
11773
11774 \end_inset
11775
11776  at this stage ordered in the depth first number, so they may not be in
11777  sequence of execution.
11778 \end_layout
11779
11780 \begin_layout List
11781 \labelwidthstring 00.00.0000
11782
11783 \series bold
11784 -
11785 \begin_inset ERT
11786 status collapsed
11787
11788 \begin_layout Standard
11789
11790
11791 \backslash
11792 /
11793 \end_layout
11794
11795 \end_inset
11796
11797 -dumpgcse
11798 \begin_inset LatexCommand index
11799 name "-\\/-dumpgcse"
11800
11801 \end_inset
11802
11803
11804 \series default
11805  Will create a dump of iCodes, after global subexpression elimination
11806 \begin_inset LatexCommand index
11807 name "Global subexpression elimination"
11808
11809 \end_inset
11810
11811 , into a file named 
11812 \emph on
11813 <source filename>.dumpgcse.
11814 \end_layout
11815
11816 \begin_layout List
11817 \labelwidthstring 00.00.0000
11818
11819 \series bold
11820 -
11821 \begin_inset ERT
11822 status collapsed
11823
11824 \begin_layout Standard
11825
11826
11827 \backslash
11828 /
11829 \end_layout
11830
11831 \end_inset
11832
11833 -dumpdeadcode
11834 \begin_inset LatexCommand index
11835 name "-\\/-dumpdeadcode"
11836
11837 \end_inset
11838
11839
11840 \series default
11841  Will create a dump of iCodes, after deadcode elimination
11842 \begin_inset LatexCommand index
11843 name "Dead-code elimination"
11844
11845 \end_inset
11846
11847 , into a file named 
11848 \emph on
11849 <source filename>.dumpdeadcode.
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 -dumploop
11870 \begin_inset LatexCommand index
11871 name "-\\/-dumploop"
11872
11873 \end_inset
11874
11875
11876 \series default
11877 \size large
11878  
11879 \size default
11880 Will create a dump of iCodes, after loop optimizations
11881 \begin_inset LatexCommand index
11882 name "Loop optimization"
11883
11884 \end_inset
11885
11886 , into a file named 
11887 \emph on
11888 <source filename>.dumploop.
11889 \end_layout
11890
11891 \begin_layout List
11892 \labelwidthstring 00.00.0000
11893
11894 \series bold
11895 -
11896 \begin_inset ERT
11897 status collapsed
11898
11899 \begin_layout Standard
11900
11901
11902 \backslash
11903 /
11904 \end_layout
11905
11906 \end_inset
11907
11908 -dumprange
11909 \begin_inset LatexCommand index
11910 name "-\\/-dumprange"
11911
11912 \end_inset
11913
11914
11915 \series default
11916 \size large
11917  
11918 \size default
11919 Will create a dump of iCodes, after live range analysis
11920 \begin_inset LatexCommand index
11921 name "Live range analysis"
11922
11923 \end_inset
11924
11925 , into a file named 
11926 \emph on
11927 <source filename>.dumprange.
11928 \end_layout
11929
11930 \begin_layout List
11931 \labelwidthstring 00.00.0000
11932
11933 \series bold
11934 -
11935 \begin_inset ERT
11936 status collapsed
11937
11938 \begin_layout Standard
11939
11940
11941 \backslash
11942 /
11943 \end_layout
11944
11945 \end_inset
11946
11947 -dumlrange
11948 \begin_inset LatexCommand index
11949 name "-\\/-dumlrange"
11950
11951 \end_inset
11952
11953
11954 \series default
11955  Will dump the life ranges
11956 \begin_inset LatexCommand index
11957 name "Live range analysis"
11958
11959 \end_inset
11960
11961  for all symbols.
11962 \end_layout
11963
11964 \begin_layout List
11965 \labelwidthstring 00.00.0000
11966
11967 \series bold
11968 -
11969 \begin_inset ERT
11970 status collapsed
11971
11972 \begin_layout Standard
11973
11974
11975 \backslash
11976 /
11977 \end_layout
11978
11979 \end_inset
11980
11981 -dumpregassign
11982 \begin_inset LatexCommand index
11983 name "-\\/-dumpregassign"
11984
11985 \end_inset
11986
11987  
11988 \series default
11989 Will create a dump of iCodes, after register assignment
11990 \begin_inset LatexCommand index
11991 name "Register assignment"
11992
11993 \end_inset
11994
11995 , into a file named 
11996 \emph on
11997 <source filename>.dumprassgn.
11998 \end_layout
11999
12000 \begin_layout List
12001 \labelwidthstring 00.00.0000
12002
12003 \series bold
12004 -
12005 \begin_inset ERT
12006 status collapsed
12007
12008 \begin_layout Standard
12009
12010
12011 \backslash
12012 /
12013 \end_layout
12014
12015 \end_inset
12016
12017 -dumplrange
12018 \begin_inset LatexCommand index
12019 name "-\\/-dumplrange"
12020
12021 \end_inset
12022
12023
12024 \series default
12025  Will create a dump of the live ranges of iTemp's
12026 \end_layout
12027
12028 \begin_layout List
12029 \labelwidthstring 00.00.0000
12030
12031 \series bold
12032 -
12033 \begin_inset ERT
12034 status collapsed
12035
12036 \begin_layout Standard
12037
12038
12039 \backslash
12040 /
12041 \end_layout
12042
12043 \end_inset
12044
12045 -dumpall
12046 \begin_inset LatexCommand index
12047 name "-\\/-dumpall"
12048
12049 \end_inset
12050
12051
12052 \size large
12053  
12054 \series default
12055 \size default
12056 Will cause all the above mentioned dumps to be created.
12057 \end_layout
12058
12059 \begin_layout Standard
12060 \begin_inset VSpace bigskip
12061 \end_inset
12062
12063
12064 \end_layout
12065
12066 \begin_layout Subsection
12067 Redirecting output on Windows Shells
12068 \end_layout
12069
12070 \begin_layout Standard
12071 By default SDCC writes its error messages to 
12072 \begin_inset Quotes sld
12073 \end_inset
12074
12075 standard error
12076 \begin_inset Quotes srd
12077 \end_inset
12078
12079 .
12080  To force all messages to 
12081 \begin_inset Quotes sld
12082 \end_inset
12083
12084 standard output
12085 \begin_inset Quotes srd
12086 \end_inset
12087
12088  use 
12089 \series bold
12090 -
12091 \series default
12092 \emph on
12093
12094 \begin_inset ERT
12095 status collapsed
12096
12097 \begin_layout Standard
12098
12099
12100 \backslash
12101 /
12102 \end_layout
12103
12104 \end_inset
12105
12106
12107 \series bold
12108 \emph default
12109 -
12110 \series default
12111 use-stdout
12112 \begin_inset LatexCommand index
12113 name "-\\/-use-stdout"
12114
12115 \end_inset
12116
12117 .
12118  Additionally, if you happen to have visual studio installed in your windows
12119  machine, you can use it to compile your sources using a custom build and
12120  the SDCC -
12121 \emph on
12122
12123 \begin_inset ERT
12124 status collapsed
12125
12126 \begin_layout Standard
12127
12128
12129 \backslash
12130 /
12131 \end_layout
12132
12133 \end_inset
12134
12135
12136 \emph default
12137 -vc
12138 \begin_inset LatexCommand index
12139 name "-\\/-vc"
12140
12141 \end_inset
12142
12143  option.
12144  Something like this should work:
12145 \newline
12146
12147 \newline
12148
12149 \series bold
12150 c:
12151 \backslash
12152 sdcc
12153 \backslash
12154 bin
12155 \backslash
12156 sdcc.exe -
12157 \series default
12158 \emph on
12159
12160 \begin_inset ERT
12161 status collapsed
12162
12163 \begin_layout Standard
12164
12165
12166 \backslash
12167 /
12168 \end_layout
12169
12170 \end_inset
12171
12172
12173 \series bold
12174 \emph default
12175 -vc -
12176 \series default
12177 \emph on
12178
12179 \begin_inset ERT
12180 status collapsed
12181
12182 \begin_layout Standard
12183
12184
12185 \backslash
12186 /
12187 \end_layout
12188
12189 \end_inset
12190
12191
12192 \series bold
12193 \emph default
12194 -model-large -c $(InputPath)
12195 \series default
12196
12197 \begin_inset VSpace bigskip
12198 \end_inset
12199
12200
12201 \end_layout
12202
12203 \begin_layout Section
12204 Environment variables
12205 \begin_inset LatexCommand index
12206 name "Environment variables"
12207
12208 \end_inset
12209
12210
12211 \end_layout
12212
12213 \begin_layout Standard
12214 SDCC recognizes the following environment variables:
12215 \end_layout
12216
12217 \begin_layout List
12218 \labelwidthstring 00.00.0000
12219
12220 \series bold
12221 SDCC_LEAVE_SIGNALS
12222 \begin_inset LatexCommand index
12223 name "SDCC\\_LEAVE\\_SIGNALS"
12224
12225 \end_inset
12226
12227
12228 \series default
12229  SDCC installs a signal handler
12230 \begin_inset LatexCommand index
12231 name "signal handler"
12232
12233 \end_inset
12234
12235  to be able to delete temporary files after an user break (^C) or an exception.
12236  If this environment variable is set, SDCC won't install the signal handler
12237  in order to be able to debug SDCC.
12238 \end_layout
12239
12240 \begin_layout List
12241 \labelwidthstring 00.00.0000
12242
12243 \series bold
12244 TMP,\InsetSpace ~
12245 TEMP,\InsetSpace ~
12246 TMPDIR
12247 \begin_inset LatexCommand index
12248 name "TMP, TEMP, TMPDIR"
12249
12250 \end_inset
12251
12252
12253 \series default
12254  Path, where temporary files will be created.
12255  The order of the variables is the search order.
12256  In a standard *nix environment these variables are not set, and there's
12257  no need to set them.
12258  On Windows it's recommended to set one of them.
12259 \end_layout
12260
12261 \begin_layout List
12262 \labelwidthstring 00.00.0000
12263
12264 \series bold
12265 SDCC_HOME
12266 \begin_inset LatexCommand index
12267 name "SDCC\\_HOME"
12268
12269 \end_inset
12270
12271
12272 \series default
12273  Path, see section 
12274 \begin_inset LatexCommand ref
12275 reference "sub:Install-paths"
12276
12277 \end_inset
12278
12279 \InsetSpace ~
12280
12281 \begin_inset Quotes sld
12282 \end_inset
12283
12284  Install Paths
12285 \begin_inset Quotes srd
12286 \end_inset
12287
12288 .
12289 \end_layout
12290
12291 \begin_layout List
12292 \labelwidthstring 00.00.0000
12293
12294 \series bold
12295 SDCC_INCLUDE
12296 \begin_inset LatexCommand index
12297 name "SDCC\\_INCLUDE"
12298
12299 \end_inset
12300
12301
12302 \series default
12303  Path, see section 
12304 \begin_inset LatexCommand ref
12305 reference "sub:Search-Paths"
12306
12307 \end_inset
12308
12309 \InsetSpace ~
12310
12311 \begin_inset Quotes sld
12312 \end_inset
12313
12314 Search Paths
12315 \begin_inset Quotes srd
12316 \end_inset
12317
12318 .
12319 \end_layout
12320
12321 \begin_layout List
12322 \labelwidthstring 00.00.0000
12323
12324 \series bold
12325 SDCC_LIB
12326 \begin_inset LatexCommand index
12327 name "SDCC\\_LIB"
12328
12329 \end_inset
12330
12331
12332 \series default
12333  Path, see section 
12334 \begin_inset LatexCommand ref
12335 reference "sub:Search-Paths"
12336
12337 \end_inset
12338
12339 \InsetSpace ~
12340
12341 \begin_inset Quotes sld
12342 \end_inset
12343
12344 Search Paths
12345 \begin_inset Quotes srd
12346 \end_inset
12347
12348 ..
12349 \end_layout
12350
12351 \begin_layout Standard
12352 There are some more environment variables recognized by SDCC, but these
12353  are solely used for debugging purposes.
12354  They can change or disappear very quickly, and will never be documented.
12355 \begin_inset VSpace bigskip
12356 \end_inset
12357
12358
12359 \end_layout
12360
12361 \begin_layout Section
12362 Storage Class Language Extensions
12363 \end_layout
12364
12365 \begin_layout Subsection
12366 MCS51/DS390 Storage Class
12367 \begin_inset LatexCommand index
12368 name "Storage class"
12369
12370 \end_inset
12371
12372  Language Extensions
12373 \end_layout
12374
12375 \begin_layout Standard
12376 In addition to the ANSI storage classes SDCC allows the following MCS51
12377  specific storage classes:
12378 \end_layout
12379
12380 \begin_layout Subsubsection
12381 data
12382 \begin_inset LatexCommand index
12383 name "data (mcs51, ds390 storage class)"
12384
12385 \end_inset
12386
12387
12388 \begin_inset LatexCommand index
12389 name "\\_\\_data (mcs51, ds390 storage class)"
12390
12391 \end_inset
12392
12393  / near
12394 \begin_inset LatexCommand index
12395 name "near (storage class)"
12396
12397 \end_inset
12398
12399
12400 \begin_inset LatexCommand index
12401 name "\\_\\_near (storage class)"
12402
12403 \end_inset
12404
12405
12406 \end_layout
12407
12408 \begin_layout Standard
12409 This is the 
12410 \series bold
12411 default
12412 \series default
12413  storage class for the Small Memory model (
12414 \emph on
12415 data
12416 \emph default
12417  and 
12418 \emph on
12419 near
12420 \emph default
12421  or the more ANSI-C compliant forms 
12422 \emph on
12423 __data
12424 \emph default
12425  and 
12426 \emph on
12427 __near
12428 \emph default
12429  can be used synonymously).
12430  Variables declared with this storage class will be allocated in the directly
12431  addressable portion of the internal RAM of a 8051, e.g.:
12432 \end_layout
12433
12434 \begin_layout Verse
12435
12436 \family typewriter
12437 __data unsigned char test_data;
12438 \end_layout
12439
12440 \begin_layout Standard
12441 Writing 0x01 to this variable generates the assembly code:
12442 \end_layout
12443
12444 \begin_layout Verse
12445
12446 \family typewriter
12447 75*00 01\InsetSpace ~
12448 \InsetSpace ~
12449 \InsetSpace ~
12450 mov\InsetSpace ~
12451 \InsetSpace ~
12452 _test_data,#0x01
12453 \end_layout
12454
12455 \begin_layout Subsubsection
12456 xdata
12457 \begin_inset LatexCommand index
12458 name "xdata (mcs51, ds390 storage class)"
12459
12460 \end_inset
12461
12462
12463 \begin_inset LatexCommand index
12464 name "\\_\\_xdata (mcs51, ds390 storage class)"
12465
12466 \end_inset
12467
12468  / far
12469 \begin_inset LatexCommand index
12470 name "far (storage class)"
12471
12472 \end_inset
12473
12474
12475 \begin_inset LatexCommand index
12476 name "\\_\\_far (storage class)"
12477
12478 \end_inset
12479
12480
12481 \end_layout
12482
12483 \begin_layout Standard
12484 Variables declared with this storage class will be placed in the external
12485  RAM.
12486  This is the 
12487 \series bold
12488 default
12489 \series default
12490  storage class for the Large Memory model, e.g.:
12491 \end_layout
12492
12493 \begin_layout Verse
12494
12495 \family typewriter
12496 __xdata unsigned char test_xdata;
12497 \end_layout
12498
12499 \begin_layout Standard
12500 Writing 0x01 to this variable generates the assembly code:
12501 \end_layout
12502
12503 \begin_layout Verse
12504
12505 \family typewriter
12506 90s00r00\InsetSpace ~
12507 \InsetSpace ~
12508 \InsetSpace ~
12509 mov\InsetSpace ~
12510 \InsetSpace ~
12511 dptr,#_test_xdata 
12512 \newline
12513 74\InsetSpace ~
12514 01\InsetSpace ~
12515 \InsetSpace ~
12516 \InsetSpace ~
12517 \InsetSpace ~
12518 \InsetSpace ~
12519 \InsetSpace ~
12520 mov\InsetSpace ~
12521 \InsetSpace ~
12522 a,#0x01 
12523 \newline
12524 F0\InsetSpace ~
12525 \InsetSpace ~
12526 \InsetSpace ~
12527 \InsetSpace ~
12528 \InsetSpace ~
12529 \InsetSpace ~
12530 \InsetSpace ~
12531 \InsetSpace ~
12532 \InsetSpace ~
12533 movx\InsetSpace ~
12534 @dptr,a 
12535 \end_layout
12536
12537 \begin_layout Subsubsection
12538 idata
12539 \begin_inset LatexCommand index
12540 name "idata (mcs51, ds390 storage class)"
12541
12542 \end_inset
12543
12544
12545 \begin_inset LatexCommand index
12546 name "\\_\\_idata (mcs51, ds390 storage class)"
12547
12548 \end_inset
12549
12550
12551 \end_layout
12552
12553 \begin_layout Standard
12554 Variables declared with this storage class will be allocated into the indirectly
12555  addressable portion of the internal ram of a 8051, e.g.:
12556 \end_layout
12557
12558 \begin_layout Verse
12559
12560 \family typewriter
12561 __idata unsigned char test_idata;
12562 \end_layout
12563
12564 \begin_layout Standard
12565 Writing 0x01 to this variable generates the assembly code:
12566 \end_layout
12567
12568 \begin_layout Verse
12569
12570 \family typewriter
12571 78r00\InsetSpace ~
12572 \InsetSpace ~
12573 \InsetSpace ~
12574 \InsetSpace ~
12575 \InsetSpace ~
12576 \InsetSpace ~
12577 \InsetSpace ~
12578 mov\InsetSpace ~
12579 \InsetSpace ~
12580 r0,#_test_idata
12581 \newline
12582 76\InsetSpace ~
12583 01\InsetSpace ~
12584 \InsetSpace ~
12585 \InsetSpace ~
12586 \InsetSpace ~
12587 \InsetSpace ~
12588 \InsetSpace ~
12589 \InsetSpace ~
12590 mov\InsetSpace ~
12591 \InsetSpace ~
12592 @r0,#0x01
12593 \end_layout
12594
12595 \begin_layout Standard
12596 Please note, the first 128 byte of idata physically access the same RAM
12597  as the data memory.
12598  The original 8051 had 128 byte idata memory, nowadays most devices have
12599  256 byte idata memory.
12600  The stack
12601 \begin_inset LatexCommand index
12602 name "stack"
12603
12604 \end_inset
12605
12606  is located in idata memory.
12607 \end_layout
12608
12609 \begin_layout Subsubsection
12610 pdata
12611 \begin_inset LatexCommand index
12612 name "pdata (mcs51, ds390 storage class)"
12613
12614 \end_inset
12615
12616
12617 \begin_inset LatexCommand index
12618 name "\\_\\_pdata (mcs51, ds390 storage class)"
12619
12620 \end_inset
12621
12622
12623 \end_layout
12624
12625 \begin_layout Standard
12626 Paged xdata access is just as straightforward as using the other addressing
12627  modes of a 8051.
12628  It is typically located at the start of xdata and has a maximum size of
12629  256 bytes.
12630  The following example writes 0x01 to the pdata variable.
12631  Please note, pdata access physically accesses xdata memory.
12632  The high byte of the address is determined by port P2 
12633 \begin_inset LatexCommand index
12634 name "P2 (mcs51 sfr)"
12635
12636 \end_inset
12637
12638 (or in case of some 8051 variants by a separate Special Function Register,
12639  see section 
12640 \begin_inset LatexCommand ref
12641 reference "sub:MCS51-variants"
12642
12643 \end_inset
12644
12645 ).
12646  This is the 
12647 \series bold
12648 default
12649 \series default
12650  storage class for the Medium Memory model, e.g.:
12651 \end_layout
12652
12653 \begin_layout Verse
12654
12655 \family typewriter
12656 __pdata unsigned char test_pdata;
12657 \end_layout
12658
12659 \begin_layout Standard
12660 Writing 0x01 to this variable generates the assembly code:
12661 \end_layout
12662
12663 \begin_layout Verse
12664
12665 \family typewriter
12666 78r00\InsetSpace ~
12667 \InsetSpace ~
12668 \InsetSpace ~
12669 \InsetSpace ~
12670 \InsetSpace ~
12671 \InsetSpace ~
12672 mov r0,#_test_pdata
12673 \newline
12674 74 01\InsetSpace ~
12675 \InsetSpace ~
12676 \InsetSpace ~
12677 \InsetSpace ~
12678 \InsetSpace ~
12679 \InsetSpace ~
12680 mov a,#0x01 
12681 \newline
12682 F2\InsetSpace ~
12683 \InsetSpace ~
12684 \InsetSpace ~
12685 \InsetSpace ~
12686 \InsetSpace ~
12687 \InsetSpace ~
12688 \InsetSpace ~
12689 \InsetSpace ~
12690 \InsetSpace ~
12691 movx @r0,a
12692 \end_layout
12693
12694 \begin_layout Standard
12695 If the -
12696 \begin_inset ERT
12697 status collapsed
12698
12699 \begin_layout Standard
12700
12701
12702 \backslash
12703 /
12704 \end_layout
12705
12706 \end_inset
12707
12708 -xstack
12709 \begin_inset LatexCommand index
12710 name "-\\/-xstack"
12711
12712 \end_inset
12713
12714  option is used the pdata memory area is followed by the xstack memory area
12715  and the sum of their sizes is limited to 256 bytes.
12716 \end_layout
12717
12718 \begin_layout Subsubsection
12719 code
12720 \begin_inset LatexCommand index
12721 name "code"
12722
12723 \end_inset
12724
12725
12726 \begin_inset LatexCommand index
12727 name "\\_\\_code"
12728
12729 \end_inset
12730
12731
12732 \end_layout
12733
12734 \begin_layout Standard
12735 'Variables' declared with this storage class will be placed in the code
12736  memory:
12737 \end_layout
12738
12739 \begin_layout Verse
12740
12741 \family typewriter
12742 __code unsigned char test_code;
12743 \end_layout
12744
12745 \begin_layout Standard
12746 Read access to this variable generates the assembly code:
12747 \end_layout
12748
12749 \begin_layout Verse
12750
12751 \family typewriter
12752 90s00r6F\InsetSpace ~
12753 \InsetSpace ~
12754 \InsetSpace ~
12755 mov dptr,#_test_code
12756 \newline
12757 E4\InsetSpace ~
12758 \InsetSpace ~
12759 \InsetSpace ~
12760 \InsetSpace ~
12761 \InsetSpace ~
12762 \InsetSpace ~
12763 \InsetSpace ~
12764 \InsetSpace ~
12765 \InsetSpace ~
12766 clr a
12767 \newline
12768 93\InsetSpace ~
12769 \InsetSpace ~
12770 \InsetSpace ~
12771 \InsetSpace ~
12772 \InsetSpace ~
12773 \InsetSpace ~
12774 \InsetSpace ~
12775 \InsetSpace ~
12776 \InsetSpace ~
12777 movc a,@a+dptr 
12778 \end_layout
12779
12780 \begin_layout Standard
12781
12782 \family typewriter
12783 char
12784 \family default
12785  indexed arrays of characters in code memory can be accessed efficiently:
12786 \end_layout
12787
12788 \begin_layout Verse
12789
12790 \family typewriter
12791 __code char test_array[] = {'c','h','e','a','p'}; 
12792 \end_layout
12793
12794 \begin_layout Standard
12795 Read access to this array using an 8-bit unsigned index generates the assembly
12796  code:
12797 \end_layout
12798
12799 \begin_layout Verse
12800
12801 \family typewriter
12802 E5*00\InsetSpace ~
12803 \InsetSpace ~
12804 \InsetSpace ~
12805 \InsetSpace ~
12806 \InsetSpace ~
12807 \InsetSpace ~
12808 mov a,_index 
12809 \end_layout
12810
12811 \begin_layout Verse
12812
12813 \family typewriter
12814 90s00r41\InsetSpace ~
12815 \InsetSpace ~
12816 \InsetSpace ~
12817 mov dptr,#_test_array
12818 \end_layout
12819
12820 \begin_layout Verse
12821
12822 \family typewriter
12823 93\InsetSpace ~
12824 \InsetSpace ~
12825 \InsetSpace ~
12826 \InsetSpace ~
12827 \InsetSpace ~
12828 \InsetSpace ~
12829 \InsetSpace ~
12830 \InsetSpace ~
12831 \InsetSpace ~
12832 movc a,@a+dptr 
12833 \end_layout
12834
12835 \begin_layout Subsubsection
12836 bit
12837 \begin_inset LatexCommand index
12838 name "bit"
12839
12840 \end_inset
12841
12842
12843 \begin_inset LatexCommand index
12844 name "\\_\\_bit"
12845
12846 \end_inset
12847
12848
12849 \end_layout
12850
12851 \begin_layout Standard
12852 This is a data-type and a storage class specifier.
12853  When a variable is declared as a bit, it is allocated into the bit addressable
12854  memory of 8051, e.g.:
12855 \end_layout
12856
12857 \begin_layout Verse
12858
12859 \family typewriter
12860 __bit test_bit;
12861 \end_layout
12862
12863 \begin_layout Standard
12864 Writing 1 to this variable generates the assembly code:
12865 \end_layout
12866
12867 \begin_layout Verse
12868
12869 \family typewriter
12870 D2*00\InsetSpace ~
12871 \InsetSpace ~
12872 \InsetSpace ~
12873 \InsetSpace ~
12874 \InsetSpace ~
12875 \InsetSpace ~
12876 \InsetSpace ~
12877 setb\InsetSpace ~
12878 _test_bit
12879 \end_layout
12880
12881 \begin_layout Standard
12882 The bit addressable memory consists of 128 bits which are located from 0x20
12883  to 0x2f in data memory.
12884  
12885 \newline
12886 Apart from this 8051 specific storage class most architectures support
12887  ANSI-C bitfields
12888 \begin_inset LatexCommand index
12889 name "bitfields"
12890
12891 \end_inset
12892
12893
12894 \begin_inset Foot
12895 status open
12896
12897 \begin_layout Standard
12898 Not really meant as examples, but nevertheless showing what bitfields are
12899  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
12900 \end_layout
12901
12902 \end_inset
12903
12904 .
12905  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
12906  signed modifier are implemented as unsigned.
12907 \end_layout
12908
12909 \begin_layout Subsubsection
12910 sfr
12911 \begin_inset LatexCommand index
12912 name "sfr"
12913
12914 \end_inset
12915
12916
12917 \begin_inset LatexCommand index
12918 name "\\_\\_sfr"
12919
12920 \end_inset
12921
12922  / sfr16
12923 \begin_inset LatexCommand index
12924 name "sfr16"
12925
12926 \end_inset
12927
12928
12929 \begin_inset LatexCommand index
12930 name "\\_\\_sfr16"
12931
12932 \end_inset
12933
12934  / sfr32
12935 \begin_inset LatexCommand index
12936 name "sfr32"
12937
12938 \end_inset
12939
12940
12941 \begin_inset LatexCommand index
12942 name "\\_\\_sfr32"
12943
12944 \end_inset
12945
12946  / sbit
12947 \begin_inset LatexCommand index
12948 name "\\_\\_sbit"
12949
12950 \end_inset
12951
12952
12953 \begin_inset LatexCommand index
12954 name "sbit"
12955
12956 \end_inset
12957
12958
12959 \end_layout
12960
12961 \begin_layout Standard
12962 Like the bit keyword, 
12963 \emph on
12964 sfr / sfr16 / sfr32 / sbit
12965 \emph default
12966  signify both a data-type and storage class, they are used to describe the
12967  
12968 \emph on
12969 s
12970 \emph default
12971 pecial 
12972 \emph on
12973 f
12974 \emph default
12975 unction 
12976 \emph on
12977 r
12978 \emph default
12979 egisters and 
12980 \emph on
12981 s
12982 \emph default
12983 pecial 
12984 \emph on
12985 bit
12986 \emph default
12987  variables of a 8051, eg:
12988 \end_layout
12989
12990 \begin_layout Verse
12991
12992 \family typewriter
12993 __sfr __at
12994 \begin_inset LatexCommand index
12995 name "at"
12996
12997 \end_inset
12998
12999
13000 \begin_inset LatexCommand index
13001 name "\\_\\_at"
13002
13003 \end_inset
13004
13005  (0x80) P0;\InsetSpace ~
13006  /* special function register P0 at location 0x80 */
13007 \newline
13008
13009 \newline
13010 /* 16 bit
13011  special function register combination for timer 0
13012 \newline
13013 \InsetSpace ~
13014 \InsetSpace ~
13015  with the high byte at
13016  location 0x8C and the low byte at location 0x8A */
13017 \newline
13018 __sfr16 __at (0x8C8A)
13019  TMR0;
13020 \newline
13021
13022 \newline
13023 __sbit __at
13024 \begin_inset LatexCommand index
13025 name "at"
13026
13027 \end_inset
13028
13029
13030 \begin_inset LatexCommand index
13031 name "\\_\\_at"
13032
13033 \end_inset
13034
13035  (0xd7) CY;\InsetSpace ~
13036  /* CY (Carry Flag
13037 \begin_inset LatexCommand index
13038 name "Flags"
13039
13040 \end_inset
13041
13042
13043 \begin_inset LatexCommand index
13044 name "Carry flag"
13045
13046 \end_inset
13047
13048 ) */
13049 \end_layout
13050
13051 \begin_layout Standard
13052 Special function registers which are located on an address dividable by
13053  8 are bit-addressable, an 
13054 \emph on
13055 sbit
13056 \emph default
13057  addresses a specific bit within these sfr.
13058 \newline
13059 16 Bit and 32 bit special function
13060  register combinations which require a certain access order are better not
13061  declared using 
13062 \emph on
13063 sfr16
13064 \emph default
13065  or 
13066 \emph on
13067 sfr32.
13068
13069 \emph default
13070  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
13071  this is not guaranteed.
13072 \newline
13073
13074 \end_layout
13075
13076 \begin_layout Standard
13077 Please note, if you use a header file which was written for another compiler
13078  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
13079  likely be 
13080 \emph on
13081 not
13082 \emph default
13083  compatible.
13084  Specifically the syntax 
13085 \family typewriter
13086 \InsetSpace ~
13087 sfr P0 = 0x80;\InsetSpace ~
13088
13089 \family default
13090  is compiled 
13091 \emph on
13092 without warning
13093 \emph default
13094  by SDCC to an assignment of 0x80 to a variable called P0 
13095 \family typewriter
13096
13097 \begin_inset Marginal
13098 status collapsed
13099
13100 \begin_layout Standard
13101
13102 \series bold
13103 \InsetSpace ~
13104 !
13105 \end_layout
13106
13107 \end_inset
13108
13109 .
13110
13111 \family default
13112  
13113 \series bold
13114 Nevertheless it is possible to write header files
13115 \begin_inset LatexCommand index
13116 name "Header files"
13117
13118 \end_inset
13119
13120
13121 \begin_inset LatexCommand index
13122 name "Include files"
13123
13124 \end_inset
13125
13126  which can be shared among different compilers (see section 
13127 \begin_inset LatexCommand ref
13128 reference "sec:Porting-code-to-other-compilers"
13129
13130 \end_inset
13131
13132 ).
13133  
13134 \end_layout
13135
13136 \begin_layout Subsubsection
13137 Pointers
13138 \begin_inset LatexCommand index
13139 name "Pointer"
13140
13141 \end_inset
13142
13143  to MCS51/DS390 specific memory spaces
13144 \end_layout
13145
13146 \begin_layout Standard
13147 SDCC allows (via language extensions) pointers to explicitly point to any
13148  of the memory spaces
13149 \begin_inset LatexCommand index
13150 name "Memory model"
13151
13152 \end_inset
13153
13154  of the 8051.
13155  In addition to the explicit pointers, the compiler uses (by default) generic
13156  pointers which can be used to point to any of the memory spaces.
13157 \newline
13158
13159 \newline
13160 Pointer
13161  declaration examples:
13162 \end_layout
13163
13164 \begin_layout Verse
13165
13166 \family typewriter
13167 /* pointer physically in internal ram pointing to object in external ram
13168  */ 
13169 \newline
13170 __xdata unsigned char * __data p;
13171 \newline
13172
13173 \newline
13174 /* pointer physically in external ram
13175  pointing to object in internal ram */ 
13176 \newline
13177 __data unsigned char * __xdata p;
13178 \newline
13179
13180 \newline
13181 /*
13182  pointer physically in code rom pointing to data in xdata space */ 
13183 \newline
13184 __xdata
13185  unsigned char * __code p;
13186 \newline
13187
13188 \newline
13189 /* pointer physically in code space pointing to
13190  data in code space */ 
13191 \newline
13192 __code unsigned char * __code p;
13193 \newline
13194
13195 \newline
13196 /* generic pointer
13197  physically located in xdata space */
13198 \newline
13199 unsigned char * __xdata p;
13200 \newline
13201
13202 \newline
13203 /* generic
13204  pointer physically located in default memory space */
13205 \newline
13206 unsigned char * p;
13207 \newline
13208
13209 \newline
13210 /*
13211  the following is a function pointer
13212 \begin_inset LatexCommand index
13213 name "function pointer"
13214
13215 \end_inset
13216
13217  physically located in data space */
13218 \newline
13219 char (* __data fp)(void);
13220 \end_layout
13221
13222 \begin_layout Standard
13223 Well you get the idea.
13224  
13225 \newline
13226
13227 \newline
13228 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
13229 \emph on
13230 generic
13231 \emph default
13232  pointers.
13233  
13234 \size small
13235
13236 \newline
13237
13238 \newline
13239
13240 \size default
13241 The highest order byte of the 
13242 \emph on
13243 generic
13244 \emph default
13245  pointers contains the data space information.
13246  Assembler support routines are called whenever data is stored or retrieved
13247  using 
13248 \emph on
13249 generic
13250 \emph default
13251  pointers.
13252  These are useful for developing reusable library
13253 \begin_inset LatexCommand index
13254 name "Libraries"
13255
13256 \end_inset
13257
13258  routines.
13259  Explicitly specifying the pointer
13260 \begin_inset LatexCommand index
13261 name "pointer"
13262
13263 \end_inset
13264
13265  type will generate the most efficient code.
13266 \end_layout
13267
13268 \begin_layout Subsubsection
13269 Notes on MCS51 memory
13270 \begin_inset LatexCommand index
13271 name "MCS51 memory"
13272
13273 \end_inset
13274
13275  layout
13276 \end_layout
13277
13278 \begin_layout Standard
13279 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
13280  RAM memory which is structured as follows:
13281 \newline
13282
13283 \newline
13284 - Bytes 00-1F - 32 bytes to hold
13285  up to 4 banks of the registers R0 to R7, 
13286 \newline
13287 - Bytes 20-2F - 16 bytes to hold
13288  128 bit
13289 \begin_inset LatexCommand index
13290 name "bit"
13291
13292 \end_inset
13293
13294  variables and, 
13295 \newline
13296 - Bytes 30-7F - 80 bytes for general purpose use.
13297 \newline
13298
13299 \end_layout
13300
13301 \begin_layout Standard
13302 Additionally some members of the MCS51 family may have up to 128 bytes of
13303  additional, indirectly addressable, internal RAM memory (
13304 \emph on
13305 idata
13306 \emph default
13307
13308 \begin_inset LatexCommand index
13309 name "idata (mcs51, ds390 storage class)"
13310
13311 \end_inset
13312
13313
13314 \begin_inset LatexCommand index
13315 name "\\_\\_idata (mcs51, ds390 storage class)"
13316
13317 \end_inset
13318
13319 ).
13320  Furthermore, some chips may have some built in external memory (
13321 \emph on
13322 xdata
13323 \emph default
13324
13325 \begin_inset LatexCommand index
13326 name "xdata (mcs51, ds390 storage class)"
13327
13328 \end_inset
13329
13330
13331 \begin_inset LatexCommand index
13332 name "\\_\\_xdata (mcs51, ds390 storage class)"
13333
13334 \end_inset
13335
13336 ) which should not be confused with the internal, directly addressable RAM
13337  memory (
13338 \emph on
13339 data
13340 \emph default
13341
13342 \begin_inset LatexCommand index
13343 name "data (mcs51, ds390 storage class)"
13344
13345 \end_inset
13346
13347
13348 \begin_inset LatexCommand index
13349 name "\\_\\_data (mcs51, ds390 storage class)"
13350
13351 \end_inset
13352
13353 ).
13354  Sometimes this built in 
13355 \emph on
13356 xdata
13357 \emph default
13358  memory has to be activated before using it (you can probably find this
13359  information on the datasheet of the microcontroller your are using, see
13360  also section 
13361 \begin_inset LatexCommand ref
13362 reference "sub:Startup-Code"
13363
13364 \end_inset
13365
13366 \InsetSpace ~
13367 Startup-Code).
13368 \end_layout
13369
13370 \begin_layout Standard
13371 Normally SDCC will only use the first bank
13372 \begin_inset LatexCommand index
13373 name "register bank (mcs51, ds390)"
13374
13375 \end_inset
13376
13377  of registers (register bank 0), but it is possible to specify that other
13378  banks of registers (keyword 
13379 \emph on
13380 using
13381 \emph default
13382  
13383 \emph on
13384
13385 \begin_inset LatexCommand index
13386 name "using (mcs51, ds390 register bank)"
13387
13388 \end_inset
13389
13390
13391 \begin_inset LatexCommand index
13392 name "\\_\\_using (mcs51, ds390 register bank)"
13393
13394 \end_inset
13395
13396
13397 \emph default
13398 ) should be used for example in interrupt
13399 \begin_inset LatexCommand index
13400 name "interrupt"
13401
13402 \end_inset
13403
13404
13405 \begin_inset LatexCommand index
13406 name "\\_\\_interrupt"
13407
13408 \end_inset
13409
13410  routines.
13411  By default, the compiler will place the stack after the last byte of allocated
13412  memory for variables.
13413  For example, if the first 2 banks of registers are used, and only four
13414  bytes are used for 
13415 \emph on
13416 data
13417 \emph default
13418  variables, it will position the base of the internal stack at address 20
13419  (0x14).
13420  This implies that as the stack
13421 \begin_inset LatexCommand index
13422 name "stack"
13423
13424 \end_inset
13425
13426  grows, it will use up the remaining register banks, and the 16 bytes used
13427  by the 128 bit variables, and 80 bytes for general purpose use.
13428  If any bit variables are used, the data variables will be placed in unused
13429  register banks and after the byte holding the last bit variable.
13430  For example, if register banks 0 and 1 are used, and there are 9 bit variables
13431  (two bytes used), 
13432 \emph on
13433 data
13434 \emph default
13435  variables will be placed starting from address 0x10 to 0x20 and continue
13436  at address 0x22.
13437  You can also use -
13438 \begin_inset ERT
13439 status collapsed
13440
13441 \begin_layout Standard
13442
13443
13444 \backslash
13445 /
13446 \end_layout
13447
13448 \end_inset
13449
13450 -data-loc
13451 \begin_inset LatexCommand index
13452 name "-\\/-data-loc <Value>"
13453
13454 \end_inset
13455
13456  to specify the start address of the 
13457 \emph on
13458 data
13459 \emph default
13460  and -
13461 \begin_inset ERT
13462 status collapsed
13463
13464 \begin_layout Standard
13465
13466
13467 \backslash
13468 /
13469 \end_layout
13470
13471 \end_inset
13472
13473 -iram-size
13474 \begin_inset LatexCommand index
13475 name "-\\/-iram-size <Value>"
13476
13477 \end_inset
13478
13479  to specify the size of the total internal RAM (
13480 \emph on
13481 data
13482 \emph default
13483 +
13484 \emph on
13485 idata
13486 \emph default
13487 ).
13488  
13489 \newline
13490
13491 \end_layout
13492
13493 \begin_layout Standard
13494 By default the 8051 linker will place the stack after the last byte of (i)data
13495  variables.
13496  Option -
13497 \begin_inset ERT
13498 status collapsed
13499
13500 \begin_layout Standard
13501
13502
13503 \backslash
13504 /
13505 \end_layout
13506
13507 \end_inset
13508
13509 -stack-loc
13510 \begin_inset LatexCommand index
13511 name "-\\/-stack-loc <Value>"
13512
13513 \end_inset
13514
13515  allows you to specify the start of the stack, i.e.
13516  you could start it after any data in the general purpose area.
13517  If your microcontroller has additional indirectly addressable internal
13518  RAM (
13519 \emph on
13520 idata
13521 \emph default
13522 ) you can place the stack on it.
13523  You may also need to use -
13524 \begin_inset ERT
13525 status collapsed
13526
13527 \begin_layout Standard
13528
13529
13530 \backslash
13531 /
13532 \end_layout
13533
13534 \end_inset
13535
13536 -xdata-loc
13537 \begin_inset LatexCommand index
13538 name "-\\/-xdata-loc<Value>"
13539
13540 \end_inset
13541
13542  to set the start address of the external RAM (
13543 \emph on
13544 xdata
13545 \emph default
13546 ) and -
13547 \begin_inset ERT
13548 status collapsed
13549
13550 \begin_layout Standard
13551
13552
13553 \backslash
13554 /
13555 \end_layout
13556
13557 \end_inset
13558
13559 -xram-size
13560 \begin_inset LatexCommand index
13561 name "-\\/-xram-size <Value>"
13562
13563 \end_inset
13564
13565  to specify its size.
13566  Same goes for the code memory, using -
13567 \begin_inset ERT
13568 status collapsed
13569
13570 \begin_layout Standard
13571
13572
13573 \backslash
13574 /
13575 \end_layout
13576
13577 \end_inset
13578
13579 -code-loc
13580 \begin_inset LatexCommand index
13581 name "-\\/-code-loc <Value>"
13582
13583 \end_inset
13584
13585  and -
13586 \begin_inset ERT
13587 status collapsed
13588
13589 \begin_layout Standard
13590
13591
13592 \backslash
13593 /
13594 \end_layout
13595
13596 \end_inset
13597
13598 -code-size
13599 \begin_inset LatexCommand index
13600 name "-\\/-code-size <Value>"
13601
13602 \end_inset
13603
13604 .
13605  If in doubt, don't specify any options and see if the resulting memory
13606  layout is appropriate, then you can adjust it.
13607 \end_layout
13608
13609 \begin_layout Standard
13610 The linker generates two files with memory allocation information.
13611  The first, with extension .map
13612 \begin_inset LatexCommand index
13613 name "<file>.map"
13614
13615 \end_inset
13616
13617  shows all the variables and segments.
13618  The second with extension .mem
13619 \begin_inset LatexCommand index
13620 name "<file>.mem"
13621
13622 \end_inset
13623
13624  shows the final memory layout.
13625  The linker will complain either if memory segments overlap, there is not
13626  enough memory, or there is not enough space for stack.
13627  If you get any linking warnings and/or errors related to stack or segments
13628  allocation, take a look at either the .map or .mem files to find out what
13629  the problem is.
13630  The .mem file may even suggest a solution to the problem.
13631 \begin_inset VSpace bigskip
13632 \end_inset
13633
13634
13635 \end_layout
13636
13637 \begin_layout Subsection
13638 Z80/Z180 Storage Class
13639 \begin_inset LatexCommand index
13640 name "Z80!Storage class"
13641
13642 \end_inset
13643
13644  Language Extensions
13645 \end_layout
13646
13647 \begin_layout Subsubsection
13648 sfr
13649 \begin_inset LatexCommand index
13650 name "sfr"
13651
13652 \end_inset
13653
13654
13655 \begin_inset LatexCommand index
13656 name "\\_\\_sfr"
13657
13658 \end_inset
13659
13660  (in/out to 8-bit addresses)
13661 \end_layout
13662
13663 \begin_layout Standard
13664 The Z80
13665 \begin_inset LatexCommand index
13666 name "Z80"
13667
13668 \end_inset
13669
13670  family has separate address spaces for memory and 
13671 \emph on
13672 i
13673 \emph default
13674 nput/
13675 \emph on
13676 o
13677 \emph default
13678 utput memory.
13679  I/O memory
13680 \begin_inset LatexCommand index
13681 name "I/O memory (Z80, Z180)"
13682
13683 \end_inset
13684
13685
13686 \begin_inset LatexCommand index
13687 name "Z80!I/O memory"
13688
13689 \end_inset
13690
13691
13692 \begin_inset LatexCommand index
13693 name "Z180!I/O memory"
13694
13695 \end_inset
13696
13697  is accessed with special instructions, e.g.:
13698 \end_layout
13699
13700 \begin_layout Verse
13701
13702 \family typewriter
13703 sfr at 0x78 IoPort;\InsetSpace ~
13704 \InsetSpace ~
13705 /* define a var in I/O space at 78h called IoPort */
13706  
13707 \end_layout
13708
13709 \begin_layout Standard
13710 Writing 0x01 to this variable generates the assembly code:
13711 \end_layout
13712
13713 \begin_layout Verse
13714
13715 \family typewriter
13716 3E 01\InsetSpace ~
13717 \InsetSpace ~
13718 \InsetSpace ~
13719 \InsetSpace ~
13720 \InsetSpace ~
13721 \InsetSpace ~
13722 ld a,#0x01
13723 \newline
13724 D3 78\InsetSpace ~
13725 \InsetSpace ~
13726 \InsetSpace ~
13727 \InsetSpace ~
13728 \InsetSpace ~
13729 \InsetSpace ~
13730 out (_IoPort),a 
13731 \end_layout
13732
13733 \begin_layout Subsubsection
13734 banked sfr
13735 \begin_inset LatexCommand index
13736 name "sfr"
13737
13738 \end_inset
13739
13740
13741 \begin_inset LatexCommand index
13742 name "\\_\\_sfr"
13743
13744 \end_inset
13745
13746  (in/out to 16-bit addresses)
13747 \end_layout
13748
13749 \begin_layout Standard
13750 The keyword 
13751 \emph on
13752 banked
13753 \emph default
13754  is used to support 16 bit addresses in I/O memory e.g.:
13755 \end_layout
13756
13757 \begin_layout Verse
13758
13759 \family typewriter
13760 sfr banked at
13761 \begin_inset LatexCommand index
13762 name "at"
13763
13764 \end_inset
13765
13766
13767 \begin_inset LatexCommand index
13768 name "\\_\\_at"
13769
13770 \end_inset
13771
13772  0x123 IoPort; 
13773 \end_layout
13774
13775 \begin_layout Standard
13776 Writing 0x01 to this variable generates the assembly code:
13777 \end_layout
13778
13779 \begin_layout Verse
13780
13781 \family typewriter
13782 01 23 01\InsetSpace ~
13783 \InsetSpace ~
13784 \InsetSpace ~
13785 ld bc,#_IoPort
13786 \newline
13787 3E 01\InsetSpace ~
13788 \InsetSpace ~
13789 \InsetSpace ~
13790 \InsetSpace ~
13791 \InsetSpace ~
13792 \InsetSpace ~
13793 ld a,#0x01 
13794 \newline
13795 ED 79\InsetSpace ~
13796 \InsetSpace ~
13797 \InsetSpace ~
13798 \InsetSpace ~
13799 \InsetSpace ~
13800 \InsetSpace ~
13801 out (c),a 
13802 \end_layout
13803
13804 \begin_layout Subsubsection
13805 sfr
13806 \begin_inset LatexCommand index
13807 name "sfr"
13808
13809 \end_inset
13810
13811
13812 \begin_inset LatexCommand index
13813 name "\\_\\_sfr"
13814
13815 \end_inset
13816
13817  (in0/out0 to 8 bit addresses on Z180
13818 \begin_inset LatexCommand index
13819 name "Z180"
13820
13821 \end_inset
13822
13823 /HD64180
13824 \begin_inset LatexCommand index
13825 name "HD64180 (see Z180)"
13826
13827 \end_inset
13828
13829 )
13830 \end_layout
13831
13832 \begin_layout Standard
13833 The compiler option -
13834 \begin_inset ERT
13835 status collapsed
13836
13837 \begin_layout Standard
13838
13839
13840 \backslash
13841 /
13842 \end_layout
13843
13844 \end_inset
13845
13846 -portmode
13847 \begin_inset LatexCommand index
13848 name "Z180!Options!-\\/-portmode"
13849
13850 \end_inset
13851
13852 =180 (80) and a compiler #pragma\InsetSpace ~
13853 portmode
13854 \begin_inset LatexCommand index
13855 name "Z180!Pragmas!\\#pragma portmode"
13856
13857 \end_inset
13858
13859  z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
13860 ns 
13861 \family typewriter
13862 in0/out0
13863 \family default
13864  instead of 
13865 \family typewriter
13866 in/out
13867 \family default
13868 .
13869  If you include the file z180.h this will be set automatically.
13870 \begin_inset VSpace bigskip
13871 \end_inset
13872
13873
13874 \end_layout
13875
13876 \begin_layout Subsection
13877 HC08 Storage Class
13878 \begin_inset LatexCommand index
13879 name "HC08!Storage class"
13880
13881 \end_inset
13882
13883  Language Extensions
13884 \end_layout
13885
13886 \begin_layout Subsubsection
13887 data
13888 \begin_inset LatexCommand index
13889 name "data (hc08 storage class)"
13890
13891 \end_inset
13892
13893
13894 \begin_inset LatexCommand index
13895 name "\\_\\_data (hc08 storage class)"
13896
13897 \end_inset
13898
13899  
13900 \end_layout
13901
13902 \begin_layout Standard
13903 The data storage class declares a variable that resides in the first 256
13904  bytes of memory (the direct page).
13905  The HC08
13906 \begin_inset LatexCommand index
13907 name "HC08"
13908
13909 \end_inset
13910
13911  is most efficient at accessing variables (especially pointers) stored here.
13912 \end_layout
13913
13914 \begin_layout Subsubsection
13915 xdata
13916 \begin_inset LatexCommand index
13917 name "xdata (hc08 storage class)"
13918
13919 \end_inset
13920
13921
13922 \begin_inset LatexCommand index
13923 name "\\_\\_xdata (hc08 storage class)"
13924
13925 \end_inset
13926
13927  
13928 \end_layout
13929
13930 \begin_layout Standard
13931 The xdata storage class declares a variable that can reside anywhere in
13932  memory.
13933  This is the default if no storage class is specified.
13934  
13935 \begin_inset VSpace bigskip
13936 \end_inset
13937
13938
13939 \end_layout
13940
13941 \begin_layout Section
13942 Other SDCC language extensions
13943 \begin_inset LatexCommand index
13944 name "Other SDCC language extensions"
13945
13946 \end_inset
13947
13948
13949 \end_layout
13950
13951 \begin_layout Subsection
13952 Binary constants
13953 \end_layout
13954
13955 \begin_layout Standard
13956 SDCC supports the use of binary constants, such as 0b01100010.
13957  This feature is only enabled when the compiler is invoked using --std-sdccxx.
13958 \end_layout
13959
13960 \begin_layout Standard
13961 \begin_inset VSpace bigskip
13962 \end_inset
13963
13964
13965 \end_layout
13966
13967 \begin_layout Section
13968 Absolute Addressing
13969 \begin_inset LatexCommand index
13970 name "Absolute addressing"
13971
13972 \end_inset
13973
13974
13975 \end_layout
13976
13977 \begin_layout Standard
13978 Data items can be assigned an absolute address with the 
13979 \emph on
13980 at
13981 \begin_inset LatexCommand index
13982 name "at"
13983
13984 \end_inset
13985
13986
13987 \begin_inset LatexCommand index
13988 name "\\_\\_at"
13989
13990 \end_inset
13991
13992  <address>
13993 \emph default
13994  keyword, in addition to a storage class, e.g.:
13995 \end_layout
13996
13997 \begin_layout Verse
13998
13999 \family typewriter
14000 xdata
14001 \begin_inset LatexCommand index
14002 name "xdata (mcs51, ds390 storage class)"
14003
14004 \end_inset
14005
14006
14007 \begin_inset LatexCommand index
14008 name "\\_\\_xdata (mcs51, ds390 storage class)"
14009
14010 \end_inset
14011
14012  at
14013 \begin_inset LatexCommand index
14014 name "at"
14015
14016 \end_inset
14017
14018
14019 \begin_inset LatexCommand index
14020 name "\\_\\_at"
14021
14022 \end_inset
14023
14024  0x7ffe unsigned int chksum;
14025 \end_layout
14026
14027 \begin_layout Standard
14028 or, better conforming to ISO/IEC 9899 C:
14029 \end_layout
14030
14031 \begin_layout Verse
14032
14033 \family typewriter
14034 __xdata __at (0x7ffe) unsigned int chksum;
14035 \end_layout
14036
14037 \begin_layout Standard
14038 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
14039  of the external ram.
14040  The compiler does 
14041 \emph on
14042 not
14043 \emph default
14044  reserve any space for variables declared in this way
14045 \begin_inset Marginal
14046 status collapsed
14047
14048 \begin_layout Standard
14049
14050 \series bold
14051 \InsetSpace ~
14052 !
14053 \end_layout
14054
14055 \end_inset
14056
14057  (they are implemented with an equate in the assembler).
14058  Thus it is left to the programmer to make sure there are no overlaps with
14059  other variables that are declared without the absolute address.
14060  The assembler listing file (.lst
14061 \begin_inset LatexCommand index
14062 name "<file>.lst"
14063
14064 \end_inset
14065
14066 ) and the linker output files (.rst
14067 \begin_inset LatexCommand index
14068 name "<file>.rst"
14069
14070 \end_inset
14071
14072 ) and (.map
14073 \begin_inset LatexCommand index
14074 name "<file>.map"
14075
14076 \end_inset
14077
14078 ) are good places to look for such overlaps.
14079 \end_layout
14080
14081 \begin_layout Standard
14082 If however you provide an initializer
14083 \begin_inset LatexCommand index
14084 name "Variable initialization"
14085
14086 \end_inset
14087
14088  actual memory allocation will take place and overlaps will be detected
14089  by the linker.
14090  E.g.:
14091 \end_layout
14092
14093 \begin_layout Verse
14094
14095 \family typewriter
14096 __code __at (0x7ff0) char Id[5] = 
14097 \begin_inset Quotes sld
14098 \end_inset
14099
14100 SDCC
14101 \begin_inset Quotes srd
14102 \end_inset
14103
14104 ;
14105 \end_layout
14106
14107 \begin_layout Standard
14108 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
14109  in code memory.
14110 \end_layout
14111
14112 \begin_layout Standard
14113 In case of memory mapped I/O devices the keyword 
14114 \emph on
14115 volatile
14116 \emph default
14117  has to be used to tell the compiler that accesses might not be removed:
14118 \end_layout
14119
14120 \begin_layout Verse
14121
14122 \family typewriter
14123 volatile
14124 \begin_inset LatexCommand index
14125 name "volatile"
14126
14127 \end_inset
14128
14129  __xdata
14130 \begin_inset LatexCommand index
14131 name "xdata (mcs51, ds390 storage class)"
14132
14133 \end_inset
14134
14135  __at
14136 \begin_inset LatexCommand index
14137 name "at"
14138
14139 \end_inset
14140
14141  (0x8000) unsigned char PORTA_8255;
14142 \end_layout
14143
14144 \begin_layout Standard
14145 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
14146 r) array
14147 \family typewriter
14148 \size footnotesize
14149
14150 \begin_inset LatexCommand index
14151 name "Aligned array"
14152
14153 \end_inset
14154
14155
14156 \family default
14157 \size default
14158  starts at a block (256 byte) boundary
14159 \begin_inset LatexCommand index
14160 name "block boundary"
14161
14162 \end_inset
14163
14164  (section 
14165 \begin_inset LatexCommand ref
14166 reference "sub:A-Step-by Assembler Introduction"
14167
14168 \end_inset
14169
14170  has an example).
14171 \newline
14172 Absolute addresses can be specified for variables in all
14173  storage classes, e.g.:
14174 \end_layout
14175
14176 \begin_layout Verse
14177
14178 \family typewriter
14179 __bit
14180 \begin_inset LatexCommand index
14181 name "bit"
14182
14183 \end_inset
14184
14185  __at
14186 \begin_inset LatexCommand index
14187 name "at"
14188
14189 \end_inset
14190
14191  (0x02) bvar;
14192 \end_layout
14193
14194 \begin_layout Standard
14195 The above example will allocate the variable at offset 0x02 in the bit-addressab
14196 le space.
14197  There is no real advantage to assigning absolute addresses to variables
14198  in this manner, unless you want strict control over all the variables allocated.
14199  One possible use would be to write hardware portable code.
14200  For example, if you have a routine that uses one or more of the microcontroller
14201  I/O pins, and such pins are different for two different hardwares, you
14202  can declare the I/O pins in your routine using:
14203 \end_layout
14204
14205 \begin_layout Verse
14206
14207 \family typewriter
14208 extern volatile
14209 \begin_inset LatexCommand index
14210 name "volatile"
14211
14212 \end_inset
14213
14214  __bit MOSI;\InsetSpace ~
14215 \InsetSpace ~
14216 \InsetSpace ~
14217 \InsetSpace ~
14218 /* master out, slave in */
14219 \newline
14220 extern volatile __bit MISO;\InsetSpace ~
14221 \InsetSpace ~
14222 \InsetSpace ~
14223 \InsetSpace ~
14224 /* master
14225  in, slave out */
14226 \newline
14227 extern volatile __bit MCLK;\InsetSpace ~
14228 \InsetSpace ~
14229 \InsetSpace ~
14230 \InsetSpace ~
14231 /* master clock */
14232 \newline
14233
14234 \newline
14235 /* Input and
14236  Output of a byte on a 3-wire serial bus.
14237 \newline
14238 \InsetSpace ~
14239 \InsetSpace ~
14240 \InsetSpace ~
14241 If needed adapt polarity of clock,
14242  polarity of data and bit order
14243 \newline
14244 \InsetSpace ~
14245 */
14246 \newline
14247 unsigned char spi_io(unsigned char out_byte)
14248  
14249 \newline
14250
14251 \newline
14252 \InsetSpace ~
14253 \InsetSpace ~
14254 \InsetSpace ~
14255 \InsetSpace ~
14256 unsigned char i=8;
14257 \newline
14258 \InsetSpace ~
14259 \InsetSpace ~
14260 \InsetSpace ~
14261 \InsetSpace ~
14262 do { 
14263 \newline
14264 \InsetSpace ~
14265 \InsetSpace ~
14266 \InsetSpace ~
14267 \InsetSpace ~
14268 \InsetSpace ~
14269 \InsetSpace ~
14270 \InsetSpace ~
14271 \InsetSpace ~
14272 MOSI = out_byte & 0x80; 
14273 \newline
14274 \InsetSpace ~
14275 \InsetSpace ~
14276 \InsetSpace ~
14277 \InsetSpace ~
14278 \InsetSpace ~
14279 \InsetSpace ~
14280 \InsetSpace ~
14281 \InsetSpace ~
14282 out_byte <<= 1;
14283 \newline
14284 \InsetSpace ~
14285 \InsetSpace ~
14286 \InsetSpace ~
14287 \InsetSpace ~
14288 \InsetSpace ~
14289 \InsetSpace ~
14290 \InsetSpace ~
14291 \InsetSpace ~
14292 MCLK =
14293  1; 
14294 \newline
14295 \InsetSpace ~
14296 \InsetSpace ~
14297 \InsetSpace ~
14298 \InsetSpace ~
14299 \InsetSpace ~
14300 \InsetSpace ~
14301 \InsetSpace ~
14302 \InsetSpace ~
14303 /* _asm nop _endasm; */\InsetSpace ~
14304 \InsetSpace ~
14305 \InsetSpace ~
14306 \InsetSpace ~
14307 \InsetSpace ~
14308 \InsetSpace ~
14309 \InsetSpace ~
14310 \InsetSpace ~
14311 /* for slow peripherals */
14312 \newline
14313 \InsetSpace ~
14314 \InsetSpace ~
14315 \InsetSpace ~
14316 \InsetSpace ~
14317 \InsetSpace ~
14318 \InsetSpace ~
14319 \InsetSpace ~
14320 \InsetSpace ~
14321 if(MISO) 
14322 \newline
14323 \InsetSpace ~
14324 \InsetSpace ~
14325 \InsetSpace ~
14326 \InsetSpace ~
14327 \InsetSpace ~
14328 \InsetSpace ~
14329 \InsetSpace ~
14330 \InsetSpace ~
14331 \InsetSpace ~
14332 \InsetSpace ~
14333 \InsetSpace ~
14334 \InsetSpace ~
14335 out_byte +=
14336  1; 
14337 \newline
14338 \InsetSpace ~
14339 \InsetSpace ~
14340 \InsetSpace ~
14341 \InsetSpace ~
14342 \InsetSpace ~
14343 \InsetSpace ~
14344 \InsetSpace ~
14345 \InsetSpace ~
14346 MCLK = 0; 
14347 \newline
14348 \InsetSpace ~
14349 \InsetSpace ~
14350 \InsetSpace ~
14351 \InsetSpace ~
14352 } while(--i);
14353 \newline
14354 \InsetSpace ~
14355 \InsetSpace ~
14356 \InsetSpace ~
14357 \InsetSpace ~
14358 return out_byte; 
14359 \newline
14360 }
14361 \end_layout
14362
14363 \begin_layout Standard
14364 Then, someplace in the code for the first hardware you would use
14365 \end_layout
14366
14367 \begin_layout Verse
14368
14369 \family typewriter
14370 __bit __at
14371 \begin_inset LatexCommand index
14372 name "at"
14373
14374 \end_inset
14375
14376
14377 \begin_inset LatexCommand index
14378 name "\\_\\_at"
14379
14380 \end_inset
14381
14382  (0x80) MOSI;\InsetSpace ~
14383 \InsetSpace ~
14384 \InsetSpace ~
14385 \InsetSpace ~
14386 /* I/O port 0, bit 0 */
14387 \newline
14388 __bit __at (0x81) MISO;\InsetSpace ~
14389 \InsetSpace ~
14390 \InsetSpace ~
14391 \InsetSpace ~
14392 /* I/O port 0,
14393  bit 1 */
14394 \newline
14395 __bit __at (0x82) MCLK;\InsetSpace ~
14396 \InsetSpace ~
14397 \InsetSpace ~
14398 \InsetSpace ~
14399 /* I/O port 0, bit 2 */
14400 \end_layout
14401
14402 \begin_layout Standard
14403 Similarly, for the second hardware you would use
14404 \end_layout
14405
14406 \begin_layout Verse
14407
14408 \family typewriter
14409 __bit __at (0x83) MOSI;\InsetSpace ~
14410 \InsetSpace ~
14411 \InsetSpace ~
14412 \InsetSpace ~
14413 /* I/O port 0, bit 3 */
14414 \newline
14415 __bit __at (0x91) MISO;\InsetSpace ~
14416 \InsetSpace ~
14417 \InsetSpace ~
14418 \InsetSpace ~
14419 /*
14420  I/O port 1, bit 1 */
14421 \newline
14422 __bit
14423 \begin_inset LatexCommand index
14424 name "bit"
14425
14426 \end_inset
14427
14428  __at (0x92) MCLK;\InsetSpace ~
14429 \InsetSpace ~
14430 \InsetSpace ~
14431 \InsetSpace ~
14432 /* I/O port 1, bit 2 */
14433 \end_layout
14434
14435 \begin_layout Standard
14436 and you can use the same hardware dependent routine without changes, as
14437  for example in a library.
14438  This is somehow similar to sbit, but only one absolute address has to be
14439  specified in the whole project.
14440 \begin_inset VSpace bigskip
14441 \end_inset
14442
14443
14444 \end_layout
14445
14446 \begin_layout Section
14447 Parameters
14448 \begin_inset LatexCommand index
14449 name "Parameters"
14450
14451 \end_inset
14452
14453
14454 \begin_inset LatexCommand index
14455 name "function parameter"
14456
14457 \end_inset
14458
14459  & Local Variables
14460 \begin_inset LatexCommand index
14461 name "local variables"
14462
14463 \end_inset
14464
14465
14466 \begin_inset LatexCommand label
14467 name "sec:Parameters-and-Local-Variables"
14468
14469 \end_inset
14470
14471
14472 \end_layout
14473
14474 \begin_layout Standard
14475 Automatic (local) variables and parameters to functions can either be placed
14476  on the stack or in data-space.
14477  The default action of the compiler is to place these variables in the internal
14478  RAM (for small model) or external RAM (for medium or large model).
14479  This in fact makes them similar to 
14480 \emph on
14481 static
14482 \begin_inset LatexCommand index
14483 name "static"
14484
14485 \end_inset
14486
14487
14488 \emph default
14489  so by default functions are non-reentrant
14490 \begin_inset LatexCommand index
14491 name "reentrant"
14492
14493 \end_inset
14494
14495 .
14496  
14497 \newline
14498
14499 \newline
14500 They can be placed on the stack
14501 \begin_inset LatexCommand index
14502 name "stack"
14503
14504 \end_inset
14505
14506  by using the 
14507 \emph on
14508 -
14509 \begin_inset ERT
14510 status collapsed
14511
14512 \begin_layout Standard
14513
14514
14515 \backslash
14516 /
14517 \end_layout
14518
14519 \end_inset
14520
14521 -stack-auto
14522 \begin_inset LatexCommand index
14523 name "-\\/-stack-auto"
14524
14525 \end_inset
14526
14527
14528 \emph default
14529  option, by using 
14530 \emph on
14531 #pragma\InsetSpace ~
14532 stackauto
14533 \emph default
14534
14535 \begin_inset LatexCommand index
14536 name "\\#pragma stackauto"
14537
14538 \end_inset
14539
14540  or by using the 
14541 \emph on
14542 reentrant
14543 \begin_inset LatexCommand index
14544 name "reentrant"
14545
14546 \end_inset
14547
14548
14549 \emph default
14550  keyword in the function declaration, e.g.:
14551 \end_layout
14552
14553 \begin_layout Verse
14554
14555 \family typewriter
14556 unsigned char foo(char i) __reentrant 
14557 \newline
14558
14559 \newline
14560 \InsetSpace ~
14561 \InsetSpace ~
14562 \InsetSpace ~
14563 \InsetSpace ~
14564 ...
14565  
14566 \newline
14567 }
14568 \end_layout
14569
14570 \begin_layout Standard
14571 Since stack space on 8051 is limited, the 
14572 \emph on
14573 reentrant
14574 \emph default
14575  keyword or the 
14576 \emph on
14577 -
14578 \begin_inset ERT
14579 status collapsed
14580
14581 \begin_layout Standard
14582
14583
14584 \backslash
14585 /
14586 \end_layout
14587
14588 \end_inset
14589
14590 -stack-auto
14591 \emph default
14592  option should be used sparingly.
14593  Note that the reentrant keyword just means that the parameters & local
14594  variables will be allocated to the stack, it 
14595 \emph on
14596 does not
14597 \emph default
14598  mean that the function is register bank
14599 \begin_inset LatexCommand index
14600 name "register bank (mcs51, ds390)"
14601
14602 \end_inset
14603
14604  independent.
14605 \newline
14606
14607 \newline
14608 Local variables
14609 \begin_inset LatexCommand index
14610 name "local variables"
14611
14612 \end_inset
14613
14614  can be assigned storage classes and absolute
14615 \begin_inset LatexCommand index
14616 name "Absolute addressing"
14617
14618 \end_inset
14619
14620  addresses, e.g.: 
14621 \end_layout
14622
14623 \begin_layout Verse
14624
14625 \family typewriter
14626 unsigned char foo() 
14627 \newline
14628 {
14629 \newline
14630 \InsetSpace ~
14631 \InsetSpace ~
14632 \InsetSpace ~
14633 \InsetSpace ~
14634 __xdata unsigned char i;
14635 \newline
14636 \InsetSpace ~
14637 \InsetSpace ~
14638 \InsetSpace ~
14639 \InsetSpace ~
14640 __bit bvar;
14641 \newline
14642 \InsetSpace ~
14643 \InsetSpace ~
14644 \InsetSpace ~
14645 \InsetSpace ~
14646 __data __at
14647 \begin_inset LatexCommand index
14648 name "at"
14649
14650 \end_inset
14651
14652  (0x31) unsigned char j;
14653 \newline
14654 \InsetSpace ~
14655 \InsetSpace ~
14656 \InsetSpace ~
14657 \InsetSpace ~
14658 ...
14659  
14660 \newline
14661 }
14662 \end_layout
14663
14664 \begin_layout Standard
14665 In the above example the variable 
14666 \emph on
14667 i
14668 \emph default
14669  will be allocated in the external ram, 
14670 \emph on
14671 bvar
14672 \emph default
14673  in bit addressable space and 
14674 \emph on
14675 j
14676 \emph default
14677  in internal ram.
14678  When compiled with 
14679 \emph on
14680 -
14681 \begin_inset ERT
14682 status collapsed
14683
14684 \begin_layout Standard
14685
14686
14687 \backslash
14688 /
14689 \end_layout
14690
14691 \end_inset
14692
14693 -stack-auto
14694 \emph default
14695  or when a function is declared as 
14696 \emph on
14697 reentrant
14698 \emph default
14699  this should only be done for static variables.
14700 \end_layout
14701
14702 \begin_layout Standard
14703 Parameters
14704 \begin_inset LatexCommand index
14705 name "function parameter"
14706
14707 \end_inset
14708
14709  however are not allowed any storage class
14710 \begin_inset LatexCommand index
14711 name "Storage class"
14712
14713 \end_inset
14714
14715 , (storage classes for parameters will be ignored), their allocation is
14716  governed by the memory model in use, and the reentrancy options.
14717 \end_layout
14718
14719 \begin_layout Standard
14720 It is however allowed to use bit parameters in reentrant functions and also
14721  non-static local bit variables are supported.
14722  Efficient use is limited to 8 semi-bitregisters in bit space.
14723  They are pushed and popped to stack
14724 \begin_inset LatexCommand index
14725 name "stack"
14726
14727 \end_inset
14728
14729  as a single byte just like the normal registers.
14730 \end_layout
14731
14732 \begin_layout Section
14733 Overlaying
14734 \begin_inset LatexCommand label
14735 name "sub:Overlaying"
14736
14737 \end_inset
14738
14739
14740 \begin_inset LatexCommand index
14741 name "Overlaying"
14742
14743 \end_inset
14744
14745
14746 \end_layout
14747
14748 \begin_layout Standard
14749 For non-reentrant
14750 \begin_inset LatexCommand index
14751 name "reentrant"
14752
14753 \end_inset
14754
14755  functions SDCC will try to reduce internal ram space usage by overlaying
14756  parameters and local variables of a function (if possible).
14757  Parameters and local variables
14758 \begin_inset LatexCommand index
14759 name "local variables"
14760
14761 \end_inset
14762
14763  of a function will be allocated to an overlayable segment if the function
14764  has 
14765 \emph on
14766 no other function calls and the function is non-reentrant and the memory
14767  model
14768 \begin_inset LatexCommand index
14769 name "Memory model"
14770
14771 \end_inset
14772
14773  is small.
14774
14775 \emph default
14776  If an explicit storage class
14777 \begin_inset LatexCommand index
14778 name "Storage class"
14779
14780 \end_inset
14781
14782  is specified for a local variable, it will NOT be overlaid.
14783 \end_layout
14784
14785 \begin_layout Standard
14786 Note that the compiler (not the linkage editor) makes the decision for overlayin
14787 g the data items.
14788  Functions that are called from an interrupt service routine
14789 \begin_inset Marginal
14790 status collapsed
14791
14792 \begin_layout Standard
14793
14794 \series bold
14795 !
14796 \end_layout
14797
14798 \end_inset
14799
14800  should be preceded by a #pragma\InsetSpace ~
14801 nooverlay
14802 \begin_inset LatexCommand index
14803 name "\\#pragma nooverlay"
14804
14805 \end_inset
14806
14807  if they are not reentrant.
14808 \end_layout
14809
14810 \begin_layout Standard
14811 Also note that the compiler does not do any processing of inline assembler
14812  code, so the compiler might incorrectly assign local variables and parameters
14813  of a function into the overlay segment if the inline assembler code calls
14814  other c-functions that might use the overlay.
14815  In that case the #pragma\InsetSpace ~
14816 nooverlay should be used.
14817 \end_layout
14818
14819 \begin_layout Standard
14820 Parameters and local variables of functions that contain 16 or 32 bit multiplica
14821 tion
14822 \begin_inset LatexCommand index
14823 name "Multiplication"
14824
14825 \end_inset
14826
14827  or division
14828 \begin_inset LatexCommand index
14829 name "Division"
14830
14831 \end_inset
14832
14833  will NOT be overlaid since these are implemented using external functions,
14834  e.g.:
14835 \end_layout
14836
14837 \begin_layout Verse
14838
14839 \family typewriter
14840 #pragma save 
14841 \newline
14842 #pragma nooverlay
14843 \begin_inset LatexCommand index
14844 name "\\#pragma nooverlay"
14845
14846 \end_inset
14847
14848  
14849 \newline
14850 void set_error(unsigned char errcd) 
14851 \newline
14852 {
14853 \newline
14854 \InsetSpace ~
14855 \InsetSpace ~
14856 \InsetSpace ~
14857 \InsetSpace ~
14858 P3 = errcd;
14859 \newline
14860
14861 \newline
14862 #pragma restore 
14863 \newline
14864
14865 \newline
14866 void
14867  some_isr () __interrupt
14868 \begin_inset LatexCommand index
14869 name "interrupt"
14870
14871 \end_inset
14872
14873  (2)
14874 \newline
14875 {
14876 \newline
14877 \InsetSpace ~
14878 \InsetSpace ~
14879 \InsetSpace ~
14880 \InsetSpace ~
14881 ...
14882 \newline
14883 \InsetSpace ~
14884 \InsetSpace ~
14885 \InsetSpace ~
14886 \InsetSpace ~
14887 set_error(10);
14888 \newline
14889 \InsetSpace ~
14890 \InsetSpace ~
14891 \InsetSpace ~
14892 \InsetSpace ~
14893 ...
14894  
14895 \newline
14896 }
14897 \end_layout
14898
14899 \begin_layout Standard
14900 In the above example the parameter 
14901 \emph on
14902 errcd
14903 \emph default
14904  for the function 
14905 \emph on
14906 set_error
14907 \emph default
14908  would be assigned to the overlayable segment if the #pragma\InsetSpace ~
14909 nooverlay was
14910  not present, this could cause unpredictable runtime behavior when called
14911  from an interrupt service routine.
14912  The #pragma\InsetSpace ~
14913 nooverlay ensures that the parameters and local variables for
14914  the function are NOT overlaid.
14915 \begin_inset VSpace bigskip
14916 \end_inset
14917
14918
14919 \end_layout
14920
14921 \begin_layout Section
14922 Interrupt Service Routines
14923 \begin_inset LatexCommand label
14924 name "sub:Interrupt-Service-Routines"
14925
14926 \end_inset
14927
14928
14929 \end_layout
14930
14931 \begin_layout Subsection
14932 General Information
14933 \end_layout
14934
14935 \begin_layout Standard
14936 SDCC allows 
14937 \emph on
14938 i
14939 \emph default
14940 nterrupt 
14941 \emph on
14942 s
14943 \emph default
14944 ervice 
14945 \emph on
14946 r
14947 \emph default
14948 outines to be coded in C, with some extended keywords.
14949 \end_layout
14950
14951 \begin_layout Verse
14952
14953 \family typewriter
14954 void timer_isr (void) __interrupt (1) __using (1) 
14955 \newline
14956
14957 \newline
14958 \InsetSpace ~
14959 \InsetSpace ~
14960 \InsetSpace ~
14961 \InsetSpace ~
14962 ...
14963  
14964 \newline
14965 }
14966 \end_layout
14967
14968 \begin_layout Standard
14969 The optional number following the 
14970 \emph on
14971 interrupt
14972 \begin_inset LatexCommand index
14973 name "interrupt"
14974
14975 \end_inset
14976
14977
14978 \begin_inset LatexCommand index
14979 name "\\_\\_interrupt"
14980
14981 \end_inset
14982
14983
14984 \emph default
14985  keyword is the interrupt number this routine will service.
14986  When present, the compiler will insert a call to this routine in the interrupt
14987  vector table
14988 \begin_inset LatexCommand index
14989 name "interrupt vector table"
14990
14991 \end_inset
14992
14993  for the interrupt number specified.
14994  If you have multiple source files in your project, interrupt service routines
14995  can be present in any of them, but a prototype of the isr MUST be present
14996  or included in the file that contains the function 
14997 \emph on
14998 main
14999 \emph default
15000 .
15001  The optional (8051 specific) keyword 
15002 \emph on
15003 using
15004 \begin_inset LatexCommand index
15005 name "using (mcs51, ds390 register bank)"
15006
15007 \end_inset
15008
15009
15010 \begin_inset LatexCommand index
15011 name "\\_\\_using (mcs51, ds390 register bank)"
15012
15013 \end_inset
15014
15015
15016 \emph default
15017  can be used to tell the compiler to use the specified register bank when
15018  generating code for this function.
15019  
15020 \newline
15021 Interrupt service routines open the door for some very interesting bugs:
15022 \end_layout
15023
15024 \begin_layout Subsubsection
15025 \begin_inset LatexCommand label
15026 name "sub:Common-interrupt-pitfall-volatile"
15027
15028 \end_inset
15029
15030 Common interrupt pitfall: variable not declared 
15031 \emph on
15032 volatile
15033 \end_layout
15034
15035 \begin_layout Standard
15036 If an interrupt service routine changes variables which are accessed by
15037  other functions these variables have to be declared 
15038 \emph on
15039 volatile
15040 \emph default
15041
15042 \begin_inset LatexCommand index
15043 name "volatile"
15044
15045 \end_inset
15046
15047 .
15048  See 
15049 \begin_inset LatexCommand url
15050 target "http://en.wikipedia.org/wiki/Volatile_variable"
15051
15052 \end_inset
15053
15054  .
15055 \end_layout
15056
15057 \begin_layout Subsubsection
15058 \begin_inset LatexCommand label
15059 name "sub:Common-interrupt-pitfall-non-atomic"
15060
15061 \end_inset
15062
15063 Common interrupt pitfall: 
15064 \emph on
15065 non-atomic access
15066 \end_layout
15067
15068 \begin_layout Standard
15069 If the access to these variables is not 
15070 \emph on
15071 atomic
15072 \begin_inset LatexCommand index
15073 name "atomic"
15074
15075 \end_inset
15076
15077
15078 \emph default
15079  (i.e.
15080  the processor needs more than one instruction for the access and could
15081  be interrupted while accessing the variable) the interrupt must be disabled
15082  during the access to avoid inconsistent data.
15083  
15084 \newline
15085 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
15086  and should be protected by disabling interrupts.
15087  You're not automatically on the safe side if you use 8 bit variables though.
15088  We need an example here: f.e.
15089  on the 8051 the harmless looking 
15090 \begin_inset Quotes srd
15091 \end_inset
15092
15093
15094 \family typewriter
15095 flags\InsetSpace ~
15096 |=\InsetSpace ~
15097 0x80;
15098 \family default
15099
15100 \begin_inset Quotes sld
15101 \end_inset
15102
15103  is not atomic if 
15104 \family typewriter
15105 flags
15106 \family default
15107  resides in xdata.
15108  Setting 
15109 \begin_inset Quotes srd
15110 \end_inset
15111
15112
15113 \family typewriter
15114 flags\InsetSpace ~
15115 |=\InsetSpace ~
15116 0x40;
15117 \family default
15118
15119 \begin_inset Quotes sld
15120 \end_inset
15121
15122  from within an interrupt routine might get lost if the interrupt occurs
15123  at the wrong time.
15124  
15125 \begin_inset Quotes sld
15126 \end_inset
15127
15128
15129 \family typewriter
15130 counter\InsetSpace ~
15131 +=\InsetSpace ~
15132 8;
15133 \family default
15134
15135 \begin_inset Quotes srd
15136 \end_inset
15137
15138  is not atomic on the 8051 even if 
15139 \family typewriter
15140 counter
15141 \family default
15142  is located in data memory.
15143 \newline
15144 Bugs like these are hard to reproduce and can
15145  cause a lot of trouble.
15146  
15147 \end_layout
15148
15149 \begin_layout Subsubsection
15150 \begin_inset LatexCommand label
15151 name "sub:Common-interrupt-pitfall-stack-overflow"
15152
15153 \end_inset
15154
15155 Common interrupt pitfall: 
15156 \emph on
15157 stack overflow
15158 \end_layout
15159
15160 \begin_layout Standard
15161 The return address and the registers used in the interrupt service routine
15162  are saved on the stack
15163 \begin_inset LatexCommand index
15164 name "stack"
15165
15166 \end_inset
15167
15168  so there must be sufficient stack space.
15169  If there isn't variables or registers (or even the return address itself)
15170  will be corrupted.
15171  This 
15172 \emph on
15173 stack overflow
15174 \emph default
15175
15176 \begin_inset LatexCommand index
15177 name "stack overflow"
15178
15179 \end_inset
15180
15181  is most likely to happen if the interrupt occurs during the 
15182 \begin_inset Quotes sld
15183 \end_inset
15184
15185 deepest
15186 \begin_inset Quotes srd
15187 \end_inset
15188
15189  subroutine when the stack is already in use for f.e.
15190  many return addresses.
15191 \end_layout
15192
15193 \begin_layout Subsubsection
15194 \begin_inset LatexCommand label
15195 name "sub:Common-interrupt-pitfall-non-reentrant"
15196
15197 \end_inset
15198
15199 Common interrupt pitfall: 
15200 \emph on
15201 use of non-reentrant functions
15202 \end_layout
15203
15204 \begin_layout Standard
15205 A special note here, int (16 bit) and long (32 bit) integer division
15206 \begin_inset LatexCommand index
15207 name "Division"
15208
15209 \end_inset
15210
15211 , multiplication
15212 \begin_inset LatexCommand index
15213 name "Multiplication"
15214
15215 \end_inset
15216
15217  & modulus
15218 \begin_inset LatexCommand index
15219 name "Modulus"
15220
15221 \end_inset
15222
15223  and floating-point
15224 \begin_inset LatexCommand index
15225 name "Floating point support"
15226
15227 \end_inset
15228
15229  operations are implemented using external support routines.
15230  If an interrupt service routine needs to do any of these operations then
15231  the support routines (as mentioned in a following section) will have to
15232  be recompiled using the 
15233 \emph on
15234 -
15235 \begin_inset ERT
15236 status collapsed
15237
15238 \begin_layout Standard
15239
15240
15241 \backslash
15242 /
15243 \end_layout
15244
15245 \end_inset
15246
15247 -stack-auto
15248 \begin_inset LatexCommand index
15249 name "-\\/-stack-auto"
15250
15251 \end_inset
15252
15253
15254 \emph default
15255  option and the source file will need to be compiled using the 
15256 \emph on
15257 -
15258 \begin_inset ERT
15259 status collapsed
15260
15261 \begin_layout Standard
15262
15263
15264 \backslash
15265 /
15266 \end_layout
15267
15268 \end_inset
15269
15270 -int-long-reent
15271 \emph default
15272
15273 \begin_inset LatexCommand index
15274 name "-\\/-int-long-reent"
15275
15276 \end_inset
15277
15278  compiler option.
15279  
15280 \newline
15281 Note, the type promotion
15282 \begin_inset LatexCommand index
15283 name "type promotion"
15284
15285 \end_inset
15286
15287  required by ANSI C can cause 16 bit routines to be used
15288 \begin_inset Marginal
15289 status collapsed
15290
15291 \begin_layout Standard
15292
15293 \series bold
15294 \InsetSpace ~
15295 !
15296 \end_layout
15297
15298 \end_inset
15299
15300  without the programmer being aware of it.
15301  See f.e.
15302  the cast 
15303 \family typewriter
15304 \series bold
15305 (unsigned char)(tail-1)
15306 \family default
15307 \series default
15308  
15309 \series bold
15310 within the if clause in section 
15311 \begin_inset LatexCommand ref
15312 reference "sub:A-Step-by Assembler Introduction"
15313
15314 \end_inset
15315
15316 .
15317 \end_layout
15318
15319 \begin_layout Standard
15320 Calling other functions from an interrupt service routine is not recommended,
15321  avoid it if possible.
15322  Note that when some function is called from an interrupt service routine
15323  it should be preceded by a #pragma\InsetSpace ~
15324 nooverlay
15325 \begin_inset LatexCommand index
15326 name "\\#pragma nooverlay"
15327
15328 \end_inset
15329
15330  if it is not reentrant.
15331  Furthermore nonreentrant functions should not be called from the main program
15332  while the interrupt service routine might be active.
15333  They also must not be called from low priority interrupt service routines
15334  while a high priority interrupt service routine might be active.
15335  You could use semaphores or make the function 
15336 \emph on
15337 critical
15338 \emph default
15339  if all parameters are passed in registers.
15340 \newline
15341  Also see section 
15342 \begin_inset LatexCommand ref
15343 reference "sub:Overlaying"
15344
15345 \end_inset
15346
15347 \InsetSpace ~
15348 about Overlaying and section 
15349 \begin_inset LatexCommand ref
15350 reference "sub:Functions-using-private-banks"
15351
15352 \end_inset
15353
15354 \InsetSpace ~
15355 about Functions using private register banks.
15356 \begin_inset VSpace bigskip
15357 \end_inset
15358
15359
15360 \end_layout
15361
15362 \begin_layout Subsection
15363 MCS51/DS390 Interrupt Service Routines
15364 \end_layout
15365
15366 \begin_layout Standard
15367 Interrupt
15368 \begin_inset LatexCommand index
15369 name "interrupt"
15370
15371 \end_inset
15372
15373  numbers and the corresponding address & descriptions for the Standard 8051/8052
15374  are listed below.
15375  SDCC will automatically adjust the 
15376 \begin_inset LatexCommand index
15377 name "interrupt vector table"
15378
15379 \end_inset
15380
15381  to the maximum interrupt number specified.
15382 \newline
15383
15384 \end_layout
15385
15386 \begin_layout Standard
15387 \align center
15388 \begin_inset Tabular
15389 <lyxtabular version="3" rows="9" columns="3">
15390 <features>
15391 <column alignment="center" valignment="top" leftline="true" width="0in">
15392 <column alignment="left" valignment="top" leftline="true" width="0in">
15393 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
15394 <row topline="true" bottomline="true">
15395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15396 \begin_inset Text
15397
15398 \begin_layout Standard
15399 Interrupt #
15400 \end_layout
15401
15402 \end_inset
15403 </cell>
15404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15405 \begin_inset Text
15406
15407 \begin_layout Standard
15408 Description
15409 \end_layout
15410
15411 \end_inset
15412 </cell>
15413 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15414 \begin_inset Text
15415
15416 \begin_layout Standard
15417 Vector Address
15418 \end_layout
15419
15420 \end_inset
15421 </cell>
15422 </row>
15423 <row topline="true">
15424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15425 \begin_inset Text
15426
15427 \begin_layout Standard
15428 0
15429 \end_layout
15430
15431 \end_inset
15432 </cell>
15433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15434 \begin_inset Text
15435
15436 \begin_layout Standard
15437 External 0
15438 \end_layout
15439
15440 \end_inset
15441 </cell>
15442 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15443 \begin_inset Text
15444
15445 \begin_layout Standard
15446 0x0003
15447 \end_layout
15448
15449 \end_inset
15450 </cell>
15451 </row>
15452 <row topline="true">
15453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15454 \begin_inset Text
15455
15456 \begin_layout Standard
15457 1
15458 \end_layout
15459
15460 \end_inset
15461 </cell>
15462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15463 \begin_inset Text
15464
15465 \begin_layout Standard
15466 Timer 0
15467 \end_layout
15468
15469 \end_inset
15470 </cell>
15471 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15472 \begin_inset Text
15473
15474 \begin_layout Standard
15475 0x000b
15476 \end_layout
15477
15478 \end_inset
15479 </cell>
15480 </row>
15481 <row topline="true">
15482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15483 \begin_inset Text
15484
15485 \begin_layout Standard
15486 2
15487 \end_layout
15488
15489 \end_inset
15490 </cell>
15491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15492 \begin_inset Text
15493
15494 \begin_layout Standard
15495 External 1
15496 \end_layout
15497
15498 \end_inset
15499 </cell>
15500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15501 \begin_inset Text
15502
15503 \begin_layout Standard
15504 0x0013
15505 \end_layout
15506
15507 \end_inset
15508 </cell>
15509 </row>
15510 <row topline="true">
15511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15512 \begin_inset Text
15513
15514 \begin_layout Standard
15515 3
15516 \end_layout
15517
15518 \end_inset
15519 </cell>
15520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15521 \begin_inset Text
15522
15523 \begin_layout Standard
15524 Timer 1
15525 \end_layout
15526
15527 \end_inset
15528 </cell>
15529 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15530 \begin_inset Text
15531
15532 \begin_layout Standard
15533 0x001b
15534 \end_layout
15535
15536 \end_inset
15537 </cell>
15538 </row>
15539 <row topline="true">
15540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15541 \begin_inset Text
15542
15543 \begin_layout Standard
15544 4
15545 \end_layout
15546
15547 \end_inset
15548 </cell>
15549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15550 \begin_inset Text
15551
15552 \begin_layout Standard
15553 Serial
15554 \end_layout
15555
15556 \end_inset
15557 </cell>
15558 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15559 \begin_inset Text
15560
15561 \begin_layout Standard
15562 0x0023
15563 \end_layout
15564
15565 \end_inset
15566 </cell>
15567 </row>
15568 <row topline="true">
15569 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15570 \begin_inset Text
15571
15572 \begin_layout Standard
15573 5
15574 \end_layout
15575
15576 \end_inset
15577 </cell>
15578 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15579 \begin_inset Text
15580
15581 \begin_layout Standard
15582 Timer 2 (8052)
15583 \end_layout
15584
15585 \end_inset
15586 </cell>
15587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15588 \begin_inset Text
15589
15590 \begin_layout Standard
15591 0x002b
15592 \end_layout
15593
15594 \end_inset
15595 </cell>
15596 </row>
15597 <row topline="true">
15598 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15599 \begin_inset Text
15600
15601 \begin_layout Standard
15602 ...
15603 \end_layout
15604
15605 \end_inset
15606 </cell>
15607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15608 \begin_inset Text
15609
15610 \begin_layout Standard
15611
15612 \end_layout
15613
15614 \end_inset
15615 </cell>
15616 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15617 \begin_inset Text
15618
15619 \begin_layout Standard
15620 ...
15621 \end_layout
15622
15623 \end_inset
15624 </cell>
15625 </row>
15626 <row topline="true" bottomline="true">
15627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15628 \begin_inset Text
15629
15630 \begin_layout Standard
15631 n
15632 \end_layout
15633
15634 \end_inset
15635 </cell>
15636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15637 \begin_inset Text
15638
15639 \begin_layout Standard
15640
15641 \end_layout
15642
15643 \end_inset
15644 </cell>
15645 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15646 \begin_inset Text
15647
15648 \begin_layout Standard
15649 0x0003 + 8*n
15650 \end_layout
15651
15652 \end_inset
15653 </cell>
15654 </row>
15655 </lyxtabular>
15656
15657 \end_inset
15658
15659
15660 \newline
15661
15662 \end_layout
15663
15664 \begin_layout Standard
15665 If the interrupt service routine is defined without 
15666 \emph on
15667 using
15668 \begin_inset LatexCommand index
15669 name "using (mcs51, ds390 register bank)"
15670
15671 \end_inset
15672
15673
15674 \begin_inset LatexCommand index
15675 name "\\_\\_using (mcs51, ds390 register bank)"
15676
15677 \end_inset
15678
15679
15680 \emph default
15681  a register bank or with register bank 0 (
15682 \emph on
15683 using
15684 \emph default
15685  0), the compiler will save the registers used by itself on the stack upon
15686  entry and restore them at exit, however if such an interrupt service routine
15687  calls another function then the entire register bank will be saved on the
15688  stack.
15689  This scheme may be advantageous for small interrupt service routines which
15690  have low register usage.
15691 \end_layout
15692
15693 \begin_layout Standard
15694 If the interrupt service routine is defined to be using a specific register
15695  bank then only 
15696 \emph on
15697 a, b, dptr
15698 \emph default
15699  & psw are saved and restored, if such an interrupt service routine calls
15700  another function (using another register bank) then the entire register
15701  bank of the called function will be saved on the stack
15702 \begin_inset LatexCommand index
15703 name "stack"
15704
15705 \end_inset
15706
15707 .
15708  This scheme is recommended for larger interrupt service routines.
15709 \begin_inset VSpace bigskip
15710 \end_inset
15711
15712
15713 \end_layout
15714
15715 \begin_layout Subsection
15716 HC08
15717 \begin_inset LatexCommand index
15718 name "HC08"
15719
15720 \end_inset
15721
15722  Interrupt Service Routines
15723 \end_layout
15724
15725 \begin_layout Standard
15726 Since the number of interrupts
15727 \begin_inset LatexCommand index
15728 name "HC08!interrupt"
15729
15730 \end_inset
15731
15732  available is chip specific and the interrupt vector table always ends at
15733  the last byte of memory, the interrupt numbers corresponds to the interrupt
15734  vectors in reverse order of address.
15735  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
15736  2 will use the interrupt vector at 0xfffa, and so on.
15737  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
15738  this way; instead see section 
15739 \begin_inset LatexCommand ref
15740 reference "sub:Startup-Code"
15741
15742 \end_inset
15743
15744  for details on customizing startup.
15745 \begin_inset VSpace bigskip
15746 \end_inset
15747
15748
15749 \end_layout
15750
15751 \begin_layout Subsection
15752 Z80 Interrupt Service Routines
15753 \end_layout
15754
15755 \begin_layout Standard
15756 The Z80
15757 \begin_inset LatexCommand index
15758 name "Z80"
15759
15760 \end_inset
15761
15762  uses several different methods for determining the correct interrupt
15763 \begin_inset LatexCommand index
15764 name "Z80!interrupt"
15765
15766 \end_inset
15767
15768  vector depending on the hardware implementation.
15769  Therefore, SDCC ignores the optional interrupt number and does not attempt
15770  to generate an interrupt vector table.
15771 \end_layout
15772
15773 \begin_layout Standard
15774 By default, SDCC generates code for a maskable interrupt, which uses a RETI
15775  instruction to return from the interrupt.
15776  To write an interrupt handler for the non-maskable interrupt, which needs
15777  a RETN instruction instead, add the 
15778 \emph on
15779 critical
15780 \emph default
15781  keyword:
15782 \end_layout
15783
15784 \begin_layout Verse
15785
15786 \family typewriter
15787 void nmi_isr (void) critical interrupt
15788 \newline
15789
15790 \newline
15791 \InsetSpace ~
15792 \InsetSpace ~
15793 \InsetSpace ~
15794 \InsetSpace ~
15795 ...
15796  
15797 \newline
15798 }
15799 \end_layout
15800
15801 \begin_layout Standard
15802 However if you need to create a non-interruptable interrupt service routine
15803  you would also require the 
15804 \emph on
15805 critical
15806 \emph default
15807  keyword.
15808  To distinguish between this and an nmi_isr you must provide an interrupt
15809  number.
15810 \begin_inset VSpace bigskip
15811 \end_inset
15812
15813
15814 \end_layout
15815
15816 \begin_layout Section
15817 Enabling and Disabling Interrupts
15818 \end_layout
15819
15820 \begin_layout Subsection
15821 Critical Functions and Critical Statements
15822 \end_layout
15823
15824 \begin_layout Standard
15825 A special keyword may be associated with a block or a function declaring
15826  it as 
15827 \emph on
15828 critical
15829 \emph default
15830 .
15831  SDCC will generate code to disable all interrupts
15832 \begin_inset LatexCommand index
15833 name "interrupt"
15834
15835 \end_inset
15836
15837  upon entry to a critical function and restore the interrupt enable to the
15838  previous state before returning.
15839  Nesting critical functions will need one additional byte on the stack
15840 \begin_inset LatexCommand index
15841 name "stack"
15842
15843 \end_inset
15844
15845  for each call.
15846 \end_layout
15847
15848 \begin_layout Verse
15849
15850 \family typewriter
15851 int foo () __critical
15852 \begin_inset LatexCommand index
15853 name "critical"
15854
15855 \end_inset
15856
15857
15858 \begin_inset LatexCommand index
15859 name "\\_\\_critical"
15860
15861 \end_inset
15862
15863  
15864 \newline
15865
15866 \newline
15867 \InsetSpace ~
15868 \InsetSpace ~
15869 \InsetSpace ~
15870 \InsetSpace ~
15871 ...
15872  
15873 \newline
15874 \InsetSpace ~
15875 \InsetSpace ~
15876 \InsetSpace ~
15877 \InsetSpace ~
15878 ...
15879  
15880 \newline
15881 }
15882 \end_layout
15883
15884 \begin_layout Standard
15885 The critical attribute maybe used with other attributes like 
15886 \emph on
15887 reentrant.
15888 \emph default
15889
15890 \newline
15891 The keyword 
15892 \emph on
15893 critical
15894 \emph default
15895  may also be used to disable interrupts more locally:
15896 \end_layout
15897
15898 \begin_layout Verse
15899
15900 \family typewriter
15901 __critical{ i++; }
15902 \end_layout
15903
15904 \begin_layout Standard
15905 More than one statement could have been included in the block.
15906 \end_layout
15907
15908 \begin_layout Subsection
15909 Enabling and Disabling Interrupts directly
15910 \end_layout
15911
15912 \begin_layout Standard
15913 Interrupts
15914 \begin_inset LatexCommand index
15915 name "interrupt"
15916
15917 \end_inset
15918
15919  can also be disabled and enabled directly (8051):
15920 \end_layout
15921
15922 \begin_layout Verse
15923
15924 \family typewriter
15925 EA = 0;\InsetSpace ~
15926 \InsetSpace ~
15927 \InsetSpace ~
15928 \InsetSpace ~
15929 \InsetSpace ~
15930 \InsetSpace ~
15931 \InsetSpace ~
15932 \InsetSpace ~
15933 \InsetSpace ~
15934 \InsetSpace ~
15935 \InsetSpace ~
15936 \InsetSpace ~
15937 or:\InsetSpace ~
15938 \InsetSpace ~
15939 \InsetSpace ~
15940 \InsetSpace ~
15941 \InsetSpace ~
15942 \InsetSpace ~
15943 \InsetSpace ~
15944 \InsetSpace ~
15945 \InsetSpace ~
15946 \InsetSpace ~
15947 \InsetSpace ~
15948 EA_SAVE = EA;
15949 \end_layout
15950
15951 \begin_layout Verse
15952
15953 \family typewriter
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 \InsetSpace ~
15978 \InsetSpace ~
15979 \InsetSpace ~
15980 \InsetSpace ~
15981 \InsetSpace ~
15982 \InsetSpace ~
15983 \InsetSpace ~
15984 EA = 0;
15985 \end_layout
15986
15987 \begin_layout Verse
15988
15989 \family typewriter
15990 EA = 1;\InsetSpace ~
15991 \InsetSpace ~
15992 \InsetSpace ~
15993 \InsetSpace ~
15994 \InsetSpace ~
15995 \InsetSpace ~
15996 \InsetSpace ~
15997 \InsetSpace ~
15998 \InsetSpace ~
15999 \InsetSpace ~
16000 \InsetSpace ~
16001 \InsetSpace ~
16002 \InsetSpace ~
16003 \InsetSpace ~
16004 \InsetSpace ~
16005 \InsetSpace ~
16006 \InsetSpace ~
16007 \InsetSpace ~
16008 \InsetSpace ~
16009 \InsetSpace ~
16010 \InsetSpace ~
16011 \InsetSpace ~
16012 \InsetSpace ~
16013 \InsetSpace ~
16014 \InsetSpace ~
16015 \InsetSpace ~
16016 ...
16017 \end_layout
16018
16019 \begin_layout Verse
16020
16021 \family typewriter
16022 \InsetSpace ~
16023 \InsetSpace ~
16024 \InsetSpace ~
16025 \InsetSpace ~
16026 \InsetSpace ~
16027 \InsetSpace ~
16028 \InsetSpace ~
16029 \InsetSpace ~
16030 \InsetSpace ~
16031 \InsetSpace ~
16032 \InsetSpace ~
16033 \InsetSpace ~
16034 \InsetSpace ~
16035 \InsetSpace ~
16036 \InsetSpace ~
16037 \InsetSpace ~
16038 \InsetSpace ~
16039 \InsetSpace ~
16040 \InsetSpace ~
16041 \InsetSpace ~
16042 \InsetSpace ~
16043 \InsetSpace ~
16044 \InsetSpace ~
16045 \InsetSpace ~
16046 \InsetSpace ~
16047 \InsetSpace ~
16048 \InsetSpace ~
16049 \InsetSpace ~
16050 \InsetSpace ~
16051 \InsetSpace ~
16052 \InsetSpace ~
16053 \InsetSpace ~
16054 \InsetSpace ~
16055 EA = EA_SAVE;
16056 \end_layout
16057
16058 \begin_layout Standard
16059 On other architectures which have separate opcodes for enabling and disabling
16060  interrupts you might want to make use of defines with inline assembly
16061 \begin_inset LatexCommand index
16062 name "Assembler routines"
16063
16064 \end_inset
16065
16066  (HC08
16067 \begin_inset LatexCommand index
16068 name "HC08!interrupt"
16069
16070 \end_inset
16071
16072 ):
16073 \end_layout
16074
16075 \begin_layout Verse
16076
16077 \family typewriter
16078 #define CLI _asm
16079 \begin_inset LatexCommand index
16080 name "\\_asm"
16081
16082 \end_inset
16083
16084 \InsetSpace ~
16085 \InsetSpace ~
16086 cli\InsetSpace ~
16087 \InsetSpace ~
16088 _endasm
16089 \begin_inset LatexCommand index
16090 name "\\_endasm"
16091
16092 \end_inset
16093
16094
16095 \end_layout
16096
16097 \begin_layout Verse
16098
16099 \family typewriter
16100 #define SEI _asm\InsetSpace ~
16101 \InsetSpace ~
16102 sei\InsetSpace ~
16103 \InsetSpace ~
16104 _endasm; 
16105 \end_layout
16106
16107 \begin_layout Verse
16108
16109 \family typewriter
16110 ...
16111 \end_layout
16112
16113 \begin_layout Standard
16114 Note: it is sometimes sufficient to disable only a specific interrupt source
16115  like f.e.
16116  a timer or serial interrupt by manipulating an 
16117 \emph on
16118 interrupt mask
16119 \begin_inset LatexCommand index
16120 name "interrupt mask"
16121
16122 \end_inset
16123
16124
16125 \emph default
16126  register.
16127  
16128 \end_layout
16129
16130 \begin_layout Standard
16131 Usually the time during which interrupts are disabled should be kept as
16132  short as possible.
16133  This minimizes both 
16134 \emph on
16135 interrupt latency
16136 \emph default
16137
16138 \begin_inset LatexCommand index
16139 name "interrupt latency"
16140
16141 \end_inset
16142
16143  (the time between the occurrence of the interrupt and the execution of
16144  the first code in the interrupt routine) and 
16145 \emph on
16146 interrupt jitter
16147 \emph default
16148
16149 \begin_inset LatexCommand index
16150 name "interrupt jitter"
16151
16152 \end_inset
16153
16154  (the difference between the shortest and the longest interrupt latency).
16155  These really are something different, f.e.
16156  a serial interrupt has to be served before its buffer overruns so it cares
16157  for the maximum interrupt latency, whereas it does not care about jitter.
16158  On a loudspeaker driven via a digital to analog converter which is fed
16159  by an interrupt a latency of a few milliseconds might be tolerable, whereas
16160  a much smaller jitter will be very audible.
16161 \end_layout
16162
16163 \begin_layout Standard
16164 You can reenable interrupts within an interrupt routine and on some architecture
16165 s you can make use of two (or more) levels of 
16166 \emph on
16167 interrupt priorities
16168 \emph default
16169
16170 \begin_inset LatexCommand index
16171 name "interrupt priority"
16172
16173 \end_inset
16174
16175 .
16176  On some architectures which don't support interrupt priorities these can
16177  be implemented by manipulating the interrupt mask and reenabling interrupts
16178  within the interrupt routine.
16179  Check there is sufficient space on the stack
16180 \begin_inset LatexCommand index
16181 name "stack"
16182
16183 \end_inset
16184
16185  and don't add complexity unless you have to.
16186  
16187 \end_layout
16188
16189 \begin_layout Subsection
16190 Semaphore
16191 \begin_inset LatexCommand index
16192 name "semaphore"
16193
16194 \end_inset
16195
16196  locking (mcs51/ds390)
16197 \end_layout
16198
16199 \begin_layout Standard
16200 Some architectures (mcs51/ds390) have an atomic
16201 \begin_inset LatexCommand index
16202 name "atomic"
16203
16204 \end_inset
16205
16206  bit test and clear instruction.
16207  These type of instructions are typically used in preemptive multitasking
16208  systems, where a routine f.e.
16209  claims the use of a data structure ('acquires a lock
16210 \begin_inset LatexCommand index
16211 name "lock"
16212
16213 \end_inset
16214
16215  on it'), makes some modifications and then releases the lock when the data
16216  structure is consistent again.
16217  The instruction may also be used if interrupt and non-interrupt code have
16218  to compete for a resource.
16219  With the atomic bit test and clear instruction interrupts
16220 \begin_inset LatexCommand index
16221 name "interrupt"
16222
16223 \end_inset
16224
16225  don't have to be disabled for the locking operation.
16226  
16227 \end_layout
16228
16229 \begin_layout Standard
16230 SDCC generates this instruction if the source follows this pattern:
16231 \end_layout
16232
16233 \begin_layout Verse
16234
16235 \family typewriter
16236 volatile
16237 \begin_inset LatexCommand index
16238 name "volatile"
16239
16240 \end_inset
16241
16242  bit resource_is_free; 
16243 \newline
16244
16245 \newline
16246 if (resource_is_free) 
16247 \newline
16248 \InsetSpace ~
16249 \InsetSpace ~
16250
16251 \newline
16252 \InsetSpace ~
16253 \InsetSpace ~
16254 \InsetSpace ~
16255 \InsetSpace ~
16256 resource_is_free=0; 
16257 \newline
16258 \InsetSpace ~
16259 \InsetSpace ~
16260 \InsetSpace ~
16261 \InsetSpace ~
16262 ...
16263  
16264 \newline
16265 \InsetSpace ~
16266 \InsetSpace ~
16267 \InsetSpace ~
16268 \InsetSpace ~
16269 resource_is_free=1;
16270 \newline
16271 \InsetSpace ~
16272 \InsetSpace ~
16273
16274 \end_layout
16275
16276 \begin_layout Standard
16277 Note, mcs51 and ds390 support only an atomic
16278 \begin_inset LatexCommand index
16279 name "atomic"
16280
16281 \end_inset
16282
16283  bit test and 
16284 \emph on
16285 clear
16286 \emph default
16287  instruction (as opposed to atomic bit test and 
16288 \emph on
16289 set).
16290 \end_layout
16291
16292 \begin_layout Section
16293 Functions using private register banks
16294 \begin_inset LatexCommand label
16295 name "sub:Functions-using-private-banks"
16296
16297 \end_inset
16298
16299  (mcs51/ds390)
16300 \end_layout
16301
16302 \begin_layout Standard
16303 Some architectures have support for quickly changing register sets.
16304  SDCC supports this feature with the 
16305 \emph on
16306 using
16307 \begin_inset LatexCommand index
16308 name "using (mcs51, ds390 register bank)"
16309
16310 \end_inset
16311
16312
16313 \begin_inset LatexCommand index
16314 name "\\_\\_using (mcs51, ds390 register bank)"
16315
16316 \end_inset
16317
16318
16319 \emph default
16320  attribute (which tells the compiler to use a register bank
16321 \begin_inset LatexCommand index
16322 name "register bank (mcs51, ds390)"
16323
16324 \end_inset
16325
16326  other than the default bank zero).
16327  It should only be applied to 
16328 \emph on
16329 interrupt
16330 \begin_inset LatexCommand index
16331 name "interrupt"
16332
16333 \end_inset
16334
16335
16336 \emph default
16337  functions (see footnote below).
16338  This will in most circumstances make the generated ISR code more efficient
16339  since it will not have to save registers on the stack.
16340 \end_layout
16341
16342 \begin_layout Standard
16343 The 
16344 \emph on
16345 using
16346 \emph default
16347  attribute will have no effect on the generated code for a 
16348 \emph on
16349 non-interrupt
16350 \emph default
16351  function (but may occasionally be useful anyway
16352 \begin_inset Foot
16353 status open
16354
16355 \begin_layout Standard
16356 possible exception: if a function is called ONLY from 'interrupt' functions
16357  using a particular bank, it can be declared with the same 'using' attribute
16358  as the calling 'interrupt' functions.
16359  For instance, if you have several ISRs using bank one, and all of them
16360  call memcpy(), it might make sense to create a specialized version of memcpy()
16361  'using 1', since this would prevent the ISR from having to save bank zero
16362  to the stack on entry and switch to bank zero before calling the function
16363 \end_layout
16364
16365 \end_inset
16366
16367 ).
16368 \newline
16369
16370 \emph on
16371 (pending: Note, nowadays the
16372 \emph default
16373  using 
16374 \emph on
16375 attribute has an effect on
16376 \emph default
16377  
16378 \emph on
16379 the generated code for a
16380 \emph default
16381  non-interrupt 
16382 \emph on
16383 function
16384 \emph default
16385 .
16386 \emph on
16387 )
16388 \end_layout
16389
16390 \begin_layout Standard
16391 An 
16392 \emph on
16393 interrupt
16394 \emph default
16395  function using a non-zero bank will assume that it can trash that register
16396  bank, and will not save it.
16397  Since high-priority interrupts
16398 \begin_inset LatexCommand index
16399 name "interrupts"
16400
16401 \end_inset
16402
16403
16404 \begin_inset LatexCommand index
16405 name "interrupt priority"
16406
16407 \end_inset
16408
16409  can interrupt low-priority ones on the 8051 and friends, this means that
16410  if a high-priority ISR 
16411 \emph on
16412 using
16413 \emph default
16414  a particular bank occurs while processing a low-priority ISR 
16415 \emph on
16416 using
16417 \emph default
16418  the same bank, terrible and bad things can happen.
16419  To prevent this, no single register bank should be 
16420 \emph on
16421 used
16422 \emph default
16423  by both a high priority and a low priority ISR.
16424  This is probably most easily done by having all high priority ISRs use
16425  one bank and all low priority ISRs use another.
16426  If you have an ISR which can change priority at runtime, you're on your
16427  own: I suggest using the default bank zero and taking the small performance
16428  hit.
16429 \end_layout
16430
16431 \begin_layout Standard
16432 It is most efficient if your ISR calls no other functions.
16433  If your ISR must call other functions, it is most efficient if those functions
16434  use the same bank as the ISR (see note 1 below); the next best is if the
16435  called functions use bank zero.
16436  It is very inefficient to call a function using a different, non-zero bank
16437  from an ISR.
16438  
16439 \begin_inset VSpace bigskip
16440 \end_inset
16441
16442
16443 \end_layout
16444
16445 \begin_layout Section
16446 Startup Code
16447 \begin_inset LatexCommand label
16448 name "sub:Startup-Code"
16449
16450 \end_inset
16451
16452
16453 \begin_inset LatexCommand index
16454 name "Startup code"
16455
16456 \end_inset
16457
16458
16459 \end_layout
16460
16461 \begin_layout Subsection
16462 MCS51/DS390 Startup Code
16463 \end_layout
16464
16465 \begin_layout Standard
16466 The compiler triggers the linker to link certain initialization modules
16467  from the runtime library
16468 \begin_inset LatexCommand index
16469 name "Runtime library"
16470
16471 \end_inset
16472
16473  called crt<something>.
16474  Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
16475  GSINIT5) is not linked unless the -
16476 \series bold
16477
16478 \begin_inset ERT
16479 status open
16480
16481 \begin_layout Standard
16482
16483
16484 \backslash
16485 /
16486 \end_layout
16487
16488 \end_inset
16489
16490
16491 \series default
16492 -xstack option is used.
16493  These modules are highly entangled by the use of special segments/areas,
16494  but a common layout is shown below:
16495 \end_layout
16496
16497 \begin_layout Verse
16498
16499 \family typewriter
16500 \series bold
16501 \size footnotesize
16502 (main.asm)
16503 \end_layout
16504
16505 \begin_layout Verse
16506
16507 \family typewriter
16508 \size footnotesize
16509 \InsetSpace ~
16510 \InsetSpace ~
16511 \InsetSpace ~
16512 \InsetSpace ~
16513 \InsetSpace ~
16514 \InsetSpace ~
16515 \InsetSpace ~
16516 \InsetSpace ~
16517 .area HOME (CODE)
16518 \newline
16519 __interrupt_vect:
16520 \newline
16521 \InsetSpace ~
16522 \InsetSpace ~
16523 \InsetSpace ~
16524 \InsetSpace ~
16525 \InsetSpace ~
16526 \InsetSpace ~
16527 \InsetSpace ~
16528 \InsetSpace ~
16529 ljmp __sdcc_gsinit_startup
16530 \end_layout
16531
16532 \begin_layout Verse
16533
16534 \family typewriter
16535 \series bold
16536 \size footnotesize
16537 (crtstart.asm)
16538 \end_layout
16539
16540 \begin_layout Verse
16541
16542 \family typewriter
16543 \size footnotesize
16544 \InsetSpace ~
16545 \InsetSpace ~
16546 \InsetSpace ~
16547 \InsetSpace ~
16548 \InsetSpace ~
16549 \InsetSpace ~
16550 \InsetSpace ~
16551 \InsetSpace ~
16552 .area GSINIT0 (CODE)
16553 \newline
16554 __sdcc_gsinit_startup::
16555 \newline
16556 \InsetSpace ~
16557 \InsetSpace ~
16558 \InsetSpace ~
16559 \InsetSpace ~
16560 \InsetSpace ~
16561 \InsetSpace ~
16562 \InsetSpace ~
16563 \InsetSpace ~
16564 mov sp,#__start__stack - 1
16565 \end_layout
16566
16567 \begin_layout Verse
16568
16569 \family typewriter
16570 \series bold
16571 \size footnotesize
16572 (crtxstack.asm)
16573 \end_layout
16574
16575 \begin_layout Verse
16576
16577 \family typewriter
16578 \size footnotesize
16579 \InsetSpace ~
16580 \InsetSpace ~
16581 \InsetSpace ~
16582 \InsetSpace ~
16583 \InsetSpace ~
16584 \InsetSpace ~
16585 \InsetSpace ~
16586 \InsetSpace ~
16587 .area GSINIT1 (CODE)
16588 \newline
16589 __sdcc_init_xstack::
16590 \newline
16591 ; Need to initialize in GSINIT1 in
16592  case the user's __sdcc_external_startup uses the xstack.
16593 \newline
16594 \InsetSpace ~
16595 \InsetSpace ~
16596 \InsetSpace ~
16597 \InsetSpace ~
16598 \InsetSpace ~
16599 \InsetSpace ~
16600 \InsetSpace ~
16601 \InsetSpace ~
16602 mov __XPAGE,#(__start__x
16603 stack >> 8)
16604 \newline
16605 \InsetSpace ~
16606 \InsetSpace ~
16607 \InsetSpace ~
16608 \InsetSpace ~
16609 \InsetSpace ~
16610 \InsetSpace ~
16611 \InsetSpace ~
16612 \InsetSpace ~
16613 mov _spx,#__start__xstack
16614 \end_layout
16615
16616 \begin_layout Verse
16617
16618 \family typewriter
16619 \series bold
16620 \size footnotesize
16621 (crtstart.asm)
16622 \end_layout
16623
16624 \begin_layout Verse
16625
16626 \family typewriter
16627 \size footnotesize
16628 \InsetSpace ~
16629 \InsetSpace ~
16630 \InsetSpace ~
16631 \InsetSpace ~
16632 \InsetSpace ~
16633 \InsetSpace ~
16634 \InsetSpace ~
16635 \InsetSpace ~
16636 .area GSINIT2 (CODE)
16637 \newline
16638 \InsetSpace ~
16639 \InsetSpace ~
16640 \InsetSpace ~
16641 \InsetSpace ~
16642 \InsetSpace ~
16643 \InsetSpace ~
16644 \InsetSpace ~
16645 \InsetSpace ~
16646 lcall __sdcc_external_startup
16647 \newline
16648 \InsetSpace ~
16649 \InsetSpace ~
16650 \InsetSpace ~
16651 \InsetSpace ~
16652 \InsetSpace ~
16653 \InsetSpace ~
16654 \InsetSpace ~
16655 \InsetSpace ~
16656 mov a,dpl
16657 \newline
16658 \InsetSpace ~
16659 \InsetSpace ~
16660 \InsetSpace ~
16661 \InsetSpace ~
16662 \InsetSpace ~
16663 \InsetSpace ~
16664 \InsetSpace ~
16665 \InsetSpace ~
16666 jz __sdcc_init_data
16667 \newline
16668 \InsetSpace ~
16669 \InsetSpace ~
16670 \InsetSpace ~
16671 \InsetSpace ~
16672 \InsetSpace ~
16673 \InsetSpace ~
16674 \InsetSpace ~
16675 \InsetSpace ~
16676 ljmp
16677  __sdcc_program_startup
16678 \newline
16679 __sdcc_init_data:
16680 \end_layout
16681
16682 \begin_layout Verse
16683
16684 \family typewriter
16685 \series bold
16686 \size footnotesize
16687 (crtxinit.asm)
16688 \end_layout
16689
16690 \begin_layout Verse
16691
16692 \family typewriter
16693 \size footnotesize
16694 \InsetSpace ~
16695 \InsetSpace ~
16696 \InsetSpace ~
16697 \InsetSpace ~
16698 \InsetSpace ~
16699 \InsetSpace ~
16700 \InsetSpace ~
16701 \InsetSpace ~
16702 .area GSINIT3 (CODE)
16703 \newline
16704 __mcs51_genXINIT::
16705 \newline
16706 \InsetSpace ~
16707 \InsetSpace ~
16708 \InsetSpace ~
16709 \InsetSpace ~
16710 \InsetSpace ~
16711 \InsetSpace ~
16712 \InsetSpace ~
16713 \InsetSpace ~
16714 mov r1,#l_XINIT
16715 \newline
16716 \InsetSpace ~
16717 \InsetSpace ~
16718 \InsetSpace ~
16719 \InsetSpace ~
16720 \InsetSpace ~
16721 \InsetSpace ~
16722 \InsetSpace ~
16723 \InsetSpace ~
16724 mov a,r1
16725 \newline
16726 \InsetSpace ~
16727 \InsetSpace ~
16728 \InsetSpace ~
16729 \InsetSpace ~
16730 \InsetSpace ~
16731 \InsetSpace ~
16732 \InsetSpace ~
16733 \InsetSpace ~
16734 orl a,#(l_XINIT
16735  >> 8)
16736 \newline
16737 \InsetSpace ~
16738 \InsetSpace ~
16739 \InsetSpace ~
16740 \InsetSpace ~
16741 \InsetSpace ~
16742 \InsetSpace ~
16743 \InsetSpace ~
16744 \InsetSpace ~
16745 jz 00003$
16746 \newline
16747 \InsetSpace ~
16748 \InsetSpace ~
16749 \InsetSpace ~
16750 \InsetSpace ~
16751 \InsetSpace ~
16752 \InsetSpace ~
16753 \InsetSpace ~
16754 \InsetSpace ~
16755 mov r2,#((l_XINIT+255) >> 8)
16756 \newline
16757 \InsetSpace ~
16758 \InsetSpace ~
16759 \InsetSpace ~
16760 \InsetSpace ~
16761 \InsetSpace ~
16762 \InsetSpace ~
16763 \InsetSpace ~
16764 \InsetSpace ~
16765 mov dptr,#s_XINIT
16766 \newline
16767 \InsetSpace ~
16768 \InsetSpace ~
16769 \InsetSpace ~
16770 \InsetSpace ~
16771 \InsetSpace ~
16772 \InsetSpace ~
16773 \InsetSpace ~
16774 \InsetSpace ~
16775 mov r0,#s_XISEG
16776 \newline
16777 \InsetSpace ~
16778 \InsetSpace ~
16779 \InsetSpace ~
16780 \InsetSpace ~
16781 \InsetSpace ~
16782 \InsetSpace ~
16783 \InsetSpace ~
16784 \InsetSpace ~
16785 mov
16786  __XPAGE,#(s_XISEG >> 8)
16787 \newline
16788 00001$:\InsetSpace ~
16789 clr a
16790 \newline
16791 \InsetSpace ~
16792 \InsetSpace ~
16793 \InsetSpace ~
16794 \InsetSpace ~
16795 \InsetSpace ~
16796 \InsetSpace ~
16797 \InsetSpace ~
16798 \InsetSpace ~
16799 movc a,@a+dptr
16800 \newline
16801 \InsetSpace ~
16802 \InsetSpace ~
16803 \InsetSpace ~
16804 \InsetSpace ~
16805 \InsetSpace ~
16806 \InsetSpace ~
16807 \InsetSpace ~
16808 \InsetSpace ~
16809 movx @r0,a
16810 \newline
16811 \InsetSpace ~
16812 \InsetSpace ~
16813 \InsetSpace ~
16814 \InsetSpace ~
16815 \InsetSpace ~
16816 \InsetSpace ~
16817 \InsetSpace ~
16818 \InsetSpace ~
16819 inc dptr
16820 \newline
16821 \InsetSpace ~
16822 \InsetSpace ~
16823 \InsetSpace ~
16824 \InsetSpace ~
16825 \InsetSpace ~
16826 \InsetSpace ~
16827 \InsetSpace ~
16828 \InsetSpace ~
16829 inc
16830  r0
16831 \newline
16832 \InsetSpace ~
16833 \InsetSpace ~
16834 \InsetSpace ~
16835 \InsetSpace ~
16836 \InsetSpace ~
16837 \InsetSpace ~
16838 \InsetSpace ~
16839 \InsetSpace ~
16840 cjne r0,#0,00002$
16841 \newline
16842 \InsetSpace ~
16843 \InsetSpace ~
16844 \InsetSpace ~
16845 \InsetSpace ~
16846 \InsetSpace ~
16847 \InsetSpace ~
16848 \InsetSpace ~
16849 \InsetSpace ~
16850 inc __XPAGE
16851 \newline
16852 00002$:\InsetSpace ~
16853 djnz r1,00001$
16854 \newline
16855 \InsetSpace ~
16856 \InsetSpace ~
16857 \InsetSpace ~
16858 \InsetSpace ~
16859 \InsetSpace ~
16860 \InsetSpace ~
16861 \InsetSpace ~
16862 \InsetSpace ~
16863 djnz r2,00001$
16864 \newline
16865 \InsetSpace ~
16866 \InsetSpace ~
16867 \InsetSpace ~
16868 \InsetSpace ~
16869 \InsetSpace ~
16870 \InsetSpace ~
16871 \InsetSpace ~
16872 \InsetSpace ~
16873 mov __XPAGE,#0
16874 xFF
16875 \newline
16876 00003$:
16877 \end_layout
16878
16879 \begin_layout Verse
16880
16881 \family typewriter
16882 \series bold
16883 \size footnotesize
16884 (crtclear.asm)
16885 \end_layout
16886
16887 \begin_layout Verse
16888
16889 \family typewriter
16890 \size footnotesize
16891 \InsetSpace ~
16892 \InsetSpace ~
16893 \InsetSpace ~
16894 \InsetSpace ~
16895 \InsetSpace ~
16896 \InsetSpace ~
16897 \InsetSpace ~
16898 \InsetSpace ~
16899 .area GSINIT4 (CODE)
16900 \newline
16901 __mcs51_genRAMCLEAR::
16902 \newline
16903 \InsetSpace ~
16904 \InsetSpace ~
16905 \InsetSpace ~
16906 \InsetSpace ~
16907 \InsetSpace ~
16908 \InsetSpace ~
16909 \InsetSpace ~
16910 \InsetSpace ~
16911 clr a
16912 \newline
16913 \InsetSpace ~
16914 \InsetSpace ~
16915 \InsetSpace ~
16916 \InsetSpace ~
16917 \InsetSpace ~
16918 \InsetSpace ~
16919 \InsetSpace ~
16920 \InsetSpace ~
16921 mov r0,#(l_IRAM-1)
16922 \newline
16923 00004$:\InsetSpace ~
16924 mov
16925  @r0,a
16926 \newline
16927 \InsetSpace ~
16928 \InsetSpace ~
16929 \InsetSpace ~
16930 \InsetSpace ~
16931 \InsetSpace ~
16932 \InsetSpace ~
16933 \InsetSpace ~
16934 \InsetSpace ~
16935 djnz r0,00004$
16936 \newline
16937 ; _mcs51_genRAMCLEAR() end
16938 \end_layout
16939
16940 \begin_layout Verse
16941
16942 \family typewriter
16943 \series bold
16944 \size footnotesize
16945 (crtxclear.asm)
16946 \end_layout
16947
16948 \begin_layout Verse
16949
16950 \family typewriter
16951 \size footnotesize
16952 \InsetSpace ~
16953 \InsetSpace ~
16954 \InsetSpace ~
16955 \InsetSpace ~
16956 \InsetSpace ~
16957 \InsetSpace ~
16958 \InsetSpace ~
16959 \InsetSpace ~
16960 .area GSINIT4 (CODE)
16961 \newline
16962 __mcs51_genXRAMCLEAR::
16963 \newline
16964 \InsetSpace ~
16965 \InsetSpace ~
16966 \InsetSpace ~
16967 \InsetSpace ~
16968 \InsetSpace ~
16969 \InsetSpace ~
16970 \InsetSpace ~
16971 \InsetSpace ~
16972 mov r0,#l_PSEG
16973 \newline
16974 \InsetSpace ~
16975 \InsetSpace ~
16976 \InsetSpace ~
16977 \InsetSpace ~
16978 \InsetSpace ~
16979 \InsetSpace ~
16980 \InsetSpace ~
16981 \InsetSpace ~
16982 mov a,r0
16983 \newline
16984 \InsetSpace ~
16985 \InsetSpace ~
16986 \InsetSpace ~
16987 \InsetSpace ~
16988 \InsetSpace ~
16989 \InsetSpace ~
16990 \InsetSpace ~
16991 \InsetSpace ~
16992 orl a,#(l_PSEG
16993  >> 8)
16994 \newline
16995 \InsetSpace ~
16996 \InsetSpace ~
16997 \InsetSpace ~
16998 \InsetSpace ~
16999 \InsetSpace ~
17000 \InsetSpace ~
17001 \InsetSpace ~
17002 \InsetSpace ~
17003 jz 00006$
17004 \newline
17005 \InsetSpace ~
17006 \InsetSpace ~
17007 \InsetSpace ~
17008 \InsetSpace ~
17009 \InsetSpace ~
17010 \InsetSpace ~
17011 \InsetSpace ~
17012 \InsetSpace ~
17013 mov r1,#s_PSEG
17014 \newline
17015 \InsetSpace ~
17016 \InsetSpace ~
17017 \InsetSpace ~
17018 \InsetSpace ~
17019 \InsetSpace ~
17020 \InsetSpace ~
17021 \InsetSpace ~
17022 \InsetSpace ~
17023 mov __XPAGE,#(s_PSEG >> 8)
17024 \newline
17025 \InsetSpace ~
17026 \InsetSpace ~
17027 \InsetSpace ~
17028 \InsetSpace ~
17029 \InsetSpace ~
17030 \InsetSpace ~
17031 \InsetSpace ~
17032 \InsetSpace ~
17033 clr a
17034 \newline
17035 00005$:\InsetSpace ~
17036 movx
17037  @r1,a
17038 \newline
17039 \InsetSpace ~
17040 \InsetSpace ~
17041 \InsetSpace ~
17042 \InsetSpace ~
17043 \InsetSpace ~
17044 \InsetSpace ~
17045 \InsetSpace ~
17046 \InsetSpace ~
17047 inc r1
17048 \newline
17049 \InsetSpace ~
17050 \InsetSpace ~
17051 \InsetSpace ~
17052 \InsetSpace ~
17053 \InsetSpace ~
17054 \InsetSpace ~
17055 \InsetSpace ~
17056 \InsetSpace ~
17057 djnz r0,00005$
17058 \newline
17059 00006$:
17060 \newline
17061 \InsetSpace ~
17062 \InsetSpace ~
17063 \InsetSpace ~
17064 \InsetSpace ~
17065 \InsetSpace ~
17066 \InsetSpace ~
17067 \InsetSpace ~
17068 \InsetSpace ~
17069 mov r0,#l_XSEG
17070 \newline
17071 \InsetSpace ~
17072 \InsetSpace ~
17073 \InsetSpace ~
17074 \InsetSpace ~
17075 \InsetSpace ~
17076 \InsetSpace ~
17077 \InsetSpace ~
17078 \InsetSpace ~
17079 mov a,r0
17080 \newline
17081 \InsetSpace ~
17082 \InsetSpace ~
17083 \InsetSpace ~
17084 \InsetSpace ~
17085 \InsetSpace ~
17086 \InsetSpace ~
17087 \InsetSpace ~
17088 \InsetSpace ~
17089 orl a,#(l_XSEG >>
17090  8)
17091 \newline
17092 \InsetSpace ~
17093 \InsetSpace ~
17094 \InsetSpace ~
17095 \InsetSpace ~
17096 \InsetSpace ~
17097 \InsetSpace ~
17098 \InsetSpace ~
17099 \InsetSpace ~
17100 jz 00008$
17101 \newline
17102 \InsetSpace ~
17103 \InsetSpace ~
17104 \InsetSpace ~
17105 \InsetSpace ~
17106 \InsetSpace ~
17107 \InsetSpace ~
17108 \InsetSpace ~
17109 \InsetSpace ~
17110 mov r1,#((l_XSEG + 255) >> 8)
17111 \newline
17112 \InsetSpace ~
17113 \InsetSpace ~
17114 \InsetSpace ~
17115 \InsetSpace ~
17116 \InsetSpace ~
17117 \InsetSpace ~
17118 \InsetSpace ~
17119 \InsetSpace ~
17120 mov dptr,#s_XSEG
17121 \newline
17122 \InsetSpace ~
17123 \InsetSpace ~
17124 \InsetSpace ~
17125 \InsetSpace ~
17126 \InsetSpace ~
17127 \InsetSpace ~
17128 \InsetSpace ~
17129 \InsetSpace ~
17130 clr a
17131 \newline
17132 00007$:\InsetSpace ~
17133 movx
17134  @dptr,a
17135 \newline
17136 \InsetSpace ~
17137 \InsetSpace ~
17138 \InsetSpace ~
17139 \InsetSpace ~
17140 \InsetSpace ~
17141 \InsetSpace ~
17142 \InsetSpace ~
17143 \InsetSpace ~
17144 inc dptr
17145 \newline
17146 \InsetSpace ~
17147 \InsetSpace ~
17148 \InsetSpace ~
17149 \InsetSpace ~
17150 \InsetSpace ~
17151 \InsetSpace ~
17152 \InsetSpace ~
17153 \InsetSpace ~
17154 djnz r0,00007$
17155 \newline
17156 \InsetSpace ~
17157 \InsetSpace ~
17158 \InsetSpace ~
17159 \InsetSpace ~
17160 \InsetSpace ~
17161 \InsetSpace ~
17162 \InsetSpace ~
17163 \InsetSpace ~
17164 djnz r1,00007$
17165 \newline
17166 00008$:
17167 \end_layout
17168
17169 \begin_layout Verse
17170
17171 \family typewriter
17172 \series bold
17173 \size footnotesize
17174 (crtxstack.asm)
17175 \end_layout
17176
17177 \begin_layout Verse
17178
17179 \family typewriter
17180 \size footnotesize
17181 \InsetSpace ~
17182 \InsetSpace ~
17183 \InsetSpace ~
17184 \InsetSpace ~
17185 \InsetSpace ~
17186 \InsetSpace ~
17187 \InsetSpace ~
17188 \InsetSpace ~
17189 .area GSINIT5 (CODE)
17190 \newline
17191 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
17192  modifies __XPAGE
17193 \newline
17194 ; and __mcs51_genRAMCLEAR modifies _spx.
17195 \newline
17196 \InsetSpace ~
17197 \InsetSpace ~
17198 \InsetSpace ~
17199 \InsetSpace ~
17200 \InsetSpace ~
17201 \InsetSpace ~
17202 \InsetSpace ~
17203 \InsetSpace ~
17204 mov __XPAGE,#(__start__x
17205 stack >> 8)
17206 \newline
17207 \InsetSpace ~
17208 \InsetSpace ~
17209 \InsetSpace ~
17210 \InsetSpace ~
17211 \InsetSpace ~
17212 \InsetSpace ~
17213 \InsetSpace ~
17214 \InsetSpace ~
17215 mov _spx,#__start__xstack
17216 \end_layout
17217
17218 \begin_layout Verse
17219
17220 \family typewriter
17221 \series bold
17222 \size footnotesize
17223 (application modules)
17224 \end_layout
17225
17226 \begin_layout Verse
17227
17228 \family typewriter
17229 \size footnotesize
17230 \InsetSpace ~
17231 \InsetSpace ~
17232 \InsetSpace ~
17233 \InsetSpace ~
17234 \InsetSpace ~
17235 \InsetSpace ~
17236 \InsetSpace ~
17237 \InsetSpace ~
17238 .area GSINIT (CODE)
17239 \end_layout
17240
17241 \begin_layout Verse
17242
17243 \family typewriter
17244 \series bold
17245 \size footnotesize
17246 (main.asm)
17247 \end_layout
17248
17249 \begin_layout Verse
17250
17251 \family typewriter
17252 \size footnotesize
17253 \InsetSpace ~
17254 \InsetSpace ~
17255 \InsetSpace ~
17256 \InsetSpace ~
17257 \InsetSpace ~
17258 \InsetSpace ~
17259 \InsetSpace ~
17260 \InsetSpace ~
17261 .area GSFINAL (CODE)
17262 \newline
17263 \InsetSpace ~
17264 \InsetSpace ~
17265 \InsetSpace ~
17266 \InsetSpace ~
17267 \InsetSpace ~
17268 \InsetSpace ~
17269 \InsetSpace ~
17270 \InsetSpace ~
17271 ljmp __sdcc_program_startup
17272 \newline
17273 ;---------------------------------
17274 -----------------------
17275 \newline
17276 ; Home
17277 \newline
17278 ;--------------------------------------------------
17279 ------
17280 \newline
17281 \InsetSpace ~
17282 \InsetSpace ~
17283 \InsetSpace ~
17284 \InsetSpace ~
17285 \InsetSpace ~
17286 \InsetSpace ~
17287 \InsetSpace ~
17288 \InsetSpace ~
17289 .area HOME (CODE)
17290 \newline
17291 \InsetSpace ~
17292 \InsetSpace ~
17293 \InsetSpace ~
17294 \InsetSpace ~
17295 \InsetSpace ~
17296 \InsetSpace ~
17297 \InsetSpace ~
17298 \InsetSpace ~
17299 .area CSEG (CODE)
17300 \newline
17301 __sdcc_program_startup:
17302 \newline
17303 \InsetSpace ~
17304 \InsetSpace ~
17305 \InsetSpace ~
17306 \InsetSpace ~
17307 \InsetSpace ~
17308 \InsetSpace ~
17309 \InsetSpace ~
17310 \InsetSpace ~
17311 lcall _main
17312 \newline
17313 ;
17314  return from main will lock up
17315 \newline
17316 \InsetSpace ~
17317 \InsetSpace ~
17318 \InsetSpace ~
17319 \InsetSpace ~
17320 \InsetSpace ~
17321 \InsetSpace ~
17322 \InsetSpace ~
17323 \InsetSpace ~
17324 sjmp .
17325 \end_layout
17326
17327 \begin_layout Standard
17328 One of these modules (crtstart.asm) contains a call to the C routine 
17329 \emph on
17330 _sdcc_external_startup()
17331 \begin_inset LatexCommand index
17332 name "\\_sdcc\\_external\\_startup()"
17333
17334 \end_inset
17335
17336
17337 \emph default
17338  at the start of the CODE area.
17339  This routine is also in the runtime library
17340 \begin_inset LatexCommand index
17341 name "Runtime library"
17342
17343 \end_inset
17344
17345  and returns 0 by default.
17346  If this routine returns a non-zero value, the static & global variable
17347  initialization will be skipped and the function main will be invoked.
17348  Otherwise static & global variables will be initialized before the function
17349  main is invoked.
17350  You could add an 
17351 \emph on
17352 _sdcc_external_startup()
17353 \emph default
17354  routine to your program to override the default if you need to setup hardware
17355  or perform some other critical operation prior to static & global variable
17356  initialization
17357 \begin_inset LatexCommand index
17358 name "Variable initialization"
17359
17360 \end_inset
17361
17362 .
17363  On some mcs51 variants xdata
17364 \begin_inset LatexCommand index
17365 name "xdata (mcs51, ds390 storage class)"
17366
17367 \end_inset
17368
17369  memory has to be explicitly enabled before it can be accessed or if the
17370  watchdog
17371 \begin_inset LatexCommand index
17372 name "watchdog"
17373
17374 \end_inset
17375
17376  needs to be disabled, this is the place to do it.
17377  The startup code clears all internal data memory, 256 bytes by default,
17378  but from 0 to n-1 if 
17379 \emph on
17380 -
17381 \begin_inset ERT
17382 status collapsed
17383
17384 \begin_layout Standard
17385
17386
17387 \backslash
17388 /
17389 \end_layout
17390
17391 \end_inset
17392
17393 -iram-size
17394 \begin_inset LatexCommand index
17395 name "-\\/-iram-size <Value>"
17396
17397 \end_inset
17398
17399 n
17400 \emph default
17401  is used.
17402  (recommended for Chipcon CC1010).
17403 \end_layout
17404
17405 \begin_layout Standard
17406 See also the compiler options 
17407 \emph on
17408 -
17409 \begin_inset ERT
17410 status collapsed
17411
17412 \begin_layout Standard
17413
17414
17415 \backslash
17416 /
17417 \end_layout
17418
17419 \end_inset
17420
17421 -no-xinit
17422 \emph default
17423 -
17424 \emph on
17425 opt
17426 \emph default
17427
17428 \begin_inset LatexCommand index
17429 name "-\\/-no-xinit-opt"
17430
17431 \end_inset
17432
17433
17434 \emph on
17435 -
17436 \begin_inset ERT
17437 status collapsed
17438
17439 \begin_layout Standard
17440
17441
17442 \backslash
17443 /
17444 \end_layout
17445
17446 \end_inset
17447
17448 -main-return
17449 \emph default
17450
17451 \begin_inset LatexCommand index
17452 name "-\\/-main-return"
17453
17454 \end_inset
17455
17456  and section 
17457 \begin_inset LatexCommand ref
17458 reference "sub:MCS51-variants"
17459
17460 \end_inset
17461
17462  about MCS51-variants.
17463 \newline
17464
17465 \end_layout
17466
17467 \begin_layout Standard
17468 While these initialization modules are meant as generic startup code there
17469  might be the need for customization.
17470  Let's assume the return value of 
17471 \emph on
17472 _sdcc_external_startup()
17473 \emph default
17474  in 
17475 \emph on
17476 crtstart.asm
17477 \emph default
17478  should not be checked (or 
17479 \emph on
17480 _sdcc_external_startup()
17481 \emph default
17482  should not be called at all).
17483  The recommended way would be to copy 
17484 \emph on
17485 crtstart.asm
17486 \emph default
17487  (f.e.
17488  from 
17489 \begin_inset LatexCommand url
17490 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/device/lib/mcs51/crtstart.asm"
17491
17492 \end_inset
17493
17494 ) into the source directory, adapt it there, then assemble it with 
17495 \emph on
17496 asx8051 -plosgff
17497 \begin_inset Foot
17498 status open
17499
17500 \begin_layout Standard
17501 \begin_inset Quotes sld
17502 \end_inset
17503
17504 -plosgff
17505 \begin_inset Quotes srd
17506 \end_inset
17507
17508  are the assembler options used in 
17509 \begin_inset LatexCommand url
17510 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/lib/mcs51/Makefile.in?view=markup "
17511
17512 \end_inset
17513
17514
17515 \end_layout
17516
17517 \end_inset
17518
17519  crtstart.asm
17520 \emph default
17521  and when linking your project explicitly specify 
17522 \emph on
17523 crtstart.rel
17524 \emph default
17525 .
17526  As a bonus a listing of the relocated object file 
17527 \emph on
17528 crtstart.rst
17529 \emph default
17530  is generated.
17531 \end_layout
17532
17533 \begin_layout Standard
17534 \begin_inset VSpace bigskip
17535 \end_inset
17536
17537
17538 \end_layout
17539
17540 \begin_layout Subsection
17541 HC08 Startup Code
17542 \end_layout
17543
17544 \begin_layout Standard
17545 The HC08
17546 \begin_inset LatexCommand index
17547 name "HC08"
17548
17549 \end_inset
17550
17551  startup code follows the same scheme as the MCS51 startup code.
17552 \begin_inset VSpace bigskip
17553 \end_inset
17554
17555
17556 \end_layout
17557
17558 \begin_layout Subsection
17559 Z80 Startup Code
17560 \end_layout
17561
17562 \begin_layout Standard
17563 On the Z80
17564 \begin_inset LatexCommand index
17565 name "Z80"
17566
17567 \end_inset
17568
17569  the startup code is inserted by linking with crt0.o which is generated from
17570  sdcc/device/lib/z80/crt0.s.
17571  If you need a different startup code you can use the compiler option 
17572 \emph on
17573 -
17574 \series bold
17575 \emph default
17576
17577 \begin_inset ERT
17578 status collapsed
17579
17580 \begin_layout Standard
17581
17582
17583 \backslash
17584 /
17585 \end_layout
17586
17587 \end_inset
17588
17589
17590 \series default
17591 \emph on
17592 -no-std-crt0
17593 \emph default
17594
17595 \begin_inset LatexCommand index
17596 name "-\\/-no-std-crt0"
17597
17598 \end_inset
17599
17600  and provide your own crt0.o.
17601  
17602 \begin_inset VSpace bigskip
17603 \end_inset
17604
17605
17606 \end_layout
17607
17608 \begin_layout Section
17609 Inline Assembler Code
17610 \begin_inset LatexCommand index
17611 name "Assembler routines"
17612
17613 \end_inset
17614
17615
17616 \end_layout
17617
17618 \begin_layout Subsection
17619 A Step by Step Introduction
17620 \begin_inset LatexCommand label
17621 name "sub:A-Step-by Assembler Introduction"
17622
17623 \end_inset
17624
17625
17626 \end_layout
17627
17628 \begin_layout Standard
17629 Starting from a small snippet of c-code this example shows for the MCS51
17630  how to use inline assembly, access variables, a function parameter and
17631  an array in xdata memory.
17632  The example uses an MCS51 here but is easily adapted for other architectures.
17633  This is a buffer routine which should be optimized:
17634 \end_layout
17635
17636 \begin_layout Verse
17637
17638 \family typewriter
17639 \size footnotesize
17640 unsigned char __far
17641 \begin_inset LatexCommand index
17642 name "far (storage class)"
17643
17644 \end_inset
17645
17646
17647 \begin_inset LatexCommand index
17648 name "\\_\\_far (storage class)"
17649
17650 \end_inset
17651
17652  __at
17653 \begin_inset LatexCommand index
17654 name "at"
17655
17656 \end_inset
17657
17658
17659 \begin_inset LatexCommand index
17660 name "\\_\\_at"
17661
17662 \end_inset
17663
17664 (0x7f00) buf[0x100];
17665 \begin_inset LatexCommand index
17666 name "Aligned array"
17667
17668 \end_inset
17669
17670
17671 \newline
17672 unsigned char head, tail;\InsetSpace ~
17673 \InsetSpace ~
17674 \InsetSpace ~
17675 \InsetSpace ~
17676 \InsetSpace ~
17677 \InsetSpace ~
17678 \InsetSpace ~
17679 \InsetSpace ~
17680 \InsetSpace ~
17681 \InsetSpace ~
17682 \InsetSpace ~
17683 \InsetSpace ~
17684 \InsetSpace ~
17685 \InsetSpace ~
17686 \InsetSpace ~
17687 \InsetSpace ~
17688 \InsetSpace ~
17689 /* if interrupts
17690 \begin_inset LatexCommand index
17691 name "interrupt"
17692
17693 \end_inset
17694
17695  are involved see
17696 \newline
17697 \InsetSpace ~
17698 \InsetSpace ~
17699 \InsetSpace ~
17700 \InsetSpace ~
17701 \InsetSpace ~
17702 \InsetSpace ~
17703 \InsetSpace ~
17704 \InsetSpace ~
17705 \InsetSpace ~
17706 \InsetSpace ~
17707 \InsetSpace ~
17708 \InsetSpace ~
17709 \InsetSpace ~
17710 \InsetSpace ~
17711 \InsetSpace ~
17712 \InsetSpace ~
17713 \InsetSpace ~
17714 \InsetSpace ~
17715 \InsetSpace ~
17716 \InsetSpace ~
17717 \InsetSpace ~
17718 \InsetSpace ~
17719 \InsetSpace ~
17720 \InsetSpace ~
17721 \InsetSpace ~
17722 \InsetSpace ~
17723 \InsetSpace ~
17724 \InsetSpace ~
17725 \InsetSpace ~
17726 \InsetSpace ~
17727 \InsetSpace ~
17728 \InsetSpace ~
17729 \InsetSpace ~
17730 \InsetSpace ~
17731 \InsetSpace ~
17732 \InsetSpace ~
17733 \InsetSpace ~
17734 \InsetSpace ~
17735 \InsetSpace ~
17736 \InsetSpace ~
17737 \InsetSpace ~
17738 \InsetSpace ~
17739 \InsetSpace ~
17740 \InsetSpace ~
17741 \InsetSpace ~
17742 section 
17743 \begin_inset LatexCommand ref
17744 reference "sub:Common-interrupt-pitfall-volatile"
17745
17746 \end_inset
17747
17748  about
17749 \family default
17750  
17751 \family typewriter
17752 \series bold
17753 volatile
17754 \family default
17755 \series default
17756  
17757 \family typewriter
17758 */
17759 \newline
17760
17761 \newline
17762 void to_buffer( unsigned char c ) 
17763 \newline
17764 {
17765 \newline
17766 \InsetSpace ~
17767 \InsetSpace ~
17768 \InsetSpace ~
17769 \InsetSpace ~
17770 if( head != (unsigned char)(tail-1)
17771  )\InsetSpace ~
17772 /* cast
17773 \family default
17774  
17775 \family typewriter
17776 \series bold
17777 needed
17778 \family default
17779 \series default
17780  
17781 \family typewriter
17782 to avoid promotion
17783 \begin_inset LatexCommand index
17784 name "promotion to signed int"
17785
17786 \end_inset
17787
17788
17789 \begin_inset LatexCommand index
17790 name "type promotion"
17791
17792 \end_inset
17793
17794  to integer */
17795 \begin_inset Marginal
17796 status collapsed
17797
17798 \begin_layout Standard
17799
17800 \series bold
17801 \InsetSpace ~
17802 !
17803 \end_layout
17804
17805 \end_inset
17806
17807
17808 \newline
17809 \InsetSpace ~
17810 \InsetSpace ~
17811 \InsetSpace ~
17812 \InsetSpace ~
17813 \InsetSpace ~
17814 \InsetSpace ~
17815 \InsetSpace ~
17816 \InsetSpace ~
17817 buf[ head++ ] = c;\InsetSpace ~
17818 \InsetSpace ~
17819 \InsetSpace ~
17820 \InsetSpace ~
17821 \InsetSpace ~
17822 \InsetSpace ~
17823 \InsetSpace ~
17824 \InsetSpace ~
17825 \InsetSpace ~
17826 \InsetSpace ~
17827 \InsetSpace ~
17828 \InsetSpace ~
17829 \InsetSpace ~
17830 \InsetSpace ~
17831 \InsetSpace ~
17832 \InsetSpace ~
17833 /* access to a 256 byte aligned array */
17834 \newline
17835
17836 \end_layout
17837
17838 \begin_layout Standard
17839 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
17840  then a corresponding buffer.asm file is generated.
17841  We define a new function 
17842 \family typewriter
17843 to_buffer_asm()
17844 \family default
17845  in file buffer.c in which we cut and paste the generated code, removing
17846  unwanted comments and some ':'.
17847  Then add 
17848 \begin_inset Quotes sld
17849 \end_inset
17850
17851
17852 \series bold
17853 _asm
17854 \series default
17855
17856 \begin_inset Quotes srd
17857 \end_inset
17858
17859  and 
17860 \begin_inset Quotes sld
17861 \end_inset
17862
17863
17864 \series bold
17865 _endasm;
17866 \series default
17867
17868 \begin_inset Quotes srd
17869 \end_inset
17870
17871
17872 \begin_inset Foot
17873 status open
17874
17875 \begin_layout Standard
17876 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
17877  and for C-99 compatibility, the double-underscore form (__asm and __endasm)
17878  has to be used.
17879  The latter is also used in the library functions.
17880 \end_layout
17881
17882 \end_inset
17883
17884  to the beginning and the end of the function body:
17885 \end_layout
17886
17887 \begin_layout Verse
17888
17889 \family typewriter
17890 \size footnotesize
17891 /* With a cut and paste from the .asm file, we have something to start with.
17892 \newline
17893 \InsetSpace ~
17894 \InsetSpace ~
17895 \InsetSpace ~
17896 The
17897  function is not yet OK! (registers aren't saved) */ 
17898 \newline
17899 void to_buffer_asm(
17900  unsigned char c ) 
17901 \newline
17902
17903 \newline
17904 \InsetSpace ~
17905 \InsetSpace ~
17906 \InsetSpace ~
17907 \InsetSpace ~
17908 _asm
17909 \begin_inset LatexCommand index
17910 name "\\_asm"
17911
17912 \end_inset
17913
17914
17915 \begin_inset LatexCommand index
17916 name "\\_\\_asm"
17917
17918 \end_inset
17919
17920
17921 \newline
17922 \InsetSpace ~
17923 \InsetSpace ~
17924 \InsetSpace ~
17925 \InsetSpace ~
17926 mov\InsetSpace ~
17927 \InsetSpace ~
17928 r2,dpl 
17929 \newline
17930 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
17931 /* cast
17932 \family default
17933  
17934 \family typewriter
17935 \series bold
17936 needed
17937 \family default
17938 \series default
17939  
17940 \family typewriter
17941 to avoid promotion
17942 \begin_inset LatexCommand index
17943 name "promotion to signed int"
17944
17945 \end_inset
17946
17947
17948 \begin_inset LatexCommand index
17949 name "type promotion"
17950
17951 \end_inset
17952
17953  to integer */
17954 \newline
17955 \InsetSpace ~
17956 \InsetSpace ~
17957 \InsetSpace ~
17958 \InsetSpace ~
17959 mov\InsetSpace ~
17960 \InsetSpace ~
17961 a,_tail 
17962 \newline
17963 \InsetSpace ~
17964 \InsetSpace ~
17965 \InsetSpace ~
17966 \InsetSpace ~
17967 dec\InsetSpace ~
17968 \InsetSpace ~
17969
17970 \newline
17971 \InsetSpace ~
17972 \InsetSpace ~
17973 \InsetSpace ~
17974 \InsetSpace ~
17975 mov\InsetSpace ~
17976 \InsetSpace ~
17977 r3,a 
17978 \newline
17979 \InsetSpace ~
17980 \InsetSpace ~
17981 \InsetSpace ~
17982 \InsetSpace ~
17983 mov\InsetSpace ~
17984 \InsetSpace ~
17985 a,_head 
17986 \newline
17987 \InsetSpace ~
17988 \InsetSpace ~
17989 \InsetSpace ~
17990 \InsetSpace ~
17991 cjne a,ar3,00106$ 
17992 \newline
17993 \InsetSpace ~
17994 \InsetSpace ~
17995 \InsetSpace ~
17996 \InsetSpace ~
17997 ret
17998 \newline
17999 00106$:
18000  
18001 \newline
18002 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
18003 \begin_inset LatexCommand index
18004 name "Aligned array"
18005
18006 \end_inset
18007
18008
18009 \newline
18010 \InsetSpace ~
18011 \InsetSpace ~
18012 \InsetSpace ~
18013 \InsetSpace ~
18014 mov\InsetSpace ~
18015 \InsetSpace ~
18016 r3,_head 
18017 \newline
18018 \InsetSpace ~
18019 \InsetSpace ~
18020 \InsetSpace ~
18021 \InsetSpace ~
18022 inc\InsetSpace ~
18023 \InsetSpace ~
18024 _head 
18025 \newline
18026 \InsetSpace ~
18027 \InsetSpace ~
18028 \InsetSpace ~
18029 \InsetSpace ~
18030 mov\InsetSpace ~
18031 \InsetSpace ~
18032 dpl,r3 
18033 \newline
18034 \InsetSpace ~
18035 \InsetSpace ~
18036 \InsetSpace ~
18037 \InsetSpace ~
18038 mov\InsetSpace ~
18039 \InsetSpace ~
18040 dph,#(_buf >> 8) 
18041 \newline
18042 \InsetSpace ~
18043 \InsetSpace ~
18044 \InsetSpace ~
18045 \InsetSpace ~
18046 mov\InsetSpace ~
18047 \InsetSpace ~
18048 a,r2 
18049 \newline
18050 \InsetSpace ~
18051 \InsetSpace ~
18052 \InsetSpace ~
18053 \InsetSpace ~
18054 movx @dptr,a
18055  
18056 \newline
18057 00103$: 
18058 \newline
18059 \InsetSpace ~
18060 \InsetSpace ~
18061 \InsetSpace ~
18062 \InsetSpace ~
18063 ret
18064 \newline
18065 \InsetSpace ~
18066 \InsetSpace ~
18067 \InsetSpace ~
18068 \InsetSpace ~
18069 _endasm
18070 \begin_inset LatexCommand index
18071 name "\\_endasm"
18072
18073 \end_inset
18074
18075
18076 \begin_inset LatexCommand index
18077 name "\\_\\_endasm"
18078
18079 \end_inset
18080
18081 ;
18082 \newline
18083
18084 \end_layout
18085
18086 \begin_layout Standard
18087 The new file buffer.c should compile with only one warning about the unreferenced
18088  function argument 'c'.
18089  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
18090  (1) and finally have:
18091 \end_layout
18092
18093 \begin_layout Verse
18094
18095 \family typewriter
18096 \size footnotesize
18097 unsigned char __far __at(0x7f00) buf[0x100];
18098 \newline
18099 unsigned char head, tail;
18100 \newline
18101 #define
18102  USE_ASSEMBLY (1)
18103 \newline
18104
18105 \newline
18106 #if !USE_ASSEMBLY
18107 \newline
18108
18109 \newline
18110 void to_buffer( unsigned char c )
18111 \newline
18112 {
18113 \newline
18114 \InsetSpace ~
18115 \InsetSpace ~
18116 \InsetSpace ~
18117 \InsetSpace ~
18118 if(
18119  head != (unsigned char)(tail-1) )
18120 \newline
18121 \InsetSpace ~
18122 \InsetSpace ~
18123 \InsetSpace ~
18124 \InsetSpace ~
18125 \InsetSpace ~
18126 \InsetSpace ~
18127 \InsetSpace ~
18128 \InsetSpace ~
18129 buf[ head++ ] = c;
18130 \newline
18131 }
18132 \newline
18133
18134 \newline
18135 #else
18136 \newline
18137
18138 \newline
18139 void to_buffer(
18140  unsigned char c )
18141 \newline
18142 {
18143 \newline
18144 \InsetSpace ~
18145 \InsetSpace ~
18146 \InsetSpace ~
18147 \InsetSpace ~
18148 c; // to avoid warning: unreferenced function argument
18149 \newline
18150 \InsetSpace ~
18151 \InsetSpace ~
18152 \InsetSpace ~
18153 \InsetSpace ~
18154 _asm
18155 \begin_inset LatexCommand index
18156 name "\\_asm"
18157
18158 \end_inset
18159
18160
18161 \begin_inset LatexCommand index
18162 name "\\_\\_asm"
18163
18164 \end_inset
18165
18166
18167 \newline
18168 \InsetSpace ~
18169 \InsetSpace ~
18170 \InsetSpace ~
18171 \InsetSpace ~
18172 \InsetSpace ~
18173 \InsetSpace ~
18174 \InsetSpace ~
18175 \InsetSpace ~
18176 ; save used registers here.
18177  
18178 \newline
18179 \InsetSpace ~
18180 \InsetSpace ~
18181 \InsetSpace ~
18182 \InsetSpace ~
18183 \InsetSpace ~
18184 \InsetSpace ~
18185 \InsetSpace ~
18186 \InsetSpace ~
18187 ; If we were still using r2,r3 we would have to push them here.
18188  
18189 \newline
18190 ; if( head != (unsigned char)(tail-1) )
18191 \newline
18192 \InsetSpace ~
18193 \InsetSpace ~
18194 \InsetSpace ~
18195 \InsetSpace ~
18196 \InsetSpace ~
18197 \InsetSpace ~
18198 \InsetSpace ~
18199 \InsetSpace ~
18200 mov\InsetSpace ~
18201  a,_tail
18202 \newline
18203 \InsetSpace ~
18204 \InsetSpace ~
18205 \InsetSpace ~
18206 \InsetSpace ~
18207 \InsetSpace ~
18208 \InsetSpace ~
18209 \InsetSpace ~
18210 \InsetSpace ~
18211 dec\InsetSpace ~
18212  a
18213 \newline
18214 \InsetSpace ~
18215 \InsetSpace ~
18216 \InsetSpace ~
18217 \InsetSpace ~
18218 \InsetSpace ~
18219 \InsetSpace ~
18220 \InsetSpace ~
18221 \InsetSpace ~
18222 xrl\InsetSpace ~
18223  a,_head
18224 \newline
18225 \InsetSpace ~
18226 \InsetSpace ~
18227 \InsetSpace ~
18228 \InsetSpace ~
18229 \InsetSpace ~
18230 \InsetSpace ~
18231 \InsetSpace ~
18232 \InsetSpace ~
18233 ; we
18234  could do an ANL a,#0x0f here to use a smaller buffer (see below)
18235 \newline
18236 \InsetSpace ~
18237 \InsetSpace ~
18238 \InsetSpace ~
18239 \InsetSpace ~
18240 \InsetSpace ~
18241 \InsetSpace ~
18242 \InsetSpace ~
18243 \InsetSpace ~
18244 jz\InsetSpace ~
18245 \InsetSpace ~
18246  t_b_end$
18247 \newline
18248 \InsetSpace ~
18249 \InsetSpace ~
18250 \InsetSpace ~
18251 \InsetSpace ~
18252 \InsetSpace ~
18253 \InsetSpace ~
18254 \InsetSpace ~
18255 \InsetSpace ~
18256 ;
18257 \newline
18258 ;
18259  buf[ head++ ] = c;
18260 \newline
18261 \InsetSpace ~
18262 \InsetSpace ~
18263 \InsetSpace ~
18264 \InsetSpace ~
18265 \InsetSpace ~
18266 \InsetSpace ~
18267 \InsetSpace ~
18268 \InsetSpace ~
18269 mov\InsetSpace ~
18270  a,dpl \InsetSpace ~
18271 \InsetSpace ~
18272 \InsetSpace ~
18273 \InsetSpace ~
18274 \InsetSpace ~
18275 \InsetSpace ~
18276 \InsetSpace ~
18277 ; dpl holds lower byte of function argument
18278 \newline
18279 \InsetSpace ~
18280 \InsetSpace ~
18281 \InsetSpace ~
18282 \InsetSpace ~
18283 \InsetSpace ~
18284 \InsetSpace ~
18285 \InsetSpace ~
18286 \InsetSpace ~
18287 mov\InsetSpace ~
18288
18289  dpl,_head \InsetSpace ~
18290 \InsetSpace ~
18291 \InsetSpace ~
18292 ; buf is 0x100 byte aligned so head can be used directly
18293 \newline
18294 \InsetSpace ~
18295 \InsetSpace ~
18296 \InsetSpace ~
18297 \InsetSpace ~
18298 \InsetSpace ~
18299 \InsetSpace ~
18300 \InsetSpace ~
18301 \InsetSpace ~
18302 mov\InsetSpace ~
18303  dph,#(_bu
18304 f>>8)
18305 \newline
18306 \InsetSpace ~
18307 \InsetSpace ~
18308 \InsetSpace ~
18309 \InsetSpace ~
18310 \InsetSpace ~
18311 \InsetSpace ~
18312 \InsetSpace ~
18313 \InsetSpace ~
18314 movx @dptr,a
18315 \newline
18316 \InsetSpace ~
18317 \InsetSpace ~
18318 \InsetSpace ~
18319 \InsetSpace ~
18320 \InsetSpace ~
18321 \InsetSpace ~
18322 \InsetSpace ~
18323 \InsetSpace ~
18324 inc \InsetSpace ~
18325 _head
18326 \newline
18327 \InsetSpace ~
18328 \InsetSpace ~
18329 \InsetSpace ~
18330 \InsetSpace ~
18331 \InsetSpace ~
18332 \InsetSpace ~
18333 \InsetSpace ~
18334 \InsetSpace ~
18335 ; we could do an ANL _head,#0x0f here to use a
18336  smaller buffer (see above)
18337 \newline
18338 t_b_end$:
18339 \newline
18340 \InsetSpace ~
18341 \InsetSpace ~
18342 \InsetSpace ~
18343 \InsetSpace ~
18344 \InsetSpace ~
18345 \InsetSpace ~
18346 \InsetSpace ~
18347 \InsetSpace ~
18348 ; restore used registers here 
18349 \newline
18350 \InsetSpace ~
18351 \InsetSpace ~
18352 \InsetSpace ~
18353 \InsetSpace ~
18354 _endasm
18355 \begin_inset LatexCommand index
18356 name "\\_endasm"
18357
18358 \end_inset
18359
18360
18361 \begin_inset LatexCommand index
18362 name "\\_\\_endasm"
18363
18364 \end_inset
18365
18366 ;
18367 \newline
18368 }
18369 \newline
18370 #endif
18371 \end_layout
18372
18373 \begin_layout Standard
18374 The inline assembler code can contain any valid code understood by the assembler
18375 , this includes any assembler directives and comment lines.
18376  The assembler does not like some characters like ':' or ''' in comments.
18377  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
18378 \begin_inset LatexCommand index
18379 name "asXXXX (as-gbz80, as-hc08, asx8051, as-z80)"
18380
18381 \end_inset
18382
18383
18384 \begin_inset LatexCommand index
18385 name "Assembler documentation"
18386
18387 \end_inset
18388
18389  or online at 
18390 \begin_inset LatexCommand url
18391 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html"
18392
18393 \end_inset
18394
18395 \InsetSpace ~
18396 .
18397 \end_layout
18398
18399 \begin_layout Standard
18400 The compiler does not do any validation of the code within the 
18401 \family typewriter
18402 _asm
18403 \begin_inset LatexCommand index
18404 name "\\_asm"
18405
18406 \end_inset
18407
18408
18409 \begin_inset LatexCommand index
18410 name "\\_\\_asm"
18411
18412 \end_inset
18413
18414  ...
18415  _endasm
18416 \size footnotesize
18417
18418 \begin_inset LatexCommand index
18419 name "\\_endasm"
18420
18421 \end_inset
18422
18423
18424 \begin_inset LatexCommand index
18425 name "\\_\\_endasm"
18426
18427 \end_inset
18428
18429
18430 \size default
18431 ;
18432 \family default
18433  keyword pair.
18434  Specifically it will not know which registers are used and thus register
18435  pushing/popping
18436 \begin_inset LatexCommand index
18437 name "push/pop"
18438
18439 \end_inset
18440
18441  has to be done manually.
18442  
18443 \end_layout
18444
18445 \begin_layout Standard
18446 It is recommended that each assembly instruction (including labels) be placed
18447  in a separate line (as the example shows).
18448  When the -
18449 \begin_inset ERT
18450 status collapsed
18451
18452 \begin_layout Standard
18453
18454
18455 \backslash
18456 /
18457 \end_layout
18458
18459 \end_inset
18460
18461 -
18462 \emph on
18463 peep-asm
18464 \begin_inset LatexCommand index
18465 name "-\\/-peep-asm"
18466
18467 \end_inset
18468
18469
18470 \emph default
18471  command line option is used, the inline assembler code will be passed through
18472  the peephole optimizer
18473 \begin_inset LatexCommand index
18474 name "Peephole optimizer"
18475
18476 \end_inset
18477
18478 .
18479  There are only a few (if any) cases where this option makes sense, it might
18480  cause some unexpected changes in the inline assembler code.
18481  Please go through the peephole optimizer rules defined in file 
18482 \emph on
18483 SDCCpeeph.def
18484 \emph default
18485  before using this option.
18486 \end_layout
18487
18488 \begin_layout Subsection
18489 Naked Functions
18490 \begin_inset LatexCommand label
18491 name "sub:Naked-Functions"
18492
18493 \end_inset
18494
18495
18496 \begin_inset LatexCommand index
18497 name "Naked functions"
18498
18499 \end_inset
18500
18501
18502 \end_layout
18503
18504 \begin_layout Standard
18505 A special keyword may be associated with a function declaring it as 
18506 \emph on
18507 _naked
18508 \begin_inset LatexCommand index
18509 name "\\_naked"
18510
18511 \end_inset
18512
18513
18514 \begin_inset LatexCommand index
18515 name "\\_\\_naked"
18516
18517 \end_inset
18518
18519 .
18520
18521 \emph default
18522  The 
18523 \emph on
18524 _naked
18525 \emph default
18526  function modifier attribute prevents the compiler from generating prologue
18527 \begin_inset LatexCommand index
18528 name "function prologue"
18529
18530 \end_inset
18531
18532  and epilogue
18533 \begin_inset LatexCommand index
18534 name "function epilogue"
18535
18536 \end_inset
18537
18538  code for that function.
18539  This means that the user is entirely responsible for such things as saving
18540  any registers that may need to be preserved, selecting the proper register
18541  bank, generating the 
18542 \emph on
18543 return
18544 \emph default
18545  instruction at the end, etc.
18546  Practically, this means that the contents of the function must be written
18547  in inline assembler.
18548  This is particularly useful for interrupt functions, which can have a large
18549  (and often unnecessary) prologue/epilogue.
18550  For example, compare the code generated by these two functions:
18551 \end_layout
18552
18553 \begin_layout Verse
18554
18555 \family typewriter
18556 volatile
18557 \begin_inset LatexCommand index
18558 name "volatile"
18559
18560 \end_inset
18561
18562  data unsigned char counter;
18563 \newline
18564
18565 \newline
18566 void simpleInterrupt(void) __interrupt
18567 \begin_inset LatexCommand index
18568 name "interrupt"
18569
18570 \end_inset
18571
18572
18573 \begin_inset LatexCommand index
18574 name "\\_\\_interrupt"
18575
18576 \end_inset
18577
18578  (1)
18579 \newline
18580 {
18581 \newline
18582 \InsetSpace ~
18583 \InsetSpace ~
18584 \InsetSpace ~
18585 \InsetSpace ~
18586 counter++;
18587 \newline
18588 }
18589 \newline
18590
18591 \newline
18592 void nakedInterrupt(void) __interrupt (2) __naked
18593 \newline
18594 {
18595 \newline
18596 \InsetSpace ~
18597 \InsetSpace ~
18598 \InsetSpace ~
18599 \InsetSpace ~
18600 _asm
18601 \begin_inset LatexCommand index
18602 name "\\_asm"
18603
18604 \end_inset
18605
18606
18607 \begin_inset LatexCommand index
18608 name "\\_\\_asm"
18609
18610 \end_inset
18611
18612
18613 \newline
18614 \InsetSpace ~
18615 \InsetSpace ~
18616 \InsetSpace ~
18617 \InsetSpace ~
18618 \InsetSpace ~
18619 \InsetSpace ~
18620 inc\InsetSpace ~
18621 \InsetSpace ~
18622 \InsetSpace ~
18623 \InsetSpace ~
18624 \InsetSpace ~
18625 _counter ; does not change flags, no need to save psw
18626 \newline
18627 \InsetSpace ~
18628 \InsetSpace ~
18629 \InsetSpace ~
18630 \InsetSpace ~
18631 \InsetSpace ~
18632 \InsetSpace ~
18633 reti\InsetSpace ~
18634 \InsetSpace ~
18635 \InsetSpace ~
18636 \InsetSpace ~
18637 ; MUST explicitly
18638  include ret or reti in _naked function.
18639 \newline
18640 \InsetSpace ~
18641 \InsetSpace ~
18642 \InsetSpace ~
18643 \InsetSpace ~
18644 _endasm
18645 \begin_inset LatexCommand index
18646 name "\\_endasm"
18647
18648 \end_inset
18649
18650
18651 \begin_inset LatexCommand index
18652 name "\\_\\_endasm"
18653
18654 \end_inset
18655
18656 ;
18657 \newline
18658 }
18659 \end_layout
18660
18661 \begin_layout Standard
18662 For an 8051 target, the generated simpleInterrupt looks like:
18663 \end_layout
18664
18665 \begin_layout Verse
18666
18667 \family typewriter
18668 Note, this is an
18669 \family default
18670  
18671 \family typewriter
18672 \emph on
18673 outdated
18674 \family default
18675 \emph default
18676  
18677 \family typewriter
18678 example, recent versions of SDCC generate
18679 \newline
18680 the
18681 \family default
18682  
18683 \family typewriter
18684 \emph on
18685 same
18686 \family default
18687 \emph default
18688  
18689 \family typewriter
18690 code for simpleInterrupt() and nakedInterrupt()!
18691 \newline
18692
18693 \newline
18694 _simpleInterrupt:
18695 \newline
18696 \InsetSpace ~
18697 \InsetSpace ~
18698 \InsetSpace ~
18699 \InsetSpace ~
18700 push\InsetSpace ~
18701 \InsetSpace ~
18702 \InsetSpace ~
18703 \InsetSpace ~
18704 acc
18705 \newline
18706 \InsetSpace ~
18707 \InsetSpace ~
18708 \InsetSpace ~
18709 \InsetSpace ~
18710 push\InsetSpace ~
18711 \InsetSpace ~
18712 \InsetSpace ~
18713 \InsetSpace ~
18714 b
18715 \newline
18716 \InsetSpace ~
18717 \InsetSpace ~
18718 \InsetSpace ~
18719 \InsetSpace ~
18720 pus
18721 h\InsetSpace ~
18722 \InsetSpace ~
18723 \InsetSpace ~
18724 \InsetSpace ~
18725 dpl
18726 \newline
18727 \InsetSpace ~
18728 \InsetSpace ~
18729 \InsetSpace ~
18730 \InsetSpace ~
18731 push\InsetSpace ~
18732 \InsetSpace ~
18733 \InsetSpace ~
18734 \InsetSpace ~
18735 dph
18736 \newline
18737 \InsetSpace ~
18738 \InsetSpace ~
18739 \InsetSpace ~
18740 \InsetSpace ~
18741 push\InsetSpace ~
18742 \InsetSpace ~
18743 \InsetSpace ~
18744 \InsetSpace ~
18745 psw
18746 \newline
18747 \InsetSpace ~
18748 \InsetSpace ~
18749 \InsetSpace ~
18750 \InsetSpace ~
18751 mov\InsetSpace ~
18752 \InsetSpace ~
18753 \InsetSpace ~
18754 \InsetSpace ~
18755 \InsetSpace ~
18756 psw,#0x00
18757 \newline
18758 \InsetSpace ~
18759 \InsetSpace ~
18760 \InsetSpace ~
18761 \InsetSpace ~
18762 inc\InsetSpace ~
18763 \InsetSpace ~
18764 \InsetSpace ~
18765 \InsetSpace ~
18766 \InsetSpace ~
18767 _counter
18768 \newline
18769 \InsetSpace ~
18770 \InsetSpace ~
18771 \InsetSpace ~
18772 \InsetSpace ~
18773 pop\InsetSpace ~
18774 \InsetSpace ~
18775 \InsetSpace ~
18776 \InsetSpace ~
18777 \InsetSpace ~
18778 psw
18779 \newline
18780 \InsetSpace ~
18781 \InsetSpace ~
18782 \InsetSpace ~
18783 \InsetSpace ~
18784 pop\InsetSpace ~
18785 \InsetSpace ~
18786 \InsetSpace ~
18787 \InsetSpace ~
18788 \InsetSpace ~
18789 dph
18790 \newline
18791 \InsetSpace ~
18792 \InsetSpace ~
18793 \InsetSpace ~
18794 \InsetSpace ~
18795 pop\InsetSpace ~
18796 \InsetSpace ~
18797 \InsetSpace ~
18798 \InsetSpace ~
18799 \InsetSpace ~
18800 dpl
18801 \newline
18802 \InsetSpace ~
18803 \InsetSpace ~
18804 \InsetSpace ~
18805 \InsetSpace ~
18806 pop\InsetSpace ~
18807 \InsetSpace ~
18808 \InsetSpace ~
18809 \InsetSpace ~
18810 \InsetSpace ~
18811 b
18812 \newline
18813 \InsetSpace ~
18814 \InsetSpace ~
18815 \InsetSpace ~
18816 \InsetSpace ~
18817 pop\InsetSpace ~
18818 \InsetSpace ~
18819 \InsetSpace ~
18820 \InsetSpace ~
18821 \InsetSpace ~
18822 acc
18823 \newline
18824 \InsetSpace ~
18825 \InsetSpace ~
18826 \InsetSpace ~
18827 \InsetSpace ~
18828 reti
18829 \end_layout
18830
18831 \begin_layout Standard
18832 whereas nakedInterrupt looks like:
18833 \end_layout
18834
18835 \begin_layout Verse
18836
18837 \family typewriter
18838 _nakedInterrupt:
18839 \newline
18840 \InsetSpace ~
18841 \InsetSpace ~
18842 \InsetSpace ~
18843 \InsetSpace ~
18844 inc\InsetSpace ~
18845 \InsetSpace ~
18846 \InsetSpace ~
18847 \InsetSpace ~
18848 _counter ; does not change flags, no need to save psw
18849 \newline
18850 \InsetSpace ~
18851 \InsetSpace ~
18852 \InsetSpace ~
18853 \InsetSpace ~
18854 reti\InsetSpace ~
18855 \InsetSpace ~
18856 \InsetSpace ~
18857 \InsetSpace ~
18858 \InsetSpace ~
18859 \InsetSpace ~
18860 \InsetSpace ~
18861 \InsetSpace ~
18862 \InsetSpace ~
18863 \InsetSpace ~
18864 \InsetSpace ~
18865 \InsetSpace ~
18866 ;
18867  MUST explicitly include ret or reti in _naked function
18868 \end_layout
18869
18870 \begin_layout Standard
18871 The related directive #pragma exclude
18872 \begin_inset LatexCommand index
18873 name "\\#pragma exclude"
18874
18875 \end_inset
18876
18877  allows a more fine grained control over pushing & popping
18878 \begin_inset LatexCommand index
18879 name "push/pop"
18880
18881 \end_inset
18882
18883  the registers.
18884 \end_layout
18885
18886 \begin_layout Standard
18887 While there is nothing preventing you from writing C code inside a 
18888 \family typewriter
18889 _naked
18890 \family default
18891  function, there are many ways to shoot yourself in the foot doing this,
18892  and it is recommended that you stick to inline assembler.
18893 \end_layout
18894
18895 \begin_layout Subsection
18896 Use of Labels within Inline Assembler
18897 \end_layout
18898
18899 \begin_layout Standard
18900 SDCC allows the use of in-line assembler with a few restrictions regarding
18901  labels.
18902  All labels defined within inline assembler code have to be of the form
18903  
18904 \emph on
18905 nnnnn$
18906 \emph default
18907  where nnnnn is a number less than 100 (which implies a limit of utmost
18908  100 inline assembler labels 
18909 \emph on
18910 per function
18911 \emph default
18912 \noun on
18913 )
18914 \noun default
18915 .
18916 \begin_inset Foot
18917 status open
18918
18919 \begin_layout Standard
18920 This is a slightly more stringent rule than absolutely necessary, but stays
18921  always on the safe side.
18922  Labels in the form of nnnnn$ are local labels in the assembler, locality
18923  of which is confined within two labels of the standard form.
18924  The compiler uses the same form for labels within a function (but starting
18925  from nnnnn=00100); and places always a standard label at the beginning
18926  of a function, thus limiting the locality of labels within the scope of
18927  the function.
18928  So, if the inline assembler part would be embedded into C-code, an improperly
18929  placed non-local label in the assembler would break up the reference space
18930  for labels created by the compiler for the C-code, leading to an assembling
18931  error.
18932 \end_layout
18933
18934 \begin_layout Standard
18935 The numeric part of local labels does not need to have 5 digits (although
18936  this is the form of labels output by the compiler), any valid integer will
18937  do.
18938  Please refer to the assemblers documentation for further details.
18939 \end_layout
18940
18941 \end_inset
18942
18943  
18944 \end_layout
18945
18946 \begin_layout Verse
18947
18948 \family typewriter
18949 _asm
18950 \begin_inset LatexCommand index
18951 name "\\_asm"
18952
18953 \end_inset
18954
18955
18956 \begin_inset LatexCommand index
18957 name "\\_\\_asm"
18958
18959 \end_inset
18960
18961  
18962 \newline
18963 \InsetSpace ~
18964 \InsetSpace ~
18965 \InsetSpace ~
18966 \InsetSpace ~
18967 mov\InsetSpace ~
18968 \InsetSpace ~
18969 \InsetSpace ~
18970 \InsetSpace ~
18971 \InsetSpace ~
18972 b,#10 
18973 \newline
18974 00001$: 
18975 \newline
18976 \InsetSpace ~
18977 \InsetSpace ~
18978 \InsetSpace ~
18979 \InsetSpace ~
18980 djnz\InsetSpace ~
18981 \InsetSpace ~
18982 \InsetSpace ~
18983 \InsetSpace ~
18984 b,00001$ 
18985 \newline
18986 _endasm
18987 \begin_inset LatexCommand index
18988 name "\\_endasm"
18989
18990 \end_inset
18991
18992
18993 \begin_inset LatexCommand index
18994 name "\\_\\_endasm"
18995
18996 \end_inset
18997
18998  ;
18999 \end_layout
19000
19001 \begin_layout Standard
19002 Inline assembler code cannot reference any C-labels, however it can reference
19003  labels
19004 \begin_inset LatexCommand index
19005 name "Labels"
19006
19007 \end_inset
19008
19009  defined by the inline assembler, e.g.:
19010 \end_layout
19011
19012 \begin_layout Verse
19013
19014 \family typewriter
19015 foo() { 
19016 \newline
19017 \InsetSpace ~
19018 \InsetSpace ~
19019 \InsetSpace ~
19020 \InsetSpace ~
19021 /* some c code */ 
19022 \newline
19023 \InsetSpace ~
19024 \InsetSpace ~
19025 \InsetSpace ~
19026 \InsetSpace ~
19027 _asm 
19028 \newline
19029 \InsetSpace ~
19030 \InsetSpace ~
19031 \InsetSpace ~
19032 \InsetSpace ~
19033 \InsetSpace ~
19034 \InsetSpace ~
19035 ; some assembler code 
19036 \newline
19037 \InsetSpace ~
19038 \InsetSpace ~
19039 \InsetSpace ~
19040 \InsetSpace ~
19041 \InsetSpace ~
19042 \InsetSpace ~
19043 ljmp 0003$ 
19044 \newline
19045 \InsetSpace ~
19046 \InsetSpace ~
19047 \InsetSpace ~
19048 \InsetSpace ~
19049 _endasm;
19050  
19051 \newline
19052 \InsetSpace ~
19053 \InsetSpace ~
19054 \InsetSpace ~
19055 \InsetSpace ~
19056 /* some more c code */ 
19057 \newline
19058 clabel:\InsetSpace ~
19059 \InsetSpace ~
19060 /* inline assembler cannot reference this
19061  label */ 
19062 \begin_inset Foot
19063 status open
19064
19065 \begin_layout Standard
19066 Here, the C-label 
19067 \family typewriter
19068 clabel
19069 \family default
19070  is translated by the compiler into a local label, so the locality of labels
19071  within the function is not broken.
19072 \end_layout
19073
19074 \end_inset
19075
19076
19077 \newline
19078 \InsetSpace ~
19079 \InsetSpace ~
19080 \InsetSpace ~
19081 \InsetSpace ~
19082 _asm
19083 \newline
19084 \InsetSpace ~
19085 \InsetSpace ~
19086 \InsetSpace ~
19087 \InsetSpace ~
19088 0003$: ;label (can be referenced by inline assembler only) 
19089 \newline
19090 \InsetSpace ~
19091 \InsetSpace ~
19092 \InsetSpace ~
19093 \InsetSpace ~
19094 _endasm
19095 \begin_inset LatexCommand index
19096 name "\\_endasm"
19097
19098 \end_inset
19099
19100
19101 \begin_inset LatexCommand index
19102 name "\\_\\_endasm"
19103
19104 \end_inset
19105
19106  ; 
19107 \newline
19108 \InsetSpace ~
19109 \InsetSpace ~
19110 \InsetSpace ~
19111 \InsetSpace ~
19112 /* some more c code */
19113 \newline
19114 }
19115 \end_layout
19116
19117 \begin_layout Standard
19118 In other words inline assembly code can access labels defined in inline
19119  assembly within the scope of the function.
19120  The same goes the other way, i.e.
19121  labels defines in inline assembly can not be accessed by C statements.
19122 \end_layout
19123
19124 \begin_layout Section
19125 Interfacing with Assembler Code
19126 \begin_inset LatexCommand index
19127 name "Assembler routines"
19128
19129 \end_inset
19130
19131
19132 \end_layout
19133
19134 \begin_layout Subsection
19135 Global Registers used for Parameter Passing
19136 \begin_inset LatexCommand index
19137 name "Parameter passing"
19138
19139 \end_inset
19140
19141
19142 \end_layout
19143
19144 \begin_layout Standard
19145 The compiler always uses the global registers 
19146 \emph on
19147 DPL, DPH
19148 \begin_inset LatexCommand index
19149 name "DPTR, DPH, DPL"
19150
19151 \end_inset
19152
19153
19154 \begin_inset LatexCommand index
19155 name "DPTR"
19156
19157 \end_inset
19158
19159 , B
19160 \begin_inset LatexCommand index
19161 name "B (mcs51, ds390 register)"
19162
19163 \end_inset
19164
19165
19166 \emph default
19167  and 
19168 \emph on
19169 ACC
19170 \begin_inset LatexCommand index
19171 name "ACC (mcs51, ds390 register)"
19172
19173 \end_inset
19174
19175
19176 \emph default
19177  to pass the first (non-bit) parameter to a function, and also to pass the
19178  return value 
19179 \begin_inset LatexCommand index
19180 name "return value"
19181
19182 \end_inset
19183
19184 of function; according to the following scheme: one byte return value in
19185  
19186 \emph on
19187 DPL
19188 \emph default
19189 , two byte value in 
19190 \emph on
19191 DPL
19192 \emph default
19193  (LSB) and 
19194 \emph on
19195 DPH
19196 \emph default
19197  (MSB).
19198  three byte values (generic pointers) in 
19199 \emph on
19200 DPH
19201 \emph default
19202
19203 \emph on
19204 DPL
19205 \emph default
19206  and 
19207 \emph on
19208 B
19209 \emph default
19210 , and four byte values in 
19211 \emph on
19212 DPH
19213 \emph default
19214
19215 \emph on
19216 DPL
19217 \emph default
19218
19219 \emph on
19220 B
19221 \emph default
19222  and 
19223 \emph on
19224 ACC
19225 \emph default
19226 .
19227  Generic pointers
19228 \begin_inset LatexCommand index
19229 name "generic pointer"
19230
19231 \end_inset
19232
19233  contain type of accessed memory in 
19234 \emph on
19235 B
19236 \emph default
19237
19238 \series bold
19239 0x00
19240 \series default
19241  -- xdata/far, 
19242 \series bold
19243 0x40
19244 \series default
19245  -- idata/near -- , 
19246 \series bold
19247 0x60
19248 \series default
19249  -- pdata, 
19250 \series bold
19251 0x80
19252 \series default
19253  -- code
19254 \begin_inset Note Note
19255 status collapsed
19256
19257 \begin_layout Standard
19258 This might not be the case of certain memory models (medium???)
19259 \end_layout
19260
19261 \end_inset
19262
19263 .
19264 \end_layout
19265
19266 \begin_layout Standard
19267 The second parameter onwards is either allocated on the stack (for reentrant
19268  routines or if -
19269 \begin_inset ERT
19270 status collapsed
19271
19272 \begin_layout Standard
19273
19274
19275 \backslash
19276 /
19277 \end_layout
19278
19279 \end_inset
19280
19281 -stack-auto is used) or in data/xdata memory (depending on the memory model).
19282 \end_layout
19283
19284 \begin_layout Standard
19285 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
19286  space for reentrant functions or allocated directly in bit memory otherwise.
19287 \end_layout
19288
19289 \begin_layout Standard
19290 Functions (with two or more parameters or bit parameters) that are called
19291  through function pointers
19292 \begin_inset LatexCommand index
19293 name "function pointers"
19294
19295 \end_inset
19296
19297  must therefor be reentrant so the compiler knows how to pass the parameters.
19298 \end_layout
19299
19300 \begin_layout Subsection
19301 Registers usage
19302 \end_layout
19303
19304 \begin_layout Standard
19305 Unless the called function is declared as 
19306 \family typewriter
19307 _naked
19308 \family default
19309
19310 \begin_inset LatexCommand index
19311 name "naked"
19312
19313 \end_inset
19314
19315 , or the -
19316 \begin_inset ERT
19317 status collapsed
19318
19319 \begin_layout Standard
19320
19321
19322 \backslash
19323 /
19324 \end_layout
19325
19326 \end_inset
19327
19328 -callee-saves
19329 \begin_inset LatexCommand index
19330 name "-\\/-callee-saves"
19331
19332 \end_inset
19333
19334 /-
19335 \begin_inset ERT
19336 status collapsed
19337
19338 \begin_layout Standard
19339
19340
19341 \backslash
19342 /
19343 \end_layout
19344
19345 \end_inset
19346
19347 -all-callee-saves command line option or the corresponding callee_saves
19348  pragma are used, the caller will save the registers (
19349 \emph on
19350 R0-R7
19351 \emph default
19352 ) around the call, so the called function can destroy they content freely.
19353 \end_layout
19354
19355 \begin_layout Standard
19356 If the called function is not declared as 
19357 \family typewriter
19358 _naked
19359 \family default
19360 , the caller will swap register banks around the call, if caller and callee
19361  use different register banks (having them defined by the 
19362 \family typewriter
19363 _using
19364 \family default
19365  modifier).
19366  
19367 \end_layout
19368
19369 \begin_layout Standard
19370 The called function can also use 
19371 \emph on
19372 DPL
19373 \emph default
19374
19375 \emph on
19376 DPH
19377 \emph default
19378
19379 \emph on
19380 B
19381 \emph default
19382  and 
19383 \emph on
19384 ACC
19385 \emph default
19386  observing that they are used for parameter/return value passing.
19387 \end_layout
19388
19389 \begin_layout Subsection
19390 Assembler Routine (non-reentrant)
19391 \end_layout
19392
19393 \begin_layout Standard
19394 In the following example
19395 \begin_inset LatexCommand index
19396 name "reentrant"
19397
19398 \end_inset
19399
19400
19401 \begin_inset LatexCommand index
19402 name "Assembler routines (non-reentrant)"
19403
19404 \end_inset
19405
19406  the function c_func calls an assembler routine asm_func, which takes two
19407  parameters
19408 \begin_inset LatexCommand index
19409 name "function parameter"
19410
19411 \end_inset
19412
19413 .
19414 \end_layout
19415
19416 \begin_layout Verse
19417
19418 \family typewriter
19419 extern int asm_func(unsigned char, unsigned char);
19420 \newline
19421
19422 \newline
19423 int c_func (unsigned char
19424  i, unsigned char j)
19425 \newline
19426 {
19427 \newline
19428 \InsetSpace ~
19429 \InsetSpace ~
19430 \InsetSpace ~
19431 \InsetSpace ~
19432 return asm_func(i,j);
19433 \newline
19434 }
19435 \newline
19436
19437 \newline
19438 int main()
19439 \newline
19440 {
19441 \newline
19442 \InsetSpace ~
19443 \InsetSpace ~
19444 \InsetSpace ~
19445 \InsetSpace ~
19446 return c_func(10,9);
19447 \newline
19448 }
19449 \end_layout
19450
19451 \begin_layout Standard
19452 The corresponding assembler function is:
19453 \end_layout
19454
19455 \begin_layout Verse
19456
19457 \family typewriter
19458 .globl _asm_func_PARM_2 
19459 \newline
19460 \InsetSpace ~
19461 \InsetSpace ~
19462 \InsetSpace ~
19463 \InsetSpace ~
19464 \InsetSpace ~
19465 \InsetSpace ~
19466 \InsetSpace ~
19467 \InsetSpace ~
19468 .globl _asm_func 
19469 \newline
19470 \InsetSpace ~
19471 \InsetSpace ~
19472 \InsetSpace ~
19473 \InsetSpace ~
19474 \InsetSpace ~
19475 \InsetSpace ~
19476 \InsetSpace ~
19477 \InsetSpace ~
19478 .area OSEG 
19479 \newline
19480 _asm_func_PARM_2:
19481 \newline
19482 \InsetSpace ~
19483 \InsetSpace ~
19484 \InsetSpace ~
19485 \InsetSpace ~
19486 \InsetSpace ~
19487 \InsetSpace ~
19488 \InsetSpace ~
19489 \InsetSpace ~
19490 .ds   
19491  1 
19492 \newline
19493 \InsetSpace ~
19494 \InsetSpace ~
19495 \InsetSpace ~
19496 \InsetSpace ~
19497 \InsetSpace ~
19498 \InsetSpace ~
19499 \InsetSpace ~
19500 \InsetSpace ~
19501 .area CSEG 
19502 \newline
19503 _asm_func: 
19504 \newline
19505 \InsetSpace ~
19506 \InsetSpace ~
19507 \InsetSpace ~
19508 \InsetSpace ~
19509 \InsetSpace ~
19510 \InsetSpace ~
19511 \InsetSpace ~
19512 \InsetSpace ~
19513 mov\InsetSpace ~
19514 \InsetSpace ~
19515 \InsetSpace ~
19516 \InsetSpace ~
19517 a,dpl 
19518 \newline
19519 \InsetSpace ~
19520 \InsetSpace ~
19521 \InsetSpace ~
19522 \InsetSpace ~
19523 \InsetSpace ~
19524 \InsetSpace ~
19525 \InsetSpace ~
19526 \InsetSpace ~
19527 add\InsetSpace ~
19528 \InsetSpace ~
19529 \InsetSpace ~
19530 \InsetSpace ~
19531 a,_asm_func_PARM_2 
19532 \newline
19533 \InsetSpace ~
19534 \InsetSpace ~
19535 \InsetSpace ~
19536 \InsetSpace ~
19537 \InsetSpace ~
19538 \InsetSpace ~
19539 \InsetSpace ~
19540 \InsetSpace ~
19541 mov\InsetSpace ~
19542 \InsetSpace ~
19543 \InsetSpace ~
19544 \InsetSpace ~
19545 dpl,a 
19546 \newline
19547 \InsetSpace ~
19548 \InsetSpace ~
19549 \InsetSpace ~
19550 \InsetSpace ~
19551 \InsetSpace ~
19552 \InsetSpace ~
19553 \InsetSpace ~
19554 \InsetSpace ~
19555 mov\InsetSpace ~
19556 \InsetSpace ~
19557 \InsetSpace ~
19558 \InsetSpace ~
19559 dph
19560 \begin_inset LatexCommand index
19561 name "DPTR, DPH, DPL"
19562
19563 \end_inset
19564
19565 ,#0x00 
19566 \newline
19567 \InsetSpace ~
19568 \InsetSpace ~
19569 \InsetSpace ~
19570 \InsetSpace ~
19571 \InsetSpace ~
19572 \InsetSpace ~
19573 \InsetSpace ~
19574 \InsetSpace ~
19575 ret
19576 \end_layout
19577
19578 \begin_layout Standard
19579 The parameter naming convention is _<function_name>_PARM_<n>, where n is
19580  the parameter number starting from 1, and counting from the left.
19581  The first parameter is passed in 
19582 \emph on
19583 DPH
19584 \emph default
19585
19586 \emph on
19587 DPL
19588 \emph default
19589
19590 \emph on
19591 B
19592 \emph default
19593  and 
19594 \emph on
19595 ACC
19596 \emph default
19597  according to the description above.
19598  The variable name for the second parameter will be _<function_name>_PARM_2.
19599 \newline
19600
19601 \newline
19602 Assem
19603 ble the assembler routine with the following command:
19604 \newline
19605
19606 \newline
19607
19608 \family sans
19609 \series bold
19610 asx8051 -losg asmfunc.asm
19611 \newline
19612
19613 \newline
19614
19615 \family default
19616 \series default
19617 Then compile and link the assembler routine to the C source file with the
19618  following command:
19619 \newline
19620
19621 \newline
19622
19623 \family sans
19624 \series bold
19625 sdcc cfunc.c asmfunc.rel
19626 \end_layout
19627
19628 \begin_layout Subsection
19629 Assembler Routine (reentrant)
19630 \end_layout
19631
19632 \begin_layout Standard
19633 In this case
19634 \begin_inset LatexCommand index
19635 name "reentrant"
19636
19637 \end_inset
19638
19639
19640 \begin_inset LatexCommand index
19641 name "Assembler routines (reentrant)"
19642
19643 \end_inset
19644
19645  the second parameter
19646 \begin_inset LatexCommand index
19647 name "function parameter"
19648
19649 \end_inset
19650
19651  onwards will be passed on the stack, the parameters are pushed from right
19652  to left i.e.
19653  before the call the second leftmost parameter will be on the top of the
19654  stack (the leftmost parameter is passed in registers).
19655  Here is an example:
19656 \end_layout
19657
19658 \begin_layout Verse
19659
19660 \family typewriter
19661 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
19662 \newline
19663
19664 \newline
19665 int
19666  c_func (unsigned char i, unsigned char j, unsigned char k) reentrant 
19667 \newline
19668 {
19669  
19670 \newline
19671 \InsetSpace ~
19672 \InsetSpace ~
19673 \InsetSpace ~
19674 \InsetSpace ~
19675 return asm_func(i,j,k); 
19676 \newline
19677
19678 \newline
19679
19680 \newline
19681 int main() 
19682 \newline
19683
19684 \newline
19685 \InsetSpace ~
19686 \InsetSpace ~
19687 \InsetSpace ~
19688 \InsetSpace ~
19689 return c_func(10,9,8); 
19690 \newline
19691 }
19692 \end_layout
19693
19694 \begin_layout Standard
19695 The corresponding (unoptimized) assembler routine is:
19696 \end_layout
19697
19698 \begin_layout Verse
19699
19700 \family typewriter
19701 .globl _asm_func 
19702 \newline
19703 _asm_func: 
19704 \newline
19705 \InsetSpace ~
19706 \InsetSpace ~
19707 \InsetSpace ~
19708 \InsetSpace ~
19709 push\InsetSpace ~
19710 _bp 
19711 \newline
19712 \InsetSpace ~
19713 \InsetSpace ~
19714 \InsetSpace ~
19715 \InsetSpace ~
19716 mov\InsetSpace ~
19717 \InsetSpace ~
19718 _bp,sp\InsetSpace ~
19719 \InsetSpace ~
19720 \InsetSpace ~
19721 \InsetSpace ~
19722 \InsetSpace ~
19723 \InsetSpace ~
19724 ;stack contains: _bp, return
19725  address, second parameter, third parameter
19726 \newline
19727 \InsetSpace ~
19728 \InsetSpace ~
19729 \InsetSpace ~
19730 \InsetSpace ~
19731 mov\InsetSpace ~
19732 \InsetSpace ~
19733 r2,dpl
19734 \newline
19735 \InsetSpace ~
19736 \InsetSpace ~
19737 \InsetSpace ~
19738 \InsetSpace ~
19739 mov\InsetSpace ~
19740 \InsetSpace ~
19741 a,_bp
19742 \newline
19743 \InsetSpace ~
19744 \InsetSpace ~
19745 \InsetSpace ~
19746 \InsetSpace ~
19747 add\InsetSpace ~
19748 \InsetSpace ~
19749 a,#0xfd\InsetSpace ~
19750 \InsetSpace ~
19751 \InsetSpace ~
19752 \InsetSpace ~
19753 \InsetSpace ~
19754 ;calculate
19755  pointer to the second parameter
19756 \newline
19757 \InsetSpace ~
19758 \InsetSpace ~
19759 \InsetSpace ~
19760 \InsetSpace ~
19761 mov\InsetSpace ~
19762 \InsetSpace ~
19763 r0,a 
19764 \newline
19765 \InsetSpace ~
19766 \InsetSpace ~
19767 \InsetSpace ~
19768 \InsetSpace ~
19769 mov\InsetSpace ~
19770 \InsetSpace ~
19771 a,_bp 
19772 \newline
19773 \InsetSpace ~
19774 \InsetSpace ~
19775 \InsetSpace ~
19776 \InsetSpace ~
19777 add\InsetSpace ~
19778 \InsetSpace ~
19779 a,#0xfc\InsetSpace ~
19780 \InsetSpace ~
19781 \InsetSpace ~
19782 \InsetSpace ~
19783 \InsetSpace ~
19784 ;calculate pointer
19785  to the rightmost parameter
19786 \newline
19787 \InsetSpace ~
19788 \InsetSpace ~
19789 \InsetSpace ~
19790 \InsetSpace ~
19791 mov\InsetSpace ~
19792 \InsetSpace ~
19793 r1,a 
19794 \newline
19795 \InsetSpace ~
19796 \InsetSpace ~
19797 \InsetSpace ~
19798 \InsetSpace ~
19799 mov\InsetSpace ~
19800 \InsetSpace ~
19801 a,@r0
19802 \newline
19803 \InsetSpace ~
19804 \InsetSpace ~
19805 \InsetSpace ~
19806 \InsetSpace ~
19807 add\InsetSpace ~
19808 \InsetSpace ~
19809 a,@r1
19810 \newline
19811 \InsetSpace ~
19812 \InsetSpace ~
19813 \InsetSpace ~
19814 \InsetSpace ~
19815 add\InsetSpace ~
19816 \InsetSpace ~
19817 a,r2\InsetSpace ~
19818 \InsetSpace ~
19819 \InsetSpace ~
19820 \InsetSpace ~
19821 \InsetSpace ~
19822 \InsetSpace ~
19823 \InsetSpace ~
19824 \InsetSpace ~
19825 ;calculate the
19826  result (= sum of all three parameters)
19827 \newline
19828 \InsetSpace ~
19829 \InsetSpace ~
19830 \InsetSpace ~
19831 \InsetSpace ~
19832 mov\InsetSpace ~
19833 \InsetSpace ~
19834 dpl,a\InsetSpace ~
19835 \InsetSpace ~
19836 \InsetSpace ~
19837 \InsetSpace ~
19838 \InsetSpace ~
19839 \InsetSpace ~
19840 \InsetSpace ~
19841 ;return value goes into dptr
19842  (cast into int)
19843 \newline
19844 \InsetSpace ~
19845 \InsetSpace ~
19846 \InsetSpace ~
19847 \InsetSpace ~
19848 mov\InsetSpace ~
19849 \InsetSpace ~
19850 dph,#0x00 
19851 \newline
19852 \InsetSpace ~
19853 \InsetSpace ~
19854 \InsetSpace ~
19855 \InsetSpace ~
19856 mov\InsetSpace ~
19857 \InsetSpace ~
19858 sp,_bp 
19859 \newline
19860 \InsetSpace ~
19861 \InsetSpace ~
19862 \InsetSpace ~
19863 \InsetSpace ~
19864 pop\InsetSpace ~
19865 \InsetSpace ~
19866 _bp 
19867 \newline
19868 \InsetSpace ~
19869 \InsetSpace ~
19870 \InsetSpace ~
19871 \InsetSpace ~
19872 ret
19873 \end_layout
19874
19875 \begin_layout Standard
19876 The compiling and linking procedure remains the same, however note the extra
19877  entry & exit linkage required for the assembler code, _bp is the stack
19878  frame pointer and is used to compute the offset into the stack for parameters
19879  and local variables.
19880 \begin_inset VSpace bigskip
19881 \end_inset
19882
19883
19884 \end_layout
19885
19886 \begin_layout Section
19887 int (16 bit)
19888 \begin_inset LatexCommand index
19889 name "int (16 bit)"
19890
19891 \end_inset
19892
19893  and long (32 bit)
19894 \begin_inset LatexCommand index
19895 name "long (32 bit)"
19896
19897 \end_inset
19898
19899  Support
19900 \end_layout
19901
19902 \begin_layout Standard
19903 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
19904  multiplication and modulus operations are implemented by support routines.
19905  These support routines are all developed in ANSI-C to facilitate porting
19906  to other MCUs, although some model specific assembler optimizations are
19907  used.
19908  The following files contain the described routines, all of them can be
19909  found in <installdir>/share/sdcc/lib.
19910 \newline
19911
19912 \end_layout
19913
19914 \begin_layout Standard
19915 \align center
19916 \begin_inset Tabular
19917 <lyxtabular version="3" rows="11" columns="2">
19918 <features>
19919 <column alignment="left" valignment="top" leftline="true" width="0">
19920 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19921 <row topline="true" bottomline="true">
19922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19923 \begin_inset Text
19924
19925 \begin_layout Standard
19926
19927 \series bold
19928 Function
19929 \end_layout
19930
19931 \end_inset
19932 </cell>
19933 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19934 \begin_inset Text
19935
19936 \begin_layout Standard
19937
19938 \series bold
19939 Description
19940 \end_layout
19941
19942 \end_inset
19943 </cell>
19944 </row>
19945 <row topline="true">
19946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19947 \begin_inset Text
19948
19949 \begin_layout Standard
19950 _mulint.c 
19951 \end_layout
19952
19953 \end_inset
19954 </cell>
19955 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19956 \begin_inset Text
19957
19958 \begin_layout Standard
19959 16 bit multiplication
19960 \end_layout
19961
19962 \end_inset
19963 </cell>
19964 </row>
19965 <row topline="true">
19966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19967 \begin_inset Text
19968
19969 \begin_layout Standard
19970 _divsint.c 
19971 \end_layout
19972
19973 \end_inset
19974 </cell>
19975 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19976 \begin_inset Text
19977
19978 \begin_layout Standard
19979  signed 16 bit division (calls _divuint)
19980 \end_layout
19981
19982 \end_inset
19983 </cell>
19984 </row>
19985 <row topline="true">
19986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19987 \begin_inset Text
19988
19989 \begin_layout Standard
19990 _divuint.c 
19991 \end_layout
19992
19993 \end_inset
19994 </cell>
19995 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19996 \begin_inset Text
19997
19998 \begin_layout Standard
19999  unsigned 16 bit division
20000 \end_layout
20001
20002 \end_inset
20003 </cell>
20004 </row>
20005 <row topline="true">
20006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20007 \begin_inset Text
20008
20009 \begin_layout Standard
20010 _modsint.c
20011 \end_layout
20012
20013 \end_inset
20014 </cell>
20015 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20016 \begin_inset Text
20017
20018 \begin_layout Standard
20019 signed 16 bit modulus (calls _moduint)
20020 \end_layout
20021
20022 \end_inset
20023 </cell>
20024 </row>
20025 <row topline="true">
20026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20027 \begin_inset Text
20028
20029 \begin_layout Standard
20030 _moduint.c
20031 \end_layout
20032
20033 \end_inset
20034 </cell>
20035 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20036 \begin_inset Text
20037
20038 \begin_layout Standard
20039 unsigned 16 bit modulus
20040 \end_layout
20041
20042 \end_inset
20043 </cell>
20044 </row>
20045 <row topline="true">
20046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20047 \begin_inset Text
20048
20049 \begin_layout Standard
20050 _mullong.c
20051 \end_layout
20052
20053 \end_inset
20054 </cell>
20055 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20056 \begin_inset Text
20057
20058 \begin_layout Standard
20059 32 bit multiplication
20060 \end_layout
20061
20062 \end_inset
20063 </cell>
20064 </row>
20065 <row topline="true">
20066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20067 \begin_inset Text
20068
20069 \begin_layout Standard
20070 _divslong.c 
20071 \end_layout
20072
20073 \end_inset
20074 </cell>
20075 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20076 \begin_inset Text
20077
20078 \begin_layout Standard
20079  signed 32 division (calls _divulong)
20080 \end_layout
20081
20082 \end_inset
20083 </cell>
20084 </row>
20085 <row topline="true">
20086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20087 \begin_inset Text
20088
20089 \begin_layout Standard
20090 _divulong.c 
20091 \end_layout
20092
20093 \end_inset
20094 </cell>
20095 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20096 \begin_inset Text
20097
20098 \begin_layout Standard
20099 unsigned 32 division
20100 \end_layout
20101
20102 \end_inset
20103 </cell>
20104 </row>
20105 <row topline="true">
20106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20107 \begin_inset Text
20108
20109 \begin_layout Standard
20110 _modslong.c
20111 \end_layout
20112
20113 \end_inset
20114 </cell>
20115 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20116 \begin_inset Text
20117
20118 \begin_layout Standard
20119  signed 32 bit modulus (calls _modulong)
20120 \end_layout
20121
20122 \end_inset
20123 </cell>
20124 </row>
20125 <row topline="true" bottomline="true">
20126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20127 \begin_inset Text
20128
20129 \begin_layout Standard
20130 _modulong.c
20131 \end_layout
20132
20133 \end_inset
20134 </cell>
20135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20136 \begin_inset Text
20137
20138 \begin_layout Standard
20139 unsigned 32 bit modulus
20140 \end_layout
20141
20142 \end_inset
20143 </cell>
20144 </row>
20145 </lyxtabular>
20146
20147 \end_inset
20148
20149
20150 \newline
20151
20152 \end_layout
20153
20154 \begin_layout Standard
20155 Since they are compiled as 
20156 \emph on
20157 non-reentrant
20158 \emph default
20159
20160 \begin_inset LatexCommand index
20161 name "reentrant"
20162
20163 \end_inset
20164
20165 , interrupt
20166 \begin_inset LatexCommand index
20167 name "interrupt"
20168
20169 \end_inset
20170
20171  service routines should not do any of the above operations.
20172  If this is unavoidable then the above routines will need to be compiled
20173  with the 
20174 \emph on
20175 -
20176 \begin_inset ERT
20177 status collapsed
20178
20179 \begin_layout Standard
20180
20181
20182 \backslash
20183 /
20184 \end_layout
20185
20186 \end_inset
20187
20188 -stack-auto
20189 \begin_inset LatexCommand index
20190 name "-\\/-stack-auto"
20191
20192 \end_inset
20193
20194
20195 \emph default
20196  option, after which the source program will have to be compiled with 
20197 \emph on
20198 -
20199 \begin_inset ERT
20200 status collapsed
20201
20202 \begin_layout Standard
20203
20204
20205 \backslash
20206 /
20207 \end_layout
20208
20209 \end_inset
20210
20211 -int-long-reent
20212 \begin_inset LatexCommand index
20213 name "-\\/-int-long-reent"
20214
20215 \end_inset
20216
20217
20218 \emph default
20219  option.
20220  Notice that you don't have to call these routines directly.
20221  The compiler will use them automatically every time an integer operation
20222  is required.
20223 \end_layout
20224
20225 \begin_layout Section
20226 Floating Point Support
20227 \begin_inset LatexCommand index
20228 name "Floating point support"
20229
20230 \end_inset
20231
20232
20233 \end_layout
20234
20235 \begin_layout Standard
20236 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
20237  The floating point support routines are derived from gcc's floatlib.c and
20238  consist of the following routines:
20239 \newline
20240
20241 \end_layout
20242
20243 \begin_layout Standard
20244 \align center
20245
20246 \size footnotesize
20247 \begin_inset Tabular
20248 <lyxtabular version="3" rows="17" columns="2">
20249 <features>
20250 <column alignment="left" valignment="top" leftline="true" width="0">
20251 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
20252 <row topline="true" bottomline="true">
20253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20254 \begin_inset Text
20255
20256 \begin_layout Standard
20257
20258 \family roman
20259 \series medium
20260 \shape up
20261 \size normal
20262 \emph off
20263 \bar no
20264 \noun off
20265 \color none
20266 Function 
20267 \end_layout
20268
20269 \end_inset
20270 </cell>
20271 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20272 \begin_inset Text
20273
20274 \begin_layout Standard
20275 Description
20276 \end_layout
20277
20278 \end_inset
20279 </cell>
20280 </row>
20281 <row topline="true">
20282 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20283 \begin_inset Text
20284
20285 \begin_layout Standard
20286
20287 \family roman
20288 \series medium
20289 \shape up
20290 \size normal
20291 \emph off
20292 \bar no
20293 \noun off
20294 \color none
20295 _fsadd.c
20296 \end_layout
20297
20298 \end_inset
20299 </cell>
20300 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20301 \begin_inset Text
20302
20303 \begin_layout Standard
20304
20305 \family roman
20306 \series medium
20307 \shape up
20308 \size normal
20309 \emph off
20310 \bar no
20311 \noun off
20312 \color none
20313 add floating point numbers
20314 \end_layout
20315
20316 \end_inset
20317 </cell>
20318 </row>
20319 <row topline="true">
20320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20321 \begin_inset Text
20322
20323 \begin_layout Standard
20324
20325 \family roman
20326 \series medium
20327 \shape up
20328 \size normal
20329 \emph off
20330 \bar no
20331 \noun off
20332 \color none
20333 _fssub.c 
20334 \end_layout
20335
20336 \end_inset
20337 </cell>
20338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20339 \begin_inset Text
20340
20341 \begin_layout Standard
20342
20343 \family roman
20344 \series medium
20345 \shape up
20346 \size normal
20347 \emph off
20348 \bar no
20349 \noun off
20350 \color none
20351 subtract floating point numbers 
20352 \end_layout
20353
20354 \end_inset
20355 </cell>
20356 </row>
20357 <row topline="true">
20358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20359 \begin_inset Text
20360
20361 \begin_layout Standard
20362
20363 \family roman
20364 \series medium
20365 \shape up
20366 \size normal
20367 \emph off
20368 \bar no
20369 \noun off
20370 \color none
20371 _fsdiv.c 
20372 \end_layout
20373
20374 \end_inset
20375 </cell>
20376 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20377 \begin_inset Text
20378
20379 \begin_layout Standard
20380
20381 \family roman
20382 \series medium
20383 \shape up
20384 \size normal
20385 \emph off
20386 \bar no
20387 \noun off
20388 \color none
20389 divide floating point numbers 
20390 \end_layout
20391
20392 \end_inset
20393 </cell>
20394 </row>
20395 <row topline="true">
20396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20397 \begin_inset Text
20398
20399 \begin_layout Standard
20400
20401 \family roman
20402 \series medium
20403 \shape up
20404 \size normal
20405 \emph off
20406 \bar no
20407 \noun off
20408 \color none
20409 _fsmul.c 
20410 \end_layout
20411
20412 \end_inset
20413 </cell>
20414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20415 \begin_inset Text
20416
20417 \begin_layout Standard
20418
20419 \family roman
20420 \series medium
20421 \shape up
20422 \size normal
20423 \emph off
20424 \bar no
20425 \noun off
20426 \color none
20427 multiply floating point numbers 
20428 \end_layout
20429
20430 \end_inset
20431 </cell>
20432 </row>
20433 <row topline="true">
20434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20435 \begin_inset Text
20436
20437 \begin_layout Standard
20438
20439 \family roman
20440 \series medium
20441 \shape up
20442 \size normal
20443 \emph off
20444 \bar no
20445 \noun off
20446 \color none
20447 _fs2uchar.c
20448 \end_layout
20449
20450 \end_inset
20451 </cell>
20452 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20453 \begin_inset Text
20454
20455 \begin_layout Standard
20456
20457 \family roman
20458 \series medium
20459 \shape up
20460 \size normal
20461 \emph off
20462 \bar no
20463 \noun off
20464 \color none
20465 convert floating point to unsigned char
20466 \end_layout
20467
20468 \end_inset
20469 </cell>
20470 </row>
20471 <row topline="true">
20472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20473 \begin_inset Text
20474
20475 \begin_layout Standard
20476
20477 \family roman
20478 \series medium
20479 \shape up
20480 \size normal
20481 \emph off
20482 \bar no
20483 \noun off
20484 \color none
20485 _fs2char.c
20486 \end_layout
20487
20488 \end_inset
20489 </cell>
20490 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20491 \begin_inset Text
20492
20493 \begin_layout Standard
20494
20495 \family roman
20496 \series medium
20497 \shape up
20498 \size normal
20499 \emph off
20500 \bar no
20501 \noun off
20502 \color none
20503 convert floating point to signed char
20504 \end_layout
20505
20506 \end_inset
20507 </cell>
20508 </row>
20509 <row topline="true">
20510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20511 \begin_inset Text
20512
20513 \begin_layout Standard
20514
20515 \family roman
20516 \series medium
20517 \shape up
20518 \size normal
20519 \emph off
20520 \bar no
20521 \noun off
20522 \color none
20523 _fs2uint.c
20524 \end_layout
20525
20526 \end_inset
20527 </cell>
20528 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20529 \begin_inset Text
20530
20531 \begin_layout Standard
20532
20533 \family roman
20534 \series medium
20535 \shape up
20536 \size normal
20537 \emph off
20538 \bar no
20539 \noun off
20540 \color none
20541 convert floating point to unsigned int
20542 \end_layout
20543
20544 \end_inset
20545 </cell>
20546 </row>
20547 <row topline="true">
20548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20549 \begin_inset Text
20550
20551 \begin_layout Standard
20552
20553 \family roman
20554 \series medium
20555 \shape up
20556 \size normal
20557 \emph off
20558 \bar no
20559 \noun off
20560 \color none
20561 _fs2int.c
20562 \end_layout
20563
20564 \end_inset
20565 </cell>
20566 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20567 \begin_inset Text
20568
20569 \begin_layout Standard
20570
20571 \family roman
20572 \series medium
20573 \shape up
20574 \size normal
20575 \emph off
20576 \bar no
20577 \noun off
20578 \color none
20579 convert floating point to signed int
20580 \end_layout
20581
20582 \end_inset
20583 </cell>
20584 </row>
20585 <row topline="true">
20586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20587 \begin_inset Text
20588
20589 \begin_layout Standard
20590
20591 \family roman
20592 \series medium
20593 \shape up
20594 \size normal
20595 \emph off
20596 \bar no
20597 \noun off
20598 \color none
20599 _fs2ulong.
20600 \family default
20601 \series default
20602 \shape default
20603 \size default
20604 \emph default
20605 \bar default
20606 \noun default
20607 c
20608 \end_layout
20609
20610 \end_inset
20611 </cell>
20612 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20613 \begin_inset Text
20614
20615 \begin_layout Standard
20616
20617 \family roman
20618 \series medium
20619 \shape up
20620 \size normal
20621 \emph off
20622 \bar no
20623 \noun off
20624 \color none
20625 convert floating point to unsigned long
20626 \end_layout
20627
20628 \end_inset
20629 </cell>
20630 </row>
20631 <row topline="true">
20632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20633 \begin_inset Text
20634
20635 \begin_layout Standard
20636
20637 \family roman
20638 \series medium
20639 \shape up
20640 \size normal
20641 \emph off
20642 \bar no
20643 \noun off
20644 \color none
20645 _fs2long.c
20646 \end_layout
20647
20648 \end_inset
20649 </cell>
20650 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20651 \begin_inset Text
20652
20653 \begin_layout Standard
20654
20655 \family roman
20656 \series medium
20657 \shape up
20658 \size normal
20659 \emph off
20660 \bar no
20661 \noun off
20662 \color none
20663 convert floating point to signed long
20664 \end_layout
20665
20666 \end_inset
20667 </cell>
20668 </row>
20669 <row topline="true">
20670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20671 \begin_inset Text
20672
20673 \begin_layout Standard
20674
20675 \family roman
20676 \series medium
20677 \shape up
20678 \size normal
20679 \emph off
20680 \bar no
20681 \noun off
20682 \color none
20683 _uchar2fs.c
20684 \end_layout
20685
20686 \end_inset
20687 </cell>
20688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20689 \begin_inset Text
20690
20691 \begin_layout Standard
20692
20693 \family roman
20694 \series medium
20695 \shape up
20696 \size normal
20697 \emph off
20698 \bar no
20699 \noun off
20700 \color none
20701 convert unsigned char to floating point
20702 \end_layout
20703
20704 \end_inset
20705 </cell>
20706 </row>
20707 <row topline="true">
20708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20709 \begin_inset Text
20710
20711 \begin_layout Standard
20712
20713 \family roman
20714 \series medium
20715 \shape up
20716 \size normal
20717 \emph off
20718 \bar no
20719 \noun off
20720 \color none
20721 _char2fs.c
20722 \end_layout
20723
20724 \end_inset
20725 </cell>
20726 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20727 \begin_inset Text
20728
20729 \begin_layout Standard
20730
20731 \family roman
20732 \series medium
20733 \shape up
20734 \size normal
20735 \emph off
20736 \bar no
20737 \noun off
20738 \color none
20739 convert char to floating point number
20740 \end_layout
20741
20742 \end_inset
20743 </cell>
20744 </row>
20745 <row topline="true">
20746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20747 \begin_inset Text
20748
20749 \begin_layout Standard
20750
20751 \family roman
20752 \series medium
20753 \shape up
20754 \size normal
20755 \emph off
20756 \bar no
20757 \noun off
20758 \color none
20759 _uint2fs.c
20760 \end_layout
20761
20762 \end_inset
20763 </cell>
20764 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20765 \begin_inset Text
20766
20767 \begin_layout Standard
20768
20769 \family roman
20770 \series medium
20771 \shape up
20772 \size normal
20773 \emph off
20774 \bar no
20775 \noun off
20776 \color none
20777 convert unsigned int to floating point
20778 \end_layout
20779
20780 \end_inset
20781 </cell>
20782 </row>
20783 <row topline="true">
20784 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20785 \begin_inset Text
20786
20787 \begin_layout Standard
20788
20789 \family roman
20790 \series medium
20791 \shape up
20792 \size normal
20793 \emph off
20794 \bar no
20795 \noun off
20796 \color none
20797 _int2fs.c
20798 \end_layout
20799
20800 \end_inset
20801 </cell>
20802 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20803 \begin_inset Text
20804
20805 \begin_layout Standard
20806
20807 \family roman
20808 \series medium
20809 \shape up
20810 \size normal
20811 \emph off
20812 \bar no
20813 \noun off
20814 \color none
20815 convert int to floating point numbers
20816 \end_layout
20817
20818 \end_inset
20819 </cell>
20820 </row>
20821 <row topline="true">
20822 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20823 \begin_inset Text
20824
20825 \begin_layout Standard
20826
20827 \family roman
20828 \series medium
20829 \shape up
20830 \size normal
20831 \emph off
20832 \bar no
20833 \noun off
20834 \color none
20835 _ulong2fs.c
20836 \end_layout
20837
20838 \end_inset
20839 </cell>
20840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20841 \begin_inset Text
20842
20843 \begin_layout Standard
20844
20845 \family roman
20846 \series medium
20847 \shape up
20848 \size normal
20849 \emph off
20850 \bar no
20851 \noun off
20852 \color none
20853 convert unsigned long to floating point number
20854 \end_layout
20855
20856 \end_inset
20857 </cell>
20858 </row>
20859 <row topline="true" bottomline="true">
20860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20861 \begin_inset Text
20862
20863 \begin_layout Standard
20864
20865 \family roman
20866 \series medium
20867 \shape up
20868 \size normal
20869 \emph off
20870 \bar no
20871 \noun off
20872 \color none
20873 _long2fs.c
20874 \end_layout
20875
20876 \end_inset
20877 </cell>
20878 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20879 \begin_inset Text
20880
20881 \begin_layout Standard
20882
20883 \family roman
20884 \series medium
20885 \shape up
20886 \size normal
20887 \emph off
20888 \bar no
20889 \noun off
20890 \color none
20891 convert long to floating point number
20892 \end_layout
20893
20894 \end_inset
20895 </cell>
20896 </row>
20897 </lyxtabular>
20898
20899 \end_inset
20900
20901
20902 \newline
20903
20904 \end_layout
20905
20906 \begin_layout Standard
20907 These support routines are developed in ANSI-C so there is room for space
20908  and speed improvement
20909 \begin_inset Foot
20910 status open
20911
20912 \begin_layout Standard
20913 These floating point routines (
20914 \emph on
20915 not
20916 \emph default
20917  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
20918  
20919 \end_layout
20920
20921 \end_inset
20922
20923 .
20924  Note if all these routines are used simultaneously the data space might
20925  overflow.
20926  For serious floating point usage the large model might be needed.
20927  Also notice that you don't have to call this routines directly.
20928  The compiler will use them automatically every time a floating point operation
20929  is required.
20930 \begin_inset VSpace bigskip
20931 \end_inset
20932
20933
20934 \end_layout
20935
20936 \begin_layout Section
20937 Library Routines
20938 \begin_inset LatexCommand index
20939 name "Libraries"
20940
20941 \end_inset
20942
20943
20944 \end_layout
20945
20946 \begin_layout Standard
20947
20948 \emph on
20949 <pending: this is messy and incomplete - a little more information is in
20950  sdcc/doc/libdoc.txt
20951 \emph default
20952  >
20953 \end_layout
20954
20955 \begin_layout Subsection
20956 Compiler support routines (_gptrget, _mulint etc.)
20957 \end_layout
20958
20959 \begin_layout Subsection
20960 Stdclib functions (puts, printf, strcat etc.)
20961 \end_layout
20962
20963 \begin_layout Subsubsection
20964 <stdio.h>
20965 \end_layout
20966
20967 \begin_layout Paragraph
20968 getchar(), putchar()
20969 \end_layout
20970
20971 \begin_layout Standard
20972 \begin_inset LatexCommand index
20973 name "<stdio.h>"
20974
20975 \end_inset
20976
20977 As usual on embedded systems you have to provide your own 
20978 \family typewriter
20979 getchar()
20980 \begin_inset LatexCommand index
20981 name "getchar()"
20982
20983 \end_inset
20984
20985
20986 \family default
20987  and 
20988 \family typewriter
20989 putchar()
20990 \begin_inset LatexCommand index
20991 name "putchar()"
20992
20993 \end_inset
20994
20995
20996 \family default
20997  routines.
20998  SDCC does not know whether the system connects to a serial line with or
20999  without handshake, LCD, keyboard or other device.
21000  And whether a 
21001 \family typewriter
21002 lf
21003 \family default
21004  to 
21005 \family typewriter
21006 crlf
21007 \family default
21008  conversion within 
21009 \family typewriter
21010 putchar()
21011 \family default
21012  is intended.
21013  You'll find examples for serial routines f.e.
21014  in sdcc/device/lib.
21015  For the mcs51 this minimalistic polling 
21016 \family typewriter
21017 putchar()
21018 \family default
21019  routine might be a start:
21020 \end_layout
21021
21022 \begin_layout Verse
21023
21024 \family typewriter
21025 void putchar (char c) { 
21026 \newline
21027 \InsetSpace ~
21028 \InsetSpace ~
21029 \InsetSpace ~
21030 \InsetSpace ~
21031 while (!TI)\InsetSpace ~
21032 \InsetSpace ~
21033 \InsetSpace ~
21034  /* assumes UART is initialized */
21035 \newline
21036 \InsetSpace ~
21037 \InsetSpace ~
21038 \InsetSpace ~
21039 \InsetSpace ~
21040 \InsetSpace ~
21041 \InsetSpace ~
21042 \InsetSpace ~
21043 \InsetSpace ~
21044 ;
21045 \newline
21046 \InsetSpace ~
21047 \InsetSpace ~
21048 \InsetSpace ~
21049 \InsetSpace ~
21050 TI
21051  = 0;
21052 \newline
21053 \InsetSpace ~
21054 \InsetSpace ~
21055 \InsetSpace ~
21056 \InsetSpace ~
21057 SBUF = c;
21058 \newline
21059 }
21060 \end_layout
21061
21062 \begin_layout Paragraph
21063 printf()
21064 \end_layout
21065
21066 \begin_layout Standard
21067 The default 
21068 \family typewriter
21069 printf()
21070 \begin_inset LatexCommand index
21071 name "printf()"
21072
21073 \end_inset
21074
21075
21076 \family default
21077  implementation in 
21078 \family typewriter
21079 printf_large.c
21080 \family default
21081  does not support float (except on ds390).
21082  To enable this, recompile it with the option 
21083 \emph on
21084 -
21085 \begin_inset ERT
21086 status collapsed
21087
21088 \begin_layout Standard
21089
21090
21091 \backslash
21092 /
21093 \end_layout
21094
21095 \end_inset
21096
21097 DUSE_FLOATS=1
21098 \begin_inset LatexCommand index
21099 name "USE\\_FLOATS"
21100
21101 \end_inset
21102
21103
21104 \emph default
21105  on the command line.
21106  Use 
21107 \emph on
21108 -
21109 \begin_inset ERT
21110 status collapsed
21111
21112 \begin_layout Standard
21113
21114
21115 \backslash
21116 /
21117 \end_layout
21118
21119 \end_inset
21120
21121 -model-large
21122 \begin_inset LatexCommand index
21123 name "-\\/-model-large"
21124
21125 \end_inset
21126
21127
21128 \emph default
21129  for the mcs51 port, since this uses a lot of memory.
21130  To enable float support for the pic16 targets, see 
21131 \begin_inset LatexCommand ref
21132 reference "sub:pic16Libraries"
21133
21134 \end_inset
21135
21136 .
21137 \end_layout
21138
21139 \begin_layout Standard
21140 If you're short on code memory you might want to use 
21141 \family typewriter
21142 printf_small()
21143 \begin_inset LatexCommand index
21144 name "printf\\_small()"
21145
21146 \end_inset
21147
21148
21149 \family default
21150  
21151 \emph on
21152 instead
21153 \emph default
21154  of 
21155 \family typewriter
21156 printf().
21157
21158 \family default
21159  For the mcs51 there additionally are assembly versions 
21160 \family typewriter
21161 printf_tiny()
21162 \begin_inset LatexCommand index
21163 name "printf\\_tiny() (mcs51)"
21164
21165 \end_inset
21166
21167
21168 \family default
21169  (subset of printf using less than 270 bytes) and 
21170 \family typewriter
21171 printf_fast()
21172 \begin_inset LatexCommand index
21173 name "printf\\_fast() (mcs51)"
21174
21175 \end_inset
21176
21177
21178 \family default
21179  and 
21180 \family typewriter
21181 printf_fast_f()
21182 \begin_inset LatexCommand index
21183 name "printf\\_fast\\_f() (mcs51)"
21184
21185 \end_inset
21186
21187
21188 \family default
21189  (floating-point aware version of printf_fast) which should fit the requirements
21190  of many embedded systems (printf_fast() can be customized by unsetting
21191  #defines to 
21192 \emph on
21193 not
21194 \emph default
21195  support long variables and field widths).
21196  Be sure to use only one of these printf options within a project.
21197 \newline
21198
21199 \end_layout
21200
21201 \begin_layout Standard
21202 Feature matrix of different 
21203 \emph on
21204 printf
21205 \emph default
21206  options on mcs51.
21207 \end_layout
21208
21209 \begin_layout Standard
21210 \begin_inset Tabular
21211 <lyxtabular version="3" rows="14" columns="7">
21212 <features islongtable="true">
21213 <column alignment="left" valignment="middle" leftline="true" width="14col%">
21214 <column alignment="center" valignment="top" leftline="true" width="0">
21215 <column alignment="center" valignment="top" leftline="true" width="12col%">
21216 <column alignment="center" valignment="top" leftline="true" width="10col%">
21217 <column alignment="center" valignment="top" leftline="true" width="0">
21218 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
21219 <column alignment="center" valignment="top" rightline="true" width="0">
21220 <row topline="true" bottomline="true" endhead="true">
21221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21222 \begin_inset Text
21223
21224 \begin_layout Standard
21225
21226 \series bold
21227 \size large
21228 mcs51
21229 \end_layout
21230
21231 \end_inset
21232 </cell>
21233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21234 \begin_inset Text
21235
21236 \begin_layout Standard
21237 printf
21238 \begin_inset LatexCommand index
21239 name "printf"
21240
21241 \end_inset
21242
21243
21244 \end_layout
21245
21246 \end_inset
21247 </cell>
21248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21249 \begin_inset Text
21250
21251 \begin_layout Standard
21252 printf 
21253 \size scriptsize
21254 USE_FLOATS=1
21255 \end_layout
21256
21257 \end_inset
21258 </cell>
21259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21260 \begin_inset Text
21261
21262 \begin_layout Standard
21263 printf_small
21264 \end_layout
21265
21266 \end_inset
21267 </cell>
21268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21269 \begin_inset Text
21270
21271 \begin_layout Standard
21272 printf_fast
21273 \end_layout
21274
21275 \end_inset
21276 </cell>
21277 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21278 \begin_inset Text
21279
21280 \begin_layout Standard
21281 printf_fast_f
21282 \end_layout
21283
21284 \end_inset
21285 </cell>
21286 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21287 \begin_inset Text
21288
21289 \begin_layout Standard
21290 printf_tiny
21291 \end_layout
21292
21293 \end_inset
21294 </cell>
21295 </row>
21296 <row topline="true" endhead="true">
21297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21298 \begin_inset Text
21299
21300 \begin_layout Standard
21301 filename
21302 \end_layout
21303
21304 \end_inset
21305 </cell>
21306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21307 \begin_inset Text
21308
21309 \begin_layout Standard
21310
21311 \size scriptsize
21312 printf_large.c
21313 \end_layout
21314
21315 \end_inset
21316 </cell>
21317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21318 \begin_inset Text
21319
21320 \begin_layout Standard
21321
21322 \size scriptsize
21323 printf_large.c
21324 \end_layout
21325
21326 \end_inset
21327 </cell>
21328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21329 \begin_inset Text
21330
21331 \begin_layout Standard
21332
21333 \size scriptsize
21334 printfl.c
21335 \end_layout
21336
21337 \end_inset
21338 </cell>
21339 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21340 \begin_inset Text
21341
21342 \begin_layout Standard
21343
21344 \size scriptsize
21345 printf_fast.c
21346 \end_layout
21347
21348 \end_inset
21349 </cell>
21350 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21351 \begin_inset Text
21352
21353 \begin_layout Standard
21354
21355 \size scriptsize
21356 printf_fast_f.c
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
21366 \size scriptsize
21367 printf_tiny.c
21368 \end_layout
21369
21370 \end_inset
21371 </cell>
21372 </row>
21373 <row topline="true" endhead="true">
21374 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21375 \begin_inset Text
21376
21377 \begin_layout Standard
21378 \begin_inset Quotes sld
21379 \end_inset
21380
21381 Hello World
21382 \begin_inset Quotes srd
21383 \end_inset
21384
21385  size
21386 \end_layout
21387
21388 \begin_layout Standard
21389 small / large
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 1.7k / 2.4k
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 4.3k / 5.6k
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.8k
21417 \end_layout
21418
21419 \end_inset
21420 </cell>
21421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21422 \begin_inset Text
21423
21424 \begin_layout Standard
21425 1.3k / 1.3k
21426 \end_layout
21427
21428 \end_inset
21429 </cell>
21430 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21431 \begin_inset Text
21432
21433 \begin_layout Standard
21434 1.9k / 1.9k
21435 \end_layout
21436
21437 \end_inset
21438 </cell>
21439 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21440 \begin_inset Text
21441
21442 \begin_layout Standard
21443 0.44k / 0.44k
21444 \end_layout
21445
21446 \end_inset
21447 </cell>
21448 </row>
21449 <row topline="true" endhead="true">
21450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21451 \begin_inset Text
21452
21453 \begin_layout Standard
21454 code size
21455 \end_layout
21456
21457 \begin_layout Standard
21458 small / large
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 1.4k / 2.0k
21468 \end_layout
21469
21470 \end_inset
21471 </cell>
21472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21473 \begin_inset Text
21474
21475 \begin_layout Standard
21476 2.8k / 3.7k
21477 \end_layout
21478
21479 \end_inset
21480 </cell>
21481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21482 \begin_inset Text
21483
21484 \begin_layout Standard
21485 0.45k / 0.47k (+ _ltoa)
21486 \end_layout
21487
21488 \end_inset
21489 </cell>
21490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21491 \begin_inset Text
21492
21493 \begin_layout Standard
21494 1.2k / 1.2k
21495 \end_layout
21496
21497 \end_inset
21498 </cell>
21499 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21500 \begin_inset Text
21501
21502 \begin_layout Standard
21503 1.6k / 1.6k
21504 \end_layout
21505
21506 \end_inset
21507 </cell>
21508 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21509 \begin_inset Text
21510
21511 \begin_layout Standard
21512 0.26k / 0.26k
21513 \end_layout
21514
21515 \end_inset
21516 </cell>
21517 </row>
21518 <row topline="true">
21519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21520 \begin_inset Text
21521
21522 \begin_layout Standard
21523 formats
21524 \end_layout
21525
21526 \end_inset
21527 </cell>
21528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21529 \begin_inset Text
21530
21531 \begin_layout Standard
21532 cdi
21533 \emph on
21534 o
21535 \emph default
21536 psux
21537 \end_layout
21538
21539 \end_inset
21540 </cell>
21541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21542 \begin_inset Text
21543
21544 \begin_layout Standard
21545
21546 \family roman
21547 \series medium
21548 \shape up
21549 \size normal
21550 \emph off
21551 \bar no
21552 \noun off
21553 \color none
21554 cd
21555 \family default
21556 \series default
21557 \shape default
21558 \size default
21559 \emph default
21560 \bar default
21561 \noun default
21562 f
21563 \family roman
21564 \series medium
21565 \shape up
21566 \size normal
21567 \emph off
21568 \bar no
21569 \noun off
21570 i
21571 \family default
21572 \series default
21573 \shape default
21574 \size default
21575 \emph on
21576 \bar default
21577 \noun default
21578 o
21579 \family roman
21580 \series medium
21581 \shape up
21582 \size normal
21583 \emph off
21584 \bar no
21585 \noun off
21586 psux
21587 \end_layout
21588
21589 \end_inset
21590 </cell>
21591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21592 \begin_inset Text
21593
21594 \begin_layout Standard
21595 c
21596 \family roman
21597 \series medium
21598 \shape up
21599 \size normal
21600 \emph off
21601 \bar no
21602 \noun off
21603 \color none
21604 d
21605 \family default
21606 \series default
21607 \shape default
21608 \size default
21609 \emph on
21610 \bar default
21611 \noun default
21612 o
21613 \family roman
21614 \series medium
21615 \shape up
21616 \size normal
21617 \emph off
21618 \bar no
21619 \noun off
21620 s
21621 \family default
21622 \series default
21623 \shape default
21624 \size default
21625 \emph default
21626 \bar default
21627 \noun default
21628 x
21629 \end_layout
21630
21631 \end_inset
21632 </cell>
21633 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21634 \begin_inset Text
21635
21636 \begin_layout Standard
21637 cdsux
21638 \end_layout
21639
21640 \end_inset
21641 </cell>
21642 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21643 \begin_inset Text
21644
21645 \begin_layout Standard
21646 cdfsux
21647 \end_layout
21648
21649 \end_inset
21650 </cell>
21651 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21652 \begin_inset Text
21653
21654 \begin_layout Standard
21655 cdsux
21656 \end_layout
21657
21658 \end_inset
21659 </cell>
21660 </row>
21661 <row topline="true">
21662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21663 \begin_inset Text
21664
21665 \begin_layout Standard
21666 long (32 bit) support
21667 \end_layout
21668
21669 \end_inset
21670 </cell>
21671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21672 \begin_inset Text
21673
21674 \begin_layout Standard
21675 x
21676 \end_layout
21677
21678 \end_inset
21679 </cell>
21680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21681 \begin_inset Text
21682
21683 \begin_layout Standard
21684 x
21685 \end_layout
21686
21687 \end_inset
21688 </cell>
21689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21690 \begin_inset Text
21691
21692 \begin_layout Standard
21693 x
21694 \end_layout
21695
21696 \end_inset
21697 </cell>
21698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21699 \begin_inset Text
21700
21701 \begin_layout Standard
21702 x
21703 \end_layout
21704
21705 \end_inset
21706 </cell>
21707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21708 \begin_inset Text
21709
21710 \begin_layout Standard
21711
21712 \family roman
21713 \series medium
21714 \shape up
21715 \size normal
21716 \emph off
21717 \bar no
21718 \noun off
21719 \color none
21720 x
21721 \end_layout
21722
21723 \end_inset
21724 </cell>
21725 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21726 \begin_inset Text
21727
21728 \begin_layout Standard
21729 -
21730 \end_layout
21731
21732 \end_inset
21733 </cell>
21734 </row>
21735 <row topline="true">
21736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21737 \begin_inset Text
21738
21739 \begin_layout Standard
21740 byte arguments on stack
21741 \end_layout
21742
21743 \end_inset
21744 </cell>
21745 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21746 \begin_inset Text
21747
21748 \begin_layout Standard
21749 b
21750 \end_layout
21751
21752 \end_inset
21753 </cell>
21754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21755 \begin_inset Text
21756
21757 \begin_layout Standard
21758 b
21759 \end_layout
21760
21761 \end_inset
21762 </cell>
21763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21764 \begin_inset Text
21765
21766 \begin_layout Standard
21767 -
21768 \end_layout
21769
21770 \end_inset
21771 </cell>
21772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21773 \begin_inset Text
21774
21775 \begin_layout Standard
21776 -
21777 \end_layout
21778
21779 \end_inset
21780 </cell>
21781 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21782 \begin_inset Text
21783
21784 \begin_layout Standard
21785 -
21786 \end_layout
21787
21788 \end_inset
21789 </cell>
21790 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21791 \begin_inset Text
21792
21793 \begin_layout Standard
21794 -
21795 \end_layout
21796
21797 \end_inset
21798 </cell>
21799 </row>
21800 <row topline="true">
21801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21802 \begin_inset Text
21803
21804 \begin_layout Standard
21805 float format
21806 \begin_inset LatexCommand index
21807 name "Floating point support"
21808
21809 \end_inset
21810
21811
21812 \end_layout
21813
21814 \end_inset
21815 </cell>
21816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21817 \begin_inset Text
21818
21819 \begin_layout Standard
21820 -
21821 \end_layout
21822
21823 \end_inset
21824 </cell>
21825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21826 \begin_inset Text
21827
21828 \begin_layout Standard
21829 %f
21830 \end_layout
21831
21832 \end_inset
21833 </cell>
21834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21835 \begin_inset Text
21836
21837 \begin_layout Standard
21838 -
21839 \end_layout
21840
21841 \end_inset
21842 </cell>
21843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21844 \begin_inset Text
21845
21846 \begin_layout Standard
21847 -
21848 \end_layout
21849
21850 \end_inset
21851 </cell>
21852 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21853 \begin_inset Text
21854
21855 \begin_layout Standard
21856 %f
21857 \begin_inset Foot
21858 status collapsed
21859
21860 \begin_layout Standard
21861 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
21862 \end_layout
21863
21864 \end_inset
21865
21866
21867 \end_layout
21868
21869 \end_inset
21870 </cell>
21871 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21872 \begin_inset Text
21873
21874 \begin_layout Standard
21875 -
21876 \end_layout
21877
21878 \end_inset
21879 </cell>
21880 </row>
21881 <row topline="true">
21882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21883 \begin_inset Text
21884
21885 \begin_layout Standard
21886 float formats %e %g
21887 \end_layout
21888
21889 \end_inset
21890 </cell>
21891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21892 \begin_inset Text
21893
21894 \begin_layout Standard
21895 -
21896 \end_layout
21897
21898 \end_inset
21899 </cell>
21900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21901 \begin_inset Text
21902
21903 \begin_layout Standard
21904 -
21905 \end_layout
21906
21907 \end_inset
21908 </cell>
21909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21910 \begin_inset Text
21911
21912 \begin_layout Standard
21913 -
21914 \end_layout
21915
21916 \end_inset
21917 </cell>
21918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21919 \begin_inset Text
21920
21921 \begin_layout Standard
21922 -
21923 \end_layout
21924
21925 \end_inset
21926 </cell>
21927 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21928 \begin_inset Text
21929
21930 \begin_layout Standard
21931 -
21932 \end_layout
21933
21934 \end_inset
21935 </cell>
21936 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21937 \begin_inset Text
21938
21939 \begin_layout Standard
21940 -
21941 \end_layout
21942
21943 \end_inset
21944 </cell>
21945 </row>
21946 <row topline="true" bottomline="true">
21947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21948 \begin_inset Text
21949
21950 \begin_layout Standard
21951 field width
21952 \end_layout
21953
21954 \end_inset
21955 </cell>
21956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21957 \begin_inset Text
21958
21959 \begin_layout Standard
21960 x
21961 \end_layout
21962
21963 \end_inset
21964 </cell>
21965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21966 \begin_inset Text
21967
21968 \begin_layout Standard
21969 x
21970 \end_layout
21971
21972 \end_inset
21973 </cell>
21974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21975 \begin_inset Text
21976
21977 \begin_layout Standard
21978 -
21979 \end_layout
21980
21981 \end_inset
21982 </cell>
21983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21984 \begin_inset Text
21985
21986 \begin_layout Standard
21987 x
21988 \end_layout
21989
21990 \end_inset
21991 </cell>
21992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21993 \begin_inset Text
21994
21995 \begin_layout Standard
21996 x
21997 \end_layout
21998
21999 \end_inset
22000 </cell>
22001 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22002 \begin_inset Text
22003
22004 \begin_layout Standard
22005 -
22006 \end_layout
22007
22008 \end_inset
22009 </cell>
22010 </row>
22011 <row bottomline="true">
22012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22013 \begin_inset Text
22014
22015 \begin_layout Standard
22016 string speed
22017 \begin_inset Foot
22018 status collapsed
22019
22020 \begin_layout Standard
22021 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
22022 \backslash
22023 r', '
22024 \backslash
22025 n'); standard 8051 @ 22.1184 MHz, empty putchar()
22026 \end_layout
22027
22028 \end_inset
22029
22030 ,
22031 \end_layout
22032
22033 \begin_layout Standard
22034 small / large
22035 \end_layout
22036
22037 \end_inset
22038 </cell>
22039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22040 \begin_inset Text
22041
22042 \begin_layout Standard
22043 1.52 / 2.59 ms
22044 \end_layout
22045
22046 \end_inset
22047 </cell>
22048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22049 \begin_inset Text
22050
22051 \begin_layout Standard
22052 1.53 / 2.62 ms
22053 \end_layout
22054
22055 \end_inset
22056 </cell>
22057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22058 \begin_inset Text
22059
22060 \begin_layout Standard
22061 0.92 / 0.93 ms
22062 \end_layout
22063
22064 \end_inset
22065 </cell>
22066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22067 \begin_inset Text
22068
22069 \begin_layout Standard
22070 0.45 / 0.45 ms
22071 \end_layout
22072
22073 \end_inset
22074 </cell>
22075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22076 \begin_inset Text
22077
22078 \begin_layout Standard
22079 0.46 / 0.46 ms
22080 \end_layout
22081
22082 \end_inset
22083 </cell>
22084 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22085 \begin_inset Text
22086
22087 \begin_layout Standard
22088 0.45 / 0.45 ms
22089 \end_layout
22090
22091 \end_inset
22092 </cell>
22093 </row>
22094 <row bottomline="true">
22095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22096 \begin_inset Text
22097
22098 \begin_layout Standard
22099 int speed
22100 \begin_inset Foot
22101 status collapsed
22102
22103 \begin_layout Standard
22104 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
22105  putchar()
22106 \end_layout
22107
22108 \end_inset
22109
22110 ,
22111 \end_layout
22112
22113 \begin_layout Standard
22114 small / large
22115 \end_layout
22116
22117 \end_inset
22118 </cell>
22119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22120 \begin_inset Text
22121
22122 \begin_layout Standard
22123 3.01 / 3.61 ms
22124 \end_layout
22125
22126 \end_inset
22127 </cell>
22128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22129 \begin_inset Text
22130
22131 \begin_layout Standard
22132 3.01 / 3.61 ms
22133 \end_layout
22134
22135 \end_inset
22136 </cell>
22137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22138 \begin_inset Text
22139
22140 \begin_layout Standard
22141 3.51 / 18.13 ms
22142 \end_layout
22143
22144 \end_inset
22145 </cell>
22146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22147 \begin_inset Text
22148
22149 \begin_layout Standard
22150 0.22 / 0.22 ms
22151 \end_layout
22152
22153 \end_inset
22154 </cell>
22155 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22156 \begin_inset Text
22157
22158 \begin_layout Standard
22159 0.23 / 0.23 ms
22160 \end_layout
22161
22162 \end_inset
22163 </cell>
22164 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22165 \begin_inset Text
22166
22167 \begin_layout Standard
22168 0.25 / 0.25 ms
22169 \begin_inset Foot
22170 status collapsed
22171
22172 \begin_layout Standard
22173 printf_tiny integer speed is data dependent, worst case is 0.33 ms
22174 \end_layout
22175
22176 \end_inset
22177
22178
22179 \end_layout
22180
22181 \end_inset
22182 </cell>
22183 </row>
22184 <row bottomline="true">
22185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22186 \begin_inset Text
22187
22188 \begin_layout Standard
22189 long speed
22190 \begin_inset Foot
22191 status collapsed
22192
22193 \begin_layout Standard
22194 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
22195  empty putchar()
22196 \end_layout
22197
22198 \end_inset
22199
22200 ,
22201 \end_layout
22202
22203 \begin_layout Standard
22204 small / large
22205 \end_layout
22206
22207 \end_inset
22208 </cell>
22209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22210 \begin_inset Text
22211
22212 \begin_layout Standard
22213 5.37 / 6.31 ms
22214 \end_layout
22215
22216 \end_inset
22217 </cell>
22218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22219 \begin_inset Text
22220
22221 \begin_layout Standard
22222 5.37 / 6.31 ms
22223 \end_layout
22224
22225 \end_inset
22226 </cell>
22227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22228 \begin_inset Text
22229
22230 \begin_layout Standard
22231 8.71 / 40.65 ms
22232 \end_layout
22233
22234 \end_inset
22235 </cell>
22236 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22237 \begin_inset Text
22238
22239 \begin_layout Standard
22240 0.40 / 0.40 ms
22241 \end_layout
22242
22243 \end_inset
22244 </cell>
22245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22246 \begin_inset Text
22247
22248 \begin_layout Standard
22249 0.40 / 0.40 ms
22250 \end_layout
22251
22252 \end_inset
22253 </cell>
22254 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22255 \begin_inset Text
22256
22257 \begin_layout Standard
22258 -
22259 \end_layout
22260
22261 \end_inset
22262 </cell>
22263 </row>
22264 <row bottomline="true">
22265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22266 \begin_inset Text
22267
22268 \begin_layout Standard
22269 float speed
22270 \begin_inset Foot
22271 status collapsed
22272
22273 \begin_layout Standard
22274 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
22275  empty putchar()
22276 \end_layout
22277
22278 \end_inset
22279
22280 ,
22281 \end_layout
22282
22283 \begin_layout Standard
22284 small / large
22285 \end_layout
22286
22287 \end_inset
22288 </cell>
22289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22290 \begin_inset Text
22291
22292 \begin_layout Standard
22293 -
22294 \end_layout
22295
22296 \end_inset
22297 </cell>
22298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22299 \begin_inset Text
22300
22301 \begin_layout Standard
22302 7.49 / 22.47 ms
22303 \end_layout
22304
22305 \end_inset
22306 </cell>
22307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22308 \begin_inset Text
22309
22310 \begin_layout Standard
22311 -
22312 \end_layout
22313
22314 \end_inset
22315 </cell>
22316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22317 \begin_inset Text
22318
22319 \begin_layout Standard
22320 -
22321 \end_layout
22322
22323 \end_inset
22324 </cell>
22325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22326 \begin_inset Text
22327
22328 \begin_layout Standard
22329 1.04 / 1.04 ms
22330 \end_layout
22331
22332 \end_inset
22333 </cell>
22334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22335 \begin_inset Text
22336
22337 \begin_layout Standard
22338 -
22339 \end_layout
22340
22341 \end_inset
22342 </cell>
22343 </row>
22344 </lyxtabular>
22345
22346 \end_inset
22347
22348
22349 \end_layout
22350
22351 \begin_layout Subsubsection
22352 <malloc.h>
22353 \begin_inset LatexCommand index
22354 name "malloc.h"
22355
22356 \end_inset
22357
22358
22359 \end_layout
22360
22361 \begin_layout Standard
22362 As of SDCC 2.6.2 you no longer need to call an initialization routine before
22363  using dynamic memory allocation
22364 \begin_inset LatexCommand index
22365 name "dynamic memory allocation (malloc)"
22366
22367 \end_inset
22368
22369  and a default heap
22370 \begin_inset LatexCommand index
22371 name "heap (malloc)"
22372
22373 \end_inset
22374
22375  space of 1024 bytes is provided for malloc to allocate memory from.
22376  If you need a different heap size you need to recompile _heap.c with the
22377  required size defined in HEAP_SIZE.
22378  It is recommended to make a copy of this file into your project directory
22379  and compile it there with:
22380 \end_layout
22381
22382 \begin_layout Verse
22383
22384 \family typewriter
22385 sdcc -c _heap.c -D HEAD_SIZE=2048
22386 \end_layout
22387
22388 \begin_layout Standard
22389 And then link it with:
22390 \end_layout
22391
22392 \begin_layout Verse
22393
22394 \family typewriter
22395 sdcc main.rel _heap.rel
22396 \end_layout
22397
22398 \begin_layout Subsection
22399 Math functions (sinf, powf, sqrtf etc.)
22400 \end_layout
22401
22402 \begin_layout Subsubsection
22403 <math.h>
22404 \end_layout
22405
22406 \begin_layout Standard
22407 See definitions in file <math.h>.
22408 \end_layout
22409
22410 \begin_layout Subsection
22411 Other libraries
22412 \end_layout
22413
22414 \begin_layout Standard
22415 Libraries
22416 \begin_inset LatexCommand index
22417 name "Libraries"
22418
22419 \end_inset
22420
22421  included in SDCC should have a license at least as liberal as the GNU Lesser
22422  General Public License
22423 \begin_inset LatexCommand index
22424 name "GNU Lesser General Public License, LGPL"
22425
22426 \end_inset
22427
22428  
22429 \emph on
22430 LGPL
22431 \emph default
22432 .
22433 \end_layout
22434
22435 \begin_layout Standard
22436 \begin_inset Note Note
22437 status collapsed
22438
22439 \begin_layout Standard
22440 license statements for the libraries are missing.
22441  sdcc/device/lib/ser_ir.c
22442 \end_layout
22443
22444 \begin_layout Standard
22445 or _decdptr f.e.
22446  come with a GPL (as opposed to LGPL) License - this will not be liberal
22447  enough for many embedded programmers.
22448 \end_layout
22449
22450 \end_inset
22451
22452
22453 \end_layout
22454
22455 \begin_layout Standard
22456 If you have ported some library or want to share experience about some code
22457  which f.e.
22458  falls into any of these categories Busses (I
22459 \begin_inset Formula $^{\textrm{2}}$
22460 \end_inset
22461
22462 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
22463  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
22464  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
22465 \begin_inset LatexCommand url
22466 target "http://sourceforge.net/mail/?group_id=599"
22467
22468 \end_inset
22469
22470 \InsetSpace ~
22471 would certainly like to hear about it.
22472 \end_layout
22473
22474 \begin_layout Standard
22475 Programmers coding for embedded systems are not especially famous for being
22476  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
22477 e these references are very valuable.
22478  Let's help to create a climate where information is shared.
22479 \begin_inset VSpace bigskip
22480 \end_inset
22481
22482
22483 \end_layout
22484
22485 \begin_layout Section
22486 Memory Models
22487 \end_layout
22488
22489 \begin_layout Subsection
22490 MCS51 Memory Models
22491 \begin_inset LatexCommand index
22492 name "Memory model"
22493
22494 \end_inset
22495
22496
22497 \begin_inset LatexCommand index
22498 name "MCS51 memory model"
22499
22500 \end_inset
22501
22502
22503 \end_layout
22504
22505 \begin_layout Subsubsection
22506 Small, Medium and Large
22507 \end_layout
22508
22509 \begin_layout Standard
22510 SDCC allows three memory models for MCS51 code, 
22511 \shape slanted
22512 small, medium
22513 \shape default
22514  and 
22515 \shape slanted
22516 large
22517 \shape default
22518 .
22519  Modules compiled with different memory models should 
22520 \emph on
22521 never
22522 \emph default
22523  be combined together or the results would be unpredictable.
22524  The library routines supplied with the compiler are compiled as small,
22525  medium and large.
22526  The compiled library modules are contained in separate directories as small,
22527  medium and large so that you can link to the appropriate set.
22528 \end_layout
22529
22530 \begin_layout Standard
22531 When the medium or large model is used all variables declared without a
22532  storage class will be allocated into the external ram, this includes all
22533  parameters and local variables (for non-reentrant
22534 \begin_inset LatexCommand index
22535 name "reentrant"
22536
22537 \end_inset
22538
22539  functions).
22540  When the small model is used variables without storage class are allocated
22541  in the internal ram.
22542 \end_layout
22543
22544 \begin_layout Standard
22545 Judicious usage of the processor specific storage classes
22546 \begin_inset LatexCommand index
22547 name "Storage class"
22548
22549 \end_inset
22550
22551  and the 'reentrant' function type will yield much more efficient code,
22552  than using the large model.
22553  Several optimizations are disabled when the program is compiled using the
22554  large model, it is therefore recommended that the small model be used unless
22555  absolutely required.
22556 \end_layout
22557
22558 \begin_layout Subsubsection
22559 External Stack
22560 \begin_inset LatexCommand label
22561 name "sub:External-Stack"
22562
22563 \end_inset
22564
22565
22566 \begin_inset LatexCommand index
22567 name "stack"
22568
22569 \end_inset
22570
22571
22572 \begin_inset LatexCommand index
22573 name "External stack (mcs51)"
22574
22575 \end_inset
22576
22577
22578 \end_layout
22579
22580 \begin_layout Standard
22581 The external stack (-
22582 \begin_inset ERT
22583 status collapsed
22584
22585 \begin_layout Standard
22586
22587
22588 \backslash
22589 /
22590 \end_layout
22591
22592 \end_inset
22593
22594 -xstack option
22595 \begin_inset LatexCommand index
22596 name "-\\/-xstack"
22597
22598 \end_inset
22599
22600 ) is located in pdata
22601 \begin_inset LatexCommand index
22602 name "pdata (mcs51, ds390 storage class)"
22603
22604 \end_inset
22605
22606  memory (usually at the start of the external ram segment) and uses all
22607  unused space in pdata (max.
22608  256 bytes).
22609  When -
22610 \begin_inset ERT
22611 status collapsed
22612
22613 \begin_layout Standard
22614
22615
22616 \backslash
22617 /
22618 \end_layout
22619
22620 \end_inset
22621
22622 -xstack option is used to compile the program, the parameters and local
22623  variables
22624 \begin_inset LatexCommand index
22625 name "local variables"
22626
22627 \end_inset
22628
22629  of all reentrant functions are allocated in this area.
22630  This option is provided for programs with large stack space requirements.
22631  When used with the -
22632 \begin_inset ERT
22633 status collapsed
22634
22635 \begin_layout Standard
22636
22637
22638 \backslash
22639 /
22640 \end_layout
22641
22642 \end_inset
22643
22644 -stack-auto
22645 \begin_inset LatexCommand index
22646 name "-\\/-stack-auto"
22647
22648 \end_inset
22649
22650  option, all parameters and local variables are allocated on the external
22651  stack (note: support libraries will need to be recompiled with the same
22652  options.
22653  There is a predefined target in the library makefile).
22654 \end_layout
22655
22656 \begin_layout Standard
22657 The compiler outputs the higher order address byte of the external ram segment
22658  into port P2
22659 \begin_inset LatexCommand index
22660 name "P2 (mcs51 sfr)"
22661
22662 \end_inset
22663
22664  (see also section 
22665 \begin_inset LatexCommand ref
22666 reference "sub:MCS51-variants"
22667
22668 \end_inset
22669
22670 ), therefore when using the External Stack option, this port 
22671 \emph on
22672 may not
22673 \emph default
22674  be used by the application program.
22675 \end_layout
22676
22677 \begin_layout Subsection
22678 DS390 Memory Model
22679 \begin_inset LatexCommand index
22680 name "Memory model"
22681
22682 \end_inset
22683
22684
22685 \begin_inset LatexCommand index
22686 name "DS390 memory model"
22687
22688 \end_inset
22689
22690
22691 \end_layout
22692
22693 \begin_layout Standard
22694 The only model supported is Flat 24
22695 \begin_inset LatexCommand index
22696 name "Flat 24 (DS390 memory model)"
22697
22698 \end_inset
22699
22700 .
22701  This generates code for the 24 bit contiguous addressing mode of the Dallas
22702  DS80C390 part.
22703  In this mode, up to four meg of external RAM or code space can be directly
22704  addressed.
22705  See the data sheets at www.dalsemi.com for further information on this part.
22706 \newline
22707
22708 \newline
22709 Note
22710  that the compiler does not generate any code to place the processor into
22711  24 bitmode (although 
22712 \emph on
22713 tinibios
22714 \emph default
22715  in the ds390 libraries will do that for you).
22716  If you don't use 
22717 \emph on
22718 tinibios
22719 \emph default
22720
22721 \begin_inset LatexCommand index
22722 name "Tinibios (DS390)"
22723
22724 \end_inset
22725
22726 , the boot loader or similar code must ensure that the processor is in 24
22727  bit contiguous addressing mode before calling the SDCC startup code.
22728 \newline
22729
22730 \newline
22731 Like
22732  the 
22733 \emph on
22734 -
22735 \begin_inset ERT
22736 status collapsed
22737
22738 \begin_layout Standard
22739
22740
22741 \backslash
22742 /
22743 \end_layout
22744
22745 \end_inset
22746
22747 -model-large
22748 \emph default
22749  option, variables will by default be placed into the XDATA segment.
22750  
22751 \newline
22752
22753 \newline
22754 Segments may be placed anywhere in the 4 meg address space using the usual
22755  -
22756 \begin_inset ERT
22757 status collapsed
22758
22759 \begin_layout Standard
22760
22761
22762 \backslash
22763 /
22764 \end_layout
22765
22766 \end_inset
22767
22768 -*-loc options.
22769  Note that if any segments are located above 64K, the -r flag must be passed
22770  to the linker to generate the proper segment relocations, and the Intel
22771  HEX output format must be used.
22772  The -r flag can be passed to the linker by using the option 
22773 \emph on
22774 -Wl-r
22775 \emph default
22776  on the SDCC command line.
22777  However, currently the linker can not handle code segments > 64k.
22778 \end_layout
22779
22780 \begin_layout Section
22781 Pragmas
22782 \begin_inset LatexCommand label
22783 name "sec:Pragmas"
22784
22785 \end_inset
22786
22787
22788 \begin_inset LatexCommand index
22789 name "Pragmas"
22790
22791 \end_inset
22792
22793
22794 \end_layout
22795
22796 \begin_layout Standard
22797 Pragmas are used to turn on and/or off certain compiler options.
22798  Some of them are closely related to corresponding command-line options
22799  (see section 
22800 \begin_inset LatexCommand vref
22801 reference "sec:Command-Line-Options"
22802
22803 \end_inset
22804
22805 ).
22806 \newline
22807 Pragmas should be placed before and/or after a function, placing pragmas
22808  inside a function body could have unpredictable results.
22809 \newline
22810
22811 \newline
22812 SDCC supports the
22813  following #pragma directives:
22814 \end_layout
22815
22816 \begin_layout Itemize
22817
22818 \series bold
22819 save
22820 \series default
22821
22822 \begin_inset LatexCommand index
22823 name "\\#pragma save"
22824
22825 \end_inset
22826
22827  - this will save most current options to the save/restore stack.
22828  See #pragma\InsetSpace ~
22829 restore.
22830 \end_layout
22831
22832 \begin_layout Itemize
22833
22834 \series bold
22835 restore
22836 \series default
22837
22838 \begin_inset LatexCommand index
22839 name "\\#pragma restore"
22840
22841 \end_inset
22842
22843  - will restore saved options from the last save.
22844  saves & restores can be nested.
22845  SDCC uses a save/restore stack: save pushes current options to the stack,
22846  restore pulls current options from the stack.
22847  See #pragma\InsetSpace ~
22848 save.
22849 \newline
22850
22851 \end_layout
22852
22853 \begin_layout Itemize
22854
22855 \series bold
22856 callee_saves
22857 \series default
22858
22859 \begin_inset LatexCommand index
22860 name "\\#pragma callee\\_saves"
22861
22862 \end_inset
22863
22864
22865 \begin_inset LatexCommand index
22866 name "function prologue"
22867
22868 \end_inset
22869
22870  function1[,function2[,function3...]] 
22871 \begin_inset LatexCommand label
22872 name "ite:callee_saves-function1[,function2[,function3...]]--"
22873
22874 \end_inset
22875
22876 - The compiler by default uses a caller saves convention for register saving
22877  across function calls, however this can cause unnecessary register pushing
22878  and popping
22879 \begin_inset LatexCommand index
22880 name "push/pop"
22881
22882 \end_inset
22883
22884  when calling small functions from larger functions.
22885  This option can be used to switch off the register saving convention for
22886  the function names specified.
22887  The compiler will not save registers when calling these functions, extra
22888  code need to be manually inserted at the entry and exit for these functions
22889  to save and restore the registers used by these functions, this can SUBSTANTIAL
22890 LY reduce code and improve run time performance of the generated code.
22891  In the future the compiler (with inter procedural analysis) may be able
22892  to determine the appropriate scheme to use for each function call.
22893  If -
22894 \begin_inset ERT
22895 status collapsed
22896
22897 \begin_layout Standard
22898
22899
22900 \backslash
22901 /
22902 \end_layout
22903
22904 \end_inset
22905
22906 -callee-saves command line option is used (see page 
22907 \begin_inset LatexCommand vpageref
22908 reference "lyx:--callee-saves-function1[,function2][,function3]..."
22909
22910 \end_inset
22911
22912 ), the function names specified in #pragma\InsetSpace ~
22913 callee_saves
22914 \begin_inset LatexCommand index
22915 name "\\#pragma callee\\_saves"
22916
22917 \end_inset
22918
22919  is appended to the list of functions specified in the command line.
22920 \end_layout
22921
22922 \begin_layout Itemize
22923
22924 \series bold
22925 exclude
22926 \series default
22927
22928 \begin_inset LatexCommand index
22929 name "\\#pragma exclude"
22930
22931 \end_inset
22932
22933  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
22934  of pairs of push/pop
22935 \begin_inset LatexCommand index
22936 name "push/pop"
22937
22938 \end_inset
22939
22940  instructions in 
22941 \emph on
22942 I
22943 \emph default
22944 nterrupt
22945 \begin_inset LatexCommand index
22946 name "interrupt"
22947
22948 \end_inset
22949
22950  
22951 \emph on
22952 S
22953 \emph default
22954 ervice 
22955 \emph on
22956 R
22957 \emph default
22958 outines.
22959  The directive should be placed immediately before the ISR function definition
22960  and it affects ALL ISR functions following it.
22961  To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
22962 exclude\InsetSpace ~
22963 none
22964 \begin_inset LatexCommand index
22965 name "\\#pragma exclude"
22966
22967 \end_inset
22968
22969 .
22970  See also the related keyword _naked
22971 \begin_inset LatexCommand index
22972 name "\\_naked"
22973
22974 \end_inset
22975
22976
22977 \begin_inset LatexCommand index
22978 name "\\_\\_naked"
22979
22980 \end_inset
22981
22982 .
22983 \end_layout
22984
22985 \begin_layout Itemize
22986
22987 \series bold
22988 less_pedantic
22989 \series default
22990
22991 \begin_inset LatexCommand index
22992 name "pedantic"
22993
22994 \end_inset
22995
22996
22997 \begin_inset LatexCommand index
22998 name "\\#pragma less\\_pedantic"
22999
23000 \end_inset
23001
23002  
23003 \begin_inset LatexCommand label
23004 name "ite:less_pedantic"
23005
23006 \end_inset
23007
23008 - the compiler will not warn you anymore for obvious mistakes, you're on
23009  your own now ;-( .
23010  See also the command line option -
23011 \begin_inset ERT
23012 status collapsed
23013
23014 \begin_layout Standard
23015
23016
23017 \backslash
23018 /
23019 \end_layout
23020
23021 \end_inset
23022
23023 -less-pedantic 
23024 \begin_inset LatexCommand vpageref
23025 reference "lyx:--less-pedantic"
23026
23027 \end_inset
23028
23029 .
23030  
23031 \newline
23032 More specifically, the following warnings will be disabled: 
23033 \shape italic
23034 comparison is always [true/false] due to limited range of data type
23035 \shape default
23036  (94); 
23037 \shape italic
23038 overflow in implicit constant conversion
23039 \shape default
23040  (158); [the (in)famous] 
23041 \shape italic
23042 conditional flow changed by optimizer: so said EVELYN the modified DOG
23043 \shape default
23044  (110); 
23045 \shape italic
23046 function '[function name]' must return value
23047 \shape default
23048  (59).
23049  
23050 \newline
23051 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
23052  level) are disabled, too, namely: 
23053 \shape italic
23054 constant value '[
23055 \begin_inset Note Note
23056 status collapsed
23057
23058 \begin_layout Standard
23059 dunno what comes here - this warning appears to be unused altogether
23060 \end_layout
23061
23062 \end_inset
23063
23064 ]', out of range
23065 \shape default
23066  (81); 
23067 \shape italic
23068 [left/right] shifting more than size of object changed to zero
23069 \shape default
23070  (116); 
23071 \shape italic
23072 unreachable code
23073 \shape default
23074  (126); 
23075 \shape italic
23076 integer overflow in expression
23077 \shape default
23078  (165); 
23079 \shape italic
23080 unmatched #pragma save and #pragma restore
23081 \shape default
23082  (170); 
23083 \shape italic
23084 comparison of 'signed char' with 'unsigned char' requires promotion to int
23085 \shape default
23086  (185); 
23087 \shape italic
23088 ISO C90 does not support flexible array members
23089 \shape default
23090  (187); 
23091 \shape italic
23092 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
23093 nam
23094 e]':\InsetSpace ~
23095 [
23096 \begin_inset Note Note
23097 status collapsed
23098
23099 \begin_layout Standard
23100 appears to be always blank - what was supposed to be here?
23101 \end_layout
23102
23103 \end_inset
23104
23105 ]
23106 \shape default
23107  (114); 
23108 \shape italic
23109 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
23110  complexity [number]
23111 \shape default
23112  (121).
23113 \end_layout
23114
23115 \begin_layout Itemize
23116
23117 \series bold
23118 disable_warning
23119 \series default
23120  <nnnn>
23121 \begin_inset LatexCommand index
23122 name "\\#pragma disable\\_warning"
23123
23124 \end_inset
23125
23126  - the compiler will not warn you anymore about warning number <nnnn>.
23127 \end_layout
23128
23129 \begin_layout Itemize
23130
23131 \series bold
23132 nogcse
23133 \series default
23134
23135 \begin_inset LatexCommand index
23136 name "\\#pragma nogcse"
23137
23138 \end_inset
23139
23140  - will stop global common subexpression elimination.
23141 \end_layout
23142
23143 \begin_layout Itemize
23144
23145 \series bold
23146 noinduction
23147 \series default
23148
23149 \begin_inset LatexCommand index
23150 name "\\#pragma noinduction"
23151
23152 \end_inset
23153
23154  - will stop loop induction optimizations.
23155 \end_layout
23156
23157 \begin_layout Itemize
23158
23159 \series bold
23160 noinvariant
23161 \series default
23162
23163 \begin_inset LatexCommand index
23164 name "\\#pragma noinvariant"
23165
23166 \end_inset
23167
23168  - will not do loop invariant optimizations.
23169  For more details see Loop Invariants in section
23170 \begin_inset LatexCommand ref
23171 reference "sub:Loop-Optimizations"
23172
23173 \end_inset
23174
23175 .
23176 \end_layout
23177
23178 \begin_layout Itemize
23179
23180 \series bold
23181 noiv
23182 \series default
23183
23184 \begin_inset LatexCommand index
23185 name "\\#pragma noiv"
23186
23187 \end_inset
23188
23189  - Do not generate interrupt
23190 \begin_inset LatexCommand index
23191 name "interrupt"
23192
23193 \end_inset
23194
23195  vector table
23196 \begin_inset LatexCommand index
23197 name "interrupt vector table"
23198
23199 \end_inset
23200
23201  entries for all ISR functions defined after the pragma.
23202  This is useful in cases where the interrupt vector table must be defined
23203  manually, or when there is a secondary, manually defined interrupt vector
23204  table (e.g.
23205  for the autovector feature of the Cypress EZ-USB FX2).
23206  More elegantly this can be achieved by omitting the optional interrupt
23207  number after the interrupt keyword, see section 
23208 \begin_inset LatexCommand ref
23209 reference "sub:Interrupt-Service-Routines"
23210
23211 \end_inset
23212
23213 \InsetSpace ~
23214 about interrupts.
23215 \end_layout
23216
23217 \begin_layout Itemize
23218
23219 \series bold
23220 nojtbound
23221 \series default
23222
23223 \begin_inset LatexCommand index
23224 name "\\#pragma nojtbound"
23225
23226 \end_inset
23227
23228  - will not generate code for boundary value checking, when switch statements
23229  are turned into jump-tables (dangerous).
23230  For more details see section 
23231 \begin_inset LatexCommand ref
23232 reference "sub:'switch'-Statements"
23233
23234 \end_inset
23235
23236 .
23237 \end_layout
23238
23239 \begin_layout Itemize
23240
23241 \series bold
23242 noloopreverse
23243 \series default
23244
23245 \begin_inset LatexCommand index
23246 name "\\#pragma noloopreverse"
23247
23248 \end_inset
23249
23250  - Will not do loop reversal optimization
23251 \end_layout
23252
23253 \begin_layout Itemize
23254
23255 \series bold
23256 nooverlay
23257 \series default
23258
23259 \begin_inset LatexCommand index
23260 name "\\#pragma nooverlay"
23261
23262 \end_inset
23263
23264  - the compiler will not overlay the parameters and local variables of a
23265  function.
23266 \end_layout
23267
23268 \begin_layout Itemize
23269
23270 \series bold
23271 stackauto
23272 \series default
23273
23274 \begin_inset LatexCommand index
23275 name "\\#pragma stackauto"
23276
23277 \end_inset
23278
23279 - See option -
23280 \begin_inset ERT
23281 status collapsed
23282
23283 \begin_layout Standard
23284
23285
23286 \backslash
23287 /
23288 \end_layout
23289
23290 \end_inset
23291
23292 -stack-auto
23293 \begin_inset LatexCommand index
23294 name "-\\/-stack-auto"
23295
23296 \end_inset
23297
23298  and section 
23299 \begin_inset LatexCommand ref
23300 reference "sec:Parameters-and-Local-Variables"
23301
23302 \end_inset
23303
23304  Parameters and Local Variables.
23305 \end_layout
23306
23307 \begin_layout Itemize
23308
23309 \series bold
23310 opt_code_speed
23311 \series default
23312  
23313 \begin_inset LatexCommand index
23314 name "\\#pragma opt\\_code\\_speed"
23315
23316 \end_inset
23317
23318 - The compiler will optimize code generation towards fast code, possibly
23319  at the expense of code size.
23320  Currently this has little effect.
23321 \end_layout
23322
23323 \begin_layout Itemize
23324
23325 \series bold
23326 opt_code_size
23327 \series default
23328  
23329 \begin_inset LatexCommand index
23330 name "\\#pragma opt\\_code\\_size"
23331
23332 \end_inset
23333
23334 - The compiler will optimize code generation towards compact code, possibly
23335  at the expense of code speed.
23336  Currently this has little effect.
23337 \end_layout
23338
23339 \begin_layout Itemize
23340
23341 \series bold
23342 opt_code_balanced
23343 \series default
23344  
23345 \begin_inset LatexCommand index
23346 name "\\#pragma opt\\_code\\_balanced"
23347
23348 \end_inset
23349
23350 - The compiler will attempt to generate code that is both compact and fast,
23351  as long as meeting one goal is not a detriment to the other (this is the
23352  default).
23353  
23354 \end_layout
23355
23356 \begin_layout Itemize
23357
23358 \series bold
23359 std_sdcc89
23360 \series default
23361  
23362 \begin_inset LatexCommand index
23363 name "\\#pragma std\\_sdcc89"
23364
23365 \end_inset
23366
23367 - Generally follow the C89 standard, but allow SDCC features that conflict
23368  with the standard (default).
23369 \end_layout
23370
23371 \begin_layout Itemize
23372
23373 \series bold
23374 std_c89
23375 \series default
23376  
23377 \begin_inset LatexCommand index
23378 name "\\#pragma std\\_c89"
23379
23380 \end_inset
23381
23382 - Follow the C89 standard and disable SDCC features that conflict with the
23383  standard.
23384 \end_layout
23385
23386 \begin_layout Itemize
23387
23388 \series bold
23389 std_sdcc99
23390 \series default
23391  
23392 \begin_inset LatexCommand index
23393 name "\\#pragma std\\_sdcc99"
23394
23395 \end_inset
23396
23397 - Generally follow the C99 standard, but allow SDCC features that conflict
23398  with the standard (incomplete support).
23399 \end_layout
23400
23401 \begin_layout Itemize
23402
23403 \series bold
23404 std_c99
23405 \series default
23406  
23407 \begin_inset LatexCommand index
23408 name "\\#pragma std\\_c99"
23409
23410 \end_inset
23411
23412 - Follow the C99 standard and disable SDCC features that conflict with the
23413  standard (incomplete support).
23414 \end_layout
23415
23416 \begin_layout Itemize
23417
23418 \series bold
23419 codeseg
23420 \series default
23421  <name>
23422 \begin_inset LatexCommand index
23423 name "\\#pragma codeseg"
23424
23425 \end_inset
23426
23427 - Use this name (max.
23428  8 characters) for the code segment.
23429  See option -
23430 \begin_inset ERT
23431 status collapsed
23432
23433 \begin_layout Standard
23434
23435
23436 \backslash
23437 /
23438 \end_layout
23439
23440 \end_inset
23441
23442 -codeseg.
23443 \end_layout
23444
23445 \begin_layout Itemize
23446
23447 \series bold
23448 constseg
23449 \series default
23450  <name>
23451 \begin_inset LatexCommand index
23452 name "\\#pragma constseg"
23453
23454 \end_inset
23455
23456 - Use this name (max.
23457  8 characters) for the const segment.
23458  See option -
23459 \begin_inset ERT
23460 status collapsed
23461
23462 \begin_layout Standard
23463
23464
23465 \backslash
23466 /
23467 \end_layout
23468
23469 \end_inset
23470
23471 -constseg.
23472 \end_layout
23473
23474 \begin_layout Standard
23475 The preprocessor SDCPP
23476 \begin_inset LatexCommand index
23477 name "sdcpp (preprocessor)"
23478
23479 \end_inset
23480
23481  supports the following #pragma directives:
23482 \end_layout
23483
23484 \begin_layout Itemize
23485
23486 \series bold
23487 pedantic_parse_number
23488 \series default
23489
23490 \begin_inset LatexCommand index
23491 name "pedantic"
23492
23493 \end_inset
23494
23495
23496 \begin_inset LatexCommand index
23497 name "\\#pragma pedantic\\_parse\\_number"
23498
23499 \end_inset
23500
23501  (+ | -) 
23502 \begin_inset LatexCommand label
23503 name "ite:pedantic_parse_number"
23504
23505 \end_inset
23506
23507 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
23508  properly and the macro LO_B(3) gets expanded.
23509  Default is off.
23510  See also the -
23511 \begin_inset ERT
23512 status collapsed
23513
23514 \begin_layout Standard
23515
23516
23517 \backslash
23518 /
23519 \end_layout
23520
23521 \end_inset
23522
23523 -pedantic-parse-number command line option 
23524 \begin_inset LatexCommand vpageref
23525 reference "lyx:-pedantic-parse-number"
23526
23527 \end_inset
23528
23529 .
23530  
23531 \newline
23532 Below is an example on how to use this pragma.
23533  
23534 \emph on
23535 Note: this functionality is not in conformance with standard!
23536 \end_layout
23537
23538 \begin_layout Verse
23539
23540 \family typewriter
23541 #pragma pedantic_parse_number +
23542 \begin_inset LatexCommand index
23543 name "\\#pragma pedantic\\_parse\\_number"
23544
23545 \end_inset
23546
23547
23548 \newline
23549
23550 \newline
23551 #define LO_B(x) ((x) & 0xff)
23552 \newline
23553
23554 \newline
23555 unsigned char foo(void)
23556 \newline
23557 {
23558 \newline
23559 \InsetSpace ~
23560 \InsetSpace ~
23561 \InsetSpace ~
23562 unsigned char c=0xfe-LO_B(3)
23563 ;
23564 \newline
23565
23566 \newline
23567 \InsetSpace ~
23568 \InsetSpace ~
23569 \InsetSpace ~
23570 return c;
23571 \newline
23572 }
23573 \newline
23574
23575 \end_layout
23576
23577 \begin_layout Itemize
23578
23579 \series bold
23580 preproc_asm
23581 \series default
23582
23583 \begin_inset LatexCommand index
23584 name "\\#pragma preproc\\_asm"
23585
23586 \end_inset
23587
23588  (+ | -) - switch _asm _endasm block preprocessing on / off.
23589  Default is on.
23590  You use this pragma to define multilines of assembly code.
23591  This will prevent the preprocessor from changing the formatting required
23592  by assembly code.
23593  Below is an example on how to use this pragma.
23594 \end_layout
23595
23596 \begin_layout Verse
23597
23598 \family typewriter
23599 #pragma preproc_asm -
23600 \begin_inset LatexCommand index
23601 name "\\#pragma preproc\\_asm"
23602
23603 \end_inset
23604
23605
23606 \newline
23607 #define MYDELAY _asm
23608 \newline
23609 \InsetSpace ~
23610 \InsetSpace ~
23611 \InsetSpace ~
23612 nop ;my assembly comment...
23613 \newline
23614 \InsetSpace ~
23615 \InsetSpace ~
23616 \InsetSpace ~
23617 nop
23618 \newline
23619 \InsetSpace ~
23620 \InsetSpace ~
23621 \InsetSpace ~
23622 nop
23623 \newline
23624 _endasm
23625 \newline
23626 #pragma preproc_asm
23627  +
23628 \newline
23629
23630 \newline
23631 void foo (void) 
23632 \newline
23633
23634 \newline
23635 \InsetSpace ~
23636 \InsetSpace ~
23637 \InsetSpace ~
23638  ...
23639  
23640 \newline
23641 \InsetSpace ~
23642 \InsetSpace ~
23643 \InsetSpace ~
23644  MYDELAY;
23645 \newline
23646 \InsetSpace ~
23647 \InsetSpace ~
23648 \InsetSpace ~
23649  ...
23650  
23651 \newline
23652
23653 \newline
23654
23655 \end_layout
23656
23657 \begin_layout Itemize
23658
23659 \series bold
23660 sdcc_hash
23661 \series default
23662
23663 \begin_inset LatexCommand index
23664 name "\\#pragma sdcc\\_hash"
23665
23666 \end_inset
23667
23668  (+ | -) - Allow "naked" hash in macro definition, for example:
23669 \newline
23670
23671 \family typewriter
23672 #define DIR_LO(x) #(x & 0xff)
23673 \family default
23674
23675 \newline
23676 Default is off.
23677  Below is an example on how to use this pragma.
23678 \end_layout
23679
23680 \begin_layout Verse
23681
23682 \family typewriter
23683 #pragma preproc_asm +
23684 \newline
23685 #pragma sdcc_hash +
23686 \begin_inset LatexCommand index
23687 name "\\#pragma sdcc\\_hash"
23688
23689 \end_inset
23690
23691
23692 \newline
23693
23694 \newline
23695 #define ROMCALL(x) 
23696 \backslash
23697
23698 \newline
23699 \InsetSpace ~
23700 \InsetSpace ~
23701 \InsetSpace ~
23702 mov R6_B3, #(x & 0xff) 
23703 \backslash
23704
23705 \newline
23706 \InsetSpace ~
23707 \InsetSpace ~
23708 \InsetSpace ~
23709 mov R7_B3, #((x >> 8) & 0xff) 
23710 \backslash
23711
23712 \newline
23713 \InsetSpace ~
23714 \InsetSpace ~
23715 \InsetSpace ~
23716 lcall __romcall
23717 \newline
23718
23719 \newline
23720 ...
23721 \newline
23722 _asm
23723 \newline
23724 ROMCALL(72)
23725 \newline
23726 _endasm;
23727 \newline
23728 ...
23729 \newline
23730
23731 \end_layout
23732
23733 \begin_layout Standard
23734 Some of the pragmas are intended to be used to turn-on or off certain optimizati
23735 ons which might cause the compiler to generate extra stack and/or data space
23736  to store compiler generated temporary variables.
23737  This usually happens in large functions.
23738  Pragma directives should be used as shown in the following example, they
23739  are used to control options and optimizations for a given function.
23740  
23741 \end_layout
23742
23743 \begin_layout Verse
23744
23745 \family typewriter
23746 #pragma save
23747 \begin_inset LatexCommand index
23748 name "\\#pragma save"
23749
23750 \end_inset
23751
23752  \InsetSpace ~
23753 \InsetSpace ~
23754 \InsetSpace ~
23755 \InsetSpace ~
23756 \InsetSpace ~
23757 \InsetSpace ~
23758 \InsetSpace ~
23759 /* save the current settings */ 
23760 \newline
23761 #pragma nogcse
23762 \begin_inset LatexCommand index
23763 name "\\#pragma nogcse"
23764
23765 \end_inset
23766
23767  \InsetSpace ~
23768 \InsetSpace ~
23769 \InsetSpace ~
23770 \InsetSpace ~
23771 \InsetSpace ~
23772 /* turnoff global subexpression elimination */ 
23773 \newline
23774 #pragma noinduction
23775 \begin_inset LatexCommand index
23776 name "\\#pragma noinduction"
23777
23778 \end_inset
23779
23780  /* turn off induction optimizations */ 
23781 \newline
23782 int foo () 
23783 \newline
23784
23785 \newline
23786 \InsetSpace ~
23787  \InsetSpace ~
23788  ...
23789  
23790 \newline
23791 \InsetSpace ~
23792  \InsetSpace ~
23793  /* large code */ 
23794 \newline
23795 \InsetSpace ~
23796  \InsetSpace ~
23797  ...
23798  
23799 \newline
23800
23801 \newline
23802 #pragma restore
23803 \begin_inset LatexCommand index
23804 name "\\#pragma restore"
23805
23806 \end_inset
23807
23808  /* turn the optimizations back on */
23809 \end_layout
23810
23811 \begin_layout Standard
23812 The compiler will generate a warning message when extra space is allocated.
23813  It is strongly recommended that the save and restore pragmas be used when
23814  changing options for a function.
23815 \newline
23816
23817 \newline
23818
23819 \newline
23820
23821 \end_layout
23822
23823 \begin_layout Section
23824 Defines Created by the Compiler
23825 \end_layout
23826
23827 \begin_layout Standard
23828 The compiler creates the following #defines
23829 \begin_inset LatexCommand index
23830 name "\\#defines"
23831
23832 \end_inset
23833
23834
23835 \begin_inset LatexCommand index
23836 name "Defines created by the compiler"
23837
23838 \end_inset
23839
23840 :
23841 \newline
23842
23843 \end_layout
23844
23845 \begin_layout Standard
23846 \begin_inset Tabular
23847 <lyxtabular version="3" rows="15" columns="2">
23848 <features>
23849 <column alignment="left" valignment="top" leftline="true" width="3in">
23850 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
23851 <row topline="true" bottomline="true">
23852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23853 \begin_inset Text
23854
23855 \begin_layout Standard
23856
23857 \series bold
23858 #define
23859 \end_layout
23860
23861 \end_inset
23862 </cell>
23863 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23864 \begin_inset Text
23865
23866 \begin_layout Standard
23867
23868 \series bold
23869 Description
23870 \end_layout
23871
23872 \end_inset
23873 </cell>
23874 </row>
23875 <row topline="true">
23876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23877 \begin_inset Text
23878
23879 \begin_layout Standard
23880 SDCC
23881 \begin_inset LatexCommand index
23882 name "SDCC"
23883
23884 \end_inset
23885
23886  
23887 \end_layout
23888
23889 \end_inset
23890 </cell>
23891 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23892 \begin_inset Text
23893
23894 \begin_layout Standard
23895 Always defined.
23896  Since version 2.5.6 the version number as an int (ex.
23897  256)
23898 \end_layout
23899
23900 \end_inset
23901 </cell>
23902 </row>
23903 <row topline="true">
23904 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23905 \begin_inset Text
23906
23907 \begin_layout Standard
23908 SDCC_mcs51
23909 \begin_inset LatexCommand index
23910 name "SDCC\\_mcs51"
23911
23912 \end_inset
23913
23914  or SDCC_ds390
23915 \begin_inset LatexCommand index
23916 name "SDCC\\_ds390"
23917
23918 \end_inset
23919
23920  or SDCC_z80
23921 \begin_inset LatexCommand index
23922 name "SDCC\\_z80"
23923
23924 \end_inset
23925
23926 , etc.
23927 \end_layout
23928
23929 \end_inset
23930 </cell>
23931 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23932 \begin_inset Text
23933
23934 \begin_layout Standard
23935 depending on the model used (e.g.: -mds390)
23936 \end_layout
23937
23938 \end_inset
23939 </cell>
23940 </row>
23941 <row topline="true">
23942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23943 \begin_inset Text
23944
23945 \begin_layout Standard
23946 __mcs51
23947 \begin_inset LatexCommand index
23948 name "\\_\\_mcs51"
23949
23950 \end_inset
23951
23952 , __ds390
23953 \begin_inset LatexCommand index
23954 name "\\_\\_ds390"
23955
23956 \end_inset
23957
23958 , __hc08
23959 \begin_inset LatexCommand index
23960 name "\\_\\_hc08"
23961
23962 \end_inset
23963
23964 , __z80
23965 \begin_inset LatexCommand index
23966 name "\\_\\_z80"
23967
23968 \end_inset
23969
23970 , etc
23971 \end_layout
23972
23973 \end_inset
23974 </cell>
23975 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23976 \begin_inset Text
23977
23978 \begin_layout Standard
23979 depending on the model used (e.g.
23980  -mz80)
23981 \end_layout
23982
23983 \end_inset
23984 </cell>
23985 </row>
23986 <row topline="true">
23987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23988 \begin_inset Text
23989
23990 \begin_layout Standard
23991 SDCC_STACK_AUTO
23992 \begin_inset LatexCommand index
23993 name "SDCC\\_STACK\\_AUTO"
23994
23995 \end_inset
23996
23997
23998 \end_layout
23999
24000 \end_inset
24001 </cell>
24002 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24003 \begin_inset Text
24004
24005 \begin_layout Standard
24006 when 
24007 \emph on
24008 -
24009 \begin_inset ERT
24010 status collapsed
24011
24012 \begin_layout Standard
24013
24014
24015 \backslash
24016 /
24017 \end_layout
24018
24019 \end_inset
24020
24021 -stack-auto
24022 \emph default
24023  option is used
24024 \end_layout
24025
24026 \end_inset
24027 </cell>
24028 </row>
24029 <row topline="true">
24030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24031 \begin_inset Text
24032
24033 \begin_layout Standard
24034 SDCC_MODEL_SMALL
24035 \begin_inset LatexCommand index
24036 name "SDCC\\_MODEL\\_SMALL"
24037
24038 \end_inset
24039
24040
24041 \end_layout
24042
24043 \end_inset
24044 </cell>
24045 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24046 \begin_inset Text
24047
24048 \begin_layout Standard
24049 when 
24050 \emph on
24051 -
24052 \begin_inset ERT
24053 status collapsed
24054
24055 \begin_layout Standard
24056
24057
24058 \backslash
24059 /
24060 \end_layout
24061
24062 \end_inset
24063
24064 -model-small
24065 \emph default
24066  is used
24067 \end_layout
24068
24069 \end_inset
24070 </cell>
24071 </row>
24072 <row topline="true">
24073 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24074 \begin_inset Text
24075
24076 \begin_layout Standard
24077 SDCC_MODEL_MEDIUM
24078 \begin_inset LatexCommand index
24079 name "SDCC\\_MODEL\\_MEDIUM"
24080
24081 \end_inset
24082
24083
24084 \end_layout
24085
24086 \end_inset
24087 </cell>
24088 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24089 \begin_inset Text
24090
24091 \begin_layout Standard
24092 when 
24093 \emph on
24094 -
24095 \begin_inset ERT
24096 status collapsed
24097
24098 \begin_layout Standard
24099
24100
24101 \backslash
24102 /
24103 \end_layout
24104
24105 \end_inset
24106
24107 -model-medium
24108 \emph default
24109  is used
24110 \end_layout
24111
24112 \end_inset
24113 </cell>
24114 </row>
24115 <row topline="true">
24116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24117 \begin_inset Text
24118
24119 \begin_layout Standard
24120 SDCC_MODEL_LARGE
24121 \begin_inset LatexCommand index
24122 name "SDCC\\_MODEL\\_LARGE"
24123
24124 \end_inset
24125
24126
24127 \end_layout
24128
24129 \end_inset
24130 </cell>
24131 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24132 \begin_inset Text
24133
24134 \begin_layout Standard
24135 when 
24136 \emph on
24137 -
24138 \begin_inset ERT
24139 status collapsed
24140
24141 \begin_layout Standard
24142
24143
24144 \backslash
24145 /
24146 \end_layout
24147
24148 \end_inset
24149
24150 -model-large
24151 \emph default
24152  is used
24153 \end_layout
24154
24155 \end_inset
24156 </cell>
24157 </row>
24158 <row topline="true">
24159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24160 \begin_inset Text
24161
24162 \begin_layout Standard
24163 SDCC_USE_XSTACK
24164 \begin_inset LatexCommand index
24165 name "SDCC\\_USE\\_XSTACK"
24166
24167 \end_inset
24168
24169
24170 \end_layout
24171
24172 \end_inset
24173 </cell>
24174 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24175 \begin_inset Text
24176
24177 \begin_layout Standard
24178 when 
24179 \emph on
24180 -
24181 \begin_inset ERT
24182 status collapsed
24183
24184 \begin_layout Standard
24185
24186
24187 \backslash
24188 /
24189 \end_layout
24190
24191 \end_inset
24192
24193 -xstack
24194 \emph default
24195  option is used
24196 \end_layout
24197
24198 \end_inset
24199 </cell>
24200 </row>
24201 <row topline="true">
24202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24203 \begin_inset Text
24204
24205 \begin_layout Standard
24206 SDCC_STACK_TENBIT
24207 \begin_inset LatexCommand index
24208 name "SDCC\\_STACK\\_TENBIT"
24209
24210 \end_inset
24211
24212  
24213 \end_layout
24214
24215 \end_inset
24216 </cell>
24217 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24218 \begin_inset Text
24219
24220 \begin_layout Standard
24221 when 
24222 \emph on
24223 -mds390
24224 \emph default
24225  is used
24226 \end_layout
24227
24228 \end_inset
24229 </cell>
24230 </row>
24231 <row topline="true">
24232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24233 \begin_inset Text
24234
24235 \begin_layout Standard
24236 SDCC_MODEL_FLAT24
24237 \begin_inset LatexCommand index
24238 name "SDCC\\_MODEL\\_FLAT24"
24239
24240 \end_inset
24241
24242
24243 \end_layout
24244
24245 \end_inset
24246 </cell>
24247 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24248 \begin_inset Text
24249
24250 \begin_layout Standard
24251 when 
24252 \emph on
24253 -mds390
24254 \emph default
24255  is used
24256 \end_layout
24257
24258 \end_inset
24259 </cell>
24260 </row>
24261 <row topline="true">
24262 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24263 \begin_inset Text
24264
24265 \begin_layout Standard
24266 SDCC_REVISION
24267 \begin_inset LatexCommand index
24268 name "SDCC\\_REVISION"
24269
24270 \end_inset
24271
24272
24273 \end_layout
24274
24275 \end_inset
24276 </cell>
24277 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24278 \begin_inset Text
24279
24280 \begin_layout Standard
24281 Always defined.
24282  SDCC svn revision number
24283 \end_layout
24284
24285 \end_inset
24286 </cell>
24287 </row>
24288 <row topline="true">
24289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24290 \begin_inset Text
24291
24292 \begin_layout Standard
24293 SDCC_PARMS_IN_BANK1
24294 \begin_inset LatexCommand index
24295 name "SDCC\\_PARMS\\_IN\\_BANK1"
24296
24297 \end_inset
24298
24299
24300 \end_layout
24301
24302 \end_inset
24303 </cell>
24304 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24305 \begin_inset Text
24306
24307 \begin_layout Standard
24308 when 
24309 \emph on
24310 -
24311 \begin_inset ERT
24312 status collapsed
24313
24314 \begin_layout Standard
24315
24316
24317 \backslash
24318 /
24319 \end_layout
24320
24321 \end_inset
24322
24323 -parms-in-bank1
24324 \emph default
24325  is used
24326 \end_layout
24327
24328 \end_inset
24329 </cell>
24330 </row>
24331 <row topline="true">
24332 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24333 \begin_inset Text
24334
24335 \begin_layout Standard
24336 SDCC_FLOAT_REENT
24337 \begin_inset LatexCommand index
24338 name "SDCC\\_MODEL\\_FLAT24"
24339
24340 \end_inset
24341
24342
24343 \end_layout
24344
24345 \end_inset
24346 </cell>
24347 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24348 \begin_inset Text
24349
24350 \begin_layout Standard
24351 when 
24352 \emph on
24353 -
24354 \begin_inset ERT
24355 status collapsed
24356
24357 \begin_layout Standard
24358
24359
24360 \backslash
24361 /
24362 \end_layout
24363
24364 \end_inset
24365
24366 -float-reent
24367 \emph default
24368  is used
24369 \end_layout
24370
24371 \end_inset
24372 </cell>
24373 </row>
24374 <row topline="true" bottomline="true">
24375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24376 \begin_inset Text
24377
24378 \begin_layout Standard
24379 SDCC_INT_LONG_REENT
24380 \begin_inset LatexCommand index
24381 name "SDCC\\_INT\\_LONG\\_REENT"
24382
24383 \end_inset
24384
24385
24386 \end_layout
24387
24388 \end_inset
24389 </cell>
24390 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24391 \begin_inset Text
24392
24393 \begin_layout Standard
24394 when 
24395 \emph on
24396 -
24397 \begin_inset ERT
24398 status collapsed
24399
24400 \begin_layout Standard
24401
24402
24403 \backslash
24404 /
24405 \end_layout
24406
24407 \end_inset
24408
24409 -int-long-reent
24410 \emph default
24411  is used
24412 \end_layout
24413
24414 \end_inset
24415 </cell>
24416 </row>
24417 </lyxtabular>
24418
24419 \end_inset
24420
24421
24422 \end_layout
24423
24424 \begin_layout Chapter
24425 Notes on supported Processors
24426 \end_layout
24427
24428 \begin_layout Section
24429 MCS51 variants
24430 \begin_inset LatexCommand label
24431 name "sub:MCS51-variants"
24432
24433 \end_inset
24434
24435
24436 \begin_inset LatexCommand index
24437 name "MCS51 variants"
24438
24439 \end_inset
24440
24441
24442 \end_layout
24443
24444 \begin_layout Standard
24445 MCS51 processors are available from many vendors and come in many different
24446  flavours.
24447  While they might differ considerably in respect to Special Function Registers
24448  the core MCS51 is usually not modified or is kept compatible.
24449  
24450 \end_layout
24451
24452 \begin_layout Subsection
24453 pdata access by SFR 
24454 \end_layout
24455
24456 \begin_layout Standard
24457 With the upcome of devices with internal xdata and flash memory devices
24458  using port P2
24459 \begin_inset LatexCommand index
24460 name "P2 (mcs51 sfr)"
24461
24462 \end_inset
24463
24464  as dedicated I/O port is becoming more popular.
24465  Switching the high byte for pdata
24466 \begin_inset LatexCommand index
24467 name "pdata (mcs51, ds390 storage class)"
24468
24469 \end_inset
24470
24471  access which was formerly done by port P2 is then achieved by a Special
24472  Function Register
24473 \begin_inset LatexCommand index
24474 name "sfr"
24475
24476 \end_inset
24477
24478 .
24479  In well-established MCS51 tradition the address of this 
24480 \emph on
24481 sfr
24482 \emph default
24483  is where the chip designers decided to put it.
24484  Needless to say that they didn't agree on a common name either.
24485  So that the startup code can correctly initialize xdata variables, you
24486  should define an sfr with the name _XPAGE
24487 \family typewriter
24488
24489 \begin_inset LatexCommand index
24490 name "\\_XPAGE (mcs51)"
24491
24492 \end_inset
24493
24494
24495 \family default
24496  at the appropriate location if the default, port P2, is not used for this.
24497  Some examples are:
24498 \end_layout
24499
24500 \begin_layout Verse
24501
24502 \family typewriter
24503 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
24504  MPAGE */
24505 \end_layout
24506
24507 \begin_layout Verse
24508
24509 \family typewriter
24510 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
24511  a.k.a.
24512  MPAGE */
24513 \end_layout
24514
24515 \begin_layout Verse
24516
24517 \family typewriter
24518 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
24519  XPAGE */
24520 \end_layout
24521
24522 \begin_layout Verse
24523
24524 \family typewriter
24525 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
24526  EMI0CN */
24527 \end_layout
24528
24529 \begin_layout Verse
24530
24531 \family typewriter
24532 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
24533  EMI0CN */
24534 \end_layout
24535
24536 \begin_layout Standard
24537 For more exotic implementations further customizations may be needed.
24538  See section 
24539 \begin_inset LatexCommand ref
24540 reference "sub:Startup-Code"
24541
24542 \end_inset
24543
24544  for other possibilities.
24545 \end_layout
24546
24547 \begin_layout Subsection
24548 Other Features available by SFR
24549 \end_layout
24550
24551 \begin_layout Standard
24552 Some MCS51 variants offer features like Double DPTR
24553 \begin_inset LatexCommand index
24554 name "DPTR"
24555
24556 \end_inset
24557
24558 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
24559  These are currently not used for the MCS51 port.
24560  If you absolutely need them you can fall back to inline assembly or submit
24561  a patch to SDCC.
24562 \end_layout
24563
24564 \begin_layout Subsection
24565 Bankswitching
24566 \end_layout
24567
24568 \begin_layout Standard
24569 Bankswitching
24570 \begin_inset LatexCommand index
24571 name "Bankswitching"
24572
24573 \end_inset
24574
24575  (a.k.a.
24576  code banking
24577 \begin_inset LatexCommand index
24578 name "code banking"
24579
24580 \end_inset
24581
24582 ) is a technique to increase the code space above the 64k limit of the 8051.
24583 \end_layout
24584
24585 \begin_layout Subsubsection
24586 Hardware
24587 \end_layout
24588
24589 \begin_layout Standard
24590 \begin_inset Tabular
24591 <lyxtabular version="3" rows="3" columns="4">
24592 <features>
24593 <column alignment="center" valignment="top" width="0">
24594 <column alignment="center" valignment="top" leftline="true" width="0">
24595 <column alignment="center" valignment="top" leftline="true" width="0">
24596 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24597 <row topline="true" bottomline="true">
24598 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24599 \begin_inset Text
24600
24601 \begin_layout Standard
24602 8000-FFFF
24603 \end_layout
24604
24605 \end_inset
24606 </cell>
24607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24608 \begin_inset Text
24609
24610 \begin_layout Standard
24611 bank1
24612 \end_layout
24613
24614 \end_inset
24615 </cell>
24616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24617 \begin_inset Text
24618
24619 \begin_layout Standard
24620 bank2
24621 \end_layout
24622
24623 \end_inset
24624 </cell>
24625 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24626 \begin_inset Text
24627
24628 \begin_layout Standard
24629 bank3
24630 \end_layout
24631
24632 \end_inset
24633 </cell>
24634 </row>
24635 <row topline="true" bottomline="true">
24636 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24637 \begin_inset Text
24638
24639 \begin_layout Standard
24640 0000-7FFF
24641 \end_layout
24642
24643 \end_inset
24644 </cell>
24645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24646 \begin_inset Text
24647
24648 \begin_layout Standard
24649 common
24650 \end_layout
24651
24652 \end_inset
24653 </cell>
24654 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24655 \begin_inset Text
24656
24657 \begin_layout Standard
24658
24659 \end_layout
24660
24661 \end_inset
24662 </cell>
24663 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24664 \begin_inset Text
24665
24666 \begin_layout Standard
24667
24668 \end_layout
24669
24670 \end_inset
24671 </cell>
24672 </row>
24673 <row>
24674 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24675 \begin_inset Text
24676
24677 \begin_layout Standard
24678 SiLabs C8051F120 example
24679 \end_layout
24680
24681 \end_inset
24682 </cell>
24683 <cell multicolumn="2" alignment="center" valignment="top" usebox="none">
24684 \begin_inset Text
24685
24686 \begin_layout Standard
24687
24688 \end_layout
24689
24690 \end_inset
24691 </cell>
24692 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24693 \begin_inset Text
24694
24695 \begin_layout Standard
24696
24697 \end_layout
24698
24699 \end_inset
24700 </cell>
24701 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24702 \begin_inset Text
24703
24704 \begin_layout Standard
24705
24706 \end_layout
24707
24708 \end_inset
24709 </cell>
24710 </row>
24711 </lyxtabular>
24712
24713 \end_inset
24714
24715
24716 \newline
24717
24718 \newline
24719 Usually the hardware uses some sfr (an output port or an internal sfr) to
24720  select a bank and put it in the banked area of the memory map.
24721  The selected bank usually becomes active immediately upon assignment to
24722  this sfr and when running inside a bank it will switch out this code it
24723  is currently running.
24724  Therefor you cannot jump or call directly from one bank to another and
24725  need to use a so-called trampoline in the common area.
24726  For SDCC an example trampoline is in crtbank.asm and you may need to change
24727  it to your 8051 derivative or schematic.
24728  The presented code is written for the C8051F120.
24729 \newline
24730
24731 \newline
24732 When calling a banked function
24733  SDCC will put the LSB of the functions address in register R0, the MSB
24734  in R1 and the bank in R2 and then call this trampoline 
24735 \emph on
24736 __sdcc_banked_call
24737 \emph default
24738 .
24739  The current selected bank is saved on the stack, the new bank is selected
24740  and an indirect jump is made.
24741  When the banked function returns it jumps to 
24742 \emph on
24743 __sdcc_banked_ret
24744 \emph default
24745  which restores the previous bank and returns to the caller.
24746 \end_layout
24747
24748 \begin_layout Subsubsection
24749 Software
24750 \end_layout
24751
24752 \begin_layout Standard
24753 When writing banked software using SDCC you need to use some special keywords
24754  and options.
24755  You also need to take over a bit of work from the linker.
24756 \newline
24757
24758 \newline
24759 To create a function
24760  that can be called from another bank it requires the keyword 
24761 \emph on
24762 banked
24763 \emph default
24764
24765 \begin_inset LatexCommand index
24766 name "banked"
24767
24768 \end_inset
24769
24770 .
24771  The caller must see this in the prototype of the callee and the callee
24772  needs it for a proper return.
24773  Called functions within the same bank as the caller do not need the 
24774 \emph on
24775 banked
24776 \emph default
24777  keyword nor do functions in the common area.
24778  Beware: SDCC does not know or check if functions are in the same bank.
24779  This is your responsibility!
24780 \newline
24781
24782 \newline
24783 Normally all functions you write end up in
24784  the segment CSEG.
24785  If you want a function explicitly to reside in the common area put it in
24786  segment HOME.
24787  This applies for instance to interrupt service routines as they should
24788  not be banked.
24789 \end_layout
24790
24791 \begin_layout Standard
24792 Functions that need to be in a switched bank must be put in a named segment.
24793  The name can be mostly anything up to eight characters (e.g.
24794  BANK1).
24795  To do this you either use -
24796 \begin_inset ERT
24797 status collapsed
24798
24799 \begin_layout Standard
24800
24801
24802 \backslash
24803 /
24804 \end_layout
24805
24806 \end_inset
24807
24808 -codeseg BANK1 (See 
24809 \begin_inset LatexCommand ref
24810 reference "lyx:-codeseg"
24811
24812 \end_inset
24813
24814 ) on the command line when compiling or #pragma codeseg BANK1 (See 
24815 \begin_inset LatexCommand ref
24816 reference "sec:Pragmas"
24817
24818 \end_inset
24819
24820 ) at the top of the C source file.
24821  The segment name always applies to the whole source file and generated
24822  object so functions for different banks need to be defined in different
24823  source files.
24824 \newline
24825
24826 \newline
24827 When linking your objects you need to tell the linker where
24828  to put your segments.
24829  To do this you use the following command line option to SDCC: -Wl-b BANK1=0x180
24830 00 (See 
24831 \begin_inset LatexCommand ref
24832 reference "lyx:-Wl option"
24833
24834 \end_inset
24835
24836 ).
24837  This sets the virtual start address of this segment.
24838  It sets the banknumber to 0x01 and maps the bank to 0x8000 and up.
24839  The linker will not check for overflows, again this is your responsibility.
24840 \end_layout
24841
24842 \begin_layout Standard
24843 \begin_inset VSpace bigskip
24844 \end_inset
24845
24846
24847 \end_layout
24848
24849 \begin_layout Section
24850 DS400 port
24851 \end_layout
24852
24853 \begin_layout Standard
24854 The DS80C400
24855 \begin_inset LatexCommand index
24856 name "DS80C400"
24857
24858 \end_inset
24859
24860
24861 \begin_inset LatexCommand index
24862 name "DS400"
24863
24864 \end_inset
24865
24866  microcontroller has a rich set of peripherals.
24867  In its built-in ROM library it includes functions to access some of the
24868  features, among them is a TCP stack with IP4 and IP6 support.
24869  Library headers (currently in beta status) and other files are provided
24870  at 
24871 \size footnotesize
24872
24873 \begin_inset LatexCommand url
24874 target "ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html"
24875
24876 \end_inset
24877
24878 .
24879  
24880 \begin_inset VSpace bigskip
24881 \end_inset
24882
24883
24884 \end_layout
24885
24886 \begin_layout Section
24887 The Z80 and gbz80 port
24888 \end_layout
24889
24890 \begin_layout Standard
24891 SDCC can target both the Zilog Z80
24892 \begin_inset LatexCommand index
24893 name "Z80"
24894
24895 \end_inset
24896
24897  and the Nintendo Gameboy's Z80-like gbz80
24898 \begin_inset LatexCommand index
24899 name "gbz80 (GameBoy Z80)"
24900
24901 \end_inset
24902
24903 .
24904  The Z80 port is passed through the same 
24905 \emph on
24906 regressions tests
24907 \begin_inset LatexCommand index
24908 name "Regression test"
24909
24910 \end_inset
24911
24912
24913 \emph default
24914  (see section 
24915 \begin_inset LatexCommand ref
24916 reference "sec:Quality-control"
24917
24918 \end_inset
24919
24920 ) as the MCS51 and DS390 ports, so floating point support, support for long
24921  variables and bitfield support is fine.
24922  See mailing lists and forums about interrupt routines.
24923 \end_layout
24924
24925 \begin_layout Standard
24926 As always, the code is the authoritative reference - see z80/ralloc.c and
24927  z80/gen.c.
24928  The stack
24929 \begin_inset LatexCommand index
24930 name "Z80!stack"
24931
24932 \end_inset
24933
24934  frame is similar to that generated by the IAR Z80 compiler.
24935  IX is used as the base pointer, HL and IY are used as a temporary registers,
24936  and BC and DE are available for holding variables.
24937  Return values
24938 \begin_inset LatexCommand index
24939 name "Z80!return value"
24940
24941 \end_inset
24942
24943  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
24944  bytes).
24945  The gbz80 port use the same set of registers for the return values, but
24946  in a different order of significance: E (one byte), DE (two bytes), or
24947  HLDE (four bytes).
24948 \begin_inset VSpace bigskip
24949 \end_inset
24950
24951
24952 \end_layout
24953
24954 \begin_layout Section
24955 The HC08 port
24956 \end_layout
24957
24958 \begin_layout Standard
24959 The port to the Freescale/Motorola HC08
24960 \begin_inset LatexCommand index
24961 name "HC08"
24962
24963 \end_inset
24964
24965  family has been added in October 2003, and is still undergoing some basic
24966  development.
24967  The code generator is complete, but the register allocation is still quite
24968  unoptimized.
24969  Some of the SDCC's standard C library functions have embedded non-HC08
24970  inline assembly and so are not yet usable.
24971 \end_layout
24972
24973 \begin_layout Standard
24974 The HC08 port passes the regression test suite (see section 
24975 \begin_inset LatexCommand ref
24976 reference "sec:Quality-control"
24977
24978 \end_inset
24979
24980 ).
24981 \begin_inset VSpace bigskip
24982 \end_inset
24983
24984
24985 \end_layout
24986
24987 \begin_layout Section
24988 The PIC14
24989 \begin_inset LatexCommand index
24990 name "PIC14"
24991
24992 \end_inset
24993
24994  port
24995 \end_layout
24996
24997 \begin_layout Standard
24998 The PIC14 port adds support for Microchip
24999 \begin_inset LatexCommand index
25000 name "Microchip"
25001
25002 \end_inset
25003
25004
25005 \begin_inset Formula $^{\text{TM}}$
25006 \end_inset
25007
25008  PIC
25009 \begin_inset LatexCommand index
25010 name "PIC14"
25011
25012 \end_inset
25013
25014
25015 \begin_inset Formula $^{\text{TM}}$
25016 \end_inset
25017
25018  MCUs with 14 bit wide instructions.
25019  This port is not yet mature and still lacks many features.
25020  However, it can work for simple code.
25021 \end_layout
25022
25023 \begin_layout Standard
25024 \noindent
25025 Currently supported devices include:
25026 \end_layout
25027
25028 \begin_layout Standard
25029 12F: 629, 635, 675, 683
25030 \end_layout
25031
25032 \begin_layout Standard
25033 16C: 432, 433
25034 \end_layout
25035
25036 \begin_layout Standard
25037 16C: 554, 557, 558
25038 \end_layout
25039
25040 \begin_layout Standard
25041 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
25042 \end_layout
25043
25044 \begin_layout Standard
25045 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
25046  781, 782
25047 \end_layout
25048
25049 \begin_layout Standard
25050 16C: 925, 926
25051 \end_layout
25052
25053 \begin_layout Standard
25054 16CR: 620a, 73, 74, 76, 77
25055 \end_layout
25056
25057 \begin_layout Standard
25058 16F: 616, 627, 627a, 628, 628a, 630, 636, 639, 648, 648a, 676, 684, 685,
25059  687, 688, 689, 690
25060 \end_layout
25061
25062 \begin_layout Standard
25063 16F: 716, 72, 73, 737, 74, 747, 76, 767, 77, 777, 785
25064 \end_layout
25065
25066 \begin_layout Standard
25067 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
25068  877, 877a, 88, 886, 887
25069 \end_layout
25070
25071 \begin_layout Standard
25072 16F: 913, 914, 916, 917, 946
25073 \end_layout
25074
25075 \begin_layout Standard
25076 26HV: 626, 785
25077 \end_layout
25078
25079 \begin_layout Standard
25080 \noindent
25081 An up-to-date list of currently supported devices can be obtained via 
25082 \family typewriter
25083 sdcc -mpic14 -phelp foo.c
25084 \family default
25085  (foo.c must exist...).
25086 \end_layout
25087
25088 \begin_layout Subsection
25089 PIC Code Pages
25090 \begin_inset LatexCommand index
25091 name "code page (pic14)"
25092
25093 \end_inset
25094
25095  and Memory Banks
25096 \begin_inset LatexCommand index
25097 name "Memory bank (pic14)"
25098
25099 \end_inset
25100
25101
25102 \end_layout
25103
25104 \begin_layout Standard
25105 The linker organizes allocation for the code page and RAM banks.
25106  It does not have intimate knowledge of the code flow.
25107  It will put all the code section of a single .asm file into a single code
25108  page.
25109  In order to make use of multiple code pages, separate asm files must be
25110  used.
25111  The compiler assigns all 
25112 \emph on
25113 static
25114 \emph default
25115  functions of a single .c file into the same code page.
25116 \newline
25117
25118 \newline
25119 To get the best results,
25120  follow these guidelines:
25121 \end_layout
25122
25123 \begin_layout Enumerate
25124 Make local functions static, as non static functions require code page selection
25125  overhead.
25126 \newline
25127 Due to the way sdcc handles functions, place called functions prior
25128  to calling functions in the file wherever possible: Otherwise sdcc will
25129  insert unnecessary pagesel directives around the call, believing that the
25130  called function is externally defined.
25131 \end_layout
25132
25133 \begin_layout Enumerate
25134 For devices that have multiple code pages it is more efficient to use the
25135  same number of files as pages: Use up to 4 separate .c files for the 16F877,
25136  but only 2 files for the 16F874.
25137  This way the linker can put the code for each file into different code
25138  pages and there will be less page selection overhead.
25139 \end_layout
25140
25141 \begin_layout Enumerate
25142 And as for any 8 bit micro (especially for PIC14 as they have a very simple
25143  instruction set), use `unsigned char' wherever possible instead of `int'.
25144 \end_layout
25145
25146 \begin_layout Subsection
25147 Adding New Devices to the Port 
25148 \end_layout
25149
25150 \begin_layout Standard
25151 Adding support for a new 14
25152 \begin_inset ERT
25153 status open
25154
25155 \begin_layout Standard
25156
25157
25158 \backslash
25159 ,
25160 \end_layout
25161
25162 \end_inset
25163
25164 bit PIC MCU requires the following steps:
25165 \end_layout
25166
25167 \begin_layout Enumerate
25168 Create a new device description.
25169 \newline
25170 Each device is described in two files: pic16f*.h
25171  and pic16f*.c.
25172  These files primarily define SFRs, structs to access their bits, and symbolic
25173  configuration options.
25174  Both files can be generated from gputils' .inc files using the perl script
25175  
25176 \family typewriter
25177 support/scripts/inc2h.pl
25178 \family default
25179 .
25180  This file also contains further instructions on how to proceed.
25181 \end_layout
25182
25183 \begin_layout Enumerate
25184 Copy the .h file into SDCC's include path and either add the .c file to your
25185  project or copy it to 
25186 \family typewriter
25187 device/lib/pic/libdev
25188 \family default
25189 .
25190  Afterwards, rebuild and install the libraries.
25191 \end_layout
25192
25193 \begin_layout Enumerate
25194 Edit pic14devices.txt in SDCC's include path (
25195 \family typewriter
25196 device/include/pic/
25197 \family default
25198  in the source tree or 
25199 \family typewriter
25200 /usr/local/share/sdcc/include/pic
25201 \family default
25202  after installation).
25203 \newline
25204 You need to add a device specification here to make
25205  the memory layout (code banks, RAM, aliased memory regions, ...) known to
25206  the compiler.
25207  Probably you can copy and modify an existing entry.
25208  The file format is documented at the top of the file.
25209 \end_layout
25210
25211 \begin_layout Subsection
25212 Interrupt Code
25213 \end_layout
25214
25215 \begin_layout Standard
25216 For the interrupt function, use the keyword `__interrupt'
25217 \begin_inset LatexCommand index
25218 name "PIC14!interrupt"
25219
25220 \end_inset
25221
25222  with level number of 0 (PIC14 only has 1 interrupt so this number is only
25223  there to avoid a syntax error - it ought to be fixed).
25224  E.g.:
25225 \end_layout
25226
25227 \begin_layout Verse
25228
25229 \family typewriter
25230 void Intr(void) __interrupt 0
25231 \newline
25232 {
25233 \newline
25234 \InsetSpace ~
25235 \InsetSpace ~
25236 T0IF = 0; /* Clear timer interrupt */
25237 \newline
25238 }
25239 \end_layout
25240
25241 \begin_layout Subsection
25242 Linking and Assembling
25243 \end_layout
25244
25245 \begin_layout Standard
25246 For assembling you can use either GPUTILS'
25247 \begin_inset LatexCommand index
25248 name "gputils (pic tools)"
25249
25250 \end_inset
25251
25252  gpasm.exe or MPLAB's mpasmwin.exe.
25253  GPUTILS are available from 
25254 \begin_inset LatexCommand url
25255 target "http://sourceforge.net/projects/gputils"
25256
25257 \end_inset
25258
25259 .
25260  For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
25261  If you use MPLAB and an interrupt function then the linker script file
25262  vectors section will need to be enlarged to link with mplink.
25263 \newline
25264
25265 \newline
25266 Here is a 
25267 \family typewriter
25268 Makefile
25269 \family default
25270  using GPUTILS:
25271 \end_layout
25272
25273 \begin_layout Verse
25274
25275 \family typewriter
25276 .c.o:
25277 \newline
25278 \InsetSpace ~
25279 \InsetSpace ~
25280 \InsetSpace ~
25281 \InsetSpace ~
25282 \InsetSpace ~
25283 \InsetSpace ~
25284 \InsetSpace ~
25285 \InsetSpace ~
25286 sdcc -V -mpic14 -p16f877 -c $< 
25287 \newline
25288
25289 \newline
25290 $(PRJ).hex: $(OBJS) 
25291 \newline
25292 \InsetSpace ~
25293 \InsetSpace ~
25294 \InsetSpace ~
25295 \InsetSpace ~
25296 \InsetSpace ~
25297 \InsetSpace ~
25298 \InsetSpace ~
25299 \InsetSpace ~
25300 gplink -m -s $(PRJ).lkr
25301  -o $(PRJ).hex $(OBJS) libsdcc.lib
25302 \end_layout
25303
25304 \begin_layout Standard
25305 Here is a 
25306 \family typewriter
25307 Makefile
25308 \family default
25309  using MPLAB:
25310 \end_layout
25311
25312 \begin_layout Verse
25313
25314 \family typewriter
25315 .c.o: 
25316 \newline
25317 \InsetSpace ~
25318 \InsetSpace ~
25319 \InsetSpace ~
25320 \InsetSpace ~
25321 \InsetSpace ~
25322 \InsetSpace ~
25323 \InsetSpace ~
25324 \InsetSpace ~
25325 sdcc -S -V -mpic14 -p16f877 $< 
25326 \newline
25327 \InsetSpace ~
25328 \InsetSpace ~
25329 \InsetSpace ~
25330 \InsetSpace ~
25331 \InsetSpace ~
25332 \InsetSpace ~
25333 \InsetSpace ~
25334 \InsetSpace ~
25335 mpasmwin /q /o $*.asm
25336 \newline
25337
25338 \newline
25339 $(PRJ).hex: $(OBJS)
25340  
25341 \newline
25342 \InsetSpace ~
25343 \InsetSpace ~
25344 \InsetSpace ~
25345 \InsetSpace ~
25346 \InsetSpace ~
25347 \InsetSpace ~
25348 \InsetSpace ~
25349 \InsetSpace ~
25350 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
25351 \end_layout
25352
25353 \begin_layout Standard
25354 Please note that indentations within a 
25355 \family typewriter
25356 Makefile
25357 \family default
25358  have to be done with a tabulator character.
25359 \end_layout
25360
25361 \begin_layout Subsection
25362 Command-Line Options
25363 \end_layout
25364
25365 \begin_layout Standard
25366 Besides the switches common to all SDCC backends, the PIC14 port accepts
25367  the following options (for an updated list see sdcc -
25368 \begin_inset ERT
25369 status collapsed
25370
25371 \begin_layout Standard
25372
25373
25374 \backslash
25375 /
25376 \end_layout
25377
25378 \end_inset
25379
25380 -help):
25381 \end_layout
25382
25383 \begin_layout Description
25384 -
25385 \begin_inset ERT
25386 status collapsed
25387
25388 \begin_layout Standard
25389
25390
25391 \backslash
25392 /
25393 \end_layout
25394
25395 \end_inset
25396
25397 -debug-xtra
25398 \begin_inset LatexCommand index
25399 name "PIC14!Options!-\\/-debug-extra"
25400
25401 \end_inset
25402
25403  emit debug info in assembly output
25404 \end_layout
25405
25406 \begin_layout Description
25407 -
25408 \begin_inset ERT
25409 status collapsed
25410
25411 \begin_layout Standard
25412
25413
25414 \backslash
25415 /
25416 \end_layout
25417
25418 \end_inset
25419
25420 -no-pcode-opt
25421 \begin_inset LatexCommand index
25422 name "PIC14!Options!-\\/-no-pcode-opt"
25423
25424 \end_inset
25425
25426  disable (slightly faulty) optimization on pCode
25427 \end_layout
25428
25429 \begin_layout Description
25430 -
25431 \begin_inset ERT
25432 status collapsed
25433
25434 \begin_layout Standard
25435
25436
25437 \backslash
25438 /
25439 \end_layout
25440
25441 \end_inset
25442
25443 -stack-loc
25444 \begin_inset LatexCommand index
25445 name "PIC14!Options!-\\/-stack-loc"
25446
25447 \end_inset
25448
25449  sets the lowest address of the argument passing stack (defaults to a suitably
25450  large shared databank to reduce BANKSEL overhead)
25451 \end_layout
25452
25453 \begin_layout Description
25454 -
25455 \begin_inset ERT
25456 status collapsed
25457
25458 \begin_layout Standard
25459
25460
25461 \backslash
25462 /
25463 \end_layout
25464
25465 \end_inset
25466
25467 -stack-size
25468 \begin_inset LatexCommand index
25469 name "PIC14!Options!-\\/-stack-size"
25470
25471 \end_inset
25472
25473  sets the size if the argument passing stack (default: 16, minimum: 4)
25474 \end_layout
25475
25476 \begin_layout Subsection
25477 Environment Variables
25478 \end_layout
25479
25480 \begin_layout Standard
25481 The PIC14 port recognizes the following environment variables:
25482 \end_layout
25483
25484 \begin_layout Description
25485 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
25486  register (the ones called r0xNNNN) in a section of its own.
25487  By default (if this variable is unset), sdcc tries to cluster registers
25488  in sections in order to reduce the BANKSEL overhead when accessing them.
25489 \end_layout
25490
25491 \begin_layout Subsection
25492 The Library
25493 \end_layout
25494
25495 \begin_layout Standard
25496 The PIC14 library currently only contains support routines required by the
25497  compiler to implement multiplication, division, and floating point support.
25498  No libc-like replacement is available at the moment, though many of the
25499  common sdcc library sources (in 
25500 \family typewriter
25501 device/lib
25502 \family default
25503 ) should also compile with the PIC14 port.
25504 \end_layout
25505
25506 \begin_layout Subsubsection
25507 error: missing definition for symbol ``__gptrget1''
25508 \end_layout
25509
25510 \begin_layout Standard
25511 The PIC14 port uses library routines to provide more complex operations
25512  like multiplication, division/modulus and (generic) pointer dereferencing.
25513  In order to add these routines to your project, you must link with PIC14's
25514  
25515 \family typewriter
25516 libsdcc.lib
25517 \family default
25518 .
25519  For single source file projects this is done automatically, more complex
25520  projects must add 
25521 \family typewriter
25522 libsdcc.lib
25523 \family default
25524  to the linker's arguments.
25525  Make sure you also add an include path for the library (using the -I switch
25526  to the linker)!
25527 \end_layout
25528
25529 \begin_layout Subsubsection
25530 Processor mismatch in file ``XXX''.
25531 \end_layout
25532
25533 \begin_layout Standard
25534 This warning can usually be ignored due to the very good compatibility amongst
25535  14
25536 \begin_inset ERT
25537 status open
25538
25539 \begin_layout Standard
25540
25541
25542 \backslash
25543 ,
25544 \end_layout
25545
25546 \end_inset
25547
25548 bit PIC
25549 \begin_inset LatexCommand index
25550 name "PIC14"
25551
25552 \end_inset
25553
25554  devices.
25555 \end_layout
25556
25557 \begin_layout Standard
25558 You might also consider recompiling the library for your specific device
25559  by changing the ARCH=p16f877 (default target) entry in 
25560 \family typewriter
25561 device/lib/pic/Makefile.in
25562 \family default
25563  and 
25564 \family typewriter
25565 device/lib/pic/Makefile
25566 \family default
25567  to reflect your device.
25568  This might even improve performance for smaller devices as unnecessary
25569  BANKSELs might be removed.
25570 \end_layout
25571
25572 \begin_layout Subsection
25573 Known Bugs
25574 \end_layout
25575
25576 \begin_layout Subsubsection
25577 Function arguments
25578 \end_layout
25579
25580 \begin_layout Standard
25581 Functions with variable argument lists (like printf) are not yet supported.
25582  Similarly, taking the address of the first argument passed into a function
25583  does not work: It is currently passed in WREG and has no address...
25584 \end_layout
25585
25586 \begin_layout Subsubsection
25587 Regression tests fail
25588 \end_layout
25589
25590 \begin_layout Standard
25591 Though the small subset of regression tests in src/regression passes, SDCC
25592  regression test suite does not, indicating that there are still major bugs
25593  in the port.
25594  However, many smaller projects have successfully used SDCC in the past...
25595 \end_layout
25596
25597 \begin_layout Standard
25598
25599 \size footnotesize
25600
25601 \newpage
25602
25603 \end_layout
25604
25605 \begin_layout Section
25606 The PIC16
25607 \begin_inset LatexCommand index
25608 name "PIC16"
25609
25610 \end_inset
25611
25612  port
25613 \end_layout
25614
25615 \begin_layout Standard
25616 The PIC16 port adds support for Microchip
25617 \begin_inset LatexCommand index
25618 name "Microchip"
25619
25620 \end_inset
25621
25622
25623 \begin_inset Formula $^{\text{TM}}$
25624 \end_inset
25625
25626  PIC
25627 \begin_inset LatexCommand index
25628 name "PIC"
25629
25630 \end_inset
25631
25632
25633 \begin_inset Formula $^{\text{TM}}$
25634 \end_inset
25635
25636  MCUs with 16 bit wide instructions.
25637  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
25638 ; devices supported by the port include:
25639 \end_layout
25640
25641 \begin_layout Standard
25642 18F: 242, 248, 252, 258, 442, 448, 452, 458
25643 \end_layout
25644
25645 \begin_layout Standard
25646 18F: 1220, 1320
25647 \end_layout
25648
25649 \begin_layout Standard
25650 18F: 2220, 2221, 2320, 2321, 2331, 2410, 2420, 2423, 2431, 2450, 2455, 2480,
25651  24j10
25652 \end_layout
25653
25654 \begin_layout Standard
25655 18F: (2510,) 2515, 2520, 2523, 2525, 2550, 2580, 2585, 25j10, 2610, 2620,
25656  2680, 2682, 2685
25657 \end_layout
25658
25659 \begin_layout Standard
25660 18F: 4220, 4221, 4320, 4321, 4331, 4410, 4420, 4423, 4431, 4450, 4455, 4480,
25661  44j10
25662 \end_layout
25663
25664 \begin_layout Standard
25665 18F: 4510, 4515, 4520, 4523, 4525, 4550, 4580, 4585, 45j10, 4610, 4620,
25666  4680, 4682, 4685
25667 \end_layout
25668
25669 \begin_layout Standard
25670 18F: 6520, 6585, 6620, 6680, 66j60, 66j65, 6720, 67j60
25671 \end_layout
25672
25673 \begin_layout Standard
25674 18F: 8520, 8585, 8620, 8680, 86j60, 86j65, 8720, 87j60
25675 \end_layout
25676
25677 \begin_layout Standard
25678 18F: 96j60, 96j65, 97j60
25679 \end_layout
25680
25681 \begin_layout Standard
25682 \noindent
25683 An up-to-date list of supported devices is also available via '
25684 \family typewriter
25685 sdcc -mpic16 -plist
25686 \family default
25687 '.
25688 \end_layout
25689
25690 \begin_layout Subsection
25691 Global Options
25692 \end_layout
25693
25694 \begin_layout Standard
25695 PIC16 port supports the standard command line arguments as supposed, with
25696  the exception of certain cases that will be mentioned in the following
25697  list:
25698 \end_layout
25699
25700 \begin_layout Description
25701 -
25702 \begin_inset ERT
25703 status collapsed
25704
25705 \begin_layout Standard
25706
25707
25708 \backslash
25709 /
25710 \end_layout
25711
25712 \end_inset
25713
25714 -callee-saves
25715 \begin_inset LatexCommand index
25716 name "PIC16!Options!-\\/-callee-saves"
25717
25718 \end_inset
25719
25720  See -
25721 \begin_inset ERT
25722 status collapsed
25723
25724 \begin_layout Standard
25725
25726
25727 \backslash
25728 /
25729 \end_layout
25730
25731 \end_inset
25732
25733 -all-callee-saves
25734 \end_layout
25735
25736 \begin_layout Description
25737 -
25738 \begin_inset ERT
25739 status collapsed
25740
25741 \begin_layout Standard
25742
25743
25744 \backslash
25745 /
25746 \end_layout
25747
25748 \end_inset
25749
25750 -fommit-frame-pointer
25751 \begin_inset LatexCommand index
25752 name "PIC16!Options!-\\/-fommit-frame-pointer"
25753
25754 \end_inset
25755
25756  Frame pointer will be omitted when the function uses no local variables.
25757 \end_layout
25758
25759 \begin_layout Subsection
25760 Port Specific Options
25761 \begin_inset LatexCommand index
25762 name "Options PIC16"
25763
25764 \end_inset
25765
25766
25767 \end_layout
25768
25769 \begin_layout Standard
25770 The port specific options appear after the global options in the sdcc -
25771 \begin_inset ERT
25772 status collapsed
25773
25774 \begin_layout Standard
25775
25776
25777 \backslash
25778 /
25779 \end_layout
25780
25781 \end_inset
25782
25783 -help output.
25784 \end_layout
25785
25786 \begin_layout Subsubsection
25787 Code Generation Options
25788 \end_layout
25789
25790 \begin_layout Standard
25791 These options influence the generated assembler code.
25792 \end_layout
25793
25794 \begin_layout Description
25795 -
25796 \begin_inset ERT
25797 status collapsed
25798
25799 \begin_layout Standard
25800
25801
25802 \backslash
25803 /
25804 \end_layout
25805
25806 \end_inset
25807
25808 -pstack-model=[model] Used in conjunction with the command above.
25809  Defines the stack model to be used, valid stack models are:
25810 \end_layout
25811
25812 \begin_deeper
25813 \begin_layout List
25814 \labelwidthstring 00.00.0000
25815
25816 \emph on
25817 small
25818 \emph default
25819  Selects small stack model.
25820  8 bit stack and frame pointers.
25821  Supports 256 bytes stack size.
25822 \end_layout
25823
25824 \begin_layout List
25825 \labelwidthstring 00.00.0000
25826
25827 \emph on
25828 large
25829 \emph default
25830  Selects large stack model.
25831  16 bit stack and frame pointers.
25832  Supports 65536 bytes stack size.
25833 \end_layout
25834
25835 \end_deeper
25836 \begin_layout Description
25837 -
25838 \begin_inset ERT
25839 status collapsed
25840
25841 \begin_layout Standard
25842
25843
25844 \backslash
25845 /
25846 \end_layout
25847
25848 \end_inset
25849
25850 -pno-banksel Do not generate BANKSEL assembler directives.
25851 \end_layout
25852
25853 \begin_layout Description
25854 -
25855 \begin_inset ERT
25856 status collapsed
25857
25858 \begin_layout Standard
25859
25860
25861 \backslash
25862 /
25863 \end_layout
25864
25865 \end_inset
25866
25867 -extended Enable extended instruction set/literal offset addressing mode.
25868  Use with care!
25869 \end_layout
25870
25871 \begin_layout Subsubsection
25872 Optimization Options
25873 \end_layout
25874
25875 \begin_layout Description
25876 -
25877 \begin_inset ERT
25878 status collapsed
25879
25880 \begin_layout Standard
25881
25882
25883 \backslash
25884 /
25885 \end_layout
25886
25887 \end_inset
25888
25889 -obanksel=n Set optimization level for inserting BANKSELs.
25890 \newline
25891
25892 \end_layout
25893
25894 \begin_deeper
25895 \begin_layout List
25896 \labelwidthstring 00.00.0000
25897 0 no optimization
25898 \end_layout
25899
25900 \begin_layout List
25901 \labelwidthstring 00.00.0000
25902 1 checks previous used register and if it is the same then does not emit
25903  BANKSEL, accounts only for labels.
25904 \end_layout
25905
25906 \begin_layout List
25907 \labelwidthstring 00.00.0000
25908 2 tries to check the location of (even different) symbols and removes BANKSELs
25909  if they are in the same bank.
25910  
25911 \newline
25912
25913 \emph on
25914 Important: There might be problems if the linker script has data sections
25915  across bank borders!
25916 \end_layout
25917
25918 \end_deeper
25919 \begin_layout Description
25920 -
25921 \begin_inset ERT
25922 status collapsed
25923
25924 \begin_layout Standard
25925
25926
25927 \backslash
25928 /
25929 \end_layout
25930
25931 \end_inset
25932
25933 -denable-peeps Force the usage of peepholes.
25934  Use with care.
25935 \end_layout
25936
25937 \begin_layout Description
25938 -
25939 \begin_inset ERT
25940 status collapsed
25941
25942 \begin_layout Standard
25943
25944
25945 \backslash
25946 /
25947 \end_layout
25948
25949 \end_inset
25950
25951 -no-optimize-goto Do not use (conditional) BRA instead of GOTO.
25952 \end_layout
25953
25954 \begin_layout Description
25955 -
25956 \begin_inset ERT
25957 status collapsed
25958
25959 \begin_layout Standard
25960
25961
25962 \backslash
25963 /
25964 \end_layout
25965
25966 \end_inset
25967
25968 -optimize-cmp Try to optimize some compares.
25969 \end_layout
25970
25971 \begin_layout Description
25972 -
25973 \begin_inset ERT
25974 status collapsed
25975
25976 \begin_layout Standard
25977
25978
25979 \backslash
25980 /
25981 \end_layout
25982
25983 \end_inset
25984
25985 -optimize-df Analyze the dataflow of the generated code and improve it.
25986 \end_layout
25987
25988 \begin_layout Subsubsection
25989 Assembling Options
25990 \end_layout
25991
25992 \begin_layout Description
25993 -
25994 \begin_inset ERT
25995 status collapsed
25996
25997 \begin_layout Standard
25998
25999
26000 \backslash
26001 /
26002 \end_layout
26003
26004 \end_inset
26005
26006 -asm= Sets the full path and name of an external assembler to call.
26007 \end_layout
26008
26009 \begin_layout Description
26010 -
26011 \begin_inset ERT
26012 status collapsed
26013
26014 \begin_layout Standard
26015
26016
26017 \backslash
26018 /
26019 \end_layout
26020
26021 \end_inset
26022
26023 -mplab-comp MPLAB
26024 \begin_inset LatexCommand index
26025 name "PIC16!MPLAB"
26026
26027 \end_inset
26028
26029  compatibility option.
26030  Currently only suppresses special gpasm directives.
26031 \end_layout
26032
26033 \begin_layout Subsubsection
26034 Linking Options
26035 \end_layout
26036
26037 \begin_layout Description
26038 -
26039 \begin_inset ERT
26040 status collapsed
26041
26042 \begin_layout Standard
26043
26044
26045 \backslash
26046 /
26047 \end_layout
26048
26049 \end_inset
26050
26051 -link= Sets the full path and name of an external linker to call.
26052 \end_layout
26053
26054 \begin_layout Description
26055 -
26056 \begin_inset ERT
26057 status collapsed
26058
26059 \begin_layout Standard
26060
26061
26062 \backslash
26063 /
26064 \end_layout
26065
26066 \end_inset
26067
26068 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
26069  unitialized data variables with [kword].
26070  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
26071 \end_layout
26072
26073 \begin_layout Description
26074 -
26075 \begin_inset ERT
26076 status collapsed
26077
26078 \begin_layout Standard
26079
26080
26081 \backslash
26082 /
26083 \end_layout
26084
26085 \end_inset
26086
26087 -ivt-loc=n Place the interrupt vector table at address 
26088 \emph on
26089 n
26090 \emph default
26091 .
26092  Useful for bootloaders.
26093 \end_layout
26094
26095 \begin_layout Description
26096 -
26097 \begin_inset ERT
26098 status collapsed
26099
26100 \begin_layout Standard
26101
26102
26103 \backslash
26104 /
26105 \end_layout
26106
26107 \end_inset
26108
26109 -nodefaultlibs Do not link default libraries when linking.
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 -use-crt= Use a custom run-time module instead of the defaults.
26127 \end_layout
26128
26129 \begin_layout Description
26130 -
26131 \begin_inset ERT
26132 status collapsed
26133
26134 \begin_layout Standard
26135
26136
26137 \backslash
26138 /
26139 \end_layout
26140
26141 \end_inset
26142
26143 -no-crt Don't link the default run-time modules
26144 \end_layout
26145
26146 \begin_layout Subsubsection
26147 Debugging Options
26148 \end_layout
26149
26150 \begin_layout Standard
26151 Debugging options enable extra debugging information in the output files.
26152 \end_layout
26153
26154 \begin_layout Description
26155 -
26156 \begin_inset ERT
26157 status collapsed
26158
26159 \begin_layout Standard
26160
26161
26162 \backslash
26163 /
26164 \end_layout
26165
26166 \end_inset
26167
26168 -debug-xtra Similar to -
26169 \begin_inset ERT
26170 status collapsed
26171
26172 \begin_layout Standard
26173
26174
26175 \backslash
26176 /
26177 \end_layout
26178
26179 \end_inset
26180
26181 -debug
26182 \begin_inset LatexCommand index
26183 name "-\\/-debug"
26184
26185 \end_inset
26186
26187 , but dumps more information.
26188 \end_layout
26189
26190 \begin_layout Description
26191 -
26192 \begin_inset ERT
26193 status collapsed
26194
26195 \begin_layout Standard
26196
26197
26198 \backslash
26199 /
26200 \end_layout
26201
26202 \end_inset
26203
26204 -debug-ralloc Force register allocator to dump <source>.d file with debugging
26205  information.
26206  <source> is the name of the file being compiled.
26207 \end_layout
26208
26209 \begin_layout Description
26210 -
26211 \begin_inset ERT
26212 status collapsed
26213
26214 \begin_layout Standard
26215
26216
26217 \backslash
26218 /
26219 \end_layout
26220
26221 \end_inset
26222
26223 -pcode-verbose Enable pcode debugging information in translation.
26224 \end_layout
26225
26226 \begin_layout Description
26227 -
26228 \begin_inset ERT
26229 status collapsed
26230
26231 \begin_layout Standard
26232
26233
26234 \backslash
26235 /
26236 \end_layout
26237
26238 \end_inset
26239
26240 -calltree Dump call tree in .calltree file.
26241 \end_layout
26242
26243 \begin_layout Description
26244 -
26245 \begin_inset ERT
26246 status collapsed
26247
26248 \begin_layout Standard
26249
26250
26251 \backslash
26252 /
26253 \end_layout
26254
26255 \end_inset
26256
26257 -gstack Trace push/pops for stack pointer overflow.
26258 \end_layout
26259
26260 \begin_layout Subsection
26261 Environment Variables
26262 \end_layout
26263
26264 \begin_layout Standard
26265 There is a number of environmental variables that can be used when running
26266  SDCC to enable certain optimizations or force a specific program behaviour.
26267  these variables are primarily for debugging purposes so they can be enabled/dis
26268 abled at will.
26269 \end_layout
26270
26271 \begin_layout Standard
26272 Currently there is only two such variables available:
26273 \end_layout
26274
26275 \begin_layout Description
26276 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
26277  bitfields is optimized by directly loading FSR0 with the address of the
26278  bitfield structure.
26279  Normally SDCC will cast the bitfield structure to a bitfield pointer and
26280  then load FSR0.
26281  This step saves data ram and code space for functions that make heavy use
26282  of bitfields.
26283  (i.e., 80 bytes of code space are saved when compiling malloc.c with this
26284  option).
26285  
26286 \end_layout
26287
26288 \begin_layout Description
26289 NO_REG_OPT Do not perform pCode registers optimization.
26290  This should be used for debugging purposes.
26291  If bugs in the pcode optimizer are found, users can benefit from temporarily
26292  disabling the optimizer until the bug is fixed.
26293 \end_layout
26294
26295 \begin_layout Subsection
26296 Preprocessor Macros
26297 \end_layout
26298
26299 \begin_layout Standard
26300 PIC16
26301 \begin_inset LatexCommand index
26302 name "PIC16"
26303
26304 \end_inset
26305
26306  port defines the following preprocessor macros while translating a source.
26307 \end_layout
26308
26309 \begin_layout Standard
26310 \align center
26311 \begin_inset Tabular
26312 <lyxtabular version="3" rows="6" columns="2">
26313 <features>
26314 <column alignment="center" valignment="top" leftline="true" width="0">
26315 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26316 <row topline="true" bottomline="true">
26317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26318 \begin_inset Text
26319
26320 \begin_layout Standard
26321 Macro
26322 \end_layout
26323
26324 \end_inset
26325 </cell>
26326 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26327 \begin_inset Text
26328
26329 \begin_layout Standard
26330 Description
26331 \end_layout
26332
26333 \end_inset
26334 </cell>
26335 </row>
26336 <row topline="true">
26337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26338 \begin_inset Text
26339
26340 \begin_layout Standard
26341 SDCC_pic16
26342 \end_layout
26343
26344 \end_inset
26345 </cell>
26346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26347 \begin_inset Text
26348
26349 \begin_layout Standard
26350 Port identification
26351 \end_layout
26352
26353 \end_inset
26354 </cell>
26355 </row>
26356 <row topline="true">
26357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26358 \begin_inset Text
26359
26360 \begin_layout Standard
26361 _
26362 \begin_inset ERT
26363 status collapsed
26364
26365 \begin_layout Standard
26366
26367
26368 \backslash
26369 /
26370 \end_layout
26371
26372 \end_inset
26373
26374 _pic16
26375 \end_layout
26376
26377 \end_inset
26378 </cell>
26379 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26380 \begin_inset Text
26381
26382 \begin_layout Standard
26383 Port identification (same as above)
26384 \end_layout
26385
26386 \end_inset
26387 </cell>
26388 </row>
26389 <row topline="true">
26390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26391 \begin_inset Text
26392
26393 \begin_layout Standard
26394 pic18fxxxx
26395 \end_layout
26396
26397 \end_inset
26398 </cell>
26399 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26400 \begin_inset Text
26401
26402 \begin_layout Standard
26403 MCU Identification.
26404  
26405 \emph on
26406 xxxx
26407 \emph default
26408  is the microcontrol identification number, i.e.
26409  452, 6620, etc
26410 \end_layout
26411
26412 \end_inset
26413 </cell>
26414 </row>
26415 <row topline="true">
26416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26417 \begin_inset Text
26418
26419 \begin_layout Standard
26420 _
26421 \begin_inset ERT
26422 status collapsed
26423
26424 \begin_layout Standard
26425
26426
26427 \backslash
26428 /
26429 \end_layout
26430
26431 \end_inset
26432
26433 _18Fxxxx
26434 \end_layout
26435
26436 \end_inset
26437 </cell>
26438 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26439 \begin_inset Text
26440
26441 \begin_layout Standard
26442 MCU Identification (same as above)
26443 \end_layout
26444
26445 \end_inset
26446 </cell>
26447 </row>
26448 <row topline="true" bottomline="true">
26449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26450 \begin_inset Text
26451
26452 \begin_layout Standard
26453 STACK_MODEL_nnn
26454 \end_layout
26455
26456 \end_inset
26457 </cell>
26458 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26459 \begin_inset Text
26460
26461 \begin_layout Standard
26462 nnn = SMALL or LARGE respectively according to the stack model used
26463 \end_layout
26464
26465 \end_inset
26466 </cell>
26467 </row>
26468 </lyxtabular>
26469
26470 \end_inset
26471
26472
26473 \end_layout
26474
26475 \begin_layout Standard
26476 \noindent
26477 In addition the following macros are defined when calling assembler:
26478 \end_layout
26479
26480 \begin_layout Standard
26481 \align center
26482 \begin_inset Tabular
26483 <lyxtabular version="3" rows="4" columns="2">
26484 <features>
26485 <column alignment="center" valignment="top" leftline="true" width="0">
26486 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26487 <row topline="true" bottomline="true">
26488 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26489 \begin_inset Text
26490
26491 \begin_layout Standard
26492 Macro
26493 \end_layout
26494
26495 \end_inset
26496 </cell>
26497 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26498 \begin_inset Text
26499
26500 \begin_layout Standard
26501 Description
26502 \end_layout
26503
26504 \end_inset
26505 </cell>
26506 </row>
26507 <row topline="true">
26508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26509 \begin_inset Text
26510
26511 \begin_layout Standard
26512 __18Fxxxx
26513 \end_layout
26514
26515 \end_inset
26516 </cell>
26517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26518 \begin_inset Text
26519
26520 \begin_layout Standard
26521 MCU Identification.
26522  
26523 \emph on
26524 xxxx
26525 \emph default
26526  is the microcontrol identification number, i.e.
26527  452, 6620, etc
26528 \end_layout
26529
26530 \end_inset
26531 </cell>
26532 </row>
26533 <row topline="true">
26534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26535 \begin_inset Text
26536
26537 \begin_layout Standard
26538 SDCC_MODEL_nnn
26539 \end_layout
26540
26541 \end_inset
26542 </cell>
26543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26544 \begin_inset Text
26545
26546 \begin_layout Standard
26547 nnn = SMALL or LARGE respectively according to the memory model used for
26548  SDCC
26549 \end_layout
26550
26551 \end_inset
26552 </cell>
26553 </row>
26554 <row topline="true" bottomline="true">
26555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26556 \begin_inset Text
26557
26558 \begin_layout Standard
26559 STACK_MODEL_nnn
26560 \end_layout
26561
26562 \end_inset
26563 </cell>
26564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26565 \begin_inset Text
26566
26567 \begin_layout Standard
26568 nnn = SMALL or LARGE respectively according to the stack model used
26569 \end_layout
26570
26571 \end_inset
26572 </cell>
26573 </row>
26574 </lyxtabular>
26575
26576 \end_inset
26577
26578
26579 \end_layout
26580
26581 \begin_layout Subsection
26582 Directories
26583 \end_layout
26584
26585 \begin_layout Standard
26586 PIC16
26587 \begin_inset LatexCommand index
26588 name "PIC16"
26589
26590 \end_inset
26591
26592  port uses the following directories for searching header files and libraries.
26593 \end_layout
26594
26595 \begin_layout Standard
26596 \align center
26597 \begin_inset Tabular
26598 <lyxtabular version="3" rows="3" columns="4">
26599 <features>
26600 <column alignment="center" valignment="top" leftline="true" width="0">
26601 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26602 <column alignment="center" valignment="top" width="0">
26603 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26604 <row topline="true" bottomline="true">
26605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26606 \begin_inset Text
26607
26608 \begin_layout Standard
26609 Directory
26610 \end_layout
26611
26612 \end_inset
26613 </cell>
26614 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26615 \begin_inset Text
26616
26617 \begin_layout Standard
26618 Description
26619 \end_layout
26620
26621 \end_inset
26622 </cell>
26623 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26624 \begin_inset Text
26625
26626 \begin_layout Standard
26627 Target
26628 \end_layout
26629
26630 \end_inset
26631 </cell>
26632 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26633 \begin_inset Text
26634
26635 \begin_layout Standard
26636 Command prefix
26637 \end_layout
26638
26639 \end_inset
26640 </cell>
26641 </row>
26642 <row topline="true">
26643 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26644 \begin_inset Text
26645
26646 \begin_layout Standard
26647 PREFIX/sdcc/include/pic16
26648 \end_layout
26649
26650 \end_inset
26651 </cell>
26652 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26653 \begin_inset Text
26654
26655 \begin_layout Standard
26656 PIC16 specific headers
26657 \end_layout
26658
26659 \end_inset
26660 </cell>
26661 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26662 \begin_inset Text
26663
26664 \begin_layout Standard
26665 Compiler
26666 \end_layout
26667
26668 \end_inset
26669 </cell>
26670 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26671 \begin_inset Text
26672
26673 \begin_layout Standard
26674 -I
26675 \end_layout
26676
26677 \end_inset
26678 </cell>
26679 </row>
26680 <row topline="true" bottomline="true">
26681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26682 \begin_inset Text
26683
26684 \begin_layout Standard
26685 PREFIX/sdcc/lib/pic16
26686 \end_layout
26687
26688 \end_inset
26689 </cell>
26690 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26691 \begin_inset Text
26692
26693 \begin_layout Standard
26694 PIC16 specific libraries
26695 \end_layout
26696
26697 \end_inset
26698 </cell>
26699 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26700 \begin_inset Text
26701
26702 \begin_layout Standard
26703 Linker
26704 \end_layout
26705
26706 \end_inset
26707 </cell>
26708 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26709 \begin_inset Text
26710
26711 \begin_layout Standard
26712 -L
26713 \end_layout
26714
26715 \end_inset
26716 </cell>
26717 </row>
26718 </lyxtabular>
26719
26720 \end_inset
26721
26722
26723 \end_layout
26724
26725 \begin_layout Subsection
26726 Pragmas
26727 \begin_inset LatexCommand label
26728 name "sub:PIC16_Pragmas"
26729
26730 \end_inset
26731
26732
26733 \end_layout
26734
26735 \begin_layout Standard
26736 The PIC16
26737 \begin_inset LatexCommand index
26738 name "PIC16"
26739
26740 \end_inset
26741
26742  port currently supports the following pragmas:
26743 \end_layout
26744
26745 \begin_layout Description
26746 stack
26747 \begin_inset LatexCommand index
26748 name "PIC16!Pragmas!\\#pragma stack"
26749
26750 \end_inset
26751
26752  This forces the code generator to initialize the stack & frame pointers
26753  at a specific address.
26754  This is an ad hoc solution for cases where no STACK directive is available
26755  in the linker script or gplink is not instructed to create a stack section.
26756 \newline
26757 The
26758  stack pragma should be used only once in a project.
26759  Multiple pragmas may result in indeterminate behaviour of the program.
26760 \begin_inset Foot
26761 status open
26762
26763 \begin_layout Standard
26764 The old format (ie.
26765  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
26766  cross page boundaries (or even exceed the available data RAM) and crash
26767  the program.
26768  Make sure that stack does not cross page boundaries when using the SMALL
26769  stack model.
26770 \end_layout
26771
26772 \end_inset
26773
26774
26775 \newline
26776 The format is as follows:
26777 \newline
26778
26779 \end_layout
26780
26781 \begin_layout LyX-Code
26782 #pragma stack bottom_address [stack_size]
26783 \newline
26784
26785 \end_layout
26786
26787 \begin_layout Standard
26788
26789 \emph on
26790 bottom_address
26791 \emph default
26792  is the lower bound of the stack section.
26793  The stack pointer initially will point at address (bottom_address+stack_size-1).
26794 \end_layout
26795
26796 \begin_layout LyX-Code
26797 Example:
26798 \end_layout
26799
26800 \begin_layout LyX-Code
26801
26802 \end_layout
26803
26804 \begin_layout LyX-Code
26805 /* initializes stack of 100 bytes at RAM address 0x200 */
26806 \end_layout
26807
26808 \begin_layout LyX-Code
26809 #pragma stack 0x200 100
26810 \end_layout
26811
26812 \begin_layout Standard
26813 If the stack_size field is omitted then a stack is created with the default
26814  size of 64.
26815  This size might be enough for most programs, but its not enough for operations
26816  with deep function nesting or excessive stack usage.
26817 \end_layout
26818
26819 \begin_layout Description
26820 code
26821 \begin_inset LatexCommand index
26822 name "PIC16!Pragmas!\\#pragma code"
26823
26824 \end_inset
26825
26826  Force a function to a static FLASH address.
26827 \end_layout
26828
26829 \begin_layout LyX-Code
26830 Example:
26831 \end_layout
26832
26833 \begin_layout LyX-Code
26834
26835 \end_layout
26836
26837 \begin_layout LyX-Code
26838 /* place function test_func at 0x4000 */
26839 \end_layout
26840
26841 \begin_layout LyX-Code
26842 #pragma code test_func 0x4000
26843 \end_layout
26844
26845 \begin_layout LyX-Code
26846
26847 \end_layout
26848
26849 \begin_layout Description
26850 library instructs the linker to use a library module.
26851 \newline
26852 Usage:
26853 \end_layout
26854
26855 \begin_layout LyX-Code
26856 #pragma library module_name
26857 \end_layout
26858
26859 \begin_layout Standard
26860
26861 \emph on
26862 module_name
26863 \emph default
26864  can be any library or object file (including its path).
26865  Note that there are four reserved keywords which have special meaning.
26866  These are:
26867 \end_layout
26868
26869 \begin_layout Standard
26870 \align center
26871 \begin_inset Tabular
26872 <lyxtabular version="3" rows="6" columns="3">
26873 <features>
26874 <column alignment="center" valignment="top" leftline="true" width="0">
26875 <column alignment="block" valignment="top" leftline="true" width="20page%">
26876 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
26877 <row topline="true" bottomline="true">
26878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26879 \begin_inset Text
26880
26881 \begin_layout Standard
26882 Keyword
26883 \end_layout
26884
26885 \end_inset
26886 </cell>
26887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26888 \begin_inset Text
26889
26890 \begin_layout Standard
26891 Description
26892 \end_layout
26893
26894 \end_inset
26895 </cell>
26896 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26897 \begin_inset Text
26898
26899 \begin_layout Standard
26900 Module to link
26901 \end_layout
26902
26903 \end_inset
26904 </cell>
26905 </row>
26906 <row topline="true">
26907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26908 \begin_inset Text
26909
26910 \begin_layout Standard
26911
26912 \series bold
26913 ignore
26914 \end_layout
26915
26916 \end_inset
26917 </cell>
26918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26919 \begin_inset Text
26920
26921 \begin_layout Standard
26922 ignore all library pragmas
26923 \end_layout
26924
26925 \end_inset
26926 </cell>
26927 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26928 \begin_inset Text
26929
26930 \begin_layout Standard
26931
26932 \emph on
26933 (none)
26934 \end_layout
26935
26936 \end_inset
26937 </cell>
26938 </row>
26939 <row topline="true">
26940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26941 \begin_inset Text
26942
26943 \begin_layout Standard
26944
26945 \series bold
26946 c
26947 \end_layout
26948
26949 \end_inset
26950 </cell>
26951 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26952 \begin_inset Text
26953
26954 \begin_layout Standard
26955 link the C library
26956 \end_layout
26957
26958 \end_inset
26959 </cell>
26960 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26961 \begin_inset Text
26962
26963 \begin_layout Standard
26964
26965 \emph on
26966 libc18f
26967 \emph default
26968 .lib
26969 \end_layout
26970
26971 \end_inset
26972 </cell>
26973 </row>
26974 <row topline="true">
26975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26976 \begin_inset Text
26977
26978 \begin_layout Standard
26979
26980 \series bold
26981 math
26982 \end_layout
26983
26984 \end_inset
26985 </cell>
26986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26987 \begin_inset Text
26988
26989 \begin_layout Standard
26990 link the Math libarary
26991 \end_layout
26992
26993 \end_inset
26994 </cell>
26995 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26996 \begin_inset Text
26997
26998 \begin_layout Standard
26999
27000 \emph on
27001 libm18f
27002 \emph default
27003 .lib
27004 \end_layout
27005
27006 \end_inset
27007 </cell>
27008 </row>
27009 <row topline="true">
27010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27011 \begin_inset Text
27012
27013 \begin_layout Standard
27014
27015 \series bold
27016 io
27017 \end_layout
27018
27019 \end_inset
27020 </cell>
27021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27022 \begin_inset Text
27023
27024 \begin_layout Standard
27025 link the I/O library
27026 \end_layout
27027
27028 \end_inset
27029 </cell>
27030 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27031 \begin_inset Text
27032
27033 \begin_layout Standard
27034
27035 \emph on
27036 libio18f*
27037 \emph default
27038 .lib
27039 \end_layout
27040
27041 \end_inset
27042 </cell>
27043 </row>
27044 <row topline="true" bottomline="true">
27045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27046 \begin_inset Text
27047
27048 \begin_layout Standard
27049
27050 \series bold
27051 debug
27052 \end_layout
27053
27054 \end_inset
27055 </cell>
27056 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27057 \begin_inset Text
27058
27059 \begin_layout Standard
27060 link the debug library
27061 \end_layout
27062
27063 \end_inset
27064 </cell>
27065 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27066 \begin_inset Text
27067
27068 \begin_layout Standard
27069
27070 \emph on
27071 libdebug
27072 \emph default
27073 .lib
27074 \end_layout
27075
27076 \end_inset
27077 </cell>
27078 </row>
27079 </lyxtabular>
27080
27081 \end_inset
27082
27083
27084 \newline
27085 * is the device number, i.e.
27086  452 for PIC18F452 MCU.
27087 \end_layout
27088
27089 \begin_layout Standard
27090 \noindent
27091 This feature allows for linking with specific libraries without having to
27092  explicit name them in the command line.
27093  Note that the 
27094 \noun on
27095 ignore
27096 \noun default
27097  keyword will reject all modules specified by the library pragma.
27098 \end_layout
27099
27100 \begin_layout Description
27101 udata The pragma udata instructs the compiler to emit code so that linker
27102  will place a variable at a specific memory bank.
27103 \end_layout
27104
27105 \begin_layout LyX-Code
27106 Example:
27107 \end_layout
27108
27109 \begin_layout LyX-Code
27110
27111 \end_layout
27112
27113 \begin_layout LyX-Code
27114 /* places variable foo at bank2 */
27115 \end_layout
27116
27117 \begin_layout LyX-Code
27118 #pragma udata bank2 foo
27119 \end_layout
27120
27121 \begin_layout LyX-Code
27122 char foo;
27123 \end_layout
27124
27125 \begin_layout Standard
27126 In order for this pragma to work extra SECTION directives should be added
27127  in the .lkr script.
27128  In the following example a sample .lkr file is shown:
27129 \end_layout
27130
27131 \begin_layout LyX-Code
27132
27133 \end_layout
27134
27135 \begin_layout LyX-Code
27136 // Sample linker script for the PIC18F452 processor
27137 \end_layout
27138
27139 \begin_layout LyX-Code
27140 LIBPATH .
27141 \end_layout
27142
27143 \begin_layout LyX-Code
27144 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
27145 \end_layout
27146
27147 \begin_layout LyX-Code
27148 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
27149 \end_layout
27150
27151 \begin_layout LyX-Code
27152 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
27153 \end_layout
27154
27155 \begin_layout LyX-Code
27156 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
27157 \end_layout
27158
27159 \begin_layout LyX-Code
27160 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
27161 \end_layout
27162
27163 \begin_layout LyX-Code
27164 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
27165 \end_layout
27166
27167 \begin_layout LyX-Code
27168 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
27169 \end_layout
27170
27171 \begin_layout LyX-Code
27172
27173 \end_layout
27174
27175 \begin_layout LyX-Code
27176 DATABANK   NAME=gpr0       START=0x80           END=0xFF
27177 \end_layout
27178
27179 \begin_layout LyX-Code
27180 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
27181 \end_layout
27182
27183 \begin_layout LyX-Code
27184 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
27185 \end_layout
27186
27187 \begin_layout LyX-Code
27188 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
27189 \end_layout
27190
27191 \begin_layout LyX-Code
27192 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
27193 \end_layout
27194
27195 \begin_layout LyX-Code
27196 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
27197 \end_layout
27198
27199 \begin_layout LyX-Code
27200 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
27201 \end_layout
27202
27203 \begin_layout LyX-Code
27204
27205 \end_layout
27206
27207 \begin_layout LyX-Code
27208 SECTION    NAME=CONFIG     ROM=config
27209 \end_layout
27210
27211 \begin_layout LyX-Code
27212
27213 \end_layout
27214
27215 \begin_layout LyX-Code
27216 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
27217 \end_layout
27218
27219 \begin_layout LyX-Code
27220 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
27221 \end_layout
27222
27223 \begin_layout LyX-Code
27224 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
27225 \end_layout
27226
27227 \begin_layout LyX-Code
27228 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
27229 \end_layout
27230
27231 \begin_layout LyX-Code
27232 SECTION    NAME=bank4      RAM=gpr4
27233 \end_layout
27234
27235 \begin_layout LyX-Code
27236 SECTION    NAME=bank5      RAM=gpr5
27237 \end_layout
27238
27239 \begin_layout Standard
27240 The linker will recognise the section name set in the pragma statement and
27241  will position the variable at the memory bank set with the RAM field at
27242  the SECTION line in the linker script file.
27243 \end_layout
27244
27245 \begin_layout Subsection
27246 Header Files
27247 \begin_inset LatexCommand label
27248 name "sub:PIC16_Header-Files"
27249
27250 \end_inset
27251
27252
27253 \end_layout
27254
27255 \begin_layout Standard
27256 There is one main header file
27257 \begin_inset LatexCommand index
27258 name "PIC16!Header files"
27259
27260 \end_inset
27261
27262  that can be included to the source files using the pic16
27263 \begin_inset LatexCommand index
27264 name "PIC16"
27265
27266 \end_inset
27267
27268  port.
27269  That file is the 
27270 \series bold
27271 pic18fregs.h
27272 \series default
27273 .
27274  This header file contains the definitions for the processor special registers,
27275  so it is necessary if the source accesses them.
27276  It can be included by adding the following line in the beginning of the
27277  file:
27278 \end_layout
27279
27280 \begin_layout LyX-Code
27281 #include <pic18fregs.h>
27282 \end_layout
27283
27284 \begin_layout Standard
27285 The specific microcontroller is selected within the pic18fregs.h automatically,
27286  so the same source can be used with a variety of devices.
27287 \end_layout
27288
27289 \begin_layout Subsection
27290 Libraries
27291 \begin_inset LatexCommand label
27292 name "sub:pic16Libraries"
27293
27294 \end_inset
27295
27296
27297 \end_layout
27298
27299 \begin_layout Standard
27300 The libraries
27301 \begin_inset LatexCommand index
27302 name "PIC16!Libraries"
27303
27304 \end_inset
27305
27306  that PIC16
27307 \begin_inset LatexCommand index
27308 name "PIC16"
27309
27310 \end_inset
27311
27312  port depends on are the microcontroller device libraries which contain
27313  the symbol definitions for the microcontroller special function registers.
27314  These libraries have the format pic18fxxxx.lib, where 
27315 \emph on
27316 xxxx
27317 \emph default
27318  is the microcontroller identification number.
27319  The specific library is selected automatically by the compiler at link
27320  stage according to the selected device.
27321 \end_layout
27322
27323 \begin_layout Standard
27324 \noindent
27325 Libraries are created with gplib which is part of the gputils package 
27326 \begin_inset LatexCommand url
27327 target "http://sourceforge.net/projects/gputils"
27328
27329 \end_inset
27330
27331 .
27332 \end_layout
27333
27334 \begin_layout Subsubsection*
27335 Building the libraries
27336 \end_layout
27337
27338 \begin_layout Standard
27339 Before using SDCC/pic16 there are some libraries that need to be compiled.
27340  This process is done automatically if gputils are found at SDCC's compile
27341  time.
27342  Should you require to rebuild the pic16 libraries manually (e.g.
27343  in order to enable output of float values
27344 \begin_inset LatexCommand index
27345 name "Floating point support"
27346
27347 \end_inset
27348
27349  via 
27350 \family typewriter
27351 printf()
27352 \family default
27353 , see below), these are the steps required to do so under Linux or Mac OS
27354  X (cygwin might work as well, but is untested):
27355 \end_layout
27356
27357 \begin_layout LyX-Code
27358 cd device/lib/pic16
27359 \end_layout
27360
27361 \begin_layout LyX-Code
27362 ./configure.gnu
27363 \end_layout
27364
27365 \begin_layout LyX-Code
27366 cd ..
27367 \end_layout
27368
27369 \begin_layout LyX-Code
27370 make model-pic16
27371 \end_layout
27372
27373 \begin_layout LyX-Code
27374 su -c 'make install'     # install the libraries, you need the root password
27375 \end_layout
27376
27377 \begin_layout LyX-Code
27378 cd ../..
27379 \end_layout
27380
27381 \begin_layout Standard
27382 If you need to install the headers too, do:
27383 \end_layout
27384
27385 \begin_layout LyX-Code
27386 cd device/include
27387 \end_layout
27388
27389 \begin_layout LyX-Code
27390 su -c 'make install'     # install the headers, you need the root password
27391 \end_layout
27392
27393 \begin_layout Subsubsection*
27394 Output of float values via printf()
27395 \end_layout
27396
27397 \begin_layout Standard
27398 The library is normally built without support for displaying float values,
27399  only <NO FLOAT> will appear instead of the value.
27400  To change this, rebuild the library as stated above, but call 
27401 \family typewriter
27402 ./configure.gnu --enable-floats 
27403 \family default
27404 instead of just 
27405 \family typewriter
27406 ./configure.gnu
27407 \family default
27408 .
27409  Also make sure that at least 
27410 \family typewriter
27411 libc/stdio/vfprintf.c
27412 \family default
27413  is actually recompiled, e.g.
27414  by 
27415 \family typewriter
27416 touch
27417 \family default
27418 ing it after the 
27419 \family typewriter
27420 configure
27421 \family default
27422  run or deleting its 
27423 \family typewriter
27424 .o
27425 \family default
27426  file.
27427 \end_layout
27428
27429 \begin_layout Standard
27430 The more common appraoch of compiling 
27431 \family typewriter
27432 vfprintf.c
27433 \family default
27434  manually with 
27435 \family typewriter
27436 -DUSE_FLOATS=1
27437 \family default
27438  should also work, but is untested.
27439 \end_layout
27440
27441 \begin_layout Subsection
27442 Adding New Devices to the Port
27443 \end_layout
27444
27445 \begin_layout Standard
27446 Adding support for a new 16
27447 \begin_inset ERT
27448 status collapsed
27449
27450 \begin_layout Standard
27451
27452
27453 \backslash
27454 ,
27455 \end_layout
27456
27457 \end_inset
27458
27459 bit PIC MCU requires the following steps:
27460 \end_layout
27461
27462 \begin_layout Enumerate
27463 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
27464 \newline
27465
27466 \family typewriter
27467 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
27468 inc
27469 \end_layout
27470
27471 \begin_layout Enumerate
27472
27473 \family typewriter
27474 mv picDEVICE.h /path/to/sdcc/device/include/pic16
27475 \end_layout
27476
27477 \begin_layout Enumerate
27478
27479 \family typewriter
27480 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
27481 \end_layout
27482
27483 \begin_layout Enumerate
27484 Add DEVICE to 
27485 \family typewriter
27486 /path/to/sdcc/device/lib/pic16/pics.all
27487 \family default
27488
27489 \newline
27490 Note: No 18f prefix here!
27491 \end_layout
27492
27493 \begin_layout Enumerate
27494 Edit 
27495 \family typewriter
27496 /path/to/sdcc/device/include/pic16/adc.h
27497 \newline
27498
27499 \family default
27500 Add the new devices to the correct ADC style class (depending on the number
27501  of ADC channels).
27502 \newline
27503 Do not touch 
27504 \family typewriter
27505 adc.h
27506 \family default
27507  if the device does not offer any ADC at all.
27508 \end_layout
27509
27510 \begin_layout Enumerate
27511 Edit 
27512 \family typewriter
27513 /path/to/sdcc/device/include/pic16/pic18fregs.h
27514 \family default
27515
27516 \newline
27517 The file format is self-explanatory, just add
27518 \newline
27519
27520 \family typewriter
27521 #elif defined(picDEVICE)
27522 \newline
27523 #
27524 \begin_inset ERT
27525 status collapsed
27526
27527 \begin_layout Standard
27528
27529
27530 \backslash
27531  
27532 \backslash
27533  
27534 \end_layout
27535
27536 \end_inset
27537
27538 include <picDEVICE.h>
27539 \family default
27540
27541 \newline
27542 at the right place (keep the file sorted, please).
27543 \end_layout
27544
27545 \begin_layout Enumerate
27546 Edit 
27547 \family typewriter
27548 /path/to/sdcc/device/include/pic16devices.txt
27549 \newline
27550
27551 \family default
27552 Copy and modify an existing entry or create a new one and insert it at the
27553  correct place (keep the file sorted, please).
27554 \end_layout
27555
27556 \begin_layout Enumerate
27557 Add the device to 
27558 \family typewriter
27559 /path/to/sdcc/device/lib/pic16/libdev/Makefile.am
27560 \family default
27561
27562 \newline
27563 Copy an existing entry and adjust the device name.
27564 \end_layout
27565
27566 \begin_layout Enumerate
27567 Add the device to 
27568 \family typewriter
27569 /path/to/sdcc/device/lib/pic16/libio/Makefile.am
27570 \family default
27571
27572 \newline
27573 Copy the record from the 18f2220 and adjust the device name.
27574 \newline
27575 If the new device
27576  does not offer ADC, I
27577 \begin_inset Formula $^{\text{2}}$
27578 \end_inset
27579
27580 C, and/or (E)USART functionality as assumed by the library, remove the lines
27581  with references to 
27582 \family typewriter
27583 adc/*.c
27584 \family default
27585
27586 \family typewriter
27587 usart/*.c
27588 \family default
27589 , or 
27590 \family typewriter
27591 usart/*.c
27592 \family default
27593 , respectively.
27594 \end_layout
27595
27596 \begin_layout Enumerate
27597 Update 
27598 \family typewriter
27599 libdev/Makefile.in
27600 \family default
27601  and 
27602 \family typewriter
27603 libio/Makefile.in
27604 \family default
27605  using
27606 \newline
27607
27608 \family typewriter
27609 ./bootstrap.sh
27610 \family default
27611
27612 \newline
27613 in 
27614 \family typewriter
27615 /path/to/sdcc/device/lib/pic16
27616 \family default
27617 .
27618 \end_layout
27619
27620 \begin_layout Enumerate
27621 Recompile the pic16 libraries as described in 
27622 \begin_inset LatexCommand ref
27623 reference "sub:pic16Libraries"
27624
27625 \end_inset
27626
27627 .
27628 \end_layout
27629
27630 \begin_layout Subsection
27631 Memory Models
27632 \end_layout
27633
27634 \begin_layout Standard
27635 The following memory models are supported by the PIC16 port:
27636 \end_layout
27637
27638 \begin_layout Itemize
27639 small model
27640 \end_layout
27641
27642 \begin_layout Itemize
27643 large model
27644 \end_layout
27645
27646 \begin_layout Standard
27647 Memory model affects the default size of pointers within the source.
27648  The sizes are shown in the next table:
27649 \end_layout
27650
27651 \begin_layout Standard
27652 \align center
27653 \begin_inset Tabular
27654 <lyxtabular version="3" rows="3" columns="3">
27655 <features>
27656 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27657 <column alignment="center" valignment="top" leftline="true" width="0">
27658 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27659 <row topline="true" bottomline="true">
27660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27661 \begin_inset Text
27662
27663 \begin_layout Standard
27664 Pointer sizes according to memory model
27665 \end_layout
27666
27667 \end_inset
27668 </cell>
27669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27670 \begin_inset Text
27671
27672 \begin_layout Standard
27673 small model
27674 \end_layout
27675
27676 \end_inset
27677 </cell>
27678 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27679 \begin_inset Text
27680
27681 \begin_layout Standard
27682 large model
27683 \end_layout
27684
27685 \end_inset
27686 </cell>
27687 </row>
27688 <row topline="true" bottomline="true">
27689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27690 \begin_inset Text
27691
27692 \begin_layout Standard
27693 code pointers
27694 \end_layout
27695
27696 \end_inset
27697 </cell>
27698 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27699 \begin_inset Text
27700
27701 \begin_layout Standard
27702 16-bits
27703 \end_layout
27704
27705 \end_inset
27706 </cell>
27707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27708 \begin_inset Text
27709
27710 \begin_layout Standard
27711 24-bits
27712 \end_layout
27713
27714 \end_inset
27715 </cell>
27716 </row>
27717 <row topline="true" bottomline="true">
27718 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27719 \begin_inset Text
27720
27721 \begin_layout Standard
27722 data pointers
27723 \end_layout
27724
27725 \end_inset
27726 </cell>
27727 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
27728 \begin_inset Text
27729
27730 \begin_layout Standard
27731 16-bits
27732 \end_layout
27733
27734 \end_inset
27735 </cell>
27736 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27737 \begin_inset Text
27738
27739 \begin_layout Standard
27740 16-bits
27741 \end_layout
27742
27743 \end_inset
27744 </cell>
27745 </row>
27746 </lyxtabular>
27747
27748 \end_inset
27749
27750
27751 \end_layout
27752
27753 \begin_layout Standard
27754 It is advisable that all sources within a project are compiled with the
27755  same memory model.
27756  If one wants to override the default memory model, this can be done by
27757  declaring a pointer as 
27758 \series bold
27759 far
27760 \series default
27761  or 
27762 \series bold
27763 near
27764 \series default
27765 .
27766  Far selects large memory model's pointers, while near selects small memory
27767  model's pointers.
27768 \end_layout
27769
27770 \begin_layout Standard
27771 The standard device libraries (see 
27772 \begin_inset LatexCommand ref
27773 reference "sub:PIC16_Header-Files"
27774
27775 \end_inset
27776
27777 ) contain no reference to pointers, so they can be used with both memory
27778  models.
27779 \end_layout
27780
27781 \begin_layout Subsection
27782 Stack
27783 \end_layout
27784
27785 \begin_layout Standard
27786 The stack
27787 \begin_inset LatexCommand index
27788 name "PIC16!stack"
27789
27790 \end_inset
27791
27792  implementation for the PIC16 port uses two indirect registers, FSR1 and
27793  FSR2.
27794 \end_layout
27795
27796 \begin_layout Description
27797 FSR1 is assigned as stack pointer
27798 \end_layout
27799
27800 \begin_layout Description
27801 FSR2 is assigned as frame pointer
27802 \end_layout
27803
27804 \begin_layout Standard
27805 The following stack models are supported by the PIC16 port
27806 \end_layout
27807
27808 \begin_layout Itemize
27809
27810 \noun on
27811 small
27812 \noun default
27813  model
27814 \end_layout
27815
27816 \begin_layout Itemize
27817
27818 \noun on
27819 large
27820 \noun default
27821  model
27822 \end_layout
27823
27824 \begin_layout Standard
27825
27826 \noun on
27827 Small
27828 \noun default
27829  model means that only the FSRxL byte is used to access stack and frame,
27830  while 
27831 \emph on
27832 \noun on
27833 large
27834 \emph default
27835 \noun default
27836  uses both FSRxL and FSRxH registers.
27837  The following table shows the stack/frame pointers sizes according to stack
27838  model and the maximum space they can address:
27839 \end_layout
27840
27841 \begin_layout Standard
27842 \align center
27843 \begin_inset Tabular
27844 <lyxtabular version="3" rows="3" columns="3">
27845 <features>
27846 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27847 <column alignment="center" valignment="top" leftline="true" width="0">
27848 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27849 <row topline="true" bottomline="true">
27850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27851 \begin_inset Text
27852
27853 \begin_layout Standard
27854 Stack & Frame pointer sizes according to stack model
27855 \end_layout
27856
27857 \end_inset
27858 </cell>
27859 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27860 \begin_inset Text
27861
27862 \begin_layout Standard
27863 small
27864 \end_layout
27865
27866 \end_inset
27867 </cell>
27868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27869 \begin_inset Text
27870
27871 \begin_layout Standard
27872 large
27873 \end_layout
27874
27875 \end_inset
27876 </cell>
27877 </row>
27878 <row topline="true">
27879 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27880 \begin_inset Text
27881
27882 \begin_layout Standard
27883 Stack pointer FSR1
27884 \end_layout
27885
27886 \end_inset
27887 </cell>
27888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27889 \begin_inset Text
27890
27891 \begin_layout Standard
27892 8-bits
27893 \end_layout
27894
27895 \end_inset
27896 </cell>
27897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27898 \begin_inset Text
27899
27900 \begin_layout Standard
27901 16-bits
27902 \end_layout
27903
27904 \end_inset
27905 </cell>
27906 </row>
27907 <row topline="true" bottomline="true">
27908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27909 \begin_inset Text
27910
27911 \begin_layout Standard
27912 Frame pointer FSR2
27913 \end_layout
27914
27915 \end_inset
27916 </cell>
27917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27918 \begin_inset Text
27919
27920 \begin_layout Standard
27921 8-bits
27922 \end_layout
27923
27924 \end_inset
27925 </cell>
27926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27927 \begin_inset Text
27928
27929 \begin_layout Standard
27930 16-bits
27931 \end_layout
27932
27933 \end_inset
27934 </cell>
27935 </row>
27936 </lyxtabular>
27937
27938 \end_inset
27939
27940
27941 \end_layout
27942
27943 \begin_layout Standard
27944 \noindent
27945
27946 \noun on
27947 Large 
27948 \noun default
27949 stack model is currently not working properly throughout the code generator.
27950  So its use is not advised.
27951  Also there are some other points that need special care:
27952 \newline
27953
27954 \end_layout
27955
27956 \begin_layout Enumerate
27957 Do not create stack sections with size more than one physical bank (that
27958  is 256 bytes)
27959 \end_layout
27960
27961 \begin_layout Enumerate
27962 Stack sections should no cross physical bank limits (i.e.
27963  #pragma stack 0x50 0x100)
27964 \end_layout
27965
27966 \begin_layout Standard
27967 These limitations are caused by the fact that only FSRxL is modified when
27968  using SMALL stack model, so no more than 256 bytes of stack can be used.
27969  This problem will disappear after LARGE model is fully implemented.
27970 \end_layout
27971
27972 \begin_layout Subsection
27973 Functions
27974 \end_layout
27975
27976 \begin_layout Standard
27977 In addition to the standard SDCC function keywords, PIC16
27978 \begin_inset LatexCommand index
27979 name "PIC16"
27980
27981 \end_inset
27982
27983  port makes available two more:
27984 \end_layout
27985
27986 \begin_layout Description
27987 wparam
27988 \begin_inset LatexCommand index
27989 name "PIC16!wparam"
27990
27991 \end_inset
27992
27993  Use the WREG to pass one byte of the first function argument.
27994  This improves speed but you may not use this for functions with arguments
27995  that are called via function pointers, otherwise the first byte of the
27996  first parameter will get lost.
27997  Usage:
27998 \end_layout
27999
28000 \begin_layout LyX-Code
28001 void func_wparam(int a) wparam
28002 \end_layout
28003
28004 \begin_layout LyX-Code
28005 {
28006 \end_layout
28007
28008 \begin_layout LyX-Code
28009     /* WREG hold the lower part of a */
28010 \end_layout
28011
28012 \begin_layout LyX-Code
28013     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
28014  */
28015 \end_layout
28016
28017 \begin_layout LyX-Code
28018 ...
28019 \end_layout
28020
28021 \begin_layout LyX-Code
28022 }
28023 \end_layout
28024
28025 \begin_layout Description
28026 shadowregs
28027 \begin_inset LatexCommand index
28028 name "PIC16!shadowregs"
28029
28030 \end_inset
28031
28032  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
28033  hardware shadow registers which hold the values of WREG, STATUS and BSR
28034  registers.
28035  This can be done by adding the keyword 
28036 \emph on
28037 shadowregs
28038 \emph default
28039  before the 
28040 \emph on
28041 interrupt
28042 \emph default
28043  keyword in the function's header.
28044 \end_layout
28045
28046 \begin_layout LyX-Code
28047 void isr_shadow(void) shadowregs interrupt 1
28048 \end_layout
28049
28050 \begin_layout LyX-Code
28051 {
28052 \end_layout
28053
28054 \begin_layout LyX-Code
28055 ...
28056 \end_layout
28057
28058 \begin_layout LyX-Code
28059 }
28060 \end_layout
28061
28062 \begin_layout Standard
28063
28064 \emph on
28065 shadowregs
28066 \emph default
28067  instructs the code generator not to store/restore WREG, STATUS, BSR when
28068  entering/exiting the ISR.
28069 \end_layout
28070
28071 \begin_layout Subsection
28072 Function return values
28073 \end_layout
28074
28075 \begin_layout Standard
28076 Return values from functions are placed to the appropriate registers following
28077  a modified Microchip policy optimized for SDCC.
28078  The following table shows these registers:
28079 \end_layout
28080
28081 \begin_layout Standard
28082 \align center
28083 \begin_inset Tabular
28084 <lyxtabular version="3" rows="6" columns="2">
28085 <features>
28086 <column alignment="center" valignment="top" leftline="true" width="0">
28087 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28088 <row topline="true" bottomline="true">
28089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28090 \begin_inset Text
28091
28092 \begin_layout Standard
28093 size
28094 \end_layout
28095
28096 \end_inset
28097 </cell>
28098 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28099 \begin_inset Text
28100
28101 \begin_layout Standard
28102 destination register
28103 \end_layout
28104
28105 \end_inset
28106 </cell>
28107 </row>
28108 <row topline="true">
28109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28110 \begin_inset Text
28111
28112 \begin_layout Standard
28113 8 bits
28114 \end_layout
28115
28116 \end_inset
28117 </cell>
28118 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28119 \begin_inset Text
28120
28121 \begin_layout Standard
28122 WREG
28123 \end_layout
28124
28125 \end_inset
28126 </cell>
28127 </row>
28128 <row topline="true">
28129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28130 \begin_inset Text
28131
28132 \begin_layout Standard
28133 16 bits
28134 \end_layout
28135
28136 \end_inset
28137 </cell>
28138 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28139 \begin_inset Text
28140
28141 \begin_layout Standard
28142 PRODL:WREG
28143 \end_layout
28144
28145 \end_inset
28146 </cell>
28147 </row>
28148 <row topline="true">
28149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28150 \begin_inset Text
28151
28152 \begin_layout Standard
28153 24 bits
28154 \end_layout
28155
28156 \end_inset
28157 </cell>
28158 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28159 \begin_inset Text
28160
28161 \begin_layout Standard
28162 PRODH:PRODL:WREG
28163 \end_layout
28164
28165 \end_inset
28166 </cell>
28167 </row>
28168 <row topline="true">
28169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28170 \begin_inset Text
28171
28172 \begin_layout Standard
28173 32 bits
28174 \end_layout
28175
28176 \end_inset
28177 </cell>
28178 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28179 \begin_inset Text
28180
28181 \begin_layout Standard
28182 FSR0L:PRODH:PRODL:WREG
28183 \end_layout
28184
28185 \end_inset
28186 </cell>
28187 </row>
28188 <row topline="true" bottomline="true">
28189 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28190 \begin_inset Text
28191
28192 \begin_layout Standard
28193 >32 bits
28194 \end_layout
28195
28196 \end_inset
28197 </cell>
28198 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28199 \begin_inset Text
28200
28201 \begin_layout Standard
28202 on stack, FSR0 points to the beginning
28203 \end_layout
28204
28205 \end_inset
28206 </cell>
28207 </row>
28208 </lyxtabular>
28209
28210 \end_inset
28211
28212
28213 \end_layout
28214
28215 \begin_layout Subsection
28216 Interrupts
28217 \end_layout
28218
28219 \begin_layout Standard
28220 An interrupt
28221 \begin_inset LatexCommand index
28222 name "PIC16!interrupt"
28223
28224 \end_inset
28225
28226  service routine (ISR) is declared using the 
28227 \emph on
28228 interrupt
28229 \emph default
28230  keyword.
28231 \end_layout
28232
28233 \begin_layout LyX-Code
28234 void isr(void) interrupt 
28235 \emph on
28236 n
28237 \end_layout
28238
28239 \begin_layout LyX-Code
28240 {
28241 \end_layout
28242
28243 \begin_layout LyX-Code
28244 ...
28245 \end_layout
28246
28247 \begin_layout LyX-Code
28248 }
28249 \end_layout
28250
28251 \begin_layout Standard
28252
28253 \emph on
28254 n
28255 \emph default
28256  is the interrupt number, which for PIC18F devices can be:
28257 \end_layout
28258
28259 \begin_layout Standard
28260 \align center
28261 \begin_inset Tabular
28262 <lyxtabular version="3" rows="4" columns="3">
28263 <features>
28264 <column alignment="center" valignment="top" leftline="true" width="0">
28265 <column alignment="center" valignment="top" leftline="true" width="0">
28266 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28267 <row topline="true" bottomline="true">
28268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28269 \begin_inset Text
28270
28271 \begin_layout Standard
28272
28273 \emph on
28274 n
28275 \end_layout
28276
28277 \end_inset
28278 </cell>
28279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28280 \begin_inset Text
28281
28282 \begin_layout Standard
28283 Interrupt Vector
28284 \end_layout
28285
28286 \end_inset
28287 </cell>
28288 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28289 \begin_inset Text
28290
28291 \begin_layout Standard
28292 Interrupt Vector Address
28293 \end_layout
28294
28295 \end_inset
28296 </cell>
28297 </row>
28298 <row topline="true">
28299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28300 \begin_inset Text
28301
28302 \begin_layout Standard
28303 0
28304 \end_layout
28305
28306 \end_inset
28307 </cell>
28308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28309 \begin_inset Text
28310
28311 \begin_layout Standard
28312 RESET vector
28313 \end_layout
28314
28315 \end_inset
28316 </cell>
28317 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28318 \begin_inset Text
28319
28320 \begin_layout Standard
28321 0x000000
28322 \end_layout
28323
28324 \end_inset
28325 </cell>
28326 </row>
28327 <row topline="true">
28328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28329 \begin_inset Text
28330
28331 \begin_layout Standard
28332
28333 \family roman
28334 \series medium
28335 \shape up
28336 \size normal
28337 \emph off
28338 \bar no
28339 \noun off
28340 \color none
28341 1
28342 \end_layout
28343
28344 \end_inset
28345 </cell>
28346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28347 \begin_inset Text
28348
28349 \begin_layout Standard
28350
28351 \family roman
28352 \series medium
28353 \shape up
28354 \size normal
28355 \emph off
28356 \bar no
28357 \noun off
28358 \color none
28359 HIGH priority interrupts
28360 \end_layout
28361
28362 \end_inset
28363 </cell>
28364 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28365 \begin_inset Text
28366
28367 \begin_layout Standard
28368 0x000008
28369 \end_layout
28370
28371 \end_inset
28372 </cell>
28373 </row>
28374 <row topline="true" bottomline="true">
28375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28376 \begin_inset Text
28377
28378 \begin_layout Standard
28379 2
28380 \end_layout
28381
28382 \end_inset
28383 </cell>
28384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28385 \begin_inset Text
28386
28387 \begin_layout Standard
28388 LOW priority interrupts
28389 \end_layout
28390
28391 \end_inset
28392 </cell>
28393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28394 \begin_inset Text
28395
28396 \begin_layout Standard
28397 0x000018
28398 \end_layout
28399
28400 \end_inset
28401 </cell>
28402 </row>
28403 </lyxtabular>
28404
28405 \end_inset
28406
28407
28408 \end_layout
28409
28410 \begin_layout Standard
28411 When generating assembly code for ISR the code generator places a 
28412 \noun on
28413 goto 
28414 \noun default
28415 instruction at the 
28416 \emph on
28417 Interrupt Vector Address
28418 \emph default
28419  which points at the generated ISR.
28420  This single GOTO instruction is part of an automatically generated 
28421 \emph on
28422 interrupt entry point
28423 \emph default
28424  function.
28425  The actuall ISR code is placed as normally would in the code space.
28426  Upon interrupt request, the GOTO instruction is executed which jumps to
28427  the ISR code.
28428  When declaring interrupt functions as _naked this GOTO instruction is 
28429 \series bold
28430 not
28431 \series default
28432  generated.
28433  The whole interrupt functions is therefore placed at the Interrupt Vector
28434  Address of the specific interrupt.
28435  This is not a problem for the LOW priority interrupts, but it is a problem
28436  for the RESET and the HIGH priority interrupts because code may be written
28437  at the next interrupt's vector address and cause indeterminate program
28438  behaviour if that interrupt is raised.
28439 \begin_inset Foot
28440 status open
28441
28442 \begin_layout Standard
28443 This is not a problem when
28444 \end_layout
28445
28446 \begin_layout Enumerate
28447 this is a HIGH interrupt ISR and LOW interrupts are 
28448 \emph on
28449 disabled
28450 \emph default
28451  or not used.
28452 \end_layout
28453
28454 \begin_layout Enumerate
28455 when the ISR is small enough not to reach the next interrupt's vector address.
28456 \end_layout
28457
28458 \end_inset
28459
28460
28461 \end_layout
28462
28463 \begin_layout Standard
28464
28465 \emph on
28466 n
28467 \emph default
28468  may be omitted.
28469  This way a function is generated similar to an ISR, but it is not assigned
28470  to any interrupt.
28471 \end_layout
28472
28473 \begin_layout Standard
28474 When entering an interrupt, currently the PIC16
28475 \begin_inset LatexCommand index
28476 name "PIC16"
28477
28478 \end_inset
28479
28480  port automatically saves the following registers:
28481 \end_layout
28482
28483 \begin_layout Itemize
28484 WREG
28485 \end_layout
28486
28487 \begin_layout Itemize
28488 STATUS
28489 \end_layout
28490
28491 \begin_layout Itemize
28492 BSR
28493 \end_layout
28494
28495 \begin_layout Itemize
28496 PROD (PRODL and PRODH)
28497 \end_layout
28498
28499 \begin_layout Itemize
28500 FSR0 (FSR0L and FSR0H)
28501 \end_layout
28502
28503 \begin_layout Standard
28504 These registers are restored upon return from the interrupt routine.
28505 \begin_inset Foot
28506 status open
28507
28508 \begin_layout Standard
28509 NOTE that when the _naked attribute is specified for an interrupt routine,
28510  then NO registers are stored or restored.
28511 \end_layout
28512
28513 \end_inset
28514
28515
28516 \end_layout
28517
28518 \begin_layout Subsection
28519 Generic Pointers
28520 \end_layout
28521
28522 \begin_layout Standard
28523 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
28524  There are 3 types of generic pointers currently implemented data, code
28525  and eeprom pointers.
28526  They are differentiated by the value of the 7th and 6th bits of the upper
28527  byte:
28528 \end_layout
28529
28530 \begin_layout Standard
28531 \align center
28532 \begin_inset Tabular
28533 <lyxtabular version="3" rows="5" columns="5">
28534 <features>
28535 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28536 <column alignment="center" valignment="top" width="0">
28537 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28538 <column alignment="center" valignment="top" width="0">
28539 <column alignment="left" valignment="top" rightline="true" width="0">
28540 <row topline="true" bottomline="true">
28541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28542 \begin_inset Text
28543
28544 \begin_layout Standard
28545 pointer type
28546 \end_layout
28547
28548 \end_inset
28549 </cell>
28550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28551 \begin_inset Text
28552
28553 \begin_layout Standard
28554 7th bit
28555 \end_layout
28556
28557 \end_inset
28558 </cell>
28559 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28560 \begin_inset Text
28561
28562 \begin_layout Standard
28563 6th bit
28564 \end_layout
28565
28566 \end_inset
28567 </cell>
28568 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28569 \begin_inset Text
28570
28571 \begin_layout Standard
28572 rest of the pointer
28573 \end_layout
28574
28575 \end_inset
28576 </cell>
28577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28578 \begin_inset Text
28579
28580 \begin_layout Standard
28581 description
28582 \end_layout
28583
28584 \end_inset
28585 </cell>
28586 </row>
28587 <row topline="true" bottomline="true">
28588 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28589 \begin_inset Text
28590
28591 \begin_layout Standard
28592 data 
28593 \end_layout
28594
28595 \end_inset
28596 </cell>
28597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28598 \begin_inset Text
28599
28600 \begin_layout Standard
28601 1
28602 \end_layout
28603
28604 \end_inset
28605 </cell>
28606 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28607 \begin_inset Text
28608
28609 \begin_layout Standard
28610 0
28611 \end_layout
28612
28613 \end_inset
28614 </cell>
28615 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28616 \begin_inset Text
28617
28618 \begin_layout Standard
28619
28620 \family typewriter
28621 \shape slanted
28622 \emph on
28623 uuuuuu uuuuxxxx xxxxxxxx
28624 \end_layout
28625
28626 \end_inset
28627 </cell>
28628 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28629 \begin_inset Text
28630
28631 \begin_layout Standard
28632 a 12-bit data pointer in data RAM memory
28633 \end_layout
28634
28635 \end_inset
28636 </cell>
28637 </row>
28638 <row bottomline="true">
28639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28640 \begin_inset Text
28641
28642 \begin_layout Standard
28643 code
28644 \end_layout
28645
28646 \end_inset
28647 </cell>
28648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28649 \begin_inset Text
28650
28651 \begin_layout Standard
28652 0
28653 \end_layout
28654
28655 \end_inset
28656 </cell>
28657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28658 \begin_inset Text
28659
28660 \begin_layout Standard
28661 0
28662 \end_layout
28663
28664 \end_inset
28665 </cell>
28666 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28667 \begin_inset Text
28668
28669 \begin_layout Standard
28670
28671 \family typewriter
28672 \shape slanted
28673 \emph on
28674 uxxxxx xxxxxxxx xxxxxxxx
28675 \end_layout
28676
28677 \end_inset
28678 </cell>
28679 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28680 \begin_inset Text
28681
28682 \begin_layout Standard
28683 a 21-bit code pointer in FLASH memory
28684 \end_layout
28685
28686 \end_inset
28687 </cell>
28688 </row>
28689 <row bottomline="true">
28690 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28691 \begin_inset Text
28692
28693 \begin_layout Standard
28694 eeprom
28695 \end_layout
28696
28697 \end_inset
28698 </cell>
28699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28700 \begin_inset Text
28701
28702 \begin_layout Standard
28703 0
28704 \end_layout
28705
28706 \end_inset
28707 </cell>
28708 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28709 \begin_inset Text
28710
28711 \begin_layout Standard
28712 1
28713 \end_layout
28714
28715 \end_inset
28716 </cell>
28717 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28718 \begin_inset Text
28719
28720 \begin_layout Standard
28721
28722 \family typewriter
28723 \shape slanted
28724 \emph on
28725 uuuuuu uuuuuuxx xxxxxxxx
28726 \end_layout
28727
28728 \end_inset
28729 </cell>
28730 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28731 \begin_inset Text
28732
28733 \begin_layout Standard
28734 a 10-bit eeprom pointer in EEPROM memory
28735 \end_layout
28736
28737 \end_inset
28738 </cell>
28739 </row>
28740 <row bottomline="true">
28741 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28742 \begin_inset Text
28743
28744 \begin_layout Standard
28745 (unimplemented)
28746 \end_layout
28747
28748 \end_inset
28749 </cell>
28750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28751 \begin_inset Text
28752
28753 \begin_layout Standard
28754 1
28755 \end_layout
28756
28757 \end_inset
28758 </cell>
28759 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28760 \begin_inset Text
28761
28762 \begin_layout Standard
28763 1
28764 \end_layout
28765
28766 \end_inset
28767 </cell>
28768 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28769 \begin_inset Text
28770
28771 \begin_layout Standard
28772
28773 \family typewriter
28774 \shape slanted
28775 \emph on
28776 xxxxxx xxxxxxxx xxxxxxxx
28777 \end_layout
28778
28779 \end_inset
28780 </cell>
28781 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28782 \begin_inset Text
28783
28784 \begin_layout Standard
28785 unimplemented pointer type
28786 \end_layout
28787
28788 \end_inset
28789 </cell>
28790 </row>
28791 </lyxtabular>
28792
28793 \end_inset
28794
28795
28796 \end_layout
28797
28798 \begin_layout Standard
28799 \noindent
28800 Generic pointer are read and written with a set of library functions which
28801  read/write 1, 2, 3, 4 bytes.
28802 \end_layout
28803
28804 \begin_layout Subsection
28805 PIC16 C Libraries
28806 \end_layout
28807
28808 \begin_layout Subsubsection
28809 Standard I/O Streams
28810 \end_layout
28811
28812 \begin_layout Standard
28813 In the 
28814 \emph on
28815 stdio.h
28816 \emph default
28817  the type FILE is defined as:
28818 \end_layout
28819
28820 \begin_layout LyX-Code
28821 typedef char * FILE;
28822 \end_layout
28823
28824 \begin_layout Standard
28825 This type is the stream type implemented I/O in the PIC18F devices.
28826  Also the standard input and output streams are declared in stdio.h:
28827 \end_layout
28828
28829 \begin_layout LyX-Code
28830 extern FILE * stdin;
28831 \end_layout
28832
28833 \begin_layout LyX-Code
28834 extern FILE * stdout;
28835 \end_layout
28836
28837 \begin_layout Standard
28838 The FILE type is actually a generic pointer which defines one more type
28839  of generic pointers, the 
28840 \emph on
28841 stream
28842 \emph default
28843  pointer.
28844  This new type has the format:
28845 \end_layout
28846
28847 \begin_layout Standard
28848 \noindent
28849 \align center
28850 \begin_inset Tabular
28851 <lyxtabular version="3" rows="2" columns="7">
28852 <features>
28853 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28854 <column alignment="center" valignment="top" width="0">
28855 <column alignment="center" valignment="top" leftline="true" width="0">
28856 <column alignment="center" valignment="top" leftline="true" width="0">
28857 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28858 <column alignment="center" valignment="top" width="0">
28859 <column alignment="left" valignment="top" rightline="true" width="0">
28860 <row topline="true" bottomline="true">
28861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28862 \begin_inset Text
28863
28864 \begin_layout Standard
28865 pointer type
28866 \end_layout
28867
28868 \end_inset
28869 </cell>
28870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28871 \begin_inset Text
28872
28873 \begin_layout Standard
28874 <7:6>
28875 \end_layout
28876
28877 \end_inset
28878 </cell>
28879 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28880 \begin_inset Text
28881
28882 \begin_layout Standard
28883 <5>
28884 \end_layout
28885
28886 \end_inset
28887 </cell>
28888 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28889 \begin_inset Text
28890
28891 \begin_layout Standard
28892 <4>
28893 \end_layout
28894
28895 \end_inset
28896 </cell>
28897 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28898 \begin_inset Text
28899
28900 \begin_layout Standard
28901 <3:0>
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 rest of the pointer
28911 \end_layout
28912
28913 \end_inset
28914 </cell>
28915 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28916 \begin_inset Text
28917
28918 \begin_layout Standard
28919 descrption
28920 \end_layout
28921
28922 \end_inset
28923 </cell>
28924 </row>
28925 <row topline="true" bottomline="true">
28926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28927 \begin_inset Text
28928
28929 \begin_layout Standard
28930 stream
28931 \end_layout
28932
28933 \end_inset
28934 </cell>
28935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28936 \begin_inset Text
28937
28938 \begin_layout Standard
28939 00
28940 \end_layout
28941
28942 \end_inset
28943 </cell>
28944 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28945 \begin_inset Text
28946
28947 \begin_layout Standard
28948 1
28949 \end_layout
28950
28951 \end_inset
28952 </cell>
28953 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28954 \begin_inset Text
28955
28956 \begin_layout Standard
28957 0
28958 \end_layout
28959
28960 \end_inset
28961 </cell>
28962 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28963 \begin_inset Text
28964
28965 \begin_layout Standard
28966 nnnn
28967 \end_layout
28968
28969 \end_inset
28970 </cell>
28971 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28972 \begin_inset Text
28973
28974 \begin_layout Standard
28975
28976 \family typewriter
28977 \shape slanted
28978 \emph on
28979 uuuuuuuu uuuuuuuu
28980 \end_layout
28981
28982 \end_inset
28983 </cell>
28984 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28985 \begin_inset Text
28986
28987 \begin_layout Standard
28988 upper byte high nubble is 0x2n, the rest are zeroes
28989 \end_layout
28990
28991 \end_inset
28992 </cell>
28993 </row>
28994 </lyxtabular>
28995
28996 \end_inset
28997
28998
28999 \end_layout
29000
29001 \begin_layout Standard
29002 \noindent
29003 Currently implemented there are 3 types of streams defined:
29004 \end_layout
29005
29006 \begin_layout Standard
29007 \noindent
29008 \align center
29009 \begin_inset Tabular
29010 <lyxtabular version="3" rows="4" columns="4">
29011 <features>
29012 <column alignment="center" valignment="top" leftline="true" width="0">
29013 <column alignment="center" valignment="top" leftline="true" width="0">
29014 <column alignment="center" valignment="top" leftline="true" width="0">
29015 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
29016 <row topline="true" bottomline="true">
29017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29018 \begin_inset Text
29019
29020 \begin_layout Standard
29021 stream type
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 value
29031 \end_layout
29032
29033 \end_inset
29034 </cell>
29035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29036 \begin_inset Text
29037
29038 \begin_layout Standard
29039 module
29040 \end_layout
29041
29042 \end_inset
29043 </cell>
29044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29045 \begin_inset Text
29046
29047 \begin_layout Standard
29048 description
29049 \end_layout
29050
29051 \end_inset
29052 </cell>
29053 </row>
29054 <row topline="true">
29055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29056 \begin_inset Text
29057
29058 \begin_layout Standard
29059 STREAM_USART
29060 \end_layout
29061
29062 \end_inset
29063 </cell>
29064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29065 \begin_inset Text
29066
29067 \begin_layout Standard
29068
29069 \family typewriter
29070 0x200000UL
29071 \end_layout
29072
29073 \end_inset
29074 </cell>
29075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29076 \begin_inset Text
29077
29078 \begin_layout Standard
29079 USART
29080 \end_layout
29081
29082 \end_inset
29083 </cell>
29084 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29085 \begin_inset Text
29086
29087 \begin_layout Standard
29088 Writes/Reads characters via the USART peripheral
29089 \end_layout
29090
29091 \end_inset
29092 </cell>
29093 </row>
29094 <row topline="true">
29095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29096 \begin_inset Text
29097
29098 \begin_layout Standard
29099 STREAM_MSSP
29100 \end_layout
29101
29102 \end_inset
29103 </cell>
29104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29105 \begin_inset Text
29106
29107 \begin_layout Standard
29108
29109 \family typewriter
29110 0x210000UL
29111 \end_layout
29112
29113 \end_inset
29114 </cell>
29115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29116 \begin_inset Text
29117
29118 \begin_layout Standard
29119 MSSP
29120 \end_layout
29121
29122 \end_inset
29123 </cell>
29124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29125 \begin_inset Text
29126
29127 \begin_layout Standard
29128 Writes/Reads characters via the MSSP peripheral
29129 \end_layout
29130
29131 \end_inset
29132 </cell>
29133 </row>
29134 <row topline="true" bottomline="true">
29135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29136 \begin_inset Text
29137
29138 \begin_layout Standard
29139 STREAM_USER
29140 \end_layout
29141
29142 \end_inset
29143 </cell>
29144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29145 \begin_inset Text
29146
29147 \begin_layout Standard
29148
29149 \family typewriter
29150 0x2f0000UL
29151 \end_layout
29152
29153 \end_inset
29154 </cell>
29155 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29156 \begin_inset Text
29157
29158 \begin_layout Standard
29159 (none)
29160 \end_layout
29161
29162 \end_inset
29163 </cell>
29164 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29165 \begin_inset Text
29166
29167 \begin_layout Standard
29168 Writes/Reads characters via used defined functions
29169 \end_layout
29170
29171 \end_inset
29172 </cell>
29173 </row>
29174 </lyxtabular>
29175
29176 \end_inset
29177
29178
29179 \end_layout
29180
29181 \begin_layout Standard
29182 \noindent
29183 The stream identifiers are declared as macros in the stdio.h header.
29184 \end_layout
29185
29186 \begin_layout Standard
29187 \noindent
29188 In the libc library there exist the functions that are used to write to
29189  each of the above streams.
29190  These are
29191 \end_layout
29192
29193 \begin_layout Description
29194 _
29195 \begin_inset ERT
29196 status collapsed
29197
29198 \begin_layout Standard
29199
29200
29201 \backslash
29202 /
29203 \end_layout
29204
29205 \end_inset
29206
29207 _stream_usart_putchar writes a character at the USART stream
29208 \end_layout
29209
29210 \begin_layout Description
29211 _
29212 \begin_inset ERT
29213 status collapsed
29214
29215 \begin_layout Standard
29216
29217
29218 \backslash
29219 /
29220 \end_layout
29221
29222 \end_inset
29223
29224 _stream_mssp_putchar writes a character at the MSSP stream
29225 \end_layout
29226
29227 \begin_layout Description
29228 putchar dummy function.
29229  This writes a character to a user specified manner.
29230 \end_layout
29231
29232 \begin_layout Standard
29233 In order to increase performance 
29234 \emph on
29235 putchar
29236 \emph default
29237  is declared in stdio.h as having its parameter in WREG (it has the wparam
29238  keyword).
29239  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
29240  in a user-friendly way.
29241  
29242 \emph on
29243 arg
29244 \emph default
29245  is the name of the variable that holds the character to print.
29246  An example follows:
29247 \end_layout
29248
29249 \begin_layout LyX-Code
29250 #include <pic18fregs.h>
29251 \newline
29252 #include <stdio.h>
29253 \newline
29254
29255 \newline
29256 PUTCHAR( c )
29257 \end_layout
29258
29259 \begin_layout LyX-Code
29260 {
29261 \end_layout
29262
29263 \begin_layout LyX-Code
29264     PORTA = c;    /* dump character c to PORTA */
29265 \end_layout
29266
29267 \begin_layout LyX-Code
29268
29269 \newline
29270
29271 \newline
29272 void main(void)
29273 \end_layout
29274
29275 \begin_layout LyX-Code
29276 {
29277 \end_layout
29278
29279 \begin_layout LyX-Code
29280     stdout = STREAM_USER;    /* this is not necessary, since stdout points
29281 \end_layout
29282
29283 \begin_layout LyX-Code
29284                               * by default to STREAM_USER */
29285 \end_layout
29286
29287 \begin_layout LyX-Code
29288     printf (
29289 \begin_inset Quotes sld
29290 \end_inset
29291
29292 This is a printf test
29293 \backslash
29294 n
29295 \begin_inset Quotes srd
29296 \end_inset
29297
29298 );
29299 \end_layout
29300
29301 \begin_layout LyX-Code
29302 }
29303 \end_layout
29304
29305 \begin_layout LyX-Code
29306
29307 \end_layout
29308
29309 \begin_layout Subsubsection
29310 Printing functions
29311 \end_layout
29312
29313 \begin_layout Standard
29314 PIC16 contains an implementation of the printf-family of functions.
29315  There exist the following functions:
29316 \end_layout
29317
29318 \begin_layout LyX-Code
29319 extern unsigned int sprintf(char *buf, char *fmt, ...);
29320 \end_layout
29321
29322 \begin_layout LyX-Code
29323 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
29324 \end_layout
29325
29326 \begin_layout LyX-Code
29327
29328 \end_layout
29329
29330 \begin_layout LyX-Code
29331 extern unsigned int printf(char *fmt, ...);
29332 \end_layout
29333
29334 \begin_layout LyX-Code
29335 extern unsigned int vprintf(char *fmt, va_lista ap);
29336 \end_layout
29337
29338 \begin_layout LyX-Code
29339
29340 \end_layout
29341
29342 \begin_layout LyX-Code
29343 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
29344 \end_layout
29345
29346 \begin_layout LyX-Code
29347 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
29348 \end_layout
29349
29350 \begin_layout Standard
29351 For sprintf and vsprintf 
29352 \emph on
29353 buf
29354 \emph default
29355  should normally be a data pointer where the resulting string will be placed.
29356  No range checking is done so the user should allocate the necessary buffer.
29357  For fprintf and vfprintf 
29358 \emph on
29359 fp
29360 \emph default
29361  should be a stream pointer (i.e.
29362  stdout, STREAM_MSSP, etc...).
29363 \end_layout
29364
29365 \begin_layout Subsubsection
29366 Signals
29367 \end_layout
29368
29369 \begin_layout Standard
29370 The PIC18F family of microcontrollers supports a number of interrupt sources.
29371  A list of these interrupts is shown in the following table:
29372 \end_layout
29373
29374 \begin_layout Standard
29375 \align center
29376 \begin_inset Tabular
29377 <lyxtabular version="3" rows="11" columns="4">
29378 <features>
29379 <column alignment="left" valignment="top" leftline="true" width="0">
29380 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
29381 <column alignment="left" valignment="top" leftline="true" width="0">
29382 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
29383 <row topline="true" bottomline="true">
29384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29385 \begin_inset Text
29386
29387 \begin_layout Standard
29388 signal name
29389 \end_layout
29390
29391 \end_inset
29392 </cell>
29393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29394 \begin_inset Text
29395
29396 \begin_layout Standard
29397 description
29398 \end_layout
29399
29400 \end_inset
29401 </cell>
29402 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29403 \begin_inset Text
29404
29405 \begin_layout Standard
29406 signal name
29407 \end_layout
29408
29409 \end_inset
29410 </cell>
29411 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29412 \begin_inset Text
29413
29414 \begin_layout Standard
29415 description
29416 \end_layout
29417
29418 \end_inset
29419 </cell>
29420 </row>
29421 <row topline="true">
29422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29423 \begin_inset Text
29424
29425 \begin_layout Standard
29426 SIG_RB
29427 \end_layout
29428
29429 \end_inset
29430 </cell>
29431 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29432 \begin_inset Text
29433
29434 \begin_layout Standard
29435 PORTB change interrupt
29436 \end_layout
29437
29438 \end_inset
29439 </cell>
29440 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29441 \begin_inset Text
29442
29443 \begin_layout Standard
29444 SIG_EE
29445 \end_layout
29446
29447 \end_inset
29448 </cell>
29449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29450 \begin_inset Text
29451
29452 \begin_layout Standard
29453 EEPROM/FLASH write complete interrupt
29454 \end_layout
29455
29456 \end_inset
29457 </cell>
29458 </row>
29459 <row topline="true">
29460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29461 \begin_inset Text
29462
29463 \begin_layout Standard
29464 SIG_INT0
29465 \end_layout
29466
29467 \end_inset
29468 </cell>
29469 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29470 \begin_inset Text
29471
29472 \begin_layout Standard
29473 INT0 external interrupt
29474 \end_layout
29475
29476 \end_inset
29477 </cell>
29478 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29479 \begin_inset Text
29480
29481 \begin_layout Standard
29482 SIG_BCOL
29483 \end_layout
29484
29485 \end_inset
29486 </cell>
29487 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29488 \begin_inset Text
29489
29490 \begin_layout Standard
29491 Bus collision interrupt
29492 \end_layout
29493
29494 \end_inset
29495 </cell>
29496 </row>
29497 <row topline="true">
29498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29499 \begin_inset Text
29500
29501 \begin_layout Standard
29502 SIG_INT1
29503 \end_layout
29504
29505 \end_inset
29506 </cell>
29507 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29508 \begin_inset Text
29509
29510 \begin_layout Standard
29511 INT1 external interrupt
29512 \end_layout
29513
29514 \end_inset
29515 </cell>
29516 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29517 \begin_inset Text
29518
29519 \begin_layout Standard
29520 SIG_LVD
29521 \end_layout
29522
29523 \end_inset
29524 </cell>
29525 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29526 \begin_inset Text
29527
29528 \begin_layout Standard
29529 Low voltage detect interrupt
29530 \end_layout
29531
29532 \end_inset
29533 </cell>
29534 </row>
29535 <row topline="true">
29536 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29537 \begin_inset Text
29538
29539 \begin_layout Standard
29540 SIG_INT2
29541 \end_layout
29542
29543 \end_inset
29544 </cell>
29545 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29546 \begin_inset Text
29547
29548 \begin_layout Standard
29549 INT2 external interrupt
29550 \end_layout
29551
29552 \end_inset
29553 </cell>
29554 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29555 \begin_inset Text
29556
29557 \begin_layout Standard
29558 SIG_PSP
29559 \end_layout
29560
29561 \end_inset
29562 </cell>
29563 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29564 \begin_inset Text
29565
29566 \begin_layout Standard
29567 Parallel slave port interrupt
29568 \end_layout
29569
29570 \end_inset
29571 </cell>
29572 </row>
29573 <row topline="true">
29574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29575 \begin_inset Text
29576
29577 \begin_layout Standard
29578 SIG_CCP1
29579 \end_layout
29580
29581 \end_inset
29582 </cell>
29583 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29584 \begin_inset Text
29585
29586 \begin_layout Standard
29587 CCP1 module interrupt
29588 \end_layout
29589
29590 \end_inset
29591 </cell>
29592 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29593 \begin_inset Text
29594
29595 \begin_layout Standard
29596 SIG_AD
29597 \end_layout
29598
29599 \end_inset
29600 </cell>
29601 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29602 \begin_inset Text
29603
29604 \begin_layout Standard
29605 AD convertion complete interrupt
29606 \end_layout
29607
29608 \end_inset
29609 </cell>
29610 </row>
29611 <row topline="true">
29612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29613 \begin_inset Text
29614
29615 \begin_layout Standard
29616 SIG_CCP2
29617 \end_layout
29618
29619 \end_inset
29620 </cell>
29621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29622 \begin_inset Text
29623
29624 \begin_layout Standard
29625 CCP2 module interrupt
29626 \end_layout
29627
29628 \end_inset
29629 </cell>
29630 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29631 \begin_inset Text
29632
29633 \begin_layout Standard
29634 SIG_RC
29635 \end_layout
29636
29637 \end_inset
29638 </cell>
29639 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29640 \begin_inset Text
29641
29642 \begin_layout Standard
29643 USART receive interrupt
29644 \end_layout
29645
29646 \end_inset
29647 </cell>
29648 </row>
29649 <row topline="true">
29650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29651 \begin_inset Text
29652
29653 \begin_layout Standard
29654 SIG_TMR0
29655 \end_layout
29656
29657 \end_inset
29658 </cell>
29659 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29660 \begin_inset Text
29661
29662 \begin_layout Standard
29663 TMR0 overflow interrupt
29664 \end_layout
29665
29666 \end_inset
29667 </cell>
29668 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29669 \begin_inset Text
29670
29671 \begin_layout Standard
29672 SIG_TX
29673 \end_layout
29674
29675 \end_inset
29676 </cell>
29677 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29678 \begin_inset Text
29679
29680 \begin_layout Standard
29681 USART transmit interrupt
29682 \end_layout
29683
29684 \end_inset
29685 </cell>
29686 </row>
29687 <row topline="true">
29688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29689 \begin_inset Text
29690
29691 \begin_layout Standard
29692 SIG_TMR1
29693 \end_layout
29694
29695 \end_inset
29696 </cell>
29697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29698 \begin_inset Text
29699
29700 \begin_layout Standard
29701 TMR1 overflow interrupt
29702 \end_layout
29703
29704 \end_inset
29705 </cell>
29706 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29707 \begin_inset Text
29708
29709 \begin_layout Standard
29710 SIG_MSSP
29711 \end_layout
29712
29713 \end_inset
29714 </cell>
29715 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29716 \begin_inset Text
29717
29718 \begin_layout Standard
29719 SSP receive/transmit interrupt
29720 \end_layout
29721
29722 \end_inset
29723 </cell>
29724 </row>
29725 <row topline="true">
29726 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29727 \begin_inset Text
29728
29729 \begin_layout Standard
29730 SIG_TMR2
29731 \end_layout
29732
29733 \end_inset
29734 </cell>
29735 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29736 \begin_inset Text
29737
29738 \begin_layout Standard
29739 TMR2 matches PR2 interrupt
29740 \end_layout
29741
29742 \end_inset
29743 </cell>
29744 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29745 \begin_inset Text
29746
29747 \begin_layout Standard
29748
29749 \end_layout
29750
29751 \end_inset
29752 </cell>
29753 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29754 \begin_inset Text
29755
29756 \begin_layout Standard
29757
29758 \end_layout
29759
29760 \end_inset
29761 </cell>
29762 </row>
29763 <row topline="true" bottomline="true">
29764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29765 \begin_inset Text
29766
29767 \begin_layout Standard
29768 SIG_TMR3
29769 \end_layout
29770
29771 \end_inset
29772 </cell>
29773 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29774 \begin_inset Text
29775
29776 \begin_layout Standard
29777 TMR3 overflow interrupt
29778 \end_layout
29779
29780 \end_inset
29781 </cell>
29782 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29783 \begin_inset Text
29784
29785 \begin_layout Standard
29786
29787 \end_layout
29788
29789 \end_inset
29790 </cell>
29791 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29792 \begin_inset Text
29793
29794 \begin_layout Standard
29795
29796 \end_layout
29797
29798 \end_inset
29799 </cell>
29800 </row>
29801 </lyxtabular>
29802
29803 \end_inset
29804
29805
29806 \end_layout
29807
29808 \begin_layout Standard
29809 \noindent
29810 The prototypes for these names are defined in the header file 
29811 \emph on
29812 signal.h
29813 \emph default
29814  .
29815 \end_layout
29816
29817 \begin_layout Standard
29818 \noindent
29819 In order to simplify signal handling, a number of macros is provided:
29820 \end_layout
29821
29822 \begin_layout List
29823 \labelwidthstring 00.00.0000
29824 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
29825  high priority interrupts.
29826  
29827 \emph on
29828 name
29829 \emph default
29830  is the function name to use.
29831 \end_layout
29832
29833 \begin_layout List
29834 \labelwidthstring 00.00.0000
29835 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
29836  low priority interrupt.
29837  
29838 \emph on
29839 name
29840 \emph default
29841  is the function name to use.
29842 \end_layout
29843
29844 \begin_layout List
29845 \labelwidthstring 00.00.0000
29846 DEF_HANDLER(sig,handler) define a handler for signal 
29847 \emph on
29848 sig.
29849 \end_layout
29850
29851 \begin_layout List
29852 \labelwidthstring 00.00.0000
29853 END_DEF end the declaration of the dispatch table.
29854 \end_layout
29855
29856 \begin_layout Standard
29857 Additionally there are two more macros to simplify the declaration of the
29858  signal handler:
29859 \end_layout
29860
29861 \begin_layout List
29862 \labelwidthstring 00.00.0000
29863
29864 \series medium
29865 SIGHANDLER(handler)
29866 \series default
29867  this declares the function prototype for the 
29868 \emph on
29869 handler
29870 \emph default
29871  function.
29872 \end_layout
29873
29874 \begin_layout List
29875 \labelwidthstring 00.00.0000
29876 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
29877 \end_layout
29878
29879 \begin_layout Standard
29880 An example of using the macros above is shown below:
29881 \end_layout
29882
29883 \begin_layout LyX-Code
29884 #include <pic18fregs.h>
29885 \end_layout
29886
29887 \begin_layout LyX-Code
29888 #include <signal.h>
29889 \newline
29890
29891 \newline
29892 DEF_INTHIGH(high_int)
29893 \end_layout
29894
29895 \begin_layout LyX-Code
29896 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
29897 \end_layout
29898
29899 \begin_layout LyX-Code
29900 DEF_HANDLER(SIG_BCOL, _bcol_handler)
29901 \end_layout
29902
29903 \begin_layout LyX-Code
29904 END_DEF
29905 \newline
29906
29907 \newline
29908 SIGHANDLER(_tmr0_handler)
29909 \end_layout
29910
29911 \begin_layout LyX-Code
29912 {
29913 \end_layout
29914
29915 \begin_layout LyX-Code
29916   /* action to be taken when timer 0 overflows */
29917 \end_layout
29918
29919 \begin_layout LyX-Code
29920 }
29921 \newline
29922
29923 \newline
29924 SIGHANDLERNAKED(_bcol_handler)
29925 \end_layout
29926
29927 \begin_layout LyX-Code
29928 {
29929 \end_layout
29930
29931 \begin_layout LyX-Code
29932   _asm
29933 \end_layout
29934
29935 \begin_layout LyX-Code
29936     /* action to be taken when bus collision occurs */
29937 \end_layout
29938
29939 \begin_layout LyX-Code
29940     retfie
29941 \end_layout
29942
29943 \begin_layout LyX-Code
29944  _endasm;
29945 \end_layout
29946
29947 \begin_layout LyX-Code
29948 }
29949 \end_layout
29950
29951 \begin_layout Standard
29952
29953 \series bold
29954 NOTES:
29955 \series default
29956  Special care should be taken when using the above scheme:
29957 \end_layout
29958
29959 \begin_layout Itemize
29960 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
29961 \end_layout
29962
29963 \begin_layout Itemize
29964 when declaring SIGHANDLERNAKED handler never forget to use 
29965 \emph on
29966 retfie
29967 \emph default
29968  for proper returning.
29969 \end_layout
29970
29971 \begin_layout Subsection
29972 PIC16 Port -- Tips
29973 \end_layout
29974
29975 \begin_layout Standard
29976 Here you can find some general tips for compiling programs with SDCC/pic16.
29977 \end_layout
29978
29979 \begin_layout Subsubsection
29980 Stack size
29981 \end_layout
29982
29983 \begin_layout Standard
29984 The default stack
29985 \begin_inset LatexCommand index
29986 name "PIC16!stack"
29987
29988 \end_inset
29989
29990  size (that is 64 bytes) probably is enough for many programs.
29991  One must take care that when there are many levels of function nesting,
29992  or there is excessive usage of stack, its size should be extended.
29993  An example of such a case is the printf/sprintf family of functions.
29994  If you encounter problems like not being able to print integers, then you
29995  need to set the stack size around the maximum (256 for small stack model).
29996  The following diagram shows what happens when calling printf to print an
29997  integer:
29998 \end_layout
29999
30000 \begin_layout LyX-Code
30001 printf () --> ltoa () --> ultoa () --> divschar ()
30002 \end_layout
30003
30004 \begin_layout Standard
30005 It is should be understood that stack is easily consumed when calling complicate
30006 d functions.
30007  Using command line arguments like -
30008 \begin_inset ERT
30009 status collapsed
30010
30011 \begin_layout Standard
30012
30013
30014 \backslash
30015 /
30016 \end_layout
30017
30018 \end_inset
30019
30020 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
30021  stack frames.
30022  Other ways to reduce stack usage may exist.
30023 \end_layout
30024
30025 \begin_layout Subsection
30026 Known Bugs
30027 \end_layout
30028
30029 \begin_layout Subsubsection
30030 Extended Instruction Set
30031 \end_layout
30032
30033 \begin_layout Standard
30034 The PIC16 port emits code which is incompatible with the extended instruction
30035  set available with many newer devices.
30036  Make sure to always explicitly disable it, usually using
30037 \end_layout
30038
30039 \begin_layout Standard
30040
30041 \family typewriter
30042 static __code char __at(__CONFIG4L) conf4l = /* more flags & */ _XINST_OFF_4L;
30043 \end_layout
30044
30045 \begin_layout Standard
30046 \noindent
30047 Some devices (namely 18f2455, 18f2550, 18f4455, and 18f4550) use _ENHCPU_OFF_4L
30048  instead of _XINST_OFF_4L.
30049 \end_layout
30050
30051 \begin_layout Subsubsection
30052 Regression Tests
30053 \end_layout
30054
30055 \begin_layout Standard
30056 The PIC16 port currently passes most but not all of the tests in SDCC's
30057  regression test
30058 \begin_inset LatexCommand index
30059 name "Regression test (PIC16)"
30060
30061 \end_inset
30062
30063  suite (see section 
30064 \begin_inset LatexCommand ref
30065 reference "sec:Quality-control"
30066
30067 \end_inset
30068
30069 ), thus no automatic regression tests are currently performed for the PIC16
30070  target.
30071 \end_layout
30072
30073 \begin_layout Chapter
30074 Debugging
30075 \end_layout
30076
30077 \begin_layout Standard
30078 There are several approaches to debugging your code.
30079  This chapter is meant to show your options and to give detail on some of
30080  them:
30081 \newline
30082
30083 \newline
30084 When writing your code:
30085 \end_layout
30086
30087 \begin_layout Itemize
30088 write your code with debugging in mind (avoid duplicating code, put conceptually
30089  similar variables into structs, use structured code, have strategic points
30090  within your code where all variables are consistent, ...)
30091 \end_layout
30092
30093 \begin_layout Itemize
30094 run a syntax-checking tool like splint
30095 \begin_inset LatexCommand index
30096 name "splint (syntax checking tool)"
30097
30098 \end_inset
30099
30100
30101 \begin_inset LatexCommand index
30102 name "lint (syntax checking tool)"
30103
30104 \end_inset
30105
30106  (see -
30107 \begin_inset ERT
30108 status collapsed
30109
30110 \begin_layout Standard
30111
30112
30113 \backslash
30114 /
30115 \end_layout
30116
30117 \end_inset
30118
30119 -more-pedantic 
30120 \begin_inset LatexCommand ref
30121 reference "lyx:more-pedantic-SPLINT"
30122
30123 \end_inset
30124
30125 ) over the code.
30126 \end_layout
30127
30128 \begin_layout Itemize
30129 for the high level code use a C-compiler (like f.e.
30130  GCC) to compile run and debug the code on your host.
30131  See (see -
30132 \begin_inset ERT
30133 status collapsed
30134
30135 \begin_layout Standard
30136
30137
30138 \backslash
30139 /
30140 \end_layout
30141
30142 \end_inset
30143
30144 -more-pedantic 
30145 \begin_inset LatexCommand ref
30146 reference "lyx:more-pedantic-SPLINT"
30147
30148 \end_inset
30149
30150 ) on how to handle syntax extensions like __xdata, __at(), ...
30151  
30152 \end_layout
30153
30154 \begin_layout Itemize
30155 use another C-compiler to compile code for your target.
30156  Always an option but not recommended:) And not very likely to help you.
30157  If you seriously consider walking this path you should at least occasionally
30158  check portability of your code.
30159  Most commercial compiler vendors will offer an evaluation version so you
30160  can test compile your code or snippets of your code.
30161 \end_layout
30162
30163 \begin_layout Standard
30164 Debugging on a simulator:
30165 \end_layout
30166
30167 \begin_layout Itemize
30168 there is a separate section about SDCDB (section 
30169 \begin_inset LatexCommand ref
30170 reference "cha:Debugging-with-SDCDB"
30171
30172 \end_inset
30173
30174 ) below.
30175 \end_layout
30176
30177 \begin_layout Itemize
30178 or (8051 specific) use a freeware/commercial simulator which interfaces
30179  to the AOMF
30180 \begin_inset LatexCommand index
30181 name "AOMF, AOMF51"
30182
30183 \end_inset
30184
30185  file (see 
30186 \begin_inset LatexCommand ref
30187 reference "OMF file"
30188
30189 \end_inset
30190
30191 ) optionally generated by SDCC.
30192 \end_layout
30193
30194 \begin_layout Standard
30195 Debugging On-target: 
30196 \end_layout
30197
30198 \begin_layout Itemize
30199 use a MCU port pin to serially output debug data to the RS232 port of your
30200  host.
30201  You'll probably want some level shifting device typically involving a MAX232
30202  or similar IC.
30203  If the hardware serial port of the MCU is not available search for 'Software
30204  UART' in your favourite search machine.
30205 \end_layout
30206
30207 \begin_layout Itemize
30208 use an on-target monitor.
30209  In this context a monitor is a small program which usually accepts commands
30210  via a serial line and allows to set program counter, to single step through
30211  a program and read/write memory locations.
30212  For the 8051 good examples of monitors are paulmon and cmon51 (see section
30213  
30214 \begin_inset LatexCommand ref
30215 reference "sec:Related-open-source-tools"
30216
30217 \end_inset
30218
30219 ).
30220 \end_layout
30221
30222 \begin_layout Itemize
30223 toggle MCU port pins at strategic points within your code and use an oscilloscop
30224 e.
30225  A 
30226 \emph on
30227 digital oscilloscope
30228 \emph default
30229
30230 \begin_inset LatexCommand index
30231 name "Oscilloscope"
30232
30233 \end_inset
30234
30235  with deep trace memory is really helpful especially if you have to debug
30236  a realtime application.
30237  If you need to monitor more pins than your oscilloscope provides you can
30238  sometimes get away with a small R-2R network.
30239  On a single channel oscilloscope you could f.e.
30240  monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
30241 k
30242 \begin_inset Formula $\Omega$
30243 \end_inset
30244
30245  resistor and the other one by a 5\InsetSpace ~
30246 k
30247 \begin_inset Formula $\Omega$
30248 \end_inset
30249
30250  resistor to the oscilloscope probe (check output drive capability of the
30251  pins you want to monitor).
30252  If you need to monitor many more pins a 
30253 \emph on
30254 logic analyzer
30255 \emph default
30256  will be handy.
30257 \end_layout
30258
30259 \begin_layout Itemize
30260 use an ICE (
30261 \emph on
30262 i
30263 \emph default
30264
30265 \emph on
30266 c
30267 \emph default
30268 ircuit 
30269 \emph on
30270 e
30271 \emph default
30272 mulator
30273 \begin_inset LatexCommand index
30274 name "ICE (in circuit emulator)"
30275
30276 \end_inset
30277
30278 ).
30279  Usually very expensive.
30280  And very nice to have too.
30281  And usually locks you (for years...) to the devices the ICE can emulate.
30282  
30283 \end_layout
30284
30285 \begin_layout Itemize
30286 use a remote debugger.
30287  In most 8-bit systems the symbol information is not available on the target,
30288  and a complete debugger is too bulky for the target system.
30289  Therefore usually a debugger on the host system connects to an on-target
30290  debugging stub which accepts only primitive commands.
30291  
30292 \newline
30293 Terms to enter into your favourite search engine could be 'remote debugging',
30294  'gdb stub' or 'inferior debugger'.
30295  (is there one?)
30296 \end_layout
30297
30298 \begin_layout Itemize
30299 use an on target hardware debugger.
30300  Some of the more modern MCUs include hardware support for setting break
30301  points and monitoring/changing variables by using dedicated hardware pins.
30302  This facility doesn't require additional code to run on the target and
30303  
30304 \emph on
30305 usually
30306 \emph default
30307  doesn't affect runtime behaviour until a breakpoint is hit.
30308  For the mcs51 most hardware debuggers use the AOMF
30309 \begin_inset LatexCommand index
30310 name "AOMF, AOMF51"
30311
30312 \end_inset
30313
30314  file (see 
30315 \begin_inset LatexCommand ref
30316 reference "OMF file"
30317
30318 \end_inset
30319
30320 ) as input file.
30321  
30322 \end_layout
30323
30324 \begin_layout Standard
30325 Last not least:
30326 \end_layout
30327
30328 \begin_layout Itemize
30329 if you are not familiar with any of the following terms you're likely to
30330  run into problems rather sooner than later: 
30331 \emph on
30332 volatile
30333 \emph default
30334
30335 \emph on
30336 atomic
30337 \emph default
30338
30339 \emph on
30340 memory map
30341 \emph default
30342
30343 \emph on
30344 overlay
30345 \emph default
30346 .
30347  As an embedded programmer you 
30348 \emph on
30349 have
30350 \emph default
30351  to know them so why not look them up 
30352 \emph on
30353 before
30354 \emph default
30355  you have problems?)
30356 \end_layout
30357
30358 \begin_layout Itemize
30359 tell someone else about your problem (actually this is a surprisingly effective
30360  means to hunt down the bug even if the listener is not familiar with your
30361  environment).
30362  As 'failure to communicate' is probably one of the job-induced deformations
30363  of an embedded programmer this is highly encouraged.
30364 \end_layout
30365
30366 \begin_layout Section
30367 Debugging with SDCDB
30368 \begin_inset LatexCommand label
30369 name "cha:Debugging-with-SDCDB"
30370
30371 \end_inset
30372
30373
30374 \begin_inset LatexCommand index
30375 name "SDCDB (debugger)"
30376
30377 \end_inset
30378
30379  
30380 \end_layout
30381
30382 \begin_layout Standard
30383 SDCC is distributed with a source level debugger
30384 \begin_inset LatexCommand index
30385 name "Debugger"
30386
30387 \end_inset
30388
30389 .
30390  The debugger uses a command line interface, the command repertoire of the
30391  debugger has been kept as close to gdb
30392 \begin_inset LatexCommand index
30393 name "gdb"
30394
30395 \end_inset
30396
30397  (the GNU debugger) as possible.
30398  The configuration and build process is part of the standard compiler installati
30399 on, which also builds and installs the debugger in the target directory
30400  specified during configuration.
30401  The debugger allows you debug BOTH at the C source and at the ASM source
30402  level.
30403 \end_layout
30404
30405 \begin_layout Subsection
30406 Compiling for Debugging
30407 \end_layout
30408
30409 \begin_layout Standard
30410 The -
30411 \begin_inset ERT
30412 status collapsed
30413
30414 \begin_layout Standard
30415
30416
30417 \backslash
30418 /
30419 \end_layout
30420
30421 \end_inset
30422
30423 -debug
30424 \begin_inset LatexCommand index
30425 name "-\\/-debug"
30426
30427 \end_inset
30428
30429  option must be specified for all files for which debug information is to
30430  be generated.
30431  The compiler generates a .adb file for each of these files.
30432  The linker creates the .cdb
30433 \begin_inset LatexCommand index
30434 name "<file>.cdb"
30435
30436 \end_inset
30437
30438  file from the .adb
30439 \begin_inset LatexCommand index
30440 name "<file>.adb"
30441
30442 \end_inset
30443
30444  files and the address information.
30445  This .cdb is used by the debugger.
30446 \end_layout
30447
30448 \begin_layout Subsection
30449 How the Debugger Works
30450 \end_layout
30451
30452 \begin_layout Standard
30453 When the -
30454 \begin_inset ERT
30455 status collapsed
30456
30457 \begin_layout Standard
30458
30459
30460 \backslash
30461 /
30462 \end_layout
30463
30464 \end_inset
30465
30466 -debug option is specified the compiler generates extra symbol information
30467  some of which are put into the assembler source and some are put into the
30468  .adb file.
30469  Then the linker creates the .cdb file from the individual .adb files with
30470  the address information for the symbols.
30471  The debugger reads the symbolic information generated by the compiler &
30472  the address information generated by the linker.
30473  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
30474  execution is controlled by the debugger.
30475  When a command is issued for the debugger, it translates it into appropriate
30476  commands for the simulator.
30477  (Currently SDCDM only connects to the simulator but 
30478 \emph on
30479 newcdb
30480 \emph default
30481  at 
30482 \begin_inset LatexCommand url
30483 target "http://ec2drv.sf.net/"
30484
30485 \end_inset
30486
30487  is an effort to connect directly to the hardware.) 
30488 \end_layout
30489
30490 \begin_layout Subsection
30491 Starting the Debugger SDCDB
30492 \end_layout
30493
30494 \begin_layout Standard
30495 The debugger can be started using the following command line.
30496  (Assume the file you are debugging has the file name foo).
30497 \newline
30498
30499 \newline
30500
30501 \family sans
30502 \series bold
30503 sdcdb foo
30504 \newline
30505
30506 \family default
30507 \series default
30508
30509 \newline
30510 The debugger will look for the following files.
30511 \end_layout
30512
30513 \begin_layout Itemize
30514 foo.c - the source file.
30515 \end_layout
30516
30517 \begin_layout Itemize
30518 foo.cdb - the debugger symbol information file.
30519 \end_layout
30520
30521 \begin_layout Itemize
30522 foo.ihx - the Intel hex format
30523 \begin_inset LatexCommand index
30524 name "Intel hex format"
30525
30526 \end_inset
30527
30528  object file.
30529 \end_layout
30530
30531 \begin_layout Subsection
30532 SDCDB Command Line Options
30533 \end_layout
30534
30535 \begin_layout Itemize
30536 -
30537 \begin_inset ERT
30538 status collapsed
30539
30540 \begin_layout Standard
30541
30542
30543 \backslash
30544 /
30545 \end_layout
30546
30547 \end_inset
30548
30549 -directory=<source file directory> this option can used to specify the directory
30550  search list.
30551  The debugger will look into the directory list specified for source, cdb
30552  & ihx files.
30553  The items in the directory list must be separated by ':', e.g.
30554  if the source files can be in the directories /home/src1 and /home/src2,
30555  the -
30556 \begin_inset ERT
30557 status collapsed
30558
30559 \begin_layout Standard
30560
30561
30562 \backslash
30563 /
30564 \end_layout
30565
30566 \end_inset
30567
30568 -directory option should be -
30569 \begin_inset ERT
30570 status collapsed
30571
30572 \begin_layout Standard
30573
30574
30575 \backslash
30576 /
30577 \end_layout
30578
30579 \end_inset
30580
30581 -directory=/home/src1:/home/src2.
30582  Note there can be no spaces in the option.
30583  
30584 \end_layout
30585
30586 \begin_layout Itemize
30587 -cd <directory> - change to the <directory>.
30588 \end_layout
30589
30590 \begin_layout Itemize
30591 -fullname - used by GUI front ends.
30592 \end_layout
30593
30594 \begin_layout Itemize
30595 -cpu <cpu-type> - this argument is passed to the simulator please see the
30596  simulator docs for details.
30597 \end_layout
30598
30599 \begin_layout Itemize
30600 -X <Clock frequency > this options is passed to the simulator please see
30601  the simulator docs for details.
30602 \end_layout
30603
30604 \begin_layout Itemize
30605 -s <serial port file> passed to simulator see the simulator docs for details.
30606 \end_layout
30607
30608 \begin_layout Itemize
30609 -S <serial in,out> passed to simulator see the simulator docs for details.
30610 \end_layout
30611
30612 \begin_layout Itemize
30613 -k <port number> passed to simulator see the simulator docs for details.
30614 \end_layout
30615
30616 \begin_layout Subsection
30617 SDCDB Debugger Commands
30618 \end_layout
30619
30620 \begin_layout Standard
30621 As mentioned earlier the command interface for the debugger has been deliberatel
30622 y kept as close the GNU debugger gdb, as possible.
30623  This will help the integration with existing graphical user interfaces
30624  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
30625  If you use a graphical user interface for the debugger you can skip this
30626  section.
30627 \end_layout
30628
30629 \begin_layout Subsubsection*
30630 break [line | file:line | function | file:function]
30631 \end_layout
30632
30633 \begin_layout Standard
30634 Set breakpoint at specified line or function:
30635 \newline
30636
30637 \newline
30638
30639 \family sans
30640 \series bold
30641 sdcdb>break 100 
30642 \newline
30643 sdcdb>break foo.c:100
30644 \newline
30645 sdcdb>break funcfoo
30646 \newline
30647 sdcdb>break foo.c:funcfoo
30648 \end_layout
30649
30650 \begin_layout Subsubsection*
30651 clear [line | file:line | function | file:function ]
30652 \end_layout
30653
30654 \begin_layout Standard
30655 Clear breakpoint at specified line or function:
30656 \newline
30657
30658 \newline
30659
30660 \family sans
30661 \series bold
30662 sdcdb>clear 100
30663 \newline
30664 sdcdb>clear foo.c:100
30665 \newline
30666 sdcdb>clear funcfoo
30667 \newline
30668 sdcdb>clear foo.c:funcfoo
30669 \end_layout
30670
30671 \begin_layout Subsubsection*
30672 continue
30673 \end_layout
30674
30675 \begin_layout Standard
30676 Continue program being debugged, after breakpoint.
30677 \end_layout
30678
30679 \begin_layout Subsubsection*
30680 finish
30681 \end_layout
30682
30683 \begin_layout Standard
30684 Execute till the end of the current function.
30685 \end_layout
30686
30687 \begin_layout Subsubsection*
30688 delete [n]
30689 \end_layout
30690
30691 \begin_layout Standard
30692 Delete breakpoint number 'n'.
30693  If used without any option clear ALL user defined break points.
30694 \end_layout
30695
30696 \begin_layout Subsubsection*
30697 info [break | stack | frame | registers ]
30698 \end_layout
30699
30700 \begin_layout Itemize
30701 info break - list all breakpoints
30702 \end_layout
30703
30704 \begin_layout Itemize
30705 info stack - show the function call stack.
30706 \end_layout
30707
30708 \begin_layout Itemize
30709 info frame - show information about the current execution frame.
30710 \end_layout
30711
30712 \begin_layout Itemize
30713 info registers - show content of all registers.
30714 \end_layout
30715
30716 \begin_layout Subsubsection*
30717 step
30718 \end_layout
30719
30720 \begin_layout Standard
30721 Step program until it reaches a different source line.
30722  Note: pressing <return> repeats the last command.
30723 \end_layout
30724
30725 \begin_layout Subsubsection*
30726 next
30727 \end_layout
30728
30729 \begin_layout Standard
30730 Step program, proceeding through subroutine calls.
30731 \end_layout
30732
30733 \begin_layout Subsubsection*
30734 run
30735 \end_layout
30736
30737 \begin_layout Standard
30738 Start debugged program.
30739 \end_layout
30740
30741 \begin_layout Subsubsection*
30742 ptype variable 
30743 \end_layout
30744
30745 \begin_layout Standard
30746 Print type information of the variable.
30747 \end_layout
30748
30749 \begin_layout Subsubsection*
30750 print variable
30751 \end_layout
30752
30753 \begin_layout Standard
30754 print value of variable.
30755 \end_layout
30756
30757 \begin_layout Subsubsection*
30758 file filename
30759 \end_layout
30760
30761 \begin_layout Standard
30762 load the given file name.
30763  Note this is an alternate method of loading file for debugging.
30764 \end_layout
30765
30766 \begin_layout Subsubsection*
30767 frame
30768 \end_layout
30769
30770 \begin_layout Standard
30771 print information about current frame.
30772 \end_layout
30773
30774 \begin_layout Subsubsection*
30775 set srcmode
30776 \end_layout
30777
30778 \begin_layout Standard
30779 Toggle between C source & assembly source.
30780 \end_layout
30781
30782 \begin_layout Subsubsection*
30783 ! simulator command
30784 \end_layout
30785
30786 \begin_layout Standard
30787 Send the string following '!' to the simulator, the simulator response is
30788  displayed.
30789  Note the debugger does not interpret the command being sent to the simulator,
30790  so if a command like 'go' is sent the debugger can loose its execution
30791  context and may display incorrect values.
30792 \end_layout
30793
30794 \begin_layout Subsubsection*
30795 quit
30796 \end_layout
30797
30798 \begin_layout Standard
30799 "Watch me now.
30800  Iam going Down.
30801  My name is Bobby Brown"
30802 \end_layout
30803
30804 \begin_layout Subsection
30805 Interfacing SDCDB with DDD
30806 \end_layout
30807
30808 \begin_layout Standard
30809 \begin_inset Note Note
30810 status collapsed
30811
30812 \begin_layout Standard
30813 The screenshot was converted from png to eps with: 
30814 \begin_inset Quotes sld
30815 \end_inset
30816
30817 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
30818 \begin_inset Quotes srd
30819 \end_inset
30820
30821  which produces a pretty compact eps file which is free from compression
30822  artifacts.
30823 \end_layout
30824
30825 \begin_layout Standard
30826 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
30827  as this broke the build system on Sourceforge (pdf-file was broken.
30828  pdflatex does not accept eps files).
30829 \end_layout
30830
30831 \end_inset
30832
30833
30834 \end_layout
30835
30836 \begin_layout Standard
30837 The 
30838 \emph on
30839 p
30840 \emph default
30841 ortable 
30842 \emph on
30843 n
30844 \emph default
30845 etwork 
30846 \emph on
30847 g
30848 \emph default
30849 raphics File 
30850 \size footnotesize
30851
30852 \begin_inset LatexCommand url
30853 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png"
30854
30855 \end_inset
30856
30857
30858 \size default
30859  shows a screenshot of a debugging session with DDD
30860 \begin_inset LatexCommand index
30861 name "DDD (debugger)"
30862
30863 \end_inset
30864
30865  (Unix only) on a simulated 8032.
30866  The debugging session might not run as smoothly as the screenshot suggests.
30867  The debugger allows setting of breakpoints, displaying and changing variables,
30868  single stepping through C and assembler code.
30869  
30870 \newline
30871 The source was compiled with 
30872 \family sans
30873 \series bold
30874
30875 \newline
30876
30877 \newline
30878 sdcc -
30879 \family default
30880 \series default
30881
30882 \begin_inset ERT
30883 status collapsed
30884
30885 \begin_layout Standard
30886
30887
30888 \backslash
30889 /
30890 \end_layout
30891
30892 \end_inset
30893
30894
30895 \family sans
30896 \series bold
30897 -debug ddd_example.c
30898 \family default
30899 \series default
30900  
30901 \family sans
30902 \series bold
30903
30904 \newline
30905
30906 \family default
30907 \series default
30908
30909 \newline
30910 and DDD was invoked with 
30911 \family sans
30912 \series bold
30913
30914 \newline
30915
30916 \newline
30917 ddd -debugger "sdcdb -cpu 8032 ddd_example"
30918 \end_layout
30919
30920 \begin_layout Standard
30921 \begin_inset Note Note
30922 status open
30923
30924 \begin_layout Standard
30925 Check that the double quotes or an apostrophe within the command line survive
30926  the LyX tool chain.
30927  Previously the apostrophes got slanted in the PDF output so a cut and paste
30928  did not work.
30929 \end_layout
30930
30931 \end_inset
30932
30933
30934 \end_layout
30935
30936 \begin_layout Subsection
30937 Interfacing SDCDB with XEmacs
30938 \begin_inset LatexCommand index
30939 name "XEmacs"
30940
30941 \end_inset
30942
30943
30944 \begin_inset LatexCommand index
30945 name "Emacs"
30946
30947 \end_inset
30948
30949
30950 \end_layout
30951
30952 \begin_layout Standard
30953 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
30954  sdcdb.el and sdcdbsrc.el.
30955  These two files can be found in the $(prefix)/bin directory after the installat
30956 ion is complete.
30957  These files need to be loaded into XEmacs for the interface to work.
30958  This can be done at XEmacs startup time by inserting the following into
30959  your '.xemacs' file (which can be found in your HOME directory): 
30960 \newline
30961
30962 \newline
30963
30964 \family typewriter
30965 (load-file sdcdbsrc.el)
30966 \family default
30967  
30968 \newline
30969
30970 \newline
30971 .xemacs is a lisp file so the () around the command is REQUIRED.
30972  The files can also be loaded dynamically while XEmacs is running, set the
30973  environment variable 'EMACSLOADPATH' to the installation bin directory
30974  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
30975  To start the interface enter the following command: 
30976 \newline
30977
30978 \newline
30979
30980 \family sans
30981 \series bold
30982 ESC-x sdcdbsrc
30983 \family default
30984 \series default
30985
30986 \newline
30987
30988 \newline
30989 You will prompted to enter the file name to be debugged.
30990  
30991 \newline
30992
30993 \newline
30994 The command line options that are passed to the simulator directly are
30995  bound to default values in the file sdcdbsrc.el.
30996  The variables are listed below, these values maybe changed as required.
30997 \end_layout
30998
30999 \begin_layout Itemize
31000 sdcdbsrc-cpu-type '51
31001 \end_layout
31002
31003 \begin_layout Itemize
31004 sdcdbsrc-frequency '11059200
31005 \end_layout
31006
31007 \begin_layout Itemize
31008 sdcdbsrc-serial nil
31009 \end_layout
31010
31011 \begin_layout Standard
31012 The following is a list of key mapping for the debugger interface.
31013 \end_layout
31014
31015 \begin_layout Standard
31016 \InsetSpace ~
31017
31018 \family typewriter
31019
31020 \newline
31021 ;;\InsetSpace ~
31022 Current Listing :: 
31023 \newline
31024 ;;key\InsetSpace ~
31025 \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 binding\InsetSpace ~
31039 \InsetSpace ~
31040 \InsetSpace ~
31041 \InsetSpace ~
31042 \InsetSpace ~
31043 \InsetSpace ~
31044 \InsetSpace ~
31045 \InsetSpace ~
31046 \InsetSpace ~
31047 \InsetSpace ~
31048 \InsetSpace ~
31049 \InsetSpace ~
31050 \InsetSpace ~
31051 \InsetSpace ~
31052 \InsetSpace ~
31053 \InsetSpace ~
31054 \InsetSpace ~
31055 \InsetSpace ~
31056 \InsetSpace ~
31057 \InsetSpace ~
31058 \InsetSpace ~
31059 \InsetSpace ~
31060 Comment 
31061 \newline
31062 ;;---\InsetSpace ~
31063 \InsetSpace ~
31064 \InsetSpace ~
31065 \InsetSpace ~
31066 \InsetSpace ~
31067 \InsetSpace ~
31068 \InsetSpace ~
31069 \InsetSpace ~
31070 \InsetSpace ~
31071 \InsetSpace ~
31072 \InsetSpace ~
31073 \InsetSpace ~
31074 \InsetSpace ~
31075 \InsetSpace ~
31076 -------\InsetSpace ~
31077 \InsetSpace ~
31078 \InsetSpace ~
31079 \InsetSpace ~
31080 \InsetSpace ~
31081 \InsetSpace ~
31082 \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 \InsetSpace ~
31098 -------
31099 \newline
31100 ;; 
31101 \newline
31102 ;;\InsetSpace ~
31103 n\InsetSpace ~
31104 \InsetSpace ~
31105 \InsetSpace ~
31106 \InsetSpace ~
31107 \InsetSpace ~
31108 \InsetSpace ~
31109 \InsetSpace ~
31110 \InsetSpace ~
31111 \InsetSpace ~
31112 \InsetSpace ~
31113 \InsetSpace ~
31114 \InsetSpace ~
31115 \InsetSpace ~
31116 \InsetSpace ~
31117 \InsetSpace ~
31118 sdcdb-next-fro
31119 m-src\InsetSpace ~
31120 \InsetSpace ~
31121 \InsetSpace ~
31122 \InsetSpace ~
31123 \InsetSpace ~
31124 \InsetSpace ~
31125 \InsetSpace ~
31126 \InsetSpace ~
31127 \InsetSpace ~
31128 \InsetSpace ~
31129 SDCDB next command 
31130 \newline
31131 ;;\InsetSpace ~
31132 b\InsetSpace ~
31133 \InsetSpace ~
31134 \InsetSpace ~
31135 \InsetSpace ~
31136 \InsetSpace ~
31137 \InsetSpace ~
31138 \InsetSpace ~
31139 \InsetSpace ~
31140 \InsetSpace ~
31141 \InsetSpace ~
31142 \InsetSpace ~
31143 \InsetSpace ~
31144 \InsetSpace ~
31145 \InsetSpace ~
31146 \InsetSpace ~
31147 sdcdb-back-from-src\InsetSpace ~
31148 \InsetSpace ~
31149 \InsetSpace ~
31150 \InsetSpace ~
31151 \InsetSpace ~
31152 \InsetSpace ~
31153 \InsetSpace ~
31154 \InsetSpace ~
31155 \InsetSpace ~
31156 \InsetSpace ~
31157 SDCDB back command 
31158 \newline
31159 ;;\InsetSpace ~
31160 c\InsetSpace ~
31161 \InsetSpace ~
31162 \InsetSpace ~
31163 \InsetSpace ~
31164 \InsetSpace ~
31165 \InsetSpace ~
31166 \InsetSpace ~
31167 \InsetSpace ~
31168 \InsetSpace ~
31169 \InsetSpace ~
31170 \InsetSpace ~
31171 \InsetSpace ~
31172 \InsetSpace ~
31173 \InsetSpace ~
31174 \InsetSpace ~
31175 sdcdb-cont-f
31176 rom-src\InsetSpace ~
31177 \InsetSpace ~
31178 \InsetSpace ~
31179 \InsetSpace ~
31180 \InsetSpace ~
31181 \InsetSpace ~
31182 \InsetSpace ~
31183 \InsetSpace ~
31184 \InsetSpace ~
31185 \InsetSpace ~
31186 SDCDB continue command
31187 \newline
31188 ;;\InsetSpace ~
31189 s\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 sdcdb-step-from-src\InsetSpace ~
31205 \InsetSpace ~
31206 \InsetSpace ~
31207 \InsetSpace ~
31208 \InsetSpace ~
31209 \InsetSpace ~
31210 \InsetSpace ~
31211 \InsetSpace ~
31212 \InsetSpace ~
31213 \InsetSpace ~
31214 SDCDB step command 
31215 \newline
31216 ;;\InsetSpace ~
31217 ?\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 sdcdb-w
31233 hatis-c-sexp\InsetSpace ~
31234 \InsetSpace ~
31235 \InsetSpace ~
31236 \InsetSpace ~
31237 \InsetSpace ~
31238 \InsetSpace ~
31239 \InsetSpace ~
31240 \InsetSpace ~
31241 \InsetSpace ~
31242 \InsetSpace ~
31243 SDCDB ptypecommand for data at 
31244 \newline
31245 ;;\InsetSpace ~
31246 \InsetSpace ~
31247 \InsetSpace ~
31248 \InsetSpace ~
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 buffer point 
31293 \newline
31294 ;;\InsetSpace ~
31295 x\InsetSpace ~
31296 \InsetSpace ~
31297 \InsetSpace ~
31298 \InsetSpace ~
31299 \InsetSpace ~
31300 \InsetSpace ~
31301 \InsetSpace ~
31302 \InsetSpace ~
31303 \InsetSpace ~
31304 \InsetSpace ~
31305 \InsetSpace ~
31306 \InsetSpace ~
31307 \InsetSpace ~
31308 \InsetSpace ~
31309 \InsetSpace ~
31310 sdcdbsrc-delete\InsetSpace ~
31311 \InsetSpace ~
31312 \InsetSpace ~
31313 \InsetSpace ~
31314 \InsetSpace ~
31315 \InsetSpace ~
31316 \InsetSpace ~
31317 \InsetSpace ~
31318 \InsetSpace ~
31319 \InsetSpace ~
31320 \InsetSpace ~
31321 \InsetSpace ~
31322 \InsetSpace ~
31323 \InsetSpace ~
31324 SDCD
31325 B Delete all breakpoints if no arg 
31326 \newline
31327 ;;\InsetSpace ~
31328 \InsetSpace ~
31329 \InsetSpace ~
31330 \InsetSpace ~
31331 \InsetSpace ~
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 given or delete arg (C-u arg x) 
31375 \newline
31376 ;;\InsetSpace ~
31377 m\InsetSpace ~
31378 \InsetSpace ~
31379 \InsetSpace ~
31380 \InsetSpace ~
31381 \InsetSpace ~
31382 \InsetSpace ~
31383 \InsetSpace ~
31384 \InsetSpace ~
31385 \InsetSpace ~
31386 \InsetSpace ~
31387 \InsetSpace ~
31388 \InsetSpace ~
31389 \InsetSpace ~
31390 \InsetSpace ~
31391 \InsetSpace ~
31392 sdcdbsrc
31393 -frame\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 SDCDB Display current frame if no arg, 
31409 \newline
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 \InsetSpace ~
31430 \InsetSpace ~
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 \InsetSpace ~
31448 \InsetSpace ~
31449 \InsetSpace ~
31450 \InsetSpace ~
31451 \InsetSpace ~
31452 \InsetSpace ~
31453 \InsetSpace ~
31454 \InsetSpace ~
31455 \InsetSpace ~
31456 \InsetSpace ~
31457 given or display frame arg
31458  
31459 \newline
31460 ;;\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 \InsetSpace ~
31476 \InsetSpace ~
31477 \InsetSpace ~
31478 \InsetSpace ~
31479 \InsetSpace ~
31480 \InsetSpace ~
31481 \InsetSpace ~
31482 \InsetSpace ~
31483 \InsetSpace ~
31484 \InsetSpace ~
31485 \InsetSpace ~
31486 \InsetSpace ~
31487 \InsetSpace ~
31488 \InsetSpace ~
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 buffer point 
31508 \newline
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 sdcdbsrc-goto-sdcdb\InsetSpace ~
31526 \InsetSpace ~
31527 \InsetSpace ~
31528 \InsetSpace ~
31529 \InsetSpace ~
31530 \InsetSpace ~
31531 \InsetSpace ~
31532 \InsetSpace ~
31533 \InsetSpace ~
31534 \InsetSpace ~
31535 Goto the SDCDB output buffer 
31536 \newline
31537 ;;\InsetSpace ~
31538 p\InsetSpace ~
31539 \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 sdcdb-prin
31554 t-c-sexp\InsetSpace ~
31555 \InsetSpace ~
31556 \InsetSpace ~
31557 \InsetSpace ~
31558 \InsetSpace ~
31559 \InsetSpace ~
31560 \InsetSpace ~
31561 \InsetSpace ~
31562 \InsetSpace ~
31563 \InsetSpace ~
31564 \InsetSpace ~
31565 SDCDB print command for data at 
31566 \newline
31567 ;;\InsetSpace ~
31568 \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 \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 \InsetSpace ~
31600 \InsetSpace ~
31601 \InsetSpace ~
31602 \InsetSpace ~
31603 \InsetSpace ~
31604 \InsetSpace ~
31605 \InsetSpace ~
31606 \InsetSpace ~
31607 \InsetSpace ~
31608 \InsetSpace ~
31609 \InsetSpace ~
31610 \InsetSpace ~
31611 \InsetSpace ~
31612 \InsetSpace ~
31613 \InsetSpace ~
31614 buffer point 
31615 \newline
31616 ;;\InsetSpace ~
31617 g\InsetSpace ~
31618 \InsetSpace ~
31619 \InsetSpace ~
31620 \InsetSpace ~
31621 \InsetSpace ~
31622 \InsetSpace ~
31623 \InsetSpace ~
31624 \InsetSpace ~
31625 \InsetSpace ~
31626 \InsetSpace ~
31627 \InsetSpace ~
31628 \InsetSpace ~
31629 \InsetSpace ~
31630 \InsetSpace ~
31631 \InsetSpace ~
31632 sdcdbsrc-goto-sdcdb\InsetSpace ~
31633 \InsetSpace ~
31634 \InsetSpace ~
31635 \InsetSpace ~
31636 \InsetSpace ~
31637 \InsetSpace ~
31638 \InsetSpace ~
31639 \InsetSpace ~
31640 \InsetSpace ~
31641 \InsetSpace ~
31642 Got
31643 o the SDCDB output buffer 
31644 \newline
31645 ;;\InsetSpace ~
31646 t\InsetSpace ~
31647 \InsetSpace ~
31648 \InsetSpace ~
31649 \InsetSpace ~
31650 \InsetSpace ~
31651 \InsetSpace ~
31652 \InsetSpace ~
31653 \InsetSpace ~
31654 \InsetSpace ~
31655 \InsetSpace ~
31656 \InsetSpace ~
31657 \InsetSpace ~
31658 \InsetSpace ~
31659 \InsetSpace ~
31660 \InsetSpace ~
31661 sdcdbsrc-mode\InsetSpace ~
31662 \InsetSpace ~
31663 \InsetSpace ~
31664 \InsetSpace ~
31665 \InsetSpace ~
31666 \InsetSpace ~
31667 \InsetSpace ~
31668 \InsetSpace ~
31669 \InsetSpace ~
31670 \InsetSpace ~
31671 \InsetSpace ~
31672 \InsetSpace ~
31673 \InsetSpace ~
31674 \InsetSpace ~
31675 \InsetSpace ~
31676 \InsetSpace ~
31677 Toggles Sdcdbsrc mode (turns it
31678  off) 
31679 \newline
31680 ;; 
31681 \newline
31682 ;;\InsetSpace ~
31683 C-c\InsetSpace ~
31684 C-f\InsetSpace ~
31685 \InsetSpace ~
31686 \InsetSpace ~
31687 \InsetSpace ~
31688 \InsetSpace ~
31689 \InsetSpace ~
31690 \InsetSpace ~
31691 \InsetSpace ~
31692 \InsetSpace ~
31693 sdcdb-finish-from-src\InsetSpace ~
31694 \InsetSpace ~
31695 \InsetSpace ~
31696 \InsetSpace ~
31697 \InsetSpace ~
31698 \InsetSpace ~
31699 \InsetSpace ~
31700 \InsetSpace ~
31701 SDCDB finish command 
31702 \newline
31703 ;; 
31704 \newline
31705 ;;\InsetSpace ~
31706 C-x\InsetSpace ~
31707 SPC\InsetSpace ~
31708 \InsetSpace ~
31709 \InsetSpace ~
31710 \InsetSpace ~
31711 \InsetSpace ~
31712 \InsetSpace ~
31713 \InsetSpace ~
31714 \InsetSpace ~
31715 \InsetSpace ~
31716 sdcdb-brea
31717 k\InsetSpace ~
31718 \InsetSpace ~
31719 \InsetSpace ~
31720 \InsetSpace ~
31721 \InsetSpace ~
31722 \InsetSpace ~
31723 \InsetSpace ~
31724 \InsetSpace ~
31725 \InsetSpace ~
31726 \InsetSpace ~
31727 \InsetSpace ~
31728 \InsetSpace ~
31729 \InsetSpace ~
31730 \InsetSpace ~
31731 \InsetSpace ~
31732 \InsetSpace ~
31733 \InsetSpace ~
31734 \InsetSpace ~
31735 Set break for line with point 
31736 \newline
31737 ;;\InsetSpace ~
31738 ESC\InsetSpace ~
31739 t\InsetSpace ~
31740 \InsetSpace ~
31741 \InsetSpace ~
31742 \InsetSpace ~
31743 \InsetSpace ~
31744 \InsetSpace ~
31745 \InsetSpace ~
31746 \InsetSpace ~
31747 \InsetSpace ~
31748 \InsetSpace ~
31749 \InsetSpace ~
31750 sdcdbsrc-mode\InsetSpace ~
31751 \InsetSpace ~
31752 \InsetSpace ~
31753 \InsetSpace ~
31754 \InsetSpace ~
31755 \InsetSpace ~
31756 \InsetSpace ~
31757 \InsetSpace ~
31758 \InsetSpace ~
31759 \InsetSpace ~
31760 \InsetSpace ~
31761 \InsetSpace ~
31762 \InsetSpace ~
31763 \InsetSpace ~
31764 \InsetSpace ~
31765 \InsetSpace ~
31766 Toggle Sdcdbsrc mode 
31767 \newline
31768 ;;\InsetSpace ~
31769 ESC\InsetSpace ~
31770 m\InsetSpace ~
31771 \InsetSpace ~
31772 \InsetSpace ~
31773 \InsetSpace ~
31774 \InsetSpace ~
31775 \InsetSpace ~
31776 \InsetSpace ~
31777 \InsetSpace ~
31778 \InsetSpace ~
31779 \InsetSpace ~
31780 \InsetSpace ~
31781 sdc
31782 dbsrc-srcmode\InsetSpace ~
31783 \InsetSpace ~
31784 \InsetSpace ~
31785 \InsetSpace ~
31786 \InsetSpace ~
31787 \InsetSpace ~
31788 \InsetSpace ~
31789 \InsetSpace ~
31790 \InsetSpace ~
31791 \InsetSpace ~
31792 \InsetSpace ~
31793 \InsetSpace ~
31794 \InsetSpace ~
31795 Toggle list mode 
31796 \newline
31797 ;; 
31798 \newline
31799
31800 \family default
31801
31802 \newpage
31803
31804 \end_layout
31805
31806 \begin_layout Chapter
31807 TIPS
31808 \end_layout
31809
31810 \begin_layout Standard
31811 Here are a few guidelines that will help the compiler generate more efficient
31812  code, some of the tips are specific to this compiler others are generally
31813  good programming practice.
31814 \end_layout
31815
31816 \begin_layout Itemize
31817 Use the smallest data type to represent your data-value.
31818  If it is known in advance that the value is going to be less than 256 then
31819  use an 'unsigned char' instead of a 'short' or 'int'.
31820  Please note, that ANSI C requires both signed and unsigned chars to be
31821  promoted to 'signed int'
31822 \begin_inset LatexCommand index
31823 name "promotion to signed int"
31824
31825 \end_inset
31826
31827
31828 \begin_inset Marginal
31829 status collapsed
31830
31831 \begin_layout Standard
31832
31833 \series bold
31834 \InsetSpace ~
31835 !
31836 \end_layout
31837
31838 \end_inset
31839
31840  before doing any operation.
31841  This promotion
31842 \begin_inset LatexCommand index
31843 name "type promotion"
31844
31845 \end_inset
31846
31847
31848 \begin_inset LatexCommand label
31849 name "type promotion"
31850
31851 \end_inset
31852
31853  can be omitted, if the result is the same.
31854  The effect of the promotion rules together with the sign-extension is often
31855  surprising:
31856 \end_layout
31857
31858 \begin_deeper
31859 \begin_layout Verse
31860
31861 \family typewriter
31862 unsigned char uc = 0xfe;
31863 \newline
31864 if (uc * uc < 0) /* this is true! */
31865 \newline
31866 {
31867 \newline
31868 \InsetSpace ~
31869 \InsetSpace ~
31870 \InsetSpace ~
31871 \InsetSpace ~
31872 ....
31873 \newline
31874 }
31875 \end_layout
31876
31877 \begin_layout Standard
31878
31879 \family typewriter
31880 uc * uc
31881 \family default
31882  is evaluated as 
31883 \family typewriter
31884 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
31885 \family default
31886 .
31887  
31888 \newline
31889 Another one:
31890 \end_layout
31891
31892 \begin_layout Verse
31893
31894 \family typewriter
31895 (unsigned char) -12 / (signed char) -3 = ...
31896 \end_layout
31897
31898 \begin_layout Standard
31899 No, the result is not 4:
31900 \end_layout
31901
31902 \begin_layout Verse
31903
31904 \family typewriter
31905 (int) (unsigned char) -12 / (int) (signed char) -3 =
31906 \newline
31907 (int) (unsigned char)
31908  0xf4 / (int) (signed char) 0xfd =
31909 \newline
31910 (int) 0x00f4 / (int) 0xfffd =
31911 \newline
31912 (int) 0x00f4
31913  / (int) 0xfffd =
31914 \newline
31915 (int) 244 / (int) -3 =
31916 \newline
31917 (int) -81 = (int) 0xffaf;
31918 \end_layout
31919
31920 \begin_layout Standard
31921 Don't complain, that gcc gives you a different result.
31922  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
31923  Therefore the results are different.
31924 \newline
31925 From 
31926 \begin_inset Quotes sld
31927 \end_inset
31928
31929 comp.lang.c FAQ
31930 \begin_inset Quotes srd
31931 \end_inset
31932
31933 :
31934 \end_layout
31935
31936 \begin_layout Quote
31937
31938 \emph on
31939 If well-defined overflow characteristics are important and negative values
31940  are not, or if you want to steer clear of sign-extension problems when
31941  manipulating bits or bytes, use one of the corresponding unsigned types.
31942  (Beware when mixing signed and unsigned values in expressions, though.)
31943 \newline
31944 Although
31945  character types (especially unsigned char) can be used as "tiny" integers,
31946  doing so is sometimes more trouble than it's worth, due to unpredictable
31947  sign extension and increased code size.
31948 \end_layout
31949
31950 \end_deeper
31951 \begin_layout Itemize
31952 Use unsigned when it is known in advance that the value is not going to
31953  be negative.
31954  This helps especially if you are doing division or multiplication, bit-shifting
31955  or are using an array index.
31956 \end_layout
31957
31958 \begin_layout Itemize
31959 NEVER jump into a LOOP.
31960 \end_layout
31961
31962 \begin_layout Itemize
31963 Declare the variables to be local
31964 \begin_inset LatexCommand index
31965 name "local variables"
31966
31967 \end_inset
31968
31969  whenever possible, especially loop control variables (induction).
31970 \end_layout
31971
31972 \begin_layout Itemize
31973 Have a look at the assembly listing to get a 
31974 \begin_inset Quotes sld
31975 \end_inset
31976
31977 feeling
31978 \begin_inset Quotes srd
31979 \end_inset
31980
31981  for the code generation.
31982 \end_layout
31983
31984 \begin_layout Section
31985 Porting code from or to other compilers
31986 \begin_inset LatexCommand label
31987 name "sec:Porting-code-to-other-compilers"
31988
31989 \end_inset
31990
31991
31992 \end_layout
31993
31994 \begin_layout Itemize
31995 check whether endianness of the compilers differs and adapt where needed.
31996 \end_layout
31997
31998 \begin_layout Itemize
31999 check the device specific header files
32000 \begin_inset LatexCommand index
32001 name "Header files"
32002
32003 \end_inset
32004
32005
32006 \begin_inset LatexCommand index
32007 name "Include files"
32008
32009 \end_inset
32010
32011  for compiler specific syntax.
32012  Eventually include the file <compiler.h
32013 \begin_inset LatexCommand index
32014 name "compiler.h (include file)"
32015
32016 \end_inset
32017
32018
32019 \begin_inset LatexCommand url
32020 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup"
32021
32022 \end_inset
32023
32024  to allow using common header files.
32025  (see f.e.
32026  cc2510fx.h 
32027 \begin_inset LatexCommand url
32028 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup"
32029
32030 \end_inset
32031
32032 ).
32033 \end_layout
32034
32035 \begin_layout Itemize
32036 check whether the startup code contains the correct initialization (watchdog,
32037  peripherals).
32038 \end_layout
32039
32040 \begin_layout Itemize
32041 check whether the sizes of short, int, long match.
32042 \end_layout
32043
32044 \begin_layout Itemize
32045 check if some 16 or 32 bit hardware registers require a specific addressing
32046  order (least significant or most significant byte first) and adapt if needed
32047  (
32048 \emph on
32049 first
32050 \emph default
32051  and 
32052 \emph on
32053 last
32054 \emph default
32055  relate to time and not to lower/upper memory location here, so this is
32056  
32057 \emph on
32058 not
32059 \emph default
32060  the same as endianness).
32061 \end_layout
32062
32063 \begin_layout Itemize
32064 check whether the keyword 
32065 \emph on
32066 volatile
32067 \emph default
32068  is used where needed.
32069  The compilers might differ in their optimization characteristics (as different
32070  versions of the same compiler might also use more clever optimizations
32071  this is good idea anyway).
32072  See section 
32073 \begin_inset LatexCommand ref
32074 reference "sub:Common-interrupt-pitfall-volatile"
32075
32076 \end_inset
32077
32078 .
32079 \end_layout
32080
32081 \begin_layout Itemize
32082 check that the compilers are not told to suppress warnings.
32083 \end_layout
32084
32085 \begin_layout Itemize
32086 check and convert compiler specific extensions (interrupts, memory areas,
32087  pragmas etc.).
32088 \end_layout
32089
32090 \begin_layout Itemize
32091 check for differences in type promotion.
32092  Especially check for math operations on 
32093 \family typewriter
32094 char
32095 \family default
32096  or 
32097 \family typewriter
32098 unsigned char
32099 \family default
32100  variables.
32101  For the sake of C99 compatibility SDCC will probably promote these to 
32102 \family typewriter
32103 int
32104 \family default
32105  more often than other compilers.
32106  Eventually insert explicit casts to 
32107 \family typewriter
32108 (char)
32109 \family default
32110  or 
32111 \family typewriter
32112 (unsigned char)
32113 \family default
32114 .
32115  Also check that the ~\InsetSpace ~
32116 operator
32117 \begin_inset LatexCommand index
32118 name "\\~\\/ Operator"
32119
32120 \end_inset
32121
32122  is not used on 
32123 \family typewriter
32124 bit
32125 \begin_inset LatexCommand index
32126 name "bit"
32127
32128 \end_inset
32129
32130
32131 \family default
32132  variables, use the !\InsetSpace ~
32133 operator instead.
32134  See sections 
32135 \begin_inset LatexCommand ref
32136 reference "type promotion"
32137
32138 \end_inset
32139
32140  and 
32141 \begin_inset LatexCommand ref
32142 reference "sec:Compatibility-with-previous"
32143
32144 \end_inset
32145
32146 .
32147 \end_layout
32148
32149 \begin_layout Itemize
32150 check the assembly code generated for interrupt routines (f.e.
32151  for calls to possibly non-reentrant library functions).
32152 \end_layout
32153
32154 \begin_layout Itemize
32155 check whether timing loops result in proper timing (or preferably consider
32156  a rewrite of the code with timer based delays instead).
32157 \end_layout
32158
32159 \begin_layout Itemize
32160 check for differences in printf parameters (some compilers push (va_arg
32161 \begin_inset LatexCommand index
32162 name "vararg, va\\_arg"
32163
32164 \end_inset
32165
32166 ) char variables as 
32167 \family typewriter
32168 int
32169 \family default
32170  others push them as 
32171 \family typewriter
32172 char
32173 \family default
32174 .
32175  See section 
32176 \begin_inset LatexCommand ref
32177 reference "sec:Compatibility-with-previous"
32178
32179 \end_inset
32180
32181 ).
32182 \end_layout
32183
32184 \begin_layout Itemize
32185 check the resulting memory map
32186 \begin_inset LatexCommand index
32187 name "Memory map"
32188
32189 \end_inset
32190
32191 .
32192  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
32193 ly idata, pdata, xdata).
32194  Eventually check if unexpected library functions are included.
32195 \end_layout
32196
32197 \begin_layout Section
32198 Tools
32199 \begin_inset LatexCommand index
32200 name "Tools"
32201
32202 \end_inset
32203
32204  included in the distribution
32205 \end_layout
32206
32207 \begin_layout Standard
32208 \align left
32209 \begin_inset Tabular
32210 <lyxtabular version="3" rows="12" columns="3">
32211 <features>
32212 <column alignment="left" valignment="top" leftline="true" width="0pt">
32213 <column alignment="left" valignment="top" leftline="true" width="0pt">
32214 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
32215 <row topline="true" bottomline="true">
32216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32217 \begin_inset Text
32218
32219 \begin_layout Standard
32220
32221 \series bold
32222 Name
32223 \end_layout
32224
32225 \end_inset
32226 </cell>
32227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32228 \begin_inset Text
32229
32230 \begin_layout Standard
32231
32232 \series bold
32233 Purpose
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
32243 \series bold
32244 Directory
32245 \end_layout
32246
32247 \end_inset
32248 </cell>
32249 </row>
32250 <row topline="true">
32251 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32252 \begin_inset Text
32253
32254 \begin_layout Standard
32255 uCsim
32256 \begin_inset LatexCommand index
32257 name "uCsim"
32258
32259 \end_inset
32260
32261
32262 \end_layout
32263
32264 \end_inset
32265 </cell>
32266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32267 \begin_inset Text
32268
32269 \begin_layout Standard
32270 Simulator for various architectures
32271 \end_layout
32272
32273 \end_inset
32274 </cell>
32275 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32276 \begin_inset Text
32277
32278 \begin_layout Standard
32279 sdcc/sim/ucsim
32280 \end_layout
32281
32282 \end_inset
32283 </cell>
32284 </row>
32285 <row topline="true">
32286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32287 \begin_inset Text
32288
32289 \begin_layout Standard
32290 keil2sdcc.pl
32291 \end_layout
32292
32293 \end_inset
32294 </cell>
32295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32296 \begin_inset Text
32297
32298 \begin_layout Standard
32299 header file
32300 \begin_inset LatexCommand index
32301 name "Header files"
32302
32303 \end_inset
32304
32305
32306 \begin_inset LatexCommand index
32307 name "Include files"
32308
32309 \end_inset
32310
32311  conversion
32312 \end_layout
32313
32314 \end_inset
32315 </cell>
32316 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32317 \begin_inset Text
32318
32319 \begin_layout Standard
32320 sdcc/support/scripts
32321 \end_layout
32322
32323 \end_inset
32324 </cell>
32325 </row>
32326 <row topline="true">
32327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32328 \begin_inset Text
32329
32330 \begin_layout Standard
32331 mh2h.c
32332 \end_layout
32333
32334 \end_inset
32335 </cell>
32336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32337 \begin_inset Text
32338
32339 \begin_layout Standard
32340 header file conversion
32341 \end_layout
32342
32343 \end_inset
32344 </cell>
32345 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32346 \begin_inset Text
32347
32348 \begin_layout Standard
32349 sdcc/support/scripts
32350 \end_layout
32351
32352 \end_inset
32353 </cell>
32354 </row>
32355 <row topline="true">
32356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32357 \begin_inset Text
32358
32359 \begin_layout Standard
32360 as-gbz80
32361 \end_layout
32362
32363 \end_inset
32364 </cell>
32365 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32366 \begin_inset Text
32367
32368 \begin_layout Standard
32369 Assembler
32370 \end_layout
32371
32372 \end_inset
32373 </cell>
32374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32375 \begin_inset Text
32376
32377 \begin_layout Standard
32378
32379 \family roman
32380 \series medium
32381 \shape up
32382 \size normal
32383 \emph off
32384 \bar no
32385 \noun off
32386 \color none
32387 sdcc/bin
32388 \end_layout
32389
32390 \end_inset
32391 </cell>
32392 </row>
32393 <row topline="true">
32394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32395 \begin_inset Text
32396
32397 \begin_layout Standard
32398 as-z80
32399 \end_layout
32400
32401 \end_inset
32402 </cell>
32403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32404 \begin_inset Text
32405
32406 \begin_layout Standard
32407 Assembler
32408 \end_layout
32409
32410 \end_inset
32411 </cell>
32412 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32413 \begin_inset Text
32414
32415 \begin_layout Standard
32416
32417 \family roman
32418 \series medium
32419 \shape up
32420 \size normal
32421 \emph off
32422 \bar no
32423 \noun off
32424 \color none
32425 sdcc/bin
32426 \end_layout
32427
32428 \end_inset
32429 </cell>
32430 </row>
32431 <row topline="true">
32432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32433 \begin_inset Text
32434
32435 \begin_layout Standard
32436 asx8051
32437 \end_layout
32438
32439 \end_inset
32440 </cell>
32441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32442 \begin_inset Text
32443
32444 \begin_layout Standard
32445 Assembler
32446 \end_layout
32447
32448 \end_inset
32449 </cell>
32450 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32451 \begin_inset Text
32452
32453 \begin_layout Standard
32454
32455 \family roman
32456 \series medium
32457 \shape up
32458 \size normal
32459 \emph off
32460 \bar no
32461 \noun off
32462 \color none
32463 sdcc/bin
32464 \end_layout
32465
32466 \end_inset
32467 </cell>
32468 </row>
32469 <row topline="true">
32470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32471 \begin_inset Text
32472
32473 \begin_layout Standard
32474 SDCDB
32475 \end_layout
32476
32477 \end_inset
32478 </cell>
32479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32480 \begin_inset Text
32481
32482 \begin_layout Standard
32483 Simulator
32484 \end_layout
32485
32486 \end_inset
32487 </cell>
32488 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32489 \begin_inset Text
32490
32491 \begin_layout Standard
32492
32493 \family roman
32494 \series medium
32495 \shape up
32496 \size normal
32497 \emph off
32498 \bar no
32499 \noun off
32500 \color none
32501 sdcc/bin
32502 \end_layout
32503
32504 \end_inset
32505 </cell>
32506 </row>
32507 <row topline="true">
32508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32509 \begin_inset Text
32510
32511 \begin_layout Standard
32512 aslink
32513 \end_layout
32514
32515 \end_inset
32516 </cell>
32517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32518 \begin_inset Text
32519
32520 \begin_layout Standard
32521 Linker
32522 \end_layout
32523
32524 \end_inset
32525 </cell>
32526 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32527 \begin_inset Text
32528
32529 \begin_layout Standard
32530
32531 \family roman
32532 \series medium
32533 \shape up
32534 \size normal
32535 \emph off
32536 \bar no
32537 \noun off
32538 \color none
32539 sdcc/bin
32540 \end_layout
32541
32542 \end_inset
32543 </cell>
32544 </row>
32545 <row topline="true">
32546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32547 \begin_inset Text
32548
32549 \begin_layout Standard
32550 link-z80
32551 \end_layout
32552
32553 \end_inset
32554 </cell>
32555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32556 \begin_inset Text
32557
32558 \begin_layout Standard
32559 Linker
32560 \end_layout
32561
32562 \end_inset
32563 </cell>
32564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32565 \begin_inset Text
32566
32567 \begin_layout Standard
32568
32569 \family roman
32570 \series medium
32571 \shape up
32572 \size normal
32573 \emph off
32574 \bar no
32575 \noun off
32576 \color none
32577 sdcc/bin
32578 \end_layout
32579
32580 \end_inset
32581 </cell>
32582 </row>
32583 <row topline="true">
32584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32585 \begin_inset Text
32586
32587 \begin_layout Standard
32588 link-gbz80
32589 \end_layout
32590
32591 \end_inset
32592 </cell>
32593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32594 \begin_inset Text
32595
32596 \begin_layout Standard
32597 Linker
32598 \end_layout
32599
32600 \end_inset
32601 </cell>
32602 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32603 \begin_inset Text
32604
32605 \begin_layout Standard
32606
32607 \family roman
32608 \series medium
32609 \shape up
32610 \size normal
32611 \emph off
32612 \bar no
32613 \noun off
32614 \color none
32615 sdcc/bin
32616 \end_layout
32617
32618 \end_inset
32619 </cell>
32620 </row>
32621 <row topline="true" bottomline="true">
32622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32623 \begin_inset Text
32624
32625 \begin_layout Standard
32626 packihx
32627 \end_layout
32628
32629 \end_inset
32630 </cell>
32631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32632 \begin_inset Text
32633
32634 \begin_layout Standard
32635 Intel Hex packer 
32636 \begin_inset LatexCommand index
32637 name "packihx (tool)"
32638
32639 \end_inset
32640
32641
32642 \end_layout
32643
32644 \end_inset
32645 </cell>
32646 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32647 \begin_inset Text
32648
32649 \begin_layout Standard
32650
32651 \family roman
32652 \series medium
32653 \shape up
32654 \size normal
32655 \emph off
32656 \bar no
32657 \noun off
32658 \color none
32659 sdcc/bin
32660 \end_layout
32661
32662 \end_inset
32663 </cell>
32664 </row>
32665 </lyxtabular>
32666
32667 \end_inset
32668
32669
32670 \newline
32671
32672 \end_layout
32673
32674 \begin_layout Section
32675 Documentation
32676 \begin_inset LatexCommand index
32677 name "Documentation"
32678
32679 \end_inset
32680
32681  included in the distribution
32682 \end_layout
32683
32684 \begin_layout Standard
32685 \align left
32686 \begin_inset Tabular
32687 <lyxtabular version="3" rows="10" columns="2">
32688 <features>
32689 <column alignment="block" valignment="top" leftline="true" width="40col%">
32690 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
32691 <row topline="true" bottomline="true" endhead="true">
32692 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32693 \begin_inset Text
32694
32695 \begin_layout Standard
32696
32697 \series bold
32698 Subject / Title
32699 \end_layout
32700
32701 \end_inset
32702 </cell>
32703 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32704 \begin_inset Text
32705
32706 \begin_layout Standard
32707
32708 \series bold
32709 Filename / Where to get
32710 \end_layout
32711
32712 \end_inset
32713 </cell>
32714 </row>
32715 <row topline="true">
32716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32717 \begin_inset Text
32718
32719 \begin_layout Standard
32720 SDCC Compiler User Guide
32721 \end_layout
32722
32723 \end_inset
32724 </cell>
32725 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32726 \begin_inset Text
32727
32728 \begin_layout Standard
32729 You're reading it right now 
32730 \emph on
32731 \InsetSpace ~
32732 \InsetSpace ~
32733 \InsetSpace ~
32734
32735 \hfill
32736 online at:
32737 \emph default
32738
32739 \newline
32740
32741 \begin_inset LatexCommand url
32742 target "http://sdcc.sourceforge.net/doc/sdccman.pdf"
32743
32744 \end_inset
32745
32746
32747 \end_layout
32748
32749 \end_inset
32750 </cell>
32751 </row>
32752 <row topline="true">
32753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32754 \begin_inset Text
32755
32756 \begin_layout Standard
32757 Changelog of SDCC
32758 \end_layout
32759
32760 \end_inset
32761 </cell>
32762 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32763 \begin_inset Text
32764
32765 \begin_layout Standard
32766 sdcc/Changelog 
32767 \emph on
32768 \InsetSpace ~
32769 \InsetSpace ~
32770 \InsetSpace ~
32771
32772 \hfill
32773 online at:
32774 \emph default
32775
32776 \newline
32777
32778 \begin_inset LatexCommand url
32779 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog"
32780
32781 \end_inset
32782
32783
32784 \end_layout
32785
32786 \end_inset
32787 </cell>
32788 </row>
32789 <row topline="true">
32790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32791 \begin_inset Text
32792
32793 \begin_layout Standard
32794 ASXXXX
32795 \begin_inset LatexCommand index
32796 name "asXXXX (as-gbz80, as-hc08, asx8051, as-z80)"
32797
32798 \end_inset
32799
32800
32801 \begin_inset LatexCommand index
32802 name "Assembler documentation"
32803
32804 \end_inset
32805
32806  Assemblers and
32807 \newline
32808 ASLINK
32809 \begin_inset LatexCommand index
32810 name "aslink"
32811
32812 \end_inset
32813
32814
32815 \begin_inset LatexCommand index
32816 name "Linker documentation"
32817
32818 \end_inset
32819
32820  Relocating Linker
32821 \end_layout
32822
32823 \end_inset
32824 </cell>
32825 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32826 \begin_inset Text
32827
32828 \begin_layout Standard
32829 sdcc/as/doc/asxhtm.html 
32830 \emph on
32831 \InsetSpace ~
32832 \InsetSpace ~
32833 \InsetSpace ~
32834
32835 \hfill
32836 online at:
32837 \emph default
32838
32839 \newline
32840
32841 \begin_inset LatexCommand url
32842 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html"
32843
32844 \end_inset
32845
32846
32847 \end_layout
32848
32849 \end_inset
32850 </cell>
32851 </row>
32852 <row topline="true">
32853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32854 \begin_inset Text
32855
32856 \begin_layout Standard
32857 SDCC regression test
32858 \begin_inset LatexCommand index
32859 name "Regression test"
32860
32861 \end_inset
32862
32863
32864 \end_layout
32865
32866 \end_inset
32867 </cell>
32868 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32869 \begin_inset Text
32870
32871 \begin_layout Standard
32872 sdcc/doc/test_suite_spec.pdf 
32873 \emph on
32874 \InsetSpace ~
32875 \InsetSpace ~
32876 \InsetSpace ~
32877
32878 \hfill
32879 online at:
32880 \emph default
32881
32882 \newline
32883
32884 \begin_inset LatexCommand url
32885 target "http://sdcc.sourceforge.net/doc/test_suite_spec.pdf"
32886
32887 \end_inset
32888
32889
32890 \end_layout
32891
32892 \end_inset
32893 </cell>
32894 </row>
32895 <row topline="true">
32896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32897 \begin_inset Text
32898
32899 \begin_layout Standard
32900 Various notes
32901 \end_layout
32902
32903 \end_inset
32904 </cell>
32905 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32906 \begin_inset Text
32907
32908 \begin_layout Standard
32909 sdcc/doc/* 
32910 \emph on
32911 \InsetSpace ~
32912 \InsetSpace ~
32913 \InsetSpace ~
32914
32915 \hfill
32916 online at:
32917 \emph default
32918
32919 \newline
32920
32921 \begin_inset LatexCommand url
32922 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/"
32923
32924 \end_inset
32925
32926
32927 \end_layout
32928
32929 \end_inset
32930 </cell>
32931 </row>
32932 <row topline="true">
32933 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32934 \begin_inset Text
32935
32936 \begin_layout Standard
32937 Notes on debugging with SDCDB
32938 \begin_inset LatexCommand index
32939 name "SDCDB (debugger)"
32940
32941 \end_inset
32942
32943
32944 \end_layout
32945
32946 \end_inset
32947 </cell>
32948 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32949 \begin_inset Text
32950
32951 \begin_layout Standard
32952 sdcc/debugger/README 
32953 \emph on
32954 \InsetSpace ~
32955 \InsetSpace ~
32956 \InsetSpace ~
32957
32958 \hfill
32959 online at
32960 \emph default
32961 :
32962 \newline
32963
32964 \begin_inset LatexCommand url
32965 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README"
32966
32967 \end_inset
32968
32969
32970 \end_layout
32971
32972 \end_inset
32973 </cell>
32974 </row>
32975 <row topline="true">
32976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32977 \begin_inset Text
32978
32979 \begin_layout Standard
32980 uCsim
32981 \begin_inset LatexCommand index
32982 name "uCsim"
32983
32984 \end_inset
32985
32986  Software simulator for microcontrollers
32987 \end_layout
32988
32989 \end_inset
32990 </cell>
32991 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32992 \begin_inset Text
32993
32994 \begin_layout Standard
32995
32996 \family roman
32997 \series medium
32998 \shape up
32999 \size normal
33000 \emph off
33001 \bar no
33002 \noun off
33003 \color none
33004 sdcc/sim/ucsim/doc
33005 \family default
33006 \series default
33007 \shape default
33008 \size default
33009 \emph default
33010 \bar default
33011 \noun default
33012 /index.html 
33013 \emph on
33014 \InsetSpace ~
33015 \InsetSpace ~
33016 \InsetSpace ~
33017
33018 \hfill
33019 online at:
33020 \emph default
33021
33022 \newline
33023
33024 \begin_inset LatexCommand url
33025 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html"
33026
33027 \end_inset
33028
33029
33030 \end_layout
33031
33032 \end_inset
33033 </cell>
33034 </row>
33035 <row topline="true">
33036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33037 \begin_inset Text
33038
33039 \begin_layout Standard
33040 Temporary notes on the pic16
33041 \begin_inset LatexCommand index
33042 name "PIC16"
33043
33044 \end_inset
33045
33046  port
33047 \end_layout
33048
33049 \end_inset
33050 </cell>
33051 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33052 \begin_inset Text
33053
33054 \begin_layout Standard
33055 sdcc/src/pic16/NOTES 
33056 \emph on
33057 \InsetSpace ~
33058 \InsetSpace ~
33059 \InsetSpace ~
33060
33061 \hfill
33062 online at:
33063 \newline
33064
33065 \emph default
33066
33067 \begin_inset LatexCommand url
33068 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES"
33069
33070 \end_inset
33071
33072
33073 \end_layout
33074
33075 \end_inset
33076 </cell>
33077 </row>
33078 <row topline="true" bottomline="true">
33079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33080 \begin_inset Text
33081
33082 \begin_layout Standard
33083 SDCC internal documentation (debugging file format)
33084 \end_layout
33085
33086 \end_inset
33087 </cell>
33088 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33089 \begin_inset Text
33090
33091 \begin_layout Standard
33092 sdcc/doc/
33093 \family roman
33094 \series medium
33095 \shape up
33096 \size normal
33097 \emph off
33098 \bar no
33099 \noun off
33100 \color none
33101 cdbfileformat.pd
33102 \family default
33103 \series default
33104 \shape default
33105 \size default
33106 \emph default
33107 \bar default
33108 \noun default
33109
33110 \emph on
33111 \InsetSpace ~
33112 \InsetSpace ~
33113 \InsetSpace ~
33114
33115 \hfill
33116 online at:
33117 \emph default
33118
33119 \newline
33120
33121 \begin_inset LatexCommand url
33122 target "http://sdcc.sourceforge.net/doc/cdbfileformat.pdf"
33123
33124 \end_inset
33125
33126
33127 \end_layout
33128
33129 \end_inset
33130 </cell>
33131 </row>
33132 </lyxtabular>
33133
33134 \end_inset
33135
33136
33137 \newline
33138
33139 \end_layout
33140
33141 \begin_layout Section
33142 Related open source tools
33143 \begin_inset LatexCommand label
33144 name "sec:Related-open-source-tools"
33145
33146 \end_inset
33147
33148
33149 \begin_inset LatexCommand index
33150 name "Related tools"
33151
33152 \end_inset
33153
33154
33155 \end_layout
33156
33157 \begin_layout Standard
33158 \align left
33159 \begin_inset Tabular
33160 <lyxtabular version="3" rows="16" columns="3">
33161 <features>
33162 <column alignment="left" valignment="top" leftline="true" width="0pt">
33163 <column alignment="block" valignment="top" leftline="true" width="30line%">
33164 <column alignment="left" valignment="top" leftline="true" rightline="true" width="40col%">
33165 <row topline="true" bottomline="true">
33166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33167 \begin_inset Text
33168
33169 \begin_layout Standard
33170
33171 \series bold
33172 Name
33173 \end_layout
33174
33175 \end_inset
33176 </cell>
33177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33178 \begin_inset Text
33179
33180 \begin_layout Standard
33181
33182 \series bold
33183 Purpose
33184 \end_layout
33185
33186 \end_inset
33187 </cell>
33188 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33189 \begin_inset Text
33190
33191 \begin_layout Standard
33192
33193 \series bold
33194 Where to get
33195 \end_layout
33196
33197 \end_inset
33198 </cell>
33199 </row>
33200 <row topline="true">
33201 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33202 \begin_inset Text
33203
33204 \begin_layout Standard
33205 gpsim
33206 \begin_inset LatexCommand index
33207 name "gpsim (pic simulator)"
33208
33209 \end_inset
33210
33211
33212 \end_layout
33213
33214 \end_inset
33215 </cell>
33216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33217 \begin_inset Text
33218
33219 \begin_layout Standard
33220 PIC simulator
33221 \end_layout
33222
33223 \end_inset
33224 </cell>
33225 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33226 \begin_inset Text
33227
33228 \begin_layout Standard
33229 \begin_inset LatexCommand url
33230 target "http://www.dattalo.com/gnupic/gpsim.html"
33231
33232 \end_inset
33233
33234
33235 \end_layout
33236
33237 \end_inset
33238 </cell>
33239 </row>
33240 <row topline="true">
33241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33242 \begin_inset Text
33243
33244 \begin_layout Standard
33245 gputils
33246 \begin_inset LatexCommand index
33247 name "gputils (pic tools)"
33248
33249 \end_inset
33250
33251
33252 \end_layout
33253
33254 \end_inset
33255 </cell>
33256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33257 \begin_inset Text
33258
33259 \begin_layout Standard
33260 GNU PIC utilities
33261 \end_layout
33262
33263 \end_inset
33264 </cell>
33265 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33266 \begin_inset Text
33267
33268 \begin_layout Standard
33269 \begin_inset LatexCommand url
33270 target "http://sourceforge.net/projects/gputils"
33271
33272 \end_inset
33273
33274
33275 \end_layout
33276
33277 \end_inset
33278 </cell>
33279 </row>
33280 <row topline="true">
33281 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33282 \begin_inset Text
33283
33284 \begin_layout Standard
33285 flP5
33286 \end_layout
33287
33288 \end_inset
33289 </cell>
33290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33291 \begin_inset Text
33292
33293 \begin_layout Standard
33294 PIC programmer
33295 \end_layout
33296
33297 \end_inset
33298 </cell>
33299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33300 \begin_inset Text
33301
33302 \begin_layout Standard
33303 \begin_inset LatexCommand url
33304 target "http://freshmeat.net/projects/flp5/"
33305
33306 \end_inset
33307
33308
33309 \end_layout
33310
33311 \end_inset
33312 </cell>
33313 </row>
33314 <row topline="true">
33315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33316 \begin_inset Text
33317
33318 \begin_layout Standard
33319 ec2drv/newcdb
33320 \end_layout
33321
33322 \end_inset
33323 </cell>
33324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33325 \begin_inset Text
33326
33327 \begin_layout Standard
33328 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
33329  (Unix only)
33330 \end_layout
33331
33332 \end_inset
33333 </cell>
33334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33335 \begin_inset Text
33336
33337 \begin_layout Standard
33338 \begin_inset LatexCommand url
33339 target "http://sourceforge.net/projects/ec2drv"
33340
33341 \end_inset
33342
33343
33344 \end_layout
33345
33346 \end_inset
33347 </cell>
33348 </row>
33349 <row topline="true">
33350 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33351 \begin_inset Text
33352
33353 \begin_layout Standard
33354 indent
33355 \begin_inset LatexCommand index
33356 name "indent (source formatting tool)"
33357
33358 \end_inset
33359
33360
33361 \end_layout
33362
33363 \end_inset
33364 </cell>
33365 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33366 \begin_inset Text
33367
33368 \begin_layout Standard
33369 Formats C source - Master of the white spaces
33370 \end_layout
33371
33372 \end_inset
33373 </cell>
33374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33375 \begin_inset Text
33376
33377 \begin_layout Standard
33378 \begin_inset LatexCommand url
33379 target "http://directory.fsf.org/GNU/indent.html"
33380
33381 \end_inset
33382
33383
33384 \end_layout
33385
33386 \end_inset
33387 </cell>
33388 </row>
33389 <row topline="true">
33390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33391 \begin_inset Text
33392
33393 \begin_layout Standard
33394 srecord
33395 \begin_inset LatexCommand index
33396 name "srecord (bin, hex, ... tool)"
33397
33398 \end_inset
33399
33400
33401 \end_layout
33402
33403 \end_inset
33404 </cell>
33405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33406 \begin_inset Text
33407
33408 \begin_layout Standard
33409 Object file conversion, checksumming, ...
33410 \end_layout
33411
33412 \end_inset
33413 </cell>
33414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33415 \begin_inset Text
33416
33417 \begin_layout Standard
33418 \begin_inset LatexCommand url
33419 target "http://sourceforge.net/projects/srecord"
33420
33421 \end_inset
33422
33423
33424 \end_layout
33425
33426 \end_inset
33427 </cell>
33428 </row>
33429 <row topline="true">
33430 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33431 \begin_inset Text
33432
33433 \begin_layout Standard
33434 objdump
33435 \begin_inset LatexCommand index
33436 name "objdump (tool)"
33437
33438 \end_inset
33439
33440
33441 \end_layout
33442
33443 \end_inset
33444 </cell>
33445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33446 \begin_inset Text
33447
33448 \begin_layout Standard
33449 Object file conversion, ...
33450 \end_layout
33451
33452 \end_inset
33453 </cell>
33454 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33455 \begin_inset Text
33456
33457 \begin_layout Standard
33458 Part of binutils (should be there anyway)
33459 \end_layout
33460
33461 \end_inset
33462 </cell>
33463 </row>
33464 <row topline="true">
33465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33466 \begin_inset Text
33467
33468 \begin_layout Standard
33469 cmon51
33470 \end_layout
33471
33472 \end_inset
33473 </cell>
33474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33475 \begin_inset Text
33476
33477 \begin_layout Standard
33478 8051 monitor (hex up-/download, single step, disassemble)
33479 \end_layout
33480
33481 \end_inset
33482 </cell>
33483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33484 \begin_inset Text
33485
33486 \begin_layout Standard
33487 \begin_inset LatexCommand url
33488 target "http://sourceforge.net/projects/cmon51"
33489
33490 \end_inset
33491
33492
33493 \end_layout
33494
33495 \end_inset
33496 </cell>
33497 </row>
33498 <row topline="true">
33499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33500 \begin_inset Text
33501
33502 \begin_layout Standard
33503 doxygen
33504 \begin_inset LatexCommand index
33505 name "doxygen (source documentation tool)"
33506
33507 \end_inset
33508
33509
33510 \end_layout
33511
33512 \end_inset
33513 </cell>
33514 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33515 \begin_inset Text
33516
33517 \begin_layout Standard
33518 Source code documentation system
33519 \end_layout
33520
33521 \end_inset
33522 </cell>
33523 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33524 \begin_inset Text
33525
33526 \begin_layout Standard
33527 \begin_inset LatexCommand url
33528 target "http://www.doxygen.org"
33529
33530 \end_inset
33531
33532
33533 \end_layout
33534
33535 \end_inset
33536 </cell>
33537 </row>
33538 <row topline="true">
33539 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33540 \begin_inset Text
33541
33542 \begin_layout Standard
33543 kdevelop
33544 \end_layout
33545
33546 \end_inset
33547 </cell>
33548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33549 \begin_inset Text
33550
33551 \begin_layout Standard
33552 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
33553 \end_layout
33554
33555 \end_inset
33556 </cell>
33557 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33558 \begin_inset Text
33559
33560 \begin_layout Standard
33561 \begin_inset LatexCommand url
33562 target "http://www.kdevelop.org"
33563
33564 \end_inset
33565
33566
33567 \end_layout
33568
33569 \end_inset
33570 </cell>
33571 </row>
33572 <row topline="true">
33573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33574 \begin_inset Text
33575
33576 \begin_layout Standard
33577 paulmon
33578 \end_layout
33579
33580 \end_inset
33581 </cell>
33582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33583 \begin_inset Text
33584
33585 \begin_layout Standard
33586 8051 monitor (hex up-/download, single step, disassemble)
33587 \end_layout
33588
33589 \end_inset
33590 </cell>
33591 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33592 \begin_inset Text
33593
33594 \begin_layout Standard
33595 \begin_inset LatexCommand url
33596 target "http://www.pjrc.com/tech/8051/paulmon2.html"
33597
33598 \end_inset
33599
33600
33601 \end_layout
33602
33603 \end_inset
33604 </cell>
33605 </row>
33606 <row topline="true">
33607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33608 \begin_inset Text
33609
33610 \begin_layout Standard
33611 splint
33612 \begin_inset LatexCommand index
33613 name "splint (syntax checking tool)"
33614
33615 \end_inset
33616
33617
33618 \end_layout
33619
33620 \end_inset
33621 </cell>
33622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33623 \begin_inset Text
33624
33625 \begin_layout Standard
33626 Statically checks c sources (see 
33627 \begin_inset LatexCommand ref
33628 reference "lyx:more-pedantic-SPLINT"
33629
33630 \end_inset
33631
33632 )
33633 \end_layout
33634
33635 \end_inset
33636 </cell>
33637 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33638 \begin_inset Text
33639
33640 \begin_layout Standard
33641 \begin_inset LatexCommand url
33642 target "http://www.splint.org"
33643
33644 \end_inset
33645
33646
33647 \end_layout
33648
33649 \end_inset
33650 </cell>
33651 </row>
33652 <row topline="true" bottomline="true">
33653 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33654 \begin_inset Text
33655
33656 \begin_layout Standard
33657 ddd
33658 \begin_inset LatexCommand index
33659 name "DDD (debugger)"
33660
33661 \end_inset
33662
33663
33664 \end_layout
33665
33666 \end_inset
33667 </cell>
33668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33669 \begin_inset Text
33670
33671 \begin_layout Standard
33672 Debugger, serves nicely as GUI to SDCDB
33673 \begin_inset LatexCommand index
33674 name "SDCDB (debugger)"
33675
33676 \end_inset
33677
33678  (Unix only)
33679 \end_layout
33680
33681 \end_inset
33682 </cell>
33683 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33684 \begin_inset Text
33685
33686 \begin_layout Standard
33687 \begin_inset LatexCommand url
33688 target "http://www.gnu.org/software/ddd/"
33689
33690 \end_inset
33691
33692
33693 \end_layout
33694
33695 \end_inset
33696 </cell>
33697 </row>
33698 <row bottomline="true">
33699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33700 \begin_inset Text
33701
33702 \begin_layout Standard
33703 d52
33704 \begin_inset LatexCommand index
33705 name "d52"
33706
33707 \end_inset
33708
33709
33710 \begin_inset LatexCommand index
33711 name "d52 (disassembler)"
33712
33713 \end_inset
33714
33715
33716 \end_layout
33717
33718 \end_inset
33719 </cell>
33720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33721 \begin_inset Text
33722
33723 \begin_layout Standard
33724 Disassembler, can count instruction cycles
33725 \begin_inset LatexCommand index
33726 name "instruction cycles (count)"
33727
33728 \end_inset
33729
33730 , use with options -pnd
33731 \end_layout
33732
33733 \end_inset
33734 </cell>
33735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33736 \begin_inset Text
33737
33738 \begin_layout Standard
33739 \begin_inset LatexCommand url
33740 target "http://www.8052.com/users/disasm/"
33741
33742 \end_inset
33743
33744
33745 \end_layout
33746
33747 \end_inset
33748 </cell>
33749 </row>
33750 <row bottomline="true">
33751 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33752 \begin_inset Text
33753
33754 \begin_layout Standard
33755 cmake
33756 \begin_inset LatexCommand index
33757 name "cmake"
33758
33759 \end_inset
33760
33761
33762 \end_layout
33763
33764 \end_inset
33765 </cell>
33766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33767 \begin_inset Text
33768
33769 \begin_layout Standard
33770 Cross platform build system, generates Makefiles
33771 \begin_inset LatexCommand index
33772 name "Makefile"
33773
33774 \end_inset
33775
33776  and project workspaces
33777 \begin_inset LatexCommand index
33778 name "project workspace"
33779
33780 \end_inset
33781
33782
33783 \end_layout
33784
33785 \end_inset
33786 </cell>
33787 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33788 \begin_inset Text
33789
33790 \begin_layout Standard
33791 \begin_inset LatexCommand url
33792 target "http://www.cmake.org"
33793
33794 \end_inset
33795
33796  \InsetSpace ~
33797 \InsetSpace ~
33798 \InsetSpace ~
33799 \InsetSpace ~
33800 and a dedicated wiki entry: 
33801 \begin_inset LatexCommand url
33802 target "http://www.cmake.org/Wiki/CmakeSdcc"
33803
33804 \end_inset
33805
33806
33807 \end_layout
33808
33809 \end_inset
33810 </cell>
33811 </row>
33812 </lyxtabular>
33813
33814 \end_inset
33815
33816
33817 \newline
33818
33819 \end_layout
33820
33821 \begin_layout Section
33822 Related documentation / recommended reading
33823 \end_layout
33824
33825 \begin_layout Standard
33826 \align left
33827 \begin_inset Tabular
33828 <lyxtabular version="3" rows="7" columns="3">
33829 <features>
33830 <column alignment="left" valignment="top" leftline="true" width="0pt">
33831 <column alignment="left" valignment="top" leftline="true" width="0">
33832 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
33833 <row topline="true" bottomline="true">
33834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33835 \begin_inset Text
33836
33837 \begin_layout Standard
33838
33839 \series bold
33840 Name
33841 \end_layout
33842
33843 \end_inset
33844 </cell>
33845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33846 \begin_inset Text
33847
33848 \begin_layout Standard
33849
33850 \series bold
33851 Subject / Title
33852 \end_layout
33853
33854 \end_inset
33855 </cell>
33856 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33857 \begin_inset Text
33858
33859 \begin_layout Standard
33860
33861 \series bold
33862 Where to get
33863 \end_layout
33864
33865 \end_inset
33866 </cell>
33867 </row>
33868 <row topline="true">
33869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33870 \begin_inset Text
33871
33872 \begin_layout Standard
33873
33874 \family roman
33875 \series medium
33876 \shape up
33877 \size normal
33878 \emph off
33879 \bar no
33880 \noun off
33881 \color none
33882 c-refcard.pdf
33883 \end_layout
33884
33885 \end_inset
33886 </cell>
33887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33888 \begin_inset Text
33889
33890 \begin_layout Standard
33891 C Reference Card
33892 \begin_inset LatexCommand index
33893 name "C Reference card"
33894
33895 \end_inset
33896
33897 , 2 pages
33898 \end_layout
33899
33900 \end_inset
33901 </cell>
33902 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33903 \begin_inset Text
33904
33905 \begin_layout Standard
33906 \begin_inset LatexCommand url
33907 target "http://refcards.com/refcards/c/index.html"
33908
33909 \end_inset
33910
33911
33912 \end_layout
33913
33914 \end_inset
33915 </cell>
33916 </row>
33917 <row topline="true">
33918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33919 \begin_inset Text
33920
33921 \begin_layout Standard
33922 c-faq
33923 \end_layout
33924
33925 \end_inset
33926 </cell>
33927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33928 \begin_inset Text
33929
33930 \begin_layout Standard
33931 C-FAQ
33932 \begin_inset LatexCommand index
33933 name "C FAQ"
33934
33935 \end_inset
33936
33937
33938 \end_layout
33939
33940 \end_inset
33941 </cell>
33942 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33943 \begin_inset Text
33944
33945 \begin_layout Standard
33946 \begin_inset LatexCommand url
33947 target "http://www.c-faq.com"
33948
33949 \end_inset
33950
33951
33952 \end_layout
33953
33954 \end_inset
33955 </cell>
33956 </row>
33957 <row topline="true">
33958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33959 \begin_inset Text
33960
33961 \begin_layout Standard
33962 ISO/IEC 9899:TC2
33963 \end_layout
33964
33965 \end_inset
33966 </cell>
33967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33968 \begin_inset Text
33969
33970 \begin_layout Standard
33971 \begin_inset Quotes sld
33972 \end_inset
33973
33974 C-Standard
33975 \begin_inset Quotes srd
33976 \end_inset
33977
33978
33979 \end_layout
33980
33981 \end_inset
33982 </cell>
33983 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33984 \begin_inset Text
33985
33986 \begin_layout Standard
33987
33988 \size footnotesize
33989 \begin_inset LatexCommand url
33990 target "http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899"
33991
33992 \end_inset
33993
33994
33995 \end_layout
33996
33997 \end_inset
33998 </cell>
33999 </row>
34000 <row topline="true">
34001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34002 \begin_inset Text
34003
34004 \begin_layout Standard
34005 ISO/IEC DTR 18037
34006 \end_layout
34007
34008 \end_inset
34009 </cell>
34010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34011 \begin_inset Text
34012
34013 \begin_layout Standard
34014 \begin_inset Quotes sld
34015 \end_inset
34016
34017 Extensions for Embedded C
34018 \begin_inset Quotes srd
34019 \end_inset
34020
34021
34022 \end_layout
34023
34024 \end_inset
34025 </cell>
34026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34027 \begin_inset Text
34028
34029 \begin_layout Standard
34030
34031 \size footnotesize
34032 \begin_inset LatexCommand url
34033 target "http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf"
34034
34035 \end_inset
34036
34037
34038 \end_layout
34039
34040 \end_inset
34041 </cell>
34042 </row>
34043 <row topline="true">
34044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34045 \begin_inset Text
34046
34047 \begin_layout Standard
34048
34049 \end_layout
34050
34051 \end_inset
34052 </cell>
34053 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34054 \begin_inset Text
34055
34056 \begin_layout Standard
34057 Latest datasheet of target CPU
34058 \end_layout
34059
34060 \end_inset
34061 </cell>
34062 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34063 \begin_inset Text
34064
34065 \begin_layout Standard
34066 vendor
34067 \end_layout
34068
34069 \end_inset
34070 </cell>
34071 </row>
34072 <row topline="true" bottomline="true">
34073 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34074 \begin_inset Text
34075
34076 \begin_layout Standard
34077
34078 \end_layout
34079
34080 \end_inset
34081 </cell>
34082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34083 \begin_inset Text
34084
34085 \begin_layout Standard
34086 Revision history of datasheet
34087 \end_layout
34088
34089 \end_inset
34090 </cell>
34091 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34092 \begin_inset Text
34093
34094 \begin_layout Standard
34095 vendor
34096 \end_layout
34097
34098 \end_inset
34099 </cell>
34100 </row>
34101 </lyxtabular>
34102
34103 \end_inset
34104
34105
34106 \newline
34107
34108 \end_layout
34109
34110 \begin_layout Section
34111 Application notes specifically for SDCC
34112 \end_layout
34113
34114 \begin_layout Standard
34115 SDCC makes no claims about the completeness of this list and about up-to-datenes
34116 s or correctness of the application notes
34117 \begin_inset LatexCommand index
34118 name "Application notes"
34119
34120 \end_inset
34121
34122 .
34123 \end_layout
34124
34125 \begin_layout Standard
34126 \align left
34127
34128 \size footnotesize
34129 \begin_inset Tabular
34130 <lyxtabular version="3" rows="7" columns="3">
34131 <features>
34132 <column alignment="block" valignment="top" leftline="true" width="17col%">
34133 <column alignment="block" valignment="top" leftline="true" width="27col%">
34134 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
34135 <row topline="true" bottomline="true">
34136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34137 \begin_inset Text
34138
34139 \begin_layout Standard
34140
34141 \series bold
34142 \size footnotesize
34143 Vendor
34144 \end_layout
34145
34146 \end_inset
34147 </cell>
34148 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
34149 \begin_inset Text
34150
34151 \begin_layout Standard
34152
34153 \series bold
34154 \size footnotesize
34155 Subject / Title
34156 \end_layout
34157
34158 \end_inset
34159 </cell>
34160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34161 \begin_inset Text
34162
34163 \begin_layout Standard
34164
34165 \series bold
34166 \size footnotesize
34167 Where to get
34168 \end_layout
34169
34170 \end_inset
34171 </cell>
34172 </row>
34173 <row topline="true">
34174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34175 \begin_inset Text
34176
34177 \begin_layout Standard
34178
34179 \size footnotesize
34180 Maxim / Dallas
34181 \end_layout
34182
34183 \end_inset
34184 </cell>
34185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34186 \begin_inset Text
34187
34188 \begin_layout Standard
34189
34190 \size footnotesize
34191 Using the SDCC Compiler for the DS80C400
34192 \begin_inset LatexCommand index
34193 name "DS80C400"
34194
34195 \end_inset
34196
34197
34198 \end_layout
34199
34200 \end_inset
34201 </cell>
34202 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34203 \begin_inset Text
34204
34205 \begin_layout Standard
34206
34207 \size footnotesize
34208 \begin_inset LatexCommand url
34209 target "http://pdfserv.maxim-ic.com/en/an/AN3346.pdf"
34210
34211 \end_inset
34212
34213
34214 \end_layout
34215
34216 \end_inset
34217 </cell>
34218 </row>
34219 <row topline="true">
34220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34221 \begin_inset Text
34222
34223 \begin_layout Standard
34224
34225 \size footnotesize
34226 Maxim / Dallas
34227 \end_layout
34228
34229 \end_inset
34230 </cell>
34231 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
34232 \begin_inset Text
34233
34234 \begin_layout Standard
34235
34236 \size footnotesize
34237 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
34238 \begin_inset LatexCommand index
34239 name "DS89C4x0"
34240
34241 \end_inset
34242
34243  Family of Microcontrollers
34244 \end_layout
34245
34246 \end_inset
34247 </cell>
34248 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34249 \begin_inset Text
34250
34251 \begin_layout Standard
34252
34253 \size footnotesize
34254 \begin_inset LatexCommand url
34255 target "http://pdfserv.maxim-ic.com/en/an/AN3477.pdf"
34256
34257 \end_inset
34258
34259
34260 \end_layout
34261
34262 \end_inset
34263 </cell>
34264 </row>
34265 <row topline="true">
34266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34267 \begin_inset Text
34268
34269 \begin_layout Standard
34270
34271 \size footnotesize
34272 Silicon Laboratories / Cygnal
34273 \end_layout
34274
34275 \end_inset
34276 </cell>
34277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34278 \begin_inset Text
34279
34280 \begin_layout Standard
34281
34282 \size footnotesize
34283 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
34284 \begin_inset LatexCommand index
34285 name "IDE"
34286
34287 \end_inset
34288
34289
34290 \end_layout
34291
34292 \end_inset
34293 </cell>
34294 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34295 \begin_inset Text
34296
34297 \begin_layout Standard
34298
34299 \size footnotesize
34300 \begin_inset LatexCommand url
34301 target "http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf"
34302
34303 \end_inset
34304
34305
34306 \end_layout
34307
34308 \end_inset
34309 </cell>
34310 </row>
34311 <row topline="true">
34312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34313 \begin_inset Text
34314
34315 \begin_layout Standard
34316
34317 \size footnotesize
34318 Ramtron / Goal Semiconductor
34319 \end_layout
34320
34321 \end_inset
34322 </cell>
34323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34324 \begin_inset Text
34325
34326 \begin_layout Standard
34327
34328 \size footnotesize
34329 Interfacing SDCC to Syn and Textpad
34330 \end_layout
34331
34332 \end_inset
34333 </cell>
34334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34335 \begin_inset Text
34336
34337 \begin_layout Standard
34338
34339 \size footnotesize
34340 \begin_inset LatexCommand url
34341 target "http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp"
34342
34343 \end_inset
34344
34345
34346 \end_layout
34347
34348 \end_inset
34349 </cell>
34350 </row>
34351 <row topline="true">
34352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34353 \begin_inset Text
34354
34355 \begin_layout Standard
34356
34357 \size footnotesize
34358 Ramtron / Goal Semiconductor
34359 \end_layout
34360
34361 \end_inset
34362 </cell>
34363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34364 \begin_inset Text
34365
34366 \begin_layout Standard
34367
34368 \size footnotesize
34369 Installing and Configuring SDCC and Crimson Editor 
34370 \end_layout
34371
34372 \end_inset
34373 </cell>
34374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34375 \begin_inset Text
34376
34377 \begin_layout Standard
34378
34379 \size footnotesize
34380 \begin_inset LatexCommand url
34381 target "http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp"
34382
34383 \end_inset
34384
34385
34386 \end_layout
34387
34388 \end_inset
34389 </cell>
34390 </row>
34391 <row topline="true" bottomline="true">
34392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34393 \begin_inset Text
34394
34395 \begin_layout Standard
34396
34397 \size footnotesize
34398 Texas Instruments
34399 \end_layout
34400
34401 \end_inset
34402 </cell>
34403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34404 \begin_inset Text
34405
34406 \begin_layout Standard
34407
34408 \size footnotesize
34409 MSC12xx Programming with SDCC
34410 \end_layout
34411
34412 \end_inset
34413 </cell>
34414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34415 \begin_inset Text
34416
34417 \begin_layout Standard
34418
34419 \size footnotesize
34420 \begin_inset LatexCommand url
34421 target "http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf"
34422
34423 \end_inset
34424
34425
34426 \end_layout
34427
34428 \end_inset
34429 </cell>
34430 </row>
34431 </lyxtabular>
34432
34433 \end_inset
34434
34435
34436 \end_layout
34437
34438 \begin_layout Section
34439 Some Questions
34440 \end_layout
34441
34442 \begin_layout Standard
34443 Some questions answered, some pointers given - it might be time to in turn
34444  ask 
34445 \emph on
34446 you
34447 \emph default
34448  some questions: 
34449 \end_layout
34450
34451 \begin_layout Itemize
34452 can you solve your project with the selected microcontroller? Would you
34453  find out early or rather late that your target is too small/slow/whatever?
34454  Can you switch to a slightly better device if it doesn't fit?
34455 \end_layout
34456
34457 \begin_layout Itemize
34458 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
34459  and/or another programming language be more adequate? Would an operating
34460  system on the target device help?
34461 \end_layout
34462
34463 \begin_layout Itemize
34464 if you solved the problem, will the marketing department be happy?
34465 \end_layout
34466
34467 \begin_layout Itemize
34468 if the marketing department is happy, will customers be happy?
34469 \end_layout
34470
34471 \begin_layout Itemize
34472 if you're the project manager, marketing department and maybe even the customer
34473  in one person, have you tried to see the project from the outside?
34474 \end_layout
34475
34476 \begin_layout Itemize
34477 is the project done if you think it is done? Or is just that other interface/pro
34478 tocol/feature/configuration/option missing? How about website, manual(s),
34479  internationali(z|s)ation, packaging, labels, 2nd source for components,
34480  electromagnetic compatability/interference, documentation for production,
34481  production test software, update mechanism, patent issues?
34482 \end_layout
34483
34484 \begin_layout Itemize
34485 is your project adequately positioned in that magic triangle: fame, fortune,
34486  fun?
34487 \end_layout
34488
34489 \begin_layout Standard
34490 Maybe not all answers to these questions are known and some answers may
34491  even be 
34492 \emph on
34493 no
34494 \emph default
34495 , nevertheless knowing these questions may help you to avoid burnout
34496 \begin_inset Foot
34497 status open
34498
34499 \begin_layout Standard
34500 burnout is bad for electronic devices, programmers and motorcycle tyres
34501 \end_layout
34502
34503 \end_inset
34504
34505 .
34506  Chances are you didn't want to hear some of them...
34507 \end_layout
34508
34509 \begin_layout Chapter
34510 Support
34511 \begin_inset LatexCommand index
34512 name "Support"
34513
34514 \end_inset
34515
34516
34517 \end_layout
34518
34519 \begin_layout Standard
34520 SDCC has grown to be a large project.
34521  The compiler alone (without the preprocessor, assembler and linker) is
34522  well over 150,000 lines of code (blank stripped).
34523  The open source nature of this project is a key to its continued growth
34524  and support.
34525  You gain the benefit and support of many active software developers and
34526  end users.
34527  Is SDCC perfect? No, that's why we need your help.
34528  The developers take pride in fixing reported bugs.
34529  You can help by reporting the bugs and helping other SDCC users.
34530  There are lots of ways to contribute, and we encourage you to take part
34531  in making SDCC a great software package.
34532  
34533 \end_layout
34534
34535 \begin_layout Standard
34536 The SDCC project is hosted on the SDCC sourceforge site at 
34537 \begin_inset LatexCommand htmlurl
34538 target "http://sourceforge.net/projects/sdcc"
34539
34540 \end_inset
34541
34542 .
34543  You'll find the complete set of mailing lists
34544 \begin_inset LatexCommand index
34545 name "Mailing list(s)"
34546
34547 \end_inset
34548
34549 , forums, bug reporting system, patch submission
34550 \begin_inset LatexCommand index
34551 name "Patch submission"
34552
34553 \end_inset
34554
34555  system, download
34556 \begin_inset LatexCommand index
34557 name "download"
34558
34559 \end_inset
34560
34561  area and Subversion code repository
34562 \begin_inset LatexCommand index
34563 name "Subversion code repository"
34564
34565 \end_inset
34566
34567  there.
34568 \end_layout
34569
34570 \begin_layout Section
34571 Reporting Bugs
34572 \begin_inset LatexCommand index
34573 name "Bug reporting"
34574
34575 \end_inset
34576
34577
34578 \begin_inset LatexCommand index
34579 name "Reporting bugs"
34580
34581 \end_inset
34582
34583
34584 \end_layout
34585
34586 \begin_layout Standard
34587 The recommended way of reporting bugs is using the infrastructure of the
34588  sourceforge site.
34589  You can follow the status of bug reports there and have an overview about
34590  the known bugs.
34591 \end_layout
34592
34593 \begin_layout Standard
34594 Bug reports are automatically forwarded to the developer mailing list and
34595  will be fixed ASAP.
34596  When reporting a bug, it is very useful to include a small test program
34597  (the smaller the better) which reproduces the problem.
34598  If you can isolate the problem by looking at the generated assembly code,
34599  this can be very helpful.
34600  Compiling your program with the -
34601 \begin_inset ERT
34602 status collapsed
34603
34604 \begin_layout Standard
34605
34606
34607 \backslash
34608 /
34609 \end_layout
34610
34611 \end_inset
34612
34613 -dumpall
34614 \begin_inset LatexCommand index
34615 name "-\\/-dumpall"
34616
34617 \end_inset
34618
34619  option can sometimes be useful in locating optimization problems.
34620  When reporting a bug please make sure you:
34621 \end_layout
34622
34623 \begin_layout Enumerate
34624 Attach the code you are compiling with SDCC.
34625  
34626 \end_layout
34627
34628 \begin_layout Enumerate
34629 Specify the exact command you use to run SDCC, or attach your Makefile.
34630  
34631 \end_layout
34632
34633 \begin_layout Enumerate
34634 Specify the SDCC version (type "
34635 \family sans
34636 \series bold
34637 sdcc -v
34638 \family default
34639 \series default
34640 "), your platform, and operating system.
34641  
34642 \end_layout
34643
34644 \begin_layout Enumerate
34645 Provide an exact copy of any error message or incorrect output.
34646  
34647 \end_layout
34648
34649 \begin_layout Enumerate
34650 Put something meaningful in the subject of your message.
34651 \end_layout
34652
34653 \begin_layout Standard
34654 Please attempt to include these 5 important parts, as applicable, in all
34655  requests for support or when reporting any problems or bugs with SDCC.
34656  Though this will make your message lengthy, it will greatly improve your
34657  chance that SDCC users and developers will be able to help you.
34658  Some SDCC developers are frustrated by bug reports without code provided
34659  that they can use to reproduce and ultimately fix the problem, so please
34660  be sure to provide sample code if you are reporting a bug! 
34661 \end_layout
34662
34663 \begin_layout Standard
34664 Please have a short check that you are using a recent version of SDCC and
34665  the bug is not yet known.
34666  This is the link for reporting bugs: 
34667 \begin_inset LatexCommand htmlurl
34668 target "http://sourceforge.net/tracker/?group_id=599&atid=100599"
34669
34670 \end_inset
34671
34672 .
34673  With SDCC on average having more than 200 downloads
34674 \begin_inset LatexCommand index
34675 name "download"
34676
34677 \end_inset
34678
34679  on sourceforge per day
34680 \begin_inset Foot
34681 status open
34682
34683 \begin_layout Standard
34684 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
34685  between 2002 and 2005.
34686  This does not include other methods of distribution.
34687 \end_layout
34688
34689 \end_inset
34690
34691  there must be some users.
34692  So it's not exactly easy to find a new bug.
34693  If you find one we need it: 
34694 \emph on
34695 reporting bugs is good
34696 \emph default
34697 .
34698 \end_layout
34699
34700 \begin_layout Section
34701 Requesting Features
34702 \begin_inset LatexCommand label
34703 name "sub:Requesting-Features"
34704
34705 \end_inset
34706
34707
34708 \begin_inset LatexCommand index
34709 name "Feature request"
34710
34711 \end_inset
34712
34713
34714 \begin_inset LatexCommand index
34715 name "Requesting features"
34716
34717 \end_inset
34718
34719
34720 \end_layout
34721
34722 \begin_layout Standard
34723 Like bug reports feature requests are forwarded to the developer mailing
34724  list.
34725  This is the link for requesting features: 
34726 \begin_inset LatexCommand htmlurl
34727 target "http://sourceforge.net/tracker/?group_id=599&atid=350599"
34728
34729 \end_inset
34730
34731 .
34732 \end_layout
34733
34734 \begin_layout Section
34735 Submitting patches
34736 \end_layout
34737
34738 \begin_layout Standard
34739 Like bug reports contributed patches are forwarded to the developer mailing
34740  list.
34741  This is the link for submitting patches
34742 \begin_inset LatexCommand index
34743 name "Patch submission"
34744
34745 \end_inset
34746
34747
34748 \begin_inset LatexCommand url
34749 target "http://sourceforge.net/tracker/?group_id=599&atid=300599"
34750
34751 \end_inset
34752
34753 .
34754 \end_layout
34755
34756 \begin_layout Standard
34757 You need to specify some parameters to the 
34758 \family typewriter
34759 diff
34760 \family default
34761  command for the patches to be useful.
34762  If you modified more than one file a patch created f.e.
34763  with 
34764 \family sans
34765 \series bold
34766
34767 \begin_inset Quotes sld
34768 \end_inset
34769
34770 diff -Naur unmodified_directory modified_directory >my_changes.patch
34771 \begin_inset Quotes srd
34772 \end_inset
34773
34774
34775 \family default
34776 \series default
34777  will be fine, otherwise 
34778 \family sans
34779 \series bold
34780
34781 \begin_inset Quotes sld
34782 \end_inset
34783
34784 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
34785 \begin_inset Quotes srd
34786 \end_inset
34787
34788
34789 \family default
34790 \series default
34791  will do.
34792 \end_layout
34793
34794 \begin_layout Section
34795 Getting Help
34796 \end_layout
34797
34798 \begin_layout Standard
34799 These links should take you directly to the 
34800 \begin_inset LatexCommand url
34801 name "Mailing lists"
34802 target "http://sourceforge.net/mail/?group_id=599"
34803
34804 \end_inset
34805
34806
34807 \begin_inset Foot
34808 status open
34809
34810 \begin_layout Standard
34811 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
34812  automated messages (mid 2003)
34813 \end_layout
34814
34815 \end_inset
34816
34817  and the 
34818 \begin_inset LatexCommand url
34819 name "Forums"
34820 target "http://sourceforge.net/forum/?group_id=599"
34821
34822 \end_inset
34823
34824 , lists
34825 \begin_inset LatexCommand index
34826 name "Mailing list(s)"
34827
34828 \end_inset
34829
34830  and forums are archived and searchable so if you are lucky someone already
34831  had a similar problem.
34832  While mails to the lists themselves are delivered promptly their web front
34833  end on sourceforge sometimes shows a severe time lag (up to several weeks),
34834  if you're seriously using SDCC please consider subscribing to the lists.
34835 \end_layout
34836
34837 \begin_layout Section
34838 ChangeLog
34839 \end_layout
34840
34841 \begin_layout Standard
34842 You can follow the status of the Subversion version
34843 \begin_inset LatexCommand index
34844 name "version"
34845
34846 \end_inset
34847
34848  of SDCC by watching the Changelog
34849 \begin_inset LatexCommand index
34850 name "Changelog"
34851
34852 \end_inset
34853
34854  in the Subversion repository
34855 \size footnotesize
34856  
34857 \begin_inset LatexCommand htmlurl
34858 target "http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog"
34859
34860 \end_inset
34861
34862 .
34863 \end_layout
34864
34865 \begin_layout Section
34866 Subversion Source Code Repository
34867 \end_layout
34868
34869 \begin_layout Standard
34870 The output of 
34871 \family sans
34872 \series bold
34873 sdcc -
34874 \family default
34875
34876 \begin_inset ERT
34877 status open
34878
34879 \begin_layout Standard
34880
34881
34882 \backslash
34883 /
34884 \end_layout
34885
34886 \end_inset
34887
34888
34889 \family sans
34890 -version
34891 \family default
34892 \series default
34893  or the filenames of the snapshot versions of SDCC include date and its
34894  Subversion
34895 \begin_inset LatexCommand index
34896 name "Subversion code repository"
34897
34898 \end_inset
34899
34900  number.
34901  Subversion allows to download the source of recent or previous versions
34902  
34903 \begin_inset LatexCommand url
34904 target "http://sourceforge.net/svn/?group_id=599"
34905
34906 \end_inset
34907
34908  (by number or by date).
34909  An on-line source code browser and detailled instructions are also available
34910  there.
34911  SDCC versions starting from 1999 up to now are available (currently the
34912  versions prior to the conversion from cvs
34913 \begin_inset LatexCommand index
34914 name "cvs|see{Subversion}"
34915
34916 \end_inset
34917
34918  to Subversion (April 2006) are either by accessible by Subversion or by
34919  cvs).
34920 \end_layout
34921
34922 \begin_layout Section
34923 Release policy
34924 \begin_inset LatexCommand index
34925 name "Release policy"
34926
34927 \end_inset
34928
34929
34930 \end_layout
34931
34932 \begin_layout Standard
34933 Historically there often were long delays between official releases and
34934  the sourceforge download area tends to get not updated at all.
34935  Excuses in the past might have referred to problems with live range analysis,
34936  but as this was fixed a while ago, the current problem is that another
34937  excuse has to be found.
34938  Kidding aside, we have to get better there! On the other hand there are
34939  daily snapshots available at 
34940 \begin_inset LatexCommand htmlurl
34941 name "snap"
34942 target "http://sdcc.sourceforge.net/snap.php"
34943
34944 \end_inset
34945
34946 , and you can always build the very last version (hopefully with many bugs
34947  fixed, and features added) from the source code available at 
34948 \begin_inset LatexCommand htmlurl
34949 name "Source"
34950 target "http://sdcc.sourceforge.net/snap.php#Source"
34951
34952 \end_inset
34953
34954 .
34955  The SDCC Wiki
34956 \begin_inset LatexCommand index
34957 name "wiki"
34958
34959 \end_inset
34960
34961
34962 \begin_inset LatexCommand index
34963 name "SDCC Wiki"
34964
34965 \end_inset
34966
34967  at 
34968 \begin_inset LatexCommand url
34969 target "http://sdcc.wiki.sourceforge.net/"
34970
34971 \end_inset
34972
34973  also holds some information about past and future releases.
34974 \end_layout
34975
34976 \begin_layout Section
34977 Examples
34978 \begin_inset LatexCommand index
34979 name "Examples"
34980
34981 \end_inset
34982
34983
34984 \end_layout
34985
34986 \begin_layout Standard
34987 You'll find some small examples in the directory 
34988 \emph on
34989 sdcc/device/examples/.
34990
34991 \emph default
34992  More examples and libraries are available at 
34993 \emph on
34994 The SDCC Open Knowledge Resource 
34995 \begin_inset LatexCommand url
34996 target "http://sdccokr.dl9sec.de/"
34997
34998 \end_inset
34999
35000
35001 \emph default
35002  web site or at 
35003 \begin_inset LatexCommand url
35004 target "http://www.pjrc.com/tech/8051/"
35005
35006 \end_inset
35007
35008 .
35009 \end_layout
35010
35011 \begin_layout Standard
35012 \begin_inset Note Note
35013 status collapsed
35014
35015 \begin_layout Standard
35016 I did insert a reference to Paul's web site here although it seems rather
35017  dedicated to a specific 8032 board (I think it's okay because it f.e.
35018  shows LCD/Harddisc interface and has a free 8051 monitor.
35019  Independent 8032 board vendors face hard competition of heavily subsidized
35020  development boards anyway).
35021 \end_layout
35022
35023 \begin_layout Standard
35024 Maybe we should include some links to real world applications.
35025  Preferably pointer to pointers (one for each architecture) so this stays
35026  manageable here?
35027 \end_layout
35028
35029 \end_inset
35030
35031
35032 \end_layout
35033
35034 \begin_layout Section
35035 Quality control
35036 \begin_inset LatexCommand label
35037 name "sec:Quality-control"
35038
35039 \end_inset
35040
35041
35042 \begin_inset LatexCommand index
35043 name "Quality control"
35044
35045 \end_inset
35046
35047
35048 \end_layout
35049
35050 \begin_layout Standard
35051 The compiler is passed through snaphot build compile and build checks.
35052  The so called 
35053 \shape italic
35054 regression tests
35055 \shape default
35056
35057 \begin_inset LatexCommand index
35058 name "Regression test"
35059
35060 \end_inset
35061
35062  check that SDCC itself compiles flawlessly on several host platforms (i386,
35063  Opteron, 64 bit Alpha, ppc64, Mac OS X on ppc and i386, Solaris on Sparc)
35064  and checks the quality of the code generated by SDCC by running the code
35065  for several target platforms through simulators.
35066  The regression test suite comprises more than 100 files which expand to
35067  more than 500 test cases which include more than 4500 tests.
35068  The results of these tests are published daily on SDCC's snapshot page
35069  (click on the red or green symbols on the right side of 
35070 \begin_inset LatexCommand url
35071 target "http://sdcc.sourceforge.net/snap.php"
35072
35073 \end_inset
35074
35075 ).
35076 \end_layout
35077
35078 \begin_layout Standard
35079 There is a separate document 
35080 \shape italic
35081 test_suite.pdf 
35082 \begin_inset LatexCommand index
35083 name "Test suite"
35084
35085 \end_inset
35086
35087
35088 \shape default
35089  
35090 \begin_inset LatexCommand url
35091 target "http://sdcc.sourceforge.net/doc/test_suite_spec.pdf"
35092
35093 \end_inset
35094
35095  about the regression test suite.
35096 \end_layout
35097
35098 \begin_layout Standard
35099 You'll find the test code in the directory 
35100 \shape italic
35101 sdcc/support/regression
35102 \shape default
35103 .
35104  You can run these tests manually by running 
35105 \family sans
35106 make
35107 \family default
35108  in this directory (or f.e.
35109  
35110 \family sans
35111 \series bold
35112
35113 \begin_inset Quotes sld
35114 \end_inset
35115
35116 make test-mcs51
35117 \begin_inset Quotes srd
35118 \end_inset
35119
35120
35121 \family default
35122 \series default
35123  if you don't want to run the complete tests).
35124  The test code might also be interesting if you want to look for examples
35125 \begin_inset LatexCommand index
35126 name "Examples"
35127
35128 \end_inset
35129
35130  checking corner cases of SDCC or if you plan to submit patches
35131 \begin_inset LatexCommand index
35132 name "Patch submission"
35133
35134 \end_inset
35135
35136 .
35137 \end_layout
35138
35139 \begin_layout Standard
35140 The PIC14 port uses a different set of regression tests 
35141 \begin_inset LatexCommand index
35142 name "Regression test (PIC14)"
35143
35144 \end_inset
35145
35146 , you'll find them in the directory 
35147 \shape italic
35148 sdcc/src/regression
35149 \shape default
35150 .
35151 \end_layout
35152
35153 \begin_layout Section
35154 Use of SDCC in Education
35155 \end_layout
35156
35157 \begin_layout Standard
35158 In short: 
35159 \emph on
35160 highly
35161 \emph default
35162  encouraged
35163 \begin_inset Foot
35164 status open
35165
35166 \begin_layout Standard
35167 the phrase "use in education" might evoke the association "
35168 \emph on
35169 only
35170 \emph default
35171  fit for use in education".
35172  This connotation is not intended but nevertheless risked as the licensing
35173  of SDCC makes it difficult to offer educational discounts
35174 \end_layout
35175
35176 \end_inset
35177
35178 .
35179  If your rationales are to:
35180 \end_layout
35181
35182 \begin_layout Enumerate
35183 give students a chance to understand the 
35184 \emph on
35185 complete
35186 \emph default
35187  steps of code generation
35188 \end_layout
35189
35190 \begin_layout Enumerate
35191 have a curriculum that can be extended for years.
35192  Then you could use an fpga board as target and your curriculum will seamlessly
35193  extend from logic synthesis (
35194 \begin_inset LatexCommand url
35195 name "http://www.opencores.org"
35196 target "opencores.org"
35197
35198 \end_inset
35199
35200
35201 \begin_inset LatexCommand url
35202 name "Oregano"
35203 target "http://www.oregano.at/ip/ip01.htm"
35204
35205 \end_inset
35206
35207 ), over assembly programming, to C to FPGA compilers (
35208 \begin_inset LatexCommand url
35209 name "FPGAC"
35210 target "http://sf.net/projects/fpgac"
35211
35212 \end_inset
35213
35214 ) and to C.
35215 \end_layout
35216
35217 \begin_layout Enumerate
35218 be able to insert excursions about skills like using a revision control
35219  system, submitting/applying patches, using a type-setting (as opposed to
35220  word-processing) engine LyX/LaTeX, using 
35221 \begin_inset LatexCommand url
35222 name "SourceForge"
35223 target "http://www.sf.net"
35224
35225 \end_inset
35226
35227 , following some 
35228 \begin_inset LatexCommand url
35229 name "netiquette"
35230 target "http://en.wikipedia.org/wiki/Netiquette"
35231
35232 \end_inset
35233
35234 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
35235  Source Software, CPU simulation, compiler regression tests
35236 \begin_inset LatexCommand index
35237 name "Regression test"
35238
35239 \end_inset
35240
35241 .
35242  
35243 \newline
35244 And if there should be a shortage of ideas then you can always point students
35245  to the ever-growing feature request list 
35246 \begin_inset LatexCommand htmlurl
35247 target "http://sourceforge.net/tracker/?group_id=599&atid=350599"
35248
35249 \end_inset
35250
35251 .
35252 \end_layout
35253
35254 \begin_layout Enumerate
35255 not tie students to a specific host platform and instead allow them to use
35256  a host platform of 
35257 \emph on
35258 their
35259 \emph default
35260  choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
35261  and eventually 
35262 \begin_inset LatexCommand url
35263 name "OLPC"
35264 target "http://www.laptop.org"
35265
35266 \end_inset
35267
35268 )
35269 \end_layout
35270
35271 \begin_layout Enumerate
35272 not encourage students to use illegal copies of educational software
35273 \end_layout
35274
35275 \begin_layout Enumerate
35276 be immune to licensing/availability/price changes of the chosen tool chain
35277 \end_layout
35278
35279 \begin_layout Enumerate
35280 be able to change to a new target platform without having to adopt a new
35281  tool chain
35282 \end_layout
35283
35284 \begin_layout Enumerate
35285 have complete control over and insight into the tool chain
35286 \end_layout
35287
35288 \begin_layout Enumerate
35289 make your students aware about the pros and cons of open source software
35290  development
35291 \end_layout
35292
35293 \begin_layout Enumerate
35294 give back to the public as you are probably at least partially publicly
35295  funded
35296 \end_layout
35297
35298 \begin_layout Enumerate
35299 give students a chance to publicly prove their skills and to possibly see
35300  a world wide impact
35301 \end_layout
35302
35303 \begin_layout Standard
35304 then SDCC is probably among the first choices.
35305  Well, probably SDCC might be the only choice.
35306 \newpage
35307
35308 \end_layout
35309
35310 \begin_layout Chapter
35311 SDCC Technical Data
35312 \end_layout
35313
35314 \begin_layout Section
35315 Optimizations
35316 \begin_inset LatexCommand index
35317 name "Optimizations"
35318
35319 \end_inset
35320
35321
35322 \end_layout
35323
35324 \begin_layout Standard
35325 SDCC performs a host of standard optimizations in addition to some MCU specific
35326  optimizations.
35327  
35328 \end_layout
35329
35330 \begin_layout Subsection
35331 Sub-expression Elimination
35332 \begin_inset LatexCommand index
35333 name "Subexpression elimination"
35334
35335 \end_inset
35336
35337
35338 \end_layout
35339
35340 \begin_layout Standard
35341 The compiler does local and 
35342 \emph on
35343 g
35344 \emph default
35345 lobal 
35346 \emph on
35347 c
35348 \emph default
35349 ommon 
35350 \emph on
35351 s
35352 \emph default
35353 ubexpression 
35354 \emph on
35355 e
35356 \emph default
35357 limination, e.g.: 
35358 \end_layout
35359
35360 \begin_layout Verse
35361
35362 \family typewriter
35363 i = x + y + 1; 
35364 \newline
35365 j = x + y;
35366 \end_layout
35367
35368 \begin_layout Standard
35369 will be translated to
35370 \end_layout
35371
35372 \begin_layout Verse
35373
35374 \family typewriter
35375 iTemp = x + y; 
35376 \newline
35377 i = iTemp + 1; 
35378 \newline
35379 j = iTemp;
35380 \end_layout
35381
35382 \begin_layout Standard
35383 Some subexpressions are not as obvious as the above example, e.g.:
35384 \end_layout
35385
35386 \begin_layout Verse
35387
35388 \family typewriter
35389 a->b[i].c = 10; 
35390 \newline
35391 a->b[i].d = 11;
35392 \end_layout
35393
35394 \begin_layout Standard
35395 In this case the address arithmetic a->b[i] will be computed only once;
35396  the equivalent code in C would be.
35397 \end_layout
35398
35399 \begin_layout Verse
35400
35401 \family typewriter
35402 iTemp = a->b[i]; 
35403 \newline
35404 iTemp.c = 10; 
35405 \newline
35406 iTemp.d = 11;
35407 \end_layout
35408
35409 \begin_layout Standard
35410 The compiler will try to keep these temporary variables in registers.
35411 \end_layout
35412
35413 \begin_layout Subsection
35414 Dead-Code Elimination
35415 \begin_inset LatexCommand index
35416 name "Dead-code elimination"
35417
35418 \end_inset
35419
35420
35421 \end_layout
35422
35423 \begin_layout Verse
35424
35425 \family typewriter
35426 int global;
35427 \newline
35428
35429 \newline
35430 void f () { 
35431 \newline
35432 \InsetSpace ~
35433 \InsetSpace ~
35434 int i; 
35435 \newline
35436 \InsetSpace ~
35437 \InsetSpace ~
35438 i = 1; \InsetSpace ~
35439 \InsetSpace ~
35440 \InsetSpace ~
35441 \InsetSpace ~
35442 \InsetSpace ~
35443 /* dead store */ 
35444 \newline
35445 \InsetSpace ~
35446 \InsetSpace ~
35447 global = 1;\InsetSpace ~
35448 /* dead
35449  store */ 
35450 \newline
35451 \InsetSpace ~
35452 \InsetSpace ~
35453 global = 2; 
35454 \newline
35455 \InsetSpace ~
35456 \InsetSpace ~
35457 return; 
35458 \newline
35459 \InsetSpace ~
35460 \InsetSpace ~
35461 global = 3;\InsetSpace ~
35462 /* unreachable */ 
35463 \newline
35464 }
35465 \end_layout
35466
35467 \begin_layout Standard
35468 will be changed to
35469 \end_layout
35470
35471 \begin_layout Verse
35472
35473 \family typewriter
35474 int global;
35475 \newline
35476
35477 \newline
35478 void f () {
35479 \newline
35480 \InsetSpace ~
35481 \InsetSpace ~
35482 global = 2; 
35483 \newline
35484 }
35485 \end_layout
35486
35487 \begin_layout Subsection
35488 Copy-Propagation
35489 \begin_inset LatexCommand index
35490 name "Copy propagation"
35491
35492 \end_inset
35493
35494
35495 \end_layout
35496
35497 \begin_layout Verse
35498
35499 \family typewriter
35500 int f() { 
35501 \newline
35502 \InsetSpace ~
35503 \InsetSpace ~
35504 int i, j; 
35505 \newline
35506 \InsetSpace ~
35507 \InsetSpace ~
35508 i = 10; 
35509 \newline
35510 \InsetSpace ~
35511 \InsetSpace ~
35512 j = i; 
35513 \newline
35514 \InsetSpace ~
35515 \InsetSpace ~
35516 return j; 
35517 \newline
35518 }
35519 \end_layout
35520
35521 \begin_layout Standard
35522 will be changed to 
35523 \end_layout
35524
35525 \begin_layout Verse
35526
35527 \family typewriter
35528 int f() { 
35529 \newline
35530 \InsetSpace ~
35531 \InsetSpace ~
35532 int i, j; 
35533 \newline
35534 \InsetSpace ~
35535 \InsetSpace ~
35536 i = 10; 
35537 \newline
35538 \InsetSpace ~
35539 \InsetSpace ~
35540 j = 10; 
35541 \newline
35542 \InsetSpace ~
35543 \InsetSpace ~
35544 return 10; 
35545 \newline
35546 }
35547 \end_layout
35548
35549 \begin_layout Standard
35550 Note: the dead stores created by this copy propagation will be eliminated
35551  by dead-code elimination.
35552 \end_layout
35553
35554 \begin_layout Subsection
35555 Loop Optimizations
35556 \begin_inset LatexCommand index
35557 name "Loop optimization"
35558
35559 \end_inset
35560
35561
35562 \begin_inset LatexCommand label
35563 name "sub:Loop-Optimizations"
35564
35565 \end_inset
35566
35567
35568 \end_layout
35569
35570 \begin_layout Standard
35571 Two types of loop optimizations are done by SDCC 
35572 \emph on
35573 loop invariant
35574 \emph default
35575  lifting and 
35576 \emph on
35577 strength reduction
35578 \emph default
35579  of loop induction variables.
35580  In addition to the strength reduction the optimizer marks the induction
35581  variables and the register allocator tries to keep the induction variables
35582  in registers for the duration of the loop.
35583  Because of this preference of the register allocator
35584 \begin_inset LatexCommand index
35585 name "Register allocation"
35586
35587 \end_inset
35588
35589 , loop induction optimization causes an increase in register pressure, which
35590  may cause unwanted spilling of other temporary variables into the stack
35591 \begin_inset LatexCommand index
35592 name "stack"
35593
35594 \end_inset
35595
35596  / data space.
35597  The compiler will generate a warning message when it is forced to allocate
35598  extra space either on the stack or data space.
35599  If this extra space allocation is undesirable then induction optimization
35600  can be eliminated either for the entire source file (with -
35601 \begin_inset ERT
35602 status collapsed
35603
35604 \begin_layout Standard
35605
35606
35607 \backslash
35608 /
35609 \end_layout
35610
35611 \end_inset
35612
35613 -noinduction option) or for a given function only using #pragma\InsetSpace ~
35614 noinduction
35615 \begin_inset LatexCommand index
35616 name "\\#pragma noinduction"
35617
35618 \end_inset
35619
35620 .
35621 \newline
35622
35623 \newline
35624 Loop Invariant:
35625 \end_layout
35626
35627 \begin_layout Verse
35628
35629 \family typewriter
35630 for (i = 0 ; i < 100 ; i ++) 
35631 \newline
35632 \InsetSpace ~
35633 \InsetSpace ~
35634 \InsetSpace ~
35635 \InsetSpace ~
35636 f += k + l;
35637 \end_layout
35638
35639 \begin_layout Standard
35640 changed to
35641 \end_layout
35642
35643 \begin_layout Verse
35644
35645 \family typewriter
35646 itemp = k + l; 
35647 \newline
35648 for (i = 0; i < 100; i++) 
35649 \newline
35650 \InsetSpace ~
35651 \InsetSpace ~
35652 \InsetSpace ~
35653 \InsetSpace ~
35654 f += itemp;
35655 \end_layout
35656
35657 \begin_layout Standard
35658 As mentioned previously some loop invariants are not as apparent, all static
35659  address computations are also moved out of the loop.
35660 \newline
35661
35662 \newline
35663 Strength Reduction
35664 \begin_inset LatexCommand index
35665 name "Strength reduction"
35666
35667 \end_inset
35668
35669 , this optimization substitutes an expression by a cheaper expression:
35670 \end_layout
35671
35672 \begin_layout Verse
35673
35674 \family typewriter
35675 for (i=0;i < 100; i++)
35676 \newline
35677 \InsetSpace ~
35678 \InsetSpace ~
35679 \InsetSpace ~
35680 \InsetSpace ~
35681 ar[i*5] = i*3;
35682 \end_layout
35683
35684 \begin_layout Standard
35685 changed to
35686 \end_layout
35687
35688 \begin_layout Verse
35689
35690 \family typewriter
35691 itemp1 = 0; 
35692 \newline
35693 itemp2 = 0; 
35694 \newline
35695 for (i=0;i< 100;i++) { 
35696 \newline
35697 \InsetSpace ~
35698 \InsetSpace ~
35699 \InsetSpace ~
35700 \InsetSpace ~
35701 ar[itemp1] = itemp2; 
35702 \newline
35703 \InsetSpace ~
35704 \InsetSpace ~
35705 \InsetSpace ~
35706 \InsetSpace ~
35707 itemp1
35708  += 5; 
35709 \newline
35710 \InsetSpace ~
35711 \InsetSpace ~
35712 \InsetSpace ~
35713 \InsetSpace ~
35714 itemp2 += 3; 
35715 \newline
35716 }
35717 \end_layout
35718
35719 \begin_layout Standard
35720 The more expensive multiplication
35721 \begin_inset LatexCommand index
35722 name "Multiplication"
35723
35724 \end_inset
35725
35726  is changed to a less expensive addition.
35727 \end_layout
35728
35729 \begin_layout Subsection
35730 Loop Reversing
35731 \begin_inset LatexCommand index
35732 name "Loop reversing"
35733
35734 \end_inset
35735
35736
35737 \end_layout
35738
35739 \begin_layout Standard
35740 This optimization is done to reduce the overhead of checking loop boundaries
35741  for every iteration.
35742  Some simple loops can be reversed and implemented using a 
35743 \begin_inset Quotes eld
35744 \end_inset
35745
35746 decrement and jump if not zero
35747 \begin_inset Quotes erd
35748 \end_inset
35749
35750  instruction.
35751  SDCC checks for the following criterion to determine if a loop is reversible
35752  (note: more sophisticated compilers use data-dependency analysis to make
35753  this determination, SDCC uses a more simple minded analysis).
35754 \end_layout
35755
35756 \begin_layout Itemize
35757 The 'for' loop is of the form 
35758 \newline
35759
35760 \newline
35761
35762 \family typewriter
35763 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
35764  += 1])
35765 \newline
35766 \InsetSpace ~
35767 \InsetSpace ~
35768 \InsetSpace ~
35769 \InsetSpace ~
35770 <for body>
35771 \end_layout
35772
35773 \begin_layout Itemize
35774 The <for body> does not contain 
35775 \begin_inset Quotes eld
35776 \end_inset
35777
35778 continue
35779 \begin_inset Quotes erd
35780 \end_inset
35781
35782  or 'break
35783 \begin_inset Quotes erd
35784 \end_inset
35785
35786 .
35787 \end_layout
35788
35789 \begin_layout Itemize
35790 All goto's are contained within the loop.
35791 \end_layout
35792
35793 \begin_layout Itemize
35794 No function calls within the loop.
35795 \end_layout
35796
35797 \begin_layout Itemize
35798 The loop control variable <sym> is not assigned any value within the loop
35799 \end_layout
35800
35801 \begin_layout Itemize
35802 The loop control variable does NOT participate in any arithmetic operation
35803  within the loop.
35804 \end_layout
35805
35806 \begin_layout Itemize
35807 There are NO switch statements in the loop.
35808 \end_layout
35809
35810 \begin_layout Subsection
35811 Algebraic Simplifications
35812 \end_layout
35813
35814 \begin_layout Standard
35815 SDCC does numerous algebraic simplifications, the following is a small sub-set
35816  of these optimizations.
35817 \end_layout
35818
35819 \begin_layout Verse
35820
35821 \family typewriter
35822 i = j + 0;\InsetSpace ~
35823 \InsetSpace ~
35824 \InsetSpace ~
35825 \InsetSpace ~
35826  /* changed to: */\InsetSpace ~
35827 \InsetSpace ~
35828 \InsetSpace ~
35829 \InsetSpace ~
35830  i = j; 
35831 \newline
35832 i /= 2;\InsetSpace ~
35833 \InsetSpace ~
35834 \InsetSpace ~
35835 \InsetSpace ~
35836 \InsetSpace ~
35837 \InsetSpace ~
35838 \InsetSpace ~
35839  /* changed to: */\InsetSpace ~
35840 \InsetSpace ~
35841 \InsetSpace ~
35842 \InsetSpace ~
35843  i >>= 1; 
35844 \newline
35845 i
35846  = j - j;\InsetSpace ~
35847 \InsetSpace ~
35848 \InsetSpace ~
35849 \InsetSpace ~
35850  /* changed to: */\InsetSpace ~
35851 \InsetSpace ~
35852 \InsetSpace ~
35853 \InsetSpace ~
35854  i = 0; 
35855 \newline
35856 i = j / 1;\InsetSpace ~
35857 \InsetSpace ~
35858 \InsetSpace ~
35859 \InsetSpace ~
35860  /* changed to: */\InsetSpace ~
35861 \InsetSpace ~
35862 \InsetSpace ~
35863 \InsetSpace ~
35864  i = j;
35865 \end_layout
35866
35867 \begin_layout Standard
35868 Note the subexpressions
35869 \begin_inset LatexCommand index
35870 name "Subexpression"
35871
35872 \end_inset
35873
35874  given above are generally introduced by macro expansions or as a result
35875  of copy/constant propagation.
35876 \end_layout
35877
35878 \begin_layout Subsection
35879 'switch' Statements
35880 \begin_inset LatexCommand label
35881 name "sub:'switch'-Statements"
35882
35883 \end_inset
35884
35885
35886 \begin_inset LatexCommand index
35887 name "switch statement"
35888
35889 \end_inset
35890
35891
35892 \end_layout
35893
35894 \begin_layout Standard
35895 SDCC can optimize switch statements to jump tables
35896 \begin_inset LatexCommand index
35897 name "jump tables"
35898
35899 \end_inset
35900
35901 .
35902  It makes the decision based on an estimate of the generated code size.
35903  SDCC is quite liberal in the requirements for jump table generation: 
35904 \end_layout
35905
35906 \begin_layout Itemize
35907 The labels need not be in order, and the starting number need not be one
35908  or zero, the case labels are in numerical sequence or not too many case
35909  labels are missing.
35910 \end_layout
35911
35912 \begin_deeper
35913 \begin_layout Verse
35914
35915 \family typewriter
35916 switch(i) {\InsetSpace ~
35917 \InsetSpace ~
35918 \InsetSpace ~
35919 \InsetSpace ~
35920 \InsetSpace ~
35921 \InsetSpace ~
35922 \InsetSpace ~
35923 \InsetSpace ~
35924 \InsetSpace ~
35925 \InsetSpace ~
35926 \InsetSpace ~
35927 \InsetSpace ~
35928 \InsetSpace ~
35929 \InsetSpace ~
35930 \InsetSpace ~
35931 \InsetSpace ~
35932 \InsetSpace ~
35933 \InsetSpace ~
35934 \InsetSpace ~
35935 \InsetSpace ~
35936 \InsetSpace ~
35937 \InsetSpace ~
35938 \InsetSpace ~
35939 \InsetSpace ~
35940 \InsetSpace ~
35941 \InsetSpace ~
35942 switch (i) { 
35943 \newline
35944 \InsetSpace ~
35945 \InsetSpace ~
35946 \InsetSpace ~
35947 case 4: ...\InsetSpace ~
35948 \InsetSpace ~
35949 \InsetSpace ~
35950 \InsetSpace ~
35951 \InsetSpace ~
35952 \InsetSpace ~
35953 \InsetSpace ~
35954 \InsetSpace ~
35955 \InsetSpace ~
35956 \InsetSpace ~
35957 \InsetSpace ~
35958 \InsetSpace ~
35959 \InsetSpace ~
35960 \InsetSpace ~
35961 \InsetSpace ~
35962 \InsetSpace ~
35963 \InsetSpace ~
35964 \InsetSpace ~
35965 \InsetSpace ~
35966 \InsetSpace ~
35967 \InsetSpace ~
35968 \InsetSpace ~
35969 \InsetSpace ~
35970 \InsetSpace ~
35971 \InsetSpace ~
35972 \InsetSpace ~
35973 case 0: ...
35974  
35975 \newline
35976 \InsetSpace ~
35977 \InsetSpace ~
35978 \InsetSpace ~
35979 case 5: ...\InsetSpace ~
35980 \InsetSpace ~
35981 \InsetSpace ~
35982 \InsetSpace ~
35983 \InsetSpace ~
35984 \InsetSpace ~
35985 \InsetSpace ~
35986 \InsetSpace ~
35987 \InsetSpace ~
35988 \InsetSpace ~
35989 \InsetSpace ~
35990 \InsetSpace ~
35991 \InsetSpace ~
35992 \InsetSpace ~
35993 \InsetSpace ~
35994 \InsetSpace ~
35995 \InsetSpace ~
35996 \InsetSpace ~
35997 \InsetSpace ~
35998 \InsetSpace ~
35999 \InsetSpace ~
36000 \InsetSpace ~
36001 \InsetSpace ~
36002 \InsetSpace ~
36003 \InsetSpace ~
36004 \InsetSpace ~
36005 case 1: ...
36006  
36007 \newline
36008 \InsetSpace ~
36009 \InsetSpace ~
36010 \InsetSpace ~
36011 case 3: ...\InsetSpace ~
36012 \InsetSpace ~
36013 \InsetSpace ~
36014 \InsetSpace ~
36015 \InsetSpace ~
36016 \InsetSpace ~
36017 \InsetSpace ~
36018 \InsetSpace ~
36019 \InsetSpace ~
36020 \InsetSpace ~
36021 \InsetSpace ~
36022 \InsetSpace ~
36023 \InsetSpace ~
36024 \InsetSpace ~
36025 \InsetSpace ~
36026 \InsetSpace ~
36027 \InsetSpace ~
36028 \InsetSpace ~
36029 \InsetSpace ~
36030 \InsetSpace ~
36031 \InsetSpace ~
36032 \InsetSpace ~
36033 \InsetSpace ~
36034 \InsetSpace ~
36035 \InsetSpace ~
36036 \InsetSpace ~
36037
36038 \newline
36039 \InsetSpace ~
36040 \InsetSpace ~
36041 \InsetSpace ~
36042 case 6: ...\InsetSpace ~
36043 \InsetSpace ~
36044 \InsetSpace ~
36045 \InsetSpace ~
36046 \InsetSpace ~
36047 \InsetSpace ~
36048 \InsetSpace ~
36049 \InsetSpace ~
36050 \InsetSpace ~
36051 \InsetSpace ~
36052 \InsetSpace ~
36053 \InsetSpace ~
36054 \InsetSpace ~
36055 \InsetSpace ~
36056 \InsetSpace ~
36057 \InsetSpace ~
36058 \InsetSpace ~
36059 \InsetSpace ~
36060 \InsetSpace ~
36061 \InsetSpace ~
36062 \InsetSpace ~
36063 \InsetSpace ~
36064 \InsetSpace ~
36065 \InsetSpace ~
36066 \InsetSpace ~
36067 \InsetSpace ~
36068 case 3: ...
36069  
36070 \newline
36071 \InsetSpace ~
36072 \InsetSpace ~
36073 \InsetSpace ~
36074 case 7: ...\InsetSpace ~
36075 \InsetSpace ~
36076 \InsetSpace ~
36077 \InsetSpace ~
36078 \InsetSpace ~
36079 \InsetSpace ~
36080 \InsetSpace ~
36081 \InsetSpace ~
36082 \InsetSpace ~
36083 \InsetSpace ~
36084 \InsetSpace ~
36085 \InsetSpace ~
36086 \InsetSpace ~
36087 \InsetSpace ~
36088 \InsetSpace ~
36089 \InsetSpace ~
36090 \InsetSpace ~
36091 \InsetSpace ~
36092 \InsetSpace ~
36093 \InsetSpace ~
36094 \InsetSpace ~
36095 \InsetSpace ~
36096 \InsetSpace ~
36097 \InsetSpace ~
36098 \InsetSpace ~
36099 \InsetSpace ~
36100 case 4: ...
36101  
36102 \newline
36103 \InsetSpace ~
36104 \InsetSpace ~
36105 \InsetSpace ~
36106 case 8: ...\InsetSpace ~
36107 \InsetSpace ~
36108 \InsetSpace ~
36109 \InsetSpace ~
36110 \InsetSpace ~
36111 \InsetSpace ~
36112 \InsetSpace ~
36113 \InsetSpace ~
36114 \InsetSpace ~
36115 \InsetSpace ~
36116 \InsetSpace ~
36117 \InsetSpace ~
36118 \InsetSpace ~
36119 \InsetSpace ~
36120 \InsetSpace ~
36121 \InsetSpace ~
36122 \InsetSpace ~
36123 \InsetSpace ~
36124 \InsetSpace ~
36125 \InsetSpace ~
36126 \InsetSpace ~
36127 \InsetSpace ~
36128 \InsetSpace ~
36129 \InsetSpace ~
36130 \InsetSpace ~
36131 \InsetSpace ~
36132 case 5: ...
36133  
36134 \newline
36135 \InsetSpace ~
36136 \InsetSpace ~
36137 \InsetSpace ~
36138 case 9: ...\InsetSpace ~
36139 \InsetSpace ~
36140 \InsetSpace ~
36141 \InsetSpace ~
36142 \InsetSpace ~
36143 \InsetSpace ~
36144 \InsetSpace ~
36145 \InsetSpace ~
36146 \InsetSpace ~
36147 \InsetSpace ~
36148 \InsetSpace ~
36149 \InsetSpace ~
36150 \InsetSpace ~
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 case 6: ...
36165  
36166 \newline
36167 \InsetSpace ~
36168 \InsetSpace ~
36169 \InsetSpace ~
36170 case 10: ...\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 \InsetSpace ~
36188 \InsetSpace ~
36189 \InsetSpace ~
36190 \InsetSpace ~
36191 \InsetSpace ~
36192 \InsetSpace ~
36193 \InsetSpace ~
36194 \InsetSpace ~
36195 case 7: ...
36196  
36197 \newline
36198 \InsetSpace ~
36199 \InsetSpace ~
36200 \InsetSpace ~
36201 case 11: ...\InsetSpace ~
36202 \InsetSpace ~
36203 \InsetSpace ~
36204 \InsetSpace ~
36205 \InsetSpace ~
36206 \InsetSpace ~
36207 \InsetSpace ~
36208 \InsetSpace ~
36209 \InsetSpace ~
36210 \InsetSpace ~
36211 \InsetSpace ~
36212 \InsetSpace ~
36213 \InsetSpace ~
36214 \InsetSpace ~
36215 \InsetSpace ~
36216 \InsetSpace ~
36217 \InsetSpace ~
36218 \InsetSpace ~
36219 \InsetSpace ~
36220 \InsetSpace ~
36221 \InsetSpace ~
36222 \InsetSpace ~
36223 \InsetSpace ~
36224 \InsetSpace ~
36225 \InsetSpace ~
36226 case 8: ...
36227  
36228 \newline
36229 }\InsetSpace ~
36230 \InsetSpace ~
36231 \InsetSpace ~
36232 \InsetSpace ~
36233 \InsetSpace ~
36234 \InsetSpace ~
36235 \InsetSpace ~
36236 \InsetSpace ~
36237 \InsetSpace ~
36238 \InsetSpace ~
36239 \InsetSpace ~
36240 \InsetSpace ~
36241 \InsetSpace ~
36242 \InsetSpace ~
36243 \InsetSpace ~
36244 \InsetSpace ~
36245 \InsetSpace ~
36246 \InsetSpace ~
36247 \InsetSpace ~
36248 \InsetSpace ~
36249 \InsetSpace ~
36250 \InsetSpace ~
36251 \InsetSpace ~
36252 \InsetSpace ~
36253 \InsetSpace ~
36254 \InsetSpace ~
36255 \InsetSpace ~
36256 \InsetSpace ~
36257 \InsetSpace ~
36258 \InsetSpace ~
36259 \InsetSpace ~
36260 \InsetSpace ~
36261 \InsetSpace ~
36262 \InsetSpace ~
36263 \InsetSpace ~
36264 \InsetSpace ~
36265 }
36266 \end_layout
36267
36268 \begin_layout Standard
36269 Both the above switch statements will be implemented using a jump-table.
36270  The example to the right side is slightly more efficient as the check for
36271  the lower boundary of the jump-table is not needed.
36272 \end_layout
36273
36274 \end_deeper
36275 \begin_layout Itemize
36276 The number of case labels is not larger than supported by the target architectur
36277 e.
36278 \end_layout
36279
36280 \begin_layout Itemize
36281 If the case labels are not in numerical sequence ('gaps' between cases)
36282  SDCC checks whether a jump table with additionally inserted dummy cases
36283  is still attractive.
36284  
36285 \end_layout
36286
36287 \begin_layout Itemize
36288 If the starting number is not zero and a check for the lower boundary of
36289  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
36290  ...
36291  .
36292 \end_layout
36293
36294 \begin_layout Standard
36295 Switch statements which have large gaps in the numeric sequence or those
36296  that have too many case labels can be split into more than one switch statement
36297  for efficient code generation, e.g.:
36298 \end_layout
36299
36300 \begin_layout Verse
36301
36302 \family typewriter
36303 switch (i) { 
36304 \newline
36305 \InsetSpace ~
36306 \InsetSpace ~
36307 case 1: ...
36308  
36309 \newline
36310 \InsetSpace ~
36311 \InsetSpace ~
36312 case 2: ...
36313  
36314 \newline
36315 \InsetSpace ~
36316 \InsetSpace ~
36317 case 3: ...
36318  
36319 \newline
36320 \InsetSpace ~
36321 \InsetSpace ~
36322 case 4: ...
36323  
36324 \newline
36325 \InsetSpace ~
36326 \InsetSpace ~
36327 case 5: ...
36328  
36329 \newline
36330 \InsetSpace ~
36331 \InsetSpace ~
36332 case 6: ...
36333  
36334 \newline
36335 \InsetSpace ~
36336 \InsetSpace ~
36337 case 7: ...
36338  
36339 \newline
36340 \InsetSpace ~
36341 \InsetSpace ~
36342 case 101: ...
36343  
36344 \newline
36345 \InsetSpace ~
36346 \InsetSpace ~
36347 case 102: ...
36348  
36349 \newline
36350 \InsetSpace ~
36351 \InsetSpace ~
36352 case 103: ...
36353  
36354 \newline
36355 \InsetSpace ~
36356 \InsetSpace ~
36357 case 104: ...
36358  
36359 \newline
36360 \InsetSpace ~
36361 \InsetSpace ~
36362 case 105: ...
36363  
36364 \newline
36365 \InsetSpace ~
36366 \InsetSpace ~
36367 case 106: ...
36368  
36369 \newline
36370 \InsetSpace ~
36371 \InsetSpace ~
36372 case 107: ...
36373  
36374 \newline
36375 }
36376 \end_layout
36377
36378 \begin_layout Standard
36379 If the above switch statement is broken down into two switch statements
36380 \end_layout
36381
36382 \begin_layout Verse
36383
36384 \family typewriter
36385 switch (i) { 
36386 \newline
36387 \InsetSpace ~
36388 \InsetSpace ~
36389 case 1: ...
36390  
36391 \newline
36392 \InsetSpace ~
36393 \InsetSpace ~
36394 case 2: ...
36395  
36396 \newline
36397 \InsetSpace ~
36398 \InsetSpace ~
36399 case 3: ...
36400  
36401 \newline
36402 \InsetSpace ~
36403 \InsetSpace ~
36404 case 4: ...
36405  
36406 \newline
36407 \InsetSpace ~
36408 \InsetSpace ~
36409 case 5: ...
36410  
36411 \newline
36412 \InsetSpace ~
36413 \InsetSpace ~
36414 case 6: ...
36415  
36416 \newline
36417 \InsetSpace ~
36418 \InsetSpace ~
36419 case 7: ...
36420  
36421 \newline
36422 }
36423 \end_layout
36424
36425 \begin_layout Standard
36426 and
36427 \end_layout
36428
36429 \begin_layout Verse
36430
36431 \family typewriter
36432 switch (i) { 
36433 \newline
36434 \InsetSpace ~
36435 \InsetSpace ~
36436 case 101: ...
36437  
36438 \newline
36439 \InsetSpace ~
36440 \InsetSpace ~
36441 case 102: ...
36442  
36443 \newline
36444 \InsetSpace ~
36445 \InsetSpace ~
36446 case 103: ...
36447  
36448 \newline
36449 \InsetSpace ~
36450 \InsetSpace ~
36451 case 104: ...
36452  
36453 \newline
36454 \InsetSpace ~
36455 \InsetSpace ~
36456 case 105: ...
36457  
36458 \newline
36459 \InsetSpace ~
36460 \InsetSpace ~
36461 case 106: ...
36462  
36463 \newline
36464 \InsetSpace ~
36465 \InsetSpace ~
36466 case 107: ...
36467  
36468 \newline
36469 }
36470 \end_layout
36471
36472 \begin_layout Standard
36473 then both the switch statements will be implemented using jump-tables whereas
36474  the unmodified switch statement will not be.
36475 \end_layout
36476
36477 \begin_layout Standard
36478 \begin_inset Note Note
36479 status collapsed
36480
36481 \begin_layout Standard
36482 There might be reasons which SDCC cannot know about to either favour or
36483  not favour jump tables.
36484  If the target system has to be as quick for the last switch case as for
36485  the first (pro jump table), or if the switch argument is known to be zero
36486  in the majority of the cases (contra jump table).
36487 \end_layout
36488
36489 \end_inset
36490
36491
36492 \end_layout
36493
36494 \begin_layout Standard
36495 The pragma nojtbound
36496 \begin_inset LatexCommand index
36497 name "\\#pragma nojtbound"
36498
36499 \end_inset
36500
36501  can be used to turn off checking the 
36502 \emph on
36503 j
36504 \emph default
36505 ump 
36506 \emph on
36507 t
36508 \emph default
36509 able 
36510 \emph on
36511 bound
36512 \emph default
36513 aries.
36514  It has no effect if a default label is supplied.
36515  Use of this pragma is dangerous: if the switch
36516 \begin_inset LatexCommand index
36517 name "switch statement"
36518
36519 \end_inset
36520
36521  argument is not matched by a case statement the processor will happily
36522  jump into Nirvana.
36523 \end_layout
36524
36525 \begin_layout Subsection
36526 Bit-shifting Operations
36527 \begin_inset LatexCommand index
36528 name "Bit shifting"
36529
36530 \end_inset
36531
36532 .
36533 \end_layout
36534
36535 \begin_layout Standard
36536 Bit shifting is one of the most frequently used operation in embedded programmin
36537 g.
36538  SDCC tries to implement bit-shift operations in the most efficient way
36539  possible, e.g.:
36540 \end_layout
36541
36542 \begin_layout Verse
36543
36544 \family typewriter
36545 unsigned char i;
36546 \newline
36547 ...
36548  
36549 \newline
36550 i >>= 4; 
36551 \newline
36552 ...
36553 \end_layout
36554
36555 \begin_layout Standard
36556 generates the following code:
36557 \end_layout
36558
36559 \begin_layout Verse
36560
36561 \family typewriter
36562 mov\InsetSpace ~
36563  a,_i 
36564 \newline
36565 swap a 
36566 \newline
36567 anl\InsetSpace ~
36568  a,#0x0f 
36569 \newline
36570 mov\InsetSpace ~
36571  _i,a
36572 \end_layout
36573
36574 \begin_layout Standard
36575 In general SDCC will never setup a loop if the shift count is known.
36576  Another example:
36577 \end_layout
36578
36579 \begin_layout Verse
36580
36581 \family typewriter
36582 unsigned int i; 
36583 \newline
36584 ...
36585  
36586 \newline
36587 i >>= 9; 
36588 \newline
36589 ...
36590 \end_layout
36591
36592 \begin_layout Standard
36593 will generate:
36594 \end_layout
36595
36596 \begin_layout Verse
36597
36598 \family typewriter
36599 mov\InsetSpace ~
36600 \InsetSpace ~
36601 a,(_i + 1) 
36602 \newline
36603 mov\InsetSpace ~
36604 \InsetSpace ~
36605 (_i + 1),#0x00 
36606 \newline
36607 clr\InsetSpace ~
36608 \InsetSpace ~
36609
36610 \newline
36611 rrc\InsetSpace ~
36612 \InsetSpace ~
36613
36614 \newline
36615 mov\InsetSpace ~
36616 \InsetSpace ~
36617 _i,a
36618 \end_layout
36619
36620 \begin_layout Subsection
36621 Bit-rotation
36622 \begin_inset LatexCommand index
36623 name "Bit rotation"
36624
36625 \end_inset
36626
36627
36628 \end_layout
36629
36630 \begin_layout Standard
36631 A special case of the bit-shift operation is bit rotation
36632 \begin_inset LatexCommand index
36633 name "rotating bits"
36634
36635 \end_inset
36636
36637 , SDCC recognizes the following expression to be a left bit-rotation:
36638 \end_layout
36639
36640 \begin_layout Verse
36641
36642 \family typewriter
36643 \series bold
36644 unsigned
36645 \series default
36646 \InsetSpace ~
36647 \InsetSpace ~
36648 char i;\InsetSpace ~
36649 \InsetSpace ~
36650 \InsetSpace ~
36651 \InsetSpace ~
36652 \InsetSpace ~
36653 \InsetSpace ~
36654 \InsetSpace ~
36655 \InsetSpace ~
36656 \InsetSpace ~
36657 \InsetSpace ~
36658 \InsetSpace ~
36659 /* unsigned is needed for rotation */ 
36660 \newline
36661 ...
36662  
36663 \newline
36664 i = ((i << 1) | (i >> 7));
36665 \family default
36666  
36667 \newline
36668
36669 \family typewriter
36670 ...
36671 \end_layout
36672
36673 \begin_layout Standard
36674 will generate the following code:
36675 \end_layout
36676
36677 \begin_layout Verse
36678
36679 \family typewriter
36680 mov\InsetSpace ~
36681 \InsetSpace ~
36682 a,_i 
36683 \newline
36684 rl\InsetSpace ~
36685 \InsetSpace ~
36686 \InsetSpace ~
36687
36688 \newline
36689 mov\InsetSpace ~
36690 \InsetSpace ~
36691 _i,a
36692 \end_layout
36693
36694 \begin_layout Standard
36695 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
36696 ns of this case will also be recognized as bit-rotation, i.e.: 
36697 \end_layout
36698
36699 \begin_layout Verse
36700
36701 \family typewriter
36702 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
36703 \end_layout
36704
36705 \begin_layout Subsection
36706 Nibble and Byte Swapping
36707 \end_layout
36708
36709 \begin_layout Standard
36710 Other special cases of the bit-shift operations are nibble or byte swapping
36711 \begin_inset LatexCommand index
36712 name "swapping nibbles/bytes"
36713
36714 \end_inset
36715
36716 , SDCC recognizes the following expressions:
36717 \end_layout
36718
36719 \begin_layout Verse
36720
36721 \family typewriter
36722 \series bold
36723 unsigned
36724 \series default
36725 \InsetSpace ~
36726 \InsetSpace ~
36727 char i; 
36728 \newline
36729
36730 \series bold
36731 unsigned
36732 \series default
36733 \InsetSpace ~
36734 \InsetSpace ~
36735 int j; 
36736 \newline
36737 ...
36738  
36739 \newline
36740 i = ((i << 4) | (i >> 4));
36741 \family default
36742  
36743 \newline
36744
36745 \family typewriter
36746 j = ((j << 8) | (j >> 8)); 
36747 \end_layout
36748
36749 \begin_layout Standard
36750 and generates a swap instruction for the nibble swapping
36751 \begin_inset LatexCommand index
36752 name "Nibble swapping"
36753
36754 \end_inset
36755
36756  or move instructions for the byte swapping
36757 \begin_inset LatexCommand index
36758 name "Byte swapping"
36759
36760 \end_inset
36761
36762 .
36763  The 
36764 \begin_inset Quotes sld
36765 \end_inset
36766
36767 j
36768 \begin_inset Quotes srd
36769 \end_inset
36770
36771  example can be used to convert from little to big-endian or vice versa.
36772  If you want to change the endianness of a 
36773 \emph on
36774 signed
36775 \emph default
36776  integer you have to cast to 
36777 \family typewriter
36778 (unsigned int)
36779 \family default
36780  first.
36781 \end_layout
36782
36783 \begin_layout Standard
36784 Note that SDCC stores numbers in little-endian
36785 \begin_inset Foot
36786 status open
36787
36788 \begin_layout Standard
36789 Usually 8-bit processors don't care much about endianness.
36790  This is not the case for the standard 8051 which only has an instruction
36791  to increment its 
36792 \emph on
36793 dptr
36794 \emph default
36795
36796 \begin_inset LatexCommand index
36797 name "DPTR"
36798
36799 \end_inset
36800
36801 -datapointer so little-endian is the more efficient byte order.
36802 \end_layout
36803
36804 \end_inset
36805
36806
36807 \begin_inset LatexCommand index
36808 name "little-endian"
36809
36810 \end_inset
36811
36812
36813 \begin_inset LatexCommand index
36814 name "Endianness"
36815
36816 \end_inset
36817
36818  format (i.e.
36819  lowest order first).
36820 \end_layout
36821
36822 \begin_layout Subsection
36823 Highest Order Bit
36824 \begin_inset LatexCommand index
36825 name "Highest Order Bit"
36826
36827 \end_inset
36828
36829  / Any Order Bit
36830 \begin_inset LatexCommand index
36831 name "Any Order Bit"
36832
36833 \end_inset
36834
36835
36836 \end_layout
36837
36838 \begin_layout Standard
36839 It is frequently required to obtain the highest order bit of an integral
36840  type (long, int, short or char types).
36841  Also obtaining any other order bit is not uncommon.
36842  SDCC recognizes the following expressions to yield the highest order bit
36843  and generates optimized code for it, e.g.:
36844 \end_layout
36845
36846 \begin_layout Verse
36847
36848 \family typewriter
36849 unsigned int gint; 
36850 \newline
36851
36852 \newline
36853 foo () { 
36854 \newline
36855 \InsetSpace ~
36856 \InsetSpace ~
36857 unsigned char hob1, aob1; 
36858 \newline
36859 \InsetSpace ~
36860 \InsetSpace ~
36861 bit hob2, hob3, aob2,
36862  aob3; 
36863 \newline
36864 \InsetSpace ~
36865 \InsetSpace ~
36866 ...
36867  
36868 \newline
36869 \InsetSpace ~
36870 \InsetSpace ~
36871 hob1 = (gint >> 15) & 1; 
36872 \newline
36873 \InsetSpace ~
36874 \InsetSpace ~
36875 hob2 = (gint >> 15) & 1; 
36876 \newline
36877 \InsetSpace ~
36878 \InsetSpace ~
36879 hob3 = gint & 0x8000;
36880  
36881 \newline
36882 \InsetSpace ~
36883 \InsetSpace ~
36884 aob1 = (gint >> 9) & 1; 
36885 \newline
36886 \InsetSpace ~
36887 \InsetSpace ~
36888 aob2 = (gint >> 8) & 1; 
36889 \newline
36890 \InsetSpace ~
36891 \InsetSpace ~
36892 aob3 = gint & 0x0800; 
36893 \newline
36894 \InsetSpace ~
36895 \InsetSpace ~
36896 ..
36897  
36898 \newline
36899 }
36900 \end_layout
36901
36902 \begin_layout Standard
36903 will generate the following code:
36904 \end_layout
36905
36906 \begin_layout Verse
36907
36908 \family typewriter
36909 \InsetSpace ~
36910 \InsetSpace ~
36911 \InsetSpace ~
36912 \InsetSpace ~
36913 \InsetSpace ~
36914 \InsetSpace ~
36915 \InsetSpace ~
36916 \InsetSpace ~
36917 \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 \InsetSpace ~
36933 \InsetSpace ~
36934  61 ;\InsetSpace ~
36935  hob.c 7 
36936 \newline
36937 000A E5*01\InsetSpace ~
36938 \InsetSpace ~
36939 \InsetSpace ~
36940 \InsetSpace ~
36941 \InsetSpace ~
36942 \InsetSpace ~
36943 \InsetSpace ~
36944 \InsetSpace ~
36945 \InsetSpace ~
36946 \InsetSpace ~
36947 \InsetSpace ~
36948 \InsetSpace ~
36949 \InsetSpace ~
36950 \InsetSpace ~
36951 \InsetSpace ~
36952  62\InsetSpace ~
36953 \InsetSpace ~
36954 \InsetSpace ~
36955 \InsetSpace ~
36956 \InsetSpace ~
36957 \InsetSpace ~
36958 \InsetSpace ~
36959 \InsetSpace ~
36960  mov\InsetSpace ~
36961 \InsetSpace ~
36962  a,(_gint + 1) 
36963 \newline
36964 000C 23\InsetSpace ~
36965 \InsetSpace ~
36966 \InsetSpace ~
36967 \InsetSpace ~
36968 \InsetSpace ~
36969 \InsetSpace ~
36970 \InsetSpace ~
36971 \InsetSpace ~
36972 \InsetSpace ~
36973 \InsetSpace ~
36974 \InsetSpace ~
36975 \InsetSpace ~
36976 \InsetSpace ~
36977 \InsetSpace ~
36978 \InsetSpace ~
36979 \InsetSpace ~
36980 \InsetSpace ~
36981 \InsetSpace ~
36982  63\InsetSpace ~
36983 \InsetSpace ~
36984 \InsetSpace ~
36985 \InsetSpace ~
36986 \InsetSpace ~
36987 \InsetSpace ~
36988 \InsetSpace ~
36989 \InsetSpace ~
36990  rl\InsetSpace ~
36991 \InsetSpace ~
36992 \InsetSpace ~
36993  a 
36994 \newline
36995 000D 54 01\InsetSpace ~
36996 \InsetSpace ~
36997 \InsetSpace ~
36998 \InsetSpace ~
36999 \InsetSpace ~
37000 \InsetSpace ~
37001 \InsetSpace ~
37002 \InsetSpace ~
37003 \InsetSpace ~
37004 \InsetSpace ~
37005 \InsetSpace ~
37006 \InsetSpace ~
37007 \InsetSpace ~
37008 \InsetSpace ~
37009 \InsetSpace ~
37010
37011  64\InsetSpace ~
37012 \InsetSpace ~
37013 \InsetSpace ~
37014 \InsetSpace ~
37015 \InsetSpace ~
37016 \InsetSpace ~
37017 \InsetSpace ~
37018 \InsetSpace ~
37019  anl\InsetSpace ~
37020 \InsetSpace ~
37021  a,#0x01 
37022 \newline
37023 000F F5*02\InsetSpace ~
37024 \InsetSpace ~
37025 \InsetSpace ~
37026 \InsetSpace ~
37027 \InsetSpace ~
37028 \InsetSpace ~
37029 \InsetSpace ~
37030 \InsetSpace ~
37031 \InsetSpace ~
37032 \InsetSpace ~
37033 \InsetSpace ~
37034 \InsetSpace ~
37035 \InsetSpace ~
37036 \InsetSpace ~
37037 \InsetSpace ~
37038  65\InsetSpace ~
37039 \InsetSpace ~
37040 \InsetSpace ~
37041 \InsetSpace ~
37042 \InsetSpace ~
37043 \InsetSpace ~
37044 \InsetSpace ~
37045 \InsetSpace ~
37046  mov\InsetSpace ~
37047 \InsetSpace ~
37048  _foo_hob1_1_1,a 
37049 \newline
37050 \InsetSpace ~
37051 \InsetSpace ~
37052 \InsetSpace ~
37053 \InsetSpace ~
37054 \InsetSpace ~
37055 \InsetSpace ~
37056 \InsetSpace ~
37057 \InsetSpace ~
37058 \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 \InsetSpace ~
37074 \InsetSpace ~
37075  66 ;\InsetSpace ~
37076  hob.c 8 
37077 \newline
37078 0011 E5*01\InsetSpace ~
37079 \InsetSpace ~
37080 \InsetSpace ~
37081 \InsetSpace ~
37082 \InsetSpace ~
37083 \InsetSpace ~
37084 \InsetSpace ~
37085 \InsetSpace ~
37086 \InsetSpace ~
37087 \InsetSpace ~
37088 \InsetSpace ~
37089 \InsetSpace ~
37090 \InsetSpace ~
37091 \InsetSpace ~
37092 \InsetSpace ~
37093
37094  67\InsetSpace ~
37095 \InsetSpace ~
37096 \InsetSpace ~
37097 \InsetSpace ~
37098 \InsetSpace ~
37099 \InsetSpace ~
37100 \InsetSpace ~
37101 \InsetSpace ~
37102  mov\InsetSpace ~
37103 \InsetSpace ~
37104  a,(_gint + 1) 
37105 \newline
37106 0013 33\InsetSpace ~
37107 \InsetSpace ~
37108 \InsetSpace ~
37109 \InsetSpace ~
37110 \InsetSpace ~
37111 \InsetSpace ~
37112 \InsetSpace ~
37113 \InsetSpace ~
37114 \InsetSpace ~
37115 \InsetSpace ~
37116 \InsetSpace ~
37117 \InsetSpace ~
37118 \InsetSpace ~
37119 \InsetSpace ~
37120 \InsetSpace ~
37121 \InsetSpace ~
37122 \InsetSpace ~
37123 \InsetSpace ~
37124  68\InsetSpace ~
37125 \InsetSpace ~
37126 \InsetSpace ~
37127 \InsetSpace ~
37128 \InsetSpace ~
37129 \InsetSpace ~
37130 \InsetSpace ~
37131 \InsetSpace ~
37132  rlc\InsetSpace ~
37133 \InsetSpace ~
37134  a 
37135 \newline
37136 0014 92*00\InsetSpace ~
37137 \InsetSpace ~
37138 \InsetSpace ~
37139 \InsetSpace ~
37140 \InsetSpace ~
37141 \InsetSpace ~
37142 \InsetSpace ~
37143 \InsetSpace ~
37144 \InsetSpace ~
37145 \InsetSpace ~
37146 \InsetSpace ~
37147 \InsetSpace ~
37148 \InsetSpace ~
37149 \InsetSpace ~
37150 \InsetSpace ~
37151  69\InsetSpace ~
37152 \InsetSpace ~
37153 \InsetSpace ~
37154 \InsetSpace ~
37155 \InsetSpace ~
37156 \InsetSpace ~
37157 \InsetSpace ~
37158 \InsetSpace ~
37159  mov\InsetSpace ~
37160 \InsetSpace ~
37161  _foo_hob2_1_1,c
37162  
37163 \newline
37164 \InsetSpace ~
37165 \InsetSpace ~
37166 \InsetSpace ~
37167 \InsetSpace ~
37168 \InsetSpace ~
37169 \InsetSpace ~
37170 \InsetSpace ~
37171 \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 \InsetSpace ~
37187 \InsetSpace ~
37188 \InsetSpace ~
37189  66 ;\InsetSpace ~
37190  hob.c 9 
37191 \newline
37192 0016 E5*01\InsetSpace ~
37193 \InsetSpace ~
37194 \InsetSpace ~
37195 \InsetSpace ~
37196 \InsetSpace ~
37197 \InsetSpace ~
37198 \InsetSpace ~
37199 \InsetSpace ~
37200 \InsetSpace ~
37201 \InsetSpace ~
37202 \InsetSpace ~
37203 \InsetSpace ~
37204 \InsetSpace ~
37205 \InsetSpace ~
37206 \InsetSpace ~
37207  67\InsetSpace ~
37208 \InsetSpace ~
37209 \InsetSpace ~
37210 \InsetSpace ~
37211 \InsetSpace ~
37212 \InsetSpace ~
37213 \InsetSpace ~
37214 \InsetSpace ~
37215  mov\InsetSpace ~
37216 \InsetSpace ~
37217  a,(_gint + 1) 
37218 \newline
37219 0018 33\InsetSpace ~
37220 \InsetSpace ~
37221 \InsetSpace ~
37222 \InsetSpace ~
37223 \InsetSpace ~
37224 \InsetSpace ~
37225 \InsetSpace ~
37226 \InsetSpace ~
37227 \InsetSpace ~
37228 \InsetSpace ~
37229 \InsetSpace ~
37230 \InsetSpace ~
37231 \InsetSpace ~
37232 \InsetSpace ~
37233 \InsetSpace ~
37234 \InsetSpace ~
37235 \InsetSpace ~
37236 \InsetSpace ~
37237  68\InsetSpace ~
37238 \InsetSpace ~
37239 \InsetSpace ~
37240 \InsetSpace ~
37241 \InsetSpace ~
37242 \InsetSpace ~
37243 \InsetSpace ~
37244 \InsetSpace ~
37245  rlc\InsetSpace ~
37246 \InsetSpace ~
37247  a 
37248 \newline
37249 0019 92*01\InsetSpace ~
37250 \InsetSpace ~
37251 \InsetSpace ~
37252 \InsetSpace ~
37253 \InsetSpace ~
37254 \InsetSpace ~
37255 \InsetSpace ~
37256 \InsetSpace ~
37257 \InsetSpace ~
37258 \InsetSpace ~
37259 \InsetSpace ~
37260 \InsetSpace ~
37261 \InsetSpace ~
37262 \InsetSpace ~
37263 \InsetSpace ~
37264
37265  69\InsetSpace ~
37266 \InsetSpace ~
37267 \InsetSpace ~
37268 \InsetSpace ~
37269 \InsetSpace ~
37270 \InsetSpace ~
37271 \InsetSpace ~
37272 \InsetSpace ~
37273  mov\InsetSpace ~
37274 \InsetSpace ~
37275  _foo_hob3_1_1,c 
37276 \newline
37277 \InsetSpace ~
37278 \InsetSpace ~
37279 \InsetSpace ~
37280 \InsetSpace ~
37281 \InsetSpace ~
37282 \InsetSpace ~
37283 \InsetSpace ~
37284 \InsetSpace ~
37285 \InsetSpace ~
37286 \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 \InsetSpace ~
37302  70 ;\InsetSpace ~
37303  hob.c 10 
37304 \newline
37305 001B E5*01\InsetSpace ~
37306 \InsetSpace ~
37307 \InsetSpace ~
37308 \InsetSpace ~
37309 \InsetSpace ~
37310 \InsetSpace ~
37311 \InsetSpace ~
37312 \InsetSpace ~
37313 \InsetSpace ~
37314 \InsetSpace ~
37315 \InsetSpace ~
37316 \InsetSpace ~
37317 \InsetSpace ~
37318 \InsetSpace ~
37319 \InsetSpace ~
37320  71\InsetSpace ~
37321 \InsetSpace ~
37322 \InsetSpace ~
37323 \InsetSpace ~
37324 \InsetSpace ~
37325 \InsetSpace ~
37326 \InsetSpace ~
37327 \InsetSpace ~
37328  mov\InsetSpace ~
37329 \InsetSpace ~
37330  a,(_gint + 1) 
37331 \newline
37332 001D
37333  03\InsetSpace ~
37334 \InsetSpace ~
37335 \InsetSpace ~
37336 \InsetSpace ~
37337 \InsetSpace ~
37338 \InsetSpace ~
37339 \InsetSpace ~
37340 \InsetSpace ~
37341 \InsetSpace ~
37342 \InsetSpace ~
37343 \InsetSpace ~
37344 \InsetSpace ~
37345 \InsetSpace ~
37346 \InsetSpace ~
37347 \InsetSpace ~
37348 \InsetSpace ~
37349 \InsetSpace ~
37350 \InsetSpace ~
37351  72\InsetSpace ~
37352 \InsetSpace ~
37353 \InsetSpace ~
37354 \InsetSpace ~
37355 \InsetSpace ~
37356 \InsetSpace ~
37357 \InsetSpace ~
37358 \InsetSpace ~
37359  rr\InsetSpace ~
37360 \InsetSpace ~
37361 \InsetSpace ~
37362  a 
37363 \newline
37364 001E 54 01\InsetSpace ~
37365 \InsetSpace ~
37366 \InsetSpace ~
37367 \InsetSpace ~
37368 \InsetSpace ~
37369 \InsetSpace ~
37370 \InsetSpace ~
37371 \InsetSpace ~
37372 \InsetSpace ~
37373 \InsetSpace ~
37374 \InsetSpace ~
37375 \InsetSpace ~
37376 \InsetSpace ~
37377 \InsetSpace ~
37378 \InsetSpace ~
37379  73\InsetSpace ~
37380 \InsetSpace ~
37381 \InsetSpace ~
37382 \InsetSpace ~
37383 \InsetSpace ~
37384 \InsetSpace ~
37385 \InsetSpace ~
37386 \InsetSpace ~
37387  anl\InsetSpace ~
37388 \InsetSpace ~
37389  a,#0x01 
37390 \newline
37391 0020 F5*03\InsetSpace ~
37392 \InsetSpace ~
37393 \InsetSpace ~
37394 \InsetSpace ~
37395 \InsetSpace ~
37396 \InsetSpace ~
37397 \InsetSpace ~
37398 \InsetSpace ~
37399 \InsetSpace ~
37400 \InsetSpace ~
37401 \InsetSpace ~
37402 \InsetSpace ~
37403 \InsetSpace ~
37404 \InsetSpace ~
37405 \InsetSpace ~
37406  74\InsetSpace ~
37407 \InsetSpace ~
37408 \InsetSpace ~
37409 \InsetSpace ~
37410 \InsetSpace ~
37411 \InsetSpace ~
37412 \InsetSpace ~
37413 \InsetSpace ~
37414  mov\InsetSpace ~
37415 \InsetSpace ~
37416  _foo_aob1_1_1,a
37417  
37418 \newline
37419 \InsetSpace ~
37420 \InsetSpace ~
37421 \InsetSpace ~
37422 \InsetSpace ~
37423 \InsetSpace ~
37424 \InsetSpace ~
37425 \InsetSpace ~
37426 \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 \InsetSpace ~
37442 \InsetSpace ~
37443 \InsetSpace ~
37444  75 ;\InsetSpace ~
37445  hob.c 11 
37446 \newline
37447 0022 E5*01\InsetSpace ~
37448 \InsetSpace ~
37449 \InsetSpace ~
37450 \InsetSpace ~
37451 \InsetSpace ~
37452 \InsetSpace ~
37453 \InsetSpace ~
37454 \InsetSpace ~
37455 \InsetSpace ~
37456 \InsetSpace ~
37457 \InsetSpace ~
37458 \InsetSpace ~
37459 \InsetSpace ~
37460 \InsetSpace ~
37461 \InsetSpace ~
37462  76\InsetSpace ~
37463 \InsetSpace ~
37464 \InsetSpace ~
37465 \InsetSpace ~
37466 \InsetSpace ~
37467 \InsetSpace ~
37468 \InsetSpace ~
37469 \InsetSpace ~
37470  mov\InsetSpace ~
37471 \InsetSpace ~
37472  a,(_gint + 1) 
37473 \newline
37474 0024 13\InsetSpace ~
37475 \InsetSpace ~
37476 \InsetSpace ~
37477 \InsetSpace ~
37478 \InsetSpace ~
37479 \InsetSpace ~
37480 \InsetSpace ~
37481 \InsetSpace ~
37482 \InsetSpace ~
37483 \InsetSpace ~
37484 \InsetSpace ~
37485 \InsetSpace ~
37486 \InsetSpace ~
37487 \InsetSpace ~
37488 \InsetSpace ~
37489 \InsetSpace ~
37490 \InsetSpace ~
37491 \InsetSpace ~
37492  77\InsetSpace ~
37493 \InsetSpace ~
37494 \InsetSpace ~
37495 \InsetSpace ~
37496 \InsetSpace ~
37497 \InsetSpace ~
37498 \InsetSpace ~
37499 \InsetSpace ~
37500  rrc\InsetSpace ~
37501 \InsetSpace ~
37502  a 
37503 \newline
37504 0025 92*02\InsetSpace ~
37505 \InsetSpace ~
37506 \InsetSpace ~
37507 \InsetSpace ~
37508 \InsetSpace ~
37509 \InsetSpace ~
37510 \InsetSpace ~
37511 \InsetSpace ~
37512 \InsetSpace ~
37513 \InsetSpace ~
37514 \InsetSpace ~
37515 \InsetSpace ~
37516 \InsetSpace ~
37517 \InsetSpace ~
37518 \InsetSpace ~
37519
37520  78\InsetSpace ~
37521 \InsetSpace ~
37522 \InsetSpace ~
37523 \InsetSpace ~
37524 \InsetSpace ~
37525 \InsetSpace ~
37526 \InsetSpace ~
37527 \InsetSpace ~
37528  mov\InsetSpace ~
37529 \InsetSpace ~
37530  _foo_aob2_1_1,c 
37531 \newline
37532 \InsetSpace ~
37533 \InsetSpace ~
37534 \InsetSpace ~
37535 \InsetSpace ~
37536 \InsetSpace ~
37537 \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 \InsetSpace ~
37553 \InsetSpace ~
37554 \InsetSpace ~
37555 \InsetSpace ~
37556 \InsetSpace ~
37557  79 ;\InsetSpace ~
37558  hob.c 12 
37559 \newline
37560 0027 E5*01\InsetSpace ~
37561 \InsetSpace ~
37562 \InsetSpace ~
37563 \InsetSpace ~
37564 \InsetSpace ~
37565 \InsetSpace ~
37566 \InsetSpace ~
37567 \InsetSpace ~
37568 \InsetSpace ~
37569 \InsetSpace ~
37570 \InsetSpace ~
37571 \InsetSpace ~
37572 \InsetSpace ~
37573 \InsetSpace ~
37574 \InsetSpace ~
37575  80\InsetSpace ~
37576 \InsetSpace ~
37577 \InsetSpace ~
37578 \InsetSpace ~
37579 \InsetSpace ~
37580 \InsetSpace ~
37581 \InsetSpace ~
37582 \InsetSpace ~
37583  mov\InsetSpace ~
37584 \InsetSpace ~
37585  a,(_gint + 1) 
37586 \newline
37587 0029
37588  A2 E3\InsetSpace ~
37589 \InsetSpace ~
37590 \InsetSpace ~
37591 \InsetSpace ~
37592 \InsetSpace ~
37593 \InsetSpace ~
37594 \InsetSpace ~
37595 \InsetSpace ~
37596 \InsetSpace ~
37597 \InsetSpace ~
37598 \InsetSpace ~
37599 \InsetSpace ~
37600 \InsetSpace ~
37601 \InsetSpace ~
37602 \InsetSpace ~
37603  81\InsetSpace ~
37604 \InsetSpace ~
37605 \InsetSpace ~
37606 \InsetSpace ~
37607 \InsetSpace ~
37608 \InsetSpace ~
37609 \InsetSpace ~
37610 \InsetSpace ~
37611  mov\InsetSpace ~
37612 \InsetSpace ~
37613  c,acc[3] 
37614 \newline
37615 002B 92*03\InsetSpace ~
37616 \InsetSpace ~
37617 \InsetSpace ~
37618 \InsetSpace ~
37619 \InsetSpace ~
37620 \InsetSpace ~
37621 \InsetSpace ~
37622 \InsetSpace ~
37623 \InsetSpace ~
37624 \InsetSpace ~
37625 \InsetSpace ~
37626 \InsetSpace ~
37627 \InsetSpace ~
37628 \InsetSpace ~
37629 \InsetSpace ~
37630  82\InsetSpace ~
37631 \InsetSpace ~
37632 \InsetSpace ~
37633 \InsetSpace ~
37634 \InsetSpace ~
37635 \InsetSpace ~
37636 \InsetSpace ~
37637 \InsetSpace ~
37638  mov\InsetSpace ~
37639 \InsetSpace ~
37640  _foo_aob3_1_1,c 
37641 \end_layout
37642
37643 \begin_layout Standard
37644 Other variations of these cases however will 
37645 \emph on
37646 not
37647 \emph default
37648  be recognized.
37649  They are standard C expressions, so I heartily recommend these be the only
37650  way to get the highest order bit, (it is portable).
37651  Of course it will be recognized even if it is embedded in other expressions,
37652  e.g.:
37653 \end_layout
37654
37655 \begin_layout Verse
37656
37657 \family typewriter
37658 xyz = gint + ((gint >> 15) & 1);
37659 \end_layout
37660
37661 \begin_layout Standard
37662 will still be recognized.
37663 \end_layout
37664
37665 \begin_layout Subsection
37666 Higher Order Byte
37667 \begin_inset LatexCommand index
37668 name "Higher Order Byte"
37669
37670 \end_inset
37671
37672  / Higher Order Word
37673 \begin_inset LatexCommand index
37674 name "Higher Order Word"
37675
37676 \end_inset
37677
37678
37679 \end_layout
37680
37681 \begin_layout Standard
37682 It is also frequently required to obtain a higher order byte or word of
37683  a larger integral type (long, int or short types).
37684  SDCC recognizes the following expressions to yield the higher order byte
37685  or word and generates optimized code for it, e.g.:
37686 \end_layout
37687
37688 \begin_layout Verse
37689
37690 \family typewriter
37691 unsigned int gint; 
37692 \newline
37693 unsigned long int glong; 
37694 \newline
37695
37696 \newline
37697 foo () { 
37698 \newline
37699 \InsetSpace ~
37700 \InsetSpace ~
37701 unsigned char hob1,
37702  hob2; 
37703 \newline
37704 \InsetSpace ~
37705 \InsetSpace ~
37706 unsigned int how1, how2; 
37707 \newline
37708 \InsetSpace ~
37709 \InsetSpace ~
37710 ...
37711  
37712 \newline
37713 \InsetSpace ~
37714 \InsetSpace ~
37715 hob1 = (gint >> 8) & 0xFF; 
37716 \newline
37717 \InsetSpace ~
37718 \InsetSpace ~
37719 hob2 = glong >> 24; 
37720 \newline
37721 \InsetSpace ~
37722 \InsetSpace ~
37723 how1 = (glong >> 16) & 0xFFFF;
37724  
37725 \newline
37726 \InsetSpace ~
37727 \InsetSpace ~
37728 how2 = glong >> 8; 
37729 \newline
37730 \InsetSpace ~
37731 \InsetSpace ~
37732 ..
37733  
37734 \newline
37735 }
37736 \end_layout
37737
37738 \begin_layout Standard
37739 will generate the following code:
37740 \end_layout
37741
37742 \begin_layout Verse
37743
37744 \family typewriter
37745 \InsetSpace ~
37746 \InsetSpace ~
37747 \InsetSpace ~
37748 \InsetSpace ~
37749 \InsetSpace ~
37750 \InsetSpace ~
37751 \InsetSpace ~
37752 \InsetSpace ~
37753 \InsetSpace ~
37754 \InsetSpace ~
37755 \InsetSpace ~
37756 \InsetSpace ~
37757 \InsetSpace ~
37758 \InsetSpace ~
37759 \InsetSpace ~
37760 \InsetSpace ~
37761 \InsetSpace ~
37762 \InsetSpace ~
37763 \InsetSpace ~
37764 \InsetSpace ~
37765 \InsetSpace ~
37766 \InsetSpace ~
37767 \InsetSpace ~
37768 \InsetSpace ~
37769 \InsetSpace ~
37770  91 ;\InsetSpace ~
37771  hob.c 15 
37772 \newline
37773 0037 85*01*06\InsetSpace ~
37774 \InsetSpace ~
37775 \InsetSpace ~
37776 \InsetSpace ~
37777 \InsetSpace ~
37778 \InsetSpace ~
37779 \InsetSpace ~
37780 \InsetSpace ~
37781 \InsetSpace ~
37782 \InsetSpace ~
37783 \InsetSpace ~
37784 \InsetSpace ~
37785  92\InsetSpace ~
37786 \InsetSpace ~
37787 \InsetSpace ~
37788 \InsetSpace ~
37789 \InsetSpace ~
37790 \InsetSpace ~
37791 \InsetSpace ~
37792 \InsetSpace ~
37793  mov\InsetSpace ~
37794 \InsetSpace ~
37795  _foo_hob1_1_1,(_gint + 1) 
37796 \newline
37797 \InsetSpace ~
37798 \InsetSpace ~
37799 \InsetSpace ~
37800 \InsetSpace ~
37801 \InsetSpace ~
37802 \InsetSpace ~
37803 \InsetSpace ~
37804 \InsetSpace ~
37805 \InsetSpace ~
37806 \InsetSpace ~
37807 \InsetSpace ~
37808 \InsetSpace ~
37809 \InsetSpace ~
37810 \InsetSpace ~
37811 \InsetSpace ~
37812 \InsetSpace ~
37813 \InsetSpace ~
37814 \InsetSpace ~
37815 \InsetSpace ~
37816 \InsetSpace ~
37817 \InsetSpace ~
37818 \InsetSpace ~
37819 \InsetSpace ~
37820 \InsetSpace ~
37821 \InsetSpace ~
37822  93 ;\InsetSpace ~
37823  hob.c
37824  16 
37825 \newline
37826 003A 85*05*07\InsetSpace ~
37827 \InsetSpace ~
37828 \InsetSpace ~
37829 \InsetSpace ~
37830 \InsetSpace ~
37831 \InsetSpace ~
37832 \InsetSpace ~
37833 \InsetSpace ~
37834 \InsetSpace ~
37835 \InsetSpace ~
37836 \InsetSpace ~
37837 \InsetSpace ~
37838  94\InsetSpace ~
37839 \InsetSpace ~
37840 \InsetSpace ~
37841 \InsetSpace ~
37842 \InsetSpace ~
37843 \InsetSpace ~
37844 \InsetSpace ~
37845 \InsetSpace ~
37846  mov\InsetSpace ~
37847 \InsetSpace ~
37848  _foo_hob2_1_1,(_glong + 3) 
37849 \newline
37850 \InsetSpace ~
37851 \InsetSpace ~
37852 \InsetSpace ~
37853 \InsetSpace ~
37854 \InsetSpace ~
37855 \InsetSpace ~
37856 \InsetSpace ~
37857 \InsetSpace ~
37858 \InsetSpace ~
37859 \InsetSpace ~
37860 \InsetSpace ~
37861 \InsetSpace ~
37862 \InsetSpace ~
37863 \InsetSpace ~
37864 \InsetSpace ~
37865 \InsetSpace ~
37866 \InsetSpace ~
37867 \InsetSpace ~
37868 \InsetSpace ~
37869 \InsetSpace ~
37870 \InsetSpace ~
37871 \InsetSpace ~
37872 \InsetSpace ~
37873 \InsetSpace ~
37874 \InsetSpace ~
37875  95 ;\InsetSpace ~
37876  hob.c 17 
37877 \newline
37878 003D 85*04*08\InsetSpace ~
37879 \InsetSpace ~
37880 \InsetSpace ~
37881 \InsetSpace ~
37882 \InsetSpace ~
37883 \InsetSpace ~
37884 \InsetSpace ~
37885 \InsetSpace ~
37886 \InsetSpace ~
37887 \InsetSpace ~
37888 \InsetSpace ~
37889 \InsetSpace ~
37890
37891  96\InsetSpace ~
37892 \InsetSpace ~
37893 \InsetSpace ~
37894 \InsetSpace ~
37895 \InsetSpace ~
37896 \InsetSpace ~
37897 \InsetSpace ~
37898 \InsetSpace ~
37899  mov\InsetSpace ~
37900 \InsetSpace ~
37901  _foo_how1_1_1,(_glong + 2) 
37902 \newline
37903 0040 85*05*09\InsetSpace ~
37904 \InsetSpace ~
37905 \InsetSpace ~
37906 \InsetSpace ~
37907 \InsetSpace ~
37908 \InsetSpace ~
37909 \InsetSpace ~
37910 \InsetSpace ~
37911 \InsetSpace ~
37912 \InsetSpace ~
37913 \InsetSpace ~
37914 \InsetSpace ~
37915  97\InsetSpace ~
37916 \InsetSpace ~
37917 \InsetSpace ~
37918 \InsetSpace ~
37919 \InsetSpace ~
37920 \InsetSpace ~
37921 \InsetSpace ~
37922 \InsetSpace ~
37923  mov\InsetSpace ~
37924 \InsetSpace ~
37925  (_foo_how1_1_1 +
37926  1),(_glong + 3) 
37927 \newline
37928 0043 85*03*0A\InsetSpace ~
37929 \InsetSpace ~
37930 \InsetSpace ~
37931 \InsetSpace ~
37932 \InsetSpace ~
37933 \InsetSpace ~
37934 \InsetSpace ~
37935 \InsetSpace ~
37936 \InsetSpace ~
37937 \InsetSpace ~
37938 \InsetSpace ~
37939 \InsetSpace ~
37940  98\InsetSpace ~
37941 \InsetSpace ~
37942 \InsetSpace ~
37943 \InsetSpace ~
37944 \InsetSpace ~
37945 \InsetSpace ~
37946 \InsetSpace ~
37947 \InsetSpace ~
37948  mov\InsetSpace ~
37949 \InsetSpace ~
37950  _foo_how2_1_1,(_glong + 1) 
37951 \newline
37952 0046 85*04*0B\InsetSpace ~
37953 \InsetSpace ~
37954 \InsetSpace ~
37955 \InsetSpace ~
37956 \InsetSpace ~
37957 \InsetSpace ~
37958 \InsetSpace ~
37959 \InsetSpace ~
37960 \InsetSpace ~
37961 \InsetSpace ~
37962 \InsetSpace ~
37963 \InsetSpace ~
37964
37965  99\InsetSpace ~
37966 \InsetSpace ~
37967 \InsetSpace ~
37968 \InsetSpace ~
37969 \InsetSpace ~
37970 \InsetSpace ~
37971 \InsetSpace ~
37972 \InsetSpace ~
37973  mov\InsetSpace ~
37974 \InsetSpace ~
37975  (_foo_how2_1_1 + 1),(_glong + 2) 
37976 \end_layout
37977
37978 \begin_layout Standard
37979 Again, variations of these cases may 
37980 \emph on
37981 not
37982 \emph default
37983  be recognized.
37984  They are standard C expressions, so I heartily recommend these be the only
37985  way to get the higher order byte/word, (it is portable).
37986  Of course it will be recognized even if it is embedded in other expressions,
37987  e.g.:
37988 \end_layout
37989
37990 \begin_layout Verse
37991
37992 \family typewriter
37993 xyz = gint + ((gint >> 8) & 0xFF);
37994 \end_layout
37995
37996 \begin_layout Standard
37997 will still be recognized.
37998 \end_layout
37999
38000 \begin_layout Subsection
38001 Peephole Optimizer
38002 \begin_inset LatexCommand label
38003 name "sub:Peephole-Optimizer"
38004
38005 \end_inset
38006
38007
38008 \begin_inset LatexCommand index
38009 name "Peephole optimizer"
38010
38011 \end_inset
38012
38013
38014 \end_layout
38015
38016 \begin_layout Standard
38017 The compiler uses a rule based, pattern matching and re-writing mechanism
38018  for peep-hole optimization.
38019  It is inspired by 
38020 \emph on
38021 copt
38022 \emph default
38023  a peep-hole optimizer by Christopher W.
38024  Fraser (cwfraser\InsetSpace ~
38025 @\InsetSpace ~
38026 microsoft.com).
38027  A default set of rules are compiled into the compiler, additional rules
38028  may be added with the 
38029 \emph on
38030 -
38031 \begin_inset ERT
38032 status collapsed
38033
38034 \begin_layout Standard
38035
38036
38037 \backslash
38038 /
38039 \end_layout
38040
38041 \end_inset
38042
38043 -peep-file
38044 \begin_inset LatexCommand index
38045 name "-\\/-peep-file"
38046
38047 \end_inset
38048
38049  <filename>
38050 \emph default
38051  option.
38052  The rule language is best illustrated with examples.
38053 \end_layout
38054
38055 \begin_layout Verse
38056
38057 \family typewriter
38058 replace { 
38059 \newline
38060 \InsetSpace ~
38061 \InsetSpace ~
38062 mov %1,a 
38063 \newline
38064 \InsetSpace ~
38065 \InsetSpace ~
38066 mov a,%1
38067 \newline
38068 } by {
38069 \newline
38070 \InsetSpace ~
38071 \InsetSpace ~
38072 mov %1,a
38073 \newline
38074 }
38075 \end_layout
38076
38077 \begin_layout Standard
38078 The above rule will change the following assembly
38079 \begin_inset LatexCommand index
38080 name "Assembler routines"
38081
38082 \end_inset
38083
38084  sequence:
38085 \end_layout
38086
38087 \begin_layout Verse
38088
38089 \family typewriter
38090 mov r1,a 
38091 \newline
38092 mov a,r1
38093 \end_layout
38094
38095 \begin_layout Standard
38096 to
38097 \end_layout
38098
38099 \begin_layout Verse
38100
38101 \family typewriter
38102 mov r1,a
38103 \end_layout
38104
38105 \begin_layout Standard
38106 Note: All occurrences of a 
38107 \emph on
38108 %n
38109 \emph default
38110  (pattern variable) must denote the same string.
38111  With the above rule, the assembly sequence:
38112 \end_layout
38113
38114 \begin_layout Verse
38115
38116 \family typewriter
38117 mov r1,a 
38118 \newline
38119 mov a,r2
38120 \end_layout
38121
38122 \begin_layout Standard
38123 will remain unmodified.
38124 \newline
38125
38126 \newline
38127 Other special case optimizations may be added by the
38128  user (via 
38129 \emph on
38130 -
38131 \begin_inset ERT
38132 status collapsed
38133
38134 \begin_layout Standard
38135
38136
38137 \backslash
38138 /
38139 \end_layout
38140
38141 \end_inset
38142
38143 -peep-file option
38144 \emph default
38145 ).
38146  E.g.
38147  some variants of the 8051 MCU
38148 \begin_inset LatexCommand index
38149 name "MCS51 variants"
38150
38151 \end_inset
38152
38153  allow only 
38154 \family typewriter
38155 ajmp
38156 \family default
38157  and 
38158 \family typewriter
38159 acall
38160 \family default
38161 .
38162  The following two rules will change all 
38163 \family typewriter
38164 ljmp
38165 \family default
38166  and 
38167 \family typewriter
38168 lcall
38169 \family default
38170  to 
38171 \family typewriter
38172 ajmp
38173 \family default
38174  and 
38175 \family typewriter
38176 acall
38177 \end_layout
38178
38179 \begin_layout Verse
38180
38181 \family typewriter
38182 replace { lcall %1 } by { acall %1 } 
38183 \newline
38184 replace { ljmp %1 } by { ajmp %1 }
38185 \end_layout
38186
38187 \begin_layout Standard
38188 (NOTE: from version 2.7.3 on, you can use option -
38189 \emph on
38190
38191 \begin_inset ERT
38192 status collapsed
38193
38194 \begin_layout Standard
38195
38196
38197 \backslash
38198 /
38199 \end_layout
38200
38201 \end_inset
38202
38203
38204 \emph default
38205 -acall-ajmp
38206 \begin_inset LatexCommand index
38207 name "-\\/-acall-ajmp"
38208
38209 \end_inset
38210
38211 , which also takes care of aligning the interrupt vectors properly.)
38212 \newline
38213
38214 \end_layout
38215
38216 \begin_layout Standard
38217 The 
38218 \emph on
38219 inline-assembler code
38220 \emph default
38221  is also passed through the peep hole optimizer, thus the peephole optimizer
38222  can also be used as an assembly level macro expander.
38223  The rules themselves are MCU dependent whereas the rule language infra-structur
38224 e is MCU independent.
38225  Peephole optimization rules for other MCU can be easily programmed using
38226  the rule language.
38227 \newline
38228
38229 \newline
38230 The syntax for a rule is as follows:
38231 \end_layout
38232
38233 \begin_layout Verse
38234
38235 \family typewriter
38236 rule := replace [ restart ] '{' <assembly sequence> '
38237 \backslash
38238 n' 
38239 \newline
38240 \InsetSpace ~
38241  \InsetSpace ~
38242  \InsetSpace ~
38243  \InsetSpace ~
38244  \InsetSpace ~
38245  \InsetSpace ~
38246  \InsetSpace ~
38247  \InsetSpace ~
38248  \InsetSpace ~
38249  \InsetSpace ~
38250  \InsetSpace ~
38251  \InsetSpace ~
38252  \InsetSpace ~
38253  \InsetSpace ~
38254  '}' by '{' '
38255 \backslash
38256 n' 
38257 \newline
38258 \InsetSpace ~
38259  \InsetSpace ~
38260  \InsetSpace ~
38261  \InsetSpace ~
38262  \InsetSpace ~
38263  \InsetSpace ~
38264  \InsetSpace ~
38265  \InsetSpace ~
38266  \InsetSpace ~
38267  \InsetSpace ~
38268  \InsetSpace ~
38269  \InsetSpace ~
38270  \InsetSpace ~
38271  \InsetSpace ~
38272  \InsetSpace ~
38273  \InsetSpace ~
38274  <assembly sequence> '
38275 \backslash
38276 n' 
38277 \newline
38278 \InsetSpace ~
38279  \InsetSpace ~
38280  \InsetSpace ~
38281  \InsetSpace ~
38282  \InsetSpace ~
38283  \InsetSpace ~
38284  \InsetSpace ~
38285  \InsetSpace ~
38286  \InsetSpace ~
38287  \InsetSpace ~
38288  \InsetSpace ~
38289  \InsetSpace ~
38290  \InsetSpace ~
38291  \InsetSpace ~
38292  '}' [if <functionName> ] '
38293 \backslash
38294 n' 
38295 \end_layout
38296
38297 \begin_layout Standard
38298 <assembly sequence> := assembly instruction (each instruction including
38299  labels must be on a separate line).
38300 \newline
38301
38302 \newline
38303 The optimizer will apply to the rules
38304  one by one from the top in the sequence of their appearance, it will terminate
38305  when all rules are exhausted.
38306  If the 'restart' option is specified, then the optimizer will start matching
38307  the rules again from the top, this option for a rule is expensive (performance)
38308 , it is intended to be used in situations where a transformation will trigger
38309  the same rule again.
38310  An example of this (not a good one, it has side effects) is the following
38311  rule:
38312 \end_layout
38313
38314 \begin_layout Verse
38315
38316 \family typewriter
38317 replace restart { 
38318 \newline
38319 \InsetSpace ~
38320 \InsetSpace ~
38321 pop %1 
38322 \newline
38323 \InsetSpace ~
38324 \InsetSpace ~
38325 push %1 } by { 
38326 \newline
38327 \InsetSpace ~
38328 \InsetSpace ~
38329 ; nop 
38330 \newline
38331 }
38332 \end_layout
38333
38334 \begin_layout Standard
38335 Note that the replace pattern cannot be a blank, but can be a comment line.
38336  Without the 'restart' option only the innermost 'pop' 'push' pair would
38337  be eliminated, i.e.:
38338 \end_layout
38339
38340 \begin_layout Verse
38341
38342 \family typewriter
38343 pop ar1 
38344 \newline
38345 pop ar2 
38346 \newline
38347 push ar2 
38348 \newline
38349 push ar1
38350 \end_layout
38351
38352 \begin_layout Standard
38353 would result in:
38354 \end_layout
38355
38356 \begin_layout Verse
38357
38358 \family typewriter
38359 pop ar1 
38360 \newline
38361 ; nop 
38362 \newline
38363 push ar1
38364 \end_layout
38365
38366 \begin_layout Standard
38367
38368 \emph on
38369 with
38370 \emph default
38371  the restart option the rule will be applied again to the resulting code
38372  and then all the pop-push pairs will be eliminated to yield:
38373 \end_layout
38374
38375 \begin_layout Verse
38376
38377 \family typewriter
38378 ; nop 
38379 \newline
38380 ; nop
38381 \end_layout
38382
38383 \begin_layout Standard
38384 A conditional function can be attached to a rule.
38385  Attaching rules are somewhat more involved, let me illustrate this with
38386  an example.
38387 \end_layout
38388
38389 \begin_layout Verse
38390
38391 \family typewriter
38392 replace { 
38393 \newline
38394 \InsetSpace ~
38395  \InsetSpace ~
38396  \InsetSpace ~
38397 ljmp %5 
38398 \newline
38399 %2:
38400 \newline
38401 } by { 
38402 \newline
38403 \InsetSpace ~
38404  \InsetSpace ~
38405  \InsetSpace ~
38406 sjmp %5 
38407 \newline
38408 %2:
38409 \newline
38410 } if labelInRange
38411 \end_layout
38412
38413 \begin_layout Standard
38414 The optimizer does a look-up of a function name table defined in function
38415  
38416 \emph on
38417 callFuncByName
38418 \emph default
38419  in the source file SDCCpeeph.c, with the name 
38420 \emph on
38421 labelInRange
38422 \emph default
38423 .
38424  If it finds a corresponding entry the function is called.
38425  Note there can be no parameters specified for these functions, in this
38426  case the use of 
38427 \emph on
38428 %5
38429 \emph default
38430  is crucial, since the function 
38431 \emph on
38432 labelInRange
38433 \emph default
38434  expects to find the label in that particular variable (the hash table containin
38435 g the variable bindings is passed as a parameter).
38436  If you want to code more such functions, take a close look at the function
38437  labelInRange and the calling mechanism in source file SDCCpeeph.c.
38438  Currently implemented are 
38439 \emph on
38440 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
38441  24bitMode, portIsDS390, 24bitModeAndPortDS390
38442 \emph default
38443  and 
38444 \emph on
38445 notVolatile
38446 \emph default
38447 .
38448 \end_layout
38449
38450 \begin_layout Standard
38451 I know this whole thing is a little kludgey, but maybe some day we will
38452  have some better means.
38453  If you are looking at this file, you will see the default rules that are
38454  compiled into the compiler, you can add your own rules in the default set
38455  there if you get tired of specifying the -
38456 \begin_inset ERT
38457 status collapsed
38458
38459 \begin_layout Standard
38460
38461
38462 \backslash
38463 /
38464 \end_layout
38465
38466 \end_inset
38467
38468 -peep-file option.
38469 \end_layout
38470
38471 \begin_layout Section
38472 ANSI-Compliance
38473 \begin_inset LatexCommand index
38474 name "ANSI-compliance"
38475
38476 \end_inset
38477
38478
38479 \begin_inset LatexCommand label
38480 name "sub:ANSI-Compliance"
38481
38482 \end_inset
38483
38484
38485 \end_layout
38486
38487 \begin_layout Standard
38488 The latest publicly available version of the standard 
38489 \emph on
38490 ISO/IEC 9899 - Programming languages - C
38491 \emph default
38492  should be available at: 
38493 \begin_inset LatexCommand url
38494 target "http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899"
38495
38496 \end_inset
38497
38498 .
38499 \newline
38500
38501 \end_layout
38502
38503 \begin_layout Standard
38504 Deviations from the compliance:
38505 \end_layout
38506
38507 \begin_layout Itemize
38508 functions are not reentrant
38509 \begin_inset LatexCommand index
38510 name "reentrant"
38511
38512 \end_inset
38513
38514  unless explicitly declared as such or the 
38515 \series bold
38516 -
38517 \begin_inset ERT
38518 status collapsed
38519
38520 \begin_layout Standard
38521
38522
38523 \backslash
38524 /
38525 \end_layout
38526
38527 \end_inset
38528
38529 -stack-auto
38530 \begin_inset LatexCommand index
38531 name "-\\/-stack-auto"
38532
38533 \end_inset
38534
38535
38536 \series default
38537  command line option is specified.
38538 \end_layout
38539
38540 \begin_layout Itemize
38541 structures
38542 \begin_inset LatexCommand index
38543 name "struct"
38544
38545 \end_inset
38546
38547  and unions
38548 \begin_inset LatexCommand index
38549 name "union"
38550
38551 \end_inset
38552
38553  cannot be assigned values directly, cannot be passed as function parameters
38554  or assigned to each other and cannot be a return value
38555 \begin_inset LatexCommand index
38556 name "return value"
38557
38558 \end_inset
38559
38560  from a function, e.g.:
38561 \end_layout
38562
38563 \begin_deeper
38564 \begin_layout Verse
38565
38566 \family typewriter
38567 struct s { ...
38568  }; 
38569 \newline
38570 struct s s1, s2; 
38571 \newline
38572 foo() 
38573 \newline
38574
38575 \newline
38576 \InsetSpace ~
38577 \InsetSpace ~
38578 \InsetSpace ~
38579 \InsetSpace ~
38580 ...
38581  
38582 \newline
38583 \InsetSpace ~
38584 \InsetSpace ~
38585 \InsetSpace ~
38586 \InsetSpace ~
38587 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
38588 \newline
38589 \InsetSpace ~
38590 \InsetSpace ~
38591 \InsetSpace ~
38592 \InsetSpace ~
38593 ...
38594  
38595 \newline
38596 }
38597 \newline
38598
38599 \series bold
38600 struct
38601 \family default
38602 \series default
38603  
38604 \family typewriter
38605 s foo1 (
38606 \series bold
38607 struct
38608 \family default
38609 \series default
38610  
38611 \family typewriter
38612 s parms) /* invalid in SDCC although allowed in ANSI */
38613 \newline
38614
38615 \newline
38616 \InsetSpace ~
38617 \InsetSpace ~
38618 \InsetSpace ~
38619 \InsetSpace ~
38620 struct s rets;
38621  
38622 \newline
38623 \InsetSpace ~
38624 \InsetSpace ~
38625 \InsetSpace ~
38626 \InsetSpace ~
38627 ...
38628  
38629 \newline
38630 \InsetSpace ~
38631 \InsetSpace ~
38632 \InsetSpace ~
38633 \InsetSpace ~
38634 return rets; /* is invalid in SDCC although allowed in ANSI */ 
38635 \newline
38636 }
38637 \end_layout
38638
38639 \end_deeper
38640 \begin_layout Itemize
38641 initialization of structure arrays must be fully braced.
38642 \end_layout
38643
38644 \begin_deeper
38645 \begin_layout Verse
38646
38647 \family typewriter
38648 struct s { char x } a[] = {1, 2};\InsetSpace ~
38649 \InsetSpace ~
38650 \InsetSpace ~
38651 \InsetSpace ~
38652 \InsetSpace ~
38653 /* invalid in SDCC */
38654 \newline
38655 struct s { char x
38656  } a[] = {{1}, {2}}; /* OK */
38657 \end_layout
38658
38659 \end_deeper
38660 \begin_layout Itemize
38661 'long long
38662 \begin_inset LatexCommand index
38663 name "long long (not supported)"
38664
38665 \end_inset
38666
38667 ' (64 bit integers
38668 \begin_inset LatexCommand index
38669 name "int (64 bit) (not supported)"
38670
38671 \end_inset
38672
38673 ) not supported.
38674 \end_layout
38675
38676 \begin_layout Itemize
38677 'double
38678 \begin_inset LatexCommand index
38679 name "double (not supported)"
38680
38681 \end_inset
38682
38683 ' precision floating point 
38684 \begin_inset LatexCommand index
38685 name "Floating point support"
38686
38687 \end_inset
38688
38689 not supported.
38690 \end_layout
38691
38692 \begin_layout Itemize
38693 Old K&R style
38694 \begin_inset LatexCommand index
38695 name "K\\&R style"
38696
38697 \end_inset
38698
38699  function declarations are NOT allowed.
38700 \end_layout
38701
38702 \begin_deeper
38703 \begin_layout Verse
38704
38705 \family typewriter
38706 foo(i,j) /* this old style of function declarations */ 
38707 \newline
38708 int i,j; /* is valid
38709  in ANSI but not valid in SDCC */ 
38710 \newline
38711
38712 \newline
38713 \InsetSpace ~
38714 \InsetSpace ~
38715 \InsetSpace ~
38716 \InsetSpace ~
38717 ...
38718  
38719 \newline
38720 }
38721 \end_layout
38722
38723 \end_deeper
38724 \begin_layout Itemize
38725 Most enhancements in C99 are not supported, e.g.:
38726 \end_layout
38727
38728 \begin_deeper
38729 \begin_layout Verse
38730
38731 \family typewriter
38732 for (
38733 \series bold
38734 int
38735 \family default
38736 \series default
38737  
38738 \family typewriter
38739 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
38740 \end_layout
38741
38742 \end_deeper
38743 \begin_layout Itemize
38744 But some have been added recently in SDCC 2.7.0.
38745  They must be considered alpha quality however.
38746 \end_layout
38747
38748 \begin_deeper
38749 \begin_layout Verse
38750
38751 \family typewriter
38752 \series bold
38753 inline
38754 \begin_inset LatexCommand index
38755 name "inline (not supported)"
38756
38757 \end_inset
38758
38759
38760 \family default
38761 \series default
38762  
38763 \family typewriter
38764 int increment (int a) { return a+1; } /* inlines the increment without function
38765  call overhead */
38766 \newline
38767 int *
38768 \family default
38769  
38770 \family typewriter
38771 \series bold
38772 restrict
38773 \begin_inset LatexCommand index
38774 name "inline (not supported)"
38775
38776 \end_inset
38777
38778
38779 \family default
38780 \series default
38781  
38782 \family typewriter
38783 p; /* accepted but ignored */
38784 \end_layout
38785
38786 \end_deeper
38787 \begin_layout Itemize
38788 Certain words that are valid identifiers in the standard may be reserved
38789  words in SDCC unless the 
38790 \series bold
38791 -
38792 \begin_inset ERT
38793 status collapsed
38794
38795 \begin_layout Standard
38796
38797
38798 \backslash
38799 /
38800 \end_layout
38801
38802 \end_inset
38803
38804 -std-c89
38805 \begin_inset LatexCommand index
38806 name "-\\/-std-c89"
38807
38808 \end_inset
38809
38810
38811 \series default
38812  or 
38813 \series bold
38814 -
38815 \begin_inset ERT
38816 status collapsed
38817
38818 \begin_layout Standard
38819
38820
38821 \backslash
38822 /
38823 \end_layout
38824
38825 \end_inset
38826
38827 -std-c99
38828 \begin_inset LatexCommand index
38829 name "-\\/-std-c99"
38830
38831 \end_inset
38832
38833
38834 \series default
38835  command line options are used.
38836  These may include (depending on the selected processor): 'at', 'banked',
38837  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
38838 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
38839  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
38840  '_naked'.
38841  Compliant equivalents of these keywords are always available in a form
38842  that begin with two underscores
38843 \begin_inset LatexCommand index
38844 name "\\_\\_ (prefix for extended keywords)"
38845
38846 \end_inset
38847
38848 , f.e.
38849  '__data' instead of 'data'.
38850 \end_layout
38851
38852 \begin_layout Itemize
38853 Integer promotion of variable arguments is not performed if the argument
38854  is explicitly taypecasted unless the 
38855 \series bold
38856 -
38857 \begin_inset ERT
38858 status collapsed
38859
38860 \begin_layout Standard
38861
38862
38863 \backslash
38864 /
38865 \end_layout
38866
38867 \end_inset
38868
38869 -std-c89
38870 \begin_inset LatexCommand index
38871 name "-\\/-std-c89"
38872
38873 \end_inset
38874
38875
38876 \series default
38877  or 
38878 \series bold
38879 -
38880 \begin_inset ERT
38881 status collapsed
38882
38883 \begin_layout Standard
38884
38885
38886 \backslash
38887 /
38888 \end_layout
38889
38890 \end_inset
38891
38892 -std-c99
38893 \begin_inset LatexCommand index
38894 name "-\\/-std-c99"
38895
38896 \end_inset
38897
38898
38899 \series default
38900  command line options are used.
38901 \end_layout
38902
38903 \begin_deeper
38904 \begin_layout Verse
38905
38906 \family typewriter
38907 void vararg_func (char *str, ...) { str; }
38908 \newline
38909
38910 \newline
38911 void main (void)
38912 \newline
38913 {
38914 \newline
38915 \InsetSpace ~
38916 \InsetSpace ~
38917 char c = 10;
38918 \newline
38919
38920 \newline
38921 \InsetSpace ~
38922 \InsetSpace ~
38923 /* argument
38924  u is promoted to int before
38925 \newline
38926 \InsetSpace ~
38927 \InsetSpace ~
38928 \InsetSpace ~
38929 * passing to function */
38930 \newline
38931 \InsetSpace ~
38932 \InsetSpace ~
38933 vararg_func ("%c", c);
38934 \newline
38935
38936 \newline
38937 \InsetSpace ~
38938 \InsetSpace ~
38939 /*
38940  argument u is not promoted to int,
38941 \newline
38942 \InsetSpace ~
38943 \InsetSpace ~
38944 \InsetSpace ~
38945 * it is passed as char to function
38946 \newline
38947 \InsetSpace ~
38948 \InsetSpace ~
38949 \InsetSpace ~
38950 * if
38951  --std-cXX is not defined;
38952 \newline
38953 \InsetSpace ~
38954 \InsetSpace ~
38955 \InsetSpace ~
38956 * is promoted to int before passing
38957 \newline
38958 \InsetSpace ~
38959 \InsetSpace ~
38960 \InsetSpace ~
38961 * to function
38962  if --std-cXX is defined */
38963 \newline
38964 \InsetSpace ~
38965 \InsetSpace ~
38966 vararg_func ("%bc", (char)u);
38967 \newline
38968 }
38969 \end_layout
38970
38971 \end_deeper
38972 \begin_layout Section
38973 Cyclomatic Complexity
38974 \begin_inset LatexCommand index
38975 name "Cyclomatic complexity"
38976
38977 \end_inset
38978
38979
38980 \end_layout
38981
38982 \begin_layout Standard
38983 Cyclomatic complexity of a function is defined as the number of independent
38984  paths the program can take during execution of the function.
38985  This is an important number since it defines the number test cases you
38986  have to generate to validate the function.
38987  The accepted industry standard for complexity number is 10, if the cyclomatic
38988  complexity reported by SDCC exceeds 10 you should think about simplification
38989  of the function logic.
38990  Note that the complexity level is not related to the number of lines of
38991  code in a function.
38992  Large functions can have low complexity, and small functions can have large
38993  complexity levels.
38994  
38995 \newline
38996
38997 \newline
38998 SDCC uses the following formula to compute the complexity:
38999 \newline
39000
39001 \end_layout
39002
39003 \begin_layout Standard
39004 complexity = (number of edges in control flow graph) - (number of nodes
39005  in control flow graph) + 2;
39006 \newline
39007
39008 \newline
39009 Having said that the industry standard is 10,
39010  you should be aware that in some cases it be may unavoidable to have a
39011  complexity level of less than 10.
39012  For example if you have switch statement with more than 10 case labels,
39013  each case label adds one to the complexity level.
39014  The complexity level is by no means an absolute measure of the algorithmic
39015  complexity of the function, it does however provide a good starting point
39016  for which functions you might look at for further optimization.
39017 \end_layout
39018
39019 \begin_layout Section
39020 Retargetting for other Processors
39021 \end_layout
39022
39023 \begin_layout Standard
39024 The issues for retargetting the compiler are far too numerous to be covered
39025  by this document.
39026  What follows is a brief description of each of the seven phases of the
39027  compiler and its MCU dependency.
39028 \end_layout
39029
39030 \begin_layout Itemize
39031 Parsing the source and building the annotated parse tree.
39032  This phase is largely MCU independent (except for the language extensions).
39033  Syntax & semantic checks are also done in this phase, along with some initial
39034  optimizations like back patching labels and the pattern matching optimizations
39035  like bit-rotation etc.
39036 \end_layout
39037
39038 \begin_layout Itemize
39039 The second phase involves generating an intermediate code which can be easy
39040  manipulated during the later phases.
39041  This phase is entirely MCU independent.
39042  The intermediate code generation assumes the target machine has unlimited
39043  number of registers, and designates them with the name iTemp.
39044  The compiler can be made to dump a human readable form of the code generated
39045  by using the -
39046 \begin_inset ERT
39047 status collapsed
39048
39049 \begin_layout Standard
39050
39051
39052 \backslash
39053 /
39054 \end_layout
39055
39056 \end_inset
39057
39058 -dumpraw option.
39059 \end_layout
39060
39061 \begin_layout Itemize
39062 This phase does the bulk of the standard optimizations and is also MCU independe
39063 nt.
39064  This phase can be broken down into several sub-phases:
39065 \newline
39066
39067 \newline
39068 Break down intermediate
39069  code (iCode) into basic blocks.
39070 \newline
39071 Do control flow & data flow analysis on the
39072  basic blocks.
39073 \newline
39074 Do local common subexpression elimination, then global subexpressio
39075 n elimination
39076 \newline
39077 Dead code elimination
39078 \newline
39079 Loop optimizations
39080 \newline
39081 If loop optimizations
39082  caused any changes then do 'global subexpression elimination' and 'dead
39083  code elimination' again.
39084 \end_layout
39085
39086 \begin_layout Itemize
39087 This phase determines the live-ranges; by live range I mean those iTemp
39088  variables defined by the compiler that still survive after all the optimization
39089 s.
39090  Live range analysis
39091 \begin_inset LatexCommand index
39092 name "Live range analysis"
39093
39094 \end_inset
39095
39096  is essential for register allocation, since these computation determines
39097  which of these iTemps will be assigned to registers, and for how long.
39098 \end_layout
39099
39100 \begin_layout Itemize
39101 Phase five is register allocation.
39102  There are two parts to this process.
39103 \newline
39104
39105 \newline
39106 The first part I call 'register packing'
39107  (for lack of a better term).
39108  In this case several MCU specific expression folding is done to reduce
39109  register pressure.
39110 \newline
39111
39112 \newline
39113 The second part is more MCU independent and deals with
39114  allocating registers to the remaining live ranges.
39115  A lot of MCU specific code does creep into this phase because of the limited
39116  number of index registers available in the 8051.
39117 \end_layout
39118
39119 \begin_layout Itemize
39120 The Code generation phase is (unhappily), entirely MCU dependent and very
39121  little (if any at all) of this code can be reused for other MCU.
39122  However the scheme for allocating a homogenized assembler operand for each
39123  iCode operand may be reused.
39124 \end_layout
39125
39126 \begin_layout Itemize
39127 As mentioned in the optimization section the peep-hole optimizer is rule
39128  based system, which can reprogrammed for other MCUs.
39129 \end_layout
39130
39131 \begin_layout Standard
39132 More information is available on SDCC Wiki
39133 \begin_inset LatexCommand index
39134 name "wiki"
39135
39136 \end_inset
39137
39138  (preliminary link 
39139 \begin_inset LatexCommand url
39140 target "http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting"
39141
39142 \end_inset
39143
39144 ) and in the thread 
39145 \begin_inset LatexCommand url
39146 target "http://sf.net/mailarchive/message.php?msg_id=13954144"
39147
39148 \end_inset
39149
39150  .
39151 \end_layout
39152
39153 \begin_layout Chapter
39154 Compiler internals
39155 \begin_inset LatexCommand index
39156 name "Compiler internals"
39157
39158 \end_inset
39159
39160
39161 \end_layout
39162
39163 \begin_layout Section
39164 The anatomy of the compiler
39165 \begin_inset LatexCommand label
39166 name "sub:The-anatomy-of"
39167
39168 \end_inset
39169
39170
39171 \end_layout
39172
39173 \begin_layout Standard
39174
39175 \shape italic
39176 This is an excerpt from an article published in Circuit Cellar Magazine
39177  in
39178 \shape default
39179  
39180 \series bold
39181 \shape italic
39182 August 2000
39183 \series default
39184 .
39185  It's a little outdated (the compiler is much more efficient now and user/develo
39186 per friendly), but pretty well exposes the guts of it all.
39187 \shape default
39188
39189 \newline
39190
39191 \newline
39192 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
39193  It is fairly easy to retarget for other 8-bit MCU.
39194  Here we take a look at some of the internals of the compiler.
39195  
39196 \end_layout
39197
39198 \begin_layout Paragraph*
39199 Parsing
39200 \begin_inset LatexCommand index
39201 name "Parsing"
39202
39203 \end_inset
39204
39205  
39206 \end_layout
39207
39208 \begin_layout Standard
39209 Parsing the input source file and creating an AST (Annotated Syntax Tree
39210 \begin_inset LatexCommand index
39211 name "Annotated syntax tree"
39212
39213 \end_inset
39214
39215 ).
39216  This phase also involves propagating types (annotating each node of the
39217  parse tree with type information) and semantic analysis.
39218  There are some MCU specific parsing rules.
39219  For example the storage classes, the extended storage classes are MCU specific
39220  while there may be a xdata storage class for 8051 there is no such storage
39221  class for z80 or Atmel AVR.
39222  SDCC allows MCU specific storage class extensions, i.e.
39223  xdata will be treated as a storage class specifier when parsing 8051 C
39224  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
39225  C code.
39226 \end_layout
39227
39228 \begin_layout Paragraph*
39229 Generating iCode
39230 \begin_inset LatexCommand index
39231 name "iCode"
39232
39233 \end_inset
39234
39235
39236 \end_layout
39237
39238 \begin_layout Standard
39239 Intermediate code generation.
39240  In this phase the AST is broken down into three-operand form (iCode).
39241  These three operand forms are represented as doubly linked lists.
39242  ICode is the term given to the intermediate form generated by the compiler.
39243  ICode example section shows some examples of iCode generated for some simple
39244  C source functions.
39245 \end_layout
39246
39247 \begin_layout Paragraph*
39248 Optimizations
39249 \begin_inset LatexCommand index
39250 name "Optimizations"
39251
39252 \end_inset
39253
39254 .
39255 \end_layout
39256
39257 \begin_layout Standard
39258 Bulk of the target independent optimizations is performed in this phase.
39259  The optimizations include constant propagation, common sub-expression eliminati
39260 on, loop invariant code movement, strength reduction of loop induction variables
39261  and dead-code elimination.
39262 \end_layout
39263
39264 \begin_layout Paragraph*
39265 Live range analysis
39266 \begin_inset LatexCommand index
39267 name "Live range analysis"
39268
39269 \end_inset
39270
39271
39272 \end_layout
39273
39274 \begin_layout Standard
39275 During intermediate code generation phase, the compiler assumes the target
39276  machine has infinite number of registers and generates a lot of temporary
39277  variables.
39278  The live range computation determines the lifetime of each of these compiler-ge
39279 nerated temporaries.
39280  A picture speaks a thousand words.
39281  ICode example sections show the live range annotations for each of the
39282  operand.
39283  It is important to note here, each iCode is assigned a number in the order
39284  of its execution in the function.
39285  The live ranges are computed in terms of these numbers.
39286  The from number is the number of the iCode which first defines the operand
39287  and the to number signifies the iCode which uses this operand last.
39288 \end_layout
39289
39290 \begin_layout Paragraph*
39291 Register Allocation
39292 \begin_inset LatexCommand index
39293 name "Register allocation"
39294
39295 \end_inset
39296
39297
39298 \end_layout
39299
39300 \begin_layout Standard
39301 The register allocation determines the type and number of registers needed
39302  by each operand.
39303  In most MCUs only a few registers can be used for indirect addressing.
39304  In case of 8051 for example the registers R0 & R1 can be used to indirectly
39305  address the internal ram and DPTR to indirectly address the external ram.
39306  The compiler will try to allocate the appropriate register to pointer variables
39307  if it can.
39308  ICode example section shows the operands annotated with the registers assigned
39309  to them.
39310  The compiler will try to keep operands in registers as much as possible;
39311  there are several schemes the compiler uses to do achieve this.
39312  When the compiler runs out of registers the compiler will check to see
39313  if there are any live operands which is not used or defined in the current
39314  basic block being processed, if there are any found then it will push that
39315  operand and use the registers in this block, the operand will then be popped
39316  at the end of the basic block.
39317  
39318 \end_layout
39319
39320 \begin_layout Standard
39321 There are other MCU specific considerations in this phase.
39322  Some MCUs have an accumulator; very short-lived operands could be assigned
39323  to the accumulator instead of a general-purpose register.
39324 \end_layout
39325
39326 \begin_layout Paragraph*
39327 Code generation
39328 \end_layout
39329
39330 \begin_layout Standard
39331 Figure II gives a table of iCode
39332 \begin_inset LatexCommand index
39333 name "iCode"
39334
39335 \end_inset
39336
39337  operations supported by the compiler.
39338  The code generation involves translating these operations into corresponding
39339  assembly code for the processor.
39340  This sounds overly simple but that is the essence of code generation.
39341  Some of the iCode operations are generated on a MCU specific manner for
39342  example, the z80 port does not use registers to pass parameters so the
39343  SEND and RECV iCode operations will not be generated, and it also does
39344  not support JUMPTABLES.
39345  
39346 \newline
39347
39348 \end_layout
39349
39350 \begin_layout Standard
39351
39352 \size footnotesize
39353 Figure II 
39354 \begin_inset Tabular
39355 <lyxtabular version="3" rows="39" columns="4">
39356 <features islongtable="true" headBottomDL="true">
39357 <column alignment="block" valignment="top" leftline="true" width="13col%">
39358 <column alignment="left" valignment="top" leftline="true" width="13col%">
39359 <column alignment="block" valignment="top" leftline="true" width="22col%">
39360 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
39361 <row topline="true" bottomline="true" endhead="true">
39362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39363 \begin_inset Text
39364
39365 \begin_layout Standard
39366
39367 \series bold
39368 iCode
39369 \series default
39370
39371 \begin_inset LatexCommand index
39372 name "iCode"
39373
39374 \end_inset
39375
39376
39377 \end_layout
39378
39379 \end_inset
39380 </cell>
39381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39382 \begin_inset Text
39383
39384 \begin_layout Standard
39385
39386 \series bold
39387 Operands
39388 \end_layout
39389
39390 \end_inset
39391 </cell>
39392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39393 \begin_inset Text
39394
39395 \begin_layout Standard
39396
39397 \series bold
39398 Description
39399 \end_layout
39400
39401 \end_inset
39402 </cell>
39403 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39404 \begin_inset Text
39405
39406 \begin_layout Standard
39407
39408 \series bold
39409 C Equivalent
39410 \end_layout
39411
39412 \end_inset
39413 </cell>
39414 </row>
39415 <row topline="true">
39416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39417 \begin_inset Text
39418
39419 \begin_layout Standard
39420
39421 \size footnotesize
39422 '!'
39423 \end_layout
39424
39425 \end_inset
39426 </cell>
39427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39428 \begin_inset Text
39429
39430 \begin_layout Standard
39431
39432 \size footnotesize
39433 IC_LEFT() IC_RESULT()
39434 \end_layout
39435
39436 \end_inset
39437 </cell>
39438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39439 \begin_inset Text
39440
39441 \begin_layout Standard
39442
39443 \size footnotesize
39444 NOT operation 
39445 \end_layout
39446
39447 \end_inset
39448 </cell>
39449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39450 \begin_inset Text
39451
39452 \begin_layout Standard
39453
39454 \size footnotesize
39455 IC_RESULT = ! IC_LEFT;
39456 \end_layout
39457
39458 \end_inset
39459 </cell>
39460 </row>
39461 <row topline="true">
39462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39463 \begin_inset Text
39464
39465 \begin_layout Standard
39466
39467 \size footnotesize
39468 '~'
39469 \end_layout
39470
39471 \end_inset
39472 </cell>
39473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39474 \begin_inset Text
39475
39476 \begin_layout Standard
39477
39478 \size footnotesize
39479 IC_LEFT() IC_RESULT()
39480 \end_layout
39481
39482 \end_inset
39483 </cell>
39484 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39485 \begin_inset Text
39486
39487 \begin_layout Standard
39488
39489 \size footnotesize
39490 Bitwise complement of 
39491 \end_layout
39492
39493 \end_inset
39494 </cell>
39495 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39496 \begin_inset Text
39497
39498 \begin_layout Standard
39499
39500 \size footnotesize
39501 IC_RESULT = ~IC_LEFT;
39502 \end_layout
39503
39504 \end_inset
39505 </cell>
39506 </row>
39507 <row topline="true">
39508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39509 \begin_inset Text
39510
39511 \begin_layout Standard
39512
39513 \size footnotesize
39514 RRC
39515 \end_layout
39516
39517 \end_inset
39518 </cell>
39519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39520 \begin_inset Text
39521
39522 \begin_layout Standard
39523
39524 \size footnotesize
39525 IC_LEFT() IC_RESULT()
39526 \end_layout
39527
39528 \end_inset
39529 </cell>
39530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39531 \begin_inset Text
39532
39533 \begin_layout Standard
39534
39535 \size footnotesize
39536 Rotate right with carry
39537 \end_layout
39538
39539 \end_inset
39540 </cell>
39541 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39542 \begin_inset Text
39543
39544 \begin_layout Standard
39545
39546 \size footnotesize
39547 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
39548 \end_layout
39549
39550 \end_inset
39551 </cell>
39552 </row>
39553 <row topline="true">
39554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39555 \begin_inset Text
39556
39557 \begin_layout Standard
39558
39559 \size footnotesize
39560 RLC
39561 \end_layout
39562
39563 \end_inset
39564 </cell>
39565 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39566 \begin_inset Text
39567
39568 \begin_layout Standard
39569
39570 \size footnotesize
39571 IC_LEFT() IC_RESULT()
39572 \end_layout
39573
39574 \end_inset
39575 </cell>
39576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39577 \begin_inset Text
39578
39579 \begin_layout Standard
39580
39581 \size footnotesize
39582 Rotate left with carry
39583 \end_layout
39584
39585 \end_inset
39586 </cell>
39587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39588 \begin_inset Text
39589
39590 \begin_layout Standard
39591
39592 \size footnotesize
39593 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
39594 \end_layout
39595
39596 \end_inset
39597 </cell>
39598 </row>
39599 <row topline="true">
39600 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39601 \begin_inset Text
39602
39603 \begin_layout Standard
39604
39605 \size footnotesize
39606 GETHBIT
39607 \end_layout
39608
39609 \end_inset
39610 </cell>
39611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39612 \begin_inset Text
39613
39614 \begin_layout Standard
39615
39616 \size footnotesize
39617 IC_LEFT() IC_RESULT()
39618 \end_layout
39619
39620 \end_inset
39621 </cell>
39622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39623 \begin_inset Text
39624
39625 \begin_layout Standard
39626
39627 \size footnotesize
39628 Get the highest order bit of IC_LEFT
39629 \end_layout
39630
39631 \end_inset
39632 </cell>
39633 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39634 \begin_inset Text
39635
39636 \begin_layout Standard
39637
39638 \size footnotesize
39639 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
39640 \end_layout
39641
39642 \end_inset
39643 </cell>
39644 </row>
39645 <row topline="true">
39646 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39647 \begin_inset Text
39648
39649 \begin_layout Standard
39650
39651 \size footnotesize
39652 UNARYMINUS
39653 \end_layout
39654
39655 \end_inset
39656 </cell>
39657 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39658 \begin_inset Text
39659
39660 \begin_layout Standard
39661
39662 \size footnotesize
39663 IC_LEFT() IC_RESULT()
39664 \end_layout
39665
39666 \end_inset
39667 </cell>
39668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39669 \begin_inset Text
39670
39671 \begin_layout Standard
39672
39673 \size footnotesize
39674 Unary minus
39675 \end_layout
39676
39677 \end_inset
39678 </cell>
39679 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39680 \begin_inset Text
39681
39682 \begin_layout Standard
39683
39684 \size footnotesize
39685 IC_RESULT = - IC_LEFT;
39686 \end_layout
39687
39688 \end_inset
39689 </cell>
39690 </row>
39691 <row topline="true">
39692 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39693 \begin_inset Text
39694
39695 \begin_layout Standard
39696
39697 \size footnotesize
39698 IPUSH
39699 \end_layout
39700
39701 \end_inset
39702 </cell>
39703 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39704 \begin_inset Text
39705
39706 \begin_layout Standard
39707
39708 \size footnotesize
39709 IC_LEFT()
39710 \end_layout
39711
39712 \end_inset
39713 </cell>
39714 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39715 \begin_inset Text
39716
39717 \begin_layout Standard
39718
39719 \size footnotesize
39720 Push the operand into stack
39721 \end_layout
39722
39723 \end_inset
39724 </cell>
39725 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39726 \begin_inset Text
39727
39728 \begin_layout Standard
39729
39730 \size footnotesize
39731 NONE
39732 \end_layout
39733
39734 \end_inset
39735 </cell>
39736 </row>
39737 <row topline="true">
39738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39739 \begin_inset Text
39740
39741 \begin_layout Standard
39742
39743 \size footnotesize
39744 IPOP
39745 \end_layout
39746
39747 \end_inset
39748 </cell>
39749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39750 \begin_inset Text
39751
39752 \begin_layout Standard
39753
39754 \size footnotesize
39755 IC_LEFT()
39756 \end_layout
39757
39758 \end_inset
39759 </cell>
39760 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39761 \begin_inset Text
39762
39763 \begin_layout Standard
39764
39765 \size footnotesize
39766 Pop the operand from the stack 
39767 \end_layout
39768
39769 \end_inset
39770 </cell>
39771 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39772 \begin_inset Text
39773
39774 \begin_layout Standard
39775
39776 \size footnotesize
39777 NONE
39778 \end_layout
39779
39780 \end_inset
39781 </cell>
39782 </row>
39783 <row topline="true">
39784 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39785 \begin_inset Text
39786
39787 \begin_layout Standard
39788
39789 \size footnotesize
39790 CALL
39791 \end_layout
39792
39793 \end_inset
39794 </cell>
39795 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39796 \begin_inset Text
39797
39798 \begin_layout Standard
39799
39800 \size footnotesize
39801 IC_LEFT() IC_RESULT()
39802 \end_layout
39803
39804 \end_inset
39805 </cell>
39806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39807 \begin_inset Text
39808
39809 \begin_layout Standard
39810
39811 \size footnotesize
39812 Call the function represented by IC_LEFT 
39813 \end_layout
39814
39815 \end_inset
39816 </cell>
39817 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39818 \begin_inset Text
39819
39820 \begin_layout Standard
39821
39822 \size footnotesize
39823 IC_RESULT = IC_LEFT();
39824 \end_layout
39825
39826 \end_inset
39827 </cell>
39828 </row>
39829 <row topline="true">
39830 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39831 \begin_inset Text
39832
39833 \begin_layout Standard
39834
39835 \size footnotesize
39836 PCALL
39837 \end_layout
39838
39839 \end_inset
39840 </cell>
39841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39842 \begin_inset Text
39843
39844 \begin_layout Standard
39845
39846 \size footnotesize
39847 IC_LEFT() IC_RESULT()
39848 \end_layout
39849
39850 \end_inset
39851 </cell>
39852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39853 \begin_inset Text
39854
39855 \begin_layout Standard
39856
39857 \size footnotesize
39858 Call via function pointer
39859 \end_layout
39860
39861 \end_inset
39862 </cell>
39863 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39864 \begin_inset Text
39865
39866 \begin_layout Standard
39867
39868 \size footnotesize
39869 IC_RESULT = (*IC_LEFT)();
39870 \end_layout
39871
39872 \end_inset
39873 </cell>
39874 </row>
39875 <row topline="true">
39876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39877 \begin_inset Text
39878
39879 \begin_layout Standard
39880
39881 \size footnotesize
39882 RETURN
39883 \end_layout
39884
39885 \end_inset
39886 </cell>
39887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39888 \begin_inset Text
39889
39890 \begin_layout Standard
39891
39892 \size footnotesize
39893 IC_LEFT()
39894 \end_layout
39895
39896 \end_inset
39897 </cell>
39898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39899 \begin_inset Text
39900
39901 \begin_layout Standard
39902
39903 \size footnotesize
39904 Return the value in operand IC_LEFT 
39905 \end_layout
39906
39907 \end_inset
39908 </cell>
39909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39910 \begin_inset Text
39911
39912 \begin_layout Standard
39913
39914 \size footnotesize
39915 return IC_LEFT;
39916 \end_layout
39917
39918 \end_inset
39919 </cell>
39920 </row>
39921 <row topline="true">
39922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39923 \begin_inset Text
39924
39925 \begin_layout Standard
39926
39927 \size footnotesize
39928 LABEL
39929 \end_layout
39930
39931 \end_inset
39932 </cell>
39933 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39934 \begin_inset Text
39935
39936 \begin_layout Standard
39937
39938 \size footnotesize
39939 IC_LABEL() 
39940 \end_layout
39941
39942 \end_inset
39943 </cell>
39944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39945 \begin_inset Text
39946
39947 \begin_layout Standard
39948
39949 \size footnotesize
39950 Label
39951 \end_layout
39952
39953 \end_inset
39954 </cell>
39955 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39956 \begin_inset Text
39957
39958 \begin_layout Standard
39959
39960 \size footnotesize
39961 IC_LABEL:
39962 \end_layout
39963
39964 \end_inset
39965 </cell>
39966 </row>
39967 <row topline="true">
39968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39969 \begin_inset Text
39970
39971 \begin_layout Standard
39972
39973 \size footnotesize
39974 GOTO
39975 \end_layout
39976
39977 \end_inset
39978 </cell>
39979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39980 \begin_inset Text
39981
39982 \begin_layout Standard
39983
39984 \size footnotesize
39985 IC_LABEL() 
39986 \end_layout
39987
39988 \end_inset
39989 </cell>
39990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39991 \begin_inset Text
39992
39993 \begin_layout Standard
39994
39995 \size footnotesize
39996 Goto label
39997 \end_layout
39998
39999 \end_inset
40000 </cell>
40001 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40002 \begin_inset Text
40003
40004 \begin_layout Standard
40005
40006 \size footnotesize
40007 goto IC_LABEL();
40008 \end_layout
40009
40010 \end_inset
40011 </cell>
40012 </row>
40013 <row topline="true">
40014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40015 \begin_inset Text
40016
40017 \begin_layout Standard
40018
40019 \size footnotesize
40020 '+'
40021 \end_layout
40022
40023 \end_inset
40024 </cell>
40025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40026 \begin_inset Text
40027
40028 \begin_layout Standard
40029
40030 \size footnotesize
40031 IC_LEFT() IC_RIGHT() IC_RESULT()
40032 \end_layout
40033
40034 \end_inset
40035 </cell>
40036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40037 \begin_inset Text
40038
40039 \begin_layout Standard
40040
40041 \size footnotesize
40042 Addition
40043 \end_layout
40044
40045 \end_inset
40046 </cell>
40047 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40048 \begin_inset Text
40049
40050 \begin_layout Standard
40051
40052 \size footnotesize
40053 IC_RESULT = IC_LEFT + IC_RIGHT
40054 \end_layout
40055
40056 \end_inset
40057 </cell>
40058 </row>
40059 <row topline="true">
40060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40061 \begin_inset Text
40062
40063 \begin_layout Standard
40064
40065 \size footnotesize
40066 '-'
40067 \end_layout
40068
40069 \end_inset
40070 </cell>
40071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40072 \begin_inset Text
40073
40074 \begin_layout Standard
40075
40076 \size footnotesize
40077 IC_LEFT() IC_RIGHT() IC_RESULT()
40078 \end_layout
40079
40080 \end_inset
40081 </cell>
40082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40083 \begin_inset Text
40084
40085 \begin_layout Standard
40086
40087 \size footnotesize
40088 Subtraction
40089 \end_layout
40090
40091 \end_inset
40092 </cell>
40093 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40094 \begin_inset Text
40095
40096 \begin_layout Standard
40097
40098 \size footnotesize
40099 IC_RESULT = IC_LEFT - IC_RIGHT 
40100 \end_layout
40101
40102 \end_inset
40103 </cell>
40104 </row>
40105 <row topline="true">
40106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40107 \begin_inset Text
40108
40109 \begin_layout Standard
40110
40111 \size footnotesize
40112 '*'
40113 \end_layout
40114
40115 \end_inset
40116 </cell>
40117 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40118 \begin_inset Text
40119
40120 \begin_layout Standard
40121
40122 \size footnotesize
40123 IC_LEFT() IC_RIGHT() IC_RESULT()
40124 \end_layout
40125
40126 \end_inset
40127 </cell>
40128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40129 \begin_inset Text
40130
40131 \begin_layout Standard
40132
40133 \size footnotesize
40134 Multiplication 
40135 \end_layout
40136
40137 \end_inset
40138 </cell>
40139 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40140 \begin_inset Text
40141
40142 \begin_layout Standard
40143
40144 \size footnotesize
40145 IC_RESULT = IC_LEFT * IC_RIGHT;
40146 \end_layout
40147
40148 \end_inset
40149 </cell>
40150 </row>
40151 <row topline="true">
40152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40153 \begin_inset Text
40154
40155 \begin_layout Standard
40156
40157 \size footnotesize
40158 '/'
40159 \end_layout
40160
40161 \end_inset
40162 </cell>
40163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40164 \begin_inset Text
40165
40166 \begin_layout Standard
40167
40168 \size footnotesize
40169 IC_LEFT() IC_RIGHT() IC_RESULT()
40170 \end_layout
40171
40172 \end_inset
40173 </cell>
40174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40175 \begin_inset Text
40176
40177 \begin_layout Standard
40178
40179 \size footnotesize
40180 Division
40181 \end_layout
40182
40183 \end_inset
40184 </cell>
40185 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40186 \begin_inset Text
40187
40188 \begin_layout Standard
40189
40190 \size footnotesize
40191 IC_RESULT = IC_LEFT / IC_RIGHT;
40192 \end_layout
40193
40194 \end_inset
40195 </cell>
40196 </row>
40197 <row topline="true">
40198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40199 \begin_inset Text
40200
40201 \begin_layout Standard
40202
40203 \size footnotesize
40204 '%'
40205 \end_layout
40206
40207 \end_inset
40208 </cell>
40209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40210 \begin_inset Text
40211
40212 \begin_layout Standard
40213
40214 \size footnotesize
40215 IC_LEFT() IC_RIGHT() IC_RESULT()
40216 \end_layout
40217
40218 \end_inset
40219 </cell>
40220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40221 \begin_inset Text
40222
40223 \begin_layout Standard
40224
40225 \size footnotesize
40226 Modulus
40227 \end_layout
40228
40229 \end_inset
40230 </cell>
40231 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40232 \begin_inset Text
40233
40234 \begin_layout Standard
40235
40236 \size footnotesize
40237 IC_RESULT = IC_LEFT % IC_RIGHT;
40238 \end_layout
40239
40240 \end_inset
40241 </cell>
40242 </row>
40243 <row topline="true">
40244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40245 \begin_inset Text
40246
40247 \begin_layout Standard
40248
40249 \size footnotesize
40250 '<'
40251 \end_layout
40252
40253 \end_inset
40254 </cell>
40255 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40256 \begin_inset Text
40257
40258 \begin_layout Standard
40259
40260 \size footnotesize
40261 IC_LEFT() IC_RIGHT() IC_RESULT()
40262 \end_layout
40263
40264 \end_inset
40265 </cell>
40266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40267 \begin_inset Text
40268
40269 \begin_layout Standard
40270
40271 \size footnotesize
40272 Less than
40273 \end_layout
40274
40275 \end_inset
40276 </cell>
40277 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40278 \begin_inset Text
40279
40280 \begin_layout Standard
40281
40282 \size footnotesize
40283 IC_RESULT = IC_LEFT < IC_RIGHT;
40284 \end_layout
40285
40286 \end_inset
40287 </cell>
40288 </row>
40289 <row topline="true">
40290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40291 \begin_inset Text
40292
40293 \begin_layout Standard
40294
40295 \size footnotesize
40296 '>'
40297 \end_layout
40298
40299 \end_inset
40300 </cell>
40301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40302 \begin_inset Text
40303
40304 \begin_layout Standard
40305
40306 \size footnotesize
40307 IC_LEFT() IC_RIGHT() IC_RESULT()
40308 \end_layout
40309
40310 \end_inset
40311 </cell>
40312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40313 \begin_inset Text
40314
40315 \begin_layout Standard
40316
40317 \size footnotesize
40318 Greater than 
40319 \end_layout
40320
40321 \end_inset
40322 </cell>
40323 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40324 \begin_inset Text
40325
40326 \begin_layout Standard
40327
40328 \size footnotesize
40329 IC_RESULT = IC_LEFT > IC_RIGHT;
40330 \end_layout
40331
40332 \end_inset
40333 </cell>
40334 </row>
40335 <row topline="true">
40336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40337 \begin_inset Text
40338
40339 \begin_layout Standard
40340
40341 \size footnotesize
40342 EQ_OP
40343 \end_layout
40344
40345 \end_inset
40346 </cell>
40347 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40348 \begin_inset Text
40349
40350 \begin_layout Standard
40351
40352 \size footnotesize
40353 IC_LEFT() IC_RIGHT() IC_RESULT()
40354 \end_layout
40355
40356 \end_inset
40357 </cell>
40358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40359 \begin_inset Text
40360
40361 \begin_layout Standard
40362
40363 \size footnotesize
40364 Equal to 
40365 \end_layout
40366
40367 \end_inset
40368 </cell>
40369 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40370 \begin_inset Text
40371
40372 \begin_layout Standard
40373
40374 \size footnotesize
40375 IC_RESULT = IC_LEFT == IC_RIGHT;
40376 \end_layout
40377
40378 \end_inset
40379 </cell>
40380 </row>
40381 <row topline="true">
40382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40383 \begin_inset Text
40384
40385 \begin_layout Standard
40386
40387 \size footnotesize
40388 AND_OP
40389 \end_layout
40390
40391 \end_inset
40392 </cell>
40393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40394 \begin_inset Text
40395
40396 \begin_layout Standard
40397
40398 \size footnotesize
40399 IC_LEFT() IC_RIGHT() IC_RESULT() 
40400 \end_layout
40401
40402 \end_inset
40403 </cell>
40404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40405 \begin_inset Text
40406
40407 \begin_layout Standard
40408
40409 \size footnotesize
40410 Logical and operation
40411 \end_layout
40412
40413 \end_inset
40414 </cell>
40415 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40416 \begin_inset Text
40417
40418 \begin_layout Standard
40419
40420 \size footnotesize
40421 IC_RESULT = IC_LEFT && IC_RIGHT; 
40422 \end_layout
40423
40424 \end_inset
40425 </cell>
40426 </row>
40427 <row topline="true">
40428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40429 \begin_inset Text
40430
40431 \begin_layout Standard
40432
40433 \size footnotesize
40434 OR_OP
40435 \end_layout
40436
40437 \end_inset
40438 </cell>
40439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40440 \begin_inset Text
40441
40442 \begin_layout Standard
40443
40444 \size footnotesize
40445 IC_LEFT() IC_RIGHT() IC_RESULT() 
40446 \end_layout
40447
40448 \end_inset
40449 </cell>
40450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40451 \begin_inset Text
40452
40453 \begin_layout Standard
40454
40455 \size footnotesize
40456 Logical or operation 
40457 \end_layout
40458
40459 \end_inset
40460 </cell>
40461 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40462 \begin_inset Text
40463
40464 \begin_layout Standard
40465
40466 \size footnotesize
40467 IC_RESULT = IC_LEFT || IC_RIGHT; 
40468 \end_layout
40469
40470 \end_inset
40471 </cell>
40472 </row>
40473 <row topline="true">
40474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40475 \begin_inset Text
40476
40477 \begin_layout Standard
40478
40479 \size footnotesize
40480 '^'
40481 \end_layout
40482
40483 \end_inset
40484 </cell>
40485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40486 \begin_inset Text
40487
40488 \begin_layout Standard
40489
40490 \size footnotesize
40491 IC_LEFT() IC_RIGHT() IC_RESULT() 
40492 \end_layout
40493
40494 \end_inset
40495 </cell>
40496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40497 \begin_inset Text
40498
40499 \begin_layout Standard
40500
40501 \size footnotesize
40502 Exclusive OR
40503 \end_layout
40504
40505 \end_inset
40506 </cell>
40507 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40508 \begin_inset Text
40509
40510 \begin_layout Standard
40511
40512 \size footnotesize
40513 IC_RESULT = IC_LEFT ^ IC_RIGHT;
40514 \end_layout
40515
40516 \end_inset
40517 </cell>
40518 </row>
40519 <row topline="true">
40520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40521 \begin_inset Text
40522
40523 \begin_layout Standard
40524
40525 \size footnotesize
40526 '|'
40527 \end_layout
40528
40529 \end_inset
40530 </cell>
40531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40532 \begin_inset Text
40533
40534 \begin_layout Standard
40535
40536 \size footnotesize
40537 IC_LEFT() IC_RIGHT() IC_RESULT() 
40538 \end_layout
40539
40540 \end_inset
40541 </cell>
40542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40543 \begin_inset Text
40544
40545 \begin_layout Standard
40546
40547 \size footnotesize
40548 Bitwise OR 
40549 \end_layout
40550
40551 \end_inset
40552 </cell>
40553 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40554 \begin_inset Text
40555
40556 \begin_layout Standard
40557
40558 \size footnotesize
40559 IC_RESULT = IC_LEFT | IC_RIGHT;
40560 \end_layout
40561
40562 \end_inset
40563 </cell>
40564 </row>
40565 <row topline="true">
40566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40567 \begin_inset Text
40568
40569 \begin_layout Standard
40570
40571 \size footnotesize
40572 BITWISEAND
40573 \end_layout
40574
40575 \end_inset
40576 </cell>
40577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40578 \begin_inset Text
40579
40580 \begin_layout Standard
40581
40582 \size footnotesize
40583 IC_LEFT() IC_RIGHT() IC_RESULT()
40584 \end_layout
40585
40586 \end_inset
40587 </cell>
40588 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40589 \begin_inset Text
40590
40591 \begin_layout Standard
40592
40593 \size footnotesize
40594 Bitwise AND 
40595 \end_layout
40596
40597 \end_inset
40598 </cell>
40599 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40600 \begin_inset Text
40601
40602 \begin_layout Standard
40603
40604 \size footnotesize
40605 IC_RESULT = IC_LEFT & IC_RIGHT;
40606 \end_layout
40607
40608 \end_inset
40609 </cell>
40610 </row>
40611 <row topline="true">
40612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40613 \begin_inset Text
40614
40615 \begin_layout Standard
40616
40617 \size footnotesize
40618 LEFT_OP
40619 \end_layout
40620
40621 \end_inset
40622 </cell>
40623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40624 \begin_inset Text
40625
40626 \begin_layout Standard
40627
40628 \size footnotesize
40629 IC_LEFT() IC_RIGHT() IC_RESULT()
40630 \end_layout
40631
40632 \end_inset
40633 </cell>
40634 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40635 \begin_inset Text
40636
40637 \begin_layout Standard
40638
40639 \size footnotesize
40640 Left shift 
40641 \end_layout
40642
40643 \end_inset
40644 </cell>
40645 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40646 \begin_inset Text
40647
40648 \begin_layout Standard
40649
40650 \size footnotesize
40651 IC_RESULT = IC_LEFT << IC_RIGHT 
40652 \end_layout
40653
40654 \end_inset
40655 </cell>
40656 </row>
40657 <row topline="true">
40658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40659 \begin_inset Text
40660
40661 \begin_layout Standard
40662
40663 \size footnotesize
40664 RIGHT_OP
40665 \end_layout
40666
40667 \end_inset
40668 </cell>
40669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40670 \begin_inset Text
40671
40672 \begin_layout Standard
40673
40674 \size footnotesize
40675 IC_LEFT() IC_RIGHT() IC_RESULT()
40676 \end_layout
40677
40678 \end_inset
40679 </cell>
40680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40681 \begin_inset Text
40682
40683 \begin_layout Standard
40684
40685 \size footnotesize
40686 Right shift
40687 \end_layout
40688
40689 \end_inset
40690 </cell>
40691 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40692 \begin_inset Text
40693
40694 \begin_layout Standard
40695
40696 \size footnotesize
40697 IC_RESULT = IC_LEFT >> IC_RIGHT 
40698 \end_layout
40699
40700 \end_inset
40701 </cell>
40702 </row>
40703 <row topline="true">
40704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40705 \begin_inset Text
40706
40707 \begin_layout Standard
40708
40709 \size footnotesize
40710 GET_VALUE_
40711 \newline
40712 AT_ ADDRESS
40713 \end_layout
40714
40715 \end_inset
40716 </cell>
40717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40718 \begin_inset Text
40719
40720 \begin_layout Standard
40721
40722 \size footnotesize
40723 IC_LEFT() IC_RESULT()
40724 \end_layout
40725
40726 \end_inset
40727 </cell>
40728 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40729 \begin_inset Text
40730
40731 \begin_layout Standard
40732
40733 \size footnotesize
40734 Indirect fetch 
40735 \end_layout
40736
40737 \end_inset
40738 </cell>
40739 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40740 \begin_inset Text
40741
40742 \begin_layout Standard
40743
40744 \size footnotesize
40745 IC_RESULT = (*IC_LEFT);
40746 \end_layout
40747
40748 \end_inset
40749 </cell>
40750 </row>
40751 <row topline="true">
40752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40753 \begin_inset Text
40754
40755 \begin_layout Standard
40756
40757 \size footnotesize
40758 POINTER_SET
40759 \end_layout
40760
40761 \end_inset
40762 </cell>
40763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40764 \begin_inset Text
40765
40766 \begin_layout Standard
40767
40768 \size footnotesize
40769 IC_RIGHT() IC_RESULT() 
40770 \end_layout
40771
40772 \end_inset
40773 </cell>
40774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40775 \begin_inset Text
40776
40777 \begin_layout Standard
40778
40779 \size footnotesize
40780 Indirect set
40781 \end_layout
40782
40783 \end_inset
40784 </cell>
40785 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40786 \begin_inset Text
40787
40788 \begin_layout Standard
40789
40790 \size footnotesize
40791 (*IC_RESULT) = IC_RIGHT;
40792 \end_layout
40793
40794 \end_inset
40795 </cell>
40796 </row>
40797 <row topline="true">
40798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40799 \begin_inset Text
40800
40801 \begin_layout Standard
40802
40803 \size footnotesize
40804 '='
40805 \end_layout
40806
40807 \end_inset
40808 </cell>
40809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40810 \begin_inset Text
40811
40812 \begin_layout Standard
40813
40814 \size footnotesize
40815 IC_RIGHT() IC_RESULT()
40816 \end_layout
40817
40818 \end_inset
40819 </cell>
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 Assignment
40827 \end_layout
40828
40829 \end_inset
40830 </cell>
40831 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40832 \begin_inset Text
40833
40834 \begin_layout Standard
40835
40836 \size footnotesize
40837 IC_RESULT = IC_RIGHT;
40838 \end_layout
40839
40840 \end_inset
40841 </cell>
40842 </row>
40843 <row topline="true">
40844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40845 \begin_inset Text
40846
40847 \begin_layout Standard
40848
40849 \size footnotesize
40850 IFX
40851 \end_layout
40852
40853 \end_inset
40854 </cell>
40855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40856 \begin_inset Text
40857
40858 \begin_layout Standard
40859
40860 \size footnotesize
40861 IC_COND IC_TRUE IC_LABEL
40862 \end_layout
40863
40864 \end_inset
40865 </cell>
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 Conditional jump.
40873  If true label is present then jump to true label if condition is true else
40874  jump to false label if condition is false 
40875 \end_layout
40876
40877 \end_inset
40878 </cell>
40879 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40880 \begin_inset Text
40881
40882 \begin_layout Standard
40883
40884 \size footnotesize
40885 if (IC_COND) goto IC_TRUE; 
40886 \newline
40887 \InsetSpace ~
40888 \InsetSpace ~
40889 Or 
40890 \newline
40891 If (!IC_COND) goto IC_FALSE;
40892 \end_layout
40893
40894 \end_inset
40895 </cell>
40896 </row>
40897 <row topline="true">
40898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40899 \begin_inset Text
40900
40901 \begin_layout Standard
40902
40903 \size footnotesize
40904 ADDRESS_OF
40905 \end_layout
40906
40907 \end_inset
40908 </cell>
40909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40910 \begin_inset Text
40911
40912 \begin_layout Standard
40913
40914 \size footnotesize
40915 IC_LEFT() IC_RESULT()
40916 \end_layout
40917
40918 \end_inset
40919 </cell>
40920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40921 \begin_inset Text
40922
40923 \begin_layout Standard
40924
40925 \size footnotesize
40926 Address of 
40927 \end_layout
40928
40929 \end_inset
40930 </cell>
40931 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40932 \begin_inset Text
40933
40934 \begin_layout Standard
40935
40936 \size footnotesize
40937 IC_RESULT = &IC_LEFT();
40938 \end_layout
40939
40940 \end_inset
40941 </cell>
40942 </row>
40943 <row topline="true">
40944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40945 \begin_inset Text
40946
40947 \begin_layout Standard
40948
40949 \size footnotesize
40950 JUMPTABLE
40951 \end_layout
40952
40953 \end_inset
40954 </cell>
40955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40956 \begin_inset Text
40957
40958 \begin_layout Standard
40959
40960 \size footnotesize
40961 IC_JTCOND IC_JTLABELS
40962 \end_layout
40963
40964 \end_inset
40965 </cell>
40966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40967 \begin_inset Text
40968
40969 \begin_layout Standard
40970
40971 \size footnotesize
40972 Jump to list of labels depending on the value of JTCOND
40973 \end_layout
40974
40975 \end_inset
40976 </cell>
40977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40978 \begin_inset Text
40979
40980 \begin_layout Standard
40981
40982 \size footnotesize
40983 Switch statement
40984 \end_layout
40985
40986 \end_inset
40987 </cell>
40988 </row>
40989 <row topline="true">
40990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40991 \begin_inset Text
40992
40993 \begin_layout Standard
40994
40995 \size footnotesize
40996 CAST
40997 \end_layout
40998
40999 \end_inset
41000 </cell>
41001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41002 \begin_inset Text
41003
41004 \begin_layout Standard
41005
41006 \size footnotesize
41007 IC_RIGHT() IC_LEFT() IC_RESULT()
41008 \end_layout
41009
41010 \end_inset
41011 </cell>
41012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41013 \begin_inset Text
41014
41015 \begin_layout Standard
41016
41017 \size footnotesize
41018 Cast types 
41019 \end_layout
41020
41021 \end_inset
41022 </cell>
41023 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41024 \begin_inset Text
41025
41026 \begin_layout Standard
41027
41028 \size footnotesize
41029 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
41030 \end_layout
41031
41032 \end_inset
41033 </cell>
41034 </row>
41035 <row topline="true">
41036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41037 \begin_inset Text
41038
41039 \begin_layout Standard
41040
41041 \size footnotesize
41042 SEND
41043 \end_layout
41044
41045 \end_inset
41046 </cell>
41047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41048 \begin_inset Text
41049
41050 \begin_layout Standard
41051
41052 \size footnotesize
41053 IC_LEFT()
41054 \end_layout
41055
41056 \end_inset
41057 </cell>
41058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41059 \begin_inset Text
41060
41061 \begin_layout Standard
41062
41063 \size footnotesize
41064 This is used for passing parameters in registers; 
41065 \newline
41066 move IC_LEFT to the next
41067  available parameter register.
41068 \end_layout
41069
41070 \end_inset
41071 </cell>
41072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41073 \begin_inset Text
41074
41075 \begin_layout Standard
41076
41077 \size footnotesize
41078 None
41079 \end_layout
41080
41081 \end_inset
41082 </cell>
41083 </row>
41084 <row topline="true">
41085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41086 \begin_inset Text
41087
41088 \begin_layout Standard
41089
41090 \size footnotesize
41091 RECV
41092 \end_layout
41093
41094 \end_inset
41095 </cell>
41096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41097 \begin_inset Text
41098
41099 \begin_layout Standard
41100
41101 \size footnotesize
41102 IC_RESULT()
41103 \end_layout
41104
41105 \end_inset
41106 </cell>
41107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41108 \begin_inset Text
41109
41110 \begin_layout Standard
41111
41112 \size footnotesize
41113 This is used for receiving parameters passed in registers;
41114 \newline
41115 Move the values
41116  in the next parameter register to IC_RESULT 
41117 \end_layout
41118
41119 \end_inset
41120 </cell>
41121 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41122 \begin_inset Text
41123
41124 \begin_layout Standard
41125
41126 \size footnotesize
41127 None
41128 \end_layout
41129
41130 \end_inset
41131 </cell>
41132 </row>
41133 <row topline="true" bottomline="true">
41134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41135 \begin_inset Text
41136
41137 \begin_layout Standard
41138
41139 \shape slanted
41140 \size footnotesize
41141 (some more have been added)
41142 \end_layout
41143
41144 \end_inset
41145 </cell>
41146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41147 \begin_inset Text
41148
41149 \begin_layout Standard
41150
41151 \end_layout
41152
41153 \end_inset
41154 </cell>
41155 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41156 \begin_inset Text
41157
41158 \begin_layout Standard
41159
41160 \end_layout
41161
41162 \end_inset
41163 </cell>
41164 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41165 \begin_inset Text
41166
41167 \begin_layout Standard
41168
41169 \shape slanted
41170 \size footnotesize
41171 see f.e.
41172
41173 \shape default
41174  
41175 \family typewriter
41176 \shape slanted
41177 gen51Code()
41178 \family default
41179 \shape default
41180  
41181 \shape slanted
41182 in
41183 \shape default
41184  
41185 \family typewriter
41186 \shape slanted
41187 src/mcs51/gen.c
41188 \end_layout
41189
41190 \end_inset
41191 </cell>
41192 </row>
41193 </lyxtabular>
41194
41195 \end_inset
41196
41197
41198 \end_layout
41199
41200 \begin_layout Standard
41201 \begin_inset Note Note
41202 status collapsed
41203
41204 \begin_layout Standard
41205 In the original article Figure II was announced to be downloadable on 
41206 \shape italic
41207 Circuit Cellar
41208 \shape default
41209 's web site.
41210  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
41211 \end_layout
41212
41213 \end_inset
41214
41215
41216 \end_layout
41217
41218 \begin_layout Paragraph*
41219 ICode Example
41220 \begin_inset LatexCommand index
41221 name "iCode"
41222
41223 \end_inset
41224
41225
41226 \end_layout
41227
41228 \begin_layout Standard
41229 This section shows some details of iCode.
41230  The example C code does not do anything useful; it is used as an example
41231  to illustrate the intermediate code generated by the compiler.
41232 \end_layout
41233
41234 \begin_layout Verse
41235
41236 \family typewriter
41237 1.\InsetSpace ~
41238 xdata int * p;
41239 \newline
41240 2.\InsetSpace ~
41241 int gint;
41242 \newline
41243 3.\InsetSpace ~
41244 /* This function does nothing useful.
41245  It is used
41246 \newline
41247 4.\InsetSpace ~
41248 \InsetSpace ~
41249 \InsetSpace ~
41250 \InsetSpace ~
41251 for the purpose of explaining iCode */
41252 \newline
41253 5.\InsetSpace ~
41254 short function (data
41255  int *x)
41256 \newline
41257 6.\InsetSpace ~
41258 {
41259 \newline
41260 7.\InsetSpace ~
41261 \InsetSpace ~
41262 \InsetSpace ~
41263 short i=10; \InsetSpace ~
41264 \InsetSpace ~
41265 /* dead initialization eliminated */
41266 \newline
41267 8.\InsetSpace ~
41268 \InsetSpace ~
41269 \InsetSpace ~
41270 short sum=10;
41271  /* dead initialization eliminated */
41272 \newline
41273 9.\InsetSpace ~
41274 \InsetSpace ~
41275 \InsetSpace ~
41276 short mul;
41277 \newline
41278 10.\InsetSpace ~
41279 \InsetSpace ~
41280 int j ;
41281 \newline
41282 11.\InsetSpace ~
41283 \InsetSpace ~
41284 while (*x) *x++
41285  = *p++; 
41286 \newline
41287 12.\InsetSpace ~
41288 \InsetSpace ~
41289 \InsetSpace ~
41290 \InsetSpace ~
41291 sum = 0 ; 
41292 \newline
41293 13.\InsetSpace ~
41294 \InsetSpace ~
41295 mul = 0;
41296 \newline
41297 14.\InsetSpace ~
41298 \InsetSpace ~
41299 /* compiler detects i,j to be induction
41300  variables */
41301 \newline
41302 15.\InsetSpace ~
41303 \InsetSpace ~
41304 for (i = 0, j = 10 ; i < 10 ; i++, j
41305 \family default
41306 -
41307 \begin_inset ERT
41308 status collapsed
41309
41310 \begin_layout Standard
41311
41312
41313 \backslash
41314 /
41315 \end_layout
41316
41317 \end_inset
41318
41319 -
41320 \family typewriter
41321 ) {
41322 \newline
41323 16.\InsetSpace ~
41324 \InsetSpace ~
41325 \InsetSpace ~
41326 \InsetSpace ~
41327 sum += i;
41328 \newline
41329 17.\InsetSpace ~
41330 \InsetSpace ~
41331 \InsetSpace ~
41332 \InsetSpace ~
41333 mul += i * 3; \InsetSpace ~
41334 \InsetSpace ~
41335 /* this multiplication remains */
41336 \newline
41337 18.\InsetSpace ~
41338 \InsetSpace ~
41339 \InsetSpace ~
41340 \InsetSpace ~
41341 gint +=
41342  j * 3;\InsetSpace ~
41343 \InsetSpace ~
41344 /* this multiplication changed to addition */
41345 \newline
41346 19.\InsetSpace ~
41347 \InsetSpace ~
41348 }
41349 \newline
41350 20.\InsetSpace ~
41351 \InsetSpace ~
41352 return sum+mul;
41353 \newline
41354 21.\InsetSpace ~
41355 }
41356 \end_layout
41357
41358 \begin_layout Standard
41359 In addition to the operands each iCode contains information about the filename
41360  and line it corresponds to in the source file.
41361  The first field in the listing should be interpreted as follows:
41362 \newline
41363
41364 \shape italic
41365 \size footnotesize
41366 Filename(linenumber: iCode Execution sequence number : ICode hash table
41367  key : loop depth of the iCode).
41368 \shape default
41369 \size default
41370
41371 \newline
41372 Then follows the human readable form of the ICode operation.
41373  Each operand of this triplet form can be of three basic types a) compiler
41374  generated temporary b) user defined variable c) a constant value.
41375  Note that local variables and parameters are replaced by compiler generated
41376  temporaries.
41377  Live ranges
41378 \begin_inset LatexCommand index
41379 name "Live range analysis"
41380
41381 \end_inset
41382
41383  are computed only for temporaries (i.e.
41384  live ranges are not computed for global variables).
41385  Registers
41386 \begin_inset LatexCommand index
41387 name "Register allocation"
41388
41389 \end_inset
41390
41391  are allocated for temporaries only.
41392  Operands are formatted in the following manner:
41393 \newline
41394
41395 \shape italic
41396 \size footnotesize
41397 Operand Name [lr live-from : live-to ] { type information } [ registers
41398  allocated ].
41399 \shape default
41400 \size default
41401
41402 \newline
41403 As mentioned earlier the live ranges are computed in terms of the execution
41404  sequence number of the iCodes, for example 
41405 \newline
41406 the iTemp0 is live from (i.e.
41407  first defined in iCode with execution sequence number 3, and is last used
41408  in the iCode with sequence number 5).
41409  For induction variables such as iTemp21 the live range computation extends
41410  the lifetime from the start to the end of the loop.
41411 \newline
41412 The register allocator
41413  used the live range information to allocate registers, the same registers
41414  may be used for different temporaries if their live ranges do not overlap,
41415  for example r0 is allocated to both iTemp6 and to iTemp17 since their live
41416  ranges do not overlap.
41417  In addition the allocator also takes into consideration the type and usage
41418  of a temporary, for example itemp6 is a pointer to near space and is used
41419  as to fetch data from (i.e.
41420  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
41421  Some short lived temporaries are allocated to special registers which have
41422  meaning to the code generator e.g.
41423  iTemp13 is allocated to a pseudo register CC which tells the back end that
41424  the temporary is used only for a conditional jump the code generation makes
41425  use of this information to optimize a compare and jump ICode.
41426 \newline
41427 There are several
41428  loop optimizations
41429 \begin_inset LatexCommand index
41430 name "Loop optimization"
41431
41432 \end_inset
41433
41434  performed by the compiler.
41435  It can detect induction variables iTemp21(i) and iTemp23(j).
41436  Also note the compiler does selective strength reduction
41437 \begin_inset LatexCommand index
41438 name "Strength reduction"
41439
41440 \end_inset
41441
41442 , i.e.
41443  the multiplication of an induction variable in line 18 (gint = j * 3) is
41444  changed to addition, a new temporary iTemp17 is allocated and assigned
41445  a initial value, a constant 3 is then added for each iteration of the loop.
41446  The compiler does not change the multiplication
41447 \begin_inset LatexCommand index
41448 name "Multiplication"
41449
41450 \end_inset
41451
41452  in line 17 however since the processor does support an 8 * 8 bit multiplication.
41453 \newline
41454
41455 Note the dead code elimination
41456 \begin_inset LatexCommand index
41457 name "Dead-code elimination"
41458
41459 \end_inset
41460
41461  optimization eliminated the dead assignments in line 7 & 8 to I and sum
41462  respectively.
41463 \newline
41464
41465 \end_layout
41466
41467 \begin_layout Standard
41468
41469 \size footnotesize
41470 Sample.c (5:1:0:0) _entry($9) :
41471 \end_layout
41472
41473 \begin_layout Standard
41474
41475 \size footnotesize
41476 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
41477 \end_layout
41478
41479 \begin_layout Standard
41480
41481 \size footnotesize
41482 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
41483 \end_layout
41484
41485 \begin_layout Standard
41486
41487 \size footnotesize
41488 Sample.c(11:4:53:0) preHeaderLbl0($11) :
41489 \end_layout
41490
41491 \begin_layout Standard
41492
41493 \size footnotesize
41494 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
41495  * int}[r2]
41496 \end_layout
41497
41498 \begin_layout Standard
41499
41500 \size footnotesize
41501 Sample.c(11:6:5:1) _whilecontinue_0($1) :
41502 \end_layout
41503
41504 \begin_layout Standard
41505
41506 \size footnotesize
41507 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
41508  int}[r0]]
41509 \end_layout
41510
41511 \begin_layout Standard
41512
41513 \size footnotesize
41514 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
41515 \end_layout
41516
41517 \begin_layout Standard
41518
41519 \size footnotesize
41520 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
41521  * int}
41522 \end_layout
41523
41524 \begin_layout Standard
41525
41526 \size footnotesize
41527 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
41528  {short}
41529 \end_layout
41530
41531 \begin_layout Standard
41532
41533 \size footnotesize
41534 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
41535  * int}[DPTR]]
41536 \end_layout
41537
41538 \begin_layout Standard
41539
41540 \size footnotesize
41541 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
41542 }[r2 r3]
41543 \end_layout
41544
41545 \begin_layout Standard
41546
41547 \size footnotesize
41548 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
41549  * int}[r0] + 0x2 {short}
41550 \end_layout
41551
41552 \begin_layout Standard
41553
41554 \size footnotesize
41555 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
41556 \end_layout
41557
41558 \begin_layout Standard
41559
41560 \size footnotesize
41561 Sample.c(11:17:21:0)_whilebreak_0($3) :
41562 \end_layout
41563
41564 \begin_layout Standard
41565
41566 \size footnotesize
41567 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
41568 \end_layout
41569
41570 \begin_layout Standard
41571
41572 \size footnotesize
41573 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
41574 \end_layout
41575
41576 \begin_layout Standard
41577
41578 \size footnotesize
41579 Sample.c(15:20:54:0)preHeaderLbl1($13) :
41580 \end_layout
41581
41582 \begin_layout Standard
41583
41584 \size footnotesize
41585 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
41586 \end_layout
41587
41588 \begin_layout Standard
41589
41590 \size footnotesize
41591 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
41592 \end_layout
41593
41594 \begin_layout Standard
41595
41596 \size footnotesize
41597 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
41598 \end_layout
41599
41600 \begin_layout Standard
41601
41602 \size footnotesize
41603 Sample.c(15:24:26:1)_forcond_0($4) :
41604 \end_layout
41605
41606 \begin_layout Standard
41607
41608 \size footnotesize
41609 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
41610  < 0xa {short}
41611 \end_layout
41612
41613 \begin_layout Standard
41614
41615 \size footnotesize
41616 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
41617 \end_layout
41618
41619 \begin_layout Standard
41620
41621 \size footnotesize
41622 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
41623  + ITemp21 [lr21:38]{short}[r4]
41624 \end_layout
41625
41626 \begin_layout Standard
41627
41628 \size footnotesize
41629 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
41630  * 0x3 {short}
41631 \end_layout
41632
41633 \begin_layout Standard
41634
41635 \size footnotesize
41636 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
41637  + iTemp15 [lr29:30]{short}[r1]
41638 \end_layout
41639
41640 \begin_layout Standard
41641
41642 \size footnotesize
41643 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
41644  r0]- 0x3 {short}
41645 \end_layout
41646
41647 \begin_layout Standard
41648
41649 \size footnotesize
41650 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
41651 int}[r7 r0]
41652 \end_layout
41653
41654 \begin_layout Standard
41655
41656 \size footnotesize
41657 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
41658  + 0x1 {short}
41659 \end_layout
41660
41661 \begin_layout Standard
41662
41663 \size footnotesize
41664 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
41665  r6]- 0x1 {short}
41666 \end_layout
41667
41668 \begin_layout Standard
41669
41670 \size footnotesize
41671 Sample.c(19:38:47:1) goto _forcond_0($4)
41672 \end_layout
41673
41674 \begin_layout Standard
41675
41676 \size footnotesize
41677 Sample.c(19:39:48:0)_forbreak_0($7) :
41678 \end_layout
41679
41680 \begin_layout Standard
41681
41682 \size footnotesize
41683 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
41684  + ITemp11 [lr19:40]{short}[r3]
41685 \end_layout
41686
41687 \begin_layout Standard
41688
41689 \size footnotesize
41690 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
41691 \end_layout
41692
41693 \begin_layout Standard
41694
41695 \size footnotesize
41696 Sample.c(20:42:51:0)_return($8) :
41697 \end_layout
41698
41699 \begin_layout Standard
41700
41701 \size footnotesize
41702 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
41703 \size default
41704
41705 \newline
41706
41707 \newline
41708 Finally the code generated for this function:
41709 \newline
41710
41711 \end_layout
41712
41713 \begin_layout Standard
41714
41715 \size footnotesize
41716 .area DSEG (DATA)
41717 \end_layout
41718
41719 \begin_layout Standard
41720
41721 \size footnotesize
41722 _p::
41723 \end_layout
41724
41725 \begin_layout Standard
41726
41727 \size footnotesize
41728 \InsetSpace ~
41729 \InsetSpace ~
41730 .ds 2
41731 \end_layout
41732
41733 \begin_layout Standard
41734
41735 \size footnotesize
41736 _gint::
41737 \end_layout
41738
41739 \begin_layout Standard
41740
41741 \size footnotesize
41742 \InsetSpace ~
41743 \InsetSpace ~
41744 .ds 2
41745 \end_layout
41746
41747 \begin_layout Standard
41748
41749 \size footnotesize
41750 ; sample.c 5
41751 \end_layout
41752
41753 \begin_layout Standard
41754
41755 \size footnotesize
41756 ; ----------------------------------------------
41757 \end_layout
41758
41759 \begin_layout Standard
41760
41761 \size footnotesize
41762 ; function function
41763 \end_layout
41764
41765 \begin_layout Standard
41766
41767 \size footnotesize
41768 ; ----------------------------------------------
41769 \end_layout
41770
41771 \begin_layout Standard
41772
41773 \size footnotesize
41774 _function:
41775 \end_layout
41776
41777 \begin_layout Standard
41778
41779 \size footnotesize
41780 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
41781 \end_layout
41782
41783 \begin_layout Standard
41784
41785 \size footnotesize
41786 \InsetSpace ~
41787 \InsetSpace ~
41788 mov r2,dpl
41789 \end_layout
41790
41791 \begin_layout Standard
41792
41793 \size footnotesize
41794 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
41795 \end_layout
41796
41797 \begin_layout Standard
41798
41799 \size footnotesize
41800 \InsetSpace ~
41801 \InsetSpace ~
41802 mov ar0,r2
41803 \end_layout
41804
41805 \begin_layout Standard
41806
41807 \size footnotesize
41808 ;_whilecontinue_0($1) :
41809 \end_layout
41810
41811 \begin_layout Standard
41812
41813 \size footnotesize
41814 00101$:
41815 \end_layout
41816
41817 \begin_layout Standard
41818
41819 \size footnotesize
41820 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
41821 \end_layout
41822
41823 \begin_layout Standard
41824
41825 \size footnotesize
41826 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
41827 \end_layout
41828
41829 \begin_layout Standard
41830
41831 \size footnotesize
41832 \InsetSpace ~
41833 \InsetSpace ~
41834 mov ar2,@r0
41835 \end_layout
41836
41837 \begin_layout Standard
41838
41839 \size footnotesize
41840 \InsetSpace ~
41841 \InsetSpace ~
41842 inc r0
41843 \end_layout
41844
41845 \begin_layout Standard
41846
41847 \size footnotesize
41848 \InsetSpace ~
41849 \InsetSpace ~
41850 mov ar3,@r0
41851 \end_layout
41852
41853 \begin_layout Standard
41854
41855 \size footnotesize
41856 \InsetSpace ~
41857 \InsetSpace ~
41858 dec r0
41859 \end_layout
41860
41861 \begin_layout Standard
41862
41863 \size footnotesize
41864 \InsetSpace ~
41865 \InsetSpace ~
41866 mov a,r2
41867 \end_layout
41868
41869 \begin_layout Standard
41870
41871 \size footnotesize
41872 \InsetSpace ~
41873 \InsetSpace ~
41874 orl a,r3
41875 \end_layout
41876
41877 \begin_layout Standard
41878
41879 \size footnotesize
41880 \InsetSpace ~
41881 \InsetSpace ~
41882 jz 00103$
41883 \end_layout
41884
41885 \begin_layout Standard
41886
41887 \size footnotesize
41888 00114$:
41889 \end_layout
41890
41891 \begin_layout Standard
41892
41893 \size footnotesize
41894 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
41895 \end_layout
41896
41897 \begin_layout Standard
41898
41899 \size footnotesize
41900 \InsetSpace ~
41901 \InsetSpace ~
41902 mov dpl,_p
41903 \end_layout
41904
41905 \begin_layout Standard
41906
41907 \size footnotesize
41908 \InsetSpace ~
41909 \InsetSpace ~
41910 mov dph,(_p + 1)
41911 \end_layout
41912
41913 \begin_layout Standard
41914
41915 \size footnotesize
41916 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
41917 \end_layout
41918
41919 \begin_layout Standard
41920
41921 \size footnotesize
41922 \InsetSpace ~
41923 \InsetSpace ~
41924 mov a,#0x02
41925 \end_layout
41926
41927 \begin_layout Standard
41928
41929 \size footnotesize
41930 \InsetSpace ~
41931 \InsetSpace ~
41932 add a,_p
41933 \end_layout
41934
41935 \begin_layout Standard
41936
41937 \size footnotesize
41938 \InsetSpace ~
41939 \InsetSpace ~
41940 mov _p,a
41941 \end_layout
41942
41943 \begin_layout Standard
41944
41945 \size footnotesize
41946 \InsetSpace ~
41947 \InsetSpace ~
41948 clr a
41949 \end_layout
41950
41951 \begin_layout Standard
41952
41953 \size footnotesize
41954 \InsetSpace ~
41955 \InsetSpace ~
41956 addc a,(_p + 1)
41957 \end_layout
41958
41959 \begin_layout Standard
41960
41961 \size footnotesize
41962 \InsetSpace ~
41963 \InsetSpace ~
41964 mov (_p + 1),a
41965 \end_layout
41966
41967 \begin_layout Standard
41968
41969 \size footnotesize
41970 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
41971 \end_layout
41972
41973 \begin_layout Standard
41974
41975 \size footnotesize
41976 \InsetSpace ~
41977 \InsetSpace ~
41978 movx a,@dptr
41979 \end_layout
41980
41981 \begin_layout Standard
41982
41983 \size footnotesize
41984 \InsetSpace ~
41985 \InsetSpace ~
41986 mov r2,a
41987 \end_layout
41988
41989 \begin_layout Standard
41990
41991 \size footnotesize
41992 \InsetSpace ~
41993 \InsetSpace ~
41994 inc dptr
41995 \end_layout
41996
41997 \begin_layout Standard
41998
41999 \size footnotesize
42000 \InsetSpace ~
42001 \InsetSpace ~
42002 movx a,@dptr
42003 \end_layout
42004
42005 \begin_layout Standard
42006
42007 \size footnotesize
42008 \InsetSpace ~
42009 \InsetSpace ~
42010 mov r3,a
42011 \end_layout
42012
42013 \begin_layout Standard
42014
42015 \size footnotesize
42016 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
42017 \end_layout
42018
42019 \begin_layout Standard
42020
42021 \size footnotesize
42022 \InsetSpace ~
42023 \InsetSpace ~
42024 mov @r0,ar2
42025 \end_layout
42026
42027 \begin_layout Standard
42028
42029 \size footnotesize
42030 \InsetSpace ~
42031 \InsetSpace ~
42032 inc r0
42033 \end_layout
42034
42035 \begin_layout Standard
42036
42037 \size footnotesize
42038 \InsetSpace ~
42039 \InsetSpace ~
42040 mov @r0,ar3
42041 \end_layout
42042
42043 \begin_layout Standard
42044
42045 \size footnotesize
42046 ; iTemp6 [lr5:16]{_near * int}[r0] = 
42047 \end_layout
42048
42049 \begin_layout Standard
42050
42051 \size footnotesize
42052 ; iTemp6 [lr5:16]{_near * int}[r0] + 
42053 \end_layout
42054
42055 \begin_layout Standard
42056
42057 \size footnotesize
42058 ; 0x2 {short}
42059 \end_layout
42060
42061 \begin_layout Standard
42062
42063 \size footnotesize
42064 \InsetSpace ~
42065 \InsetSpace ~
42066 inc r0
42067 \end_layout
42068
42069 \begin_layout Standard
42070
42071 \size footnotesize
42072 ; goto _whilecontinue_0($1)
42073 \end_layout
42074
42075 \begin_layout Standard
42076
42077 \size footnotesize
42078 \InsetSpace ~
42079 \InsetSpace ~
42080 sjmp 00101$
42081 \end_layout
42082
42083 \begin_layout Standard
42084
42085 \size footnotesize
42086 ; _whilebreak_0($3) :
42087 \end_layout
42088
42089 \begin_layout Standard
42090
42091 \size footnotesize
42092 00103$:
42093 \end_layout
42094
42095 \begin_layout Standard
42096
42097 \size footnotesize
42098 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
42099 \end_layout
42100
42101 \begin_layout Standard
42102
42103 \size footnotesize
42104 \InsetSpace ~
42105 \InsetSpace ~
42106 mov r2,#0x00
42107 \end_layout
42108
42109 \begin_layout Standard
42110
42111 \size footnotesize
42112 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
42113 \end_layout
42114
42115 \begin_layout Standard
42116
42117 \size footnotesize
42118 \InsetSpace ~
42119 \InsetSpace ~
42120 mov r3,#0x00
42121 \end_layout
42122
42123 \begin_layout Standard
42124
42125 \size footnotesize
42126 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
42127 \end_layout
42128
42129 \begin_layout Standard
42130
42131 \size footnotesize
42132 \InsetSpace ~
42133 \InsetSpace ~
42134 mov r4,#0x00
42135 \end_layout
42136
42137 \begin_layout Standard
42138
42139 \size footnotesize
42140 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
42141 \end_layout
42142
42143 \begin_layout Standard
42144
42145 \size footnotesize
42146 \InsetSpace ~
42147 \InsetSpace ~
42148 mov r5,#0x0A
42149 \end_layout
42150
42151 \begin_layout Standard
42152
42153 \size footnotesize
42154 \InsetSpace ~
42155 \InsetSpace ~
42156 mov r6,#0x00
42157 \end_layout
42158
42159 \begin_layout Standard
42160
42161 \size footnotesize
42162 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
42163 \end_layout
42164
42165 \begin_layout Standard
42166
42167 \size footnotesize
42168 \InsetSpace ~
42169 \InsetSpace ~
42170 mov r7,#0x1E
42171 \end_layout
42172
42173 \begin_layout Standard
42174
42175 \size footnotesize
42176 \InsetSpace ~
42177 \InsetSpace ~
42178 mov r0,#0x00
42179 \end_layout
42180
42181 \begin_layout Standard
42182
42183 \size footnotesize
42184 ; _forcond_0($4) :
42185 \end_layout
42186
42187 \begin_layout Standard
42188
42189 \size footnotesize
42190 00104$:
42191 \end_layout
42192
42193 \begin_layout Standard
42194
42195 \size footnotesize
42196 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
42197 \end_layout
42198
42199 \begin_layout Standard
42200
42201 \size footnotesize
42202 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
42203 \end_layout
42204
42205 \begin_layout Standard
42206
42207 \size footnotesize
42208 \InsetSpace ~
42209 \InsetSpace ~
42210 clr c
42211 \end_layout
42212
42213 \begin_layout Standard
42214
42215 \size footnotesize
42216 \InsetSpace ~
42217 \InsetSpace ~
42218 mov a,r4
42219 \end_layout
42220
42221 \begin_layout Standard
42222
42223 \size footnotesize
42224 \InsetSpace ~
42225 \InsetSpace ~
42226 xrl a,#0x80
42227 \end_layout
42228
42229 \begin_layout Standard
42230
42231 \size footnotesize
42232 \InsetSpace ~
42233 \InsetSpace ~
42234 subb a,#0x8a
42235 \end_layout
42236
42237 \begin_layout Standard
42238
42239 \size footnotesize
42240 \InsetSpace ~
42241 \InsetSpace ~
42242 jnc 00107$
42243 \end_layout
42244
42245 \begin_layout Standard
42246
42247 \size footnotesize
42248 00115$:
42249 \end_layout
42250
42251 \begin_layout Standard
42252
42253 \size footnotesize
42254 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
42255 \end_layout
42256
42257 \begin_layout Standard
42258
42259 \size footnotesize
42260 ; iTemp21 [lr21:38]{short}[r4]
42261 \end_layout
42262
42263 \begin_layout Standard
42264
42265 \size footnotesize
42266 \InsetSpace ~
42267 \InsetSpace ~
42268 mov a,r4
42269 \end_layout
42270
42271 \begin_layout Standard
42272
42273 \size footnotesize
42274 \InsetSpace ~
42275 \InsetSpace ~
42276 add a,r2
42277 \end_layout
42278
42279 \begin_layout Standard
42280
42281 \size footnotesize
42282 \InsetSpace ~
42283 \InsetSpace ~
42284 mov r2,a
42285 \end_layout
42286
42287 \begin_layout Standard
42288
42289 \size footnotesize
42290 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
42291 \end_layout
42292
42293 \begin_layout Standard
42294
42295 \size footnotesize
42296 \InsetSpace ~
42297 \InsetSpace ~
42298 mov b,#0x03
42299 \end_layout
42300
42301 \begin_layout Standard
42302
42303 \size footnotesize
42304 \InsetSpace ~
42305 \InsetSpace ~
42306 mov a,r4
42307 \end_layout
42308
42309 \begin_layout Standard
42310
42311 \size footnotesize
42312 \InsetSpace ~
42313 \InsetSpace ~
42314 mul ab
42315 \end_layout
42316
42317 \begin_layout Standard
42318
42319 \size footnotesize
42320 \InsetSpace ~
42321 \InsetSpace ~
42322 mov r1,a
42323 \end_layout
42324
42325 \begin_layout Standard
42326
42327 \size footnotesize
42328 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
42329 \end_layout
42330
42331 \begin_layout Standard
42332
42333 \size footnotesize
42334 ; iTemp15 [lr29:30]{short}[r1]
42335 \end_layout
42336
42337 \begin_layout Standard
42338
42339 \size footnotesize
42340 \InsetSpace ~
42341 \InsetSpace ~
42342 add a,r3
42343 \end_layout
42344
42345 \begin_layout Standard
42346
42347 \size footnotesize
42348 \InsetSpace ~
42349 \InsetSpace ~
42350 mov r3,a
42351 \end_layout
42352
42353 \begin_layout Standard
42354
42355 \size footnotesize
42356 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
42357 \end_layout
42358
42359 \begin_layout Standard
42360
42361 \size footnotesize
42362 \InsetSpace ~
42363 \InsetSpace ~
42364 mov a,r7
42365 \end_layout
42366
42367 \begin_layout Standard
42368
42369 \size footnotesize
42370 \InsetSpace ~
42371 \InsetSpace ~
42372 add a,#0xfd
42373 \end_layout
42374
42375 \begin_layout Standard
42376
42377 \size footnotesize
42378 \InsetSpace ~
42379 \InsetSpace ~
42380 mov r7,a
42381 \end_layout
42382
42383 \begin_layout Standard
42384
42385 \size footnotesize
42386 \InsetSpace ~
42387 \InsetSpace ~
42388 mov a,r0
42389 \end_layout
42390
42391 \begin_layout Standard
42392
42393 \size footnotesize
42394 \InsetSpace ~
42395 \InsetSpace ~
42396 addc a,#0xff
42397 \end_layout
42398
42399 \begin_layout Standard
42400
42401 \size footnotesize
42402 \InsetSpace ~
42403 \InsetSpace ~
42404 mov r0,a
42405 \end_layout
42406
42407 \begin_layout Standard
42408
42409 \size footnotesize
42410 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
42411 \end_layout
42412
42413 \begin_layout Standard
42414
42415 \size footnotesize
42416 \InsetSpace ~
42417 \InsetSpace ~
42418 mov a,r7
42419 \end_layout
42420
42421 \begin_layout Standard
42422
42423 \size footnotesize
42424 \InsetSpace ~
42425 \InsetSpace ~
42426 add a,_gint
42427 \end_layout
42428
42429 \begin_layout Standard
42430
42431 \size footnotesize
42432 \InsetSpace ~
42433 \InsetSpace ~
42434 mov _gint,a
42435 \end_layout
42436
42437 \begin_layout Standard
42438
42439 \size footnotesize
42440 \InsetSpace ~
42441 \InsetSpace ~
42442 mov a,r0
42443 \end_layout
42444
42445 \begin_layout Standard
42446
42447 \size footnotesize
42448 \InsetSpace ~
42449 \InsetSpace ~
42450 addc a,(_gint + 1)
42451 \end_layout
42452
42453 \begin_layout Standard
42454
42455 \size footnotesize
42456 \InsetSpace ~
42457 \InsetSpace ~
42458 mov (_gint + 1),a
42459 \end_layout
42460
42461 \begin_layout Standard
42462
42463 \size footnotesize
42464 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
42465 \end_layout
42466
42467 \begin_layout Standard
42468
42469 \size footnotesize
42470 \InsetSpace ~
42471 \InsetSpace ~
42472 inc r4
42473 \end_layout
42474
42475 \begin_layout Standard
42476
42477 \size footnotesize
42478 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
42479 \end_layout
42480
42481 \begin_layout Standard
42482
42483 \size footnotesize
42484 \InsetSpace ~
42485 \InsetSpace ~
42486 dec r5
42487 \end_layout
42488
42489 \begin_layout Standard
42490
42491 \size footnotesize
42492 \InsetSpace ~
42493 \InsetSpace ~
42494 cjne r5,#0xff,00104$
42495 \end_layout
42496
42497 \begin_layout Standard
42498
42499 \size footnotesize
42500 \InsetSpace ~
42501 \InsetSpace ~
42502 dec r6
42503 \end_layout
42504
42505 \begin_layout Standard
42506
42507 \size footnotesize
42508 ; goto _forcond_0($4)
42509 \end_layout
42510
42511 \begin_layout Standard
42512
42513 \size footnotesize
42514 \InsetSpace ~
42515 \InsetSpace ~
42516 sjmp 00104$
42517 \end_layout
42518
42519 \begin_layout Standard
42520
42521 \size footnotesize
42522 ; _forbreak_0($7) :
42523 \end_layout
42524
42525 \begin_layout Standard
42526
42527 \size footnotesize
42528 00107$:
42529 \end_layout
42530
42531 \begin_layout Standard
42532
42533 \size footnotesize
42534 ; ret iTemp24 [lr40:41]{short}
42535 \end_layout
42536
42537 \begin_layout Standard
42538
42539 \size footnotesize
42540 \InsetSpace ~
42541 \InsetSpace ~
42542 mov a,r3
42543 \end_layout
42544
42545 \begin_layout Standard
42546
42547 \size footnotesize
42548 \InsetSpace ~
42549 \InsetSpace ~
42550 add a,r2
42551 \end_layout
42552
42553 \begin_layout Standard
42554
42555 \size footnotesize
42556 \InsetSpace ~
42557 \InsetSpace ~
42558 mov dpl,a
42559 \end_layout
42560
42561 \begin_layout Standard
42562
42563 \size footnotesize
42564 ; _return($8) :
42565 \end_layout
42566
42567 \begin_layout Standard
42568
42569 \size footnotesize
42570 00108$:
42571 \end_layout
42572
42573 \begin_layout Standard
42574
42575 \size footnotesize
42576 \InsetSpace ~
42577 \InsetSpace ~
42578 ret
42579 \newline
42580
42581 \end_layout
42582
42583 \begin_layout Section
42584 A few words about basic block successors, predecessors and dominators
42585 \end_layout
42586
42587 \begin_layout Standard
42588 Successors are basic blocks
42589 \begin_inset LatexCommand index
42590 name "Basic blocks"
42591
42592 \end_inset
42593
42594  that might execute after this basic block.
42595 \newline
42596 Predecessors are basic blocks
42597  that might execute before reaching this basic block.
42598 \newline
42599 Dominators are basic
42600  blocks that WILL execute before reaching this basic block.
42601 \newline
42602
42603 \end_layout
42604
42605 \begin_layout Standard
42606 [basic block 1]
42607 \end_layout
42608
42609 \begin_layout Standard
42610 if (something)
42611 \end_layout
42612
42613 \begin_layout Standard
42614 \InsetSpace ~
42615 \InsetSpace ~
42616 \InsetSpace ~
42617 \InsetSpace ~
42618 [basic block 2]
42619 \end_layout
42620
42621 \begin_layout Standard
42622 else
42623 \end_layout
42624
42625 \begin_layout Standard
42626 \InsetSpace ~
42627 \InsetSpace ~
42628 \InsetSpace ~
42629 \InsetSpace ~
42630 [basic block 3]
42631 \end_layout
42632
42633 \begin_layout Standard
42634 [basic block 4]
42635 \newline
42636
42637 \end_layout
42638
42639 \begin_layout Standard
42640 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
42641 \end_layout
42642
42643 \begin_layout Standard
42644 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
42645 \end_layout
42646
42647 \begin_layout Standard
42648 c) domVect of [BB4] = BB1 ...
42649  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
42650  was executed.
42651 \end_layout
42652
42653 \begin_layout Chapter
42654 Acknowledgments
42655 \end_layout
42656
42657 \begin_layout Standard
42658 \begin_inset LatexCommand url
42659 target "http://sdcc.sourceforge.net/#Who"
42660
42661 \end_inset
42662
42663
42664 \newline
42665
42666 \newline
42667
42668 \emph on
42669 Thanks to all the other volunteer developers who have helped with coding,
42670  testing, web-page creation, distribution sets, etc.
42671  You know who you are :-)
42672 \emph default
42673
42674 \newline
42675
42676 \newline
42677
42678 \emph on
42679 Thanks to Sourceforge 
42680 \begin_inset LatexCommand url
42681 target "http://www.sf.net"
42682
42683 \end_inset
42684
42685  which has hosted the project since 1999 and donates significant download
42686  bandwidth.
42687 \emph default
42688
42689 \newline
42690
42691 \newline
42692
42693 \emph on
42694 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
42695  cycles and bandwidth for snapshot builds.
42696 \newline
42697
42698 \end_layout
42699
42700 \begin_layout Standard
42701 This document was initially written by Sandeep Dutta
42702 \end_layout
42703
42704 \begin_layout Standard
42705 All product names mentioned herein may be trademarks
42706 \begin_inset LatexCommand index
42707 name "Trademarks"
42708
42709 \end_inset
42710
42711  of their respective companies.
42712  
42713 \end_layout
42714
42715 \begin_layout Section*
42716 Alphabetical index
42717 \end_layout
42718
42719 \begin_layout Standard
42720 To avoid confusion, the installation and building options for SDCC itself
42721  (chapter 2) are not part of the index.
42722 \end_layout
42723
42724 \begin_layout Standard
42725 \begin_inset LatexCommand printindex
42726
42727 \end_inset
42728
42729
42730 \end_layout
42731
42732 \end_body
42733 \end_document