* device/include/mcs51/p89v66x.h: added ENBOOT thanks Gudjon Gudjonsson <gudjon AT...
[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$
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 GNU Compiler Collection
7771 \begin_inset LatexCommand index
7772 name "gcc (GNU Compiler Collection)"
7773
7774 \end_inset
7775
7776  preprocessor 
7777 \emph on
7778 cpp
7779 \emph default
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 ).
7791  If you need more dedicated options please refer to the GCC\InsetSpace ~
7792 CPP\InsetSpace ~
7793 Manual at
7794  
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
21082 \begin_inset LatexCommand index
21083 name "Floating point support"
21084
21085 \end_inset
21086
21087  (except on ds390), only <NO FLOAT>
21088 \begin_inset LatexCommand index
21089 name "<NO FLOAT>"
21090
21091 \end_inset
21092
21093
21094 \begin_inset LatexCommand index
21095 name "printf floating point support"
21096
21097 \end_inset
21098
21099  will be printed instead of the value.
21100  To enable floating point output, recompile it with the option 
21101 \emph on
21102 -
21103 \begin_inset ERT
21104 status collapsed
21105
21106 \begin_layout Standard
21107
21108
21109 \backslash
21110 /
21111 \end_layout
21112
21113 \end_inset
21114
21115 DUSE_FLOATS=1
21116 \begin_inset LatexCommand index
21117 name "USE\\_FLOATS"
21118
21119 \end_inset
21120
21121
21122 \emph default
21123  on the command line.
21124  Use 
21125 \emph on
21126 -
21127 \begin_inset ERT
21128 status open
21129
21130 \begin_layout Standard
21131
21132
21133 \backslash
21134 /
21135 \end_layout
21136
21137 \end_inset
21138
21139 -model-large
21140 \begin_inset LatexCommand index
21141 name "-\\/-model-large"
21142
21143 \end_inset
21144
21145
21146 \emph default
21147  for the mcs51 port, since this uses a lot of memory.
21148  To enable float support for the pic16 targets, see 
21149 \begin_inset LatexCommand ref
21150 reference "sub:pic16Libraries"
21151
21152 \end_inset
21153
21154 .
21155 \end_layout
21156
21157 \begin_layout Standard
21158 If you're short on code memory you might want to use 
21159 \family typewriter
21160 printf_small()
21161 \begin_inset LatexCommand index
21162 name "printf\\_small()"
21163
21164 \end_inset
21165
21166
21167 \family default
21168  
21169 \emph on
21170 instead
21171 \emph default
21172  of 
21173 \family typewriter
21174 printf().
21175
21176 \family default
21177  For the mcs51 there additionally are assembly versions 
21178 \family typewriter
21179 printf_tiny()
21180 \begin_inset LatexCommand index
21181 name "printf\\_tiny() (mcs51)"
21182
21183 \end_inset
21184
21185
21186 \family default
21187  (subset of printf using less than 270 bytes) and 
21188 \family typewriter
21189 printf_fast()
21190 \begin_inset LatexCommand index
21191 name "printf\\_fast() (mcs51)"
21192
21193 \end_inset
21194
21195
21196 \family default
21197  and 
21198 \family typewriter
21199 printf_fast_f()
21200 \begin_inset LatexCommand index
21201 name "printf\\_fast\\_f() (mcs51)"
21202
21203 \end_inset
21204
21205
21206 \family default
21207  (floating-point aware version of printf_fast) which should fit the requirements
21208  of many embedded systems (printf_fast() can be customized by unsetting
21209  #defines to 
21210 \emph on
21211 not
21212 \emph default
21213  support long variables and field widths).
21214  Be sure to use only one of these printf options within a project.
21215 \newline
21216
21217 \end_layout
21218
21219 \begin_layout Standard
21220 Feature matrix of different 
21221 \emph on
21222 printf
21223 \emph default
21224  options on mcs51.
21225 \end_layout
21226
21227 \begin_layout Standard
21228 \begin_inset Tabular
21229 <lyxtabular version="3" rows="14" columns="7">
21230 <features islongtable="true">
21231 <column alignment="left" valignment="middle" leftline="true" width="14col%">
21232 <column alignment="center" valignment="top" leftline="true" width="0">
21233 <column alignment="center" valignment="top" leftline="true" width="12col%">
21234 <column alignment="center" valignment="top" leftline="true" width="10col%">
21235 <column alignment="center" valignment="top" leftline="true" width="0">
21236 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
21237 <column alignment="center" valignment="top" rightline="true" width="0">
21238 <row topline="true" bottomline="true" endhead="true">
21239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21240 \begin_inset Text
21241
21242 \begin_layout Standard
21243
21244 \series bold
21245 \size large
21246 mcs51
21247 \end_layout
21248
21249 \end_inset
21250 </cell>
21251 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21252 \begin_inset Text
21253
21254 \begin_layout Standard
21255 printf
21256 \begin_inset LatexCommand index
21257 name "printf()"
21258
21259 \end_inset
21260
21261
21262 \end_layout
21263
21264 \end_inset
21265 </cell>
21266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21267 \begin_inset Text
21268
21269 \begin_layout Standard
21270 printf 
21271 \size scriptsize
21272 USE_FLOATS=1
21273 \end_layout
21274
21275 \end_inset
21276 </cell>
21277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21278 \begin_inset Text
21279
21280 \begin_layout Standard
21281 printf_small
21282 \end_layout
21283
21284 \end_inset
21285 </cell>
21286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21287 \begin_inset Text
21288
21289 \begin_layout Standard
21290 printf_fast
21291 \end_layout
21292
21293 \end_inset
21294 </cell>
21295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21296 \begin_inset Text
21297
21298 \begin_layout Standard
21299 printf_fast_f
21300 \end_layout
21301
21302 \end_inset
21303 </cell>
21304 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21305 \begin_inset Text
21306
21307 \begin_layout Standard
21308 printf_tiny
21309 \end_layout
21310
21311 \end_inset
21312 </cell>
21313 </row>
21314 <row topline="true" endhead="true">
21315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21316 \begin_inset Text
21317
21318 \begin_layout Standard
21319 filename
21320 \end_layout
21321
21322 \end_inset
21323 </cell>
21324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21325 \begin_inset Text
21326
21327 \begin_layout Standard
21328
21329 \size scriptsize
21330 printf_large.c
21331 \end_layout
21332
21333 \end_inset
21334 </cell>
21335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21336 \begin_inset Text
21337
21338 \begin_layout Standard
21339
21340 \size scriptsize
21341 printf_large.c
21342 \end_layout
21343
21344 \end_inset
21345 </cell>
21346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21347 \begin_inset Text
21348
21349 \begin_layout Standard
21350
21351 \size scriptsize
21352 printfl.c
21353 \end_layout
21354
21355 \end_inset
21356 </cell>
21357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21358 \begin_inset Text
21359
21360 \begin_layout Standard
21361
21362 \size scriptsize
21363 printf_fast.c
21364 \end_layout
21365
21366 \end_inset
21367 </cell>
21368 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21369 \begin_inset Text
21370
21371 \begin_layout Standard
21372
21373 \size scriptsize
21374 printf_fast_f.c
21375 \end_layout
21376
21377 \end_inset
21378 </cell>
21379 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21380 \begin_inset Text
21381
21382 \begin_layout Standard
21383
21384 \size scriptsize
21385 printf_tiny.c
21386 \end_layout
21387
21388 \end_inset
21389 </cell>
21390 </row>
21391 <row topline="true" endhead="true">
21392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21393 \begin_inset Text
21394
21395 \begin_layout Standard
21396 \begin_inset Quotes sld
21397 \end_inset
21398
21399 Hello World
21400 \begin_inset Quotes srd
21401 \end_inset
21402
21403  size
21404 \end_layout
21405
21406 \begin_layout Standard
21407 small / large
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.7k / 2.4k
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 4.3k / 5.6k
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.2k / 1.8k
21435 \end_layout
21436
21437 \end_inset
21438 </cell>
21439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21440 \begin_inset Text
21441
21442 \begin_layout Standard
21443 1.3k / 1.3k
21444 \end_layout
21445
21446 \end_inset
21447 </cell>
21448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21449 \begin_inset Text
21450
21451 \begin_layout Standard
21452 1.9k / 1.9k
21453 \end_layout
21454
21455 \end_inset
21456 </cell>
21457 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21458 \begin_inset Text
21459
21460 \begin_layout Standard
21461 0.44k / 0.44k
21462 \end_layout
21463
21464 \end_inset
21465 </cell>
21466 </row>
21467 <row topline="true" endhead="true">
21468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21469 \begin_inset Text
21470
21471 \begin_layout Standard
21472 code size
21473 \end_layout
21474
21475 \begin_layout Standard
21476 small / large
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 1.4k / 2.0k
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 2.8k / 3.7k
21495 \end_layout
21496
21497 \end_inset
21498 </cell>
21499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21500 \begin_inset Text
21501
21502 \begin_layout Standard
21503 0.45k / 0.47k (+ _ltoa)
21504 \end_layout
21505
21506 \end_inset
21507 </cell>
21508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21509 \begin_inset Text
21510
21511 \begin_layout Standard
21512 1.2k / 1.2k
21513 \end_layout
21514
21515 \end_inset
21516 </cell>
21517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21518 \begin_inset Text
21519
21520 \begin_layout Standard
21521 1.6k / 1.6k
21522 \end_layout
21523
21524 \end_inset
21525 </cell>
21526 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21527 \begin_inset Text
21528
21529 \begin_layout Standard
21530 0.26k / 0.26k
21531 \end_layout
21532
21533 \end_inset
21534 </cell>
21535 </row>
21536 <row topline="true">
21537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21538 \begin_inset Text
21539
21540 \begin_layout Standard
21541 formats
21542 \end_layout
21543
21544 \end_inset
21545 </cell>
21546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21547 \begin_inset Text
21548
21549 \begin_layout Standard
21550 cdi
21551 \emph on
21552 o
21553 \emph default
21554 psux
21555 \end_layout
21556
21557 \end_inset
21558 </cell>
21559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21560 \begin_inset Text
21561
21562 \begin_layout Standard
21563
21564 \family roman
21565 \series medium
21566 \shape up
21567 \size normal
21568 \emph off
21569 \bar no
21570 \noun off
21571 \color none
21572 cd
21573 \family default
21574 \series default
21575 \shape default
21576 \size default
21577 \emph default
21578 \bar default
21579 \noun default
21580 f
21581 \family roman
21582 \series medium
21583 \shape up
21584 \size normal
21585 \emph off
21586 \bar no
21587 \noun off
21588 i
21589 \family default
21590 \series default
21591 \shape default
21592 \size default
21593 \emph on
21594 \bar default
21595 \noun default
21596 o
21597 \family roman
21598 \series medium
21599 \shape up
21600 \size normal
21601 \emph off
21602 \bar no
21603 \noun off
21604 psux
21605 \end_layout
21606
21607 \end_inset
21608 </cell>
21609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21610 \begin_inset Text
21611
21612 \begin_layout Standard
21613 c
21614 \family roman
21615 \series medium
21616 \shape up
21617 \size normal
21618 \emph off
21619 \bar no
21620 \noun off
21621 \color none
21622 d
21623 \family default
21624 \series default
21625 \shape default
21626 \size default
21627 \emph on
21628 \bar default
21629 \noun default
21630 o
21631 \family roman
21632 \series medium
21633 \shape up
21634 \size normal
21635 \emph off
21636 \bar no
21637 \noun off
21638 s
21639 \family default
21640 \series default
21641 \shape default
21642 \size default
21643 \emph default
21644 \bar default
21645 \noun default
21646 x
21647 \end_layout
21648
21649 \end_inset
21650 </cell>
21651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21652 \begin_inset Text
21653
21654 \begin_layout Standard
21655 cdsux
21656 \end_layout
21657
21658 \end_inset
21659 </cell>
21660 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21661 \begin_inset Text
21662
21663 \begin_layout Standard
21664 cdfsux
21665 \end_layout
21666
21667 \end_inset
21668 </cell>
21669 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21670 \begin_inset Text
21671
21672 \begin_layout Standard
21673 cdsux
21674 \end_layout
21675
21676 \end_inset
21677 </cell>
21678 </row>
21679 <row topline="true">
21680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21681 \begin_inset Text
21682
21683 \begin_layout Standard
21684 long (32 bit) support
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" usebox="none">
21708 \begin_inset Text
21709
21710 \begin_layout Standard
21711 x
21712 \end_layout
21713
21714 \end_inset
21715 </cell>
21716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21717 \begin_inset Text
21718
21719 \begin_layout Standard
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 \family roman
21731 \series medium
21732 \shape up
21733 \size normal
21734 \emph off
21735 \bar no
21736 \noun off
21737 \color none
21738 x
21739 \end_layout
21740
21741 \end_inset
21742 </cell>
21743 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21744 \begin_inset Text
21745
21746 \begin_layout Standard
21747 -
21748 \end_layout
21749
21750 \end_inset
21751 </cell>
21752 </row>
21753 <row topline="true">
21754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21755 \begin_inset Text
21756
21757 \begin_layout Standard
21758 byte arguments on stack
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 b
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 b
21777 \end_layout
21778
21779 \end_inset
21780 </cell>
21781 <cell alignment="center" valignment="top" topline="true" leftline="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" usebox="none">
21791 \begin_inset Text
21792
21793 \begin_layout Standard
21794 -
21795 \end_layout
21796
21797 \end_inset
21798 </cell>
21799 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21800 \begin_inset Text
21801
21802 \begin_layout Standard
21803 -
21804 \end_layout
21805
21806 \end_inset
21807 </cell>
21808 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21809 \begin_inset Text
21810
21811 \begin_layout Standard
21812 -
21813 \end_layout
21814
21815 \end_inset
21816 </cell>
21817 </row>
21818 <row topline="true">
21819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21820 \begin_inset Text
21821
21822 \begin_layout Standard
21823 float format
21824 \begin_inset LatexCommand index
21825 name "Floating point support"
21826
21827 \end_inset
21828
21829
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 %f
21848 \end_layout
21849
21850 \end_inset
21851 </cell>
21852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21853 \begin_inset Text
21854
21855 \begin_layout Standard
21856 -
21857 \end_layout
21858
21859 \end_inset
21860 </cell>
21861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21862 \begin_inset Text
21863
21864 \begin_layout Standard
21865 -
21866 \end_layout
21867
21868 \end_inset
21869 </cell>
21870 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21871 \begin_inset Text
21872
21873 \begin_layout Standard
21874 %f
21875 \begin_inset Foot
21876 status collapsed
21877
21878 \begin_layout Standard
21879 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
21880 \end_layout
21881
21882 \end_inset
21883
21884
21885 \end_layout
21886
21887 \end_inset
21888 </cell>
21889 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21890 \begin_inset Text
21891
21892 \begin_layout Standard
21893 -
21894 \end_layout
21895
21896 \end_inset
21897 </cell>
21898 </row>
21899 <row topline="true">
21900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21901 \begin_inset Text
21902
21903 \begin_layout Standard
21904 float formats %e %g
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" 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" usebox="none">
21937 \begin_inset Text
21938
21939 \begin_layout Standard
21940 -
21941 \end_layout
21942
21943 \end_inset
21944 </cell>
21945 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21946 \begin_inset Text
21947
21948 \begin_layout Standard
21949 -
21950 \end_layout
21951
21952 \end_inset
21953 </cell>
21954 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21955 \begin_inset Text
21956
21957 \begin_layout Standard
21958 -
21959 \end_layout
21960
21961 \end_inset
21962 </cell>
21963 </row>
21964 <row topline="true" bottomline="true">
21965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21966 \begin_inset Text
21967
21968 \begin_layout Standard
21969 field width
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 x
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" usebox="none">
21993 \begin_inset Text
21994
21995 \begin_layout Standard
21996 -
21997 \end_layout
21998
21999 \end_inset
22000 </cell>
22001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22002 \begin_inset Text
22003
22004 \begin_layout Standard
22005 x
22006 \end_layout
22007
22008 \end_inset
22009 </cell>
22010 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22011 \begin_inset Text
22012
22013 \begin_layout Standard
22014 x
22015 \end_layout
22016
22017 \end_inset
22018 </cell>
22019 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22020 \begin_inset Text
22021
22022 \begin_layout Standard
22023 -
22024 \end_layout
22025
22026 \end_inset
22027 </cell>
22028 </row>
22029 <row bottomline="true">
22030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22031 \begin_inset Text
22032
22033 \begin_layout Standard
22034 string speed
22035 \begin_inset Foot
22036 status collapsed
22037
22038 \begin_layout Standard
22039 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
22040 \backslash
22041 r', '
22042 \backslash
22043 n'); standard 8051 @ 22.1184 MHz, empty putchar()
22044 \end_layout
22045
22046 \end_inset
22047
22048 ,
22049 \end_layout
22050
22051 \begin_layout Standard
22052 small / large
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 1.52 / 2.59 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 1.53 / 2.62 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.92 / 0.93 ms
22080 \end_layout
22081
22082 \end_inset
22083 </cell>
22084 <cell alignment="center" valignment="top" topline="true" leftline="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 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22094 \begin_inset Text
22095
22096 \begin_layout Standard
22097 0.46 / 0.46 ms
22098 \end_layout
22099
22100 \end_inset
22101 </cell>
22102 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22103 \begin_inset Text
22104
22105 \begin_layout Standard
22106 0.45 / 0.45 ms
22107 \end_layout
22108
22109 \end_inset
22110 </cell>
22111 </row>
22112 <row bottomline="true">
22113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22114 \begin_inset Text
22115
22116 \begin_layout Standard
22117 int speed
22118 \begin_inset Foot
22119 status collapsed
22120
22121 \begin_layout Standard
22122 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
22123  putchar()
22124 \end_layout
22125
22126 \end_inset
22127
22128 ,
22129 \end_layout
22130
22131 \begin_layout Standard
22132 small / large
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.01 / 3.61 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 3.01 / 3.61 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 3.51 / 18.13 ms
22160 \end_layout
22161
22162 \end_inset
22163 </cell>
22164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22165 \begin_inset Text
22166
22167 \begin_layout Standard
22168 0.22 / 0.22 ms
22169 \end_layout
22170
22171 \end_inset
22172 </cell>
22173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22174 \begin_inset Text
22175
22176 \begin_layout Standard
22177 0.23 / 0.23 ms
22178 \end_layout
22179
22180 \end_inset
22181 </cell>
22182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22183 \begin_inset Text
22184
22185 \begin_layout Standard
22186 0.25 / 0.25 ms
22187 \begin_inset Foot
22188 status collapsed
22189
22190 \begin_layout Standard
22191 printf_tiny integer speed is data dependent, worst case is 0.33 ms
22192 \end_layout
22193
22194 \end_inset
22195
22196
22197 \end_layout
22198
22199 \end_inset
22200 </cell>
22201 </row>
22202 <row bottomline="true">
22203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22204 \begin_inset Text
22205
22206 \begin_layout Standard
22207 long speed
22208 \begin_inset Foot
22209 status collapsed
22210
22211 \begin_layout Standard
22212 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
22213  empty putchar()
22214 \end_layout
22215
22216 \end_inset
22217
22218 ,
22219 \end_layout
22220
22221 \begin_layout Standard
22222 small / large
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 5.37 / 6.31 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 5.37 / 6.31 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 8.71 / 40.65 ms
22250 \end_layout
22251
22252 \end_inset
22253 </cell>
22254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22255 \begin_inset Text
22256
22257 \begin_layout Standard
22258 0.40 / 0.40 ms
22259 \end_layout
22260
22261 \end_inset
22262 </cell>
22263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22264 \begin_inset Text
22265
22266 \begin_layout Standard
22267 0.40 / 0.40 ms
22268 \end_layout
22269
22270 \end_inset
22271 </cell>
22272 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22273 \begin_inset Text
22274
22275 \begin_layout Standard
22276 -
22277 \end_layout
22278
22279 \end_inset
22280 </cell>
22281 </row>
22282 <row bottomline="true">
22283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22284 \begin_inset Text
22285
22286 \begin_layout Standard
22287 float speed
22288 \begin_inset Foot
22289 status collapsed
22290
22291 \begin_layout Standard
22292 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
22293  empty putchar()
22294 \end_layout
22295
22296 \end_inset
22297
22298 ,
22299 \end_layout
22300
22301 \begin_layout Standard
22302 small / large
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 7.49 / 22.47 ms
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 -
22330 \end_layout
22331
22332 \end_inset
22333 </cell>
22334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22335 \begin_inset Text
22336
22337 \begin_layout Standard
22338 -
22339 \end_layout
22340
22341 \end_inset
22342 </cell>
22343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22344 \begin_inset Text
22345
22346 \begin_layout Standard
22347 1.04 / 1.04 ms
22348 \end_layout
22349
22350 \end_inset
22351 </cell>
22352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22353 \begin_inset Text
22354
22355 \begin_layout Standard
22356 -
22357 \end_layout
22358
22359 \end_inset
22360 </cell>
22361 </row>
22362 </lyxtabular>
22363
22364 \end_inset
22365
22366
22367 \end_layout
22368
22369 \begin_layout Subsubsection
22370 <malloc.h>
22371 \begin_inset LatexCommand index
22372 name "malloc.h"
22373
22374 \end_inset
22375
22376
22377 \end_layout
22378
22379 \begin_layout Standard
22380 As of SDCC 2.6.2 you no longer need to call an initialization routine before
22381  using dynamic memory allocation
22382 \begin_inset LatexCommand index
22383 name "dynamic memory allocation (malloc)"
22384
22385 \end_inset
22386
22387  and a default heap
22388 \begin_inset LatexCommand index
22389 name "heap (malloc)"
22390
22391 \end_inset
22392
22393  space of 1024 bytes is provided for malloc to allocate memory from.
22394  If you need a different heap size you need to recompile _heap.c with the
22395  required size defined in HEAP_SIZE.
22396  It is recommended to make a copy of this file into your project directory
22397  and compile it there with:
22398 \end_layout
22399
22400 \begin_layout Verse
22401
22402 \family typewriter
22403 sdcc -c _heap.c -D HEAD_SIZE=2048
22404 \end_layout
22405
22406 \begin_layout Standard
22407 And then link it with:
22408 \end_layout
22409
22410 \begin_layout Verse
22411
22412 \family typewriter
22413 sdcc main.rel _heap.rel
22414 \end_layout
22415
22416 \begin_layout Subsection
22417 Math functions (sinf, powf, sqrtf etc.)
22418 \end_layout
22419
22420 \begin_layout Subsubsection
22421 <math.h>
22422 \end_layout
22423
22424 \begin_layout Standard
22425 See definitions in file <math.h>.
22426 \end_layout
22427
22428 \begin_layout Subsection
22429 Other libraries
22430 \end_layout
22431
22432 \begin_layout Standard
22433 Libraries
22434 \begin_inset LatexCommand index
22435 name "Libraries"
22436
22437 \end_inset
22438
22439  included in SDCC should have a license at least as liberal as the GNU Lesser
22440  General Public License
22441 \begin_inset LatexCommand index
22442 name "GNU Lesser General Public License, LGPL"
22443
22444 \end_inset
22445
22446  
22447 \emph on
22448 LGPL
22449 \emph default
22450 .
22451 \end_layout
22452
22453 \begin_layout Standard
22454 \begin_inset Note Note
22455 status collapsed
22456
22457 \begin_layout Standard
22458 license statements for the libraries are missing.
22459  sdcc/device/lib/ser_ir.c
22460 \end_layout
22461
22462 \begin_layout Standard
22463 or _decdptr f.e.
22464  come with a GPL (as opposed to LGPL) License - this will not be liberal
22465  enough for many embedded programmers.
22466 \end_layout
22467
22468 \end_inset
22469
22470
22471 \end_layout
22472
22473 \begin_layout Standard
22474 If you have ported some library or want to share experience about some code
22475  which f.e.
22476  falls into any of these categories Busses (I
22477 \begin_inset Formula $^{\textrm{2}}$
22478 \end_inset
22479
22480 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
22481  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
22482  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
22483 \begin_inset LatexCommand url
22484 target "http://sourceforge.net/mail/?group_id=599"
22485
22486 \end_inset
22487
22488 \InsetSpace ~
22489 would certainly like to hear about it.
22490 \end_layout
22491
22492 \begin_layout Standard
22493 Programmers coding for embedded systems are not especially famous for being
22494  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
22495 e these references are very valuable.
22496  Let's help to create a climate where information is shared.
22497 \begin_inset VSpace bigskip
22498 \end_inset
22499
22500
22501 \end_layout
22502
22503 \begin_layout Section
22504 Memory Models
22505 \end_layout
22506
22507 \begin_layout Subsection
22508 MCS51 Memory Models
22509 \begin_inset LatexCommand index
22510 name "Memory model"
22511
22512 \end_inset
22513
22514
22515 \begin_inset LatexCommand index
22516 name "MCS51 memory model"
22517
22518 \end_inset
22519
22520
22521 \end_layout
22522
22523 \begin_layout Subsubsection
22524 Small, Medium and Large
22525 \end_layout
22526
22527 \begin_layout Standard
22528 SDCC allows three memory models for MCS51 code, 
22529 \shape slanted
22530 small, medium
22531 \shape default
22532  and 
22533 \shape slanted
22534 large
22535 \shape default
22536 .
22537  Modules compiled with different memory models should 
22538 \emph on
22539 never
22540 \emph default
22541  be combined together or the results would be unpredictable.
22542  The library routines supplied with the compiler are compiled as small,
22543  medium and large.
22544  The compiled library modules are contained in separate directories as small,
22545  medium and large so that you can link to the appropriate set.
22546 \end_layout
22547
22548 \begin_layout Standard
22549 When the medium or large model is used all variables declared without a
22550  storage class will be allocated into the external ram, this includes all
22551  parameters and local variables (for non-reentrant
22552 \begin_inset LatexCommand index
22553 name "reentrant"
22554
22555 \end_inset
22556
22557  functions).
22558  When the small model is used variables without storage class are allocated
22559  in the internal ram.
22560 \end_layout
22561
22562 \begin_layout Standard
22563 Judicious usage of the processor specific storage classes
22564 \begin_inset LatexCommand index
22565 name "Storage class"
22566
22567 \end_inset
22568
22569  and the 'reentrant' function type will yield much more efficient code,
22570  than using the large model.
22571  Several optimizations are disabled when the program is compiled using the
22572  large model, it is therefore recommended that the small model be used unless
22573  absolutely required.
22574 \end_layout
22575
22576 \begin_layout Subsubsection
22577 External Stack
22578 \begin_inset LatexCommand label
22579 name "sub:External-Stack"
22580
22581 \end_inset
22582
22583
22584 \begin_inset LatexCommand index
22585 name "stack"
22586
22587 \end_inset
22588
22589
22590 \begin_inset LatexCommand index
22591 name "External stack (mcs51)"
22592
22593 \end_inset
22594
22595
22596 \end_layout
22597
22598 \begin_layout Standard
22599 The external stack (-
22600 \begin_inset ERT
22601 status collapsed
22602
22603 \begin_layout Standard
22604
22605
22606 \backslash
22607 /
22608 \end_layout
22609
22610 \end_inset
22611
22612 -xstack option
22613 \begin_inset LatexCommand index
22614 name "-\\/-xstack"
22615
22616 \end_inset
22617
22618 ) is located in pdata
22619 \begin_inset LatexCommand index
22620 name "pdata (mcs51, ds390 storage class)"
22621
22622 \end_inset
22623
22624  memory (usually at the start of the external ram segment) and uses all
22625  unused space in pdata (max.
22626  256 bytes).
22627  When -
22628 \begin_inset ERT
22629 status collapsed
22630
22631 \begin_layout Standard
22632
22633
22634 \backslash
22635 /
22636 \end_layout
22637
22638 \end_inset
22639
22640 -xstack option is used to compile the program, the parameters and local
22641  variables
22642 \begin_inset LatexCommand index
22643 name "local variables"
22644
22645 \end_inset
22646
22647  of all reentrant functions are allocated in this area.
22648  This option is provided for programs with large stack space requirements.
22649  When used with the -
22650 \begin_inset ERT
22651 status collapsed
22652
22653 \begin_layout Standard
22654
22655
22656 \backslash
22657 /
22658 \end_layout
22659
22660 \end_inset
22661
22662 -stack-auto
22663 \begin_inset LatexCommand index
22664 name "-\\/-stack-auto"
22665
22666 \end_inset
22667
22668  option, all parameters and local variables are allocated on the external
22669  stack (note: support libraries will need to be recompiled with the same
22670  options.
22671  There is a predefined target in the library makefile).
22672 \end_layout
22673
22674 \begin_layout Standard
22675 The compiler outputs the higher order address byte of the external ram segment
22676  into port P2
22677 \begin_inset LatexCommand index
22678 name "P2 (mcs51 sfr)"
22679
22680 \end_inset
22681
22682  (see also section 
22683 \begin_inset LatexCommand ref
22684 reference "sub:MCS51-variants"
22685
22686 \end_inset
22687
22688 ), therefore when using the External Stack option, this port 
22689 \emph on
22690 may not
22691 \emph default
22692  be used by the application program.
22693 \end_layout
22694
22695 \begin_layout Subsection
22696 DS390 Memory Model
22697 \begin_inset LatexCommand index
22698 name "Memory model"
22699
22700 \end_inset
22701
22702
22703 \begin_inset LatexCommand index
22704 name "DS390 memory model"
22705
22706 \end_inset
22707
22708
22709 \end_layout
22710
22711 \begin_layout Standard
22712 The only model supported is Flat 24
22713 \begin_inset LatexCommand index
22714 name "Flat 24 (DS390 memory model)"
22715
22716 \end_inset
22717
22718 .
22719  This generates code for the 24 bit contiguous addressing mode of the Dallas
22720  DS80C390 part.
22721  In this mode, up to four meg of external RAM or code space can be directly
22722  addressed.
22723  See the data sheets at www.dalsemi.com for further information on this part.
22724 \newline
22725
22726 \newline
22727 Note
22728  that the compiler does not generate any code to place the processor into
22729  24 bitmode (although 
22730 \emph on
22731 tinibios
22732 \emph default
22733  in the ds390 libraries will do that for you).
22734  If you don't use 
22735 \emph on
22736 tinibios
22737 \emph default
22738
22739 \begin_inset LatexCommand index
22740 name "Tinibios (DS390)"
22741
22742 \end_inset
22743
22744 , the boot loader or similar code must ensure that the processor is in 24
22745  bit contiguous addressing mode before calling the SDCC startup code.
22746 \newline
22747
22748 \newline
22749 Like
22750  the 
22751 \emph on
22752 -
22753 \begin_inset ERT
22754 status collapsed
22755
22756 \begin_layout Standard
22757
22758
22759 \backslash
22760 /
22761 \end_layout
22762
22763 \end_inset
22764
22765 -model-large
22766 \emph default
22767  option, variables will by default be placed into the XDATA segment.
22768  
22769 \newline
22770
22771 \newline
22772 Segments may be placed anywhere in the 4 meg address space using the usual
22773  -
22774 \begin_inset ERT
22775 status collapsed
22776
22777 \begin_layout Standard
22778
22779
22780 \backslash
22781 /
22782 \end_layout
22783
22784 \end_inset
22785
22786 -*-loc options.
22787  Note that if any segments are located above 64K, the -r flag must be passed
22788  to the linker to generate the proper segment relocations, and the Intel
22789  HEX output format must be used.
22790  The -r flag can be passed to the linker by using the option 
22791 \emph on
22792 -Wl-r
22793 \emph default
22794  on the SDCC command line.
22795  However, currently the linker can not handle code segments > 64k.
22796 \end_layout
22797
22798 \begin_layout Section
22799 Pragmas
22800 \begin_inset LatexCommand label
22801 name "sec:Pragmas"
22802
22803 \end_inset
22804
22805
22806 \begin_inset LatexCommand index
22807 name "Pragmas"
22808
22809 \end_inset
22810
22811
22812 \end_layout
22813
22814 \begin_layout Standard
22815 Pragmas are used to turn on and/or off certain compiler options.
22816  Some of them are closely related to corresponding command-line options
22817  (see section 
22818 \begin_inset LatexCommand vref
22819 reference "sec:Command-Line-Options"
22820
22821 \end_inset
22822
22823 ).
22824 \newline
22825 Pragmas should be placed before and/or after a function, placing pragmas
22826  inside a function body could have unpredictable results.
22827 \newline
22828
22829 \newline
22830 SDCC supports the
22831  following #pragma directives:
22832 \end_layout
22833
22834 \begin_layout Itemize
22835
22836 \series bold
22837 save
22838 \series default
22839
22840 \begin_inset LatexCommand index
22841 name "\\#pragma save"
22842
22843 \end_inset
22844
22845  - this will save most current options to the save/restore stack.
22846  See #pragma\InsetSpace ~
22847 restore.
22848 \end_layout
22849
22850 \begin_layout Itemize
22851
22852 \series bold
22853 restore
22854 \series default
22855
22856 \begin_inset LatexCommand index
22857 name "\\#pragma restore"
22858
22859 \end_inset
22860
22861  - will restore saved options from the last save.
22862  saves & restores can be nested.
22863  SDCC uses a save/restore stack: save pushes current options to the stack,
22864  restore pulls current options from the stack.
22865  See #pragma\InsetSpace ~
22866 save.
22867 \newline
22868
22869 \end_layout
22870
22871 \begin_layout Itemize
22872
22873 \series bold
22874 callee_saves
22875 \series default
22876
22877 \begin_inset LatexCommand index
22878 name "\\#pragma callee\\_saves"
22879
22880 \end_inset
22881
22882
22883 \begin_inset LatexCommand index
22884 name "function prologue"
22885
22886 \end_inset
22887
22888  function1[,function2[,function3...]] 
22889 \begin_inset LatexCommand label
22890 name "ite:callee_saves-function1[,function2[,function3...]]--"
22891
22892 \end_inset
22893
22894 - The compiler by default uses a caller saves convention for register saving
22895  across function calls, however this can cause unnecessary register pushing
22896  and popping
22897 \begin_inset LatexCommand index
22898 name "push/pop"
22899
22900 \end_inset
22901
22902  when calling small functions from larger functions.
22903  This option can be used to switch off the register saving convention for
22904  the function names specified.
22905  The compiler will not save registers when calling these functions, extra
22906  code need to be manually inserted at the entry and exit for these functions
22907  to save and restore the registers used by these functions, this can SUBSTANTIAL
22908 LY reduce code and improve run time performance of the generated code.
22909  In the future the compiler (with inter procedural analysis) may be able
22910  to determine the appropriate scheme to use for each function call.
22911  If -
22912 \begin_inset ERT
22913 status collapsed
22914
22915 \begin_layout Standard
22916
22917
22918 \backslash
22919 /
22920 \end_layout
22921
22922 \end_inset
22923
22924 -callee-saves command line option is used (see page 
22925 \begin_inset LatexCommand vpageref
22926 reference "lyx:--callee-saves-function1[,function2][,function3]..."
22927
22928 \end_inset
22929
22930 ), the function names specified in #pragma\InsetSpace ~
22931 callee_saves
22932 \begin_inset LatexCommand index
22933 name "\\#pragma callee\\_saves"
22934
22935 \end_inset
22936
22937  is appended to the list of functions specified in the command line.
22938 \end_layout
22939
22940 \begin_layout Itemize
22941
22942 \series bold
22943 exclude
22944 \series default
22945
22946 \begin_inset LatexCommand index
22947 name "\\#pragma exclude"
22948
22949 \end_inset
22950
22951  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
22952  of pairs of push/pop
22953 \begin_inset LatexCommand index
22954 name "push/pop"
22955
22956 \end_inset
22957
22958  instructions in 
22959 \emph on
22960 I
22961 \emph default
22962 nterrupt
22963 \begin_inset LatexCommand index
22964 name "interrupt"
22965
22966 \end_inset
22967
22968  
22969 \emph on
22970 S
22971 \emph default
22972 ervice 
22973 \emph on
22974 R
22975 \emph default
22976 outines.
22977  The directive should be placed immediately before the ISR function definition
22978  and it affects ALL ISR functions following it.
22979  To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
22980 exclude\InsetSpace ~
22981 none
22982 \begin_inset LatexCommand index
22983 name "\\#pragma exclude"
22984
22985 \end_inset
22986
22987 .
22988  See also the related keyword _naked
22989 \begin_inset LatexCommand index
22990 name "\\_naked"
22991
22992 \end_inset
22993
22994
22995 \begin_inset LatexCommand index
22996 name "\\_\\_naked"
22997
22998 \end_inset
22999
23000 .
23001 \end_layout
23002
23003 \begin_layout Itemize
23004
23005 \series bold
23006 less_pedantic
23007 \series default
23008
23009 \begin_inset LatexCommand index
23010 name "pedantic"
23011
23012 \end_inset
23013
23014
23015 \begin_inset LatexCommand index
23016 name "\\#pragma less\\_pedantic"
23017
23018 \end_inset
23019
23020  
23021 \begin_inset LatexCommand label
23022 name "ite:less_pedantic"
23023
23024 \end_inset
23025
23026 - the compiler will not warn you anymore for obvious mistakes, you're on
23027  your own now ;-( .
23028  See also the command line option -
23029 \begin_inset ERT
23030 status collapsed
23031
23032 \begin_layout Standard
23033
23034
23035 \backslash
23036 /
23037 \end_layout
23038
23039 \end_inset
23040
23041 -less-pedantic 
23042 \begin_inset LatexCommand vpageref
23043 reference "lyx:--less-pedantic"
23044
23045 \end_inset
23046
23047 .
23048  
23049 \newline
23050 More specifically, the following warnings will be disabled: 
23051 \shape italic
23052 comparison is always [true/false] due to limited range of data type
23053 \shape default
23054  (94); 
23055 \shape italic
23056 overflow in implicit constant conversion
23057 \shape default
23058  (158); [the (in)famous] 
23059 \shape italic
23060 conditional flow changed by optimizer: so said EVELYN the modified DOG
23061 \shape default
23062  (110); 
23063 \shape italic
23064 function '[function name]' must return value
23065 \shape default
23066  (59).
23067  
23068 \newline
23069 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
23070  level) are disabled, too, namely: 
23071 \shape italic
23072 constant value '[
23073 \begin_inset Note Note
23074 status collapsed
23075
23076 \begin_layout Standard
23077 dunno what comes here - this warning appears to be unused altogether
23078 \end_layout
23079
23080 \end_inset
23081
23082 ]', out of range
23083 \shape default
23084  (81); 
23085 \shape italic
23086 [left/right] shifting more than size of object changed to zero
23087 \shape default
23088  (116); 
23089 \shape italic
23090 unreachable code
23091 \shape default
23092  (126); 
23093 \shape italic
23094 integer overflow in expression
23095 \shape default
23096  (165); 
23097 \shape italic
23098 unmatched #pragma save and #pragma restore
23099 \shape default
23100  (170); 
23101 \shape italic
23102 comparison of 'signed char' with 'unsigned char' requires promotion to int
23103 \shape default
23104  (185); 
23105 \shape italic
23106 ISO C90 does not support flexible array members
23107 \shape default
23108  (187); 
23109 \shape italic
23110 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
23111 nam
23112 e]':\InsetSpace ~
23113 [
23114 \begin_inset Note Note
23115 status collapsed
23116
23117 \begin_layout Standard
23118 appears to be always blank - what was supposed to be here?
23119 \end_layout
23120
23121 \end_inset
23122
23123 ]
23124 \shape default
23125  (114); 
23126 \shape italic
23127 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
23128  complexity [number]
23129 \shape default
23130  (121).
23131 \end_layout
23132
23133 \begin_layout Itemize
23134
23135 \series bold
23136 disable_warning
23137 \series default
23138  <nnnn>
23139 \begin_inset LatexCommand index
23140 name "\\#pragma disable\\_warning"
23141
23142 \end_inset
23143
23144  - the compiler will not warn you anymore about warning number <nnnn>.
23145 \end_layout
23146
23147 \begin_layout Itemize
23148
23149 \series bold
23150 nogcse
23151 \series default
23152
23153 \begin_inset LatexCommand index
23154 name "\\#pragma nogcse"
23155
23156 \end_inset
23157
23158  - will stop global common subexpression elimination.
23159 \end_layout
23160
23161 \begin_layout Itemize
23162
23163 \series bold
23164 noinduction
23165 \series default
23166
23167 \begin_inset LatexCommand index
23168 name "\\#pragma noinduction"
23169
23170 \end_inset
23171
23172  - will stop loop induction optimizations.
23173 \end_layout
23174
23175 \begin_layout Itemize
23176
23177 \series bold
23178 noinvariant
23179 \series default
23180
23181 \begin_inset LatexCommand index
23182 name "\\#pragma noinvariant"
23183
23184 \end_inset
23185
23186  - will not do loop invariant optimizations.
23187  For more details see Loop Invariants in section
23188 \begin_inset LatexCommand ref
23189 reference "sub:Loop-Optimizations"
23190
23191 \end_inset
23192
23193 .
23194 \end_layout
23195
23196 \begin_layout Itemize
23197
23198 \series bold
23199 noiv
23200 \series default
23201
23202 \begin_inset LatexCommand index
23203 name "\\#pragma noiv"
23204
23205 \end_inset
23206
23207  - Do not generate interrupt
23208 \begin_inset LatexCommand index
23209 name "interrupt"
23210
23211 \end_inset
23212
23213  vector table
23214 \begin_inset LatexCommand index
23215 name "interrupt vector table"
23216
23217 \end_inset
23218
23219  entries for all ISR functions defined after the pragma.
23220  This is useful in cases where the interrupt vector table must be defined
23221  manually, or when there is a secondary, manually defined interrupt vector
23222  table (e.g.
23223  for the autovector feature of the Cypress EZ-USB FX2).
23224  More elegantly this can be achieved by omitting the optional interrupt
23225  number after the interrupt keyword, see section 
23226 \begin_inset LatexCommand ref
23227 reference "sub:Interrupt-Service-Routines"
23228
23229 \end_inset
23230
23231 \InsetSpace ~
23232 about interrupts.
23233 \end_layout
23234
23235 \begin_layout Itemize
23236
23237 \series bold
23238 nojtbound
23239 \series default
23240
23241 \begin_inset LatexCommand index
23242 name "\\#pragma nojtbound"
23243
23244 \end_inset
23245
23246  - will not generate code for boundary value checking, when switch statements
23247  are turned into jump-tables (dangerous).
23248  For more details see section 
23249 \begin_inset LatexCommand ref
23250 reference "sub:'switch'-Statements"
23251
23252 \end_inset
23253
23254 .
23255 \end_layout
23256
23257 \begin_layout Itemize
23258
23259 \series bold
23260 noloopreverse
23261 \series default
23262
23263 \begin_inset LatexCommand index
23264 name "\\#pragma noloopreverse"
23265
23266 \end_inset
23267
23268  - Will not do loop reversal optimization
23269 \end_layout
23270
23271 \begin_layout Itemize
23272
23273 \series bold
23274 nooverlay
23275 \series default
23276
23277 \begin_inset LatexCommand index
23278 name "\\#pragma nooverlay"
23279
23280 \end_inset
23281
23282  - the compiler will not overlay the parameters and local variables of a
23283  function.
23284 \end_layout
23285
23286 \begin_layout Itemize
23287
23288 \series bold
23289 stackauto
23290 \series default
23291
23292 \begin_inset LatexCommand index
23293 name "\\#pragma stackauto"
23294
23295 \end_inset
23296
23297 - See option -
23298 \begin_inset ERT
23299 status collapsed
23300
23301 \begin_layout Standard
23302
23303
23304 \backslash
23305 /
23306 \end_layout
23307
23308 \end_inset
23309
23310 -stack-auto
23311 \begin_inset LatexCommand index
23312 name "-\\/-stack-auto"
23313
23314 \end_inset
23315
23316  and section 
23317 \begin_inset LatexCommand ref
23318 reference "sec:Parameters-and-Local-Variables"
23319
23320 \end_inset
23321
23322  Parameters and Local Variables.
23323 \end_layout
23324
23325 \begin_layout Itemize
23326
23327 \series bold
23328 opt_code_speed
23329 \series default
23330  
23331 \begin_inset LatexCommand index
23332 name "\\#pragma opt\\_code\\_speed"
23333
23334 \end_inset
23335
23336 - The compiler will optimize code generation towards fast code, possibly
23337  at the expense of code size.
23338  Currently this has little effect.
23339 \end_layout
23340
23341 \begin_layout Itemize
23342
23343 \series bold
23344 opt_code_size
23345 \series default
23346  
23347 \begin_inset LatexCommand index
23348 name "\\#pragma opt\\_code\\_size"
23349
23350 \end_inset
23351
23352 - The compiler will optimize code generation towards compact code, possibly
23353  at the expense of code speed.
23354  Currently this has little effect.
23355 \end_layout
23356
23357 \begin_layout Itemize
23358
23359 \series bold
23360 opt_code_balanced
23361 \series default
23362  
23363 \begin_inset LatexCommand index
23364 name "\\#pragma opt\\_code\\_balanced"
23365
23366 \end_inset
23367
23368 - The compiler will attempt to generate code that is both compact and fast,
23369  as long as meeting one goal is not a detriment to the other (this is the
23370  default).
23371  
23372 \end_layout
23373
23374 \begin_layout Itemize
23375
23376 \series bold
23377 std_sdcc89
23378 \series default
23379  
23380 \begin_inset LatexCommand index
23381 name "\\#pragma std\\_sdcc89"
23382
23383 \end_inset
23384
23385 - Generally follow the C89 standard, but allow SDCC features that conflict
23386  with the standard (default).
23387 \end_layout
23388
23389 \begin_layout Itemize
23390
23391 \series bold
23392 std_c89
23393 \series default
23394  
23395 \begin_inset LatexCommand index
23396 name "\\#pragma std\\_c89"
23397
23398 \end_inset
23399
23400 - Follow the C89 standard and disable SDCC features that conflict with the
23401  standard.
23402 \end_layout
23403
23404 \begin_layout Itemize
23405
23406 \series bold
23407 std_sdcc99
23408 \series default
23409  
23410 \begin_inset LatexCommand index
23411 name "\\#pragma std\\_sdcc99"
23412
23413 \end_inset
23414
23415 - Generally follow the C99 standard, but allow SDCC features that conflict
23416  with the standard (incomplete support).
23417 \end_layout
23418
23419 \begin_layout Itemize
23420
23421 \series bold
23422 std_c99
23423 \series default
23424  
23425 \begin_inset LatexCommand index
23426 name "\\#pragma std\\_c99"
23427
23428 \end_inset
23429
23430 - Follow the C99 standard and disable SDCC features that conflict with the
23431  standard (incomplete support).
23432 \end_layout
23433
23434 \begin_layout Itemize
23435
23436 \series bold
23437 codeseg
23438 \series default
23439  <name>
23440 \begin_inset LatexCommand index
23441 name "\\#pragma codeseg"
23442
23443 \end_inset
23444
23445 - Use this name (max.
23446  8 characters) for the code segment.
23447  See option -
23448 \begin_inset ERT
23449 status collapsed
23450
23451 \begin_layout Standard
23452
23453
23454 \backslash
23455 /
23456 \end_layout
23457
23458 \end_inset
23459
23460 -codeseg.
23461 \end_layout
23462
23463 \begin_layout Itemize
23464
23465 \series bold
23466 constseg
23467 \series default
23468  <name>
23469 \begin_inset LatexCommand index
23470 name "\\#pragma constseg"
23471
23472 \end_inset
23473
23474 - Use this name (max.
23475  8 characters) for the const segment.
23476  See option -
23477 \begin_inset ERT
23478 status collapsed
23479
23480 \begin_layout Standard
23481
23482
23483 \backslash
23484 /
23485 \end_layout
23486
23487 \end_inset
23488
23489 -constseg.
23490 \end_layout
23491
23492 \begin_layout Standard
23493 The preprocessor SDCPP
23494 \begin_inset LatexCommand index
23495 name "sdcpp (preprocessor)"
23496
23497 \end_inset
23498
23499  supports the following #pragma directives:
23500 \end_layout
23501
23502 \begin_layout Itemize
23503
23504 \series bold
23505 pedantic_parse_number
23506 \series default
23507
23508 \begin_inset LatexCommand index
23509 name "pedantic"
23510
23511 \end_inset
23512
23513
23514 \begin_inset LatexCommand index
23515 name "\\#pragma pedantic\\_parse\\_number"
23516
23517 \end_inset
23518
23519  (+ | -) 
23520 \begin_inset LatexCommand label
23521 name "ite:pedantic_parse_number"
23522
23523 \end_inset
23524
23525 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
23526  properly and the macro LO_B(3) gets expanded.
23527  Default is off.
23528  See also the -
23529 \begin_inset ERT
23530 status collapsed
23531
23532 \begin_layout Standard
23533
23534
23535 \backslash
23536 /
23537 \end_layout
23538
23539 \end_inset
23540
23541 -pedantic-parse-number command line option 
23542 \begin_inset LatexCommand vpageref
23543 reference "lyx:-pedantic-parse-number"
23544
23545 \end_inset
23546
23547 .
23548  
23549 \newline
23550 Below is an example on how to use this pragma.
23551  
23552 \emph on
23553 Note: this functionality is not in conformance with standard!
23554 \end_layout
23555
23556 \begin_layout Verse
23557
23558 \family typewriter
23559 #pragma pedantic_parse_number +
23560 \begin_inset LatexCommand index
23561 name "\\#pragma pedantic\\_parse\\_number"
23562
23563 \end_inset
23564
23565
23566 \newline
23567
23568 \newline
23569 #define LO_B(x) ((x) & 0xff)
23570 \newline
23571
23572 \newline
23573 unsigned char foo(void)
23574 \newline
23575 {
23576 \newline
23577 \InsetSpace ~
23578 \InsetSpace ~
23579 \InsetSpace ~
23580 unsigned char c=0xfe-LO_B(3)
23581 ;
23582 \newline
23583
23584 \newline
23585 \InsetSpace ~
23586 \InsetSpace ~
23587 \InsetSpace ~
23588 return c;
23589 \newline
23590 }
23591 \newline
23592
23593 \end_layout
23594
23595 \begin_layout Itemize
23596
23597 \series bold
23598 preproc_asm
23599 \series default
23600
23601 \begin_inset LatexCommand index
23602 name "\\#pragma preproc\\_asm"
23603
23604 \end_inset
23605
23606  (+ | -) - switch _asm _endasm block preprocessing on / off.
23607  Default is on.
23608  You use this pragma to define multilines of assembly code.
23609  This will prevent the preprocessor from changing the formatting required
23610  by assembly code.
23611  Below is an example on how to use this pragma.
23612 \end_layout
23613
23614 \begin_layout Verse
23615
23616 \family typewriter
23617 #pragma preproc_asm -
23618 \begin_inset LatexCommand index
23619 name "\\#pragma preproc\\_asm"
23620
23621 \end_inset
23622
23623
23624 \newline
23625 #define MYDELAY _asm
23626 \newline
23627 \InsetSpace ~
23628 \InsetSpace ~
23629 \InsetSpace ~
23630 nop ;my assembly comment...
23631 \newline
23632 \InsetSpace ~
23633 \InsetSpace ~
23634 \InsetSpace ~
23635 nop
23636 \newline
23637 \InsetSpace ~
23638 \InsetSpace ~
23639 \InsetSpace ~
23640 nop
23641 \newline
23642 _endasm
23643 \newline
23644 #pragma preproc_asm
23645  +
23646 \newline
23647
23648 \newline
23649 void foo (void) 
23650 \newline
23651
23652 \newline
23653 \InsetSpace ~
23654 \InsetSpace ~
23655 \InsetSpace ~
23656  ...
23657  
23658 \newline
23659 \InsetSpace ~
23660 \InsetSpace ~
23661 \InsetSpace ~
23662  MYDELAY;
23663 \newline
23664 \InsetSpace ~
23665 \InsetSpace ~
23666 \InsetSpace ~
23667  ...
23668  
23669 \newline
23670
23671 \newline
23672
23673 \end_layout
23674
23675 \begin_layout Itemize
23676
23677 \series bold
23678 sdcc_hash
23679 \series default
23680
23681 \begin_inset LatexCommand index
23682 name "\\#pragma sdcc\\_hash"
23683
23684 \end_inset
23685
23686  (+ | -) - Allow "naked" hash in macro definition, for example:
23687 \newline
23688
23689 \family typewriter
23690 #define DIR_LO(x) #(x & 0xff)
23691 \family default
23692
23693 \newline
23694 Default is off.
23695  Below is an example on how to use this pragma.
23696 \end_layout
23697
23698 \begin_layout Verse
23699
23700 \family typewriter
23701 #pragma preproc_asm +
23702 \newline
23703 #pragma sdcc_hash +
23704 \begin_inset LatexCommand index
23705 name "\\#pragma sdcc\\_hash"
23706
23707 \end_inset
23708
23709
23710 \newline
23711
23712 \newline
23713 #define ROMCALL(x) 
23714 \backslash
23715
23716 \newline
23717 \InsetSpace ~
23718 \InsetSpace ~
23719 \InsetSpace ~
23720 mov R6_B3, #(x & 0xff) 
23721 \backslash
23722
23723 \newline
23724 \InsetSpace ~
23725 \InsetSpace ~
23726 \InsetSpace ~
23727 mov R7_B3, #((x >> 8) & 0xff) 
23728 \backslash
23729
23730 \newline
23731 \InsetSpace ~
23732 \InsetSpace ~
23733 \InsetSpace ~
23734 lcall __romcall
23735 \newline
23736
23737 \newline
23738 ...
23739 \newline
23740 _asm
23741 \newline
23742 ROMCALL(72)
23743 \newline
23744 _endasm;
23745 \newline
23746 ...
23747 \newline
23748
23749 \end_layout
23750
23751 \begin_layout Standard
23752 Some of the pragmas are intended to be used to turn-on or off certain optimizati
23753 ons which might cause the compiler to generate extra stack and/or data space
23754  to store compiler generated temporary variables.
23755  This usually happens in large functions.
23756  Pragma directives should be used as shown in the following example, they
23757  are used to control options and optimizations for a given function.
23758  
23759 \end_layout
23760
23761 \begin_layout Verse
23762
23763 \family typewriter
23764 #pragma save
23765 \begin_inset LatexCommand index
23766 name "\\#pragma save"
23767
23768 \end_inset
23769
23770  \InsetSpace ~
23771 \InsetSpace ~
23772 \InsetSpace ~
23773 \InsetSpace ~
23774 \InsetSpace ~
23775 \InsetSpace ~
23776 \InsetSpace ~
23777 /* save the current settings */ 
23778 \newline
23779 #pragma nogcse
23780 \begin_inset LatexCommand index
23781 name "\\#pragma nogcse"
23782
23783 \end_inset
23784
23785  \InsetSpace ~
23786 \InsetSpace ~
23787 \InsetSpace ~
23788 \InsetSpace ~
23789 \InsetSpace ~
23790 /* turnoff global subexpression elimination */ 
23791 \newline
23792 #pragma noinduction
23793 \begin_inset LatexCommand index
23794 name "\\#pragma noinduction"
23795
23796 \end_inset
23797
23798  /* turn off induction optimizations */ 
23799 \newline
23800 int foo () 
23801 \newline
23802
23803 \newline
23804 \InsetSpace ~
23805  \InsetSpace ~
23806  ...
23807  
23808 \newline
23809 \InsetSpace ~
23810  \InsetSpace ~
23811  /* large code */ 
23812 \newline
23813 \InsetSpace ~
23814  \InsetSpace ~
23815  ...
23816  
23817 \newline
23818
23819 \newline
23820 #pragma restore
23821 \begin_inset LatexCommand index
23822 name "\\#pragma restore"
23823
23824 \end_inset
23825
23826  /* turn the optimizations back on */
23827 \end_layout
23828
23829 \begin_layout Standard
23830 The compiler will generate a warning message when extra space is allocated.
23831  It is strongly recommended that the save and restore pragmas be used when
23832  changing options for a function.
23833 \newline
23834
23835 \newline
23836
23837 \newline
23838
23839 \end_layout
23840
23841 \begin_layout Section
23842 Defines Created by the Compiler
23843 \end_layout
23844
23845 \begin_layout Standard
23846 The compiler creates the following #defines
23847 \begin_inset LatexCommand index
23848 name "\\#defines"
23849
23850 \end_inset
23851
23852
23853 \begin_inset LatexCommand index
23854 name "Defines created by the compiler"
23855
23856 \end_inset
23857
23858 :
23859 \newline
23860
23861 \end_layout
23862
23863 \begin_layout Standard
23864 \begin_inset Tabular
23865 <lyxtabular version="3" rows="15" columns="2">
23866 <features>
23867 <column alignment="left" valignment="top" leftline="true" width="3in">
23868 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
23869 <row topline="true" bottomline="true">
23870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23871 \begin_inset Text
23872
23873 \begin_layout Standard
23874
23875 \series bold
23876 #define
23877 \end_layout
23878
23879 \end_inset
23880 </cell>
23881 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23882 \begin_inset Text
23883
23884 \begin_layout Standard
23885
23886 \series bold
23887 Description
23888 \end_layout
23889
23890 \end_inset
23891 </cell>
23892 </row>
23893 <row topline="true">
23894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23895 \begin_inset Text
23896
23897 \begin_layout Standard
23898 SDCC
23899 \begin_inset LatexCommand index
23900 name "SDCC"
23901
23902 \end_inset
23903
23904  
23905 \end_layout
23906
23907 \end_inset
23908 </cell>
23909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23910 \begin_inset Text
23911
23912 \begin_layout Standard
23913 Always defined.
23914  Since version 2.5.6 the version number as an int (ex.
23915  256)
23916 \end_layout
23917
23918 \end_inset
23919 </cell>
23920 </row>
23921 <row topline="true">
23922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23923 \begin_inset Text
23924
23925 \begin_layout Standard
23926 SDCC_mcs51
23927 \begin_inset LatexCommand index
23928 name "SDCC\\_mcs51"
23929
23930 \end_inset
23931
23932  or SDCC_ds390
23933 \begin_inset LatexCommand index
23934 name "SDCC\\_ds390"
23935
23936 \end_inset
23937
23938  or SDCC_z80
23939 \begin_inset LatexCommand index
23940 name "SDCC\\_z80"
23941
23942 \end_inset
23943
23944 , etc.
23945 \end_layout
23946
23947 \end_inset
23948 </cell>
23949 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23950 \begin_inset Text
23951
23952 \begin_layout Standard
23953 depending on the model used (e.g.: -mds390)
23954 \end_layout
23955
23956 \end_inset
23957 </cell>
23958 </row>
23959 <row topline="true">
23960 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23961 \begin_inset Text
23962
23963 \begin_layout Standard
23964 __mcs51
23965 \begin_inset LatexCommand index
23966 name "\\_\\_mcs51"
23967
23968 \end_inset
23969
23970 , __ds390
23971 \begin_inset LatexCommand index
23972 name "\\_\\_ds390"
23973
23974 \end_inset
23975
23976 , __hc08
23977 \begin_inset LatexCommand index
23978 name "\\_\\_hc08"
23979
23980 \end_inset
23981
23982 , __z80
23983 \begin_inset LatexCommand index
23984 name "\\_\\_z80"
23985
23986 \end_inset
23987
23988 , etc
23989 \end_layout
23990
23991 \end_inset
23992 </cell>
23993 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23994 \begin_inset Text
23995
23996 \begin_layout Standard
23997 depending on the model used (e.g.
23998  -mz80)
23999 \end_layout
24000
24001 \end_inset
24002 </cell>
24003 </row>
24004 <row topline="true">
24005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24006 \begin_inset Text
24007
24008 \begin_layout Standard
24009 SDCC_STACK_AUTO
24010 \begin_inset LatexCommand index
24011 name "SDCC\\_STACK\\_AUTO"
24012
24013 \end_inset
24014
24015
24016 \end_layout
24017
24018 \end_inset
24019 </cell>
24020 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24021 \begin_inset Text
24022
24023 \begin_layout Standard
24024 when 
24025 \emph on
24026 -
24027 \begin_inset ERT
24028 status collapsed
24029
24030 \begin_layout Standard
24031
24032
24033 \backslash
24034 /
24035 \end_layout
24036
24037 \end_inset
24038
24039 -stack-auto
24040 \emph default
24041  option is used
24042 \end_layout
24043
24044 \end_inset
24045 </cell>
24046 </row>
24047 <row topline="true">
24048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24049 \begin_inset Text
24050
24051 \begin_layout Standard
24052 SDCC_MODEL_SMALL
24053 \begin_inset LatexCommand index
24054 name "SDCC\\_MODEL\\_SMALL"
24055
24056 \end_inset
24057
24058
24059 \end_layout
24060
24061 \end_inset
24062 </cell>
24063 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24064 \begin_inset Text
24065
24066 \begin_layout Standard
24067 when 
24068 \emph on
24069 -
24070 \begin_inset ERT
24071 status collapsed
24072
24073 \begin_layout Standard
24074
24075
24076 \backslash
24077 /
24078 \end_layout
24079
24080 \end_inset
24081
24082 -model-small
24083 \emph default
24084  is used
24085 \end_layout
24086
24087 \end_inset
24088 </cell>
24089 </row>
24090 <row topline="true">
24091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24092 \begin_inset Text
24093
24094 \begin_layout Standard
24095 SDCC_MODEL_MEDIUM
24096 \begin_inset LatexCommand index
24097 name "SDCC\\_MODEL\\_MEDIUM"
24098
24099 \end_inset
24100
24101
24102 \end_layout
24103
24104 \end_inset
24105 </cell>
24106 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24107 \begin_inset Text
24108
24109 \begin_layout Standard
24110 when 
24111 \emph on
24112 -
24113 \begin_inset ERT
24114 status collapsed
24115
24116 \begin_layout Standard
24117
24118
24119 \backslash
24120 /
24121 \end_layout
24122
24123 \end_inset
24124
24125 -model-medium
24126 \emph default
24127  is used
24128 \end_layout
24129
24130 \end_inset
24131 </cell>
24132 </row>
24133 <row topline="true">
24134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24135 \begin_inset Text
24136
24137 \begin_layout Standard
24138 SDCC_MODEL_LARGE
24139 \begin_inset LatexCommand index
24140 name "SDCC\\_MODEL\\_LARGE"
24141
24142 \end_inset
24143
24144
24145 \end_layout
24146
24147 \end_inset
24148 </cell>
24149 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24150 \begin_inset Text
24151
24152 \begin_layout Standard
24153 when 
24154 \emph on
24155 -
24156 \begin_inset ERT
24157 status collapsed
24158
24159 \begin_layout Standard
24160
24161
24162 \backslash
24163 /
24164 \end_layout
24165
24166 \end_inset
24167
24168 -model-large
24169 \emph default
24170  is used
24171 \end_layout
24172
24173 \end_inset
24174 </cell>
24175 </row>
24176 <row topline="true">
24177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24178 \begin_inset Text
24179
24180 \begin_layout Standard
24181 SDCC_USE_XSTACK
24182 \begin_inset LatexCommand index
24183 name "SDCC\\_USE\\_XSTACK"
24184
24185 \end_inset
24186
24187
24188 \end_layout
24189
24190 \end_inset
24191 </cell>
24192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24193 \begin_inset Text
24194
24195 \begin_layout Standard
24196 when 
24197 \emph on
24198 -
24199 \begin_inset ERT
24200 status collapsed
24201
24202 \begin_layout Standard
24203
24204
24205 \backslash
24206 /
24207 \end_layout
24208
24209 \end_inset
24210
24211 -xstack
24212 \emph default
24213  option is used
24214 \end_layout
24215
24216 \end_inset
24217 </cell>
24218 </row>
24219 <row topline="true">
24220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24221 \begin_inset Text
24222
24223 \begin_layout Standard
24224 SDCC_STACK_TENBIT
24225 \begin_inset LatexCommand index
24226 name "SDCC\\_STACK\\_TENBIT"
24227
24228 \end_inset
24229
24230  
24231 \end_layout
24232
24233 \end_inset
24234 </cell>
24235 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24236 \begin_inset Text
24237
24238 \begin_layout Standard
24239 when 
24240 \emph on
24241 -mds390
24242 \emph default
24243  is used
24244 \end_layout
24245
24246 \end_inset
24247 </cell>
24248 </row>
24249 <row topline="true">
24250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24251 \begin_inset Text
24252
24253 \begin_layout Standard
24254 SDCC_MODEL_FLAT24
24255 \begin_inset LatexCommand index
24256 name "SDCC\\_MODEL\\_FLAT24"
24257
24258 \end_inset
24259
24260
24261 \end_layout
24262
24263 \end_inset
24264 </cell>
24265 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24266 \begin_inset Text
24267
24268 \begin_layout Standard
24269 when 
24270 \emph on
24271 -mds390
24272 \emph default
24273  is used
24274 \end_layout
24275
24276 \end_inset
24277 </cell>
24278 </row>
24279 <row topline="true">
24280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24281 \begin_inset Text
24282
24283 \begin_layout Standard
24284 SDCC_REVISION
24285 \begin_inset LatexCommand index
24286 name "SDCC\\_REVISION"
24287
24288 \end_inset
24289
24290
24291 \end_layout
24292
24293 \end_inset
24294 </cell>
24295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24296 \begin_inset Text
24297
24298 \begin_layout Standard
24299 Always defined.
24300  SDCC svn revision number
24301 \end_layout
24302
24303 \end_inset
24304 </cell>
24305 </row>
24306 <row topline="true">
24307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24308 \begin_inset Text
24309
24310 \begin_layout Standard
24311 SDCC_PARMS_IN_BANK1
24312 \begin_inset LatexCommand index
24313 name "SDCC\\_PARMS\\_IN\\_BANK1"
24314
24315 \end_inset
24316
24317
24318 \end_layout
24319
24320 \end_inset
24321 </cell>
24322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24323 \begin_inset Text
24324
24325 \begin_layout Standard
24326 when 
24327 \emph on
24328 -
24329 \begin_inset ERT
24330 status collapsed
24331
24332 \begin_layout Standard
24333
24334
24335 \backslash
24336 /
24337 \end_layout
24338
24339 \end_inset
24340
24341 -parms-in-bank1
24342 \emph default
24343  is used
24344 \end_layout
24345
24346 \end_inset
24347 </cell>
24348 </row>
24349 <row topline="true">
24350 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24351 \begin_inset Text
24352
24353 \begin_layout Standard
24354 SDCC_FLOAT_REENT
24355 \begin_inset LatexCommand index
24356 name "SDCC\\_MODEL\\_FLAT24"
24357
24358 \end_inset
24359
24360
24361 \end_layout
24362
24363 \end_inset
24364 </cell>
24365 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24366 \begin_inset Text
24367
24368 \begin_layout Standard
24369 when 
24370 \emph on
24371 -
24372 \begin_inset ERT
24373 status collapsed
24374
24375 \begin_layout Standard
24376
24377
24378 \backslash
24379 /
24380 \end_layout
24381
24382 \end_inset
24383
24384 -float-reent
24385 \emph default
24386  is used
24387 \end_layout
24388
24389 \end_inset
24390 </cell>
24391 </row>
24392 <row topline="true" bottomline="true">
24393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24394 \begin_inset Text
24395
24396 \begin_layout Standard
24397 SDCC_INT_LONG_REENT
24398 \begin_inset LatexCommand index
24399 name "SDCC\\_INT\\_LONG\\_REENT"
24400
24401 \end_inset
24402
24403
24404 \end_layout
24405
24406 \end_inset
24407 </cell>
24408 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24409 \begin_inset Text
24410
24411 \begin_layout Standard
24412 when 
24413 \emph on
24414 -
24415 \begin_inset ERT
24416 status collapsed
24417
24418 \begin_layout Standard
24419
24420
24421 \backslash
24422 /
24423 \end_layout
24424
24425 \end_inset
24426
24427 -int-long-reent
24428 \emph default
24429  is used
24430 \end_layout
24431
24432 \end_inset
24433 </cell>
24434 </row>
24435 </lyxtabular>
24436
24437 \end_inset
24438
24439
24440 \end_layout
24441
24442 \begin_layout Chapter
24443 Notes on supported Processors
24444 \end_layout
24445
24446 \begin_layout Section
24447 MCS51 variants
24448 \begin_inset LatexCommand label
24449 name "sub:MCS51-variants"
24450
24451 \end_inset
24452
24453
24454 \begin_inset LatexCommand index
24455 name "MCS51 variants"
24456
24457 \end_inset
24458
24459
24460 \end_layout
24461
24462 \begin_layout Standard
24463 MCS51 processors are available from many vendors and come in many different
24464  flavours.
24465  While they might differ considerably in respect to Special Function Registers
24466  the core MCS51 is usually not modified or is kept compatible.
24467  
24468 \end_layout
24469
24470 \begin_layout Subsection
24471 pdata access by SFR 
24472 \end_layout
24473
24474 \begin_layout Standard
24475 With the upcome of devices with internal xdata and flash memory devices
24476  using port P2
24477 \begin_inset LatexCommand index
24478 name "P2 (mcs51 sfr)"
24479
24480 \end_inset
24481
24482  as dedicated I/O port is becoming more popular.
24483  Switching the high byte for pdata
24484 \begin_inset LatexCommand index
24485 name "pdata (mcs51, ds390 storage class)"
24486
24487 \end_inset
24488
24489  access which was formerly done by port P2 is then achieved by a Special
24490  Function Register
24491 \begin_inset LatexCommand index
24492 name "sfr"
24493
24494 \end_inset
24495
24496 .
24497  In well-established MCS51 tradition the address of this 
24498 \emph on
24499 sfr
24500 \emph default
24501  is where the chip designers decided to put it.
24502  Needless to say that they didn't agree on a common name either.
24503  So that the startup code can correctly initialize xdata variables, you
24504  should define an sfr with the name _XPAGE
24505 \family typewriter
24506
24507 \begin_inset LatexCommand index
24508 name "\\_XPAGE (mcs51)"
24509
24510 \end_inset
24511
24512
24513 \family default
24514  at the appropriate location if the default, port P2, is not used for this.
24515  Some examples are:
24516 \end_layout
24517
24518 \begin_layout Verse
24519
24520 \family typewriter
24521 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
24522  MPAGE */
24523 \end_layout
24524
24525 \begin_layout Verse
24526
24527 \family typewriter
24528 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
24529  a.k.a.
24530  MPAGE */
24531 \end_layout
24532
24533 \begin_layout Verse
24534
24535 \family typewriter
24536 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
24537  XPAGE */
24538 \end_layout
24539
24540 \begin_layout Verse
24541
24542 \family typewriter
24543 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
24544  EMI0CN */
24545 \end_layout
24546
24547 \begin_layout Verse
24548
24549 \family typewriter
24550 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
24551  EMI0CN */
24552 \end_layout
24553
24554 \begin_layout Standard
24555 For more exotic implementations further customizations may be needed.
24556  See section 
24557 \begin_inset LatexCommand ref
24558 reference "sub:Startup-Code"
24559
24560 \end_inset
24561
24562  for other possibilities.
24563 \end_layout
24564
24565 \begin_layout Subsection
24566 Other Features available by SFR
24567 \end_layout
24568
24569 \begin_layout Standard
24570 Some MCS51 variants offer features like Double DPTR
24571 \begin_inset LatexCommand index
24572 name "DPTR"
24573
24574 \end_inset
24575
24576 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
24577  These are currently not used for the MCS51 port.
24578  If you absolutely need them you can fall back to inline assembly or submit
24579  a patch to SDCC.
24580 \end_layout
24581
24582 \begin_layout Subsection
24583 Bankswitching
24584 \end_layout
24585
24586 \begin_layout Standard
24587 Bankswitching
24588 \begin_inset LatexCommand index
24589 name "Bankswitching"
24590
24591 \end_inset
24592
24593  (a.k.a.
24594  code banking
24595 \begin_inset LatexCommand index
24596 name "code banking"
24597
24598 \end_inset
24599
24600 ) is a technique to increase the code space above the 64k limit of the 8051.
24601 \end_layout
24602
24603 \begin_layout Subsubsection
24604 Hardware
24605 \end_layout
24606
24607 \begin_layout Standard
24608 \begin_inset Tabular
24609 <lyxtabular version="3" rows="3" columns="4">
24610 <features>
24611 <column alignment="center" valignment="top" width="0">
24612 <column alignment="center" valignment="top" leftline="true" width="0">
24613 <column alignment="center" valignment="top" leftline="true" width="0">
24614 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24615 <row topline="true" bottomline="true">
24616 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24617 \begin_inset Text
24618
24619 \begin_layout Standard
24620 8000-FFFF
24621 \end_layout
24622
24623 \end_inset
24624 </cell>
24625 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24626 \begin_inset Text
24627
24628 \begin_layout Standard
24629 bank1
24630 \end_layout
24631
24632 \end_inset
24633 </cell>
24634 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24635 \begin_inset Text
24636
24637 \begin_layout Standard
24638 bank2
24639 \end_layout
24640
24641 \end_inset
24642 </cell>
24643 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24644 \begin_inset Text
24645
24646 \begin_layout Standard
24647 bank3
24648 \end_layout
24649
24650 \end_inset
24651 </cell>
24652 </row>
24653 <row topline="true" bottomline="true">
24654 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24655 \begin_inset Text
24656
24657 \begin_layout Standard
24658 0000-7FFF
24659 \end_layout
24660
24661 \end_inset
24662 </cell>
24663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24664 \begin_inset Text
24665
24666 \begin_layout Standard
24667 common
24668 \end_layout
24669
24670 \end_inset
24671 </cell>
24672 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24673 \begin_inset Text
24674
24675 \begin_layout Standard
24676
24677 \end_layout
24678
24679 \end_inset
24680 </cell>
24681 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24682 \begin_inset Text
24683
24684 \begin_layout Standard
24685
24686 \end_layout
24687
24688 \end_inset
24689 </cell>
24690 </row>
24691 <row>
24692 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24693 \begin_inset Text
24694
24695 \begin_layout Standard
24696 SiLabs C8051F120 example
24697 \end_layout
24698
24699 \end_inset
24700 </cell>
24701 <cell multicolumn="2" alignment="center" valignment="top" usebox="none">
24702 \begin_inset Text
24703
24704 \begin_layout Standard
24705
24706 \end_layout
24707
24708 \end_inset
24709 </cell>
24710 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24711 \begin_inset Text
24712
24713 \begin_layout Standard
24714
24715 \end_layout
24716
24717 \end_inset
24718 </cell>
24719 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24720 \begin_inset Text
24721
24722 \begin_layout Standard
24723
24724 \end_layout
24725
24726 \end_inset
24727 </cell>
24728 </row>
24729 </lyxtabular>
24730
24731 \end_inset
24732
24733
24734 \newline
24735
24736 \newline
24737 Usually the hardware uses some sfr (an output port or an internal sfr) to
24738  select a bank and put it in the banked area of the memory map.
24739  The selected bank usually becomes active immediately upon assignment to
24740  this sfr and when running inside a bank it will switch out this code it
24741  is currently running.
24742  Therefor you cannot jump or call directly from one bank to another and
24743  need to use a so-called trampoline in the common area.
24744  For SDCC an example trampoline is in crtbank.asm and you may need to change
24745  it to your 8051 derivative or schematic.
24746  The presented code is written for the C8051F120.
24747 \newline
24748
24749 \newline
24750 When calling a banked function
24751  SDCC will put the LSB of the functions address in register R0, the MSB
24752  in R1 and the bank in R2 and then call this trampoline 
24753 \emph on
24754 __sdcc_banked_call
24755 \emph default
24756 .
24757  The current selected bank is saved on the stack, the new bank is selected
24758  and an indirect jump is made.
24759  When the banked function returns it jumps to 
24760 \emph on
24761 __sdcc_banked_ret
24762 \emph default
24763  which restores the previous bank and returns to the caller.
24764 \end_layout
24765
24766 \begin_layout Subsubsection
24767 Software
24768 \end_layout
24769
24770 \begin_layout Standard
24771 When writing banked software using SDCC you need to use some special keywords
24772  and options.
24773  You also need to take over a bit of work from the linker.
24774 \newline
24775
24776 \newline
24777 To create a function
24778  that can be called from another bank it requires the keyword 
24779 \emph on
24780 banked
24781 \emph default
24782
24783 \begin_inset LatexCommand index
24784 name "banked"
24785
24786 \end_inset
24787
24788 .
24789  The caller must see this in the prototype of the callee and the callee
24790  needs it for a proper return.
24791  Called functions within the same bank as the caller do not need the 
24792 \emph on
24793 banked
24794 \emph default
24795  keyword nor do functions in the common area.
24796  Beware: SDCC does not know or check if functions are in the same bank.
24797  This is your responsibility!
24798 \newline
24799
24800 \newline
24801 Normally all functions you write end up in
24802  the segment CSEG.
24803  If you want a function explicitly to reside in the common area put it in
24804  segment HOME.
24805  This applies for instance to interrupt service routines as they should
24806  not be banked.
24807 \end_layout
24808
24809 \begin_layout Standard
24810 Functions that need to be in a switched bank must be put in a named segment.
24811  The name can be mostly anything up to eight characters (e.g.
24812  BANK1).
24813  To do this you either use -
24814 \begin_inset ERT
24815 status collapsed
24816
24817 \begin_layout Standard
24818
24819
24820 \backslash
24821 /
24822 \end_layout
24823
24824 \end_inset
24825
24826 -codeseg BANK1 (See 
24827 \begin_inset LatexCommand ref
24828 reference "lyx:-codeseg"
24829
24830 \end_inset
24831
24832 ) on the command line when compiling or #pragma codeseg BANK1 (See 
24833 \begin_inset LatexCommand ref
24834 reference "sec:Pragmas"
24835
24836 \end_inset
24837
24838 ) at the top of the C source file.
24839  The segment name always applies to the whole source file and generated
24840  object so functions for different banks need to be defined in different
24841  source files.
24842 \newline
24843
24844 \newline
24845 When linking your objects you need to tell the linker where
24846  to put your segments.
24847  To do this you use the following command line option to SDCC: -Wl-b BANK1=0x180
24848 00 (See 
24849 \begin_inset LatexCommand ref
24850 reference "lyx:-Wl option"
24851
24852 \end_inset
24853
24854 ).
24855  This sets the virtual start address of this segment.
24856  It sets the banknumber to 0x01 and maps the bank to 0x8000 and up.
24857  The linker will not check for overflows, again this is your responsibility.
24858 \end_layout
24859
24860 \begin_layout Standard
24861 \begin_inset VSpace bigskip
24862 \end_inset
24863
24864
24865 \end_layout
24866
24867 \begin_layout Section
24868 DS400 port
24869 \end_layout
24870
24871 \begin_layout Standard
24872 The DS80C400
24873 \begin_inset LatexCommand index
24874 name "DS80C400"
24875
24876 \end_inset
24877
24878
24879 \begin_inset LatexCommand index
24880 name "DS400"
24881
24882 \end_inset
24883
24884  microcontroller has a rich set of peripherals.
24885  In its built-in ROM library it includes functions to access some of the
24886  features, among them is a TCP stack with IP4 and IP6 support.
24887  Library headers (currently in beta status) and other files are provided
24888  at 
24889 \size footnotesize
24890
24891 \begin_inset LatexCommand url
24892 target "ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html"
24893
24894 \end_inset
24895
24896 .
24897  
24898 \begin_inset VSpace bigskip
24899 \end_inset
24900
24901
24902 \end_layout
24903
24904 \begin_layout Section
24905 The Z80 and gbz80 port
24906 \end_layout
24907
24908 \begin_layout Standard
24909 SDCC can target both the Zilog Z80
24910 \begin_inset LatexCommand index
24911 name "Z80"
24912
24913 \end_inset
24914
24915  and the Nintendo Gameboy's Z80-like gbz80
24916 \begin_inset LatexCommand index
24917 name "gbz80 (GameBoy Z80)"
24918
24919 \end_inset
24920
24921 .
24922  The Z80 port is passed through the same 
24923 \emph on
24924 regressions tests
24925 \begin_inset LatexCommand index
24926 name "Regression test"
24927
24928 \end_inset
24929
24930
24931 \emph default
24932  (see section 
24933 \begin_inset LatexCommand ref
24934 reference "sec:Quality-control"
24935
24936 \end_inset
24937
24938 ) as the MCS51 and DS390 ports, so floating point support, support for long
24939  variables and bitfield support is fine.
24940  See mailing lists and forums about interrupt routines.
24941 \end_layout
24942
24943 \begin_layout Standard
24944 As always, the code is the authoritative reference - see z80/ralloc.c and
24945  z80/gen.c.
24946  The stack
24947 \begin_inset LatexCommand index
24948 name "Z80!stack"
24949
24950 \end_inset
24951
24952  frame is similar to that generated by the IAR Z80 compiler.
24953  IX is used as the base pointer, HL and IY are used as a temporary registers,
24954  and BC and DE are available for holding variables.
24955  Return values
24956 \begin_inset LatexCommand index
24957 name "Z80!return value"
24958
24959 \end_inset
24960
24961  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
24962  bytes).
24963  The gbz80 port use the same set of registers for the return values, but
24964  in a different order of significance: E (one byte), DE (two bytes), or
24965  HLDE (four bytes).
24966 \begin_inset VSpace bigskip
24967 \end_inset
24968
24969
24970 \end_layout
24971
24972 \begin_layout Section
24973 The HC08 port
24974 \end_layout
24975
24976 \begin_layout Standard
24977 The port to the Freescale/Motorola HC08
24978 \begin_inset LatexCommand index
24979 name "HC08"
24980
24981 \end_inset
24982
24983  family has been added in October 2003, and is still undergoing some basic
24984  development.
24985  The code generator is complete, but the register allocation is still quite
24986  unoptimized.
24987  Some of the SDCC's standard C library functions have embedded non-HC08
24988  inline assembly and so are not yet usable.
24989 \end_layout
24990
24991 \begin_layout Standard
24992 The HC08 port passes the regression test suite (see section 
24993 \begin_inset LatexCommand ref
24994 reference "sec:Quality-control"
24995
24996 \end_inset
24997
24998 ).
24999 \begin_inset VSpace bigskip
25000 \end_inset
25001
25002
25003 \end_layout
25004
25005 \begin_layout Section
25006 The PIC14
25007 \begin_inset LatexCommand index
25008 name "PIC14"
25009
25010 \end_inset
25011
25012  port
25013 \end_layout
25014
25015 \begin_layout Standard
25016 The PIC14 port adds support for Microchip
25017 \begin_inset LatexCommand index
25018 name "Microchip"
25019
25020 \end_inset
25021
25022
25023 \begin_inset Formula $^{\text{TM}}$
25024 \end_inset
25025
25026  PIC
25027 \begin_inset LatexCommand index
25028 name "PIC14"
25029
25030 \end_inset
25031
25032
25033 \begin_inset Formula $^{\text{TM}}$
25034 \end_inset
25035
25036  MCUs with 14 bit wide instructions.
25037  This port is not yet mature and still lacks many features.
25038  However, it can work for simple code.
25039 \end_layout
25040
25041 \begin_layout Standard
25042 \noindent
25043 Currently supported devices include:
25044 \end_layout
25045
25046 \begin_layout Standard
25047 12F: 629, 635, 675, 683
25048 \end_layout
25049
25050 \begin_layout Standard
25051 16C: 432, 433
25052 \end_layout
25053
25054 \begin_layout Standard
25055 16C: 554, 557, 558
25056 \end_layout
25057
25058 \begin_layout Standard
25059 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
25060 \end_layout
25061
25062 \begin_layout Standard
25063 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
25064  781, 782
25065 \end_layout
25066
25067 \begin_layout Standard
25068 16C: 925, 926
25069 \end_layout
25070
25071 \begin_layout Standard
25072 16CR: 620a, 73, 74, 76, 77
25073 \end_layout
25074
25075 \begin_layout Standard
25076 16F: 616, 627, 627a, 628, 628a, 630, 636, 639, 648, 648a, 676, 684, 685,
25077  687, 688, 689, 690
25078 \end_layout
25079
25080 \begin_layout Standard
25081 16F: 716, 72, 73, 737, 74, 747, 76, 767, 77, 777, 785
25082 \end_layout
25083
25084 \begin_layout Standard
25085 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
25086  877, 877a, 88, 886, 887
25087 \end_layout
25088
25089 \begin_layout Standard
25090 16F: 913, 914, 916, 917, 946
25091 \end_layout
25092
25093 \begin_layout Standard
25094 26HV: 626, 785
25095 \end_layout
25096
25097 \begin_layout Standard
25098 \noindent
25099 An up-to-date list of currently supported devices can be obtained via 
25100 \family typewriter
25101 sdcc -mpic14 -phelp foo.c
25102 \family default
25103  (foo.c must exist...).
25104 \end_layout
25105
25106 \begin_layout Subsection
25107 PIC Code Pages
25108 \begin_inset LatexCommand index
25109 name "code page (pic14)"
25110
25111 \end_inset
25112
25113  and Memory Banks
25114 \begin_inset LatexCommand index
25115 name "Memory bank (pic14)"
25116
25117 \end_inset
25118
25119
25120 \end_layout
25121
25122 \begin_layout Standard
25123 The linker organizes allocation for the code page and RAM banks.
25124  It does not have intimate knowledge of the code flow.
25125  It will put all the code section of a single .asm file into a single code
25126  page.
25127  In order to make use of multiple code pages, separate asm files must be
25128  used.
25129  The compiler assigns all 
25130 \emph on
25131 static
25132 \emph default
25133  functions of a single .c file into the same code page.
25134 \newline
25135
25136 \newline
25137 To get the best results,
25138  follow these guidelines:
25139 \end_layout
25140
25141 \begin_layout Enumerate
25142 Make local functions static, as non static functions require code page selection
25143  overhead.
25144 \newline
25145 Due to the way sdcc handles functions, place called functions prior
25146  to calling functions in the file wherever possible: Otherwise sdcc will
25147  insert unnecessary pagesel directives around the call, believing that the
25148  called function is externally defined.
25149 \end_layout
25150
25151 \begin_layout Enumerate
25152 For devices that have multiple code pages it is more efficient to use the
25153  same number of files as pages: Use up to 4 separate .c files for the 16F877,
25154  but only 2 files for the 16F874.
25155  This way the linker can put the code for each file into different code
25156  pages and there will be less page selection overhead.
25157 \end_layout
25158
25159 \begin_layout Enumerate
25160 And as for any 8 bit micro (especially for PIC14 as they have a very simple
25161  instruction set), use `unsigned char' wherever possible instead of `int'.
25162 \end_layout
25163
25164 \begin_layout Subsection
25165 Adding New Devices to the Port 
25166 \end_layout
25167
25168 \begin_layout Standard
25169 Adding support for a new 14
25170 \begin_inset ERT
25171 status open
25172
25173 \begin_layout Standard
25174
25175
25176 \backslash
25177 ,
25178 \end_layout
25179
25180 \end_inset
25181
25182 bit PIC MCU requires the following steps:
25183 \end_layout
25184
25185 \begin_layout Enumerate
25186 Create a new device description.
25187 \newline
25188 Each device is described in two files: pic16f*.h
25189  and pic16f*.c.
25190  These files primarily define SFRs, structs to access their bits, and symbolic
25191  configuration options.
25192  Both files can be generated from gputils' .inc files using the perl script
25193  
25194 \family typewriter
25195 support/scripts/inc2h.pl
25196 \family default
25197 .
25198  This file also contains further instructions on how to proceed.
25199 \end_layout
25200
25201 \begin_layout Enumerate
25202 Copy the .h file into SDCC's include path and either add the .c file to your
25203  project or copy it to 
25204 \family typewriter
25205 device/lib/pic/libdev
25206 \family default
25207 .
25208  Afterwards, rebuild and install the libraries.
25209 \end_layout
25210
25211 \begin_layout Enumerate
25212 Edit pic14devices.txt in SDCC's include path (
25213 \family typewriter
25214 device/include/pic/
25215 \family default
25216  in the source tree or 
25217 \family typewriter
25218 /usr/local/share/sdcc/include/pic
25219 \family default
25220  after installation).
25221 \newline
25222 You need to add a device specification here to make
25223  the memory layout (code banks, RAM, aliased memory regions, ...) known to
25224  the compiler.
25225  Probably you can copy and modify an existing entry.
25226  The file format is documented at the top of the file.
25227 \end_layout
25228
25229 \begin_layout Subsection
25230 Interrupt Code
25231 \end_layout
25232
25233 \begin_layout Standard
25234 For the interrupt function, use the keyword `__interrupt'
25235 \begin_inset LatexCommand index
25236 name "PIC14!interrupt"
25237
25238 \end_inset
25239
25240  with level number of 0 (PIC14 only has 1 interrupt so this number is only
25241  there to avoid a syntax error - it ought to be fixed).
25242  E.g.:
25243 \end_layout
25244
25245 \begin_layout Verse
25246
25247 \family typewriter
25248 void Intr(void) __interrupt 0
25249 \newline
25250 {
25251 \newline
25252 \InsetSpace ~
25253 \InsetSpace ~
25254 T0IF = 0; /* Clear timer interrupt */
25255 \newline
25256 }
25257 \end_layout
25258
25259 \begin_layout Subsection
25260 Linking and Assembling
25261 \end_layout
25262
25263 \begin_layout Standard
25264 For assembling you can use either GPUTILS'
25265 \begin_inset LatexCommand index
25266 name "gputils (pic tools)"
25267
25268 \end_inset
25269
25270  gpasm.exe or MPLAB's mpasmwin.exe.
25271  GPUTILS are available from 
25272 \begin_inset LatexCommand url
25273 target "http://sourceforge.net/projects/gputils"
25274
25275 \end_inset
25276
25277 .
25278  For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
25279  If you use MPLAB and an interrupt function then the linker script file
25280  vectors section will need to be enlarged to link with mplink.
25281 \newline
25282
25283 \newline
25284 Here is a 
25285 \family typewriter
25286 Makefile
25287 \family default
25288  using GPUTILS:
25289 \end_layout
25290
25291 \begin_layout Verse
25292
25293 \family typewriter
25294 .c.o:
25295 \newline
25296 \InsetSpace ~
25297 \InsetSpace ~
25298 \InsetSpace ~
25299 \InsetSpace ~
25300 \InsetSpace ~
25301 \InsetSpace ~
25302 \InsetSpace ~
25303 \InsetSpace ~
25304 sdcc -V -mpic14 -p16f877 -c $< 
25305 \newline
25306
25307 \newline
25308 $(PRJ).hex: $(OBJS) 
25309 \newline
25310 \InsetSpace ~
25311 \InsetSpace ~
25312 \InsetSpace ~
25313 \InsetSpace ~
25314 \InsetSpace ~
25315 \InsetSpace ~
25316 \InsetSpace ~
25317 \InsetSpace ~
25318 gplink -m -s $(PRJ).lkr
25319  -o $(PRJ).hex $(OBJS) libsdcc.lib
25320 \end_layout
25321
25322 \begin_layout Standard
25323 Here is a 
25324 \family typewriter
25325 Makefile
25326 \family default
25327  using MPLAB:
25328 \end_layout
25329
25330 \begin_layout Verse
25331
25332 \family typewriter
25333 .c.o: 
25334 \newline
25335 \InsetSpace ~
25336 \InsetSpace ~
25337 \InsetSpace ~
25338 \InsetSpace ~
25339 \InsetSpace ~
25340 \InsetSpace ~
25341 \InsetSpace ~
25342 \InsetSpace ~
25343 sdcc -S -V -mpic14 -p16f877 $< 
25344 \newline
25345 \InsetSpace ~
25346 \InsetSpace ~
25347 \InsetSpace ~
25348 \InsetSpace ~
25349 \InsetSpace ~
25350 \InsetSpace ~
25351 \InsetSpace ~
25352 \InsetSpace ~
25353 mpasmwin /q /o $*.asm
25354 \newline
25355
25356 \newline
25357 $(PRJ).hex: $(OBJS)
25358  
25359 \newline
25360 \InsetSpace ~
25361 \InsetSpace ~
25362 \InsetSpace ~
25363 \InsetSpace ~
25364 \InsetSpace ~
25365 \InsetSpace ~
25366 \InsetSpace ~
25367 \InsetSpace ~
25368 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
25369 \end_layout
25370
25371 \begin_layout Standard
25372 Please note that indentations within a 
25373 \family typewriter
25374 Makefile
25375 \family default
25376  have to be done with a tabulator character.
25377 \end_layout
25378
25379 \begin_layout Subsection
25380 Command-Line Options
25381 \end_layout
25382
25383 \begin_layout Standard
25384 Besides the switches common to all SDCC backends, the PIC14 port accepts
25385  the following options (for an updated list see sdcc -
25386 \begin_inset ERT
25387 status collapsed
25388
25389 \begin_layout Standard
25390
25391
25392 \backslash
25393 /
25394 \end_layout
25395
25396 \end_inset
25397
25398 -help):
25399 \end_layout
25400
25401 \begin_layout Description
25402 -
25403 \begin_inset ERT
25404 status collapsed
25405
25406 \begin_layout Standard
25407
25408
25409 \backslash
25410 /
25411 \end_layout
25412
25413 \end_inset
25414
25415 -debug-xtra
25416 \begin_inset LatexCommand index
25417 name "PIC14!Options!-\\/-debug-extra"
25418
25419 \end_inset
25420
25421  emit debug info in assembly output
25422 \end_layout
25423
25424 \begin_layout Description
25425 -
25426 \begin_inset ERT
25427 status collapsed
25428
25429 \begin_layout Standard
25430
25431
25432 \backslash
25433 /
25434 \end_layout
25435
25436 \end_inset
25437
25438 -no-pcode-opt
25439 \begin_inset LatexCommand index
25440 name "PIC14!Options!-\\/-no-pcode-opt"
25441
25442 \end_inset
25443
25444  disable (slightly faulty) optimization on pCode
25445 \end_layout
25446
25447 \begin_layout Description
25448 -
25449 \begin_inset ERT
25450 status collapsed
25451
25452 \begin_layout Standard
25453
25454
25455 \backslash
25456 /
25457 \end_layout
25458
25459 \end_inset
25460
25461 -stack-loc
25462 \begin_inset LatexCommand index
25463 name "PIC14!Options!-\\/-stack-loc"
25464
25465 \end_inset
25466
25467  sets the lowest address of the argument passing stack (defaults to a suitably
25468  large shared databank to reduce BANKSEL overhead)
25469 \end_layout
25470
25471 \begin_layout Description
25472 -
25473 \begin_inset ERT
25474 status collapsed
25475
25476 \begin_layout Standard
25477
25478
25479 \backslash
25480 /
25481 \end_layout
25482
25483 \end_inset
25484
25485 -stack-size
25486 \begin_inset LatexCommand index
25487 name "PIC14!Options!-\\/-stack-size"
25488
25489 \end_inset
25490
25491  sets the size if the argument passing stack (default: 16, minimum: 4)
25492 \end_layout
25493
25494 \begin_layout Subsection
25495 Environment Variables
25496 \end_layout
25497
25498 \begin_layout Standard
25499 The PIC14 port recognizes the following environment variables:
25500 \end_layout
25501
25502 \begin_layout Description
25503 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
25504  register (the ones called r0xNNNN) in a section of its own.
25505  By default (if this variable is unset), sdcc tries to cluster registers
25506  in sections in order to reduce the BANKSEL overhead when accessing them.
25507 \end_layout
25508
25509 \begin_layout Subsection
25510 The Library
25511 \end_layout
25512
25513 \begin_layout Standard
25514 The PIC14 library currently only contains support routines required by the
25515  compiler to implement multiplication, division, and floating point support.
25516  No libc-like replacement is available at the moment, though many of the
25517  common sdcc library sources (in 
25518 \family typewriter
25519 device/lib
25520 \family default
25521 ) should also compile with the PIC14 port.
25522 \end_layout
25523
25524 \begin_layout Subsubsection
25525 error: missing definition for symbol ``__gptrget1''
25526 \end_layout
25527
25528 \begin_layout Standard
25529 The PIC14 port uses library routines to provide more complex operations
25530  like multiplication, division/modulus and (generic) pointer dereferencing.
25531  In order to add these routines to your project, you must link with PIC14's
25532  
25533 \family typewriter
25534 libsdcc.lib
25535 \family default
25536 .
25537  For single source file projects this is done automatically, more complex
25538  projects must add 
25539 \family typewriter
25540 libsdcc.lib
25541 \family default
25542  to the linker's arguments.
25543  Make sure you also add an include path for the library (using the -I switch
25544  to the linker)!
25545 \end_layout
25546
25547 \begin_layout Subsubsection
25548 Processor mismatch in file ``XXX''.
25549 \end_layout
25550
25551 \begin_layout Standard
25552 This warning can usually be ignored due to the very good compatibility amongst
25553  14
25554 \begin_inset ERT
25555 status open
25556
25557 \begin_layout Standard
25558
25559
25560 \backslash
25561 ,
25562 \end_layout
25563
25564 \end_inset
25565
25566 bit PIC
25567 \begin_inset LatexCommand index
25568 name "PIC14"
25569
25570 \end_inset
25571
25572  devices.
25573 \end_layout
25574
25575 \begin_layout Standard
25576 You might also consider recompiling the library for your specific device
25577  by changing the ARCH=p16f877 (default target) entry in 
25578 \family typewriter
25579 device/lib/pic/Makefile.in
25580 \family default
25581  and 
25582 \family typewriter
25583 device/lib/pic/Makefile
25584 \family default
25585  to reflect your device.
25586  This might even improve performance for smaller devices as unnecessary
25587  BANKSELs might be removed.
25588 \end_layout
25589
25590 \begin_layout Subsection
25591 Known Bugs
25592 \end_layout
25593
25594 \begin_layout Subsubsection
25595 Function arguments
25596 \end_layout
25597
25598 \begin_layout Standard
25599 Functions with variable argument lists (like printf) are not yet supported.
25600  Similarly, taking the address of the first argument passed into a function
25601  does not work: It is currently passed in WREG and has no address...
25602 \end_layout
25603
25604 \begin_layout Subsubsection
25605 Regression tests fail
25606 \end_layout
25607
25608 \begin_layout Standard
25609 Though the small subset of regression tests in src/regression passes, SDCC
25610  regression test suite does not, indicating that there are still major bugs
25611  in the port.
25612  However, many smaller projects have successfully used SDCC in the past...
25613 \end_layout
25614
25615 \begin_layout Standard
25616
25617 \size footnotesize
25618
25619 \newpage
25620
25621 \end_layout
25622
25623 \begin_layout Section
25624 The PIC16
25625 \begin_inset LatexCommand index
25626 name "PIC16"
25627
25628 \end_inset
25629
25630  port
25631 \end_layout
25632
25633 \begin_layout Standard
25634 The PIC16 port adds support for Microchip
25635 \begin_inset LatexCommand index
25636 name "Microchip"
25637
25638 \end_inset
25639
25640
25641 \begin_inset Formula $^{\text{TM}}$
25642 \end_inset
25643
25644  PIC
25645 \begin_inset LatexCommand index
25646 name "PIC"
25647
25648 \end_inset
25649
25650
25651 \begin_inset Formula $^{\text{TM}}$
25652 \end_inset
25653
25654  MCUs with 16 bit wide instructions.
25655  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
25656 ; devices supported by the port include:
25657 \end_layout
25658
25659 \begin_layout Standard
25660 18F: 242, 248, 252, 258, 442, 448, 452, 458
25661 \end_layout
25662
25663 \begin_layout Standard
25664 18F: 1220, 1320
25665 \end_layout
25666
25667 \begin_layout Standard
25668 18F: 2220, 2221, 2320, 2321, 2331, 2410, 2420, 2423, 2431, 2450, 2455, 2480,
25669  24j10
25670 \end_layout
25671
25672 \begin_layout Standard
25673 18F: (2510,) 2515, 2520, 2523, 2525, 2550, 2580, 2585, 25j10, 2610, 2620,
25674  2680, 2682, 2685
25675 \end_layout
25676
25677 \begin_layout Standard
25678 18F: 4220, 4221, 4320, 4321, 4331, 4410, 4420, 4423, 4431, 4450, 4455, 4480,
25679  44j10
25680 \end_layout
25681
25682 \begin_layout Standard
25683 18F: 4510, 4515, 4520, 4523, 4525, 4550, 4580, 4585, 45j10, 4610, 4620,
25684  4680, 4682, 4685
25685 \end_layout
25686
25687 \begin_layout Standard
25688 18F: 6520, 6585, 6620, 6680, 66j60, 66j65, 6720, 67j60
25689 \end_layout
25690
25691 \begin_layout Standard
25692 18F: 8520, 8585, 8620, 8680, 86j60, 86j65, 8720, 87j60
25693 \end_layout
25694
25695 \begin_layout Standard
25696 18F: 96j60, 96j65, 97j60
25697 \end_layout
25698
25699 \begin_layout Standard
25700 \noindent
25701 An up-to-date list of supported devices is also available via '
25702 \family typewriter
25703 sdcc -mpic16 -plist
25704 \family default
25705 '.
25706 \end_layout
25707
25708 \begin_layout Subsection
25709 Global Options
25710 \end_layout
25711
25712 \begin_layout Standard
25713 PIC16 port supports the standard command line arguments as supposed, with
25714  the exception of certain cases that will be mentioned in the following
25715  list:
25716 \end_layout
25717
25718 \begin_layout Description
25719 -
25720 \begin_inset ERT
25721 status collapsed
25722
25723 \begin_layout Standard
25724
25725
25726 \backslash
25727 /
25728 \end_layout
25729
25730 \end_inset
25731
25732 -callee-saves
25733 \begin_inset LatexCommand index
25734 name "PIC16!Options!-\\/-callee-saves"
25735
25736 \end_inset
25737
25738  See -
25739 \begin_inset ERT
25740 status collapsed
25741
25742 \begin_layout Standard
25743
25744
25745 \backslash
25746 /
25747 \end_layout
25748
25749 \end_inset
25750
25751 -all-callee-saves
25752 \end_layout
25753
25754 \begin_layout Description
25755 -
25756 \begin_inset ERT
25757 status collapsed
25758
25759 \begin_layout Standard
25760
25761
25762 \backslash
25763 /
25764 \end_layout
25765
25766 \end_inset
25767
25768 -fommit-frame-pointer
25769 \begin_inset LatexCommand index
25770 name "PIC16!Options!-\\/-fommit-frame-pointer"
25771
25772 \end_inset
25773
25774  Frame pointer will be omitted when the function uses no local variables.
25775 \end_layout
25776
25777 \begin_layout Subsection
25778 Port Specific Options
25779 \begin_inset LatexCommand index
25780 name "Options PIC16"
25781
25782 \end_inset
25783
25784
25785 \end_layout
25786
25787 \begin_layout Standard
25788 The port specific options appear after the global options in the sdcc -
25789 \begin_inset ERT
25790 status collapsed
25791
25792 \begin_layout Standard
25793
25794
25795 \backslash
25796 /
25797 \end_layout
25798
25799 \end_inset
25800
25801 -help output.
25802 \end_layout
25803
25804 \begin_layout Subsubsection
25805 Code Generation Options
25806 \end_layout
25807
25808 \begin_layout Standard
25809 These options influence the generated assembler code.
25810 \end_layout
25811
25812 \begin_layout Description
25813 -
25814 \begin_inset ERT
25815 status collapsed
25816
25817 \begin_layout Standard
25818
25819
25820 \backslash
25821 /
25822 \end_layout
25823
25824 \end_inset
25825
25826 -pstack-model=[model] Used in conjunction with the command above.
25827  Defines the stack model to be used, valid stack models are:
25828 \end_layout
25829
25830 \begin_deeper
25831 \begin_layout List
25832 \labelwidthstring 00.00.0000
25833
25834 \emph on
25835 small
25836 \emph default
25837  Selects small stack model.
25838  8 bit stack and frame pointers.
25839  Supports 256 bytes stack size.
25840 \end_layout
25841
25842 \begin_layout List
25843 \labelwidthstring 00.00.0000
25844
25845 \emph on
25846 large
25847 \emph default
25848  Selects large stack model.
25849  16 bit stack and frame pointers.
25850  Supports 65536 bytes stack size.
25851 \end_layout
25852
25853 \end_deeper
25854 \begin_layout Description
25855 -
25856 \begin_inset ERT
25857 status collapsed
25858
25859 \begin_layout Standard
25860
25861
25862 \backslash
25863 /
25864 \end_layout
25865
25866 \end_inset
25867
25868 -pno-banksel Do not generate BANKSEL assembler directives.
25869 \end_layout
25870
25871 \begin_layout Description
25872 -
25873 \begin_inset ERT
25874 status collapsed
25875
25876 \begin_layout Standard
25877
25878
25879 \backslash
25880 /
25881 \end_layout
25882
25883 \end_inset
25884
25885 -extended Enable extended instruction set/literal offset addressing mode.
25886  Use with care!
25887 \end_layout
25888
25889 \begin_layout Subsubsection
25890 Optimization Options
25891 \end_layout
25892
25893 \begin_layout Description
25894 -
25895 \begin_inset ERT
25896 status collapsed
25897
25898 \begin_layout Standard
25899
25900
25901 \backslash
25902 /
25903 \end_layout
25904
25905 \end_inset
25906
25907 -obanksel=n Set optimization level for inserting BANKSELs.
25908 \newline
25909
25910 \end_layout
25911
25912 \begin_deeper
25913 \begin_layout List
25914 \labelwidthstring 00.00.0000
25915 0 no optimization
25916 \end_layout
25917
25918 \begin_layout List
25919 \labelwidthstring 00.00.0000
25920 1 checks previous used register and if it is the same then does not emit
25921  BANKSEL, accounts only for labels.
25922 \end_layout
25923
25924 \begin_layout List
25925 \labelwidthstring 00.00.0000
25926 2 tries to check the location of (even different) symbols and removes BANKSELs
25927  if they are in the same bank.
25928  
25929 \newline
25930
25931 \emph on
25932 Important: There might be problems if the linker script has data sections
25933  across bank borders!
25934 \end_layout
25935
25936 \end_deeper
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 -denable-peeps Force the usage of peepholes.
25952  Use with care.
25953 \end_layout
25954
25955 \begin_layout Description
25956 -
25957 \begin_inset ERT
25958 status collapsed
25959
25960 \begin_layout Standard
25961
25962
25963 \backslash
25964 /
25965 \end_layout
25966
25967 \end_inset
25968
25969 -no-optimize-goto Do not use (conditional) BRA instead of GOTO.
25970 \end_layout
25971
25972 \begin_layout Description
25973 -
25974 \begin_inset ERT
25975 status collapsed
25976
25977 \begin_layout Standard
25978
25979
25980 \backslash
25981 /
25982 \end_layout
25983
25984 \end_inset
25985
25986 -optimize-cmp Try to optimize some compares.
25987 \end_layout
25988
25989 \begin_layout Description
25990 -
25991 \begin_inset ERT
25992 status collapsed
25993
25994 \begin_layout Standard
25995
25996
25997 \backslash
25998 /
25999 \end_layout
26000
26001 \end_inset
26002
26003 -optimize-df Analyze the dataflow of the generated code and improve it.
26004 \end_layout
26005
26006 \begin_layout Subsubsection
26007 Assembling Options
26008 \end_layout
26009
26010 \begin_layout Description
26011 -
26012 \begin_inset ERT
26013 status collapsed
26014
26015 \begin_layout Standard
26016
26017
26018 \backslash
26019 /
26020 \end_layout
26021
26022 \end_inset
26023
26024 -asm= Sets the full path and name of an external assembler to call.
26025 \end_layout
26026
26027 \begin_layout Description
26028 -
26029 \begin_inset ERT
26030 status collapsed
26031
26032 \begin_layout Standard
26033
26034
26035 \backslash
26036 /
26037 \end_layout
26038
26039 \end_inset
26040
26041 -mplab-comp MPLAB
26042 \begin_inset LatexCommand index
26043 name "PIC16!MPLAB"
26044
26045 \end_inset
26046
26047  compatibility option.
26048  Currently only suppresses special gpasm directives.
26049 \end_layout
26050
26051 \begin_layout Subsubsection
26052 Linking Options
26053 \end_layout
26054
26055 \begin_layout Description
26056 -
26057 \begin_inset ERT
26058 status collapsed
26059
26060 \begin_layout Standard
26061
26062
26063 \backslash
26064 /
26065 \end_layout
26066
26067 \end_inset
26068
26069 -link= Sets the full path and name of an external linker to call.
26070 \end_layout
26071
26072 \begin_layout Description
26073 -
26074 \begin_inset ERT
26075 status collapsed
26076
26077 \begin_layout Standard
26078
26079
26080 \backslash
26081 /
26082 \end_layout
26083
26084 \end_inset
26085
26086 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
26087  unitialized data variables with [kword].
26088  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
26089 \end_layout
26090
26091 \begin_layout Description
26092 -
26093 \begin_inset ERT
26094 status collapsed
26095
26096 \begin_layout Standard
26097
26098
26099 \backslash
26100 /
26101 \end_layout
26102
26103 \end_inset
26104
26105 -ivt-loc=n Place the interrupt vector table at address 
26106 \emph on
26107 n
26108 \emph default
26109 .
26110  Useful for bootloaders.
26111 \end_layout
26112
26113 \begin_layout Description
26114 -
26115 \begin_inset ERT
26116 status collapsed
26117
26118 \begin_layout Standard
26119
26120
26121 \backslash
26122 /
26123 \end_layout
26124
26125 \end_inset
26126
26127 -nodefaultlibs Do not link default libraries when linking.
26128 \end_layout
26129
26130 \begin_layout Description
26131 -
26132 \begin_inset ERT
26133 status collapsed
26134
26135 \begin_layout Standard
26136
26137
26138 \backslash
26139 /
26140 \end_layout
26141
26142 \end_inset
26143
26144 -use-crt= Use a custom run-time module instead of the defaults.
26145 \end_layout
26146
26147 \begin_layout Description
26148 -
26149 \begin_inset ERT
26150 status collapsed
26151
26152 \begin_layout Standard
26153
26154
26155 \backslash
26156 /
26157 \end_layout
26158
26159 \end_inset
26160
26161 -no-crt Don't link the default run-time modules
26162 \end_layout
26163
26164 \begin_layout Subsubsection
26165 Debugging Options
26166 \end_layout
26167
26168 \begin_layout Standard
26169 Debugging options enable extra debugging information in the output files.
26170 \end_layout
26171
26172 \begin_layout Description
26173 -
26174 \begin_inset ERT
26175 status collapsed
26176
26177 \begin_layout Standard
26178
26179
26180 \backslash
26181 /
26182 \end_layout
26183
26184 \end_inset
26185
26186 -debug-xtra Similar to -
26187 \begin_inset ERT
26188 status collapsed
26189
26190 \begin_layout Standard
26191
26192
26193 \backslash
26194 /
26195 \end_layout
26196
26197 \end_inset
26198
26199 -debug
26200 \begin_inset LatexCommand index
26201 name "-\\/-debug"
26202
26203 \end_inset
26204
26205 , but dumps more information.
26206 \end_layout
26207
26208 \begin_layout Description
26209 -
26210 \begin_inset ERT
26211 status collapsed
26212
26213 \begin_layout Standard
26214
26215
26216 \backslash
26217 /
26218 \end_layout
26219
26220 \end_inset
26221
26222 -debug-ralloc Force register allocator to dump <source>.d file with debugging
26223  information.
26224  <source> is the name of the file being compiled.
26225 \end_layout
26226
26227 \begin_layout Description
26228 -
26229 \begin_inset ERT
26230 status collapsed
26231
26232 \begin_layout Standard
26233
26234
26235 \backslash
26236 /
26237 \end_layout
26238
26239 \end_inset
26240
26241 -pcode-verbose Enable pcode debugging information in translation.
26242 \end_layout
26243
26244 \begin_layout Description
26245 -
26246 \begin_inset ERT
26247 status collapsed
26248
26249 \begin_layout Standard
26250
26251
26252 \backslash
26253 /
26254 \end_layout
26255
26256 \end_inset
26257
26258 -calltree Dump call tree in .calltree file.
26259 \end_layout
26260
26261 \begin_layout Description
26262 -
26263 \begin_inset ERT
26264 status collapsed
26265
26266 \begin_layout Standard
26267
26268
26269 \backslash
26270 /
26271 \end_layout
26272
26273 \end_inset
26274
26275 -gstack Trace push/pops for stack pointer overflow.
26276 \end_layout
26277
26278 \begin_layout Subsection
26279 Environment Variables
26280 \end_layout
26281
26282 \begin_layout Standard
26283 There is a number of environmental variables that can be used when running
26284  SDCC to enable certain optimizations or force a specific program behaviour.
26285  these variables are primarily for debugging purposes so they can be enabled/dis
26286 abled at will.
26287 \end_layout
26288
26289 \begin_layout Standard
26290 Currently there is only two such variables available:
26291 \end_layout
26292
26293 \begin_layout Description
26294 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
26295  bitfields is optimized by directly loading FSR0 with the address of the
26296  bitfield structure.
26297  Normally SDCC will cast the bitfield structure to a bitfield pointer and
26298  then load FSR0.
26299  This step saves data ram and code space for functions that make heavy use
26300  of bitfields.
26301  (i.e., 80 bytes of code space are saved when compiling malloc.c with this
26302  option).
26303  
26304 \end_layout
26305
26306 \begin_layout Description
26307 NO_REG_OPT Do not perform pCode registers optimization.
26308  This should be used for debugging purposes.
26309  If bugs in the pcode optimizer are found, users can benefit from temporarily
26310  disabling the optimizer until the bug is fixed.
26311 \end_layout
26312
26313 \begin_layout Subsection
26314 Preprocessor Macros
26315 \end_layout
26316
26317 \begin_layout Standard
26318 PIC16
26319 \begin_inset LatexCommand index
26320 name "PIC16"
26321
26322 \end_inset
26323
26324  port defines the following preprocessor macros while translating a source.
26325 \end_layout
26326
26327 \begin_layout Standard
26328 \align center
26329 \begin_inset Tabular
26330 <lyxtabular version="3" rows="6" columns="2">
26331 <features>
26332 <column alignment="center" valignment="top" leftline="true" width="0">
26333 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26334 <row topline="true" bottomline="true">
26335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26336 \begin_inset Text
26337
26338 \begin_layout Standard
26339 Macro
26340 \end_layout
26341
26342 \end_inset
26343 </cell>
26344 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26345 \begin_inset Text
26346
26347 \begin_layout Standard
26348 Description
26349 \end_layout
26350
26351 \end_inset
26352 </cell>
26353 </row>
26354 <row topline="true">
26355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26356 \begin_inset Text
26357
26358 \begin_layout Standard
26359 SDCC_pic16
26360 \end_layout
26361
26362 \end_inset
26363 </cell>
26364 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26365 \begin_inset Text
26366
26367 \begin_layout Standard
26368 Port identification
26369 \end_layout
26370
26371 \end_inset
26372 </cell>
26373 </row>
26374 <row topline="true">
26375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26376 \begin_inset Text
26377
26378 \begin_layout Standard
26379 _
26380 \begin_inset ERT
26381 status collapsed
26382
26383 \begin_layout Standard
26384
26385
26386 \backslash
26387 /
26388 \end_layout
26389
26390 \end_inset
26391
26392 _pic16
26393 \end_layout
26394
26395 \end_inset
26396 </cell>
26397 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26398 \begin_inset Text
26399
26400 \begin_layout Standard
26401 Port identification (same as above)
26402 \end_layout
26403
26404 \end_inset
26405 </cell>
26406 </row>
26407 <row topline="true">
26408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26409 \begin_inset Text
26410
26411 \begin_layout Standard
26412 pic18fxxxx
26413 \end_layout
26414
26415 \end_inset
26416 </cell>
26417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26418 \begin_inset Text
26419
26420 \begin_layout Standard
26421 MCU Identification.
26422  
26423 \emph on
26424 xxxx
26425 \emph default
26426  is the microcontrol identification number, i.e.
26427  452, 6620, etc
26428 \end_layout
26429
26430 \end_inset
26431 </cell>
26432 </row>
26433 <row topline="true">
26434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26435 \begin_inset Text
26436
26437 \begin_layout Standard
26438 _
26439 \begin_inset ERT
26440 status collapsed
26441
26442 \begin_layout Standard
26443
26444
26445 \backslash
26446 /
26447 \end_layout
26448
26449 \end_inset
26450
26451 _18Fxxxx
26452 \end_layout
26453
26454 \end_inset
26455 </cell>
26456 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26457 \begin_inset Text
26458
26459 \begin_layout Standard
26460 MCU Identification (same as above)
26461 \end_layout
26462
26463 \end_inset
26464 </cell>
26465 </row>
26466 <row topline="true" bottomline="true">
26467 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26468 \begin_inset Text
26469
26470 \begin_layout Standard
26471 STACK_MODEL_nnn
26472 \end_layout
26473
26474 \end_inset
26475 </cell>
26476 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26477 \begin_inset Text
26478
26479 \begin_layout Standard
26480 nnn = SMALL or LARGE respectively according to the stack model used
26481 \end_layout
26482
26483 \end_inset
26484 </cell>
26485 </row>
26486 </lyxtabular>
26487
26488 \end_inset
26489
26490
26491 \end_layout
26492
26493 \begin_layout Standard
26494 \noindent
26495 In addition the following macros are defined when calling assembler:
26496 \end_layout
26497
26498 \begin_layout Standard
26499 \align center
26500 \begin_inset Tabular
26501 <lyxtabular version="3" rows="4" columns="2">
26502 <features>
26503 <column alignment="center" valignment="top" leftline="true" width="0">
26504 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26505 <row topline="true" bottomline="true">
26506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26507 \begin_inset Text
26508
26509 \begin_layout Standard
26510 Macro
26511 \end_layout
26512
26513 \end_inset
26514 </cell>
26515 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26516 \begin_inset Text
26517
26518 \begin_layout Standard
26519 Description
26520 \end_layout
26521
26522 \end_inset
26523 </cell>
26524 </row>
26525 <row topline="true">
26526 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26527 \begin_inset Text
26528
26529 \begin_layout Standard
26530 __18Fxxxx
26531 \end_layout
26532
26533 \end_inset
26534 </cell>
26535 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26536 \begin_inset Text
26537
26538 \begin_layout Standard
26539 MCU Identification.
26540  
26541 \emph on
26542 xxxx
26543 \emph default
26544  is the microcontrol identification number, i.e.
26545  452, 6620, etc
26546 \end_layout
26547
26548 \end_inset
26549 </cell>
26550 </row>
26551 <row topline="true">
26552 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26553 \begin_inset Text
26554
26555 \begin_layout Standard
26556 SDCC_MODEL_nnn
26557 \end_layout
26558
26559 \end_inset
26560 </cell>
26561 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26562 \begin_inset Text
26563
26564 \begin_layout Standard
26565 nnn = SMALL or LARGE respectively according to the memory model used for
26566  SDCC
26567 \end_layout
26568
26569 \end_inset
26570 </cell>
26571 </row>
26572 <row topline="true" bottomline="true">
26573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26574 \begin_inset Text
26575
26576 \begin_layout Standard
26577 STACK_MODEL_nnn
26578 \end_layout
26579
26580 \end_inset
26581 </cell>
26582 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26583 \begin_inset Text
26584
26585 \begin_layout Standard
26586 nnn = SMALL or LARGE respectively according to the stack model used
26587 \end_layout
26588
26589 \end_inset
26590 </cell>
26591 </row>
26592 </lyxtabular>
26593
26594 \end_inset
26595
26596
26597 \end_layout
26598
26599 \begin_layout Subsection
26600 Directories
26601 \end_layout
26602
26603 \begin_layout Standard
26604 PIC16
26605 \begin_inset LatexCommand index
26606 name "PIC16"
26607
26608 \end_inset
26609
26610  port uses the following directories for searching header files and libraries.
26611 \end_layout
26612
26613 \begin_layout Standard
26614 \align center
26615 \begin_inset Tabular
26616 <lyxtabular version="3" rows="3" columns="4">
26617 <features>
26618 <column alignment="center" valignment="top" leftline="true" width="0">
26619 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26620 <column alignment="center" valignment="top" width="0">
26621 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26622 <row topline="true" bottomline="true">
26623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26624 \begin_inset Text
26625
26626 \begin_layout Standard
26627 Directory
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 Description
26637 \end_layout
26638
26639 \end_inset
26640 </cell>
26641 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26642 \begin_inset Text
26643
26644 \begin_layout Standard
26645 Target
26646 \end_layout
26647
26648 \end_inset
26649 </cell>
26650 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26651 \begin_inset Text
26652
26653 \begin_layout Standard
26654 Command prefix
26655 \end_layout
26656
26657 \end_inset
26658 </cell>
26659 </row>
26660 <row topline="true">
26661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26662 \begin_inset Text
26663
26664 \begin_layout Standard
26665 PREFIX/sdcc/include/pic16
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 PIC16 specific headers
26675 \end_layout
26676
26677 \end_inset
26678 </cell>
26679 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26680 \begin_inset Text
26681
26682 \begin_layout Standard
26683 Compiler
26684 \end_layout
26685
26686 \end_inset
26687 </cell>
26688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26689 \begin_inset Text
26690
26691 \begin_layout Standard
26692 -I
26693 \end_layout
26694
26695 \end_inset
26696 </cell>
26697 </row>
26698 <row topline="true" bottomline="true">
26699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26700 \begin_inset Text
26701
26702 \begin_layout Standard
26703 PREFIX/sdcc/lib/pic16
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 PIC16 specific libraries
26713 \end_layout
26714
26715 \end_inset
26716 </cell>
26717 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26718 \begin_inset Text
26719
26720 \begin_layout Standard
26721 Linker
26722 \end_layout
26723
26724 \end_inset
26725 </cell>
26726 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26727 \begin_inset Text
26728
26729 \begin_layout Standard
26730 -L
26731 \end_layout
26732
26733 \end_inset
26734 </cell>
26735 </row>
26736 </lyxtabular>
26737
26738 \end_inset
26739
26740
26741 \end_layout
26742
26743 \begin_layout Subsection
26744 Pragmas
26745 \begin_inset LatexCommand label
26746 name "sub:PIC16_Pragmas"
26747
26748 \end_inset
26749
26750
26751 \end_layout
26752
26753 \begin_layout Standard
26754 The PIC16
26755 \begin_inset LatexCommand index
26756 name "PIC16"
26757
26758 \end_inset
26759
26760  port currently supports the following pragmas:
26761 \end_layout
26762
26763 \begin_layout Description
26764 stack
26765 \begin_inset LatexCommand index
26766 name "PIC16!Pragmas!\\#pragma stack"
26767
26768 \end_inset
26769
26770  This forces the code generator to initialize the stack & frame pointers
26771  at a specific address.
26772  This is an ad hoc solution for cases where no STACK directive is available
26773  in the linker script or gplink is not instructed to create a stack section.
26774 \newline
26775 The
26776  stack pragma should be used only once in a project.
26777  Multiple pragmas may result in indeterminate behaviour of the program.
26778 \begin_inset Foot
26779 status open
26780
26781 \begin_layout Standard
26782 The old format (ie.
26783  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
26784  cross page boundaries (or even exceed the available data RAM) and crash
26785  the program.
26786  Make sure that stack does not cross page boundaries when using the SMALL
26787  stack model.
26788 \end_layout
26789
26790 \end_inset
26791
26792
26793 \newline
26794 The format is as follows:
26795 \newline
26796
26797 \end_layout
26798
26799 \begin_layout LyX-Code
26800 #pragma stack bottom_address [stack_size]
26801 \newline
26802
26803 \end_layout
26804
26805 \begin_layout Standard
26806
26807 \emph on
26808 bottom_address
26809 \emph default
26810  is the lower bound of the stack section.
26811  The stack pointer initially will point at address (bottom_address+stack_size-1).
26812 \end_layout
26813
26814 \begin_layout LyX-Code
26815 Example:
26816 \end_layout
26817
26818 \begin_layout LyX-Code
26819
26820 \end_layout
26821
26822 \begin_layout LyX-Code
26823 /* initializes stack of 100 bytes at RAM address 0x200 */
26824 \end_layout
26825
26826 \begin_layout LyX-Code
26827 #pragma stack 0x200 100
26828 \end_layout
26829
26830 \begin_layout Standard
26831 If the stack_size field is omitted then a stack is created with the default
26832  size of 64.
26833  This size might be enough for most programs, but its not enough for operations
26834  with deep function nesting or excessive stack usage.
26835 \end_layout
26836
26837 \begin_layout Description
26838 code
26839 \begin_inset LatexCommand index
26840 name "PIC16!Pragmas!\\#pragma code"
26841
26842 \end_inset
26843
26844  Force a function to a static FLASH address.
26845 \end_layout
26846
26847 \begin_layout LyX-Code
26848 Example:
26849 \end_layout
26850
26851 \begin_layout LyX-Code
26852
26853 \end_layout
26854
26855 \begin_layout LyX-Code
26856 /* place function test_func at 0x4000 */
26857 \end_layout
26858
26859 \begin_layout LyX-Code
26860 #pragma code test_func 0x4000
26861 \end_layout
26862
26863 \begin_layout LyX-Code
26864
26865 \end_layout
26866
26867 \begin_layout Description
26868 library instructs the linker to use a library module.
26869 \newline
26870 Usage:
26871 \end_layout
26872
26873 \begin_layout LyX-Code
26874 #pragma library module_name
26875 \end_layout
26876
26877 \begin_layout Standard
26878
26879 \emph on
26880 module_name
26881 \emph default
26882  can be any library or object file (including its path).
26883  Note that there are four reserved keywords which have special meaning.
26884  These are:
26885 \end_layout
26886
26887 \begin_layout Standard
26888 \align center
26889 \begin_inset Tabular
26890 <lyxtabular version="3" rows="6" columns="3">
26891 <features>
26892 <column alignment="center" valignment="top" leftline="true" width="0">
26893 <column alignment="block" valignment="top" leftline="true" width="20page%">
26894 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
26895 <row topline="true" bottomline="true">
26896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26897 \begin_inset Text
26898
26899 \begin_layout Standard
26900 Keyword
26901 \end_layout
26902
26903 \end_inset
26904 </cell>
26905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26906 \begin_inset Text
26907
26908 \begin_layout Standard
26909 Description
26910 \end_layout
26911
26912 \end_inset
26913 </cell>
26914 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26915 \begin_inset Text
26916
26917 \begin_layout Standard
26918 Module to link
26919 \end_layout
26920
26921 \end_inset
26922 </cell>
26923 </row>
26924 <row topline="true">
26925 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26926 \begin_inset Text
26927
26928 \begin_layout Standard
26929
26930 \series bold
26931 ignore
26932 \end_layout
26933
26934 \end_inset
26935 </cell>
26936 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26937 \begin_inset Text
26938
26939 \begin_layout Standard
26940 ignore all library pragmas
26941 \end_layout
26942
26943 \end_inset
26944 </cell>
26945 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26946 \begin_inset Text
26947
26948 \begin_layout Standard
26949
26950 \emph on
26951 (none)
26952 \end_layout
26953
26954 \end_inset
26955 </cell>
26956 </row>
26957 <row topline="true">
26958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26959 \begin_inset Text
26960
26961 \begin_layout Standard
26962
26963 \series bold
26964 c
26965 \end_layout
26966
26967 \end_inset
26968 </cell>
26969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26970 \begin_inset Text
26971
26972 \begin_layout Standard
26973 link the C library
26974 \end_layout
26975
26976 \end_inset
26977 </cell>
26978 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26979 \begin_inset Text
26980
26981 \begin_layout Standard
26982
26983 \emph on
26984 libc18f
26985 \emph default
26986 .lib
26987 \end_layout
26988
26989 \end_inset
26990 </cell>
26991 </row>
26992 <row topline="true">
26993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26994 \begin_inset Text
26995
26996 \begin_layout Standard
26997
26998 \series bold
26999 math
27000 \end_layout
27001
27002 \end_inset
27003 </cell>
27004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27005 \begin_inset Text
27006
27007 \begin_layout Standard
27008 link the Math libarary
27009 \end_layout
27010
27011 \end_inset
27012 </cell>
27013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27014 \begin_inset Text
27015
27016 \begin_layout Standard
27017
27018 \emph on
27019 libm18f
27020 \emph default
27021 .lib
27022 \end_layout
27023
27024 \end_inset
27025 </cell>
27026 </row>
27027 <row topline="true">
27028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27029 \begin_inset Text
27030
27031 \begin_layout Standard
27032
27033 \series bold
27034 io
27035 \end_layout
27036
27037 \end_inset
27038 </cell>
27039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27040 \begin_inset Text
27041
27042 \begin_layout Standard
27043 link the I/O library
27044 \end_layout
27045
27046 \end_inset
27047 </cell>
27048 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27049 \begin_inset Text
27050
27051 \begin_layout Standard
27052
27053 \emph on
27054 libio18f*
27055 \emph default
27056 .lib
27057 \end_layout
27058
27059 \end_inset
27060 </cell>
27061 </row>
27062 <row topline="true" bottomline="true">
27063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27064 \begin_inset Text
27065
27066 \begin_layout Standard
27067
27068 \series bold
27069 debug
27070 \end_layout
27071
27072 \end_inset
27073 </cell>
27074 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27075 \begin_inset Text
27076
27077 \begin_layout Standard
27078 link the debug library
27079 \end_layout
27080
27081 \end_inset
27082 </cell>
27083 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27084 \begin_inset Text
27085
27086 \begin_layout Standard
27087
27088 \emph on
27089 libdebug
27090 \emph default
27091 .lib
27092 \end_layout
27093
27094 \end_inset
27095 </cell>
27096 </row>
27097 </lyxtabular>
27098
27099 \end_inset
27100
27101
27102 \newline
27103 * is the device number, i.e.
27104  452 for PIC18F452 MCU.
27105 \end_layout
27106
27107 \begin_layout Standard
27108 \noindent
27109 This feature allows for linking with specific libraries without having to
27110  explicit name them in the command line.
27111  Note that the 
27112 \noun on
27113 ignore
27114 \noun default
27115  keyword will reject all modules specified by the library pragma.
27116 \end_layout
27117
27118 \begin_layout Description
27119 udata The pragma udata instructs the compiler to emit code so that linker
27120  will place a variable at a specific memory bank.
27121 \end_layout
27122
27123 \begin_layout LyX-Code
27124 Example:
27125 \end_layout
27126
27127 \begin_layout LyX-Code
27128
27129 \end_layout
27130
27131 \begin_layout LyX-Code
27132 /* places variable foo at bank2 */
27133 \end_layout
27134
27135 \begin_layout LyX-Code
27136 #pragma udata bank2 foo
27137 \end_layout
27138
27139 \begin_layout LyX-Code
27140 char foo;
27141 \end_layout
27142
27143 \begin_layout Standard
27144 In order for this pragma to work extra SECTION directives should be added
27145  in the .lkr script.
27146  In the following example a sample .lkr file is shown:
27147 \end_layout
27148
27149 \begin_layout LyX-Code
27150
27151 \end_layout
27152
27153 \begin_layout LyX-Code
27154 // Sample linker script for the PIC18F452 processor
27155 \end_layout
27156
27157 \begin_layout LyX-Code
27158 LIBPATH .
27159 \end_layout
27160
27161 \begin_layout LyX-Code
27162 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
27163 \end_layout
27164
27165 \begin_layout LyX-Code
27166 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
27167 \end_layout
27168
27169 \begin_layout LyX-Code
27170 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
27171 \end_layout
27172
27173 \begin_layout LyX-Code
27174 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
27175 \end_layout
27176
27177 \begin_layout LyX-Code
27178 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
27179 \end_layout
27180
27181 \begin_layout LyX-Code
27182 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
27183 \end_layout
27184
27185 \begin_layout LyX-Code
27186 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
27187 \end_layout
27188
27189 \begin_layout LyX-Code
27190
27191 \end_layout
27192
27193 \begin_layout LyX-Code
27194 DATABANK   NAME=gpr0       START=0x80           END=0xFF
27195 \end_layout
27196
27197 \begin_layout LyX-Code
27198 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
27199 \end_layout
27200
27201 \begin_layout LyX-Code
27202 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
27203 \end_layout
27204
27205 \begin_layout LyX-Code
27206 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
27207 \end_layout
27208
27209 \begin_layout LyX-Code
27210 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
27211 \end_layout
27212
27213 \begin_layout LyX-Code
27214 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
27215 \end_layout
27216
27217 \begin_layout LyX-Code
27218 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
27219 \end_layout
27220
27221 \begin_layout LyX-Code
27222
27223 \end_layout
27224
27225 \begin_layout LyX-Code
27226 SECTION    NAME=CONFIG     ROM=config
27227 \end_layout
27228
27229 \begin_layout LyX-Code
27230
27231 \end_layout
27232
27233 \begin_layout LyX-Code
27234 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
27235 \end_layout
27236
27237 \begin_layout LyX-Code
27238 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
27239 \end_layout
27240
27241 \begin_layout LyX-Code
27242 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
27243 \end_layout
27244
27245 \begin_layout LyX-Code
27246 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
27247 \end_layout
27248
27249 \begin_layout LyX-Code
27250 SECTION    NAME=bank4      RAM=gpr4
27251 \end_layout
27252
27253 \begin_layout LyX-Code
27254 SECTION    NAME=bank5      RAM=gpr5
27255 \end_layout
27256
27257 \begin_layout Standard
27258 The linker will recognise the section name set in the pragma statement and
27259  will position the variable at the memory bank set with the RAM field at
27260  the SECTION line in the linker script file.
27261 \end_layout
27262
27263 \begin_layout Subsection
27264 Header Files
27265 \begin_inset LatexCommand label
27266 name "sub:PIC16_Header-Files"
27267
27268 \end_inset
27269
27270
27271 \end_layout
27272
27273 \begin_layout Standard
27274 There is one main header file
27275 \begin_inset LatexCommand index
27276 name "PIC16!Header files"
27277
27278 \end_inset
27279
27280  that can be included to the source files using the pic16
27281 \begin_inset LatexCommand index
27282 name "PIC16"
27283
27284 \end_inset
27285
27286  port.
27287  That file is the 
27288 \series bold
27289 pic18fregs.h
27290 \series default
27291 .
27292  This header file contains the definitions for the processor special registers,
27293  so it is necessary if the source accesses them.
27294  It can be included by adding the following line in the beginning of the
27295  file:
27296 \end_layout
27297
27298 \begin_layout LyX-Code
27299 #include <pic18fregs.h>
27300 \end_layout
27301
27302 \begin_layout Standard
27303 The specific microcontroller is selected within the pic18fregs.h automatically,
27304  so the same source can be used with a variety of devices.
27305 \end_layout
27306
27307 \begin_layout Subsection
27308 Libraries
27309 \begin_inset LatexCommand label
27310 name "sub:pic16Libraries"
27311
27312 \end_inset
27313
27314
27315 \end_layout
27316
27317 \begin_layout Standard
27318 The libraries
27319 \begin_inset LatexCommand index
27320 name "PIC16!Libraries"
27321
27322 \end_inset
27323
27324  that PIC16
27325 \begin_inset LatexCommand index
27326 name "PIC16"
27327
27328 \end_inset
27329
27330  port depends on are the microcontroller device libraries which contain
27331  the symbol definitions for the microcontroller special function registers.
27332  These libraries have the format pic18fxxxx.lib, where 
27333 \emph on
27334 xxxx
27335 \emph default
27336  is the microcontroller identification number.
27337  The specific library is selected automatically by the compiler at link
27338  stage according to the selected device.
27339 \end_layout
27340
27341 \begin_layout Standard
27342 \noindent
27343 Libraries are created with gplib which is part of the gputils package 
27344 \begin_inset LatexCommand url
27345 target "http://sourceforge.net/projects/gputils"
27346
27347 \end_inset
27348
27349 .
27350 \end_layout
27351
27352 \begin_layout Subsubsection*
27353 Building the libraries
27354 \end_layout
27355
27356 \begin_layout Standard
27357 Before using SDCC/pic16 there are some libraries that need to be compiled.
27358  This process is done automatically if gputils are found at SDCC's compile
27359  time.
27360  Should you require to rebuild the pic16 libraries manually (e.g.
27361  in order to enable output of float values
27362 \begin_inset LatexCommand index
27363 name "Floating point support"
27364
27365 \end_inset
27366
27367  via 
27368 \family typewriter
27369 printf()
27370 \family default
27371 , see below), these are the steps required to do so under Linux or Mac OS
27372  X (cygwin might work as well, but is untested):
27373 \end_layout
27374
27375 \begin_layout LyX-Code
27376 cd device/lib/pic16
27377 \end_layout
27378
27379 \begin_layout LyX-Code
27380 ./configure.gnu
27381 \end_layout
27382
27383 \begin_layout LyX-Code
27384 cd ..
27385 \end_layout
27386
27387 \begin_layout LyX-Code
27388 make model-pic16
27389 \end_layout
27390
27391 \begin_layout LyX-Code
27392 su -c 'make install'     # install the libraries, you need the root password
27393 \end_layout
27394
27395 \begin_layout LyX-Code
27396 cd ../..
27397 \end_layout
27398
27399 \begin_layout Standard
27400 If you need to install the headers too, do:
27401 \end_layout
27402
27403 \begin_layout LyX-Code
27404 cd device/include
27405 \end_layout
27406
27407 \begin_layout LyX-Code
27408 su -c 'make install'     # install the headers, you need the root password
27409 \end_layout
27410
27411 \begin_layout Subsubsection*
27412 Output of float values via printf()
27413 \end_layout
27414
27415 \begin_layout Standard
27416 The library is normally built without support for displaying float values,
27417  only <NO FLOAT>
27418 \begin_inset LatexCommand index
27419 name "<NO FLOAT>"
27420
27421 \end_inset
27422
27423
27424 \begin_inset LatexCommand index
27425 name "printf floating point support"
27426
27427 \end_inset
27428
27429  will appear instead of the value.
27430  To change this, rebuild the library as stated above, but call 
27431 \family typewriter
27432 ./configure.gnu --enable-floats 
27433 \family default
27434 instead of just 
27435 \family typewriter
27436 ./configure.gnu
27437 \family default
27438 .
27439  Also make sure that at least 
27440 \family typewriter
27441 libc/stdio/vfprintf.c
27442 \family default
27443  is actually recompiled, e.g.
27444  by 
27445 \family typewriter
27446 touch
27447 \family default
27448 ing it after the 
27449 \family typewriter
27450 configure
27451 \family default
27452  run or deleting its 
27453 \family typewriter
27454 .o
27455 \family default
27456  file.
27457 \end_layout
27458
27459 \begin_layout Standard
27460 The more common appraoch of compiling 
27461 \family typewriter
27462 vfprintf.c
27463 \family default
27464  manually with 
27465 \family typewriter
27466 -DUSE_FLOATS=1
27467 \family default
27468  should also work, but is untested.
27469 \end_layout
27470
27471 \begin_layout Subsection
27472 Adding New Devices to the Port
27473 \end_layout
27474
27475 \begin_layout Standard
27476 Adding support for a new 16
27477 \begin_inset ERT
27478 status collapsed
27479
27480 \begin_layout Standard
27481
27482
27483 \backslash
27484 ,
27485 \end_layout
27486
27487 \end_inset
27488
27489 bit PIC MCU requires the following steps:
27490 \end_layout
27491
27492 \begin_layout Enumerate
27493 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
27494 \newline
27495
27496 \family typewriter
27497 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
27498 inc
27499 \end_layout
27500
27501 \begin_layout Enumerate
27502
27503 \family typewriter
27504 mv picDEVICE.h /path/to/sdcc/device/include/pic16
27505 \end_layout
27506
27507 \begin_layout Enumerate
27508
27509 \family typewriter
27510 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
27511 \end_layout
27512
27513 \begin_layout Enumerate
27514 Add DEVICE to 
27515 \family typewriter
27516 /path/to/sdcc/device/lib/pic16/pics.all
27517 \family default
27518
27519 \newline
27520 Note: No 18f prefix here!
27521 \end_layout
27522
27523 \begin_layout Enumerate
27524 Edit 
27525 \family typewriter
27526 /path/to/sdcc/device/include/pic16/adc.h
27527 \newline
27528
27529 \family default
27530 Add the new devices to the correct ADC style class (depending on the number
27531  of ADC channels).
27532 \newline
27533 Do not touch 
27534 \family typewriter
27535 adc.h
27536 \family default
27537  if the device does not offer any ADC at all.
27538 \end_layout
27539
27540 \begin_layout Enumerate
27541 Edit 
27542 \family typewriter
27543 /path/to/sdcc/device/include/pic16/pic18fregs.h
27544 \family default
27545
27546 \newline
27547 The file format is self-explanatory, just add
27548 \newline
27549
27550 \family typewriter
27551 #elif defined(picDEVICE)
27552 \newline
27553 #
27554 \begin_inset ERT
27555 status collapsed
27556
27557 \begin_layout Standard
27558
27559
27560 \backslash
27561  
27562 \backslash
27563  
27564 \end_layout
27565
27566 \end_inset
27567
27568 include <picDEVICE.h>
27569 \family default
27570
27571 \newline
27572 at the right place (keep the file sorted, please).
27573 \end_layout
27574
27575 \begin_layout Enumerate
27576 Edit 
27577 \family typewriter
27578 /path/to/sdcc/device/include/pic16devices.txt
27579 \newline
27580
27581 \family default
27582 Copy and modify an existing entry or create a new one and insert it at the
27583  correct place (keep the file sorted, please).
27584 \end_layout
27585
27586 \begin_layout Enumerate
27587 Add the device to 
27588 \family typewriter
27589 /path/to/sdcc/device/lib/pic16/libdev/Makefile.am
27590 \family default
27591
27592 \newline
27593 Copy an existing entry and adjust the device name.
27594 \end_layout
27595
27596 \begin_layout Enumerate
27597 Add the device to 
27598 \family typewriter
27599 /path/to/sdcc/device/lib/pic16/libio/Makefile.am
27600 \family default
27601
27602 \newline
27603 Copy the record from the 18f2220 and adjust the device name.
27604 \newline
27605 If the new device
27606  does not offer ADC, I
27607 \begin_inset Formula $^{\text{2}}$
27608 \end_inset
27609
27610 C, and/or (E)USART functionality as assumed by the library, remove the lines
27611  with references to 
27612 \family typewriter
27613 adc/*.c
27614 \family default
27615
27616 \family typewriter
27617 usart/*.c
27618 \family default
27619 , or 
27620 \family typewriter
27621 usart/*.c
27622 \family default
27623 , respectively.
27624 \end_layout
27625
27626 \begin_layout Enumerate
27627 Update 
27628 \family typewriter
27629 libdev/Makefile.in
27630 \family default
27631  and 
27632 \family typewriter
27633 libio/Makefile.in
27634 \family default
27635  using
27636 \newline
27637
27638 \family typewriter
27639 ./bootstrap.sh
27640 \family default
27641
27642 \newline
27643 in 
27644 \family typewriter
27645 /path/to/sdcc/device/lib/pic16
27646 \family default
27647 .
27648 \end_layout
27649
27650 \begin_layout Enumerate
27651 Recompile the pic16 libraries as described in 
27652 \begin_inset LatexCommand ref
27653 reference "sub:pic16Libraries"
27654
27655 \end_inset
27656
27657 .
27658 \end_layout
27659
27660 \begin_layout Subsection
27661 Memory Models
27662 \end_layout
27663
27664 \begin_layout Standard
27665 The following memory models are supported by the PIC16 port:
27666 \end_layout
27667
27668 \begin_layout Itemize
27669 small model
27670 \end_layout
27671
27672 \begin_layout Itemize
27673 large model
27674 \end_layout
27675
27676 \begin_layout Standard
27677 Memory model affects the default size of pointers within the source.
27678  The sizes are shown in the next table:
27679 \end_layout
27680
27681 \begin_layout Standard
27682 \align center
27683 \begin_inset Tabular
27684 <lyxtabular version="3" rows="3" columns="3">
27685 <features>
27686 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27687 <column alignment="center" valignment="top" leftline="true" width="0">
27688 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27689 <row topline="true" bottomline="true">
27690 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27691 \begin_inset Text
27692
27693 \begin_layout Standard
27694 Pointer sizes according to memory model
27695 \end_layout
27696
27697 \end_inset
27698 </cell>
27699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27700 \begin_inset Text
27701
27702 \begin_layout Standard
27703 small model
27704 \end_layout
27705
27706 \end_inset
27707 </cell>
27708 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27709 \begin_inset Text
27710
27711 \begin_layout Standard
27712 large model
27713 \end_layout
27714
27715 \end_inset
27716 </cell>
27717 </row>
27718 <row topline="true" bottomline="true">
27719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27720 \begin_inset Text
27721
27722 \begin_layout Standard
27723 code pointers
27724 \end_layout
27725
27726 \end_inset
27727 </cell>
27728 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27729 \begin_inset Text
27730
27731 \begin_layout Standard
27732 16-bits
27733 \end_layout
27734
27735 \end_inset
27736 </cell>
27737 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27738 \begin_inset Text
27739
27740 \begin_layout Standard
27741 24-bits
27742 \end_layout
27743
27744 \end_inset
27745 </cell>
27746 </row>
27747 <row topline="true" bottomline="true">
27748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27749 \begin_inset Text
27750
27751 \begin_layout Standard
27752 data pointers
27753 \end_layout
27754
27755 \end_inset
27756 </cell>
27757 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
27758 \begin_inset Text
27759
27760 \begin_layout Standard
27761 16-bits
27762 \end_layout
27763
27764 \end_inset
27765 </cell>
27766 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27767 \begin_inset Text
27768
27769 \begin_layout Standard
27770 16-bits
27771 \end_layout
27772
27773 \end_inset
27774 </cell>
27775 </row>
27776 </lyxtabular>
27777
27778 \end_inset
27779
27780
27781 \end_layout
27782
27783 \begin_layout Standard
27784 It is advisable that all sources within a project are compiled with the
27785  same memory model.
27786  If one wants to override the default memory model, this can be done by
27787  declaring a pointer as 
27788 \series bold
27789 far
27790 \series default
27791  or 
27792 \series bold
27793 near
27794 \series default
27795 .
27796  Far selects large memory model's pointers, while near selects small memory
27797  model's pointers.
27798 \end_layout
27799
27800 \begin_layout Standard
27801 The standard device libraries (see 
27802 \begin_inset LatexCommand ref
27803 reference "sub:PIC16_Header-Files"
27804
27805 \end_inset
27806
27807 ) contain no reference to pointers, so they can be used with both memory
27808  models.
27809 \end_layout
27810
27811 \begin_layout Subsection
27812 Stack
27813 \end_layout
27814
27815 \begin_layout Standard
27816 The stack
27817 \begin_inset LatexCommand index
27818 name "PIC16!stack"
27819
27820 \end_inset
27821
27822  implementation for the PIC16 port uses two indirect registers, FSR1 and
27823  FSR2.
27824 \end_layout
27825
27826 \begin_layout Description
27827 FSR1 is assigned as stack pointer
27828 \end_layout
27829
27830 \begin_layout Description
27831 FSR2 is assigned as frame pointer
27832 \end_layout
27833
27834 \begin_layout Standard
27835 The following stack models are supported by the PIC16 port
27836 \end_layout
27837
27838 \begin_layout Itemize
27839
27840 \noun on
27841 small
27842 \noun default
27843  model
27844 \end_layout
27845
27846 \begin_layout Itemize
27847
27848 \noun on
27849 large
27850 \noun default
27851  model
27852 \end_layout
27853
27854 \begin_layout Standard
27855
27856 \noun on
27857 Small
27858 \noun default
27859  model means that only the FSRxL byte is used to access stack and frame,
27860  while 
27861 \emph on
27862 \noun on
27863 large
27864 \emph default
27865 \noun default
27866  uses both FSRxL and FSRxH registers.
27867  The following table shows the stack/frame pointers sizes according to stack
27868  model and the maximum space they can address:
27869 \end_layout
27870
27871 \begin_layout Standard
27872 \align center
27873 \begin_inset Tabular
27874 <lyxtabular version="3" rows="3" columns="3">
27875 <features>
27876 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27877 <column alignment="center" valignment="top" leftline="true" width="0">
27878 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27879 <row topline="true" bottomline="true">
27880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27881 \begin_inset Text
27882
27883 \begin_layout Standard
27884 Stack & Frame pointer sizes according to stack model
27885 \end_layout
27886
27887 \end_inset
27888 </cell>
27889 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27890 \begin_inset Text
27891
27892 \begin_layout Standard
27893 small
27894 \end_layout
27895
27896 \end_inset
27897 </cell>
27898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27899 \begin_inset Text
27900
27901 \begin_layout Standard
27902 large
27903 \end_layout
27904
27905 \end_inset
27906 </cell>
27907 </row>
27908 <row topline="true">
27909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27910 \begin_inset Text
27911
27912 \begin_layout Standard
27913 Stack pointer FSR1
27914 \end_layout
27915
27916 \end_inset
27917 </cell>
27918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27919 \begin_inset Text
27920
27921 \begin_layout Standard
27922 8-bits
27923 \end_layout
27924
27925 \end_inset
27926 </cell>
27927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27928 \begin_inset Text
27929
27930 \begin_layout Standard
27931 16-bits
27932 \end_layout
27933
27934 \end_inset
27935 </cell>
27936 </row>
27937 <row topline="true" bottomline="true">
27938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27939 \begin_inset Text
27940
27941 \begin_layout Standard
27942 Frame pointer FSR2
27943 \end_layout
27944
27945 \end_inset
27946 </cell>
27947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27948 \begin_inset Text
27949
27950 \begin_layout Standard
27951 8-bits
27952 \end_layout
27953
27954 \end_inset
27955 </cell>
27956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27957 \begin_inset Text
27958
27959 \begin_layout Standard
27960 16-bits
27961 \end_layout
27962
27963 \end_inset
27964 </cell>
27965 </row>
27966 </lyxtabular>
27967
27968 \end_inset
27969
27970
27971 \end_layout
27972
27973 \begin_layout Standard
27974 \noindent
27975
27976 \noun on
27977 Large 
27978 \noun default
27979 stack model is currently not working properly throughout the code generator.
27980  So its use is not advised.
27981  Also there are some other points that need special care:
27982 \newline
27983
27984 \end_layout
27985
27986 \begin_layout Enumerate
27987 Do not create stack sections with size more than one physical bank (that
27988  is 256 bytes)
27989 \end_layout
27990
27991 \begin_layout Enumerate
27992 Stack sections should no cross physical bank limits (i.e.
27993  #pragma stack 0x50 0x100)
27994 \end_layout
27995
27996 \begin_layout Standard
27997 These limitations are caused by the fact that only FSRxL is modified when
27998  using SMALL stack model, so no more than 256 bytes of stack can be used.
27999  This problem will disappear after LARGE model is fully implemented.
28000 \end_layout
28001
28002 \begin_layout Subsection
28003 Functions
28004 \end_layout
28005
28006 \begin_layout Standard
28007 In addition to the standard SDCC function keywords, PIC16
28008 \begin_inset LatexCommand index
28009 name "PIC16"
28010
28011 \end_inset
28012
28013  port makes available two more:
28014 \end_layout
28015
28016 \begin_layout Description
28017 wparam
28018 \begin_inset LatexCommand index
28019 name "PIC16!wparam"
28020
28021 \end_inset
28022
28023  Use the WREG to pass one byte of the first function argument.
28024  This improves speed but you may not use this for functions with arguments
28025  that are called via function pointers, otherwise the first byte of the
28026  first parameter will get lost.
28027  Usage:
28028 \end_layout
28029
28030 \begin_layout LyX-Code
28031 void func_wparam(int a) wparam
28032 \end_layout
28033
28034 \begin_layout LyX-Code
28035 {
28036 \end_layout
28037
28038 \begin_layout LyX-Code
28039     /* WREG hold the lower part of a */
28040 \end_layout
28041
28042 \begin_layout LyX-Code
28043     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
28044  */
28045 \end_layout
28046
28047 \begin_layout LyX-Code
28048 ...
28049 \end_layout
28050
28051 \begin_layout LyX-Code
28052 }
28053 \end_layout
28054
28055 \begin_layout Description
28056 shadowregs
28057 \begin_inset LatexCommand index
28058 name "PIC16!shadowregs"
28059
28060 \end_inset
28061
28062  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
28063  hardware shadow registers which hold the values of WREG, STATUS and BSR
28064  registers.
28065  This can be done by adding the keyword 
28066 \emph on
28067 shadowregs
28068 \emph default
28069  before the 
28070 \emph on
28071 interrupt
28072 \emph default
28073  keyword in the function's header.
28074 \end_layout
28075
28076 \begin_layout LyX-Code
28077 void isr_shadow(void) shadowregs interrupt 1
28078 \end_layout
28079
28080 \begin_layout LyX-Code
28081 {
28082 \end_layout
28083
28084 \begin_layout LyX-Code
28085 ...
28086 \end_layout
28087
28088 \begin_layout LyX-Code
28089 }
28090 \end_layout
28091
28092 \begin_layout Standard
28093
28094 \emph on
28095 shadowregs
28096 \emph default
28097  instructs the code generator not to store/restore WREG, STATUS, BSR when
28098  entering/exiting the ISR.
28099 \end_layout
28100
28101 \begin_layout Subsection
28102 Function return values
28103 \end_layout
28104
28105 \begin_layout Standard
28106 Return values from functions are placed to the appropriate registers following
28107  a modified Microchip policy optimized for SDCC.
28108  The following table shows these registers:
28109 \end_layout
28110
28111 \begin_layout Standard
28112 \align center
28113 \begin_inset Tabular
28114 <lyxtabular version="3" rows="6" columns="2">
28115 <features>
28116 <column alignment="center" valignment="top" leftline="true" width="0">
28117 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28118 <row topline="true" bottomline="true">
28119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28120 \begin_inset Text
28121
28122 \begin_layout Standard
28123 size
28124 \end_layout
28125
28126 \end_inset
28127 </cell>
28128 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28129 \begin_inset Text
28130
28131 \begin_layout Standard
28132 destination register
28133 \end_layout
28134
28135 \end_inset
28136 </cell>
28137 </row>
28138 <row topline="true">
28139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28140 \begin_inset Text
28141
28142 \begin_layout Standard
28143 8 bits
28144 \end_layout
28145
28146 \end_inset
28147 </cell>
28148 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28149 \begin_inset Text
28150
28151 \begin_layout Standard
28152 WREG
28153 \end_layout
28154
28155 \end_inset
28156 </cell>
28157 </row>
28158 <row topline="true">
28159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28160 \begin_inset Text
28161
28162 \begin_layout Standard
28163 16 bits
28164 \end_layout
28165
28166 \end_inset
28167 </cell>
28168 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28169 \begin_inset Text
28170
28171 \begin_layout Standard
28172 PRODL:WREG
28173 \end_layout
28174
28175 \end_inset
28176 </cell>
28177 </row>
28178 <row topline="true">
28179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28180 \begin_inset Text
28181
28182 \begin_layout Standard
28183 24 bits
28184 \end_layout
28185
28186 \end_inset
28187 </cell>
28188 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28189 \begin_inset Text
28190
28191 \begin_layout Standard
28192 PRODH:PRODL:WREG
28193 \end_layout
28194
28195 \end_inset
28196 </cell>
28197 </row>
28198 <row topline="true">
28199 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28200 \begin_inset Text
28201
28202 \begin_layout Standard
28203 32 bits
28204 \end_layout
28205
28206 \end_inset
28207 </cell>
28208 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28209 \begin_inset Text
28210
28211 \begin_layout Standard
28212 FSR0L:PRODH:PRODL:WREG
28213 \end_layout
28214
28215 \end_inset
28216 </cell>
28217 </row>
28218 <row topline="true" bottomline="true">
28219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28220 \begin_inset Text
28221
28222 \begin_layout Standard
28223 >32 bits
28224 \end_layout
28225
28226 \end_inset
28227 </cell>
28228 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28229 \begin_inset Text
28230
28231 \begin_layout Standard
28232 on stack, FSR0 points to the beginning
28233 \end_layout
28234
28235 \end_inset
28236 </cell>
28237 </row>
28238 </lyxtabular>
28239
28240 \end_inset
28241
28242
28243 \end_layout
28244
28245 \begin_layout Subsection
28246 Interrupts
28247 \end_layout
28248
28249 \begin_layout Standard
28250 An interrupt
28251 \begin_inset LatexCommand index
28252 name "PIC16!interrupt"
28253
28254 \end_inset
28255
28256  service routine (ISR) is declared using the 
28257 \emph on
28258 interrupt
28259 \emph default
28260  keyword.
28261 \end_layout
28262
28263 \begin_layout LyX-Code
28264 void isr(void) interrupt 
28265 \emph on
28266 n
28267 \end_layout
28268
28269 \begin_layout LyX-Code
28270 {
28271 \end_layout
28272
28273 \begin_layout LyX-Code
28274 ...
28275 \end_layout
28276
28277 \begin_layout LyX-Code
28278 }
28279 \end_layout
28280
28281 \begin_layout Standard
28282
28283 \emph on
28284 n
28285 \emph default
28286  is the interrupt number, which for PIC18F devices can be:
28287 \end_layout
28288
28289 \begin_layout Standard
28290 \align center
28291 \begin_inset Tabular
28292 <lyxtabular version="3" rows="4" columns="3">
28293 <features>
28294 <column alignment="center" valignment="top" leftline="true" width="0">
28295 <column alignment="center" valignment="top" leftline="true" width="0">
28296 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28297 <row topline="true" bottomline="true">
28298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28299 \begin_inset Text
28300
28301 \begin_layout Standard
28302
28303 \emph on
28304 n
28305 \end_layout
28306
28307 \end_inset
28308 </cell>
28309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28310 \begin_inset Text
28311
28312 \begin_layout Standard
28313 Interrupt Vector
28314 \end_layout
28315
28316 \end_inset
28317 </cell>
28318 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28319 \begin_inset Text
28320
28321 \begin_layout Standard
28322 Interrupt Vector Address
28323 \end_layout
28324
28325 \end_inset
28326 </cell>
28327 </row>
28328 <row topline="true">
28329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28330 \begin_inset Text
28331
28332 \begin_layout Standard
28333 0
28334 \end_layout
28335
28336 \end_inset
28337 </cell>
28338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28339 \begin_inset Text
28340
28341 \begin_layout Standard
28342 RESET vector
28343 \end_layout
28344
28345 \end_inset
28346 </cell>
28347 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28348 \begin_inset Text
28349
28350 \begin_layout Standard
28351 0x000000
28352 \end_layout
28353
28354 \end_inset
28355 </cell>
28356 </row>
28357 <row topline="true">
28358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28359 \begin_inset Text
28360
28361 \begin_layout Standard
28362
28363 \family roman
28364 \series medium
28365 \shape up
28366 \size normal
28367 \emph off
28368 \bar no
28369 \noun off
28370 \color none
28371 1
28372 \end_layout
28373
28374 \end_inset
28375 </cell>
28376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28377 \begin_inset Text
28378
28379 \begin_layout Standard
28380
28381 \family roman
28382 \series medium
28383 \shape up
28384 \size normal
28385 \emph off
28386 \bar no
28387 \noun off
28388 \color none
28389 HIGH priority interrupts
28390 \end_layout
28391
28392 \end_inset
28393 </cell>
28394 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28395 \begin_inset Text
28396
28397 \begin_layout Standard
28398 0x000008
28399 \end_layout
28400
28401 \end_inset
28402 </cell>
28403 </row>
28404 <row topline="true" bottomline="true">
28405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28406 \begin_inset Text
28407
28408 \begin_layout Standard
28409 2
28410 \end_layout
28411
28412 \end_inset
28413 </cell>
28414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28415 \begin_inset Text
28416
28417 \begin_layout Standard
28418 LOW priority interrupts
28419 \end_layout
28420
28421 \end_inset
28422 </cell>
28423 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28424 \begin_inset Text
28425
28426 \begin_layout Standard
28427 0x000018
28428 \end_layout
28429
28430 \end_inset
28431 </cell>
28432 </row>
28433 </lyxtabular>
28434
28435 \end_inset
28436
28437
28438 \end_layout
28439
28440 \begin_layout Standard
28441 When generating assembly code for ISR the code generator places a 
28442 \noun on
28443 goto 
28444 \noun default
28445 instruction at the 
28446 \emph on
28447 Interrupt Vector Address
28448 \emph default
28449  which points at the generated ISR.
28450  This single GOTO instruction is part of an automatically generated 
28451 \emph on
28452 interrupt entry point
28453 \emph default
28454  function.
28455  The actuall ISR code is placed as normally would in the code space.
28456  Upon interrupt request, the GOTO instruction is executed which jumps to
28457  the ISR code.
28458  When declaring interrupt functions as _naked this GOTO instruction is 
28459 \series bold
28460 not
28461 \series default
28462  generated.
28463  The whole interrupt functions is therefore placed at the Interrupt Vector
28464  Address of the specific interrupt.
28465  This is not a problem for the LOW priority interrupts, but it is a problem
28466  for the RESET and the HIGH priority interrupts because code may be written
28467  at the next interrupt's vector address and cause indeterminate program
28468  behaviour if that interrupt is raised.
28469 \begin_inset Foot
28470 status open
28471
28472 \begin_layout Standard
28473 This is not a problem when
28474 \end_layout
28475
28476 \begin_layout Enumerate
28477 this is a HIGH interrupt ISR and LOW interrupts are 
28478 \emph on
28479 disabled
28480 \emph default
28481  or not used.
28482 \end_layout
28483
28484 \begin_layout Enumerate
28485 when the ISR is small enough not to reach the next interrupt's vector address.
28486 \end_layout
28487
28488 \end_inset
28489
28490
28491 \end_layout
28492
28493 \begin_layout Standard
28494
28495 \emph on
28496 n
28497 \emph default
28498  may be omitted.
28499  This way a function is generated similar to an ISR, but it is not assigned
28500  to any interrupt.
28501 \end_layout
28502
28503 \begin_layout Standard
28504 When entering an interrupt, currently the PIC16
28505 \begin_inset LatexCommand index
28506 name "PIC16"
28507
28508 \end_inset
28509
28510  port automatically saves the following registers:
28511 \end_layout
28512
28513 \begin_layout Itemize
28514 WREG
28515 \end_layout
28516
28517 \begin_layout Itemize
28518 STATUS
28519 \end_layout
28520
28521 \begin_layout Itemize
28522 BSR
28523 \end_layout
28524
28525 \begin_layout Itemize
28526 PROD (PRODL and PRODH)
28527 \end_layout
28528
28529 \begin_layout Itemize
28530 FSR0 (FSR0L and FSR0H)
28531 \end_layout
28532
28533 \begin_layout Standard
28534 These registers are restored upon return from the interrupt routine.
28535 \begin_inset Foot
28536 status open
28537
28538 \begin_layout Standard
28539 NOTE that when the _naked attribute is specified for an interrupt routine,
28540  then NO registers are stored or restored.
28541 \end_layout
28542
28543 \end_inset
28544
28545
28546 \end_layout
28547
28548 \begin_layout Subsection
28549 Generic Pointers
28550 \end_layout
28551
28552 \begin_layout Standard
28553 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
28554  There are 3 types of generic pointers currently implemented data, code
28555  and eeprom pointers.
28556  They are differentiated by the value of the 7th and 6th bits of the upper
28557  byte:
28558 \end_layout
28559
28560 \begin_layout Standard
28561 \align center
28562 \begin_inset Tabular
28563 <lyxtabular version="3" rows="5" columns="5">
28564 <features>
28565 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28566 <column alignment="center" valignment="top" width="0">
28567 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28568 <column alignment="center" valignment="top" width="0">
28569 <column alignment="left" valignment="top" rightline="true" width="0">
28570 <row topline="true" bottomline="true">
28571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28572 \begin_inset Text
28573
28574 \begin_layout Standard
28575 pointer type
28576 \end_layout
28577
28578 \end_inset
28579 </cell>
28580 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28581 \begin_inset Text
28582
28583 \begin_layout Standard
28584 7th bit
28585 \end_layout
28586
28587 \end_inset
28588 </cell>
28589 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28590 \begin_inset Text
28591
28592 \begin_layout Standard
28593 6th bit
28594 \end_layout
28595
28596 \end_inset
28597 </cell>
28598 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28599 \begin_inset Text
28600
28601 \begin_layout Standard
28602 rest of the pointer
28603 \end_layout
28604
28605 \end_inset
28606 </cell>
28607 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28608 \begin_inset Text
28609
28610 \begin_layout Standard
28611 description
28612 \end_layout
28613
28614 \end_inset
28615 </cell>
28616 </row>
28617 <row topline="true" bottomline="true">
28618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28619 \begin_inset Text
28620
28621 \begin_layout Standard
28622 data 
28623 \end_layout
28624
28625 \end_inset
28626 </cell>
28627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28628 \begin_inset Text
28629
28630 \begin_layout Standard
28631 1
28632 \end_layout
28633
28634 \end_inset
28635 </cell>
28636 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28637 \begin_inset Text
28638
28639 \begin_layout Standard
28640 0
28641 \end_layout
28642
28643 \end_inset
28644 </cell>
28645 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28646 \begin_inset Text
28647
28648 \begin_layout Standard
28649
28650 \family typewriter
28651 \shape slanted
28652 \emph on
28653 uuuuuu uuuuxxxx xxxxxxxx
28654 \end_layout
28655
28656 \end_inset
28657 </cell>
28658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28659 \begin_inset Text
28660
28661 \begin_layout Standard
28662 a 12-bit data pointer in data RAM memory
28663 \end_layout
28664
28665 \end_inset
28666 </cell>
28667 </row>
28668 <row bottomline="true">
28669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28670 \begin_inset Text
28671
28672 \begin_layout Standard
28673 code
28674 \end_layout
28675
28676 \end_inset
28677 </cell>
28678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28679 \begin_inset Text
28680
28681 \begin_layout Standard
28682 0
28683 \end_layout
28684
28685 \end_inset
28686 </cell>
28687 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28688 \begin_inset Text
28689
28690 \begin_layout Standard
28691 0
28692 \end_layout
28693
28694 \end_inset
28695 </cell>
28696 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28697 \begin_inset Text
28698
28699 \begin_layout Standard
28700
28701 \family typewriter
28702 \shape slanted
28703 \emph on
28704 uxxxxx xxxxxxxx xxxxxxxx
28705 \end_layout
28706
28707 \end_inset
28708 </cell>
28709 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28710 \begin_inset Text
28711
28712 \begin_layout Standard
28713 a 21-bit code pointer in FLASH memory
28714 \end_layout
28715
28716 \end_inset
28717 </cell>
28718 </row>
28719 <row bottomline="true">
28720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28721 \begin_inset Text
28722
28723 \begin_layout Standard
28724 eeprom
28725 \end_layout
28726
28727 \end_inset
28728 </cell>
28729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28730 \begin_inset Text
28731
28732 \begin_layout Standard
28733 0
28734 \end_layout
28735
28736 \end_inset
28737 </cell>
28738 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28739 \begin_inset Text
28740
28741 \begin_layout Standard
28742 1
28743 \end_layout
28744
28745 \end_inset
28746 </cell>
28747 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28748 \begin_inset Text
28749
28750 \begin_layout Standard
28751
28752 \family typewriter
28753 \shape slanted
28754 \emph on
28755 uuuuuu uuuuuuxx xxxxxxxx
28756 \end_layout
28757
28758 \end_inset
28759 </cell>
28760 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28761 \begin_inset Text
28762
28763 \begin_layout Standard
28764 a 10-bit eeprom pointer in EEPROM memory
28765 \end_layout
28766
28767 \end_inset
28768 </cell>
28769 </row>
28770 <row bottomline="true">
28771 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28772 \begin_inset Text
28773
28774 \begin_layout Standard
28775 (unimplemented)
28776 \end_layout
28777
28778 \end_inset
28779 </cell>
28780 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28781 \begin_inset Text
28782
28783 \begin_layout Standard
28784 1
28785 \end_layout
28786
28787 \end_inset
28788 </cell>
28789 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28790 \begin_inset Text
28791
28792 \begin_layout Standard
28793 1
28794 \end_layout
28795
28796 \end_inset
28797 </cell>
28798 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28799 \begin_inset Text
28800
28801 \begin_layout Standard
28802
28803 \family typewriter
28804 \shape slanted
28805 \emph on
28806 xxxxxx xxxxxxxx xxxxxxxx
28807 \end_layout
28808
28809 \end_inset
28810 </cell>
28811 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28812 \begin_inset Text
28813
28814 \begin_layout Standard
28815 unimplemented pointer type
28816 \end_layout
28817
28818 \end_inset
28819 </cell>
28820 </row>
28821 </lyxtabular>
28822
28823 \end_inset
28824
28825
28826 \end_layout
28827
28828 \begin_layout Standard
28829 \noindent
28830 Generic pointer are read and written with a set of library functions which
28831  read/write 1, 2, 3, 4 bytes.
28832 \end_layout
28833
28834 \begin_layout Subsection
28835 PIC16 C Libraries
28836 \end_layout
28837
28838 \begin_layout Subsubsection
28839 Standard I/O Streams
28840 \end_layout
28841
28842 \begin_layout Standard
28843 In the 
28844 \emph on
28845 stdio.h
28846 \emph default
28847  the type FILE is defined as:
28848 \end_layout
28849
28850 \begin_layout LyX-Code
28851 typedef char * FILE;
28852 \end_layout
28853
28854 \begin_layout Standard
28855 This type is the stream type implemented I/O in the PIC18F devices.
28856  Also the standard input and output streams are declared in stdio.h:
28857 \end_layout
28858
28859 \begin_layout LyX-Code
28860 extern FILE * stdin;
28861 \end_layout
28862
28863 \begin_layout LyX-Code
28864 extern FILE * stdout;
28865 \end_layout
28866
28867 \begin_layout Standard
28868 The FILE type is actually a generic pointer which defines one more type
28869  of generic pointers, the 
28870 \emph on
28871 stream
28872 \emph default
28873  pointer.
28874  This new type has the format:
28875 \end_layout
28876
28877 \begin_layout Standard
28878 \noindent
28879 \align center
28880 \begin_inset Tabular
28881 <lyxtabular version="3" rows="2" columns="7">
28882 <features>
28883 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28884 <column alignment="center" valignment="top" width="0">
28885 <column alignment="center" valignment="top" leftline="true" width="0">
28886 <column alignment="center" valignment="top" leftline="true" width="0">
28887 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28888 <column alignment="center" valignment="top" width="0">
28889 <column alignment="left" valignment="top" rightline="true" width="0">
28890 <row topline="true" bottomline="true">
28891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28892 \begin_inset Text
28893
28894 \begin_layout Standard
28895 pointer type
28896 \end_layout
28897
28898 \end_inset
28899 </cell>
28900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28901 \begin_inset Text
28902
28903 \begin_layout Standard
28904 <7:6>
28905 \end_layout
28906
28907 \end_inset
28908 </cell>
28909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28910 \begin_inset Text
28911
28912 \begin_layout Standard
28913 <5>
28914 \end_layout
28915
28916 \end_inset
28917 </cell>
28918 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28919 \begin_inset Text
28920
28921 \begin_layout Standard
28922 <4>
28923 \end_layout
28924
28925 \end_inset
28926 </cell>
28927 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28928 \begin_inset Text
28929
28930 \begin_layout Standard
28931 <3:0>
28932 \end_layout
28933
28934 \end_inset
28935 </cell>
28936 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28937 \begin_inset Text
28938
28939 \begin_layout Standard
28940 rest of the pointer
28941 \end_layout
28942
28943 \end_inset
28944 </cell>
28945 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28946 \begin_inset Text
28947
28948 \begin_layout Standard
28949 descrption
28950 \end_layout
28951
28952 \end_inset
28953 </cell>
28954 </row>
28955 <row topline="true" bottomline="true">
28956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28957 \begin_inset Text
28958
28959 \begin_layout Standard
28960 stream
28961 \end_layout
28962
28963 \end_inset
28964 </cell>
28965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28966 \begin_inset Text
28967
28968 \begin_layout Standard
28969 00
28970 \end_layout
28971
28972 \end_inset
28973 </cell>
28974 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28975 \begin_inset Text
28976
28977 \begin_layout Standard
28978 1
28979 \end_layout
28980
28981 \end_inset
28982 </cell>
28983 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28984 \begin_inset Text
28985
28986 \begin_layout Standard
28987 0
28988 \end_layout
28989
28990 \end_inset
28991 </cell>
28992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28993 \begin_inset Text
28994
28995 \begin_layout Standard
28996 nnnn
28997 \end_layout
28998
28999 \end_inset
29000 </cell>
29001 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29002 \begin_inset Text
29003
29004 \begin_layout Standard
29005
29006 \family typewriter
29007 \shape slanted
29008 \emph on
29009 uuuuuuuu uuuuuuuu
29010 \end_layout
29011
29012 \end_inset
29013 </cell>
29014 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29015 \begin_inset Text
29016
29017 \begin_layout Standard
29018 upper byte high nubble is 0x2n, the rest are zeroes
29019 \end_layout
29020
29021 \end_inset
29022 </cell>
29023 </row>
29024 </lyxtabular>
29025
29026 \end_inset
29027
29028
29029 \end_layout
29030
29031 \begin_layout Standard
29032 \noindent
29033 Currently implemented there are 3 types of streams defined:
29034 \end_layout
29035
29036 \begin_layout Standard
29037 \noindent
29038 \align center
29039 \begin_inset Tabular
29040 <lyxtabular version="3" rows="4" columns="4">
29041 <features>
29042 <column alignment="center" valignment="top" leftline="true" width="0">
29043 <column alignment="center" valignment="top" leftline="true" width="0">
29044 <column alignment="center" valignment="top" leftline="true" width="0">
29045 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
29046 <row topline="true" bottomline="true">
29047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29048 \begin_inset Text
29049
29050 \begin_layout Standard
29051 stream type
29052 \end_layout
29053
29054 \end_inset
29055 </cell>
29056 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29057 \begin_inset Text
29058
29059 \begin_layout Standard
29060 value
29061 \end_layout
29062
29063 \end_inset
29064 </cell>
29065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29066 \begin_inset Text
29067
29068 \begin_layout Standard
29069 module
29070 \end_layout
29071
29072 \end_inset
29073 </cell>
29074 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29075 \begin_inset Text
29076
29077 \begin_layout Standard
29078 description
29079 \end_layout
29080
29081 \end_inset
29082 </cell>
29083 </row>
29084 <row topline="true">
29085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29086 \begin_inset Text
29087
29088 \begin_layout Standard
29089 STREAM_USART
29090 \end_layout
29091
29092 \end_inset
29093 </cell>
29094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29095 \begin_inset Text
29096
29097 \begin_layout Standard
29098
29099 \family typewriter
29100 0x200000UL
29101 \end_layout
29102
29103 \end_inset
29104 </cell>
29105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29106 \begin_inset Text
29107
29108 \begin_layout Standard
29109 USART
29110 \end_layout
29111
29112 \end_inset
29113 </cell>
29114 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29115 \begin_inset Text
29116
29117 \begin_layout Standard
29118 Writes/Reads characters via the USART peripheral
29119 \end_layout
29120
29121 \end_inset
29122 </cell>
29123 </row>
29124 <row topline="true">
29125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29126 \begin_inset Text
29127
29128 \begin_layout Standard
29129 STREAM_MSSP
29130 \end_layout
29131
29132 \end_inset
29133 </cell>
29134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29135 \begin_inset Text
29136
29137 \begin_layout Standard
29138
29139 \family typewriter
29140 0x210000UL
29141 \end_layout
29142
29143 \end_inset
29144 </cell>
29145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29146 \begin_inset Text
29147
29148 \begin_layout Standard
29149 MSSP
29150 \end_layout
29151
29152 \end_inset
29153 </cell>
29154 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29155 \begin_inset Text
29156
29157 \begin_layout Standard
29158 Writes/Reads characters via the MSSP peripheral
29159 \end_layout
29160
29161 \end_inset
29162 </cell>
29163 </row>
29164 <row topline="true" bottomline="true">
29165 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29166 \begin_inset Text
29167
29168 \begin_layout Standard
29169 STREAM_USER
29170 \end_layout
29171
29172 \end_inset
29173 </cell>
29174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29175 \begin_inset Text
29176
29177 \begin_layout Standard
29178
29179 \family typewriter
29180 0x2f0000UL
29181 \end_layout
29182
29183 \end_inset
29184 </cell>
29185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29186 \begin_inset Text
29187
29188 \begin_layout Standard
29189 (none)
29190 \end_layout
29191
29192 \end_inset
29193 </cell>
29194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29195 \begin_inset Text
29196
29197 \begin_layout Standard
29198 Writes/Reads characters via used defined functions
29199 \end_layout
29200
29201 \end_inset
29202 </cell>
29203 </row>
29204 </lyxtabular>
29205
29206 \end_inset
29207
29208
29209 \end_layout
29210
29211 \begin_layout Standard
29212 \noindent
29213 The stream identifiers are declared as macros in the stdio.h header.
29214 \end_layout
29215
29216 \begin_layout Standard
29217 \noindent
29218 In the libc library there exist the functions that are used to write to
29219  each of the above streams.
29220  These are
29221 \end_layout
29222
29223 \begin_layout Description
29224 _
29225 \begin_inset ERT
29226 status collapsed
29227
29228 \begin_layout Standard
29229
29230
29231 \backslash
29232 /
29233 \end_layout
29234
29235 \end_inset
29236
29237 _stream_usart_putchar writes a character at the USART stream
29238 \end_layout
29239
29240 \begin_layout Description
29241 _
29242 \begin_inset ERT
29243 status collapsed
29244
29245 \begin_layout Standard
29246
29247
29248 \backslash
29249 /
29250 \end_layout
29251
29252 \end_inset
29253
29254 _stream_mssp_putchar writes a character at the MSSP stream
29255 \end_layout
29256
29257 \begin_layout Description
29258 putchar dummy function.
29259  This writes a character to a user specified manner.
29260 \end_layout
29261
29262 \begin_layout Standard
29263 In order to increase performance 
29264 \emph on
29265 putchar
29266 \emph default
29267  is declared in stdio.h as having its parameter in WREG (it has the wparam
29268  keyword).
29269  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
29270  in a user-friendly way.
29271  
29272 \emph on
29273 arg
29274 \emph default
29275  is the name of the variable that holds the character to print.
29276  An example follows:
29277 \end_layout
29278
29279 \begin_layout LyX-Code
29280 #include <pic18fregs.h>
29281 \newline
29282 #include <stdio.h>
29283 \newline
29284
29285 \newline
29286 PUTCHAR( c )
29287 \end_layout
29288
29289 \begin_layout LyX-Code
29290 {
29291 \end_layout
29292
29293 \begin_layout LyX-Code
29294     PORTA = c;    /* dump character c to PORTA */
29295 \end_layout
29296
29297 \begin_layout LyX-Code
29298
29299 \newline
29300
29301 \newline
29302 void main(void)
29303 \end_layout
29304
29305 \begin_layout LyX-Code
29306 {
29307 \end_layout
29308
29309 \begin_layout LyX-Code
29310     stdout = STREAM_USER;    /* this is not necessary, since stdout points
29311 \end_layout
29312
29313 \begin_layout LyX-Code
29314                               * by default to STREAM_USER */
29315 \end_layout
29316
29317 \begin_layout LyX-Code
29318     printf (
29319 \begin_inset Quotes sld
29320 \end_inset
29321
29322 This is a printf test
29323 \backslash
29324 n
29325 \begin_inset Quotes srd
29326 \end_inset
29327
29328 );
29329 \end_layout
29330
29331 \begin_layout LyX-Code
29332 }
29333 \end_layout
29334
29335 \begin_layout LyX-Code
29336
29337 \end_layout
29338
29339 \begin_layout Subsubsection
29340 Printing functions
29341 \end_layout
29342
29343 \begin_layout Standard
29344 PIC16 contains an implementation of the printf-family of functions.
29345  There exist the following functions:
29346 \end_layout
29347
29348 \begin_layout LyX-Code
29349 extern unsigned int sprintf(char *buf, char *fmt, ...);
29350 \end_layout
29351
29352 \begin_layout LyX-Code
29353 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
29354 \end_layout
29355
29356 \begin_layout LyX-Code
29357
29358 \end_layout
29359
29360 \begin_layout LyX-Code
29361 extern unsigned int printf(char *fmt, ...);
29362 \end_layout
29363
29364 \begin_layout LyX-Code
29365 extern unsigned int vprintf(char *fmt, va_lista ap);
29366 \end_layout
29367
29368 \begin_layout LyX-Code
29369
29370 \end_layout
29371
29372 \begin_layout LyX-Code
29373 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
29374 \end_layout
29375
29376 \begin_layout LyX-Code
29377 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
29378 \end_layout
29379
29380 \begin_layout Standard
29381 For sprintf and vsprintf 
29382 \emph on
29383 buf
29384 \emph default
29385  should normally be a data pointer where the resulting string will be placed.
29386  No range checking is done so the user should allocate the necessary buffer.
29387  For fprintf and vfprintf 
29388 \emph on
29389 fp
29390 \emph default
29391  should be a stream pointer (i.e.
29392  stdout, STREAM_MSSP, etc...).
29393 \end_layout
29394
29395 \begin_layout Subsubsection
29396 Signals
29397 \end_layout
29398
29399 \begin_layout Standard
29400 The PIC18F family of microcontrollers supports a number of interrupt sources.
29401  A list of these interrupts is shown in the following table:
29402 \end_layout
29403
29404 \begin_layout Standard
29405 \align center
29406 \begin_inset Tabular
29407 <lyxtabular version="3" rows="11" columns="4">
29408 <features>
29409 <column alignment="left" valignment="top" leftline="true" width="0">
29410 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
29411 <column alignment="left" valignment="top" leftline="true" width="0">
29412 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
29413 <row topline="true" bottomline="true">
29414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29415 \begin_inset Text
29416
29417 \begin_layout Standard
29418 signal name
29419 \end_layout
29420
29421 \end_inset
29422 </cell>
29423 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29424 \begin_inset Text
29425
29426 \begin_layout Standard
29427 description
29428 \end_layout
29429
29430 \end_inset
29431 </cell>
29432 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29433 \begin_inset Text
29434
29435 \begin_layout Standard
29436 signal name
29437 \end_layout
29438
29439 \end_inset
29440 </cell>
29441 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29442 \begin_inset Text
29443
29444 \begin_layout Standard
29445 description
29446 \end_layout
29447
29448 \end_inset
29449 </cell>
29450 </row>
29451 <row topline="true">
29452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29453 \begin_inset Text
29454
29455 \begin_layout Standard
29456 SIG_RB
29457 \end_layout
29458
29459 \end_inset
29460 </cell>
29461 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29462 \begin_inset Text
29463
29464 \begin_layout Standard
29465 PORTB change interrupt
29466 \end_layout
29467
29468 \end_inset
29469 </cell>
29470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29471 \begin_inset Text
29472
29473 \begin_layout Standard
29474 SIG_EE
29475 \end_layout
29476
29477 \end_inset
29478 </cell>
29479 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29480 \begin_inset Text
29481
29482 \begin_layout Standard
29483 EEPROM/FLASH write complete interrupt
29484 \end_layout
29485
29486 \end_inset
29487 </cell>
29488 </row>
29489 <row topline="true">
29490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29491 \begin_inset Text
29492
29493 \begin_layout Standard
29494 SIG_INT0
29495 \end_layout
29496
29497 \end_inset
29498 </cell>
29499 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29500 \begin_inset Text
29501
29502 \begin_layout Standard
29503 INT0 external interrupt
29504 \end_layout
29505
29506 \end_inset
29507 </cell>
29508 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29509 \begin_inset Text
29510
29511 \begin_layout Standard
29512 SIG_BCOL
29513 \end_layout
29514
29515 \end_inset
29516 </cell>
29517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29518 \begin_inset Text
29519
29520 \begin_layout Standard
29521 Bus collision interrupt
29522 \end_layout
29523
29524 \end_inset
29525 </cell>
29526 </row>
29527 <row topline="true">
29528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29529 \begin_inset Text
29530
29531 \begin_layout Standard
29532 SIG_INT1
29533 \end_layout
29534
29535 \end_inset
29536 </cell>
29537 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29538 \begin_inset Text
29539
29540 \begin_layout Standard
29541 INT1 external interrupt
29542 \end_layout
29543
29544 \end_inset
29545 </cell>
29546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29547 \begin_inset Text
29548
29549 \begin_layout Standard
29550 SIG_LVD
29551 \end_layout
29552
29553 \end_inset
29554 </cell>
29555 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29556 \begin_inset Text
29557
29558 \begin_layout Standard
29559 Low voltage detect interrupt
29560 \end_layout
29561
29562 \end_inset
29563 </cell>
29564 </row>
29565 <row topline="true">
29566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29567 \begin_inset Text
29568
29569 \begin_layout Standard
29570 SIG_INT2
29571 \end_layout
29572
29573 \end_inset
29574 </cell>
29575 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29576 \begin_inset Text
29577
29578 \begin_layout Standard
29579 INT2 external interrupt
29580 \end_layout
29581
29582 \end_inset
29583 </cell>
29584 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29585 \begin_inset Text
29586
29587 \begin_layout Standard
29588 SIG_PSP
29589 \end_layout
29590
29591 \end_inset
29592 </cell>
29593 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29594 \begin_inset Text
29595
29596 \begin_layout Standard
29597 Parallel slave port interrupt
29598 \end_layout
29599
29600 \end_inset
29601 </cell>
29602 </row>
29603 <row topline="true">
29604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29605 \begin_inset Text
29606
29607 \begin_layout Standard
29608 SIG_CCP1
29609 \end_layout
29610
29611 \end_inset
29612 </cell>
29613 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29614 \begin_inset Text
29615
29616 \begin_layout Standard
29617 CCP1 module interrupt
29618 \end_layout
29619
29620 \end_inset
29621 </cell>
29622 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29623 \begin_inset Text
29624
29625 \begin_layout Standard
29626 SIG_AD
29627 \end_layout
29628
29629 \end_inset
29630 </cell>
29631 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29632 \begin_inset Text
29633
29634 \begin_layout Standard
29635 AD convertion complete interrupt
29636 \end_layout
29637
29638 \end_inset
29639 </cell>
29640 </row>
29641 <row topline="true">
29642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29643 \begin_inset Text
29644
29645 \begin_layout Standard
29646 SIG_CCP2
29647 \end_layout
29648
29649 \end_inset
29650 </cell>
29651 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29652 \begin_inset Text
29653
29654 \begin_layout Standard
29655 CCP2 module interrupt
29656 \end_layout
29657
29658 \end_inset
29659 </cell>
29660 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29661 \begin_inset Text
29662
29663 \begin_layout Standard
29664 SIG_RC
29665 \end_layout
29666
29667 \end_inset
29668 </cell>
29669 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29670 \begin_inset Text
29671
29672 \begin_layout Standard
29673 USART receive interrupt
29674 \end_layout
29675
29676 \end_inset
29677 </cell>
29678 </row>
29679 <row topline="true">
29680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29681 \begin_inset Text
29682
29683 \begin_layout Standard
29684 SIG_TMR0
29685 \end_layout
29686
29687 \end_inset
29688 </cell>
29689 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29690 \begin_inset Text
29691
29692 \begin_layout Standard
29693 TMR0 overflow interrupt
29694 \end_layout
29695
29696 \end_inset
29697 </cell>
29698 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29699 \begin_inset Text
29700
29701 \begin_layout Standard
29702 SIG_TX
29703 \end_layout
29704
29705 \end_inset
29706 </cell>
29707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29708 \begin_inset Text
29709
29710 \begin_layout Standard
29711 USART transmit interrupt
29712 \end_layout
29713
29714 \end_inset
29715 </cell>
29716 </row>
29717 <row topline="true">
29718 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29719 \begin_inset Text
29720
29721 \begin_layout Standard
29722 SIG_TMR1
29723 \end_layout
29724
29725 \end_inset
29726 </cell>
29727 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29728 \begin_inset Text
29729
29730 \begin_layout Standard
29731 TMR1 overflow interrupt
29732 \end_layout
29733
29734 \end_inset
29735 </cell>
29736 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29737 \begin_inset Text
29738
29739 \begin_layout Standard
29740 SIG_MSSP
29741 \end_layout
29742
29743 \end_inset
29744 </cell>
29745 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29746 \begin_inset Text
29747
29748 \begin_layout Standard
29749 SSP receive/transmit interrupt
29750 \end_layout
29751
29752 \end_inset
29753 </cell>
29754 </row>
29755 <row topline="true">
29756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29757 \begin_inset Text
29758
29759 \begin_layout Standard
29760 SIG_TMR2
29761 \end_layout
29762
29763 \end_inset
29764 </cell>
29765 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29766 \begin_inset Text
29767
29768 \begin_layout Standard
29769 TMR2 matches PR2 interrupt
29770 \end_layout
29771
29772 \end_inset
29773 </cell>
29774 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29775 \begin_inset Text
29776
29777 \begin_layout Standard
29778
29779 \end_layout
29780
29781 \end_inset
29782 </cell>
29783 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29784 \begin_inset Text
29785
29786 \begin_layout Standard
29787
29788 \end_layout
29789
29790 \end_inset
29791 </cell>
29792 </row>
29793 <row topline="true" bottomline="true">
29794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29795 \begin_inset Text
29796
29797 \begin_layout Standard
29798 SIG_TMR3
29799 \end_layout
29800
29801 \end_inset
29802 </cell>
29803 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29804 \begin_inset Text
29805
29806 \begin_layout Standard
29807 TMR3 overflow interrupt
29808 \end_layout
29809
29810 \end_inset
29811 </cell>
29812 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29813 \begin_inset Text
29814
29815 \begin_layout Standard
29816
29817 \end_layout
29818
29819 \end_inset
29820 </cell>
29821 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29822 \begin_inset Text
29823
29824 \begin_layout Standard
29825
29826 \end_layout
29827
29828 \end_inset
29829 </cell>
29830 </row>
29831 </lyxtabular>
29832
29833 \end_inset
29834
29835
29836 \end_layout
29837
29838 \begin_layout Standard
29839 \noindent
29840 The prototypes for these names are defined in the header file 
29841 \emph on
29842 signal.h
29843 \emph default
29844  .
29845 \end_layout
29846
29847 \begin_layout Standard
29848 \noindent
29849 In order to simplify signal handling, a number of macros is provided:
29850 \end_layout
29851
29852 \begin_layout List
29853 \labelwidthstring 00.00.0000
29854 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
29855  high priority interrupts.
29856  
29857 \emph on
29858 name
29859 \emph default
29860  is the function name to use.
29861 \end_layout
29862
29863 \begin_layout List
29864 \labelwidthstring 00.00.0000
29865 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
29866  low priority interrupt.
29867  
29868 \emph on
29869 name
29870 \emph default
29871  is the function name to use.
29872 \end_layout
29873
29874 \begin_layout List
29875 \labelwidthstring 00.00.0000
29876 DEF_HANDLER(sig,handler) define a handler for signal 
29877 \emph on
29878 sig.
29879 \end_layout
29880
29881 \begin_layout List
29882 \labelwidthstring 00.00.0000
29883 END_DEF end the declaration of the dispatch table.
29884 \end_layout
29885
29886 \begin_layout Standard
29887 Additionally there are two more macros to simplify the declaration of the
29888  signal handler:
29889 \end_layout
29890
29891 \begin_layout List
29892 \labelwidthstring 00.00.0000
29893
29894 \series medium
29895 SIGHANDLER(handler)
29896 \series default
29897  this declares the function prototype for the 
29898 \emph on
29899 handler
29900 \emph default
29901  function.
29902 \end_layout
29903
29904 \begin_layout List
29905 \labelwidthstring 00.00.0000
29906 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
29907 \end_layout
29908
29909 \begin_layout Standard
29910 An example of using the macros above is shown below:
29911 \end_layout
29912
29913 \begin_layout LyX-Code
29914 #include <pic18fregs.h>
29915 \end_layout
29916
29917 \begin_layout LyX-Code
29918 #include <signal.h>
29919 \newline
29920
29921 \newline
29922 DEF_INTHIGH(high_int)
29923 \end_layout
29924
29925 \begin_layout LyX-Code
29926 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
29927 \end_layout
29928
29929 \begin_layout LyX-Code
29930 DEF_HANDLER(SIG_BCOL, _bcol_handler)
29931 \end_layout
29932
29933 \begin_layout LyX-Code
29934 END_DEF
29935 \newline
29936
29937 \newline
29938 SIGHANDLER(_tmr0_handler)
29939 \end_layout
29940
29941 \begin_layout LyX-Code
29942 {
29943 \end_layout
29944
29945 \begin_layout LyX-Code
29946   /* action to be taken when timer 0 overflows */
29947 \end_layout
29948
29949 \begin_layout LyX-Code
29950 }
29951 \newline
29952
29953 \newline
29954 SIGHANDLERNAKED(_bcol_handler)
29955 \end_layout
29956
29957 \begin_layout LyX-Code
29958 {
29959 \end_layout
29960
29961 \begin_layout LyX-Code
29962   _asm
29963 \end_layout
29964
29965 \begin_layout LyX-Code
29966     /* action to be taken when bus collision occurs */
29967 \end_layout
29968
29969 \begin_layout LyX-Code
29970     retfie
29971 \end_layout
29972
29973 \begin_layout LyX-Code
29974  _endasm;
29975 \end_layout
29976
29977 \begin_layout LyX-Code
29978 }
29979 \end_layout
29980
29981 \begin_layout Standard
29982
29983 \series bold
29984 NOTES:
29985 \series default
29986  Special care should be taken when using the above scheme:
29987 \end_layout
29988
29989 \begin_layout Itemize
29990 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
29991 \end_layout
29992
29993 \begin_layout Itemize
29994 when declaring SIGHANDLERNAKED handler never forget to use 
29995 \emph on
29996 retfie
29997 \emph default
29998  for proper returning.
29999 \end_layout
30000
30001 \begin_layout Subsection
30002 PIC16 Port -- Tips
30003 \end_layout
30004
30005 \begin_layout Standard
30006 Here you can find some general tips for compiling programs with SDCC/pic16.
30007 \end_layout
30008
30009 \begin_layout Subsubsection
30010 Stack size
30011 \end_layout
30012
30013 \begin_layout Standard
30014 The default stack
30015 \begin_inset LatexCommand index
30016 name "PIC16!stack"
30017
30018 \end_inset
30019
30020  size (that is 64 bytes) probably is enough for many programs.
30021  One must take care that when there are many levels of function nesting,
30022  or there is excessive usage of stack, its size should be extended.
30023  An example of such a case is the printf/sprintf family of functions.
30024  If you encounter problems like not being able to print integers, then you
30025  need to set the stack size around the maximum (256 for small stack model).
30026  The following diagram shows what happens when calling printf to print an
30027  integer:
30028 \end_layout
30029
30030 \begin_layout LyX-Code
30031 printf () --> ltoa () --> ultoa () --> divschar ()
30032 \end_layout
30033
30034 \begin_layout Standard
30035 It is should be understood that stack is easily consumed when calling complicate
30036 d functions.
30037  Using command line arguments like -
30038 \begin_inset ERT
30039 status collapsed
30040
30041 \begin_layout Standard
30042
30043
30044 \backslash
30045 /
30046 \end_layout
30047
30048 \end_inset
30049
30050 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
30051  stack frames.
30052  Other ways to reduce stack usage may exist.
30053 \end_layout
30054
30055 \begin_layout Subsection
30056 Known Bugs
30057 \end_layout
30058
30059 \begin_layout Subsubsection
30060 Extended Instruction Set
30061 \end_layout
30062
30063 \begin_layout Standard
30064 The PIC16 port emits code which is incompatible with the extended instruction
30065  set available with many newer devices.
30066  Make sure to always explicitly disable it, usually using
30067 \end_layout
30068
30069 \begin_layout Standard
30070
30071 \family typewriter
30072 static __code char __at(__CONFIG4L) conf4l = /* more flags & */ _XINST_OFF_4L;
30073 \end_layout
30074
30075 \begin_layout Standard
30076 \noindent
30077 Some devices (namely 18f2455, 18f2550, 18f4455, and 18f4550) use _ENHCPU_OFF_4L
30078  instead of _XINST_OFF_4L.
30079 \end_layout
30080
30081 \begin_layout Subsubsection
30082 Regression Tests
30083 \end_layout
30084
30085 \begin_layout Standard
30086 The PIC16 port currently passes most but not all of the tests in SDCC's
30087  regression test
30088 \begin_inset LatexCommand index
30089 name "Regression test (PIC16)"
30090
30091 \end_inset
30092
30093  suite (see section 
30094 \begin_inset LatexCommand ref
30095 reference "sec:Quality-control"
30096
30097 \end_inset
30098
30099 ), thus no automatic regression tests are currently performed for the PIC16
30100  target.
30101 \end_layout
30102
30103 \begin_layout Chapter
30104 Debugging
30105 \end_layout
30106
30107 \begin_layout Standard
30108 There are several approaches to debugging your code.
30109  This chapter is meant to show your options and to give detail on some of
30110  them:
30111 \newline
30112
30113 \newline
30114 When writing your code:
30115 \end_layout
30116
30117 \begin_layout Itemize
30118 write your code with debugging in mind (avoid duplicating code, put conceptually
30119  similar variables into structs, use structured code, have strategic points
30120  within your code where all variables are consistent, ...)
30121 \end_layout
30122
30123 \begin_layout Itemize
30124 run a syntax-checking tool like splint
30125 \begin_inset LatexCommand index
30126 name "splint (syntax checking tool)"
30127
30128 \end_inset
30129
30130
30131 \begin_inset LatexCommand index
30132 name "lint (syntax checking tool)"
30133
30134 \end_inset
30135
30136  (see -
30137 \begin_inset ERT
30138 status collapsed
30139
30140 \begin_layout Standard
30141
30142
30143 \backslash
30144 /
30145 \end_layout
30146
30147 \end_inset
30148
30149 -more-pedantic 
30150 \begin_inset LatexCommand ref
30151 reference "lyx:more-pedantic-SPLINT"
30152
30153 \end_inset
30154
30155 ) over the code.
30156 \end_layout
30157
30158 \begin_layout Itemize
30159 for the high level code use a C-compiler (like f.e.
30160  GCC) to compile run and debug the code on your host.
30161  See (see -
30162 \begin_inset ERT
30163 status collapsed
30164
30165 \begin_layout Standard
30166
30167
30168 \backslash
30169 /
30170 \end_layout
30171
30172 \end_inset
30173
30174 -more-pedantic 
30175 \begin_inset LatexCommand ref
30176 reference "lyx:more-pedantic-SPLINT"
30177
30178 \end_inset
30179
30180 ) on how to handle syntax extensions like __xdata, __at(), ...
30181  
30182 \end_layout
30183
30184 \begin_layout Itemize
30185 use another C-compiler to compile code for your target.
30186  Always an option but not recommended:) And not very likely to help you.
30187  If you seriously consider walking this path you should at least occasionally
30188  check portability of your code.
30189  Most commercial compiler vendors will offer an evaluation version so you
30190  can test compile your code or snippets of your code.
30191 \end_layout
30192
30193 \begin_layout Standard
30194 Debugging on a simulator:
30195 \end_layout
30196
30197 \begin_layout Itemize
30198 there is a separate section about SDCDB (section 
30199 \begin_inset LatexCommand ref
30200 reference "cha:Debugging-with-SDCDB"
30201
30202 \end_inset
30203
30204 ) below.
30205 \end_layout
30206
30207 \begin_layout Itemize
30208 or (8051 specific) use a freeware/commercial simulator which interfaces
30209  to the AOMF
30210 \begin_inset LatexCommand index
30211 name "AOMF, AOMF51"
30212
30213 \end_inset
30214
30215  file (see 
30216 \begin_inset LatexCommand ref
30217 reference "OMF file"
30218
30219 \end_inset
30220
30221 ) optionally generated by SDCC.
30222 \end_layout
30223
30224 \begin_layout Standard
30225 Debugging On-target: 
30226 \end_layout
30227
30228 \begin_layout Itemize
30229 use a MCU port pin to serially output debug data to the RS232 port of your
30230  host.
30231  You'll probably want some level shifting device typically involving a MAX232
30232  or similar IC.
30233  If the hardware serial port of the MCU is not available search for 'Software
30234  UART' in your favourite search machine.
30235 \end_layout
30236
30237 \begin_layout Itemize
30238 use an on-target monitor.
30239  In this context a monitor is a small program which usually accepts commands
30240  via a serial line and allows to set program counter, to single step through
30241  a program and read/write memory locations.
30242  For the 8051 good examples of monitors are paulmon and cmon51 (see section
30243  
30244 \begin_inset LatexCommand ref
30245 reference "sec:Related-open-source-tools"
30246
30247 \end_inset
30248
30249 ).
30250 \end_layout
30251
30252 \begin_layout Itemize
30253 toggle MCU port pins at strategic points within your code and use an oscilloscop
30254 e.
30255  A 
30256 \emph on
30257 digital oscilloscope
30258 \emph default
30259
30260 \begin_inset LatexCommand index
30261 name "Oscilloscope"
30262
30263 \end_inset
30264
30265  with deep trace memory is really helpful especially if you have to debug
30266  a realtime application.
30267  If you need to monitor more pins than your oscilloscope provides you can
30268  sometimes get away with a small R-2R network.
30269  On a single channel oscilloscope you could f.e.
30270  monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
30271 k
30272 \begin_inset Formula $\Omega$
30273 \end_inset
30274
30275  resistor and the other one by a 5\InsetSpace ~
30276 k
30277 \begin_inset Formula $\Omega$
30278 \end_inset
30279
30280  resistor to the oscilloscope probe (check output drive capability of the
30281  pins you want to monitor).
30282  If you need to monitor many more pins a 
30283 \emph on
30284 logic analyzer
30285 \emph default
30286  will be handy.
30287 \end_layout
30288
30289 \begin_layout Itemize
30290 use an ICE (
30291 \emph on
30292 i
30293 \emph default
30294
30295 \emph on
30296 c
30297 \emph default
30298 ircuit 
30299 \emph on
30300 e
30301 \emph default
30302 mulator
30303 \begin_inset LatexCommand index
30304 name "ICE (in circuit emulator)"
30305
30306 \end_inset
30307
30308 ).
30309  Usually very expensive.
30310  And very nice to have too.
30311  And usually locks you (for years...) to the devices the ICE can emulate.
30312  
30313 \end_layout
30314
30315 \begin_layout Itemize
30316 use a remote debugger.
30317  In most 8-bit systems the symbol information is not available on the target,
30318  and a complete debugger is too bulky for the target system.
30319  Therefore usually a debugger on the host system connects to an on-target
30320  debugging stub which accepts only primitive commands.
30321  
30322 \newline
30323 Terms to enter into your favourite search engine could be 'remote debugging',
30324  'gdb stub' or 'inferior debugger'.
30325  (is there one?)
30326 \end_layout
30327
30328 \begin_layout Itemize
30329 use an on target hardware debugger.
30330  Some of the more modern MCUs include hardware support for setting break
30331  points and monitoring/changing variables by using dedicated hardware pins.
30332  This facility doesn't require additional code to run on the target and
30333  
30334 \emph on
30335 usually
30336 \emph default
30337  doesn't affect runtime behaviour until a breakpoint is hit.
30338  For the mcs51 most hardware debuggers use the AOMF
30339 \begin_inset LatexCommand index
30340 name "AOMF, AOMF51"
30341
30342 \end_inset
30343
30344  file (see 
30345 \begin_inset LatexCommand ref
30346 reference "OMF file"
30347
30348 \end_inset
30349
30350 ) as input file.
30351  
30352 \end_layout
30353
30354 \begin_layout Standard
30355 Last not least:
30356 \end_layout
30357
30358 \begin_layout Itemize
30359 if you are not familiar with any of the following terms you're likely to
30360  run into problems rather sooner than later: 
30361 \emph on
30362 volatile
30363 \emph default
30364
30365 \emph on
30366 atomic
30367 \emph default
30368
30369 \emph on
30370 memory map
30371 \emph default
30372
30373 \emph on
30374 overlay
30375 \emph default
30376 .
30377  As an embedded programmer you 
30378 \emph on
30379 have
30380 \emph default
30381  to know them so why not look them up 
30382 \emph on
30383 before
30384 \emph default
30385  you have problems?)
30386 \end_layout
30387
30388 \begin_layout Itemize
30389 tell someone else about your problem (actually this is a surprisingly effective
30390  means to hunt down the bug even if the listener is not familiar with your
30391  environment).
30392  As 'failure to communicate' is probably one of the job-induced deformations
30393  of an embedded programmer this is highly encouraged.
30394 \end_layout
30395
30396 \begin_layout Section
30397 Debugging with SDCDB
30398 \begin_inset LatexCommand label
30399 name "cha:Debugging-with-SDCDB"
30400
30401 \end_inset
30402
30403
30404 \begin_inset LatexCommand index
30405 name "SDCDB (debugger)"
30406
30407 \end_inset
30408
30409  
30410 \end_layout
30411
30412 \begin_layout Standard
30413 SDCC is distributed with a source level debugger
30414 \begin_inset LatexCommand index
30415 name "Debugger"
30416
30417 \end_inset
30418
30419 .
30420  The debugger uses a command line interface, the command repertoire of the
30421  debugger has been kept as close to gdb
30422 \begin_inset LatexCommand index
30423 name "gdb"
30424
30425 \end_inset
30426
30427  (the GNU debugger) as possible.
30428  The configuration and build process is part of the standard compiler installati
30429 on, which also builds and installs the debugger in the target directory
30430  specified during configuration.
30431  The debugger allows you debug BOTH at the C source and at the ASM source
30432  level.
30433 \end_layout
30434
30435 \begin_layout Subsection
30436 Compiling for Debugging
30437 \end_layout
30438
30439 \begin_layout Standard
30440 The -
30441 \begin_inset ERT
30442 status collapsed
30443
30444 \begin_layout Standard
30445
30446
30447 \backslash
30448 /
30449 \end_layout
30450
30451 \end_inset
30452
30453 -debug
30454 \begin_inset LatexCommand index
30455 name "-\\/-debug"
30456
30457 \end_inset
30458
30459  option must be specified for all files for which debug information is to
30460  be generated.
30461  The compiler generates a .adb file for each of these files.
30462  The linker creates the .cdb
30463 \begin_inset LatexCommand index
30464 name "<file>.cdb"
30465
30466 \end_inset
30467
30468  file from the .adb
30469 \begin_inset LatexCommand index
30470 name "<file>.adb"
30471
30472 \end_inset
30473
30474  files and the address information.
30475  This .cdb is used by the debugger.
30476 \end_layout
30477
30478 \begin_layout Subsection
30479 How the Debugger Works
30480 \end_layout
30481
30482 \begin_layout Standard
30483 When the -
30484 \begin_inset ERT
30485 status collapsed
30486
30487 \begin_layout Standard
30488
30489
30490 \backslash
30491 /
30492 \end_layout
30493
30494 \end_inset
30495
30496 -debug option is specified the compiler generates extra symbol information
30497  some of which are put into the assembler source and some are put into the
30498  .adb file.
30499  Then the linker creates the .cdb file from the individual .adb files with
30500  the address information for the symbols.
30501  The debugger reads the symbolic information generated by the compiler &
30502  the address information generated by the linker.
30503  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
30504  execution is controlled by the debugger.
30505  When a command is issued for the debugger, it translates it into appropriate
30506  commands for the simulator.
30507  (Currently SDCDM only connects to the simulator but 
30508 \emph on
30509 newcdb
30510 \emph default
30511  at 
30512 \begin_inset LatexCommand url
30513 target "http://ec2drv.sf.net/"
30514
30515 \end_inset
30516
30517  is an effort to connect directly to the hardware.) 
30518 \end_layout
30519
30520 \begin_layout Subsection
30521 Starting the Debugger SDCDB
30522 \end_layout
30523
30524 \begin_layout Standard
30525 The debugger can be started using the following command line.
30526  (Assume the file you are debugging has the file name foo).
30527 \newline
30528
30529 \newline
30530
30531 \family sans
30532 \series bold
30533 sdcdb foo
30534 \newline
30535
30536 \family default
30537 \series default
30538
30539 \newline
30540 The debugger will look for the following files.
30541 \end_layout
30542
30543 \begin_layout Itemize
30544 foo.c - the source file.
30545 \end_layout
30546
30547 \begin_layout Itemize
30548 foo.cdb - the debugger symbol information file.
30549 \end_layout
30550
30551 \begin_layout Itemize
30552 foo.ihx - the Intel hex format
30553 \begin_inset LatexCommand index
30554 name "Intel hex format"
30555
30556 \end_inset
30557
30558  object file.
30559 \end_layout
30560
30561 \begin_layout Subsection
30562 SDCDB Command Line Options
30563 \end_layout
30564
30565 \begin_layout Itemize
30566 -
30567 \begin_inset ERT
30568 status collapsed
30569
30570 \begin_layout Standard
30571
30572
30573 \backslash
30574 /
30575 \end_layout
30576
30577 \end_inset
30578
30579 -directory=<source file directory> this option can used to specify the directory
30580  search list.
30581  The debugger will look into the directory list specified for source, cdb
30582  & ihx files.
30583  The items in the directory list must be separated by ':', e.g.
30584  if the source files can be in the directories /home/src1 and /home/src2,
30585  the -
30586 \begin_inset ERT
30587 status collapsed
30588
30589 \begin_layout Standard
30590
30591
30592 \backslash
30593 /
30594 \end_layout
30595
30596 \end_inset
30597
30598 -directory option should be -
30599 \begin_inset ERT
30600 status collapsed
30601
30602 \begin_layout Standard
30603
30604
30605 \backslash
30606 /
30607 \end_layout
30608
30609 \end_inset
30610
30611 -directory=/home/src1:/home/src2.
30612  Note there can be no spaces in the option.
30613  
30614 \end_layout
30615
30616 \begin_layout Itemize
30617 -cd <directory> - change to the <directory>.
30618 \end_layout
30619
30620 \begin_layout Itemize
30621 -fullname - used by GUI front ends.
30622 \end_layout
30623
30624 \begin_layout Itemize
30625 -cpu <cpu-type> - this argument is passed to the simulator please see the
30626  simulator docs for details.
30627 \end_layout
30628
30629 \begin_layout Itemize
30630 -X <Clock frequency > this options is passed to the simulator please see
30631  the simulator docs for details.
30632 \end_layout
30633
30634 \begin_layout Itemize
30635 -s <serial port file> passed to simulator see the simulator docs for details.
30636 \end_layout
30637
30638 \begin_layout Itemize
30639 -S <serial in,out> passed to simulator see the simulator docs for details.
30640 \end_layout
30641
30642 \begin_layout Itemize
30643 -k <port number> passed to simulator see the simulator docs for details.
30644 \end_layout
30645
30646 \begin_layout Subsection
30647 SDCDB Debugger Commands
30648 \end_layout
30649
30650 \begin_layout Standard
30651 As mentioned earlier the command interface for the debugger has been deliberatel
30652 y kept as close the GNU debugger gdb, as possible.
30653  This will help the integration with existing graphical user interfaces
30654  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
30655  If you use a graphical user interface for the debugger you can skip this
30656  section.
30657 \end_layout
30658
30659 \begin_layout Subsubsection*
30660 break [line | file:line | function | file:function]
30661 \end_layout
30662
30663 \begin_layout Standard
30664 Set breakpoint at specified line or function:
30665 \newline
30666
30667 \newline
30668
30669 \family sans
30670 \series bold
30671 sdcdb>break 100 
30672 \newline
30673 sdcdb>break foo.c:100
30674 \newline
30675 sdcdb>break funcfoo
30676 \newline
30677 sdcdb>break foo.c:funcfoo
30678 \end_layout
30679
30680 \begin_layout Subsubsection*
30681 clear [line | file:line | function | file:function ]
30682 \end_layout
30683
30684 \begin_layout Standard
30685 Clear breakpoint at specified line or function:
30686 \newline
30687
30688 \newline
30689
30690 \family sans
30691 \series bold
30692 sdcdb>clear 100
30693 \newline
30694 sdcdb>clear foo.c:100
30695 \newline
30696 sdcdb>clear funcfoo
30697 \newline
30698 sdcdb>clear foo.c:funcfoo
30699 \end_layout
30700
30701 \begin_layout Subsubsection*
30702 continue
30703 \end_layout
30704
30705 \begin_layout Standard
30706 Continue program being debugged, after breakpoint.
30707 \end_layout
30708
30709 \begin_layout Subsubsection*
30710 finish
30711 \end_layout
30712
30713 \begin_layout Standard
30714 Execute till the end of the current function.
30715 \end_layout
30716
30717 \begin_layout Subsubsection*
30718 delete [n]
30719 \end_layout
30720
30721 \begin_layout Standard
30722 Delete breakpoint number 'n'.
30723  If used without any option clear ALL user defined break points.
30724 \end_layout
30725
30726 \begin_layout Subsubsection*
30727 info [break | stack | frame | registers ]
30728 \end_layout
30729
30730 \begin_layout Itemize
30731 info break - list all breakpoints
30732 \end_layout
30733
30734 \begin_layout Itemize
30735 info stack - show the function call stack.
30736 \end_layout
30737
30738 \begin_layout Itemize
30739 info frame - show information about the current execution frame.
30740 \end_layout
30741
30742 \begin_layout Itemize
30743 info registers - show content of all registers.
30744 \end_layout
30745
30746 \begin_layout Subsubsection*
30747 step
30748 \end_layout
30749
30750 \begin_layout Standard
30751 Step program until it reaches a different source line.
30752  Note: pressing <return> repeats the last command.
30753 \end_layout
30754
30755 \begin_layout Subsubsection*
30756 next
30757 \end_layout
30758
30759 \begin_layout Standard
30760 Step program, proceeding through subroutine calls.
30761 \end_layout
30762
30763 \begin_layout Subsubsection*
30764 run
30765 \end_layout
30766
30767 \begin_layout Standard
30768 Start debugged program.
30769 \end_layout
30770
30771 \begin_layout Subsubsection*
30772 ptype variable 
30773 \end_layout
30774
30775 \begin_layout Standard
30776 Print type information of the variable.
30777 \end_layout
30778
30779 \begin_layout Subsubsection*
30780 print variable
30781 \end_layout
30782
30783 \begin_layout Standard
30784 print value of variable.
30785 \end_layout
30786
30787 \begin_layout Subsubsection*
30788 file filename
30789 \end_layout
30790
30791 \begin_layout Standard
30792 load the given file name.
30793  Note this is an alternate method of loading file for debugging.
30794 \end_layout
30795
30796 \begin_layout Subsubsection*
30797 frame
30798 \end_layout
30799
30800 \begin_layout Standard
30801 print information about current frame.
30802 \end_layout
30803
30804 \begin_layout Subsubsection*
30805 set srcmode
30806 \end_layout
30807
30808 \begin_layout Standard
30809 Toggle between C source & assembly source.
30810 \end_layout
30811
30812 \begin_layout Subsubsection*
30813 ! simulator command
30814 \end_layout
30815
30816 \begin_layout Standard
30817 Send the string following '!' to the simulator, the simulator response is
30818  displayed.
30819  Note the debugger does not interpret the command being sent to the simulator,
30820  so if a command like 'go' is sent the debugger can loose its execution
30821  context and may display incorrect values.
30822 \end_layout
30823
30824 \begin_layout Subsubsection*
30825 quit
30826 \end_layout
30827
30828 \begin_layout Standard
30829 "Watch me now.
30830  Iam going Down.
30831  My name is Bobby Brown"
30832 \end_layout
30833
30834 \begin_layout Subsection
30835 Interfacing SDCDB with DDD
30836 \end_layout
30837
30838 \begin_layout Standard
30839 \begin_inset Note Note
30840 status collapsed
30841
30842 \begin_layout Standard
30843 The screenshot was converted from png to eps with: 
30844 \begin_inset Quotes sld
30845 \end_inset
30846
30847 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
30848 \begin_inset Quotes srd
30849 \end_inset
30850
30851  which produces a pretty compact eps file which is free from compression
30852  artifacts.
30853 \end_layout
30854
30855 \begin_layout Standard
30856 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
30857  as this broke the build system on Sourceforge (pdf-file was broken.
30858  pdflatex does not accept eps files).
30859 \end_layout
30860
30861 \end_inset
30862
30863
30864 \end_layout
30865
30866 \begin_layout Standard
30867 The 
30868 \emph on
30869 p
30870 \emph default
30871 ortable 
30872 \emph on
30873 n
30874 \emph default
30875 etwork 
30876 \emph on
30877 g
30878 \emph default
30879 raphics File 
30880 \size footnotesize
30881
30882 \begin_inset LatexCommand url
30883 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png"
30884
30885 \end_inset
30886
30887
30888 \size default
30889  shows a screenshot of a debugging session with DDD
30890 \begin_inset LatexCommand index
30891 name "DDD (debugger)"
30892
30893 \end_inset
30894
30895  (Unix only) on a simulated 8032.
30896  The debugging session might not run as smoothly as the screenshot suggests.
30897  The debugger allows setting of breakpoints, displaying and changing variables,
30898  single stepping through C and assembler code.
30899  
30900 \newline
30901 The source was compiled with 
30902 \family sans
30903 \series bold
30904
30905 \newline
30906
30907 \newline
30908 sdcc -
30909 \family default
30910 \series default
30911
30912 \begin_inset ERT
30913 status collapsed
30914
30915 \begin_layout Standard
30916
30917
30918 \backslash
30919 /
30920 \end_layout
30921
30922 \end_inset
30923
30924
30925 \family sans
30926 \series bold
30927 -debug ddd_example.c
30928 \family default
30929 \series default
30930  
30931 \family sans
30932 \series bold
30933
30934 \newline
30935
30936 \family default
30937 \series default
30938
30939 \newline
30940 and DDD was invoked with 
30941 \family sans
30942 \series bold
30943
30944 \newline
30945
30946 \newline
30947 ddd -debugger "sdcdb -cpu 8032 ddd_example"
30948 \end_layout
30949
30950 \begin_layout Standard
30951 \begin_inset Note Note
30952 status open
30953
30954 \begin_layout Standard
30955 Check that the double quotes or an apostrophe within the command line survive
30956  the LyX tool chain.
30957  Previously the apostrophes got slanted in the PDF output so a cut and paste
30958  did not work.
30959 \end_layout
30960
30961 \end_inset
30962
30963
30964 \end_layout
30965
30966 \begin_layout Subsection
30967 Interfacing SDCDB with XEmacs
30968 \begin_inset LatexCommand index
30969 name "XEmacs"
30970
30971 \end_inset
30972
30973
30974 \begin_inset LatexCommand index
30975 name "Emacs"
30976
30977 \end_inset
30978
30979
30980 \end_layout
30981
30982 \begin_layout Standard
30983 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
30984  sdcdb.el and sdcdbsrc.el.
30985  These two files can be found in the $(prefix)/bin directory after the installat
30986 ion is complete.
30987  These files need to be loaded into XEmacs for the interface to work.
30988  This can be done at XEmacs startup time by inserting the following into
30989  your '.xemacs' file (which can be found in your HOME directory): 
30990 \newline
30991
30992 \newline
30993
30994 \family typewriter
30995 (load-file sdcdbsrc.el)
30996 \family default
30997  
30998 \newline
30999
31000 \newline
31001 .xemacs is a lisp file so the () around the command is REQUIRED.
31002  The files can also be loaded dynamically while XEmacs is running, set the
31003  environment variable 'EMACSLOADPATH' to the installation bin directory
31004  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
31005  To start the interface enter the following command: 
31006 \newline
31007
31008 \newline
31009
31010 \family sans
31011 \series bold
31012 ESC-x sdcdbsrc
31013 \family default
31014 \series default
31015
31016 \newline
31017
31018 \newline
31019 You will prompted to enter the file name to be debugged.
31020  
31021 \newline
31022
31023 \newline
31024 The command line options that are passed to the simulator directly are
31025  bound to default values in the file sdcdbsrc.el.
31026  The variables are listed below, these values maybe changed as required.
31027 \end_layout
31028
31029 \begin_layout Itemize
31030 sdcdbsrc-cpu-type '51
31031 \end_layout
31032
31033 \begin_layout Itemize
31034 sdcdbsrc-frequency '11059200
31035 \end_layout
31036
31037 \begin_layout Itemize
31038 sdcdbsrc-serial nil
31039 \end_layout
31040
31041 \begin_layout Standard
31042 The following is a list of key mapping for the debugger interface.
31043 \end_layout
31044
31045 \begin_layout Standard
31046 \InsetSpace ~
31047
31048 \family typewriter
31049
31050 \newline
31051 ;;\InsetSpace ~
31052 Current Listing :: 
31053 \newline
31054 ;;key\InsetSpace ~
31055 \InsetSpace ~
31056 \InsetSpace ~
31057 \InsetSpace ~
31058 \InsetSpace ~
31059 \InsetSpace ~
31060 \InsetSpace ~
31061 \InsetSpace ~
31062 \InsetSpace ~
31063 \InsetSpace ~
31064 \InsetSpace ~
31065 \InsetSpace ~
31066 \InsetSpace ~
31067 \InsetSpace ~
31068 binding\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 Comment 
31091 \newline
31092 ;;---\InsetSpace ~
31093 \InsetSpace ~
31094 \InsetSpace ~
31095 \InsetSpace ~
31096 \InsetSpace ~
31097 \InsetSpace ~
31098 \InsetSpace ~
31099 \InsetSpace ~
31100 \InsetSpace ~
31101 \InsetSpace ~
31102 \InsetSpace ~
31103 \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 \InsetSpace ~
31119 \InsetSpace ~
31120 \InsetSpace ~
31121 \InsetSpace ~
31122 \InsetSpace ~
31123 \InsetSpace ~
31124 \InsetSpace ~
31125 \InsetSpace ~
31126 \InsetSpace ~
31127 \InsetSpace ~
31128 -------
31129 \newline
31130 ;; 
31131 \newline
31132 ;;\InsetSpace ~
31133 n\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 \InsetSpace ~
31148 sdcdb-next-fro
31149 m-src\InsetSpace ~
31150 \InsetSpace ~
31151 \InsetSpace ~
31152 \InsetSpace ~
31153 \InsetSpace ~
31154 \InsetSpace ~
31155 \InsetSpace ~
31156 \InsetSpace ~
31157 \InsetSpace ~
31158 \InsetSpace ~
31159 SDCDB next command 
31160 \newline
31161 ;;\InsetSpace ~
31162 b\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 \InsetSpace ~
31176 \InsetSpace ~
31177 sdcdb-back-from-src\InsetSpace ~
31178 \InsetSpace ~
31179 \InsetSpace ~
31180 \InsetSpace ~
31181 \InsetSpace ~
31182 \InsetSpace ~
31183 \InsetSpace ~
31184 \InsetSpace ~
31185 \InsetSpace ~
31186 \InsetSpace ~
31187 SDCDB back command 
31188 \newline
31189 ;;\InsetSpace ~
31190 c\InsetSpace ~
31191 \InsetSpace ~
31192 \InsetSpace ~
31193 \InsetSpace ~
31194 \InsetSpace ~
31195 \InsetSpace ~
31196 \InsetSpace ~
31197 \InsetSpace ~
31198 \InsetSpace ~
31199 \InsetSpace ~
31200 \InsetSpace ~
31201 \InsetSpace ~
31202 \InsetSpace ~
31203 \InsetSpace ~
31204 \InsetSpace ~
31205 sdcdb-cont-f
31206 rom-src\InsetSpace ~
31207 \InsetSpace ~
31208 \InsetSpace ~
31209 \InsetSpace ~
31210 \InsetSpace ~
31211 \InsetSpace ~
31212 \InsetSpace ~
31213 \InsetSpace ~
31214 \InsetSpace ~
31215 \InsetSpace ~
31216 SDCDB continue command
31217 \newline
31218 ;;\InsetSpace ~
31219 s\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 \InsetSpace ~
31233 \InsetSpace ~
31234 sdcdb-step-from-src\InsetSpace ~
31235 \InsetSpace ~
31236 \InsetSpace ~
31237 \InsetSpace ~
31238 \InsetSpace ~
31239 \InsetSpace ~
31240 \InsetSpace ~
31241 \InsetSpace ~
31242 \InsetSpace ~
31243 \InsetSpace ~
31244 SDCDB step command 
31245 \newline
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 sdcdb-w
31263 hatis-c-sexp\InsetSpace ~
31264 \InsetSpace ~
31265 \InsetSpace ~
31266 \InsetSpace ~
31267 \InsetSpace ~
31268 \InsetSpace ~
31269 \InsetSpace ~
31270 \InsetSpace ~
31271 \InsetSpace ~
31272 \InsetSpace ~
31273 SDCDB ptypecommand for data at 
31274 \newline
31275 ;;\InsetSpace ~
31276 \InsetSpace ~
31277 \InsetSpace ~
31278 \InsetSpace ~
31279 \InsetSpace ~
31280 \InsetSpace ~
31281 \InsetSpace ~
31282 \InsetSpace ~
31283 \InsetSpace ~
31284 \InsetSpace ~
31285 \InsetSpace ~
31286 \InsetSpace ~
31287 \InsetSpace ~
31288 \InsetSpace ~
31289 \InsetSpace ~
31290 \InsetSpace ~
31291 \InsetSpace ~
31292 \InsetSpace ~
31293 \InsetSpace ~
31294 \InsetSpace ~
31295 \InsetSpace ~
31296 \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 \InsetSpace ~
31311 \InsetSpace ~
31312 \InsetSpace ~
31313 \InsetSpace ~
31314 \InsetSpace ~
31315 \InsetSpace ~
31316 \InsetSpace ~
31317 \InsetSpace ~
31318 \InsetSpace ~
31319 \InsetSpace ~
31320 \InsetSpace ~
31321 \InsetSpace ~
31322 buffer point 
31323 \newline
31324 ;;\InsetSpace ~
31325 x\InsetSpace ~
31326 \InsetSpace ~
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 sdcdbsrc-delete\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 SDCD
31355 B Delete all breakpoints if no arg 
31356 \newline
31357 ;;\InsetSpace ~
31358 \InsetSpace ~
31359 \InsetSpace ~
31360 \InsetSpace ~
31361 \InsetSpace ~
31362 \InsetSpace ~
31363 \InsetSpace ~
31364 \InsetSpace ~
31365 \InsetSpace ~
31366 \InsetSpace ~
31367 \InsetSpace ~
31368 \InsetSpace ~
31369 \InsetSpace ~
31370 \InsetSpace ~
31371 \InsetSpace ~
31372 \InsetSpace ~
31373 \InsetSpace ~
31374 \InsetSpace ~
31375 \InsetSpace ~
31376 \InsetSpace ~
31377 \InsetSpace ~
31378 \InsetSpace ~
31379 \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 \InsetSpace ~
31393 \InsetSpace ~
31394 \InsetSpace ~
31395 \InsetSpace ~
31396 \InsetSpace ~
31397 \InsetSpace ~
31398 \InsetSpace ~
31399 \InsetSpace ~
31400 \InsetSpace ~
31401 \InsetSpace ~
31402 \InsetSpace ~
31403 \InsetSpace ~
31404 given or delete arg (C-u arg x) 
31405 \newline
31406 ;;\InsetSpace ~
31407 m\InsetSpace ~
31408 \InsetSpace ~
31409 \InsetSpace ~
31410 \InsetSpace ~
31411 \InsetSpace ~
31412 \InsetSpace ~
31413 \InsetSpace ~
31414 \InsetSpace ~
31415 \InsetSpace ~
31416 \InsetSpace ~
31417 \InsetSpace ~
31418 \InsetSpace ~
31419 \InsetSpace ~
31420 \InsetSpace ~
31421 \InsetSpace ~
31422 sdcdbsrc
31423 -frame\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 SDCDB Display current frame if no arg, 
31439 \newline
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 \InsetSpace ~
31458 \InsetSpace ~
31459 \InsetSpace ~
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 given or display frame arg
31488  
31489 \newline
31490 ;;\InsetSpace ~
31491 \InsetSpace ~
31492 \InsetSpace ~
31493 \InsetSpace ~
31494 \InsetSpace ~
31495 \InsetSpace ~
31496 \InsetSpace ~
31497 \InsetSpace ~
31498 \InsetSpace ~
31499 \InsetSpace ~
31500 \InsetSpace ~
31501 \InsetSpace ~
31502 \InsetSpace ~
31503 \InsetSpace ~
31504 \InsetSpace ~
31505 \InsetSpace ~
31506 \InsetSpace ~
31507 \InsetSpace ~
31508 \InsetSpace ~
31509 \InsetSpace ~
31510 \InsetSpace ~
31511 \InsetSpace ~
31512 \InsetSpace ~
31513 \InsetSpace ~
31514 \InsetSpace ~
31515 \InsetSpace ~
31516 \InsetSpace ~
31517 \InsetSpace ~
31518 \InsetSpace ~
31519 \InsetSpace ~
31520 \InsetSpace ~
31521 \InsetSpace ~
31522 \InsetSpace ~
31523 \InsetSpace ~
31524 \InsetSpace ~
31525 \InsetSpace ~
31526 \InsetSpace ~
31527 \InsetSpace ~
31528 \InsetSpace ~
31529 \InsetSpace ~
31530 \InsetSpace ~
31531 \InsetSpace ~
31532 \InsetSpace ~
31533 \InsetSpace ~
31534 \InsetSpace ~
31535 \InsetSpace ~
31536 \InsetSpace ~
31537 buffer point 
31538 \newline
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 \InsetSpace ~
31554 \InsetSpace ~
31555 sdcdbsrc-goto-sdcdb\InsetSpace ~
31556 \InsetSpace ~
31557 \InsetSpace ~
31558 \InsetSpace ~
31559 \InsetSpace ~
31560 \InsetSpace ~
31561 \InsetSpace ~
31562 \InsetSpace ~
31563 \InsetSpace ~
31564 \InsetSpace ~
31565 Goto the SDCDB output buffer 
31566 \newline
31567 ;;\InsetSpace ~
31568 p\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 sdcdb-prin
31584 t-c-sexp\InsetSpace ~
31585 \InsetSpace ~
31586 \InsetSpace ~
31587 \InsetSpace ~
31588 \InsetSpace ~
31589 \InsetSpace ~
31590 \InsetSpace ~
31591 \InsetSpace ~
31592 \InsetSpace ~
31593 \InsetSpace ~
31594 \InsetSpace ~
31595 SDCDB print command for data at 
31596 \newline
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 \InsetSpace ~
31615 \InsetSpace ~
31616 \InsetSpace ~
31617 \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 \InsetSpace ~
31633 \InsetSpace ~
31634 \InsetSpace ~
31635 \InsetSpace ~
31636 \InsetSpace ~
31637 \InsetSpace ~
31638 \InsetSpace ~
31639 \InsetSpace ~
31640 \InsetSpace ~
31641 \InsetSpace ~
31642 \InsetSpace ~
31643 \InsetSpace ~
31644 buffer point 
31645 \newline
31646 ;;\InsetSpace ~
31647 g\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 \InsetSpace ~
31662 sdcdbsrc-goto-sdcdb\InsetSpace ~
31663 \InsetSpace ~
31664 \InsetSpace ~
31665 \InsetSpace ~
31666 \InsetSpace ~
31667 \InsetSpace ~
31668 \InsetSpace ~
31669 \InsetSpace ~
31670 \InsetSpace ~
31671 \InsetSpace ~
31672 Got
31673 o the SDCDB output buffer 
31674 \newline
31675 ;;\InsetSpace ~
31676 t\InsetSpace ~
31677 \InsetSpace ~
31678 \InsetSpace ~
31679 \InsetSpace ~
31680 \InsetSpace ~
31681 \InsetSpace ~
31682 \InsetSpace ~
31683 \InsetSpace ~
31684 \InsetSpace ~
31685 \InsetSpace ~
31686 \InsetSpace ~
31687 \InsetSpace ~
31688 \InsetSpace ~
31689 \InsetSpace ~
31690 \InsetSpace ~
31691 sdcdbsrc-mode\InsetSpace ~
31692 \InsetSpace ~
31693 \InsetSpace ~
31694 \InsetSpace ~
31695 \InsetSpace ~
31696 \InsetSpace ~
31697 \InsetSpace ~
31698 \InsetSpace ~
31699 \InsetSpace ~
31700 \InsetSpace ~
31701 \InsetSpace ~
31702 \InsetSpace ~
31703 \InsetSpace ~
31704 \InsetSpace ~
31705 \InsetSpace ~
31706 \InsetSpace ~
31707 Toggles Sdcdbsrc mode (turns it
31708  off) 
31709 \newline
31710 ;; 
31711 \newline
31712 ;;\InsetSpace ~
31713 C-c\InsetSpace ~
31714 C-f\InsetSpace ~
31715 \InsetSpace ~
31716 \InsetSpace ~
31717 \InsetSpace ~
31718 \InsetSpace ~
31719 \InsetSpace ~
31720 \InsetSpace ~
31721 \InsetSpace ~
31722 \InsetSpace ~
31723 sdcdb-finish-from-src\InsetSpace ~
31724 \InsetSpace ~
31725 \InsetSpace ~
31726 \InsetSpace ~
31727 \InsetSpace ~
31728 \InsetSpace ~
31729 \InsetSpace ~
31730 \InsetSpace ~
31731 SDCDB finish command 
31732 \newline
31733 ;; 
31734 \newline
31735 ;;\InsetSpace ~
31736 C-x\InsetSpace ~
31737 SPC\InsetSpace ~
31738 \InsetSpace ~
31739 \InsetSpace ~
31740 \InsetSpace ~
31741 \InsetSpace ~
31742 \InsetSpace ~
31743 \InsetSpace ~
31744 \InsetSpace ~
31745 \InsetSpace ~
31746 sdcdb-brea
31747 k\InsetSpace ~
31748 \InsetSpace ~
31749 \InsetSpace ~
31750 \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 Set break for line with point 
31766 \newline
31767 ;;\InsetSpace ~
31768 ESC\InsetSpace ~
31769 t\InsetSpace ~
31770 \InsetSpace ~
31771 \InsetSpace ~
31772 \InsetSpace ~
31773 \InsetSpace ~
31774 \InsetSpace ~
31775 \InsetSpace ~
31776 \InsetSpace ~
31777 \InsetSpace ~
31778 \InsetSpace ~
31779 \InsetSpace ~
31780 sdcdbsrc-mode\InsetSpace ~
31781 \InsetSpace ~
31782 \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 \InsetSpace ~
31796 Toggle Sdcdbsrc mode 
31797 \newline
31798 ;;\InsetSpace ~
31799 ESC\InsetSpace ~
31800 m\InsetSpace ~
31801 \InsetSpace ~
31802 \InsetSpace ~
31803 \InsetSpace ~
31804 \InsetSpace ~
31805 \InsetSpace ~
31806 \InsetSpace ~
31807 \InsetSpace ~
31808 \InsetSpace ~
31809 \InsetSpace ~
31810 \InsetSpace ~
31811 sdc
31812 dbsrc-srcmode\InsetSpace ~
31813 \InsetSpace ~
31814 \InsetSpace ~
31815 \InsetSpace ~
31816 \InsetSpace ~
31817 \InsetSpace ~
31818 \InsetSpace ~
31819 \InsetSpace ~
31820 \InsetSpace ~
31821 \InsetSpace ~
31822 \InsetSpace ~
31823 \InsetSpace ~
31824 \InsetSpace ~
31825 Toggle list mode 
31826 \newline
31827 ;; 
31828 \newline
31829
31830 \family default
31831
31832 \newpage
31833
31834 \end_layout
31835
31836 \begin_layout Chapter
31837 TIPS
31838 \end_layout
31839
31840 \begin_layout Standard
31841 Here are a few guidelines that will help the compiler generate more efficient
31842  code, some of the tips are specific to this compiler others are generally
31843  good programming practice.
31844 \end_layout
31845
31846 \begin_layout Itemize
31847 Use the smallest data type to represent your data-value.
31848  If it is known in advance that the value is going to be less than 256 then
31849  use an 'unsigned char' instead of a 'short' or 'int'.
31850  Please note, that ANSI C requires both signed and unsigned chars to be
31851  promoted to 'signed int'
31852 \begin_inset LatexCommand index
31853 name "promotion to signed int"
31854
31855 \end_inset
31856
31857
31858 \begin_inset Marginal
31859 status collapsed
31860
31861 \begin_layout Standard
31862
31863 \series bold
31864 \InsetSpace ~
31865 !
31866 \end_layout
31867
31868 \end_inset
31869
31870  before doing any operation.
31871  This promotion
31872 \begin_inset LatexCommand index
31873 name "type promotion"
31874
31875 \end_inset
31876
31877
31878 \begin_inset LatexCommand label
31879 name "type promotion"
31880
31881 \end_inset
31882
31883  can be omitted, if the result is the same.
31884  The effect of the promotion rules together with the sign-extension is often
31885  surprising:
31886 \end_layout
31887
31888 \begin_deeper
31889 \begin_layout Verse
31890
31891 \family typewriter
31892 unsigned char uc = 0xfe;
31893 \newline
31894 if (uc * uc < 0) /* this is true! */
31895 \newline
31896 {
31897 \newline
31898 \InsetSpace ~
31899 \InsetSpace ~
31900 \InsetSpace ~
31901 \InsetSpace ~
31902 ....
31903 \newline
31904 }
31905 \end_layout
31906
31907 \begin_layout Standard
31908
31909 \family typewriter
31910 uc * uc
31911 \family default
31912  is evaluated as 
31913 \family typewriter
31914 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
31915 \family default
31916 .
31917  
31918 \newline
31919 Another one:
31920 \end_layout
31921
31922 \begin_layout Verse
31923
31924 \family typewriter
31925 (unsigned char) -12 / (signed char) -3 = ...
31926 \end_layout
31927
31928 \begin_layout Standard
31929 No, the result is not 4:
31930 \end_layout
31931
31932 \begin_layout Verse
31933
31934 \family typewriter
31935 (int) (unsigned char) -12 / (int) (signed char) -3 =
31936 \newline
31937 (int) (unsigned char)
31938  0xf4 / (int) (signed char) 0xfd =
31939 \newline
31940 (int) 0x00f4 / (int) 0xfffd =
31941 \newline
31942 (int) 0x00f4
31943  / (int) 0xfffd =
31944 \newline
31945 (int) 244 / (int) -3 =
31946 \newline
31947 (int) -81 = (int) 0xffaf;
31948 \end_layout
31949
31950 \begin_layout Standard
31951 Don't complain, that gcc gives you a different result.
31952  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
31953  Therefore the results are different.
31954 \newline
31955 From 
31956 \begin_inset Quotes sld
31957 \end_inset
31958
31959 comp.lang.c FAQ
31960 \begin_inset Quotes srd
31961 \end_inset
31962
31963 :
31964 \end_layout
31965
31966 \begin_layout Quote
31967
31968 \emph on
31969 If well-defined overflow characteristics are important and negative values
31970  are not, or if you want to steer clear of sign-extension problems when
31971  manipulating bits or bytes, use one of the corresponding unsigned types.
31972  (Beware when mixing signed and unsigned values in expressions, though.)
31973 \newline
31974 Although
31975  character types (especially unsigned char) can be used as "tiny" integers,
31976  doing so is sometimes more trouble than it's worth, due to unpredictable
31977  sign extension and increased code size.
31978 \end_layout
31979
31980 \end_deeper
31981 \begin_layout Itemize
31982 Use unsigned when it is known in advance that the value is not going to
31983  be negative.
31984  This helps especially if you are doing division or multiplication, bit-shifting
31985  or are using an array index.
31986 \end_layout
31987
31988 \begin_layout Itemize
31989 NEVER jump into a LOOP.
31990 \end_layout
31991
31992 \begin_layout Itemize
31993 Declare the variables to be local
31994 \begin_inset LatexCommand index
31995 name "local variables"
31996
31997 \end_inset
31998
31999  whenever possible, especially loop control variables (induction).
32000 \end_layout
32001
32002 \begin_layout Itemize
32003 Have a look at the assembly listing to get a 
32004 \begin_inset Quotes sld
32005 \end_inset
32006
32007 feeling
32008 \begin_inset Quotes srd
32009 \end_inset
32010
32011  for the code generation.
32012 \end_layout
32013
32014 \begin_layout Section
32015 Porting code from or to other compilers
32016 \begin_inset LatexCommand label
32017 name "sec:Porting-code-to-other-compilers"
32018
32019 \end_inset
32020
32021
32022 \end_layout
32023
32024 \begin_layout Itemize
32025 check whether endianness of the compilers differs and adapt where needed.
32026 \end_layout
32027
32028 \begin_layout Itemize
32029 check the device specific header files
32030 \begin_inset LatexCommand index
32031 name "Header files"
32032
32033 \end_inset
32034
32035
32036 \begin_inset LatexCommand index
32037 name "Include files"
32038
32039 \end_inset
32040
32041  for compiler specific syntax.
32042  Eventually include the file <compiler.h
32043 \begin_inset LatexCommand index
32044 name "compiler.h (include file)"
32045
32046 \end_inset
32047
32048
32049 \begin_inset LatexCommand url
32050 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup"
32051
32052 \end_inset
32053
32054  to allow using common header files.
32055  (see f.e.
32056  cc2510fx.h 
32057 \begin_inset LatexCommand url
32058 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup"
32059
32060 \end_inset
32061
32062 ).
32063 \end_layout
32064
32065 \begin_layout Itemize
32066 check whether the startup code contains the correct initialization (watchdog,
32067  peripherals).
32068 \end_layout
32069
32070 \begin_layout Itemize
32071 check whether the sizes of short, int, long match.
32072 \end_layout
32073
32074 \begin_layout Itemize
32075 check if some 16 or 32 bit hardware registers require a specific addressing
32076  order (least significant or most significant byte first) and adapt if needed
32077  (
32078 \emph on
32079 first
32080 \emph default
32081  and 
32082 \emph on
32083 last
32084 \emph default
32085  relate to time and not to lower/upper memory location here, so this is
32086  
32087 \emph on
32088 not
32089 \emph default
32090  the same as endianness).
32091 \end_layout
32092
32093 \begin_layout Itemize
32094 check whether the keyword 
32095 \emph on
32096 volatile
32097 \emph default
32098  is used where needed.
32099  The compilers might differ in their optimization characteristics (as different
32100  versions of the same compiler might also use more clever optimizations
32101  this is good idea anyway).
32102  See section 
32103 \begin_inset LatexCommand ref
32104 reference "sub:Common-interrupt-pitfall-volatile"
32105
32106 \end_inset
32107
32108 .
32109 \end_layout
32110
32111 \begin_layout Itemize
32112 check that the compilers are not told to suppress warnings.
32113 \end_layout
32114
32115 \begin_layout Itemize
32116 check and convert compiler specific extensions (interrupts, memory areas,
32117  pragmas etc.).
32118 \end_layout
32119
32120 \begin_layout Itemize
32121 check for differences in type promotion.
32122  Especially check for math operations on 
32123 \family typewriter
32124 char
32125 \family default
32126  or 
32127 \family typewriter
32128 unsigned char
32129 \family default
32130  variables.
32131  For the sake of C99 compatibility SDCC will probably promote these to 
32132 \family typewriter
32133 int
32134 \family default
32135  more often than other compilers.
32136  Eventually insert explicit casts to 
32137 \family typewriter
32138 (char)
32139 \family default
32140  or 
32141 \family typewriter
32142 (unsigned char)
32143 \family default
32144 .
32145  Also check that the ~\InsetSpace ~
32146 operator
32147 \begin_inset LatexCommand index
32148 name "\\~\\/ Operator"
32149
32150 \end_inset
32151
32152  is not used on 
32153 \family typewriter
32154 bit
32155 \begin_inset LatexCommand index
32156 name "bit"
32157
32158 \end_inset
32159
32160
32161 \family default
32162  variables, use the !\InsetSpace ~
32163 operator instead.
32164  See sections 
32165 \begin_inset LatexCommand ref
32166 reference "type promotion"
32167
32168 \end_inset
32169
32170  and 
32171 \begin_inset LatexCommand ref
32172 reference "sec:Compatibility-with-previous"
32173
32174 \end_inset
32175
32176 .
32177 \end_layout
32178
32179 \begin_layout Itemize
32180 check the assembly code generated for interrupt routines (f.e.
32181  for calls to possibly non-reentrant library functions).
32182 \end_layout
32183
32184 \begin_layout Itemize
32185 check whether timing loops result in proper timing (or preferably consider
32186  a rewrite of the code with timer based delays instead).
32187 \end_layout
32188
32189 \begin_layout Itemize
32190 check for differences in printf parameters (some compilers push (va_arg
32191 \begin_inset LatexCommand index
32192 name "vararg, va\\_arg"
32193
32194 \end_inset
32195
32196 ) char variables as 
32197 \family typewriter
32198 int
32199 \family default
32200  others push them as 
32201 \family typewriter
32202 char
32203 \family default
32204 .
32205  See section 
32206 \begin_inset LatexCommand ref
32207 reference "sec:Compatibility-with-previous"
32208
32209 \end_inset
32210
32211 ).
32212 \end_layout
32213
32214 \begin_layout Itemize
32215 check the resulting memory map
32216 \begin_inset LatexCommand index
32217 name "Memory map"
32218
32219 \end_inset
32220
32221 .
32222  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
32223 ly idata, pdata, xdata).
32224  Eventually check if unexpected library functions are included.
32225 \end_layout
32226
32227 \begin_layout Section
32228 Tools
32229 \begin_inset LatexCommand index
32230 name "Tools"
32231
32232 \end_inset
32233
32234  included in the distribution
32235 \end_layout
32236
32237 \begin_layout Standard
32238 \align left
32239 \begin_inset Tabular
32240 <lyxtabular version="3" rows="12" columns="3">
32241 <features>
32242 <column alignment="left" valignment="top" leftline="true" width="0pt">
32243 <column alignment="left" valignment="top" leftline="true" width="0pt">
32244 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
32245 <row topline="true" bottomline="true">
32246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32247 \begin_inset Text
32248
32249 \begin_layout Standard
32250
32251 \series bold
32252 Name
32253 \end_layout
32254
32255 \end_inset
32256 </cell>
32257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32258 \begin_inset Text
32259
32260 \begin_layout Standard
32261
32262 \series bold
32263 Purpose
32264 \end_layout
32265
32266 \end_inset
32267 </cell>
32268 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32269 \begin_inset Text
32270
32271 \begin_layout Standard
32272
32273 \series bold
32274 Directory
32275 \end_layout
32276
32277 \end_inset
32278 </cell>
32279 </row>
32280 <row topline="true">
32281 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32282 \begin_inset Text
32283
32284 \begin_layout Standard
32285 uCsim
32286 \begin_inset LatexCommand index
32287 name "uCsim"
32288
32289 \end_inset
32290
32291
32292 \end_layout
32293
32294 \end_inset
32295 </cell>
32296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32297 \begin_inset Text
32298
32299 \begin_layout Standard
32300 Simulator for various architectures
32301 \end_layout
32302
32303 \end_inset
32304 </cell>
32305 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32306 \begin_inset Text
32307
32308 \begin_layout Standard
32309 sdcc/sim/ucsim
32310 \end_layout
32311
32312 \end_inset
32313 </cell>
32314 </row>
32315 <row topline="true">
32316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32317 \begin_inset Text
32318
32319 \begin_layout Standard
32320 keil2sdcc.pl
32321 \end_layout
32322
32323 \end_inset
32324 </cell>
32325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32326 \begin_inset Text
32327
32328 \begin_layout Standard
32329 header file
32330 \begin_inset LatexCommand index
32331 name "Header files"
32332
32333 \end_inset
32334
32335
32336 \begin_inset LatexCommand index
32337 name "Include files"
32338
32339 \end_inset
32340
32341  conversion
32342 \end_layout
32343
32344 \end_inset
32345 </cell>
32346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32347 \begin_inset Text
32348
32349 \begin_layout Standard
32350 sdcc/support/scripts
32351 \end_layout
32352
32353 \end_inset
32354 </cell>
32355 </row>
32356 <row topline="true">
32357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32358 \begin_inset Text
32359
32360 \begin_layout Standard
32361 mh2h.c
32362 \end_layout
32363
32364 \end_inset
32365 </cell>
32366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32367 \begin_inset Text
32368
32369 \begin_layout Standard
32370 header file conversion
32371 \end_layout
32372
32373 \end_inset
32374 </cell>
32375 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32376 \begin_inset Text
32377
32378 \begin_layout Standard
32379 sdcc/support/scripts
32380 \end_layout
32381
32382 \end_inset
32383 </cell>
32384 </row>
32385 <row topline="true">
32386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32387 \begin_inset Text
32388
32389 \begin_layout Standard
32390 as-gbz80
32391 \end_layout
32392
32393 \end_inset
32394 </cell>
32395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32396 \begin_inset Text
32397
32398 \begin_layout Standard
32399 Assembler
32400 \end_layout
32401
32402 \end_inset
32403 </cell>
32404 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32405 \begin_inset Text
32406
32407 \begin_layout Standard
32408
32409 \family roman
32410 \series medium
32411 \shape up
32412 \size normal
32413 \emph off
32414 \bar no
32415 \noun off
32416 \color none
32417 sdcc/bin
32418 \end_layout
32419
32420 \end_inset
32421 </cell>
32422 </row>
32423 <row topline="true">
32424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32425 \begin_inset Text
32426
32427 \begin_layout Standard
32428 as-z80
32429 \end_layout
32430
32431 \end_inset
32432 </cell>
32433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32434 \begin_inset Text
32435
32436 \begin_layout Standard
32437 Assembler
32438 \end_layout
32439
32440 \end_inset
32441 </cell>
32442 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32443 \begin_inset Text
32444
32445 \begin_layout Standard
32446
32447 \family roman
32448 \series medium
32449 \shape up
32450 \size normal
32451 \emph off
32452 \bar no
32453 \noun off
32454 \color none
32455 sdcc/bin
32456 \end_layout
32457
32458 \end_inset
32459 </cell>
32460 </row>
32461 <row topline="true">
32462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32463 \begin_inset Text
32464
32465 \begin_layout Standard
32466 asx8051
32467 \end_layout
32468
32469 \end_inset
32470 </cell>
32471 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32472 \begin_inset Text
32473
32474 \begin_layout Standard
32475 Assembler
32476 \end_layout
32477
32478 \end_inset
32479 </cell>
32480 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32481 \begin_inset Text
32482
32483 \begin_layout Standard
32484
32485 \family roman
32486 \series medium
32487 \shape up
32488 \size normal
32489 \emph off
32490 \bar no
32491 \noun off
32492 \color none
32493 sdcc/bin
32494 \end_layout
32495
32496 \end_inset
32497 </cell>
32498 </row>
32499 <row topline="true">
32500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32501 \begin_inset Text
32502
32503 \begin_layout Standard
32504 SDCDB
32505 \end_layout
32506
32507 \end_inset
32508 </cell>
32509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32510 \begin_inset Text
32511
32512 \begin_layout Standard
32513 Simulator
32514 \end_layout
32515
32516 \end_inset
32517 </cell>
32518 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32519 \begin_inset Text
32520
32521 \begin_layout Standard
32522
32523 \family roman
32524 \series medium
32525 \shape up
32526 \size normal
32527 \emph off
32528 \bar no
32529 \noun off
32530 \color none
32531 sdcc/bin
32532 \end_layout
32533
32534 \end_inset
32535 </cell>
32536 </row>
32537 <row topline="true">
32538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32539 \begin_inset Text
32540
32541 \begin_layout Standard
32542 aslink
32543 \end_layout
32544
32545 \end_inset
32546 </cell>
32547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32548 \begin_inset Text
32549
32550 \begin_layout Standard
32551 Linker
32552 \end_layout
32553
32554 \end_inset
32555 </cell>
32556 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32557 \begin_inset Text
32558
32559 \begin_layout Standard
32560
32561 \family roman
32562 \series medium
32563 \shape up
32564 \size normal
32565 \emph off
32566 \bar no
32567 \noun off
32568 \color none
32569 sdcc/bin
32570 \end_layout
32571
32572 \end_inset
32573 </cell>
32574 </row>
32575 <row topline="true">
32576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32577 \begin_inset Text
32578
32579 \begin_layout Standard
32580 link-z80
32581 \end_layout
32582
32583 \end_inset
32584 </cell>
32585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32586 \begin_inset Text
32587
32588 \begin_layout Standard
32589 Linker
32590 \end_layout
32591
32592 \end_inset
32593 </cell>
32594 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32595 \begin_inset Text
32596
32597 \begin_layout Standard
32598
32599 \family roman
32600 \series medium
32601 \shape up
32602 \size normal
32603 \emph off
32604 \bar no
32605 \noun off
32606 \color none
32607 sdcc/bin
32608 \end_layout
32609
32610 \end_inset
32611 </cell>
32612 </row>
32613 <row topline="true">
32614 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32615 \begin_inset Text
32616
32617 \begin_layout Standard
32618 link-gbz80
32619 \end_layout
32620
32621 \end_inset
32622 </cell>
32623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32624 \begin_inset Text
32625
32626 \begin_layout Standard
32627 Linker
32628 \end_layout
32629
32630 \end_inset
32631 </cell>
32632 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32633 \begin_inset Text
32634
32635 \begin_layout Standard
32636
32637 \family roman
32638 \series medium
32639 \shape up
32640 \size normal
32641 \emph off
32642 \bar no
32643 \noun off
32644 \color none
32645 sdcc/bin
32646 \end_layout
32647
32648 \end_inset
32649 </cell>
32650 </row>
32651 <row topline="true" bottomline="true">
32652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32653 \begin_inset Text
32654
32655 \begin_layout Standard
32656 packihx
32657 \end_layout
32658
32659 \end_inset
32660 </cell>
32661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32662 \begin_inset Text
32663
32664 \begin_layout Standard
32665 Intel Hex packer 
32666 \begin_inset LatexCommand index
32667 name "packihx (tool)"
32668
32669 \end_inset
32670
32671
32672 \end_layout
32673
32674 \end_inset
32675 </cell>
32676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32677 \begin_inset Text
32678
32679 \begin_layout Standard
32680
32681 \family roman
32682 \series medium
32683 \shape up
32684 \size normal
32685 \emph off
32686 \bar no
32687 \noun off
32688 \color none
32689 sdcc/bin
32690 \end_layout
32691
32692 \end_inset
32693 </cell>
32694 </row>
32695 </lyxtabular>
32696
32697 \end_inset
32698
32699
32700 \newline
32701
32702 \end_layout
32703
32704 \begin_layout Section
32705 Documentation
32706 \begin_inset LatexCommand index
32707 name "Documentation"
32708
32709 \end_inset
32710
32711  included in the distribution
32712 \end_layout
32713
32714 \begin_layout Standard
32715 \align left
32716 \begin_inset Tabular
32717 <lyxtabular version="3" rows="10" columns="2">
32718 <features>
32719 <column alignment="block" valignment="top" leftline="true" width="40col%">
32720 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
32721 <row topline="true" bottomline="true" endhead="true">
32722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32723 \begin_inset Text
32724
32725 \begin_layout Standard
32726
32727 \series bold
32728 Subject / Title
32729 \end_layout
32730
32731 \end_inset
32732 </cell>
32733 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32734 \begin_inset Text
32735
32736 \begin_layout Standard
32737
32738 \series bold
32739 Filename / Where to get
32740 \end_layout
32741
32742 \end_inset
32743 </cell>
32744 </row>
32745 <row topline="true">
32746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32747 \begin_inset Text
32748
32749 \begin_layout Standard
32750 SDCC Compiler User Guide
32751 \end_layout
32752
32753 \end_inset
32754 </cell>
32755 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32756 \begin_inset Text
32757
32758 \begin_layout Standard
32759 You're reading it right now 
32760 \emph on
32761 \InsetSpace ~
32762 \InsetSpace ~
32763 \InsetSpace ~
32764
32765 \hfill
32766 online at:
32767 \emph default
32768
32769 \newline
32770
32771 \begin_inset LatexCommand url
32772 target "http://sdcc.sourceforge.net/doc/sdccman.pdf"
32773
32774 \end_inset
32775
32776
32777 \end_layout
32778
32779 \end_inset
32780 </cell>
32781 </row>
32782 <row topline="true">
32783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32784 \begin_inset Text
32785
32786 \begin_layout Standard
32787 Changelog of SDCC
32788 \end_layout
32789
32790 \end_inset
32791 </cell>
32792 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32793 \begin_inset Text
32794
32795 \begin_layout Standard
32796 sdcc/Changelog 
32797 \emph on
32798 \InsetSpace ~
32799 \InsetSpace ~
32800 \InsetSpace ~
32801
32802 \hfill
32803 online at:
32804 \emph default
32805
32806 \newline
32807
32808 \begin_inset LatexCommand url
32809 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog"
32810
32811 \end_inset
32812
32813
32814 \end_layout
32815
32816 \end_inset
32817 </cell>
32818 </row>
32819 <row topline="true">
32820 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32821 \begin_inset Text
32822
32823 \begin_layout Standard
32824 ASXXXX
32825 \begin_inset LatexCommand index
32826 name "asXXXX (as-gbz80, as-hc08, asx8051, as-z80)"
32827
32828 \end_inset
32829
32830
32831 \begin_inset LatexCommand index
32832 name "Assembler documentation"
32833
32834 \end_inset
32835
32836  Assemblers and
32837 \newline
32838 ASLINK
32839 \begin_inset LatexCommand index
32840 name "aslink"
32841
32842 \end_inset
32843
32844
32845 \begin_inset LatexCommand index
32846 name "Linker documentation"
32847
32848 \end_inset
32849
32850  Relocating Linker
32851 \end_layout
32852
32853 \end_inset
32854 </cell>
32855 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32856 \begin_inset Text
32857
32858 \begin_layout Standard
32859 sdcc/as/doc/asxhtm.html 
32860 \emph on
32861 \InsetSpace ~
32862 \InsetSpace ~
32863 \InsetSpace ~
32864
32865 \hfill
32866 online at:
32867 \emph default
32868
32869 \newline
32870
32871 \begin_inset LatexCommand url
32872 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html"
32873
32874 \end_inset
32875
32876
32877 \end_layout
32878
32879 \end_inset
32880 </cell>
32881 </row>
32882 <row topline="true">
32883 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32884 \begin_inset Text
32885
32886 \begin_layout Standard
32887 SDCC regression test
32888 \begin_inset LatexCommand index
32889 name "Regression test"
32890
32891 \end_inset
32892
32893
32894 \end_layout
32895
32896 \end_inset
32897 </cell>
32898 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32899 \begin_inset Text
32900
32901 \begin_layout Standard
32902 sdcc/doc/test_suite_spec.pdf 
32903 \emph on
32904 \InsetSpace ~
32905 \InsetSpace ~
32906 \InsetSpace ~
32907
32908 \hfill
32909 online at:
32910 \emph default
32911
32912 \newline
32913
32914 \begin_inset LatexCommand url
32915 target "http://sdcc.sourceforge.net/doc/test_suite_spec.pdf"
32916
32917 \end_inset
32918
32919
32920 \end_layout
32921
32922 \end_inset
32923 </cell>
32924 </row>
32925 <row topline="true">
32926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32927 \begin_inset Text
32928
32929 \begin_layout Standard
32930 Various notes
32931 \end_layout
32932
32933 \end_inset
32934 </cell>
32935 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32936 \begin_inset Text
32937
32938 \begin_layout Standard
32939 sdcc/doc/* 
32940 \emph on
32941 \InsetSpace ~
32942 \InsetSpace ~
32943 \InsetSpace ~
32944
32945 \hfill
32946 online at:
32947 \emph default
32948
32949 \newline
32950
32951 \begin_inset LatexCommand url
32952 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/"
32953
32954 \end_inset
32955
32956
32957 \end_layout
32958
32959 \end_inset
32960 </cell>
32961 </row>
32962 <row topline="true">
32963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32964 \begin_inset Text
32965
32966 \begin_layout Standard
32967 Notes on debugging with SDCDB
32968 \begin_inset LatexCommand index
32969 name "SDCDB (debugger)"
32970
32971 \end_inset
32972
32973
32974 \end_layout
32975
32976 \end_inset
32977 </cell>
32978 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32979 \begin_inset Text
32980
32981 \begin_layout Standard
32982 sdcc/debugger/README 
32983 \emph on
32984 \InsetSpace ~
32985 \InsetSpace ~
32986 \InsetSpace ~
32987
32988 \hfill
32989 online at
32990 \emph default
32991 :
32992 \newline
32993
32994 \begin_inset LatexCommand url
32995 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README"
32996
32997 \end_inset
32998
32999
33000 \end_layout
33001
33002 \end_inset
33003 </cell>
33004 </row>
33005 <row topline="true">
33006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33007 \begin_inset Text
33008
33009 \begin_layout Standard
33010 uCsim
33011 \begin_inset LatexCommand index
33012 name "uCsim"
33013
33014 \end_inset
33015
33016  Software simulator for microcontrollers
33017 \end_layout
33018
33019 \end_inset
33020 </cell>
33021 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33022 \begin_inset Text
33023
33024 \begin_layout Standard
33025
33026 \family roman
33027 \series medium
33028 \shape up
33029 \size normal
33030 \emph off
33031 \bar no
33032 \noun off
33033 \color none
33034 sdcc/sim/ucsim/doc
33035 \family default
33036 \series default
33037 \shape default
33038 \size default
33039 \emph default
33040 \bar default
33041 \noun default
33042 /index.html 
33043 \emph on
33044 \InsetSpace ~
33045 \InsetSpace ~
33046 \InsetSpace ~
33047
33048 \hfill
33049 online at:
33050 \emph default
33051
33052 \newline
33053
33054 \begin_inset LatexCommand url
33055 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html"
33056
33057 \end_inset
33058
33059
33060 \end_layout
33061
33062 \end_inset
33063 </cell>
33064 </row>
33065 <row topline="true">
33066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33067 \begin_inset Text
33068
33069 \begin_layout Standard
33070 Temporary notes on the pic16
33071 \begin_inset LatexCommand index
33072 name "PIC16"
33073
33074 \end_inset
33075
33076  port
33077 \end_layout
33078
33079 \end_inset
33080 </cell>
33081 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33082 \begin_inset Text
33083
33084 \begin_layout Standard
33085 sdcc/src/pic16/NOTES 
33086 \emph on
33087 \InsetSpace ~
33088 \InsetSpace ~
33089 \InsetSpace ~
33090
33091 \hfill
33092 online at:
33093 \newline
33094
33095 \emph default
33096
33097 \begin_inset LatexCommand url
33098 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES"
33099
33100 \end_inset
33101
33102
33103 \end_layout
33104
33105 \end_inset
33106 </cell>
33107 </row>
33108 <row topline="true" bottomline="true">
33109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33110 \begin_inset Text
33111
33112 \begin_layout Standard
33113 SDCC internal documentation (debugging file format)
33114 \end_layout
33115
33116 \end_inset
33117 </cell>
33118 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33119 \begin_inset Text
33120
33121 \begin_layout Standard
33122 sdcc/doc/
33123 \family roman
33124 \series medium
33125 \shape up
33126 \size normal
33127 \emph off
33128 \bar no
33129 \noun off
33130 \color none
33131 cdbfileformat.pd
33132 \family default
33133 \series default
33134 \shape default
33135 \size default
33136 \emph default
33137 \bar default
33138 \noun default
33139
33140 \emph on
33141 \InsetSpace ~
33142 \InsetSpace ~
33143 \InsetSpace ~
33144
33145 \hfill
33146 online at:
33147 \emph default
33148
33149 \newline
33150
33151 \begin_inset LatexCommand url
33152 target "http://sdcc.sourceforge.net/doc/cdbfileformat.pdf"
33153
33154 \end_inset
33155
33156
33157 \end_layout
33158
33159 \end_inset
33160 </cell>
33161 </row>
33162 </lyxtabular>
33163
33164 \end_inset
33165
33166
33167 \newline
33168
33169 \end_layout
33170
33171 \begin_layout Section
33172 Related open source tools
33173 \begin_inset LatexCommand label
33174 name "sec:Related-open-source-tools"
33175
33176 \end_inset
33177
33178
33179 \begin_inset LatexCommand index
33180 name "Related tools"
33181
33182 \end_inset
33183
33184
33185 \end_layout
33186
33187 \begin_layout Standard
33188 \align left
33189 \begin_inset Tabular
33190 <lyxtabular version="3" rows="16" columns="3">
33191 <features>
33192 <column alignment="left" valignment="top" leftline="true" width="0pt">
33193 <column alignment="block" valignment="top" leftline="true" width="30line%">
33194 <column alignment="left" valignment="top" leftline="true" rightline="true" width="40col%">
33195 <row topline="true" bottomline="true">
33196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33197 \begin_inset Text
33198
33199 \begin_layout Standard
33200
33201 \series bold
33202 Name
33203 \end_layout
33204
33205 \end_inset
33206 </cell>
33207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33208 \begin_inset Text
33209
33210 \begin_layout Standard
33211
33212 \series bold
33213 Purpose
33214 \end_layout
33215
33216 \end_inset
33217 </cell>
33218 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33219 \begin_inset Text
33220
33221 \begin_layout Standard
33222
33223 \series bold
33224 Where to get
33225 \end_layout
33226
33227 \end_inset
33228 </cell>
33229 </row>
33230 <row topline="true">
33231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33232 \begin_inset Text
33233
33234 \begin_layout Standard
33235 gpsim
33236 \begin_inset LatexCommand index
33237 name "gpsim (pic simulator)"
33238
33239 \end_inset
33240
33241
33242 \end_layout
33243
33244 \end_inset
33245 </cell>
33246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33247 \begin_inset Text
33248
33249 \begin_layout Standard
33250 PIC simulator
33251 \end_layout
33252
33253 \end_inset
33254 </cell>
33255 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33256 \begin_inset Text
33257
33258 \begin_layout Standard
33259 \begin_inset LatexCommand url
33260 target "http://www.dattalo.com/gnupic/gpsim.html"
33261
33262 \end_inset
33263
33264
33265 \end_layout
33266
33267 \end_inset
33268 </cell>
33269 </row>
33270 <row topline="true">
33271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33272 \begin_inset Text
33273
33274 \begin_layout Standard
33275 gputils
33276 \begin_inset LatexCommand index
33277 name "gputils (pic tools)"
33278
33279 \end_inset
33280
33281
33282 \end_layout
33283
33284 \end_inset
33285 </cell>
33286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33287 \begin_inset Text
33288
33289 \begin_layout Standard
33290 GNU PIC utilities
33291 \end_layout
33292
33293 \end_inset
33294 </cell>
33295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33296 \begin_inset Text
33297
33298 \begin_layout Standard
33299 \begin_inset LatexCommand url
33300 target "http://sourceforge.net/projects/gputils"
33301
33302 \end_inset
33303
33304
33305 \end_layout
33306
33307 \end_inset
33308 </cell>
33309 </row>
33310 <row topline="true">
33311 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33312 \begin_inset Text
33313
33314 \begin_layout Standard
33315 flP5
33316 \end_layout
33317
33318 \end_inset
33319 </cell>
33320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33321 \begin_inset Text
33322
33323 \begin_layout Standard
33324 PIC programmer
33325 \end_layout
33326
33327 \end_inset
33328 </cell>
33329 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33330 \begin_inset Text
33331
33332 \begin_layout Standard
33333 \begin_inset LatexCommand url
33334 target "http://freshmeat.net/projects/flp5/"
33335
33336 \end_inset
33337
33338
33339 \end_layout
33340
33341 \end_inset
33342 </cell>
33343 </row>
33344 <row topline="true">
33345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33346 \begin_inset Text
33347
33348 \begin_layout Standard
33349 ec2drv/newcdb
33350 \end_layout
33351
33352 \end_inset
33353 </cell>
33354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33355 \begin_inset Text
33356
33357 \begin_layout Standard
33358 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
33359  (Unix only)
33360 \end_layout
33361
33362 \end_inset
33363 </cell>
33364 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33365 \begin_inset Text
33366
33367 \begin_layout Standard
33368 \begin_inset LatexCommand url
33369 target "http://sourceforge.net/projects/ec2drv"
33370
33371 \end_inset
33372
33373
33374 \end_layout
33375
33376 \end_inset
33377 </cell>
33378 </row>
33379 <row topline="true">
33380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33381 \begin_inset Text
33382
33383 \begin_layout Standard
33384 indent
33385 \begin_inset LatexCommand index
33386 name "indent (source formatting tool)"
33387
33388 \end_inset
33389
33390
33391 \end_layout
33392
33393 \end_inset
33394 </cell>
33395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33396 \begin_inset Text
33397
33398 \begin_layout Standard
33399 Formats C source - Master of the white spaces
33400 \end_layout
33401
33402 \end_inset
33403 </cell>
33404 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33405 \begin_inset Text
33406
33407 \begin_layout Standard
33408 \begin_inset LatexCommand url
33409 target "http://directory.fsf.org/GNU/indent.html"
33410
33411 \end_inset
33412
33413
33414 \end_layout
33415
33416 \end_inset
33417 </cell>
33418 </row>
33419 <row topline="true">
33420 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33421 \begin_inset Text
33422
33423 \begin_layout Standard
33424 srecord
33425 \begin_inset LatexCommand index
33426 name "srecord (bin, hex, ... tool)"
33427
33428 \end_inset
33429
33430
33431 \end_layout
33432
33433 \end_inset
33434 </cell>
33435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33436 \begin_inset Text
33437
33438 \begin_layout Standard
33439 Object file conversion, checksumming, ...
33440 \end_layout
33441
33442 \end_inset
33443 </cell>
33444 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33445 \begin_inset Text
33446
33447 \begin_layout Standard
33448 \begin_inset LatexCommand url
33449 target "http://sourceforge.net/projects/srecord"
33450
33451 \end_inset
33452
33453
33454 \end_layout
33455
33456 \end_inset
33457 </cell>
33458 </row>
33459 <row topline="true">
33460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33461 \begin_inset Text
33462
33463 \begin_layout Standard
33464 objdump
33465 \begin_inset LatexCommand index
33466 name "objdump (tool)"
33467
33468 \end_inset
33469
33470
33471 \end_layout
33472
33473 \end_inset
33474 </cell>
33475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33476 \begin_inset Text
33477
33478 \begin_layout Standard
33479 Object file conversion, ...
33480 \end_layout
33481
33482 \end_inset
33483 </cell>
33484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33485 \begin_inset Text
33486
33487 \begin_layout Standard
33488 Part of binutils (should be there anyway)
33489 \end_layout
33490
33491 \end_inset
33492 </cell>
33493 </row>
33494 <row topline="true">
33495 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33496 \begin_inset Text
33497
33498 \begin_layout Standard
33499 cmon51
33500 \end_layout
33501
33502 \end_inset
33503 </cell>
33504 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33505 \begin_inset Text
33506
33507 \begin_layout Standard
33508 8051 monitor (hex up-/download, single step, disassemble)
33509 \end_layout
33510
33511 \end_inset
33512 </cell>
33513 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33514 \begin_inset Text
33515
33516 \begin_layout Standard
33517 \begin_inset LatexCommand url
33518 target "http://sourceforge.net/projects/cmon51"
33519
33520 \end_inset
33521
33522
33523 \end_layout
33524
33525 \end_inset
33526 </cell>
33527 </row>
33528 <row topline="true">
33529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33530 \begin_inset Text
33531
33532 \begin_layout Standard
33533 doxygen
33534 \begin_inset LatexCommand index
33535 name "doxygen (source documentation tool)"
33536
33537 \end_inset
33538
33539
33540 \end_layout
33541
33542 \end_inset
33543 </cell>
33544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33545 \begin_inset Text
33546
33547 \begin_layout Standard
33548 Source code documentation system
33549 \end_layout
33550
33551 \end_inset
33552 </cell>
33553 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33554 \begin_inset Text
33555
33556 \begin_layout Standard
33557 \begin_inset LatexCommand url
33558 target "http://www.doxygen.org"
33559
33560 \end_inset
33561
33562
33563 \end_layout
33564
33565 \end_inset
33566 </cell>
33567 </row>
33568 <row topline="true">
33569 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33570 \begin_inset Text
33571
33572 \begin_layout Standard
33573 kdevelop
33574 \end_layout
33575
33576 \end_inset
33577 </cell>
33578 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33579 \begin_inset Text
33580
33581 \begin_layout Standard
33582 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
33583 \end_layout
33584
33585 \end_inset
33586 </cell>
33587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33588 \begin_inset Text
33589
33590 \begin_layout Standard
33591 \begin_inset LatexCommand url
33592 target "http://www.kdevelop.org"
33593
33594 \end_inset
33595
33596
33597 \end_layout
33598
33599 \end_inset
33600 </cell>
33601 </row>
33602 <row topline="true">
33603 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33604 \begin_inset Text
33605
33606 \begin_layout Standard
33607 paulmon
33608 \end_layout
33609
33610 \end_inset
33611 </cell>
33612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33613 \begin_inset Text
33614
33615 \begin_layout Standard
33616 8051 monitor (hex up-/download, single step, disassemble)
33617 \end_layout
33618
33619 \end_inset
33620 </cell>
33621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33622 \begin_inset Text
33623
33624 \begin_layout Standard
33625 \begin_inset LatexCommand url
33626 target "http://www.pjrc.com/tech/8051/paulmon2.html"
33627
33628 \end_inset
33629
33630
33631 \end_layout
33632
33633 \end_inset
33634 </cell>
33635 </row>
33636 <row topline="true">
33637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33638 \begin_inset Text
33639
33640 \begin_layout Standard
33641 splint
33642 \begin_inset LatexCommand index
33643 name "splint (syntax checking tool)"
33644
33645 \end_inset
33646
33647
33648 \end_layout
33649
33650 \end_inset
33651 </cell>
33652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33653 \begin_inset Text
33654
33655 \begin_layout Standard
33656 Statically checks c sources (see 
33657 \begin_inset LatexCommand ref
33658 reference "lyx:more-pedantic-SPLINT"
33659
33660 \end_inset
33661
33662 )
33663 \end_layout
33664
33665 \end_inset
33666 </cell>
33667 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33668 \begin_inset Text
33669
33670 \begin_layout Standard
33671 \begin_inset LatexCommand url
33672 target "http://www.splint.org"
33673
33674 \end_inset
33675
33676
33677 \end_layout
33678
33679 \end_inset
33680 </cell>
33681 </row>
33682 <row topline="true" bottomline="true">
33683 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33684 \begin_inset Text
33685
33686 \begin_layout Standard
33687 ddd
33688 \begin_inset LatexCommand index
33689 name "DDD (debugger)"
33690
33691 \end_inset
33692
33693
33694 \end_layout
33695
33696 \end_inset
33697 </cell>
33698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33699 \begin_inset Text
33700
33701 \begin_layout Standard
33702 Debugger, serves nicely as GUI to SDCDB
33703 \begin_inset LatexCommand index
33704 name "SDCDB (debugger)"
33705
33706 \end_inset
33707
33708  (Unix only)
33709 \end_layout
33710
33711 \end_inset
33712 </cell>
33713 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33714 \begin_inset Text
33715
33716 \begin_layout Standard
33717 \begin_inset LatexCommand url
33718 target "http://www.gnu.org/software/ddd/"
33719
33720 \end_inset
33721
33722
33723 \end_layout
33724
33725 \end_inset
33726 </cell>
33727 </row>
33728 <row bottomline="true">
33729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33730 \begin_inset Text
33731
33732 \begin_layout Standard
33733 d52
33734 \begin_inset LatexCommand index
33735 name "d52"
33736
33737 \end_inset
33738
33739
33740 \begin_inset LatexCommand index
33741 name "d52 (disassembler)"
33742
33743 \end_inset
33744
33745
33746 \end_layout
33747
33748 \end_inset
33749 </cell>
33750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33751 \begin_inset Text
33752
33753 \begin_layout Standard
33754 Disassembler, can count instruction cycles
33755 \begin_inset LatexCommand index
33756 name "instruction cycles (count)"
33757
33758 \end_inset
33759
33760 , use with options -pnd
33761 \end_layout
33762
33763 \end_inset
33764 </cell>
33765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33766 \begin_inset Text
33767
33768 \begin_layout Standard
33769 \begin_inset LatexCommand url
33770 target "http://www.8052.com/users/disasm/"
33771
33772 \end_inset
33773
33774
33775 \end_layout
33776
33777 \end_inset
33778 </cell>
33779 </row>
33780 <row bottomline="true">
33781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33782 \begin_inset Text
33783
33784 \begin_layout Standard
33785 cmake
33786 \begin_inset LatexCommand index
33787 name "cmake"
33788
33789 \end_inset
33790
33791
33792 \end_layout
33793
33794 \end_inset
33795 </cell>
33796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33797 \begin_inset Text
33798
33799 \begin_layout Standard
33800 Cross platform build system, generates Makefiles
33801 \begin_inset LatexCommand index
33802 name "Makefile"
33803
33804 \end_inset
33805
33806  and project workspaces
33807 \begin_inset LatexCommand index
33808 name "project workspace"
33809
33810 \end_inset
33811
33812
33813 \end_layout
33814
33815 \end_inset
33816 </cell>
33817 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33818 \begin_inset Text
33819
33820 \begin_layout Standard
33821 \begin_inset LatexCommand url
33822 target "http://www.cmake.org"
33823
33824 \end_inset
33825
33826  \InsetSpace ~
33827 \InsetSpace ~
33828 \InsetSpace ~
33829 \InsetSpace ~
33830 and a dedicated wiki entry: 
33831 \begin_inset LatexCommand url
33832 target "http://www.cmake.org/Wiki/CmakeSdcc"
33833
33834 \end_inset
33835
33836
33837 \end_layout
33838
33839 \end_inset
33840 </cell>
33841 </row>
33842 </lyxtabular>
33843
33844 \end_inset
33845
33846
33847 \newline
33848
33849 \end_layout
33850
33851 \begin_layout Section
33852 Related documentation / recommended reading
33853 \end_layout
33854
33855 \begin_layout Standard
33856 \align left
33857 \begin_inset Tabular
33858 <lyxtabular version="3" rows="7" columns="3">
33859 <features>
33860 <column alignment="left" valignment="top" leftline="true" width="0pt">
33861 <column alignment="left" valignment="top" leftline="true" width="0">
33862 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
33863 <row topline="true" bottomline="true">
33864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33865 \begin_inset Text
33866
33867 \begin_layout Standard
33868
33869 \series bold
33870 Name
33871 \end_layout
33872
33873 \end_inset
33874 </cell>
33875 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33876 \begin_inset Text
33877
33878 \begin_layout Standard
33879
33880 \series bold
33881 Subject / Title
33882 \end_layout
33883
33884 \end_inset
33885 </cell>
33886 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33887 \begin_inset Text
33888
33889 \begin_layout Standard
33890
33891 \series bold
33892 Where to get
33893 \end_layout
33894
33895 \end_inset
33896 </cell>
33897 </row>
33898 <row topline="true">
33899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33900 \begin_inset Text
33901
33902 \begin_layout Standard
33903
33904 \family roman
33905 \series medium
33906 \shape up
33907 \size normal
33908 \emph off
33909 \bar no
33910 \noun off
33911 \color none
33912 c-refcard.pdf
33913 \end_layout
33914
33915 \end_inset
33916 </cell>
33917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33918 \begin_inset Text
33919
33920 \begin_layout Standard
33921 C Reference Card
33922 \begin_inset LatexCommand index
33923 name "C Reference card"
33924
33925 \end_inset
33926
33927 , 2 pages
33928 \end_layout
33929
33930 \end_inset
33931 </cell>
33932 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33933 \begin_inset Text
33934
33935 \begin_layout Standard
33936 \begin_inset LatexCommand url
33937 target "http://refcards.com/refcards/c/index.html"
33938
33939 \end_inset
33940
33941
33942 \end_layout
33943
33944 \end_inset
33945 </cell>
33946 </row>
33947 <row topline="true">
33948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33949 \begin_inset Text
33950
33951 \begin_layout Standard
33952 c-faq
33953 \end_layout
33954
33955 \end_inset
33956 </cell>
33957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33958 \begin_inset Text
33959
33960 \begin_layout Standard
33961 C-FAQ
33962 \begin_inset LatexCommand index
33963 name "C FAQ"
33964
33965 \end_inset
33966
33967
33968 \end_layout
33969
33970 \end_inset
33971 </cell>
33972 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33973 \begin_inset Text
33974
33975 \begin_layout Standard
33976 \begin_inset LatexCommand url
33977 target "http://www.c-faq.com"
33978
33979 \end_inset
33980
33981
33982 \end_layout
33983
33984 \end_inset
33985 </cell>
33986 </row>
33987 <row topline="true">
33988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33989 \begin_inset Text
33990
33991 \begin_layout Standard
33992 ISO/IEC 9899:TC2
33993 \end_layout
33994
33995 \end_inset
33996 </cell>
33997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33998 \begin_inset Text
33999
34000 \begin_layout Standard
34001 \begin_inset Quotes sld
34002 \end_inset
34003
34004 C-Standard
34005 \begin_inset Quotes srd
34006 \end_inset
34007
34008
34009 \end_layout
34010
34011 \end_inset
34012 </cell>
34013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34014 \begin_inset Text
34015
34016 \begin_layout Standard
34017
34018 \size footnotesize
34019 \begin_inset LatexCommand url
34020 target "http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899"
34021
34022 \end_inset
34023
34024
34025 \end_layout
34026
34027 \end_inset
34028 </cell>
34029 </row>
34030 <row topline="true">
34031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34032 \begin_inset Text
34033
34034 \begin_layout Standard
34035 ISO/IEC DTR 18037
34036 \end_layout
34037
34038 \end_inset
34039 </cell>
34040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34041 \begin_inset Text
34042
34043 \begin_layout Standard
34044 \begin_inset Quotes sld
34045 \end_inset
34046
34047 Extensions for Embedded C
34048 \begin_inset Quotes srd
34049 \end_inset
34050
34051
34052 \end_layout
34053
34054 \end_inset
34055 </cell>
34056 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34057 \begin_inset Text
34058
34059 \begin_layout Standard
34060
34061 \size footnotesize
34062 \begin_inset LatexCommand url
34063 target "http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf"
34064
34065 \end_inset
34066
34067
34068 \end_layout
34069
34070 \end_inset
34071 </cell>
34072 </row>
34073 <row topline="true">
34074 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34075 \begin_inset Text
34076
34077 \begin_layout Standard
34078
34079 \end_layout
34080
34081 \end_inset
34082 </cell>
34083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34084 \begin_inset Text
34085
34086 \begin_layout Standard
34087 Latest datasheet of target CPU
34088 \end_layout
34089
34090 \end_inset
34091 </cell>
34092 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34093 \begin_inset Text
34094
34095 \begin_layout Standard
34096 vendor
34097 \end_layout
34098
34099 \end_inset
34100 </cell>
34101 </row>
34102 <row topline="true" bottomline="true">
34103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34104 \begin_inset Text
34105
34106 \begin_layout Standard
34107
34108 \end_layout
34109
34110 \end_inset
34111 </cell>
34112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34113 \begin_inset Text
34114
34115 \begin_layout Standard
34116 Revision history of datasheet
34117 \end_layout
34118
34119 \end_inset
34120 </cell>
34121 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34122 \begin_inset Text
34123
34124 \begin_layout Standard
34125 vendor
34126 \end_layout
34127
34128 \end_inset
34129 </cell>
34130 </row>
34131 </lyxtabular>
34132
34133 \end_inset
34134
34135
34136 \newline
34137
34138 \end_layout
34139
34140 \begin_layout Section
34141 Application notes specifically for SDCC
34142 \end_layout
34143
34144 \begin_layout Standard
34145 SDCC makes no claims about the completeness of this list and about up-to-datenes
34146 s or correctness of the application notes
34147 \begin_inset LatexCommand index
34148 name "Application notes"
34149
34150 \end_inset
34151
34152 .
34153 \end_layout
34154
34155 \begin_layout Standard
34156 \align left
34157
34158 \size footnotesize
34159 \begin_inset Tabular
34160 <lyxtabular version="3" rows="7" columns="3">
34161 <features>
34162 <column alignment="block" valignment="top" leftline="true" width="17col%">
34163 <column alignment="block" valignment="top" leftline="true" width="27col%">
34164 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
34165 <row topline="true" bottomline="true">
34166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34167 \begin_inset Text
34168
34169 \begin_layout Standard
34170
34171 \series bold
34172 \size footnotesize
34173 Vendor
34174 \end_layout
34175
34176 \end_inset
34177 </cell>
34178 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
34179 \begin_inset Text
34180
34181 \begin_layout Standard
34182
34183 \series bold
34184 \size footnotesize
34185 Subject / Title
34186 \end_layout
34187
34188 \end_inset
34189 </cell>
34190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34191 \begin_inset Text
34192
34193 \begin_layout Standard
34194
34195 \series bold
34196 \size footnotesize
34197 Where to get
34198 \end_layout
34199
34200 \end_inset
34201 </cell>
34202 </row>
34203 <row topline="true">
34204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34205 \begin_inset Text
34206
34207 \begin_layout Standard
34208
34209 \size footnotesize
34210 Maxim / Dallas
34211 \end_layout
34212
34213 \end_inset
34214 </cell>
34215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34216 \begin_inset Text
34217
34218 \begin_layout Standard
34219
34220 \size footnotesize
34221 Using the SDCC Compiler for the DS80C400
34222 \begin_inset LatexCommand index
34223 name "DS80C400"
34224
34225 \end_inset
34226
34227
34228 \end_layout
34229
34230 \end_inset
34231 </cell>
34232 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34233 \begin_inset Text
34234
34235 \begin_layout Standard
34236
34237 \size footnotesize
34238 \begin_inset LatexCommand url
34239 target "http://pdfserv.maxim-ic.com/en/an/AN3346.pdf"
34240
34241 \end_inset
34242
34243
34244 \end_layout
34245
34246 \end_inset
34247 </cell>
34248 </row>
34249 <row topline="true">
34250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34251 \begin_inset Text
34252
34253 \begin_layout Standard
34254
34255 \size footnotesize
34256 Maxim / Dallas
34257 \end_layout
34258
34259 \end_inset
34260 </cell>
34261 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
34262 \begin_inset Text
34263
34264 \begin_layout Standard
34265
34266 \size footnotesize
34267 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
34268 \begin_inset LatexCommand index
34269 name "DS89C4x0"
34270
34271 \end_inset
34272
34273  Family of Microcontrollers
34274 \end_layout
34275
34276 \end_inset
34277 </cell>
34278 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34279 \begin_inset Text
34280
34281 \begin_layout Standard
34282
34283 \size footnotesize
34284 \begin_inset LatexCommand url
34285 target "http://pdfserv.maxim-ic.com/en/an/AN3477.pdf"
34286
34287 \end_inset
34288
34289
34290 \end_layout
34291
34292 \end_inset
34293 </cell>
34294 </row>
34295 <row topline="true">
34296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34297 \begin_inset Text
34298
34299 \begin_layout Standard
34300
34301 \size footnotesize
34302 Silicon Laboratories / Cygnal
34303 \end_layout
34304
34305 \end_inset
34306 </cell>
34307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34308 \begin_inset Text
34309
34310 \begin_layout Standard
34311
34312 \size footnotesize
34313 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
34314 \begin_inset LatexCommand index
34315 name "IDE"
34316
34317 \end_inset
34318
34319
34320 \end_layout
34321
34322 \end_inset
34323 </cell>
34324 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34325 \begin_inset Text
34326
34327 \begin_layout Standard
34328
34329 \size footnotesize
34330 \begin_inset LatexCommand url
34331 target "http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf"
34332
34333 \end_inset
34334
34335
34336 \end_layout
34337
34338 \end_inset
34339 </cell>
34340 </row>
34341 <row topline="true">
34342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34343 \begin_inset Text
34344
34345 \begin_layout Standard
34346
34347 \size footnotesize
34348 Ramtron / Goal Semiconductor
34349 \end_layout
34350
34351 \end_inset
34352 </cell>
34353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34354 \begin_inset Text
34355
34356 \begin_layout Standard
34357
34358 \size footnotesize
34359 Interfacing SDCC to Syn and Textpad
34360 \end_layout
34361
34362 \end_inset
34363 </cell>
34364 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34365 \begin_inset Text
34366
34367 \begin_layout Standard
34368
34369 \size footnotesize
34370 \begin_inset LatexCommand url
34371 target "http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp"
34372
34373 \end_inset
34374
34375
34376 \end_layout
34377
34378 \end_inset
34379 </cell>
34380 </row>
34381 <row topline="true">
34382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34383 \begin_inset Text
34384
34385 \begin_layout Standard
34386
34387 \size footnotesize
34388 Ramtron / Goal Semiconductor
34389 \end_layout
34390
34391 \end_inset
34392 </cell>
34393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34394 \begin_inset Text
34395
34396 \begin_layout Standard
34397
34398 \size footnotesize
34399 Installing and Configuring SDCC and Crimson Editor 
34400 \end_layout
34401
34402 \end_inset
34403 </cell>
34404 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34405 \begin_inset Text
34406
34407 \begin_layout Standard
34408
34409 \size footnotesize
34410 \begin_inset LatexCommand url
34411 target "http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp"
34412
34413 \end_inset
34414
34415
34416 \end_layout
34417
34418 \end_inset
34419 </cell>
34420 </row>
34421 <row topline="true" bottomline="true">
34422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34423 \begin_inset Text
34424
34425 \begin_layout Standard
34426
34427 \size footnotesize
34428 Texas Instruments
34429 \end_layout
34430
34431 \end_inset
34432 </cell>
34433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34434 \begin_inset Text
34435
34436 \begin_layout Standard
34437
34438 \size footnotesize
34439 MSC12xx Programming with SDCC
34440 \end_layout
34441
34442 \end_inset
34443 </cell>
34444 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34445 \begin_inset Text
34446
34447 \begin_layout Standard
34448
34449 \size footnotesize
34450 \begin_inset LatexCommand url
34451 target "http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf"
34452
34453 \end_inset
34454
34455
34456 \end_layout
34457
34458 \end_inset
34459 </cell>
34460 </row>
34461 </lyxtabular>
34462
34463 \end_inset
34464
34465
34466 \end_layout
34467
34468 \begin_layout Section
34469 Some Questions
34470 \end_layout
34471
34472 \begin_layout Standard
34473 Some questions answered, some pointers given - it might be time to in turn
34474  ask 
34475 \emph on
34476 you
34477 \emph default
34478  some questions: 
34479 \end_layout
34480
34481 \begin_layout Itemize
34482 can you solve your project with the selected microcontroller? Would you
34483  find out early or rather late that your target is too small/slow/whatever?
34484  Can you switch to a slightly better device if it doesn't fit?
34485 \end_layout
34486
34487 \begin_layout Itemize
34488 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
34489  and/or another programming language be more adequate? Would an operating
34490  system on the target device help?
34491 \end_layout
34492
34493 \begin_layout Itemize
34494 if you solved the problem, will the marketing department be happy?
34495 \end_layout
34496
34497 \begin_layout Itemize
34498 if the marketing department is happy, will customers be happy?
34499 \end_layout
34500
34501 \begin_layout Itemize
34502 if you're the project manager, marketing department and maybe even the customer
34503  in one person, have you tried to see the project from the outside?
34504 \end_layout
34505
34506 \begin_layout Itemize
34507 is the project done if you think it is done? Or is just that other interface/pro
34508 tocol/feature/configuration/option missing? How about website, manual(s),
34509  internationali(z|s)ation, packaging, labels, 2nd source for components,
34510  electromagnetic compatability/interference, documentation for production,
34511  production test software, update mechanism, patent issues?
34512 \end_layout
34513
34514 \begin_layout Itemize
34515 is your project adequately positioned in that magic triangle: fame, fortune,
34516  fun?
34517 \end_layout
34518
34519 \begin_layout Standard
34520 Maybe not all answers to these questions are known and some answers may
34521  even be 
34522 \emph on
34523 no
34524 \emph default
34525 , nevertheless knowing these questions may help you to avoid burnout
34526 \begin_inset Foot
34527 status open
34528
34529 \begin_layout Standard
34530 burnout is bad for electronic devices, programmers and motorcycle tyres
34531 \end_layout
34532
34533 \end_inset
34534
34535 .
34536  Chances are you didn't want to hear some of them...
34537 \end_layout
34538
34539 \begin_layout Chapter
34540 Support
34541 \begin_inset LatexCommand index
34542 name "Support"
34543
34544 \end_inset
34545
34546
34547 \end_layout
34548
34549 \begin_layout Standard
34550 SDCC has grown to be a large project.
34551  The compiler alone (without the preprocessor, assembler and linker) is
34552  well over 150,000 lines of code (blank stripped).
34553  The open source nature of this project is a key to its continued growth
34554  and support.
34555  You gain the benefit and support of many active software developers and
34556  end users.
34557  Is SDCC perfect? No, that's why we need your help.
34558  The developers take pride in fixing reported bugs.
34559  You can help by reporting the bugs and helping other SDCC users.
34560  There are lots of ways to contribute, and we encourage you to take part
34561  in making SDCC a great software package.
34562  
34563 \end_layout
34564
34565 \begin_layout Standard
34566 The SDCC project is hosted on the SDCC sourceforge site at 
34567 \begin_inset LatexCommand htmlurl
34568 target "http://sourceforge.net/projects/sdcc"
34569
34570 \end_inset
34571
34572 .
34573  You'll find the complete set of mailing lists
34574 \begin_inset LatexCommand index
34575 name "Mailing list(s)"
34576
34577 \end_inset
34578
34579 , forums, bug reporting system, patch submission
34580 \begin_inset LatexCommand index
34581 name "Patch submission"
34582
34583 \end_inset
34584
34585  system, download
34586 \begin_inset LatexCommand index
34587 name "download"
34588
34589 \end_inset
34590
34591  area and Subversion code repository
34592 \begin_inset LatexCommand index
34593 name "Subversion code repository"
34594
34595 \end_inset
34596
34597  there.
34598 \end_layout
34599
34600 \begin_layout Section
34601 Reporting Bugs
34602 \begin_inset LatexCommand index
34603 name "Bug reporting"
34604
34605 \end_inset
34606
34607
34608 \begin_inset LatexCommand index
34609 name "Reporting bugs"
34610
34611 \end_inset
34612
34613
34614 \end_layout
34615
34616 \begin_layout Standard
34617 The recommended way of reporting bugs is using the infrastructure of the
34618  sourceforge site.
34619  You can follow the status of bug reports there and have an overview about
34620  the known bugs.
34621 \end_layout
34622
34623 \begin_layout Standard
34624 Bug reports are automatically forwarded to the developer mailing list and
34625  will be fixed ASAP.
34626  When reporting a bug, it is very useful to include a small test program
34627  (the smaller the better) which reproduces the problem.
34628  If you can isolate the problem by looking at the generated assembly code,
34629  this can be very helpful.
34630  Compiling your program with the -
34631 \begin_inset ERT
34632 status collapsed
34633
34634 \begin_layout Standard
34635
34636
34637 \backslash
34638 /
34639 \end_layout
34640
34641 \end_inset
34642
34643 -dumpall
34644 \begin_inset LatexCommand index
34645 name "-\\/-dumpall"
34646
34647 \end_inset
34648
34649  option can sometimes be useful in locating optimization problems.
34650  When reporting a bug please make sure you:
34651 \end_layout
34652
34653 \begin_layout Enumerate
34654 Attach the code you are compiling with SDCC.
34655  
34656 \end_layout
34657
34658 \begin_layout Enumerate
34659 Specify the exact command you use to run SDCC, or attach your Makefile.
34660  
34661 \end_layout
34662
34663 \begin_layout Enumerate
34664 Specify the SDCC version (type "
34665 \family sans
34666 \series bold
34667 sdcc -v
34668 \family default
34669 \series default
34670 "), your platform, and operating system.
34671  
34672 \end_layout
34673
34674 \begin_layout Enumerate
34675 Provide an exact copy of any error message or incorrect output.
34676  
34677 \end_layout
34678
34679 \begin_layout Enumerate
34680 Put something meaningful in the subject of your message.
34681 \end_layout
34682
34683 \begin_layout Standard
34684 Please attempt to include these 5 important parts, as applicable, in all
34685  requests for support or when reporting any problems or bugs with SDCC.
34686  Though this will make your message lengthy, it will greatly improve your
34687  chance that SDCC users and developers will be able to help you.
34688  Some SDCC developers are frustrated by bug reports without code provided
34689  that they can use to reproduce and ultimately fix the problem, so please
34690  be sure to provide sample code if you are reporting a bug! 
34691 \end_layout
34692
34693 \begin_layout Standard
34694 Please have a short check that you are using a recent version of SDCC and
34695  the bug is not yet known.
34696  This is the link for reporting bugs: 
34697 \begin_inset LatexCommand htmlurl
34698 target "http://sourceforge.net/tracker/?group_id=599&atid=100599"
34699
34700 \end_inset
34701
34702 .
34703  With SDCC on average having more than 200 downloads
34704 \begin_inset LatexCommand index
34705 name "download"
34706
34707 \end_inset
34708
34709  on sourceforge per day
34710 \begin_inset Foot
34711 status open
34712
34713 \begin_layout Standard
34714 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
34715  between 2002 and 2005.
34716  This does not include other methods of distribution.
34717 \end_layout
34718
34719 \end_inset
34720
34721  there must be some users.
34722  So it's not exactly easy to find a new bug.
34723  If you find one we need it: 
34724 \emph on
34725 reporting bugs is good
34726 \emph default
34727 .
34728 \end_layout
34729
34730 \begin_layout Section
34731 Requesting Features
34732 \begin_inset LatexCommand label
34733 name "sub:Requesting-Features"
34734
34735 \end_inset
34736
34737
34738 \begin_inset LatexCommand index
34739 name "Feature request"
34740
34741 \end_inset
34742
34743
34744 \begin_inset LatexCommand index
34745 name "Requesting features"
34746
34747 \end_inset
34748
34749
34750 \end_layout
34751
34752 \begin_layout Standard
34753 Like bug reports feature requests are forwarded to the developer mailing
34754  list.
34755  This is the link for requesting features: 
34756 \begin_inset LatexCommand htmlurl
34757 target "http://sourceforge.net/tracker/?group_id=599&atid=350599"
34758
34759 \end_inset
34760
34761 .
34762 \end_layout
34763
34764 \begin_layout Section
34765 Submitting patches
34766 \end_layout
34767
34768 \begin_layout Standard
34769 Like bug reports contributed patches are forwarded to the developer mailing
34770  list.
34771  This is the link for submitting patches
34772 \begin_inset LatexCommand index
34773 name "Patch submission"
34774
34775 \end_inset
34776
34777
34778 \begin_inset LatexCommand url
34779 target "http://sourceforge.net/tracker/?group_id=599&atid=300599"
34780
34781 \end_inset
34782
34783 .
34784 \end_layout
34785
34786 \begin_layout Standard
34787 You need to specify some parameters to the 
34788 \family typewriter
34789 diff
34790 \family default
34791  command for the patches to be useful.
34792  If you modified more than one file a patch created f.e.
34793  with 
34794 \family sans
34795 \series bold
34796
34797 \begin_inset Quotes sld
34798 \end_inset
34799
34800 diff -Naur unmodified_directory modified_directory >my_changes.patch
34801 \begin_inset Quotes srd
34802 \end_inset
34803
34804
34805 \family default
34806 \series default
34807  will be fine, otherwise 
34808 \family sans
34809 \series bold
34810
34811 \begin_inset Quotes sld
34812 \end_inset
34813
34814 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
34815 \begin_inset Quotes srd
34816 \end_inset
34817
34818
34819 \family default
34820 \series default
34821  will do.
34822 \end_layout
34823
34824 \begin_layout Section
34825 Getting Help
34826 \end_layout
34827
34828 \begin_layout Standard
34829 These links should take you directly to the 
34830 \begin_inset LatexCommand url
34831 name "Mailing lists"
34832 target "http://sourceforge.net/mail/?group_id=599"
34833
34834 \end_inset
34835
34836
34837 \begin_inset Foot
34838 status open
34839
34840 \begin_layout Standard
34841 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
34842  automated messages (mid 2003)
34843 \end_layout
34844
34845 \end_inset
34846
34847  and the 
34848 \begin_inset LatexCommand url
34849 name "Forums"
34850 target "http://sourceforge.net/forum/?group_id=599"
34851
34852 \end_inset
34853
34854 , lists
34855 \begin_inset LatexCommand index
34856 name "Mailing list(s)"
34857
34858 \end_inset
34859
34860  and forums are archived and searchable so if you are lucky someone already
34861  had a similar problem.
34862  While mails to the lists themselves are delivered promptly their web front
34863  end on sourceforge sometimes shows a severe time lag (up to several weeks),
34864  if you're seriously using SDCC please consider subscribing to the lists.
34865 \end_layout
34866
34867 \begin_layout Section
34868 ChangeLog
34869 \end_layout
34870
34871 \begin_layout Standard
34872 You can follow the status of the Subversion version
34873 \begin_inset LatexCommand index
34874 name "version"
34875
34876 \end_inset
34877
34878  of SDCC by watching the Changelog
34879 \begin_inset LatexCommand index
34880 name "Changelog"
34881
34882 \end_inset
34883
34884  in the Subversion repository
34885 \size footnotesize
34886  
34887 \begin_inset LatexCommand htmlurl
34888 target "http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog"
34889
34890 \end_inset
34891
34892 .
34893 \end_layout
34894
34895 \begin_layout Section
34896 Subversion Source Code Repository
34897 \end_layout
34898
34899 \begin_layout Standard
34900 The output of 
34901 \family sans
34902 \series bold
34903 sdcc -
34904 \family default
34905
34906 \begin_inset ERT
34907 status open
34908
34909 \begin_layout Standard
34910
34911
34912 \backslash
34913 /
34914 \end_layout
34915
34916 \end_inset
34917
34918
34919 \family sans
34920 -version
34921 \family default
34922 \series default
34923  or the filenames of the snapshot versions of SDCC include date and its
34924  Subversion
34925 \begin_inset LatexCommand index
34926 name "Subversion code repository"
34927
34928 \end_inset
34929
34930  number.
34931  Subversion allows to download the source of recent or previous versions
34932  
34933 \begin_inset LatexCommand url
34934 target "http://sourceforge.net/svn/?group_id=599"
34935
34936 \end_inset
34937
34938  (by number or by date).
34939  An on-line source code browser and detailled instructions are also available
34940  there.
34941  SDCC versions starting from 1999 up to now are available (currently the
34942  versions prior to the conversion from cvs
34943 \begin_inset LatexCommand index
34944 name "cvs|see{Subversion}"
34945
34946 \end_inset
34947
34948  to Subversion (April 2006) are either by accessible by Subversion or by
34949  cvs).
34950 \end_layout
34951
34952 \begin_layout Section
34953 Release policy
34954 \begin_inset LatexCommand index
34955 name "Release policy"
34956
34957 \end_inset
34958
34959
34960 \end_layout
34961
34962 \begin_layout Standard
34963 Historically there often were long delays between official releases and
34964  the sourceforge download area tends to get not updated at all.
34965  Excuses in the past might have referred to problems with live range analysis,
34966  but as this was fixed a while ago, the current problem is that another
34967  excuse has to be found.
34968  Kidding aside, we have to get better there! On the other hand there are
34969  daily snapshots available at 
34970 \begin_inset LatexCommand htmlurl
34971 name "snap"
34972 target "http://sdcc.sourceforge.net/snap.php"
34973
34974 \end_inset
34975
34976 , and you can always build the very last version (hopefully with many bugs
34977  fixed, and features added) from the source code available at 
34978 \begin_inset LatexCommand htmlurl
34979 name "Source"
34980 target "http://sdcc.sourceforge.net/snap.php#Source"
34981
34982 \end_inset
34983
34984 .
34985  The SDCC Wiki
34986 \begin_inset LatexCommand index
34987 name "wiki"
34988
34989 \end_inset
34990
34991
34992 \begin_inset LatexCommand index
34993 name "SDCC Wiki"
34994
34995 \end_inset
34996
34997  at 
34998 \begin_inset LatexCommand url
34999 target "http://sdcc.wiki.sourceforge.net/"
35000
35001 \end_inset
35002
35003  also holds some information about past and future releases.
35004 \end_layout
35005
35006 \begin_layout Section
35007 Examples
35008 \begin_inset LatexCommand index
35009 name "Examples"
35010
35011 \end_inset
35012
35013
35014 \end_layout
35015
35016 \begin_layout Standard
35017 You'll find some small examples in the directory 
35018 \emph on
35019 sdcc/device/examples/.
35020
35021 \emph default
35022  More examples and libraries are available at 
35023 \emph on
35024 The SDCC Open Knowledge Resource 
35025 \begin_inset LatexCommand url
35026 target "http://sdccokr.dl9sec.de/"
35027
35028 \end_inset
35029
35030
35031 \emph default
35032  web site or at 
35033 \begin_inset LatexCommand url
35034 target "http://www.pjrc.com/tech/8051/"
35035
35036 \end_inset
35037
35038 .
35039 \end_layout
35040
35041 \begin_layout Standard
35042 \begin_inset Note Note
35043 status collapsed
35044
35045 \begin_layout Standard
35046 I did insert a reference to Paul's web site here although it seems rather
35047  dedicated to a specific 8032 board (I think it's okay because it f.e.
35048  shows LCD/Harddisc interface and has a free 8051 monitor.
35049  Independent 8032 board vendors face hard competition of heavily subsidized
35050  development boards anyway).
35051 \end_layout
35052
35053 \begin_layout Standard
35054 Maybe we should include some links to real world applications.
35055  Preferably pointer to pointers (one for each architecture) so this stays
35056  manageable here?
35057 \end_layout
35058
35059 \end_inset
35060
35061
35062 \end_layout
35063
35064 \begin_layout Section
35065 Quality control
35066 \begin_inset LatexCommand label
35067 name "sec:Quality-control"
35068
35069 \end_inset
35070
35071
35072 \begin_inset LatexCommand index
35073 name "Quality control"
35074
35075 \end_inset
35076
35077
35078 \end_layout
35079
35080 \begin_layout Standard
35081 The compiler is passed through snaphot build compile and build checks.
35082  The so called 
35083 \shape italic
35084 regression tests
35085 \shape default
35086
35087 \begin_inset LatexCommand index
35088 name "Regression test"
35089
35090 \end_inset
35091
35092  check that SDCC itself compiles flawlessly on several host platforms (i386,
35093  Opteron, 64 bit Alpha, ppc64, Mac OS X on ppc and i386, Solaris on Sparc)
35094  and checks the quality of the code generated by SDCC by running the code
35095  for several target platforms through simulators.
35096  The regression test suite comprises more than 100 files which expand to
35097  more than 500 test cases which include more than 4500 tests.
35098  The results of these tests are published daily on SDCC's snapshot page
35099  (click on the red or green symbols on the right side of 
35100 \begin_inset LatexCommand url
35101 target "http://sdcc.sourceforge.net/snap.php"
35102
35103 \end_inset
35104
35105 ).
35106 \end_layout
35107
35108 \begin_layout Standard
35109 There is a separate document 
35110 \shape italic
35111 test_suite.pdf 
35112 \begin_inset LatexCommand index
35113 name "Test suite"
35114
35115 \end_inset
35116
35117
35118 \shape default
35119  
35120 \begin_inset LatexCommand url
35121 target "http://sdcc.sourceforge.net/doc/test_suite_spec.pdf"
35122
35123 \end_inset
35124
35125  about the regression test suite.
35126 \end_layout
35127
35128 \begin_layout Standard
35129 You'll find the test code in the directory 
35130 \shape italic
35131 sdcc/support/regression
35132 \shape default
35133 .
35134  You can run these tests manually by running 
35135 \family sans
35136 make
35137 \family default
35138  in this directory (or f.e.
35139  
35140 \family sans
35141 \series bold
35142
35143 \begin_inset Quotes sld
35144 \end_inset
35145
35146 make test-mcs51
35147 \begin_inset Quotes srd
35148 \end_inset
35149
35150
35151 \family default
35152 \series default
35153  if you don't want to run the complete tests).
35154  The test code might also be interesting if you want to look for examples
35155 \begin_inset LatexCommand index
35156 name "Examples"
35157
35158 \end_inset
35159
35160  checking corner cases of SDCC or if you plan to submit patches
35161 \begin_inset LatexCommand index
35162 name "Patch submission"
35163
35164 \end_inset
35165
35166 .
35167 \end_layout
35168
35169 \begin_layout Standard
35170 The PIC14 port uses a different set of regression tests 
35171 \begin_inset LatexCommand index
35172 name "Regression test (PIC14)"
35173
35174 \end_inset
35175
35176 , you'll find them in the directory 
35177 \shape italic
35178 sdcc/src/regression
35179 \shape default
35180 .
35181 \end_layout
35182
35183 \begin_layout Section
35184 Use of SDCC in Education
35185 \end_layout
35186
35187 \begin_layout Standard
35188 In short: 
35189 \emph on
35190 highly
35191 \emph default
35192  encouraged
35193 \begin_inset Foot
35194 status open
35195
35196 \begin_layout Standard
35197 the phrase "use in education" might evoke the association "
35198 \emph on
35199 only
35200 \emph default
35201  fit for use in education".
35202  This connotation is not intended but nevertheless risked as the licensing
35203  of SDCC makes it difficult to offer educational discounts
35204 \end_layout
35205
35206 \end_inset
35207
35208 .
35209  If your rationales are to:
35210 \end_layout
35211
35212 \begin_layout Enumerate
35213 give students a chance to understand the 
35214 \emph on
35215 complete
35216 \emph default
35217  steps of code generation
35218 \end_layout
35219
35220 \begin_layout Enumerate
35221 have a curriculum that can be extended for years.
35222  Then you could use an fpga board as target and your curriculum will seamlessly
35223  extend from logic synthesis (
35224 \begin_inset LatexCommand url
35225 name "http://www.opencores.org"
35226 target "opencores.org"
35227
35228 \end_inset
35229
35230
35231 \begin_inset LatexCommand url
35232 name "Oregano"
35233 target "http://www.oregano.at/ip/ip01.htm"
35234
35235 \end_inset
35236
35237 ), over assembly programming, to C to FPGA compilers (
35238 \begin_inset LatexCommand url
35239 name "FPGAC"
35240 target "http://sf.net/projects/fpgac"
35241
35242 \end_inset
35243
35244 ) and to C.
35245 \end_layout
35246
35247 \begin_layout Enumerate
35248 be able to insert excursions about skills like using a revision control
35249  system, submitting/applying patches, using a type-setting (as opposed to
35250  word-processing) engine LyX/LaTeX, using 
35251 \begin_inset LatexCommand url
35252 name "SourceForge"
35253 target "http://www.sf.net"
35254
35255 \end_inset
35256
35257 , following some 
35258 \begin_inset LatexCommand url
35259 name "netiquette"
35260 target "http://en.wikipedia.org/wiki/Netiquette"
35261
35262 \end_inset
35263
35264 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
35265  Source Software, CPU simulation, compiler regression tests
35266 \begin_inset LatexCommand index
35267 name "Regression test"
35268
35269 \end_inset
35270
35271 .
35272  
35273 \newline
35274 And if there should be a shortage of ideas then you can always point students
35275  to the ever-growing feature request list 
35276 \begin_inset LatexCommand htmlurl
35277 target "http://sourceforge.net/tracker/?group_id=599&atid=350599"
35278
35279 \end_inset
35280
35281 .
35282 \end_layout
35283
35284 \begin_layout Enumerate
35285 not tie students to a specific host platform and instead allow them to use
35286  a host platform of 
35287 \emph on
35288 their
35289 \emph default
35290  choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
35291  and eventually 
35292 \begin_inset LatexCommand url
35293 name "OLPC"
35294 target "http://www.laptop.org"
35295
35296 \end_inset
35297
35298 )
35299 \end_layout
35300
35301 \begin_layout Enumerate
35302 not encourage students to use illegal copies of educational software
35303 \end_layout
35304
35305 \begin_layout Enumerate
35306 be immune to licensing/availability/price changes of the chosen tool chain
35307 \end_layout
35308
35309 \begin_layout Enumerate
35310 be able to change to a new target platform without having to adopt a new
35311  tool chain
35312 \end_layout
35313
35314 \begin_layout Enumerate
35315 have complete control over and insight into the tool chain
35316 \end_layout
35317
35318 \begin_layout Enumerate
35319 make your students aware about the pros and cons of open source software
35320  development
35321 \end_layout
35322
35323 \begin_layout Enumerate
35324 give back to the public as you are probably at least partially publicly
35325  funded
35326 \end_layout
35327
35328 \begin_layout Enumerate
35329 give students a chance to publicly prove their skills and to possibly see
35330  a world wide impact
35331 \end_layout
35332
35333 \begin_layout Standard
35334 then SDCC is probably among the first choices.
35335  Well, probably SDCC might be the only choice.
35336 \newpage
35337
35338 \end_layout
35339
35340 \begin_layout Chapter
35341 SDCC Technical Data
35342 \end_layout
35343
35344 \begin_layout Section
35345 Optimizations
35346 \begin_inset LatexCommand index
35347 name "Optimizations"
35348
35349 \end_inset
35350
35351
35352 \end_layout
35353
35354 \begin_layout Standard
35355 SDCC performs a host of standard optimizations in addition to some MCU specific
35356  optimizations.
35357  
35358 \end_layout
35359
35360 \begin_layout Subsection
35361 Sub-expression Elimination
35362 \begin_inset LatexCommand index
35363 name "Subexpression elimination"
35364
35365 \end_inset
35366
35367
35368 \end_layout
35369
35370 \begin_layout Standard
35371 The compiler does local and 
35372 \emph on
35373 g
35374 \emph default
35375 lobal 
35376 \emph on
35377 c
35378 \emph default
35379 ommon 
35380 \emph on
35381 s
35382 \emph default
35383 ubexpression 
35384 \emph on
35385 e
35386 \emph default
35387 limination, e.g.: 
35388 \end_layout
35389
35390 \begin_layout Verse
35391
35392 \family typewriter
35393 i = x + y + 1; 
35394 \newline
35395 j = x + y;
35396 \end_layout
35397
35398 \begin_layout Standard
35399 will be translated to
35400 \end_layout
35401
35402 \begin_layout Verse
35403
35404 \family typewriter
35405 iTemp = x + y; 
35406 \newline
35407 i = iTemp + 1; 
35408 \newline
35409 j = iTemp;
35410 \end_layout
35411
35412 \begin_layout Standard
35413 Some subexpressions are not as obvious as the above example, e.g.:
35414 \end_layout
35415
35416 \begin_layout Verse
35417
35418 \family typewriter
35419 a->b[i].c = 10; 
35420 \newline
35421 a->b[i].d = 11;
35422 \end_layout
35423
35424 \begin_layout Standard
35425 In this case the address arithmetic a->b[i] will be computed only once;
35426  the equivalent code in C would be.
35427 \end_layout
35428
35429 \begin_layout Verse
35430
35431 \family typewriter
35432 iTemp = a->b[i]; 
35433 \newline
35434 iTemp.c = 10; 
35435 \newline
35436 iTemp.d = 11;
35437 \end_layout
35438
35439 \begin_layout Standard
35440 The compiler will try to keep these temporary variables in registers.
35441 \end_layout
35442
35443 \begin_layout Subsection
35444 Dead-Code Elimination
35445 \begin_inset LatexCommand index
35446 name "Dead-code elimination"
35447
35448 \end_inset
35449
35450
35451 \end_layout
35452
35453 \begin_layout Verse
35454
35455 \family typewriter
35456 int global;
35457 \newline
35458
35459 \newline
35460 void f () { 
35461 \newline
35462 \InsetSpace ~
35463 \InsetSpace ~
35464 int i; 
35465 \newline
35466 \InsetSpace ~
35467 \InsetSpace ~
35468 i = 1; \InsetSpace ~
35469 \InsetSpace ~
35470 \InsetSpace ~
35471 \InsetSpace ~
35472 \InsetSpace ~
35473 /* dead store */ 
35474 \newline
35475 \InsetSpace ~
35476 \InsetSpace ~
35477 global = 1;\InsetSpace ~
35478 /* dead
35479  store */ 
35480 \newline
35481 \InsetSpace ~
35482 \InsetSpace ~
35483 global = 2; 
35484 \newline
35485 \InsetSpace ~
35486 \InsetSpace ~
35487 return; 
35488 \newline
35489 \InsetSpace ~
35490 \InsetSpace ~
35491 global = 3;\InsetSpace ~
35492 /* unreachable */ 
35493 \newline
35494 }
35495 \end_layout
35496
35497 \begin_layout Standard
35498 will be changed to
35499 \end_layout
35500
35501 \begin_layout Verse
35502
35503 \family typewriter
35504 int global;
35505 \newline
35506
35507 \newline
35508 void f () {
35509 \newline
35510 \InsetSpace ~
35511 \InsetSpace ~
35512 global = 2; 
35513 \newline
35514 }
35515 \end_layout
35516
35517 \begin_layout Subsection
35518 Copy-Propagation
35519 \begin_inset LatexCommand index
35520 name "Copy propagation"
35521
35522 \end_inset
35523
35524
35525 \end_layout
35526
35527 \begin_layout Verse
35528
35529 \family typewriter
35530 int f() { 
35531 \newline
35532 \InsetSpace ~
35533 \InsetSpace ~
35534 int i, j; 
35535 \newline
35536 \InsetSpace ~
35537 \InsetSpace ~
35538 i = 10; 
35539 \newline
35540 \InsetSpace ~
35541 \InsetSpace ~
35542 j = i; 
35543 \newline
35544 \InsetSpace ~
35545 \InsetSpace ~
35546 return j; 
35547 \newline
35548 }
35549 \end_layout
35550
35551 \begin_layout Standard
35552 will be changed to 
35553 \end_layout
35554
35555 \begin_layout Verse
35556
35557 \family typewriter
35558 int f() { 
35559 \newline
35560 \InsetSpace ~
35561 \InsetSpace ~
35562 int i, j; 
35563 \newline
35564 \InsetSpace ~
35565 \InsetSpace ~
35566 i = 10; 
35567 \newline
35568 \InsetSpace ~
35569 \InsetSpace ~
35570 j = 10; 
35571 \newline
35572 \InsetSpace ~
35573 \InsetSpace ~
35574 return 10; 
35575 \newline
35576 }
35577 \end_layout
35578
35579 \begin_layout Standard
35580 Note: the dead stores created by this copy propagation will be eliminated
35581  by dead-code elimination.
35582 \end_layout
35583
35584 \begin_layout Subsection
35585 Loop Optimizations
35586 \begin_inset LatexCommand index
35587 name "Loop optimization"
35588
35589 \end_inset
35590
35591
35592 \begin_inset LatexCommand label
35593 name "sub:Loop-Optimizations"
35594
35595 \end_inset
35596
35597
35598 \end_layout
35599
35600 \begin_layout Standard
35601 Two types of loop optimizations are done by SDCC 
35602 \emph on
35603 loop invariant
35604 \emph default
35605  lifting and 
35606 \emph on
35607 strength reduction
35608 \emph default
35609  of loop induction variables.
35610  In addition to the strength reduction the optimizer marks the induction
35611  variables and the register allocator tries to keep the induction variables
35612  in registers for the duration of the loop.
35613  Because of this preference of the register allocator
35614 \begin_inset LatexCommand index
35615 name "Register allocation"
35616
35617 \end_inset
35618
35619 , loop induction optimization causes an increase in register pressure, which
35620  may cause unwanted spilling of other temporary variables into the stack
35621 \begin_inset LatexCommand index
35622 name "stack"
35623
35624 \end_inset
35625
35626  / data space.
35627  The compiler will generate a warning message when it is forced to allocate
35628  extra space either on the stack or data space.
35629  If this extra space allocation is undesirable then induction optimization
35630  can be eliminated either for the entire source file (with -
35631 \begin_inset ERT
35632 status collapsed
35633
35634 \begin_layout Standard
35635
35636
35637 \backslash
35638 /
35639 \end_layout
35640
35641 \end_inset
35642
35643 -noinduction option) or for a given function only using #pragma\InsetSpace ~
35644 noinduction
35645 \begin_inset LatexCommand index
35646 name "\\#pragma noinduction"
35647
35648 \end_inset
35649
35650 .
35651 \newline
35652
35653 \newline
35654 Loop Invariant:
35655 \end_layout
35656
35657 \begin_layout Verse
35658
35659 \family typewriter
35660 for (i = 0 ; i < 100 ; i ++) 
35661 \newline
35662 \InsetSpace ~
35663 \InsetSpace ~
35664 \InsetSpace ~
35665 \InsetSpace ~
35666 f += k + l;
35667 \end_layout
35668
35669 \begin_layout Standard
35670 changed to
35671 \end_layout
35672
35673 \begin_layout Verse
35674
35675 \family typewriter
35676 itemp = k + l; 
35677 \newline
35678 for (i = 0; i < 100; i++) 
35679 \newline
35680 \InsetSpace ~
35681 \InsetSpace ~
35682 \InsetSpace ~
35683 \InsetSpace ~
35684 f += itemp;
35685 \end_layout
35686
35687 \begin_layout Standard
35688 As mentioned previously some loop invariants are not as apparent, all static
35689  address computations are also moved out of the loop.
35690 \newline
35691
35692 \newline
35693 Strength Reduction
35694 \begin_inset LatexCommand index
35695 name "Strength reduction"
35696
35697 \end_inset
35698
35699 , this optimization substitutes an expression by a cheaper expression:
35700 \end_layout
35701
35702 \begin_layout Verse
35703
35704 \family typewriter
35705 for (i=0;i < 100; i++)
35706 \newline
35707 \InsetSpace ~
35708 \InsetSpace ~
35709 \InsetSpace ~
35710 \InsetSpace ~
35711 ar[i*5] = i*3;
35712 \end_layout
35713
35714 \begin_layout Standard
35715 changed to
35716 \end_layout
35717
35718 \begin_layout Verse
35719
35720 \family typewriter
35721 itemp1 = 0; 
35722 \newline
35723 itemp2 = 0; 
35724 \newline
35725 for (i=0;i< 100;i++) { 
35726 \newline
35727 \InsetSpace ~
35728 \InsetSpace ~
35729 \InsetSpace ~
35730 \InsetSpace ~
35731 ar[itemp1] = itemp2; 
35732 \newline
35733 \InsetSpace ~
35734 \InsetSpace ~
35735 \InsetSpace ~
35736 \InsetSpace ~
35737 itemp1
35738  += 5; 
35739 \newline
35740 \InsetSpace ~
35741 \InsetSpace ~
35742 \InsetSpace ~
35743 \InsetSpace ~
35744 itemp2 += 3; 
35745 \newline
35746 }
35747 \end_layout
35748
35749 \begin_layout Standard
35750 The more expensive multiplication
35751 \begin_inset LatexCommand index
35752 name "Multiplication"
35753
35754 \end_inset
35755
35756  is changed to a less expensive addition.
35757 \end_layout
35758
35759 \begin_layout Subsection
35760 Loop Reversing
35761 \begin_inset LatexCommand index
35762 name "Loop reversing"
35763
35764 \end_inset
35765
35766
35767 \end_layout
35768
35769 \begin_layout Standard
35770 This optimization is done to reduce the overhead of checking loop boundaries
35771  for every iteration.
35772  Some simple loops can be reversed and implemented using a 
35773 \begin_inset Quotes eld
35774 \end_inset
35775
35776 decrement and jump if not zero
35777 \begin_inset Quotes erd
35778 \end_inset
35779
35780  instruction.
35781  SDCC checks for the following criterion to determine if a loop is reversible
35782  (note: more sophisticated compilers use data-dependency analysis to make
35783  this determination, SDCC uses a more simple minded analysis).
35784 \end_layout
35785
35786 \begin_layout Itemize
35787 The 'for' loop is of the form 
35788 \newline
35789
35790 \newline
35791
35792 \family typewriter
35793 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
35794  += 1])
35795 \newline
35796 \InsetSpace ~
35797 \InsetSpace ~
35798 \InsetSpace ~
35799 \InsetSpace ~
35800 <for body>
35801 \end_layout
35802
35803 \begin_layout Itemize
35804 The <for body> does not contain 
35805 \begin_inset Quotes eld
35806 \end_inset
35807
35808 continue
35809 \begin_inset Quotes erd
35810 \end_inset
35811
35812  or 'break
35813 \begin_inset Quotes erd
35814 \end_inset
35815
35816 .
35817 \end_layout
35818
35819 \begin_layout Itemize
35820 All goto's are contained within the loop.
35821 \end_layout
35822
35823 \begin_layout Itemize
35824 No function calls within the loop.
35825 \end_layout
35826
35827 \begin_layout Itemize
35828 The loop control variable <sym> is not assigned any value within the loop
35829 \end_layout
35830
35831 \begin_layout Itemize
35832 The loop control variable does NOT participate in any arithmetic operation
35833  within the loop.
35834 \end_layout
35835
35836 \begin_layout Itemize
35837 There are NO switch statements in the loop.
35838 \end_layout
35839
35840 \begin_layout Subsection
35841 Algebraic Simplifications
35842 \end_layout
35843
35844 \begin_layout Standard
35845 SDCC does numerous algebraic simplifications, the following is a small sub-set
35846  of these optimizations.
35847 \end_layout
35848
35849 \begin_layout Verse
35850
35851 \family typewriter
35852 i = j + 0;\InsetSpace ~
35853 \InsetSpace ~
35854 \InsetSpace ~
35855 \InsetSpace ~
35856  /* changed to: */\InsetSpace ~
35857 \InsetSpace ~
35858 \InsetSpace ~
35859 \InsetSpace ~
35860  i = j; 
35861 \newline
35862 i /= 2;\InsetSpace ~
35863 \InsetSpace ~
35864 \InsetSpace ~
35865 \InsetSpace ~
35866 \InsetSpace ~
35867 \InsetSpace ~
35868 \InsetSpace ~
35869  /* changed to: */\InsetSpace ~
35870 \InsetSpace ~
35871 \InsetSpace ~
35872 \InsetSpace ~
35873  i >>= 1; 
35874 \newline
35875 i
35876  = j - j;\InsetSpace ~
35877 \InsetSpace ~
35878 \InsetSpace ~
35879 \InsetSpace ~
35880  /* changed to: */\InsetSpace ~
35881 \InsetSpace ~
35882 \InsetSpace ~
35883 \InsetSpace ~
35884  i = 0; 
35885 \newline
35886 i = j / 1;\InsetSpace ~
35887 \InsetSpace ~
35888 \InsetSpace ~
35889 \InsetSpace ~
35890  /* changed to: */\InsetSpace ~
35891 \InsetSpace ~
35892 \InsetSpace ~
35893 \InsetSpace ~
35894  i = j;
35895 \end_layout
35896
35897 \begin_layout Standard
35898 Note the subexpressions
35899 \begin_inset LatexCommand index
35900 name "Subexpression"
35901
35902 \end_inset
35903
35904  given above are generally introduced by macro expansions or as a result
35905  of copy/constant propagation.
35906 \end_layout
35907
35908 \begin_layout Subsection
35909 'switch' Statements
35910 \begin_inset LatexCommand label
35911 name "sub:'switch'-Statements"
35912
35913 \end_inset
35914
35915
35916 \begin_inset LatexCommand index
35917 name "switch statement"
35918
35919 \end_inset
35920
35921
35922 \end_layout
35923
35924 \begin_layout Standard
35925 SDCC can optimize switch statements to jump tables
35926 \begin_inset LatexCommand index
35927 name "jump tables"
35928
35929 \end_inset
35930
35931 .
35932  It makes the decision based on an estimate of the generated code size.
35933  SDCC is quite liberal in the requirements for jump table generation: 
35934 \end_layout
35935
35936 \begin_layout Itemize
35937 The labels need not be in order, and the starting number need not be one
35938  or zero, the case labels are in numerical sequence or not too many case
35939  labels are missing.
35940 \end_layout
35941
35942 \begin_deeper
35943 \begin_layout Verse
35944
35945 \family typewriter
35946 switch(i) {\InsetSpace ~
35947 \InsetSpace ~
35948 \InsetSpace ~
35949 \InsetSpace ~
35950 \InsetSpace ~
35951 \InsetSpace ~
35952 \InsetSpace ~
35953 \InsetSpace ~
35954 \InsetSpace ~
35955 \InsetSpace ~
35956 \InsetSpace ~
35957 \InsetSpace ~
35958 \InsetSpace ~
35959 \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 switch (i) { 
35973 \newline
35974 \InsetSpace ~
35975 \InsetSpace ~
35976 \InsetSpace ~
35977 case 4: ...\InsetSpace ~
35978 \InsetSpace ~
35979 \InsetSpace ~
35980 \InsetSpace ~
35981 \InsetSpace ~
35982 \InsetSpace ~
35983 \InsetSpace ~
35984 \InsetSpace ~
35985 \InsetSpace ~
35986 \InsetSpace ~
35987 \InsetSpace ~
35988 \InsetSpace ~
35989 \InsetSpace ~
35990 \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 case 0: ...
36004  
36005 \newline
36006 \InsetSpace ~
36007 \InsetSpace ~
36008 \InsetSpace ~
36009 case 5: ...\InsetSpace ~
36010 \InsetSpace ~
36011 \InsetSpace ~
36012 \InsetSpace ~
36013 \InsetSpace ~
36014 \InsetSpace ~
36015 \InsetSpace ~
36016 \InsetSpace ~
36017 \InsetSpace ~
36018 \InsetSpace ~
36019 \InsetSpace ~
36020 \InsetSpace ~
36021 \InsetSpace ~
36022 \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 case 1: ...
36036  
36037 \newline
36038 \InsetSpace ~
36039 \InsetSpace ~
36040 \InsetSpace ~
36041 case 3: ...\InsetSpace ~
36042 \InsetSpace ~
36043 \InsetSpace ~
36044 \InsetSpace ~
36045 \InsetSpace ~
36046 \InsetSpace ~
36047 \InsetSpace ~
36048 \InsetSpace ~
36049 \InsetSpace ~
36050 \InsetSpace ~
36051 \InsetSpace ~
36052 \InsetSpace ~
36053 \InsetSpace ~
36054 \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
36068 \newline
36069 \InsetSpace ~
36070 \InsetSpace ~
36071 \InsetSpace ~
36072 case 6: ...\InsetSpace ~
36073 \InsetSpace ~
36074 \InsetSpace ~
36075 \InsetSpace ~
36076 \InsetSpace ~
36077 \InsetSpace ~
36078 \InsetSpace ~
36079 \InsetSpace ~
36080 \InsetSpace ~
36081 \InsetSpace ~
36082 \InsetSpace ~
36083 \InsetSpace ~
36084 \InsetSpace ~
36085 \InsetSpace ~
36086 \InsetSpace ~
36087 \InsetSpace ~
36088 \InsetSpace ~
36089 \InsetSpace ~
36090 \InsetSpace ~
36091 \InsetSpace ~
36092 \InsetSpace ~
36093 \InsetSpace ~
36094 \InsetSpace ~
36095 \InsetSpace ~
36096 \InsetSpace ~
36097 \InsetSpace ~
36098 case 3: ...
36099  
36100 \newline
36101 \InsetSpace ~
36102 \InsetSpace ~
36103 \InsetSpace ~
36104 case 7: ...\InsetSpace ~
36105 \InsetSpace ~
36106 \InsetSpace ~
36107 \InsetSpace ~
36108 \InsetSpace ~
36109 \InsetSpace ~
36110 \InsetSpace ~
36111 \InsetSpace ~
36112 \InsetSpace ~
36113 \InsetSpace ~
36114 \InsetSpace ~
36115 \InsetSpace ~
36116 \InsetSpace ~
36117 \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 case 4: ...
36131  
36132 \newline
36133 \InsetSpace ~
36134 \InsetSpace ~
36135 \InsetSpace ~
36136 case 8: ...\InsetSpace ~
36137 \InsetSpace ~
36138 \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 case 5: ...
36163  
36164 \newline
36165 \InsetSpace ~
36166 \InsetSpace ~
36167 \InsetSpace ~
36168 case 9: ...\InsetSpace ~
36169 \InsetSpace ~
36170 \InsetSpace ~
36171 \InsetSpace ~
36172 \InsetSpace ~
36173 \InsetSpace ~
36174 \InsetSpace ~
36175 \InsetSpace ~
36176 \InsetSpace ~
36177 \InsetSpace ~
36178 \InsetSpace ~
36179 \InsetSpace ~
36180 \InsetSpace ~
36181 \InsetSpace ~
36182 \InsetSpace ~
36183 \InsetSpace ~
36184 \InsetSpace ~
36185 \InsetSpace ~
36186 \InsetSpace ~
36187 \InsetSpace ~
36188 \InsetSpace ~
36189 \InsetSpace ~
36190 \InsetSpace ~
36191 \InsetSpace ~
36192 \InsetSpace ~
36193 \InsetSpace ~
36194 case 6: ...
36195  
36196 \newline
36197 \InsetSpace ~
36198 \InsetSpace ~
36199 \InsetSpace ~
36200 case 10: ...\InsetSpace ~
36201 \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 case 7: ...
36226  
36227 \newline
36228 \InsetSpace ~
36229 \InsetSpace ~
36230 \InsetSpace ~
36231 case 11: ...\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 case 8: ...
36257  
36258 \newline
36259 }\InsetSpace ~
36260 \InsetSpace ~
36261 \InsetSpace ~
36262 \InsetSpace ~
36263 \InsetSpace ~
36264 \InsetSpace ~
36265 \InsetSpace ~
36266 \InsetSpace ~
36267 \InsetSpace ~
36268 \InsetSpace ~
36269 \InsetSpace ~
36270 \InsetSpace ~
36271 \InsetSpace ~
36272 \InsetSpace ~
36273 \InsetSpace ~
36274 \InsetSpace ~
36275 \InsetSpace ~
36276 \InsetSpace ~
36277 \InsetSpace ~
36278 \InsetSpace ~
36279 \InsetSpace ~
36280 \InsetSpace ~
36281 \InsetSpace ~
36282 \InsetSpace ~
36283 \InsetSpace ~
36284 \InsetSpace ~
36285 \InsetSpace ~
36286 \InsetSpace ~
36287 \InsetSpace ~
36288 \InsetSpace ~
36289 \InsetSpace ~
36290 \InsetSpace ~
36291 \InsetSpace ~
36292 \InsetSpace ~
36293 \InsetSpace ~
36294 \InsetSpace ~
36295 }
36296 \end_layout
36297
36298 \begin_layout Standard
36299 Both the above switch statements will be implemented using a jump-table.
36300  The example to the right side is slightly more efficient as the check for
36301  the lower boundary of the jump-table is not needed.
36302 \end_layout
36303
36304 \end_deeper
36305 \begin_layout Itemize
36306 The number of case labels is not larger than supported by the target architectur
36307 e.
36308 \end_layout
36309
36310 \begin_layout Itemize
36311 If the case labels are not in numerical sequence ('gaps' between cases)
36312  SDCC checks whether a jump table with additionally inserted dummy cases
36313  is still attractive.
36314  
36315 \end_layout
36316
36317 \begin_layout Itemize
36318 If the starting number is not zero and a check for the lower boundary of
36319  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
36320  ...
36321  .
36322 \end_layout
36323
36324 \begin_layout Standard
36325 Switch statements which have large gaps in the numeric sequence or those
36326  that have too many case labels can be split into more than one switch statement
36327  for efficient code generation, e.g.:
36328 \end_layout
36329
36330 \begin_layout Verse
36331
36332 \family typewriter
36333 switch (i) { 
36334 \newline
36335 \InsetSpace ~
36336 \InsetSpace ~
36337 case 1: ...
36338  
36339 \newline
36340 \InsetSpace ~
36341 \InsetSpace ~
36342 case 2: ...
36343  
36344 \newline
36345 \InsetSpace ~
36346 \InsetSpace ~
36347 case 3: ...
36348  
36349 \newline
36350 \InsetSpace ~
36351 \InsetSpace ~
36352 case 4: ...
36353  
36354 \newline
36355 \InsetSpace ~
36356 \InsetSpace ~
36357 case 5: ...
36358  
36359 \newline
36360 \InsetSpace ~
36361 \InsetSpace ~
36362 case 6: ...
36363  
36364 \newline
36365 \InsetSpace ~
36366 \InsetSpace ~
36367 case 7: ...
36368  
36369 \newline
36370 \InsetSpace ~
36371 \InsetSpace ~
36372 case 101: ...
36373  
36374 \newline
36375 \InsetSpace ~
36376 \InsetSpace ~
36377 case 102: ...
36378  
36379 \newline
36380 \InsetSpace ~
36381 \InsetSpace ~
36382 case 103: ...
36383  
36384 \newline
36385 \InsetSpace ~
36386 \InsetSpace ~
36387 case 104: ...
36388  
36389 \newline
36390 \InsetSpace ~
36391 \InsetSpace ~
36392 case 105: ...
36393  
36394 \newline
36395 \InsetSpace ~
36396 \InsetSpace ~
36397 case 106: ...
36398  
36399 \newline
36400 \InsetSpace ~
36401 \InsetSpace ~
36402 case 107: ...
36403  
36404 \newline
36405 }
36406 \end_layout
36407
36408 \begin_layout Standard
36409 If the above switch statement is broken down into two switch statements
36410 \end_layout
36411
36412 \begin_layout Verse
36413
36414 \family typewriter
36415 switch (i) { 
36416 \newline
36417 \InsetSpace ~
36418 \InsetSpace ~
36419 case 1: ...
36420  
36421 \newline
36422 \InsetSpace ~
36423 \InsetSpace ~
36424 case 2: ...
36425  
36426 \newline
36427 \InsetSpace ~
36428 \InsetSpace ~
36429 case 3: ...
36430  
36431 \newline
36432 \InsetSpace ~
36433 \InsetSpace ~
36434 case 4: ...
36435  
36436 \newline
36437 \InsetSpace ~
36438 \InsetSpace ~
36439 case 5: ...
36440  
36441 \newline
36442 \InsetSpace ~
36443 \InsetSpace ~
36444 case 6: ...
36445  
36446 \newline
36447 \InsetSpace ~
36448 \InsetSpace ~
36449 case 7: ...
36450  
36451 \newline
36452 }
36453 \end_layout
36454
36455 \begin_layout Standard
36456 and
36457 \end_layout
36458
36459 \begin_layout Verse
36460
36461 \family typewriter
36462 switch (i) { 
36463 \newline
36464 \InsetSpace ~
36465 \InsetSpace ~
36466 case 101: ...
36467  
36468 \newline
36469 \InsetSpace ~
36470 \InsetSpace ~
36471 case 102: ...
36472  
36473 \newline
36474 \InsetSpace ~
36475 \InsetSpace ~
36476 case 103: ...
36477  
36478 \newline
36479 \InsetSpace ~
36480 \InsetSpace ~
36481 case 104: ...
36482  
36483 \newline
36484 \InsetSpace ~
36485 \InsetSpace ~
36486 case 105: ...
36487  
36488 \newline
36489 \InsetSpace ~
36490 \InsetSpace ~
36491 case 106: ...
36492  
36493 \newline
36494 \InsetSpace ~
36495 \InsetSpace ~
36496 case 107: ...
36497  
36498 \newline
36499 }
36500 \end_layout
36501
36502 \begin_layout Standard
36503 then both the switch statements will be implemented using jump-tables whereas
36504  the unmodified switch statement will not be.
36505 \end_layout
36506
36507 \begin_layout Standard
36508 \begin_inset Note Note
36509 status collapsed
36510
36511 \begin_layout Standard
36512 There might be reasons which SDCC cannot know about to either favour or
36513  not favour jump tables.
36514  If the target system has to be as quick for the last switch case as for
36515  the first (pro jump table), or if the switch argument is known to be zero
36516  in the majority of the cases (contra jump table).
36517 \end_layout
36518
36519 \end_inset
36520
36521
36522 \end_layout
36523
36524 \begin_layout Standard
36525 The pragma nojtbound
36526 \begin_inset LatexCommand index
36527 name "\\#pragma nojtbound"
36528
36529 \end_inset
36530
36531  can be used to turn off checking the 
36532 \emph on
36533 j
36534 \emph default
36535 ump 
36536 \emph on
36537 t
36538 \emph default
36539 able 
36540 \emph on
36541 bound
36542 \emph default
36543 aries.
36544  It has no effect if a default label is supplied.
36545  Use of this pragma is dangerous: if the switch
36546 \begin_inset LatexCommand index
36547 name "switch statement"
36548
36549 \end_inset
36550
36551  argument is not matched by a case statement the processor will happily
36552  jump into Nirvana.
36553 \end_layout
36554
36555 \begin_layout Subsection
36556 Bit-shifting Operations
36557 \begin_inset LatexCommand index
36558 name "Bit shifting"
36559
36560 \end_inset
36561
36562 .
36563 \end_layout
36564
36565 \begin_layout Standard
36566 Bit shifting is one of the most frequently used operation in embedded programmin
36567 g.
36568  SDCC tries to implement bit-shift operations in the most efficient way
36569  possible, e.g.:
36570 \end_layout
36571
36572 \begin_layout Verse
36573
36574 \family typewriter
36575 unsigned char i;
36576 \newline
36577 ...
36578  
36579 \newline
36580 i >>= 4; 
36581 \newline
36582 ...
36583 \end_layout
36584
36585 \begin_layout Standard
36586 generates the following code:
36587 \end_layout
36588
36589 \begin_layout Verse
36590
36591 \family typewriter
36592 mov\InsetSpace ~
36593  a,_i 
36594 \newline
36595 swap a 
36596 \newline
36597 anl\InsetSpace ~
36598  a,#0x0f 
36599 \newline
36600 mov\InsetSpace ~
36601  _i,a
36602 \end_layout
36603
36604 \begin_layout Standard
36605 In general SDCC will never setup a loop if the shift count is known.
36606  Another example:
36607 \end_layout
36608
36609 \begin_layout Verse
36610
36611 \family typewriter
36612 unsigned int i; 
36613 \newline
36614 ...
36615  
36616 \newline
36617 i >>= 9; 
36618 \newline
36619 ...
36620 \end_layout
36621
36622 \begin_layout Standard
36623 will generate:
36624 \end_layout
36625
36626 \begin_layout Verse
36627
36628 \family typewriter
36629 mov\InsetSpace ~
36630 \InsetSpace ~
36631 a,(_i + 1) 
36632 \newline
36633 mov\InsetSpace ~
36634 \InsetSpace ~
36635 (_i + 1),#0x00 
36636 \newline
36637 clr\InsetSpace ~
36638 \InsetSpace ~
36639
36640 \newline
36641 rrc\InsetSpace ~
36642 \InsetSpace ~
36643
36644 \newline
36645 mov\InsetSpace ~
36646 \InsetSpace ~
36647 _i,a
36648 \end_layout
36649
36650 \begin_layout Subsection
36651 Bit-rotation
36652 \begin_inset LatexCommand index
36653 name "Bit rotation"
36654
36655 \end_inset
36656
36657
36658 \end_layout
36659
36660 \begin_layout Standard
36661 A special case of the bit-shift operation is bit rotation
36662 \begin_inset LatexCommand index
36663 name "rotating bits"
36664
36665 \end_inset
36666
36667 , SDCC recognizes the following expression to be a left bit-rotation:
36668 \end_layout
36669
36670 \begin_layout Verse
36671
36672 \family typewriter
36673 \series bold
36674 unsigned
36675 \series default
36676 \InsetSpace ~
36677 \InsetSpace ~
36678 char i;\InsetSpace ~
36679 \InsetSpace ~
36680 \InsetSpace ~
36681 \InsetSpace ~
36682 \InsetSpace ~
36683 \InsetSpace ~
36684 \InsetSpace ~
36685 \InsetSpace ~
36686 \InsetSpace ~
36687 \InsetSpace ~
36688 \InsetSpace ~
36689 /* unsigned is needed for rotation */ 
36690 \newline
36691 ...
36692  
36693 \newline
36694 i = ((i << 1) | (i >> 7));
36695 \family default
36696  
36697 \newline
36698
36699 \family typewriter
36700 ...
36701 \end_layout
36702
36703 \begin_layout Standard
36704 will generate the following code:
36705 \end_layout
36706
36707 \begin_layout Verse
36708
36709 \family typewriter
36710 mov\InsetSpace ~
36711 \InsetSpace ~
36712 a,_i 
36713 \newline
36714 rl\InsetSpace ~
36715 \InsetSpace ~
36716 \InsetSpace ~
36717
36718 \newline
36719 mov\InsetSpace ~
36720 \InsetSpace ~
36721 _i,a
36722 \end_layout
36723
36724 \begin_layout Standard
36725 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
36726 ns of this case will also be recognized as bit-rotation, i.e.: 
36727 \end_layout
36728
36729 \begin_layout Verse
36730
36731 \family typewriter
36732 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
36733 \end_layout
36734
36735 \begin_layout Subsection
36736 Nibble and Byte Swapping
36737 \end_layout
36738
36739 \begin_layout Standard
36740 Other special cases of the bit-shift operations are nibble or byte swapping
36741 \begin_inset LatexCommand index
36742 name "swapping nibbles/bytes"
36743
36744 \end_inset
36745
36746 , SDCC recognizes the following expressions:
36747 \end_layout
36748
36749 \begin_layout Verse
36750
36751 \family typewriter
36752 \series bold
36753 unsigned
36754 \series default
36755 \InsetSpace ~
36756 \InsetSpace ~
36757 char i; 
36758 \newline
36759
36760 \series bold
36761 unsigned
36762 \series default
36763 \InsetSpace ~
36764 \InsetSpace ~
36765 int j; 
36766 \newline
36767 ...
36768  
36769 \newline
36770 i = ((i << 4) | (i >> 4));
36771 \family default
36772  
36773 \newline
36774
36775 \family typewriter
36776 j = ((j << 8) | (j >> 8)); 
36777 \end_layout
36778
36779 \begin_layout Standard
36780 and generates a swap instruction for the nibble swapping
36781 \begin_inset LatexCommand index
36782 name "Nibble swapping"
36783
36784 \end_inset
36785
36786  or move instructions for the byte swapping
36787 \begin_inset LatexCommand index
36788 name "Byte swapping"
36789
36790 \end_inset
36791
36792 .
36793  The 
36794 \begin_inset Quotes sld
36795 \end_inset
36796
36797 j
36798 \begin_inset Quotes srd
36799 \end_inset
36800
36801  example can be used to convert from little to big-endian or vice versa.
36802  If you want to change the endianness of a 
36803 \emph on
36804 signed
36805 \emph default
36806  integer you have to cast to 
36807 \family typewriter
36808 (unsigned int)
36809 \family default
36810  first.
36811 \end_layout
36812
36813 \begin_layout Standard
36814 Note that SDCC stores numbers in little-endian
36815 \begin_inset Foot
36816 status open
36817
36818 \begin_layout Standard
36819 Usually 8-bit processors don't care much about endianness.
36820  This is not the case for the standard 8051 which only has an instruction
36821  to increment its 
36822 \emph on
36823 dptr
36824 \emph default
36825
36826 \begin_inset LatexCommand index
36827 name "DPTR"
36828
36829 \end_inset
36830
36831 -datapointer so little-endian is the more efficient byte order.
36832 \end_layout
36833
36834 \end_inset
36835
36836
36837 \begin_inset LatexCommand index
36838 name "little-endian"
36839
36840 \end_inset
36841
36842
36843 \begin_inset LatexCommand index
36844 name "Endianness"
36845
36846 \end_inset
36847
36848  format (i.e.
36849  lowest order first).
36850 \end_layout
36851
36852 \begin_layout Subsection
36853 Highest Order Bit
36854 \begin_inset LatexCommand index
36855 name "Highest Order Bit"
36856
36857 \end_inset
36858
36859  / Any Order Bit
36860 \begin_inset LatexCommand index
36861 name "Any Order Bit"
36862
36863 \end_inset
36864
36865
36866 \end_layout
36867
36868 \begin_layout Standard
36869 It is frequently required to obtain the highest order bit of an integral
36870  type (long, int, short or char types).
36871  Also obtaining any other order bit is not uncommon.
36872  SDCC recognizes the following expressions to yield the highest order bit
36873  and generates optimized code for it, e.g.:
36874 \end_layout
36875
36876 \begin_layout Verse
36877
36878 \family typewriter
36879 unsigned int gint; 
36880 \newline
36881
36882 \newline
36883 foo () { 
36884 \newline
36885 \InsetSpace ~
36886 \InsetSpace ~
36887 unsigned char hob1, aob1; 
36888 \newline
36889 \InsetSpace ~
36890 \InsetSpace ~
36891 bit hob2, hob3, aob2,
36892  aob3; 
36893 \newline
36894 \InsetSpace ~
36895 \InsetSpace ~
36896 ...
36897  
36898 \newline
36899 \InsetSpace ~
36900 \InsetSpace ~
36901 hob1 = (gint >> 15) & 1; 
36902 \newline
36903 \InsetSpace ~
36904 \InsetSpace ~
36905 hob2 = (gint >> 15) & 1; 
36906 \newline
36907 \InsetSpace ~
36908 \InsetSpace ~
36909 hob3 = gint & 0x8000;
36910  
36911 \newline
36912 \InsetSpace ~
36913 \InsetSpace ~
36914 aob1 = (gint >> 9) & 1; 
36915 \newline
36916 \InsetSpace ~
36917 \InsetSpace ~
36918 aob2 = (gint >> 8) & 1; 
36919 \newline
36920 \InsetSpace ~
36921 \InsetSpace ~
36922 aob3 = gint & 0x0800; 
36923 \newline
36924 \InsetSpace ~
36925 \InsetSpace ~
36926 ..
36927  
36928 \newline
36929 }
36930 \end_layout
36931
36932 \begin_layout Standard
36933 will generate the following code:
36934 \end_layout
36935
36936 \begin_layout Verse
36937
36938 \family typewriter
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 \InsetSpace ~
36953 \InsetSpace ~
36954 \InsetSpace ~
36955 \InsetSpace ~
36956 \InsetSpace ~
36957 \InsetSpace ~
36958 \InsetSpace ~
36959 \InsetSpace ~
36960 \InsetSpace ~
36961 \InsetSpace ~
36962 \InsetSpace ~
36963 \InsetSpace ~
36964  61 ;\InsetSpace ~
36965  hob.c 7 
36966 \newline
36967 000A E5*01\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  62\InsetSpace ~
36983 \InsetSpace ~
36984 \InsetSpace ~
36985 \InsetSpace ~
36986 \InsetSpace ~
36987 \InsetSpace ~
36988 \InsetSpace ~
36989 \InsetSpace ~
36990  mov\InsetSpace ~
36991 \InsetSpace ~
36992  a,(_gint + 1) 
36993 \newline
36994 000C 23\InsetSpace ~
36995 \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 \InsetSpace ~
37011 \InsetSpace ~
37012  63\InsetSpace ~
37013 \InsetSpace ~
37014 \InsetSpace ~
37015 \InsetSpace ~
37016 \InsetSpace ~
37017 \InsetSpace ~
37018 \InsetSpace ~
37019 \InsetSpace ~
37020  rl\InsetSpace ~
37021 \InsetSpace ~
37022 \InsetSpace ~
37023  a 
37024 \newline
37025 000D 54 01\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 \InsetSpace ~
37039 \InsetSpace ~
37040
37041  64\InsetSpace ~
37042 \InsetSpace ~
37043 \InsetSpace ~
37044 \InsetSpace ~
37045 \InsetSpace ~
37046 \InsetSpace ~
37047 \InsetSpace ~
37048 \InsetSpace ~
37049  anl\InsetSpace ~
37050 \InsetSpace ~
37051  a,#0x01 
37052 \newline
37053 000F F5*02\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  65\InsetSpace ~
37069 \InsetSpace ~
37070 \InsetSpace ~
37071 \InsetSpace ~
37072 \InsetSpace ~
37073 \InsetSpace ~
37074 \InsetSpace ~
37075 \InsetSpace ~
37076  mov\InsetSpace ~
37077 \InsetSpace ~
37078  _foo_hob1_1_1,a 
37079 \newline
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 \InsetSpace ~
37094 \InsetSpace ~
37095 \InsetSpace ~
37096 \InsetSpace ~
37097 \InsetSpace ~
37098 \InsetSpace ~
37099 \InsetSpace ~
37100 \InsetSpace ~
37101 \InsetSpace ~
37102 \InsetSpace ~
37103 \InsetSpace ~
37104 \InsetSpace ~
37105  66 ;\InsetSpace ~
37106  hob.c 8 
37107 \newline
37108 0011 E5*01\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
37124  67\InsetSpace ~
37125 \InsetSpace ~
37126 \InsetSpace ~
37127 \InsetSpace ~
37128 \InsetSpace ~
37129 \InsetSpace ~
37130 \InsetSpace ~
37131 \InsetSpace ~
37132  mov\InsetSpace ~
37133 \InsetSpace ~
37134  a,(_gint + 1) 
37135 \newline
37136 0013 33\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 \InsetSpace ~
37152 \InsetSpace ~
37153 \InsetSpace ~
37154  68\InsetSpace ~
37155 \InsetSpace ~
37156 \InsetSpace ~
37157 \InsetSpace ~
37158 \InsetSpace ~
37159 \InsetSpace ~
37160 \InsetSpace ~
37161 \InsetSpace ~
37162  rlc\InsetSpace ~
37163 \InsetSpace ~
37164  a 
37165 \newline
37166 0014 92*00\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  69\InsetSpace ~
37182 \InsetSpace ~
37183 \InsetSpace ~
37184 \InsetSpace ~
37185 \InsetSpace ~
37186 \InsetSpace ~
37187 \InsetSpace ~
37188 \InsetSpace ~
37189  mov\InsetSpace ~
37190 \InsetSpace ~
37191  _foo_hob2_1_1,c
37192  
37193 \newline
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 \InsetSpace ~
37208 \InsetSpace ~
37209 \InsetSpace ~
37210 \InsetSpace ~
37211 \InsetSpace ~
37212 \InsetSpace ~
37213 \InsetSpace ~
37214 \InsetSpace ~
37215 \InsetSpace ~
37216 \InsetSpace ~
37217 \InsetSpace ~
37218 \InsetSpace ~
37219  66 ;\InsetSpace ~
37220  hob.c 9 
37221 \newline
37222 0016 E5*01\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  67\InsetSpace ~
37238 \InsetSpace ~
37239 \InsetSpace ~
37240 \InsetSpace ~
37241 \InsetSpace ~
37242 \InsetSpace ~
37243 \InsetSpace ~
37244 \InsetSpace ~
37245  mov\InsetSpace ~
37246 \InsetSpace ~
37247  a,(_gint + 1) 
37248 \newline
37249 0018 33\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 \InsetSpace ~
37265 \InsetSpace ~
37266 \InsetSpace ~
37267  68\InsetSpace ~
37268 \InsetSpace ~
37269 \InsetSpace ~
37270 \InsetSpace ~
37271 \InsetSpace ~
37272 \InsetSpace ~
37273 \InsetSpace ~
37274 \InsetSpace ~
37275  rlc\InsetSpace ~
37276 \InsetSpace ~
37277  a 
37278 \newline
37279 0019 92*01\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
37295  69\InsetSpace ~
37296 \InsetSpace ~
37297 \InsetSpace ~
37298 \InsetSpace ~
37299 \InsetSpace ~
37300 \InsetSpace ~
37301 \InsetSpace ~
37302 \InsetSpace ~
37303  mov\InsetSpace ~
37304 \InsetSpace ~
37305  _foo_hob3_1_1,c 
37306 \newline
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 \InsetSpace ~
37321 \InsetSpace ~
37322 \InsetSpace ~
37323 \InsetSpace ~
37324 \InsetSpace ~
37325 \InsetSpace ~
37326 \InsetSpace ~
37327 \InsetSpace ~
37328 \InsetSpace ~
37329 \InsetSpace ~
37330 \InsetSpace ~
37331 \InsetSpace ~
37332  70 ;\InsetSpace ~
37333  hob.c 10 
37334 \newline
37335 001B E5*01\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  71\InsetSpace ~
37351 \InsetSpace ~
37352 \InsetSpace ~
37353 \InsetSpace ~
37354 \InsetSpace ~
37355 \InsetSpace ~
37356 \InsetSpace ~
37357 \InsetSpace ~
37358  mov\InsetSpace ~
37359 \InsetSpace ~
37360  a,(_gint + 1) 
37361 \newline
37362 001D
37363  03\InsetSpace ~
37364 \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 \InsetSpace ~
37380 \InsetSpace ~
37381  72\InsetSpace ~
37382 \InsetSpace ~
37383 \InsetSpace ~
37384 \InsetSpace ~
37385 \InsetSpace ~
37386 \InsetSpace ~
37387 \InsetSpace ~
37388 \InsetSpace ~
37389  rr\InsetSpace ~
37390 \InsetSpace ~
37391 \InsetSpace ~
37392  a 
37393 \newline
37394 001E 54 01\InsetSpace ~
37395 \InsetSpace ~
37396 \InsetSpace ~
37397 \InsetSpace ~
37398 \InsetSpace ~
37399 \InsetSpace ~
37400 \InsetSpace ~
37401 \InsetSpace ~
37402 \InsetSpace ~
37403 \InsetSpace ~
37404 \InsetSpace ~
37405 \InsetSpace ~
37406 \InsetSpace ~
37407 \InsetSpace ~
37408 \InsetSpace ~
37409  73\InsetSpace ~
37410 \InsetSpace ~
37411 \InsetSpace ~
37412 \InsetSpace ~
37413 \InsetSpace ~
37414 \InsetSpace ~
37415 \InsetSpace ~
37416 \InsetSpace ~
37417  anl\InsetSpace ~
37418 \InsetSpace ~
37419  a,#0x01 
37420 \newline
37421 0020 F5*03\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  74\InsetSpace ~
37437 \InsetSpace ~
37438 \InsetSpace ~
37439 \InsetSpace ~
37440 \InsetSpace ~
37441 \InsetSpace ~
37442 \InsetSpace ~
37443 \InsetSpace ~
37444  mov\InsetSpace ~
37445 \InsetSpace ~
37446  _foo_aob1_1_1,a
37447  
37448 \newline
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 \InsetSpace ~
37463 \InsetSpace ~
37464 \InsetSpace ~
37465 \InsetSpace ~
37466 \InsetSpace ~
37467 \InsetSpace ~
37468 \InsetSpace ~
37469 \InsetSpace ~
37470 \InsetSpace ~
37471 \InsetSpace ~
37472 \InsetSpace ~
37473 \InsetSpace ~
37474  75 ;\InsetSpace ~
37475  hob.c 11 
37476 \newline
37477 0022 E5*01\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  76\InsetSpace ~
37493 \InsetSpace ~
37494 \InsetSpace ~
37495 \InsetSpace ~
37496 \InsetSpace ~
37497 \InsetSpace ~
37498 \InsetSpace ~
37499 \InsetSpace ~
37500  mov\InsetSpace ~
37501 \InsetSpace ~
37502  a,(_gint + 1) 
37503 \newline
37504 0024 13\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 \InsetSpace ~
37520 \InsetSpace ~
37521 \InsetSpace ~
37522  77\InsetSpace ~
37523 \InsetSpace ~
37524 \InsetSpace ~
37525 \InsetSpace ~
37526 \InsetSpace ~
37527 \InsetSpace ~
37528 \InsetSpace ~
37529 \InsetSpace ~
37530  rrc\InsetSpace ~
37531 \InsetSpace ~
37532  a 
37533 \newline
37534 0025 92*02\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
37550  78\InsetSpace ~
37551 \InsetSpace ~
37552 \InsetSpace ~
37553 \InsetSpace ~
37554 \InsetSpace ~
37555 \InsetSpace ~
37556 \InsetSpace ~
37557 \InsetSpace ~
37558  mov\InsetSpace ~
37559 \InsetSpace ~
37560  _foo_aob2_1_1,c 
37561 \newline
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 \InsetSpace ~
37576 \InsetSpace ~
37577 \InsetSpace ~
37578 \InsetSpace ~
37579 \InsetSpace ~
37580 \InsetSpace ~
37581 \InsetSpace ~
37582 \InsetSpace ~
37583 \InsetSpace ~
37584 \InsetSpace ~
37585 \InsetSpace ~
37586 \InsetSpace ~
37587  79 ;\InsetSpace ~
37588  hob.c 12 
37589 \newline
37590 0027 E5*01\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 \InsetSpace ~
37604 \InsetSpace ~
37605  80\InsetSpace ~
37606 \InsetSpace ~
37607 \InsetSpace ~
37608 \InsetSpace ~
37609 \InsetSpace ~
37610 \InsetSpace ~
37611 \InsetSpace ~
37612 \InsetSpace ~
37613  mov\InsetSpace ~
37614 \InsetSpace ~
37615  a,(_gint + 1) 
37616 \newline
37617 0029
37618  A2 E3\InsetSpace ~
37619 \InsetSpace ~
37620 \InsetSpace ~
37621 \InsetSpace ~
37622 \InsetSpace ~
37623 \InsetSpace ~
37624 \InsetSpace ~
37625 \InsetSpace ~
37626 \InsetSpace ~
37627 \InsetSpace ~
37628 \InsetSpace ~
37629 \InsetSpace ~
37630 \InsetSpace ~
37631 \InsetSpace ~
37632 \InsetSpace ~
37633  81\InsetSpace ~
37634 \InsetSpace ~
37635 \InsetSpace ~
37636 \InsetSpace ~
37637 \InsetSpace ~
37638 \InsetSpace ~
37639 \InsetSpace ~
37640 \InsetSpace ~
37641  mov\InsetSpace ~
37642 \InsetSpace ~
37643  c,acc[3] 
37644 \newline
37645 002B 92*03\InsetSpace ~
37646 \InsetSpace ~
37647 \InsetSpace ~
37648 \InsetSpace ~
37649 \InsetSpace ~
37650 \InsetSpace ~
37651 \InsetSpace ~
37652 \InsetSpace ~
37653 \InsetSpace ~
37654 \InsetSpace ~
37655 \InsetSpace ~
37656 \InsetSpace ~
37657 \InsetSpace ~
37658 \InsetSpace ~
37659 \InsetSpace ~
37660  82\InsetSpace ~
37661 \InsetSpace ~
37662 \InsetSpace ~
37663 \InsetSpace ~
37664 \InsetSpace ~
37665 \InsetSpace ~
37666 \InsetSpace ~
37667 \InsetSpace ~
37668  mov\InsetSpace ~
37669 \InsetSpace ~
37670  _foo_aob3_1_1,c 
37671 \end_layout
37672
37673 \begin_layout Standard
37674 Other variations of these cases however will 
37675 \emph on
37676 not
37677 \emph default
37678  be recognized.
37679  They are standard C expressions, so I heartily recommend these be the only
37680  way to get the highest order bit, (it is portable).
37681  Of course it will be recognized even if it is embedded in other expressions,
37682  e.g.:
37683 \end_layout
37684
37685 \begin_layout Verse
37686
37687 \family typewriter
37688 xyz = gint + ((gint >> 15) & 1);
37689 \end_layout
37690
37691 \begin_layout Standard
37692 will still be recognized.
37693 \end_layout
37694
37695 \begin_layout Subsection
37696 Higher Order Byte
37697 \begin_inset LatexCommand index
37698 name "Higher Order Byte"
37699
37700 \end_inset
37701
37702  / Higher Order Word
37703 \begin_inset LatexCommand index
37704 name "Higher Order Word"
37705
37706 \end_inset
37707
37708
37709 \end_layout
37710
37711 \begin_layout Standard
37712 It is also frequently required to obtain a higher order byte or word of
37713  a larger integral type (long, int or short types).
37714  SDCC recognizes the following expressions to yield the higher order byte
37715  or word and generates optimized code for it, e.g.:
37716 \end_layout
37717
37718 \begin_layout Verse
37719
37720 \family typewriter
37721 unsigned int gint; 
37722 \newline
37723 unsigned long int glong; 
37724 \newline
37725
37726 \newline
37727 foo () { 
37728 \newline
37729 \InsetSpace ~
37730 \InsetSpace ~
37731 unsigned char hob1,
37732  hob2; 
37733 \newline
37734 \InsetSpace ~
37735 \InsetSpace ~
37736 unsigned int how1, how2; 
37737 \newline
37738 \InsetSpace ~
37739 \InsetSpace ~
37740 ...
37741  
37742 \newline
37743 \InsetSpace ~
37744 \InsetSpace ~
37745 hob1 = (gint >> 8) & 0xFF; 
37746 \newline
37747 \InsetSpace ~
37748 \InsetSpace ~
37749 hob2 = glong >> 24; 
37750 \newline
37751 \InsetSpace ~
37752 \InsetSpace ~
37753 how1 = (glong >> 16) & 0xFFFF;
37754  
37755 \newline
37756 \InsetSpace ~
37757 \InsetSpace ~
37758 how2 = glong >> 8; 
37759 \newline
37760 \InsetSpace ~
37761 \InsetSpace ~
37762 ..
37763  
37764 \newline
37765 }
37766 \end_layout
37767
37768 \begin_layout Standard
37769 will generate the following code:
37770 \end_layout
37771
37772 \begin_layout Verse
37773
37774 \family typewriter
37775 \InsetSpace ~
37776 \InsetSpace ~
37777 \InsetSpace ~
37778 \InsetSpace ~
37779 \InsetSpace ~
37780 \InsetSpace ~
37781 \InsetSpace ~
37782 \InsetSpace ~
37783 \InsetSpace ~
37784 \InsetSpace ~
37785 \InsetSpace ~
37786 \InsetSpace ~
37787 \InsetSpace ~
37788 \InsetSpace ~
37789 \InsetSpace ~
37790 \InsetSpace ~
37791 \InsetSpace ~
37792 \InsetSpace ~
37793 \InsetSpace ~
37794 \InsetSpace ~
37795 \InsetSpace ~
37796 \InsetSpace ~
37797 \InsetSpace ~
37798 \InsetSpace ~
37799 \InsetSpace ~
37800  91 ;\InsetSpace ~
37801  hob.c 15 
37802 \newline
37803 0037 85*01*06\InsetSpace ~
37804 \InsetSpace ~
37805 \InsetSpace ~
37806 \InsetSpace ~
37807 \InsetSpace ~
37808 \InsetSpace ~
37809 \InsetSpace ~
37810 \InsetSpace ~
37811 \InsetSpace ~
37812 \InsetSpace ~
37813 \InsetSpace ~
37814 \InsetSpace ~
37815  92\InsetSpace ~
37816 \InsetSpace ~
37817 \InsetSpace ~
37818 \InsetSpace ~
37819 \InsetSpace ~
37820 \InsetSpace ~
37821 \InsetSpace ~
37822 \InsetSpace ~
37823  mov\InsetSpace ~
37824 \InsetSpace ~
37825  _foo_hob1_1_1,(_gint + 1) 
37826 \newline
37827 \InsetSpace ~
37828 \InsetSpace ~
37829 \InsetSpace ~
37830 \InsetSpace ~
37831 \InsetSpace ~
37832 \InsetSpace ~
37833 \InsetSpace ~
37834 \InsetSpace ~
37835 \InsetSpace ~
37836 \InsetSpace ~
37837 \InsetSpace ~
37838 \InsetSpace ~
37839 \InsetSpace ~
37840 \InsetSpace ~
37841 \InsetSpace ~
37842 \InsetSpace ~
37843 \InsetSpace ~
37844 \InsetSpace ~
37845 \InsetSpace ~
37846 \InsetSpace ~
37847 \InsetSpace ~
37848 \InsetSpace ~
37849 \InsetSpace ~
37850 \InsetSpace ~
37851 \InsetSpace ~
37852  93 ;\InsetSpace ~
37853  hob.c
37854  16 
37855 \newline
37856 003A 85*05*07\InsetSpace ~
37857 \InsetSpace ~
37858 \InsetSpace ~
37859 \InsetSpace ~
37860 \InsetSpace ~
37861 \InsetSpace ~
37862 \InsetSpace ~
37863 \InsetSpace ~
37864 \InsetSpace ~
37865 \InsetSpace ~
37866 \InsetSpace ~
37867 \InsetSpace ~
37868  94\InsetSpace ~
37869 \InsetSpace ~
37870 \InsetSpace ~
37871 \InsetSpace ~
37872 \InsetSpace ~
37873 \InsetSpace ~
37874 \InsetSpace ~
37875 \InsetSpace ~
37876  mov\InsetSpace ~
37877 \InsetSpace ~
37878  _foo_hob2_1_1,(_glong + 3) 
37879 \newline
37880 \InsetSpace ~
37881 \InsetSpace ~
37882 \InsetSpace ~
37883 \InsetSpace ~
37884 \InsetSpace ~
37885 \InsetSpace ~
37886 \InsetSpace ~
37887 \InsetSpace ~
37888 \InsetSpace ~
37889 \InsetSpace ~
37890 \InsetSpace ~
37891 \InsetSpace ~
37892 \InsetSpace ~
37893 \InsetSpace ~
37894 \InsetSpace ~
37895 \InsetSpace ~
37896 \InsetSpace ~
37897 \InsetSpace ~
37898 \InsetSpace ~
37899 \InsetSpace ~
37900 \InsetSpace ~
37901 \InsetSpace ~
37902 \InsetSpace ~
37903 \InsetSpace ~
37904 \InsetSpace ~
37905  95 ;\InsetSpace ~
37906  hob.c 17 
37907 \newline
37908 003D 85*04*08\InsetSpace ~
37909 \InsetSpace ~
37910 \InsetSpace ~
37911 \InsetSpace ~
37912 \InsetSpace ~
37913 \InsetSpace ~
37914 \InsetSpace ~
37915 \InsetSpace ~
37916 \InsetSpace ~
37917 \InsetSpace ~
37918 \InsetSpace ~
37919 \InsetSpace ~
37920
37921  96\InsetSpace ~
37922 \InsetSpace ~
37923 \InsetSpace ~
37924 \InsetSpace ~
37925 \InsetSpace ~
37926 \InsetSpace ~
37927 \InsetSpace ~
37928 \InsetSpace ~
37929  mov\InsetSpace ~
37930 \InsetSpace ~
37931  _foo_how1_1_1,(_glong + 2) 
37932 \newline
37933 0040 85*05*09\InsetSpace ~
37934 \InsetSpace ~
37935 \InsetSpace ~
37936 \InsetSpace ~
37937 \InsetSpace ~
37938 \InsetSpace ~
37939 \InsetSpace ~
37940 \InsetSpace ~
37941 \InsetSpace ~
37942 \InsetSpace ~
37943 \InsetSpace ~
37944 \InsetSpace ~
37945  97\InsetSpace ~
37946 \InsetSpace ~
37947 \InsetSpace ~
37948 \InsetSpace ~
37949 \InsetSpace ~
37950 \InsetSpace ~
37951 \InsetSpace ~
37952 \InsetSpace ~
37953  mov\InsetSpace ~
37954 \InsetSpace ~
37955  (_foo_how1_1_1 +
37956  1),(_glong + 3) 
37957 \newline
37958 0043 85*03*0A\InsetSpace ~
37959 \InsetSpace ~
37960 \InsetSpace ~
37961 \InsetSpace ~
37962 \InsetSpace ~
37963 \InsetSpace ~
37964 \InsetSpace ~
37965 \InsetSpace ~
37966 \InsetSpace ~
37967 \InsetSpace ~
37968 \InsetSpace ~
37969 \InsetSpace ~
37970  98\InsetSpace ~
37971 \InsetSpace ~
37972 \InsetSpace ~
37973 \InsetSpace ~
37974 \InsetSpace ~
37975 \InsetSpace ~
37976 \InsetSpace ~
37977 \InsetSpace ~
37978  mov\InsetSpace ~
37979 \InsetSpace ~
37980  _foo_how2_1_1,(_glong + 1) 
37981 \newline
37982 0046 85*04*0B\InsetSpace ~
37983 \InsetSpace ~
37984 \InsetSpace ~
37985 \InsetSpace ~
37986 \InsetSpace ~
37987 \InsetSpace ~
37988 \InsetSpace ~
37989 \InsetSpace ~
37990 \InsetSpace ~
37991 \InsetSpace ~
37992 \InsetSpace ~
37993 \InsetSpace ~
37994
37995  99\InsetSpace ~
37996 \InsetSpace ~
37997 \InsetSpace ~
37998 \InsetSpace ~
37999 \InsetSpace ~
38000 \InsetSpace ~
38001 \InsetSpace ~
38002 \InsetSpace ~
38003  mov\InsetSpace ~
38004 \InsetSpace ~
38005  (_foo_how2_1_1 + 1),(_glong + 2) 
38006 \end_layout
38007
38008 \begin_layout Standard
38009 Again, variations of these cases may 
38010 \emph on
38011 not
38012 \emph default
38013  be recognized.
38014  They are standard C expressions, so I heartily recommend these be the only
38015  way to get the higher order byte/word, (it is portable).
38016  Of course it will be recognized even if it is embedded in other expressions,
38017  e.g.:
38018 \end_layout
38019
38020 \begin_layout Verse
38021
38022 \family typewriter
38023 xyz = gint + ((gint >> 8) & 0xFF);
38024 \end_layout
38025
38026 \begin_layout Standard
38027 will still be recognized.
38028 \end_layout
38029
38030 \begin_layout Subsection
38031 Peephole Optimizer
38032 \begin_inset LatexCommand label
38033 name "sub:Peephole-Optimizer"
38034
38035 \end_inset
38036
38037
38038 \begin_inset LatexCommand index
38039 name "Peephole optimizer"
38040
38041 \end_inset
38042
38043
38044 \end_layout
38045
38046 \begin_layout Standard
38047 The compiler uses a rule based, pattern matching and re-writing mechanism
38048  for peep-hole optimization.
38049  It is inspired by 
38050 \emph on
38051 copt
38052 \emph default
38053  a peep-hole optimizer by Christopher W.
38054  Fraser (cwfraser\InsetSpace ~
38055 @\InsetSpace ~
38056 microsoft.com).
38057  A default set of rules are compiled into the compiler, additional rules
38058  may be added with the 
38059 \emph on
38060 -
38061 \begin_inset ERT
38062 status collapsed
38063
38064 \begin_layout Standard
38065
38066
38067 \backslash
38068 /
38069 \end_layout
38070
38071 \end_inset
38072
38073 -peep-file
38074 \begin_inset LatexCommand index
38075 name "-\\/-peep-file"
38076
38077 \end_inset
38078
38079  <filename>
38080 \emph default
38081  option.
38082  The rule language is best illustrated with examples.
38083 \end_layout
38084
38085 \begin_layout Verse
38086
38087 \family typewriter
38088 replace { 
38089 \newline
38090 \InsetSpace ~
38091 \InsetSpace ~
38092 mov %1,a 
38093 \newline
38094 \InsetSpace ~
38095 \InsetSpace ~
38096 mov a,%1
38097 \newline
38098 } by {
38099 \newline
38100 \InsetSpace ~
38101 \InsetSpace ~
38102 mov %1,a
38103 \newline
38104 }
38105 \end_layout
38106
38107 \begin_layout Standard
38108 The above rule will change the following assembly
38109 \begin_inset LatexCommand index
38110 name "Assembler routines"
38111
38112 \end_inset
38113
38114  sequence:
38115 \end_layout
38116
38117 \begin_layout Verse
38118
38119 \family typewriter
38120 mov r1,a 
38121 \newline
38122 mov a,r1
38123 \end_layout
38124
38125 \begin_layout Standard
38126 to
38127 \end_layout
38128
38129 \begin_layout Verse
38130
38131 \family typewriter
38132 mov r1,a
38133 \end_layout
38134
38135 \begin_layout Standard
38136 Note: All occurrences of a 
38137 \emph on
38138 %n
38139 \emph default
38140  (pattern variable) must denote the same string.
38141  With the above rule, the assembly sequence:
38142 \end_layout
38143
38144 \begin_layout Verse
38145
38146 \family typewriter
38147 mov r1,a 
38148 \newline
38149 mov a,r2
38150 \end_layout
38151
38152 \begin_layout Standard
38153 will remain unmodified.
38154 \newline
38155
38156 \newline
38157 Other special case optimizations may be added by the
38158  user (via 
38159 \emph on
38160 -
38161 \begin_inset ERT
38162 status collapsed
38163
38164 \begin_layout Standard
38165
38166
38167 \backslash
38168 /
38169 \end_layout
38170
38171 \end_inset
38172
38173 -peep-file option
38174 \emph default
38175 ).
38176  E.g.
38177  some variants of the 8051 MCU
38178 \begin_inset LatexCommand index
38179 name "MCS51 variants"
38180
38181 \end_inset
38182
38183  allow only 
38184 \family typewriter
38185 ajmp
38186 \family default
38187  and 
38188 \family typewriter
38189 acall
38190 \family default
38191 .
38192  The following two rules will change all 
38193 \family typewriter
38194 ljmp
38195 \family default
38196  and 
38197 \family typewriter
38198 lcall
38199 \family default
38200  to 
38201 \family typewriter
38202 ajmp
38203 \family default
38204  and 
38205 \family typewriter
38206 acall
38207 \end_layout
38208
38209 \begin_layout Verse
38210
38211 \family typewriter
38212 replace { lcall %1 } by { acall %1 } 
38213 \newline
38214 replace { ljmp %1 } by { ajmp %1 }
38215 \end_layout
38216
38217 \begin_layout Standard
38218 (NOTE: from version 2.7.3 on, you can use option -
38219 \emph on
38220
38221 \begin_inset ERT
38222 status collapsed
38223
38224 \begin_layout Standard
38225
38226
38227 \backslash
38228 /
38229 \end_layout
38230
38231 \end_inset
38232
38233
38234 \emph default
38235 -acall-ajmp
38236 \begin_inset LatexCommand index
38237 name "-\\/-acall-ajmp"
38238
38239 \end_inset
38240
38241 , which also takes care of aligning the interrupt vectors properly.)
38242 \newline
38243
38244 \end_layout
38245
38246 \begin_layout Standard
38247 The 
38248 \emph on
38249 inline-assembler code
38250 \emph default
38251  is also passed through the peep hole optimizer, thus the peephole optimizer
38252  can also be used as an assembly level macro expander.
38253  The rules themselves are MCU dependent whereas the rule language infra-structur
38254 e is MCU independent.
38255  Peephole optimization rules for other MCU can be easily programmed using
38256  the rule language.
38257 \newline
38258
38259 \newline
38260 The syntax for a rule is as follows:
38261 \end_layout
38262
38263 \begin_layout Verse
38264
38265 \family typewriter
38266 rule := replace [ restart ] '{' <assembly sequence> '
38267 \backslash
38268 n' 
38269 \newline
38270 \InsetSpace ~
38271  \InsetSpace ~
38272  \InsetSpace ~
38273  \InsetSpace ~
38274  \InsetSpace ~
38275  \InsetSpace ~
38276  \InsetSpace ~
38277  \InsetSpace ~
38278  \InsetSpace ~
38279  \InsetSpace ~
38280  \InsetSpace ~
38281  \InsetSpace ~
38282  \InsetSpace ~
38283  \InsetSpace ~
38284  '}' by '{' '
38285 \backslash
38286 n' 
38287 \newline
38288 \InsetSpace ~
38289  \InsetSpace ~
38290  \InsetSpace ~
38291  \InsetSpace ~
38292  \InsetSpace ~
38293  \InsetSpace ~
38294  \InsetSpace ~
38295  \InsetSpace ~
38296  \InsetSpace ~
38297  \InsetSpace ~
38298  \InsetSpace ~
38299  \InsetSpace ~
38300  \InsetSpace ~
38301  \InsetSpace ~
38302  \InsetSpace ~
38303  \InsetSpace ~
38304  <assembly sequence> '
38305 \backslash
38306 n' 
38307 \newline
38308 \InsetSpace ~
38309  \InsetSpace ~
38310  \InsetSpace ~
38311  \InsetSpace ~
38312  \InsetSpace ~
38313  \InsetSpace ~
38314  \InsetSpace ~
38315  \InsetSpace ~
38316  \InsetSpace ~
38317  \InsetSpace ~
38318  \InsetSpace ~
38319  \InsetSpace ~
38320  \InsetSpace ~
38321  \InsetSpace ~
38322  '}' [if <functionName> ] '
38323 \backslash
38324 n' 
38325 \end_layout
38326
38327 \begin_layout Standard
38328 <assembly sequence> := assembly instruction (each instruction including
38329  labels must be on a separate line).
38330 \newline
38331
38332 \newline
38333 The optimizer will apply to the rules
38334  one by one from the top in the sequence of their appearance, it will terminate
38335  when all rules are exhausted.
38336  If the 'restart' option is specified, then the optimizer will start matching
38337  the rules again from the top, this option for a rule is expensive (performance)
38338 , it is intended to be used in situations where a transformation will trigger
38339  the same rule again.
38340  An example of this (not a good one, it has side effects) is the following
38341  rule:
38342 \end_layout
38343
38344 \begin_layout Verse
38345
38346 \family typewriter
38347 replace restart { 
38348 \newline
38349 \InsetSpace ~
38350 \InsetSpace ~
38351 pop %1 
38352 \newline
38353 \InsetSpace ~
38354 \InsetSpace ~
38355 push %1 } by { 
38356 \newline
38357 \InsetSpace ~
38358 \InsetSpace ~
38359 ; nop 
38360 \newline
38361 }
38362 \end_layout
38363
38364 \begin_layout Standard
38365 Note that the replace pattern cannot be a blank, but can be a comment line.
38366  Without the 'restart' option only the innermost 'pop' 'push' pair would
38367  be eliminated, i.e.:
38368 \end_layout
38369
38370 \begin_layout Verse
38371
38372 \family typewriter
38373 pop ar1 
38374 \newline
38375 pop ar2 
38376 \newline
38377 push ar2 
38378 \newline
38379 push ar1
38380 \end_layout
38381
38382 \begin_layout Standard
38383 would result in:
38384 \end_layout
38385
38386 \begin_layout Verse
38387
38388 \family typewriter
38389 pop ar1 
38390 \newline
38391 ; nop 
38392 \newline
38393 push ar1
38394 \end_layout
38395
38396 \begin_layout Standard
38397
38398 \emph on
38399 with
38400 \emph default
38401  the restart option the rule will be applied again to the resulting code
38402  and then all the pop-push pairs will be eliminated to yield:
38403 \end_layout
38404
38405 \begin_layout Verse
38406
38407 \family typewriter
38408 ; nop 
38409 \newline
38410 ; nop
38411 \end_layout
38412
38413 \begin_layout Standard
38414 A conditional function can be attached to a rule.
38415  Attaching rules are somewhat more involved, let me illustrate this with
38416  an example.
38417 \end_layout
38418
38419 \begin_layout Verse
38420
38421 \family typewriter
38422 replace { 
38423 \newline
38424 \InsetSpace ~
38425  \InsetSpace ~
38426  \InsetSpace ~
38427 ljmp %5 
38428 \newline
38429 %2:
38430 \newline
38431 } by { 
38432 \newline
38433 \InsetSpace ~
38434  \InsetSpace ~
38435  \InsetSpace ~
38436 sjmp %5 
38437 \newline
38438 %2:
38439 \newline
38440 } if labelInRange
38441 \end_layout
38442
38443 \begin_layout Standard
38444 The optimizer does a look-up of a function name table defined in function
38445  
38446 \emph on
38447 callFuncByName
38448 \emph default
38449  in the source file SDCCpeeph.c, with the name 
38450 \emph on
38451 labelInRange
38452 \emph default
38453 .
38454  If it finds a corresponding entry the function is called.
38455  Note there can be no parameters specified for these functions, in this
38456  case the use of 
38457 \emph on
38458 %5
38459 \emph default
38460  is crucial, since the function 
38461 \emph on
38462 labelInRange
38463 \emph default
38464  expects to find the label in that particular variable (the hash table containin
38465 g the variable bindings is passed as a parameter).
38466  If you want to code more such functions, take a close look at the function
38467  labelInRange and the calling mechanism in source file SDCCpeeph.c.
38468  Currently implemented are 
38469 \emph on
38470 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
38471  24bitMode, portIsDS390, 24bitModeAndPortDS390
38472 \emph default
38473  and 
38474 \emph on
38475 notVolatile
38476 \emph default
38477 .
38478 \end_layout
38479
38480 \begin_layout Standard
38481 I know this whole thing is a little kludgey, but maybe some day we will
38482  have some better means.
38483  If you are looking at this file, you will see the default rules that are
38484  compiled into the compiler, you can add your own rules in the default set
38485  there if you get tired of specifying the -
38486 \begin_inset ERT
38487 status collapsed
38488
38489 \begin_layout Standard
38490
38491
38492 \backslash
38493 /
38494 \end_layout
38495
38496 \end_inset
38497
38498 -peep-file option.
38499 \end_layout
38500
38501 \begin_layout Section
38502 ANSI-Compliance
38503 \begin_inset LatexCommand index
38504 name "ANSI-compliance"
38505
38506 \end_inset
38507
38508
38509 \begin_inset LatexCommand label
38510 name "sub:ANSI-Compliance"
38511
38512 \end_inset
38513
38514
38515 \end_layout
38516
38517 \begin_layout Standard
38518 The latest publicly available version of the standard 
38519 \emph on
38520 ISO/IEC 9899 - Programming languages - C
38521 \emph default
38522  should be available at: 
38523 \begin_inset LatexCommand url
38524 target "http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899"
38525
38526 \end_inset
38527
38528 .
38529 \newline
38530
38531 \end_layout
38532
38533 \begin_layout Standard
38534 Deviations from the compliance:
38535 \end_layout
38536
38537 \begin_layout Itemize
38538 functions are not reentrant
38539 \begin_inset LatexCommand index
38540 name "reentrant"
38541
38542 \end_inset
38543
38544  unless explicitly declared as such or the 
38545 \series bold
38546 -
38547 \begin_inset ERT
38548 status collapsed
38549
38550 \begin_layout Standard
38551
38552
38553 \backslash
38554 /
38555 \end_layout
38556
38557 \end_inset
38558
38559 -stack-auto
38560 \begin_inset LatexCommand index
38561 name "-\\/-stack-auto"
38562
38563 \end_inset
38564
38565
38566 \series default
38567  command line option is specified.
38568 \end_layout
38569
38570 \begin_layout Itemize
38571 structures
38572 \begin_inset LatexCommand index
38573 name "struct"
38574
38575 \end_inset
38576
38577  and unions
38578 \begin_inset LatexCommand index
38579 name "union"
38580
38581 \end_inset
38582
38583  cannot be assigned values directly, cannot be passed as function parameters
38584  or assigned to each other and cannot be a return value
38585 \begin_inset LatexCommand index
38586 name "return value"
38587
38588 \end_inset
38589
38590  from a function, e.g.:
38591 \end_layout
38592
38593 \begin_deeper
38594 \begin_layout Verse
38595
38596 \family typewriter
38597 struct s { ...
38598  }; 
38599 \newline
38600 struct s s1, s2; 
38601 \newline
38602 foo() 
38603 \newline
38604
38605 \newline
38606 \InsetSpace ~
38607 \InsetSpace ~
38608 \InsetSpace ~
38609 \InsetSpace ~
38610 ...
38611  
38612 \newline
38613 \InsetSpace ~
38614 \InsetSpace ~
38615 \InsetSpace ~
38616 \InsetSpace ~
38617 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
38618 \newline
38619 \InsetSpace ~
38620 \InsetSpace ~
38621 \InsetSpace ~
38622 \InsetSpace ~
38623 ...
38624  
38625 \newline
38626 }
38627 \newline
38628
38629 \series bold
38630 struct
38631 \family default
38632 \series default
38633  
38634 \family typewriter
38635 s foo1 (
38636 \series bold
38637 struct
38638 \family default
38639 \series default
38640  
38641 \family typewriter
38642 s parms) /* invalid in SDCC although allowed in ANSI */
38643 \newline
38644
38645 \newline
38646 \InsetSpace ~
38647 \InsetSpace ~
38648 \InsetSpace ~
38649 \InsetSpace ~
38650 struct s rets;
38651  
38652 \newline
38653 \InsetSpace ~
38654 \InsetSpace ~
38655 \InsetSpace ~
38656 \InsetSpace ~
38657 ...
38658  
38659 \newline
38660 \InsetSpace ~
38661 \InsetSpace ~
38662 \InsetSpace ~
38663 \InsetSpace ~
38664 return rets; /* is invalid in SDCC although allowed in ANSI */ 
38665 \newline
38666 }
38667 \end_layout
38668
38669 \end_deeper
38670 \begin_layout Itemize
38671 initialization of structure arrays must be fully braced.
38672 \end_layout
38673
38674 \begin_deeper
38675 \begin_layout Verse
38676
38677 \family typewriter
38678 struct s { char x } a[] = {1, 2};\InsetSpace ~
38679 \InsetSpace ~
38680 \InsetSpace ~
38681 \InsetSpace ~
38682 \InsetSpace ~
38683 /* invalid in SDCC */
38684 \newline
38685 struct s { char x
38686  } a[] = {{1}, {2}}; /* OK */
38687 \end_layout
38688
38689 \end_deeper
38690 \begin_layout Itemize
38691 'long long
38692 \begin_inset LatexCommand index
38693 name "long long (not supported)"
38694
38695 \end_inset
38696
38697 ' (64 bit integers
38698 \begin_inset LatexCommand index
38699 name "int (64 bit) (not supported)"
38700
38701 \end_inset
38702
38703 ) not supported.
38704 \end_layout
38705
38706 \begin_layout Itemize
38707 'double
38708 \begin_inset LatexCommand index
38709 name "double (not supported)"
38710
38711 \end_inset
38712
38713 ' precision floating point 
38714 \begin_inset LatexCommand index
38715 name "Floating point support"
38716
38717 \end_inset
38718
38719 not supported.
38720 \end_layout
38721
38722 \begin_layout Itemize
38723 Old K&R style
38724 \begin_inset LatexCommand index
38725 name "K\\&R style"
38726
38727 \end_inset
38728
38729  function declarations are NOT allowed.
38730 \end_layout
38731
38732 \begin_deeper
38733 \begin_layout Verse
38734
38735 \family typewriter
38736 foo(i,j) /* this old style of function declarations */ 
38737 \newline
38738 int i,j; /* is valid
38739  in ANSI but not valid in SDCC */ 
38740 \newline
38741
38742 \newline
38743 \InsetSpace ~
38744 \InsetSpace ~
38745 \InsetSpace ~
38746 \InsetSpace ~
38747 ...
38748  
38749 \newline
38750 }
38751 \end_layout
38752
38753 \end_deeper
38754 \begin_layout Itemize
38755 Most enhancements in C99 are not supported, e.g.:
38756 \end_layout
38757
38758 \begin_deeper
38759 \begin_layout Verse
38760
38761 \family typewriter
38762 for (
38763 \series bold
38764 int
38765 \family default
38766 \series default
38767  
38768 \family typewriter
38769 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
38770 \end_layout
38771
38772 \end_deeper
38773 \begin_layout Itemize
38774 But some have been added recently in SDCC 2.7.0.
38775  They must be considered alpha quality however.
38776 \end_layout
38777
38778 \begin_deeper
38779 \begin_layout Verse
38780
38781 \family typewriter
38782 \series bold
38783 inline
38784 \begin_inset LatexCommand index
38785 name "inline (not supported)"
38786
38787 \end_inset
38788
38789
38790 \family default
38791 \series default
38792  
38793 \family typewriter
38794 int increment (int a) { return a+1; } /* inlines the increment without function
38795  call overhead */
38796 \newline
38797 int *
38798 \family default
38799  
38800 \family typewriter
38801 \series bold
38802 restrict
38803 \begin_inset LatexCommand index
38804 name "inline (not supported)"
38805
38806 \end_inset
38807
38808
38809 \family default
38810 \series default
38811  
38812 \family typewriter
38813 p; /* accepted but ignored */
38814 \end_layout
38815
38816 \end_deeper
38817 \begin_layout Itemize
38818 Certain words that are valid identifiers in the standard may be reserved
38819  words in SDCC unless the 
38820 \series bold
38821 -
38822 \begin_inset ERT
38823 status collapsed
38824
38825 \begin_layout Standard
38826
38827
38828 \backslash
38829 /
38830 \end_layout
38831
38832 \end_inset
38833
38834 -std-c89
38835 \begin_inset LatexCommand index
38836 name "-\\/-std-c89"
38837
38838 \end_inset
38839
38840
38841 \series default
38842  or 
38843 \series bold
38844 -
38845 \begin_inset ERT
38846 status collapsed
38847
38848 \begin_layout Standard
38849
38850
38851 \backslash
38852 /
38853 \end_layout
38854
38855 \end_inset
38856
38857 -std-c99
38858 \begin_inset LatexCommand index
38859 name "-\\/-std-c99"
38860
38861 \end_inset
38862
38863
38864 \series default
38865  command line options are used.
38866  These may include (depending on the selected processor): 'at', 'banked',
38867  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
38868 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
38869  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
38870  '_naked'.
38871  Compliant equivalents of these keywords are always available in a form
38872  that begin with two underscores
38873 \begin_inset LatexCommand index
38874 name "\\_\\_ (prefix for extended keywords)"
38875
38876 \end_inset
38877
38878 , f.e.
38879  '__data' instead of 'data'.
38880 \end_layout
38881
38882 \begin_layout Itemize
38883 Integer promotion of variable arguments is not performed if the argument
38884  is explicitly taypecasted unless the 
38885 \series bold
38886 -
38887 \begin_inset ERT
38888 status collapsed
38889
38890 \begin_layout Standard
38891
38892
38893 \backslash
38894 /
38895 \end_layout
38896
38897 \end_inset
38898
38899 -std-c89
38900 \begin_inset LatexCommand index
38901 name "-\\/-std-c89"
38902
38903 \end_inset
38904
38905
38906 \series default
38907  or 
38908 \series bold
38909 -
38910 \begin_inset ERT
38911 status collapsed
38912
38913 \begin_layout Standard
38914
38915
38916 \backslash
38917 /
38918 \end_layout
38919
38920 \end_inset
38921
38922 -std-c99
38923 \begin_inset LatexCommand index
38924 name "-\\/-std-c99"
38925
38926 \end_inset
38927
38928
38929 \series default
38930  command line options are used.
38931 \end_layout
38932
38933 \begin_deeper
38934 \begin_layout Verse
38935
38936 \family typewriter
38937 void vararg_func (char *str, ...) { str; }
38938 \newline
38939
38940 \newline
38941 void main (void)
38942 \newline
38943 {
38944 \newline
38945 \InsetSpace ~
38946 \InsetSpace ~
38947 char c = 10;
38948 \newline
38949
38950 \newline
38951 \InsetSpace ~
38952 \InsetSpace ~
38953 /* argument
38954  u is promoted to int before
38955 \newline
38956 \InsetSpace ~
38957 \InsetSpace ~
38958 \InsetSpace ~
38959 * passing to function */
38960 \newline
38961 \InsetSpace ~
38962 \InsetSpace ~
38963 vararg_func ("%c", c);
38964 \newline
38965
38966 \newline
38967 \InsetSpace ~
38968 \InsetSpace ~
38969 /*
38970  argument u is not promoted to int,
38971 \newline
38972 \InsetSpace ~
38973 \InsetSpace ~
38974 \InsetSpace ~
38975 * it is passed as char to function
38976 \newline
38977 \InsetSpace ~
38978 \InsetSpace ~
38979 \InsetSpace ~
38980 * if
38981  --std-cXX is not defined;
38982 \newline
38983 \InsetSpace ~
38984 \InsetSpace ~
38985 \InsetSpace ~
38986 * is promoted to int before passing
38987 \newline
38988 \InsetSpace ~
38989 \InsetSpace ~
38990 \InsetSpace ~
38991 * to function
38992  if --std-cXX is defined */
38993 \newline
38994 \InsetSpace ~
38995 \InsetSpace ~
38996 vararg_func ("%bc", (char)u);
38997 \newline
38998 }
38999 \end_layout
39000
39001 \end_deeper
39002 \begin_layout Section
39003 Cyclomatic Complexity
39004 \begin_inset LatexCommand index
39005 name "Cyclomatic complexity"
39006
39007 \end_inset
39008
39009
39010 \end_layout
39011
39012 \begin_layout Standard
39013 Cyclomatic complexity of a function is defined as the number of independent
39014  paths the program can take during execution of the function.
39015  This is an important number since it defines the number test cases you
39016  have to generate to validate the function.
39017  The accepted industry standard for complexity number is 10, if the cyclomatic
39018  complexity reported by SDCC exceeds 10 you should think about simplification
39019  of the function logic.
39020  Note that the complexity level is not related to the number of lines of
39021  code in a function.
39022  Large functions can have low complexity, and small functions can have large
39023  complexity levels.
39024  
39025 \newline
39026
39027 \newline
39028 SDCC uses the following formula to compute the complexity:
39029 \newline
39030
39031 \end_layout
39032
39033 \begin_layout Standard
39034 complexity = (number of edges in control flow graph) - (number of nodes
39035  in control flow graph) + 2;
39036 \newline
39037
39038 \newline
39039 Having said that the industry standard is 10,
39040  you should be aware that in some cases it be may unavoidable to have a
39041  complexity level of less than 10.
39042  For example if you have switch statement with more than 10 case labels,
39043  each case label adds one to the complexity level.
39044  The complexity level is by no means an absolute measure of the algorithmic
39045  complexity of the function, it does however provide a good starting point
39046  for which functions you might look at for further optimization.
39047 \end_layout
39048
39049 \begin_layout Section
39050 Retargetting for other Processors
39051 \end_layout
39052
39053 \begin_layout Standard
39054 The issues for retargetting the compiler are far too numerous to be covered
39055  by this document.
39056  What follows is a brief description of each of the seven phases of the
39057  compiler and its MCU dependency.
39058 \end_layout
39059
39060 \begin_layout Itemize
39061 Parsing the source and building the annotated parse tree.
39062  This phase is largely MCU independent (except for the language extensions).
39063  Syntax & semantic checks are also done in this phase, along with some initial
39064  optimizations like back patching labels and the pattern matching optimizations
39065  like bit-rotation etc.
39066 \end_layout
39067
39068 \begin_layout Itemize
39069 The second phase involves generating an intermediate code which can be easy
39070  manipulated during the later phases.
39071  This phase is entirely MCU independent.
39072  The intermediate code generation assumes the target machine has unlimited
39073  number of registers, and designates them with the name iTemp.
39074  The compiler can be made to dump a human readable form of the code generated
39075  by using the -
39076 \begin_inset ERT
39077 status collapsed
39078
39079 \begin_layout Standard
39080
39081
39082 \backslash
39083 /
39084 \end_layout
39085
39086 \end_inset
39087
39088 -dumpraw option.
39089 \end_layout
39090
39091 \begin_layout Itemize
39092 This phase does the bulk of the standard optimizations and is also MCU independe
39093 nt.
39094  This phase can be broken down into several sub-phases:
39095 \newline
39096
39097 \newline
39098 Break down intermediate
39099  code (iCode) into basic blocks.
39100 \newline
39101 Do control flow & data flow analysis on the
39102  basic blocks.
39103 \newline
39104 Do local common subexpression elimination, then global subexpressio
39105 n elimination
39106 \newline
39107 Dead code elimination
39108 \newline
39109 Loop optimizations
39110 \newline
39111 If loop optimizations
39112  caused any changes then do 'global subexpression elimination' and 'dead
39113  code elimination' again.
39114 \end_layout
39115
39116 \begin_layout Itemize
39117 This phase determines the live-ranges; by live range I mean those iTemp
39118  variables defined by the compiler that still survive after all the optimization
39119 s.
39120  Live range analysis
39121 \begin_inset LatexCommand index
39122 name "Live range analysis"
39123
39124 \end_inset
39125
39126  is essential for register allocation, since these computation determines
39127  which of these iTemps will be assigned to registers, and for how long.
39128 \end_layout
39129
39130 \begin_layout Itemize
39131 Phase five is register allocation.
39132  There are two parts to this process.
39133 \newline
39134
39135 \newline
39136 The first part I call 'register packing'
39137  (for lack of a better term).
39138  In this case several MCU specific expression folding is done to reduce
39139  register pressure.
39140 \newline
39141
39142 \newline
39143 The second part is more MCU independent and deals with
39144  allocating registers to the remaining live ranges.
39145  A lot of MCU specific code does creep into this phase because of the limited
39146  number of index registers available in the 8051.
39147 \end_layout
39148
39149 \begin_layout Itemize
39150 The Code generation phase is (unhappily), entirely MCU dependent and very
39151  little (if any at all) of this code can be reused for other MCU.
39152  However the scheme for allocating a homogenized assembler operand for each
39153  iCode operand may be reused.
39154 \end_layout
39155
39156 \begin_layout Itemize
39157 As mentioned in the optimization section the peep-hole optimizer is rule
39158  based system, which can reprogrammed for other MCUs.
39159 \end_layout
39160
39161 \begin_layout Standard
39162 More information is available on SDCC Wiki
39163 \begin_inset LatexCommand index
39164 name "wiki"
39165
39166 \end_inset
39167
39168  (preliminary link 
39169 \begin_inset LatexCommand url
39170 target "http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting"
39171
39172 \end_inset
39173
39174 ) and in the thread 
39175 \begin_inset LatexCommand url
39176 target "http://sf.net/mailarchive/message.php?msg_id=13954144"
39177
39178 \end_inset
39179
39180  .
39181 \end_layout
39182
39183 \begin_layout Chapter
39184 Compiler internals
39185 \begin_inset LatexCommand index
39186 name "Compiler internals"
39187
39188 \end_inset
39189
39190
39191 \end_layout
39192
39193 \begin_layout Section
39194 The anatomy of the compiler
39195 \begin_inset LatexCommand label
39196 name "sub:The-anatomy-of"
39197
39198 \end_inset
39199
39200
39201 \end_layout
39202
39203 \begin_layout Standard
39204
39205 \shape italic
39206 This is an excerpt from an article published in Circuit Cellar Magazine
39207  in
39208 \shape default
39209  
39210 \series bold
39211 \shape italic
39212 August 2000
39213 \series default
39214 .
39215  It's a little outdated (the compiler is much more efficient now and user/develo
39216 per friendly), but pretty well exposes the guts of it all.
39217 \shape default
39218
39219 \newline
39220
39221 \newline
39222 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
39223  It is fairly easy to retarget for other 8-bit MCU.
39224  Here we take a look at some of the internals of the compiler.
39225  
39226 \end_layout
39227
39228 \begin_layout Paragraph*
39229 Parsing
39230 \begin_inset LatexCommand index
39231 name "Parsing"
39232
39233 \end_inset
39234
39235  
39236 \end_layout
39237
39238 \begin_layout Standard
39239 Parsing the input source file and creating an AST (Annotated Syntax Tree
39240 \begin_inset LatexCommand index
39241 name "Annotated syntax tree"
39242
39243 \end_inset
39244
39245 ).
39246  This phase also involves propagating types (annotating each node of the
39247  parse tree with type information) and semantic analysis.
39248  There are some MCU specific parsing rules.
39249  For example the storage classes, the extended storage classes are MCU specific
39250  while there may be a xdata storage class for 8051 there is no such storage
39251  class for z80 or Atmel AVR.
39252  SDCC allows MCU specific storage class extensions, i.e.
39253  xdata will be treated as a storage class specifier when parsing 8051 C
39254  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
39255  C code.
39256 \end_layout
39257
39258 \begin_layout Paragraph*
39259 Generating iCode
39260 \begin_inset LatexCommand index
39261 name "iCode"
39262
39263 \end_inset
39264
39265
39266 \end_layout
39267
39268 \begin_layout Standard
39269 Intermediate code generation.
39270  In this phase the AST is broken down into three-operand form (iCode).
39271  These three operand forms are represented as doubly linked lists.
39272  ICode is the term given to the intermediate form generated by the compiler.
39273  ICode example section shows some examples of iCode generated for some simple
39274  C source functions.
39275 \end_layout
39276
39277 \begin_layout Paragraph*
39278 Optimizations
39279 \begin_inset LatexCommand index
39280 name "Optimizations"
39281
39282 \end_inset
39283
39284 .
39285 \end_layout
39286
39287 \begin_layout Standard
39288 Bulk of the target independent optimizations is performed in this phase.
39289  The optimizations include constant propagation, common sub-expression eliminati
39290 on, loop invariant code movement, strength reduction of loop induction variables
39291  and dead-code elimination.
39292 \end_layout
39293
39294 \begin_layout Paragraph*
39295 Live range analysis
39296 \begin_inset LatexCommand index
39297 name "Live range analysis"
39298
39299 \end_inset
39300
39301
39302 \end_layout
39303
39304 \begin_layout Standard
39305 During intermediate code generation phase, the compiler assumes the target
39306  machine has infinite number of registers and generates a lot of temporary
39307  variables.
39308  The live range computation determines the lifetime of each of these compiler-ge
39309 nerated temporaries.
39310  A picture speaks a thousand words.
39311  ICode example sections show the live range annotations for each of the
39312  operand.
39313  It is important to note here, each iCode is assigned a number in the order
39314  of its execution in the function.
39315  The live ranges are computed in terms of these numbers.
39316  The from number is the number of the iCode which first defines the operand
39317  and the to number signifies the iCode which uses this operand last.
39318 \end_layout
39319
39320 \begin_layout Paragraph*
39321 Register Allocation
39322 \begin_inset LatexCommand index
39323 name "Register allocation"
39324
39325 \end_inset
39326
39327
39328 \end_layout
39329
39330 \begin_layout Standard
39331 The register allocation determines the type and number of registers needed
39332  by each operand.
39333  In most MCUs only a few registers can be used for indirect addressing.
39334  In case of 8051 for example the registers R0 & R1 can be used to indirectly
39335  address the internal ram and DPTR to indirectly address the external ram.
39336  The compiler will try to allocate the appropriate register to pointer variables
39337  if it can.
39338  ICode example section shows the operands annotated with the registers assigned
39339  to them.
39340  The compiler will try to keep operands in registers as much as possible;
39341  there are several schemes the compiler uses to do achieve this.
39342  When the compiler runs out of registers the compiler will check to see
39343  if there are any live operands which is not used or defined in the current
39344  basic block being processed, if there are any found then it will push that
39345  operand and use the registers in this block, the operand will then be popped
39346  at the end of the basic block.
39347  
39348 \end_layout
39349
39350 \begin_layout Standard
39351 There are other MCU specific considerations in this phase.
39352  Some MCUs have an accumulator; very short-lived operands could be assigned
39353  to the accumulator instead of a general-purpose register.
39354 \end_layout
39355
39356 \begin_layout Paragraph*
39357 Code generation
39358 \end_layout
39359
39360 \begin_layout Standard
39361 Figure II gives a table of iCode
39362 \begin_inset LatexCommand index
39363 name "iCode"
39364
39365 \end_inset
39366
39367  operations supported by the compiler.
39368  The code generation involves translating these operations into corresponding
39369  assembly code for the processor.
39370  This sounds overly simple but that is the essence of code generation.
39371  Some of the iCode operations are generated on a MCU specific manner for
39372  example, the z80 port does not use registers to pass parameters so the
39373  SEND and RECV iCode operations will not be generated, and it also does
39374  not support JUMPTABLES.
39375  
39376 \newline
39377
39378 \end_layout
39379
39380 \begin_layout Standard
39381
39382 \size footnotesize
39383 Figure II 
39384 \begin_inset Tabular
39385 <lyxtabular version="3" rows="39" columns="4">
39386 <features islongtable="true" headBottomDL="true">
39387 <column alignment="block" valignment="top" leftline="true" width="13col%">
39388 <column alignment="left" valignment="top" leftline="true" width="13col%">
39389 <column alignment="block" valignment="top" leftline="true" width="22col%">
39390 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
39391 <row topline="true" bottomline="true" endhead="true">
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 iCode
39399 \series default
39400
39401 \begin_inset LatexCommand index
39402 name "iCode"
39403
39404 \end_inset
39405
39406
39407 \end_layout
39408
39409 \end_inset
39410 </cell>
39411 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39412 \begin_inset Text
39413
39414 \begin_layout Standard
39415
39416 \series bold
39417 Operands
39418 \end_layout
39419
39420 \end_inset
39421 </cell>
39422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39423 \begin_inset Text
39424
39425 \begin_layout Standard
39426
39427 \series bold
39428 Description
39429 \end_layout
39430
39431 \end_inset
39432 </cell>
39433 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39434 \begin_inset Text
39435
39436 \begin_layout Standard
39437
39438 \series bold
39439 C Equivalent
39440 \end_layout
39441
39442 \end_inset
39443 </cell>
39444 </row>
39445 <row topline="true">
39446 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39447 \begin_inset Text
39448
39449 \begin_layout Standard
39450
39451 \size footnotesize
39452 '!'
39453 \end_layout
39454
39455 \end_inset
39456 </cell>
39457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39458 \begin_inset Text
39459
39460 \begin_layout Standard
39461
39462 \size footnotesize
39463 IC_LEFT() IC_RESULT()
39464 \end_layout
39465
39466 \end_inset
39467 </cell>
39468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39469 \begin_inset Text
39470
39471 \begin_layout Standard
39472
39473 \size footnotesize
39474 NOT operation 
39475 \end_layout
39476
39477 \end_inset
39478 </cell>
39479 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39480 \begin_inset Text
39481
39482 \begin_layout Standard
39483
39484 \size footnotesize
39485 IC_RESULT = ! IC_LEFT;
39486 \end_layout
39487
39488 \end_inset
39489 </cell>
39490 </row>
39491 <row topline="true">
39492 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39493 \begin_inset Text
39494
39495 \begin_layout Standard
39496
39497 \size footnotesize
39498 '~'
39499 \end_layout
39500
39501 \end_inset
39502 </cell>
39503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39504 \begin_inset Text
39505
39506 \begin_layout Standard
39507
39508 \size footnotesize
39509 IC_LEFT() IC_RESULT()
39510 \end_layout
39511
39512 \end_inset
39513 </cell>
39514 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39515 \begin_inset Text
39516
39517 \begin_layout Standard
39518
39519 \size footnotesize
39520 Bitwise complement of 
39521 \end_layout
39522
39523 \end_inset
39524 </cell>
39525 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39526 \begin_inset Text
39527
39528 \begin_layout Standard
39529
39530 \size footnotesize
39531 IC_RESULT = ~IC_LEFT;
39532 \end_layout
39533
39534 \end_inset
39535 </cell>
39536 </row>
39537 <row topline="true">
39538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39539 \begin_inset Text
39540
39541 \begin_layout Standard
39542
39543 \size footnotesize
39544 RRC
39545 \end_layout
39546
39547 \end_inset
39548 </cell>
39549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39550 \begin_inset Text
39551
39552 \begin_layout Standard
39553
39554 \size footnotesize
39555 IC_LEFT() IC_RESULT()
39556 \end_layout
39557
39558 \end_inset
39559 </cell>
39560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39561 \begin_inset Text
39562
39563 \begin_layout Standard
39564
39565 \size footnotesize
39566 Rotate right with carry
39567 \end_layout
39568
39569 \end_inset
39570 </cell>
39571 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39572 \begin_inset Text
39573
39574 \begin_layout Standard
39575
39576 \size footnotesize
39577 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
39578 \end_layout
39579
39580 \end_inset
39581 </cell>
39582 </row>
39583 <row topline="true">
39584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39585 \begin_inset Text
39586
39587 \begin_layout Standard
39588
39589 \size footnotesize
39590 RLC
39591 \end_layout
39592
39593 \end_inset
39594 </cell>
39595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39596 \begin_inset Text
39597
39598 \begin_layout Standard
39599
39600 \size footnotesize
39601 IC_LEFT() IC_RESULT()
39602 \end_layout
39603
39604 \end_inset
39605 </cell>
39606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39607 \begin_inset Text
39608
39609 \begin_layout Standard
39610
39611 \size footnotesize
39612 Rotate left with carry
39613 \end_layout
39614
39615 \end_inset
39616 </cell>
39617 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39618 \begin_inset Text
39619
39620 \begin_layout Standard
39621
39622 \size footnotesize
39623 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
39624 \end_layout
39625
39626 \end_inset
39627 </cell>
39628 </row>
39629 <row topline="true">
39630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39631 \begin_inset Text
39632
39633 \begin_layout Standard
39634
39635 \size footnotesize
39636 GETHBIT
39637 \end_layout
39638
39639 \end_inset
39640 </cell>
39641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39642 \begin_inset Text
39643
39644 \begin_layout Standard
39645
39646 \size footnotesize
39647 IC_LEFT() IC_RESULT()
39648 \end_layout
39649
39650 \end_inset
39651 </cell>
39652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39653 \begin_inset Text
39654
39655 \begin_layout Standard
39656
39657 \size footnotesize
39658 Get the highest order bit of IC_LEFT
39659 \end_layout
39660
39661 \end_inset
39662 </cell>
39663 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39664 \begin_inset Text
39665
39666 \begin_layout Standard
39667
39668 \size footnotesize
39669 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
39670 \end_layout
39671
39672 \end_inset
39673 </cell>
39674 </row>
39675 <row topline="true">
39676 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39677 \begin_inset Text
39678
39679 \begin_layout Standard
39680
39681 \size footnotesize
39682 UNARYMINUS
39683 \end_layout
39684
39685 \end_inset
39686 </cell>
39687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39688 \begin_inset Text
39689
39690 \begin_layout Standard
39691
39692 \size footnotesize
39693 IC_LEFT() IC_RESULT()
39694 \end_layout
39695
39696 \end_inset
39697 </cell>
39698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39699 \begin_inset Text
39700
39701 \begin_layout Standard
39702
39703 \size footnotesize
39704 Unary minus
39705 \end_layout
39706
39707 \end_inset
39708 </cell>
39709 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39710 \begin_inset Text
39711
39712 \begin_layout Standard
39713
39714 \size footnotesize
39715 IC_RESULT = - IC_LEFT;
39716 \end_layout
39717
39718 \end_inset
39719 </cell>
39720 </row>
39721 <row topline="true">
39722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39723 \begin_inset Text
39724
39725 \begin_layout Standard
39726
39727 \size footnotesize
39728 IPUSH
39729 \end_layout
39730
39731 \end_inset
39732 </cell>
39733 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39734 \begin_inset Text
39735
39736 \begin_layout Standard
39737
39738 \size footnotesize
39739 IC_LEFT()
39740 \end_layout
39741
39742 \end_inset
39743 </cell>
39744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39745 \begin_inset Text
39746
39747 \begin_layout Standard
39748
39749 \size footnotesize
39750 Push the operand into stack
39751 \end_layout
39752
39753 \end_inset
39754 </cell>
39755 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39756 \begin_inset Text
39757
39758 \begin_layout Standard
39759
39760 \size footnotesize
39761 NONE
39762 \end_layout
39763
39764 \end_inset
39765 </cell>
39766 </row>
39767 <row topline="true">
39768 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39769 \begin_inset Text
39770
39771 \begin_layout Standard
39772
39773 \size footnotesize
39774 IPOP
39775 \end_layout
39776
39777 \end_inset
39778 </cell>
39779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39780 \begin_inset Text
39781
39782 \begin_layout Standard
39783
39784 \size footnotesize
39785 IC_LEFT()
39786 \end_layout
39787
39788 \end_inset
39789 </cell>
39790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39791 \begin_inset Text
39792
39793 \begin_layout Standard
39794
39795 \size footnotesize
39796 Pop the operand from the stack 
39797 \end_layout
39798
39799 \end_inset
39800 </cell>
39801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39802 \begin_inset Text
39803
39804 \begin_layout Standard
39805
39806 \size footnotesize
39807 NONE
39808 \end_layout
39809
39810 \end_inset
39811 </cell>
39812 </row>
39813 <row topline="true">
39814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39815 \begin_inset Text
39816
39817 \begin_layout Standard
39818
39819 \size footnotesize
39820 CALL
39821 \end_layout
39822
39823 \end_inset
39824 </cell>
39825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39826 \begin_inset Text
39827
39828 \begin_layout Standard
39829
39830 \size footnotesize
39831 IC_LEFT() IC_RESULT()
39832 \end_layout
39833
39834 \end_inset
39835 </cell>
39836 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39837 \begin_inset Text
39838
39839 \begin_layout Standard
39840
39841 \size footnotesize
39842 Call the function represented by IC_LEFT 
39843 \end_layout
39844
39845 \end_inset
39846 </cell>
39847 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39848 \begin_inset Text
39849
39850 \begin_layout Standard
39851
39852 \size footnotesize
39853 IC_RESULT = IC_LEFT();
39854 \end_layout
39855
39856 \end_inset
39857 </cell>
39858 </row>
39859 <row topline="true">
39860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39861 \begin_inset Text
39862
39863 \begin_layout Standard
39864
39865 \size footnotesize
39866 PCALL
39867 \end_layout
39868
39869 \end_inset
39870 </cell>
39871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39872 \begin_inset Text
39873
39874 \begin_layout Standard
39875
39876 \size footnotesize
39877 IC_LEFT() IC_RESULT()
39878 \end_layout
39879
39880 \end_inset
39881 </cell>
39882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39883 \begin_inset Text
39884
39885 \begin_layout Standard
39886
39887 \size footnotesize
39888 Call via function pointer
39889 \end_layout
39890
39891 \end_inset
39892 </cell>
39893 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39894 \begin_inset Text
39895
39896 \begin_layout Standard
39897
39898 \size footnotesize
39899 IC_RESULT = (*IC_LEFT)();
39900 \end_layout
39901
39902 \end_inset
39903 </cell>
39904 </row>
39905 <row topline="true">
39906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39907 \begin_inset Text
39908
39909 \begin_layout Standard
39910
39911 \size footnotesize
39912 RETURN
39913 \end_layout
39914
39915 \end_inset
39916 </cell>
39917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39918 \begin_inset Text
39919
39920 \begin_layout Standard
39921
39922 \size footnotesize
39923 IC_LEFT()
39924 \end_layout
39925
39926 \end_inset
39927 </cell>
39928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39929 \begin_inset Text
39930
39931 \begin_layout Standard
39932
39933 \size footnotesize
39934 Return the value in operand IC_LEFT 
39935 \end_layout
39936
39937 \end_inset
39938 </cell>
39939 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39940 \begin_inset Text
39941
39942 \begin_layout Standard
39943
39944 \size footnotesize
39945 return IC_LEFT;
39946 \end_layout
39947
39948 \end_inset
39949 </cell>
39950 </row>
39951 <row topline="true">
39952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39953 \begin_inset Text
39954
39955 \begin_layout Standard
39956
39957 \size footnotesize
39958 LABEL
39959 \end_layout
39960
39961 \end_inset
39962 </cell>
39963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39964 \begin_inset Text
39965
39966 \begin_layout Standard
39967
39968 \size footnotesize
39969 IC_LABEL() 
39970 \end_layout
39971
39972 \end_inset
39973 </cell>
39974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39975 \begin_inset Text
39976
39977 \begin_layout Standard
39978
39979 \size footnotesize
39980 Label
39981 \end_layout
39982
39983 \end_inset
39984 </cell>
39985 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39986 \begin_inset Text
39987
39988 \begin_layout Standard
39989
39990 \size footnotesize
39991 IC_LABEL:
39992 \end_layout
39993
39994 \end_inset
39995 </cell>
39996 </row>
39997 <row topline="true">
39998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39999 \begin_inset Text
40000
40001 \begin_layout Standard
40002
40003 \size footnotesize
40004 GOTO
40005 \end_layout
40006
40007 \end_inset
40008 </cell>
40009 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40010 \begin_inset Text
40011
40012 \begin_layout Standard
40013
40014 \size footnotesize
40015 IC_LABEL() 
40016 \end_layout
40017
40018 \end_inset
40019 </cell>
40020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40021 \begin_inset Text
40022
40023 \begin_layout Standard
40024
40025 \size footnotesize
40026 Goto label
40027 \end_layout
40028
40029 \end_inset
40030 </cell>
40031 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40032 \begin_inset Text
40033
40034 \begin_layout Standard
40035
40036 \size footnotesize
40037 goto IC_LABEL();
40038 \end_layout
40039
40040 \end_inset
40041 </cell>
40042 </row>
40043 <row topline="true">
40044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40045 \begin_inset Text
40046
40047 \begin_layout Standard
40048
40049 \size footnotesize
40050 '+'
40051 \end_layout
40052
40053 \end_inset
40054 </cell>
40055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40056 \begin_inset Text
40057
40058 \begin_layout Standard
40059
40060 \size footnotesize
40061 IC_LEFT() IC_RIGHT() IC_RESULT()
40062 \end_layout
40063
40064 \end_inset
40065 </cell>
40066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40067 \begin_inset Text
40068
40069 \begin_layout Standard
40070
40071 \size footnotesize
40072 Addition
40073 \end_layout
40074
40075 \end_inset
40076 </cell>
40077 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40078 \begin_inset Text
40079
40080 \begin_layout Standard
40081
40082 \size footnotesize
40083 IC_RESULT = IC_LEFT + IC_RIGHT
40084 \end_layout
40085
40086 \end_inset
40087 </cell>
40088 </row>
40089 <row topline="true">
40090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40091 \begin_inset Text
40092
40093 \begin_layout Standard
40094
40095 \size footnotesize
40096 '-'
40097 \end_layout
40098
40099 \end_inset
40100 </cell>
40101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40102 \begin_inset Text
40103
40104 \begin_layout Standard
40105
40106 \size footnotesize
40107 IC_LEFT() IC_RIGHT() IC_RESULT()
40108 \end_layout
40109
40110 \end_inset
40111 </cell>
40112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40113 \begin_inset Text
40114
40115 \begin_layout Standard
40116
40117 \size footnotesize
40118 Subtraction
40119 \end_layout
40120
40121 \end_inset
40122 </cell>
40123 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40124 \begin_inset Text
40125
40126 \begin_layout Standard
40127
40128 \size footnotesize
40129 IC_RESULT = IC_LEFT - IC_RIGHT 
40130 \end_layout
40131
40132 \end_inset
40133 </cell>
40134 </row>
40135 <row topline="true">
40136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40137 \begin_inset Text
40138
40139 \begin_layout Standard
40140
40141 \size footnotesize
40142 '*'
40143 \end_layout
40144
40145 \end_inset
40146 </cell>
40147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40148 \begin_inset Text
40149
40150 \begin_layout Standard
40151
40152 \size footnotesize
40153 IC_LEFT() IC_RIGHT() IC_RESULT()
40154 \end_layout
40155
40156 \end_inset
40157 </cell>
40158 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40159 \begin_inset Text
40160
40161 \begin_layout Standard
40162
40163 \size footnotesize
40164 Multiplication 
40165 \end_layout
40166
40167 \end_inset
40168 </cell>
40169 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40170 \begin_inset Text
40171
40172 \begin_layout Standard
40173
40174 \size footnotesize
40175 IC_RESULT = IC_LEFT * IC_RIGHT;
40176 \end_layout
40177
40178 \end_inset
40179 </cell>
40180 </row>
40181 <row topline="true">
40182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40183 \begin_inset Text
40184
40185 \begin_layout Standard
40186
40187 \size footnotesize
40188 '/'
40189 \end_layout
40190
40191 \end_inset
40192 </cell>
40193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40194 \begin_inset Text
40195
40196 \begin_layout Standard
40197
40198 \size footnotesize
40199 IC_LEFT() IC_RIGHT() IC_RESULT()
40200 \end_layout
40201
40202 \end_inset
40203 </cell>
40204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40205 \begin_inset Text
40206
40207 \begin_layout Standard
40208
40209 \size footnotesize
40210 Division
40211 \end_layout
40212
40213 \end_inset
40214 </cell>
40215 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40216 \begin_inset Text
40217
40218 \begin_layout Standard
40219
40220 \size footnotesize
40221 IC_RESULT = IC_LEFT / IC_RIGHT;
40222 \end_layout
40223
40224 \end_inset
40225 </cell>
40226 </row>
40227 <row topline="true">
40228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40229 \begin_inset Text
40230
40231 \begin_layout Standard
40232
40233 \size footnotesize
40234 '%'
40235 \end_layout
40236
40237 \end_inset
40238 </cell>
40239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40240 \begin_inset Text
40241
40242 \begin_layout Standard
40243
40244 \size footnotesize
40245 IC_LEFT() IC_RIGHT() IC_RESULT()
40246 \end_layout
40247
40248 \end_inset
40249 </cell>
40250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40251 \begin_inset Text
40252
40253 \begin_layout Standard
40254
40255 \size footnotesize
40256 Modulus
40257 \end_layout
40258
40259 \end_inset
40260 </cell>
40261 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40262 \begin_inset Text
40263
40264 \begin_layout Standard
40265
40266 \size footnotesize
40267 IC_RESULT = IC_LEFT % IC_RIGHT;
40268 \end_layout
40269
40270 \end_inset
40271 </cell>
40272 </row>
40273 <row topline="true">
40274 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40275 \begin_inset Text
40276
40277 \begin_layout Standard
40278
40279 \size footnotesize
40280 '<'
40281 \end_layout
40282
40283 \end_inset
40284 </cell>
40285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40286 \begin_inset Text
40287
40288 \begin_layout Standard
40289
40290 \size footnotesize
40291 IC_LEFT() IC_RIGHT() IC_RESULT()
40292 \end_layout
40293
40294 \end_inset
40295 </cell>
40296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40297 \begin_inset Text
40298
40299 \begin_layout Standard
40300
40301 \size footnotesize
40302 Less than
40303 \end_layout
40304
40305 \end_inset
40306 </cell>
40307 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40308 \begin_inset Text
40309
40310 \begin_layout Standard
40311
40312 \size footnotesize
40313 IC_RESULT = IC_LEFT < IC_RIGHT;
40314 \end_layout
40315
40316 \end_inset
40317 </cell>
40318 </row>
40319 <row topline="true">
40320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40321 \begin_inset Text
40322
40323 \begin_layout Standard
40324
40325 \size footnotesize
40326 '>'
40327 \end_layout
40328
40329 \end_inset
40330 </cell>
40331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40332 \begin_inset Text
40333
40334 \begin_layout Standard
40335
40336 \size footnotesize
40337 IC_LEFT() IC_RIGHT() IC_RESULT()
40338 \end_layout
40339
40340 \end_inset
40341 </cell>
40342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40343 \begin_inset Text
40344
40345 \begin_layout Standard
40346
40347 \size footnotesize
40348 Greater than 
40349 \end_layout
40350
40351 \end_inset
40352 </cell>
40353 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40354 \begin_inset Text
40355
40356 \begin_layout Standard
40357
40358 \size footnotesize
40359 IC_RESULT = IC_LEFT > IC_RIGHT;
40360 \end_layout
40361
40362 \end_inset
40363 </cell>
40364 </row>
40365 <row topline="true">
40366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40367 \begin_inset Text
40368
40369 \begin_layout Standard
40370
40371 \size footnotesize
40372 EQ_OP
40373 \end_layout
40374
40375 \end_inset
40376 </cell>
40377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40378 \begin_inset Text
40379
40380 \begin_layout Standard
40381
40382 \size footnotesize
40383 IC_LEFT() IC_RIGHT() IC_RESULT()
40384 \end_layout
40385
40386 \end_inset
40387 </cell>
40388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40389 \begin_inset Text
40390
40391 \begin_layout Standard
40392
40393 \size footnotesize
40394 Equal to 
40395 \end_layout
40396
40397 \end_inset
40398 </cell>
40399 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40400 \begin_inset Text
40401
40402 \begin_layout Standard
40403
40404 \size footnotesize
40405 IC_RESULT = IC_LEFT == IC_RIGHT;
40406 \end_layout
40407
40408 \end_inset
40409 </cell>
40410 </row>
40411 <row topline="true">
40412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40413 \begin_inset Text
40414
40415 \begin_layout Standard
40416
40417 \size footnotesize
40418 AND_OP
40419 \end_layout
40420
40421 \end_inset
40422 </cell>
40423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40424 \begin_inset Text
40425
40426 \begin_layout Standard
40427
40428 \size footnotesize
40429 IC_LEFT() IC_RIGHT() IC_RESULT() 
40430 \end_layout
40431
40432 \end_inset
40433 </cell>
40434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40435 \begin_inset Text
40436
40437 \begin_layout Standard
40438
40439 \size footnotesize
40440 Logical and operation
40441 \end_layout
40442
40443 \end_inset
40444 </cell>
40445 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40446 \begin_inset Text
40447
40448 \begin_layout Standard
40449
40450 \size footnotesize
40451 IC_RESULT = IC_LEFT && IC_RIGHT; 
40452 \end_layout
40453
40454 \end_inset
40455 </cell>
40456 </row>
40457 <row topline="true">
40458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40459 \begin_inset Text
40460
40461 \begin_layout Standard
40462
40463 \size footnotesize
40464 OR_OP
40465 \end_layout
40466
40467 \end_inset
40468 </cell>
40469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40470 \begin_inset Text
40471
40472 \begin_layout Standard
40473
40474 \size footnotesize
40475 IC_LEFT() IC_RIGHT() IC_RESULT() 
40476 \end_layout
40477
40478 \end_inset
40479 </cell>
40480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40481 \begin_inset Text
40482
40483 \begin_layout Standard
40484
40485 \size footnotesize
40486 Logical or operation 
40487 \end_layout
40488
40489 \end_inset
40490 </cell>
40491 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40492 \begin_inset Text
40493
40494 \begin_layout Standard
40495
40496 \size footnotesize
40497 IC_RESULT = IC_LEFT || IC_RIGHT; 
40498 \end_layout
40499
40500 \end_inset
40501 </cell>
40502 </row>
40503 <row topline="true">
40504 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40505 \begin_inset Text
40506
40507 \begin_layout Standard
40508
40509 \size footnotesize
40510 '^'
40511 \end_layout
40512
40513 \end_inset
40514 </cell>
40515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40516 \begin_inset Text
40517
40518 \begin_layout Standard
40519
40520 \size footnotesize
40521 IC_LEFT() IC_RIGHT() IC_RESULT() 
40522 \end_layout
40523
40524 \end_inset
40525 </cell>
40526 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40527 \begin_inset Text
40528
40529 \begin_layout Standard
40530
40531 \size footnotesize
40532 Exclusive OR
40533 \end_layout
40534
40535 \end_inset
40536 </cell>
40537 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40538 \begin_inset Text
40539
40540 \begin_layout Standard
40541
40542 \size footnotesize
40543 IC_RESULT = IC_LEFT ^ IC_RIGHT;
40544 \end_layout
40545
40546 \end_inset
40547 </cell>
40548 </row>
40549 <row topline="true">
40550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40551 \begin_inset Text
40552
40553 \begin_layout Standard
40554
40555 \size footnotesize
40556 '|'
40557 \end_layout
40558
40559 \end_inset
40560 </cell>
40561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40562 \begin_inset Text
40563
40564 \begin_layout Standard
40565
40566 \size footnotesize
40567 IC_LEFT() IC_RIGHT() IC_RESULT() 
40568 \end_layout
40569
40570 \end_inset
40571 </cell>
40572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40573 \begin_inset Text
40574
40575 \begin_layout Standard
40576
40577 \size footnotesize
40578 Bitwise OR 
40579 \end_layout
40580
40581 \end_inset
40582 </cell>
40583 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40584 \begin_inset Text
40585
40586 \begin_layout Standard
40587
40588 \size footnotesize
40589 IC_RESULT = IC_LEFT | IC_RIGHT;
40590 \end_layout
40591
40592 \end_inset
40593 </cell>
40594 </row>
40595 <row topline="true">
40596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40597 \begin_inset Text
40598
40599 \begin_layout Standard
40600
40601 \size footnotesize
40602 BITWISEAND
40603 \end_layout
40604
40605 \end_inset
40606 </cell>
40607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40608 \begin_inset Text
40609
40610 \begin_layout Standard
40611
40612 \size footnotesize
40613 IC_LEFT() IC_RIGHT() IC_RESULT()
40614 \end_layout
40615
40616 \end_inset
40617 </cell>
40618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40619 \begin_inset Text
40620
40621 \begin_layout Standard
40622
40623 \size footnotesize
40624 Bitwise AND 
40625 \end_layout
40626
40627 \end_inset
40628 </cell>
40629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40630 \begin_inset Text
40631
40632 \begin_layout Standard
40633
40634 \size footnotesize
40635 IC_RESULT = IC_LEFT & IC_RIGHT;
40636 \end_layout
40637
40638 \end_inset
40639 </cell>
40640 </row>
40641 <row topline="true">
40642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40643 \begin_inset Text
40644
40645 \begin_layout Standard
40646
40647 \size footnotesize
40648 LEFT_OP
40649 \end_layout
40650
40651 \end_inset
40652 </cell>
40653 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40654 \begin_inset Text
40655
40656 \begin_layout Standard
40657
40658 \size footnotesize
40659 IC_LEFT() IC_RIGHT() IC_RESULT()
40660 \end_layout
40661
40662 \end_inset
40663 </cell>
40664 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40665 \begin_inset Text
40666
40667 \begin_layout Standard
40668
40669 \size footnotesize
40670 Left shift 
40671 \end_layout
40672
40673 \end_inset
40674 </cell>
40675 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40676 \begin_inset Text
40677
40678 \begin_layout Standard
40679
40680 \size footnotesize
40681 IC_RESULT = IC_LEFT << IC_RIGHT 
40682 \end_layout
40683
40684 \end_inset
40685 </cell>
40686 </row>
40687 <row topline="true">
40688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40689 \begin_inset Text
40690
40691 \begin_layout Standard
40692
40693 \size footnotesize
40694 RIGHT_OP
40695 \end_layout
40696
40697 \end_inset
40698 </cell>
40699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40700 \begin_inset Text
40701
40702 \begin_layout Standard
40703
40704 \size footnotesize
40705 IC_LEFT() IC_RIGHT() IC_RESULT()
40706 \end_layout
40707
40708 \end_inset
40709 </cell>
40710 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40711 \begin_inset Text
40712
40713 \begin_layout Standard
40714
40715 \size footnotesize
40716 Right shift
40717 \end_layout
40718
40719 \end_inset
40720 </cell>
40721 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40722 \begin_inset Text
40723
40724 \begin_layout Standard
40725
40726 \size footnotesize
40727 IC_RESULT = IC_LEFT >> IC_RIGHT 
40728 \end_layout
40729
40730 \end_inset
40731 </cell>
40732 </row>
40733 <row topline="true">
40734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40735 \begin_inset Text
40736
40737 \begin_layout Standard
40738
40739 \size footnotesize
40740 GET_VALUE_
40741 \newline
40742 AT_ ADDRESS
40743 \end_layout
40744
40745 \end_inset
40746 </cell>
40747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40748 \begin_inset Text
40749
40750 \begin_layout Standard
40751
40752 \size footnotesize
40753 IC_LEFT() IC_RESULT()
40754 \end_layout
40755
40756 \end_inset
40757 </cell>
40758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40759 \begin_inset Text
40760
40761 \begin_layout Standard
40762
40763 \size footnotesize
40764 Indirect fetch 
40765 \end_layout
40766
40767 \end_inset
40768 </cell>
40769 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40770 \begin_inset Text
40771
40772 \begin_layout Standard
40773
40774 \size footnotesize
40775 IC_RESULT = (*IC_LEFT);
40776 \end_layout
40777
40778 \end_inset
40779 </cell>
40780 </row>
40781 <row topline="true">
40782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40783 \begin_inset Text
40784
40785 \begin_layout Standard
40786
40787 \size footnotesize
40788 POINTER_SET
40789 \end_layout
40790
40791 \end_inset
40792 </cell>
40793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40794 \begin_inset Text
40795
40796 \begin_layout Standard
40797
40798 \size footnotesize
40799 IC_RIGHT() IC_RESULT() 
40800 \end_layout
40801
40802 \end_inset
40803 </cell>
40804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40805 \begin_inset Text
40806
40807 \begin_layout Standard
40808
40809 \size footnotesize
40810 Indirect set
40811 \end_layout
40812
40813 \end_inset
40814 </cell>
40815 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40816 \begin_inset Text
40817
40818 \begin_layout Standard
40819
40820 \size footnotesize
40821 (*IC_RESULT) = IC_RIGHT;
40822 \end_layout
40823
40824 \end_inset
40825 </cell>
40826 </row>
40827 <row topline="true">
40828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40829 \begin_inset Text
40830
40831 \begin_layout Standard
40832
40833 \size footnotesize
40834 '='
40835 \end_layout
40836
40837 \end_inset
40838 </cell>
40839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40840 \begin_inset Text
40841
40842 \begin_layout Standard
40843
40844 \size footnotesize
40845 IC_RIGHT() IC_RESULT()
40846 \end_layout
40847
40848 \end_inset
40849 </cell>
40850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40851 \begin_inset Text
40852
40853 \begin_layout Standard
40854
40855 \size footnotesize
40856 Assignment
40857 \end_layout
40858
40859 \end_inset
40860 </cell>
40861 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40862 \begin_inset Text
40863
40864 \begin_layout Standard
40865
40866 \size footnotesize
40867 IC_RESULT = IC_RIGHT;
40868 \end_layout
40869
40870 \end_inset
40871 </cell>
40872 </row>
40873 <row topline="true">
40874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40875 \begin_inset Text
40876
40877 \begin_layout Standard
40878
40879 \size footnotesize
40880 IFX
40881 \end_layout
40882
40883 \end_inset
40884 </cell>
40885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40886 \begin_inset Text
40887
40888 \begin_layout Standard
40889
40890 \size footnotesize
40891 IC_COND IC_TRUE IC_LABEL
40892 \end_layout
40893
40894 \end_inset
40895 </cell>
40896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40897 \begin_inset Text
40898
40899 \begin_layout Standard
40900
40901 \size footnotesize
40902 Conditional jump.
40903  If true label is present then jump to true label if condition is true else
40904  jump to false label if condition is false 
40905 \end_layout
40906
40907 \end_inset
40908 </cell>
40909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40910 \begin_inset Text
40911
40912 \begin_layout Standard
40913
40914 \size footnotesize
40915 if (IC_COND) goto IC_TRUE; 
40916 \newline
40917 \InsetSpace ~
40918 \InsetSpace ~
40919 Or 
40920 \newline
40921 If (!IC_COND) goto IC_FALSE;
40922 \end_layout
40923
40924 \end_inset
40925 </cell>
40926 </row>
40927 <row topline="true">
40928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40929 \begin_inset Text
40930
40931 \begin_layout Standard
40932
40933 \size footnotesize
40934 ADDRESS_OF
40935 \end_layout
40936
40937 \end_inset
40938 </cell>
40939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40940 \begin_inset Text
40941
40942 \begin_layout Standard
40943
40944 \size footnotesize
40945 IC_LEFT() IC_RESULT()
40946 \end_layout
40947
40948 \end_inset
40949 </cell>
40950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40951 \begin_inset Text
40952
40953 \begin_layout Standard
40954
40955 \size footnotesize
40956 Address of 
40957 \end_layout
40958
40959 \end_inset
40960 </cell>
40961 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40962 \begin_inset Text
40963
40964 \begin_layout Standard
40965
40966 \size footnotesize
40967 IC_RESULT = &IC_LEFT();
40968 \end_layout
40969
40970 \end_inset
40971 </cell>
40972 </row>
40973 <row topline="true">
40974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40975 \begin_inset Text
40976
40977 \begin_layout Standard
40978
40979 \size footnotesize
40980 JUMPTABLE
40981 \end_layout
40982
40983 \end_inset
40984 </cell>
40985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40986 \begin_inset Text
40987
40988 \begin_layout Standard
40989
40990 \size footnotesize
40991 IC_JTCOND IC_JTLABELS
40992 \end_layout
40993
40994 \end_inset
40995 </cell>
40996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40997 \begin_inset Text
40998
40999 \begin_layout Standard
41000
41001 \size footnotesize
41002 Jump to list of labels depending on the value of JTCOND
41003 \end_layout
41004
41005 \end_inset
41006 </cell>
41007 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41008 \begin_inset Text
41009
41010 \begin_layout Standard
41011
41012 \size footnotesize
41013 Switch statement
41014 \end_layout
41015
41016 \end_inset
41017 </cell>
41018 </row>
41019 <row topline="true">
41020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41021 \begin_inset Text
41022
41023 \begin_layout Standard
41024
41025 \size footnotesize
41026 CAST
41027 \end_layout
41028
41029 \end_inset
41030 </cell>
41031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41032 \begin_inset Text
41033
41034 \begin_layout Standard
41035
41036 \size footnotesize
41037 IC_RIGHT() IC_LEFT() IC_RESULT()
41038 \end_layout
41039
41040 \end_inset
41041 </cell>
41042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41043 \begin_inset Text
41044
41045 \begin_layout Standard
41046
41047 \size footnotesize
41048 Cast types 
41049 \end_layout
41050
41051 \end_inset
41052 </cell>
41053 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41054 \begin_inset Text
41055
41056 \begin_layout Standard
41057
41058 \size footnotesize
41059 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
41060 \end_layout
41061
41062 \end_inset
41063 </cell>
41064 </row>
41065 <row topline="true">
41066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41067 \begin_inset Text
41068
41069 \begin_layout Standard
41070
41071 \size footnotesize
41072 SEND
41073 \end_layout
41074
41075 \end_inset
41076 </cell>
41077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41078 \begin_inset Text
41079
41080 \begin_layout Standard
41081
41082 \size footnotesize
41083 IC_LEFT()
41084 \end_layout
41085
41086 \end_inset
41087 </cell>
41088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41089 \begin_inset Text
41090
41091 \begin_layout Standard
41092
41093 \size footnotesize
41094 This is used for passing parameters in registers; 
41095 \newline
41096 move IC_LEFT to the next
41097  available parameter register.
41098 \end_layout
41099
41100 \end_inset
41101 </cell>
41102 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41103 \begin_inset Text
41104
41105 \begin_layout Standard
41106
41107 \size footnotesize
41108 None
41109 \end_layout
41110
41111 \end_inset
41112 </cell>
41113 </row>
41114 <row topline="true">
41115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41116 \begin_inset Text
41117
41118 \begin_layout Standard
41119
41120 \size footnotesize
41121 RECV
41122 \end_layout
41123
41124 \end_inset
41125 </cell>
41126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41127 \begin_inset Text
41128
41129 \begin_layout Standard
41130
41131 \size footnotesize
41132 IC_RESULT()
41133 \end_layout
41134
41135 \end_inset
41136 </cell>
41137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41138 \begin_inset Text
41139
41140 \begin_layout Standard
41141
41142 \size footnotesize
41143 This is used for receiving parameters passed in registers;
41144 \newline
41145 Move the values
41146  in the next parameter register to IC_RESULT 
41147 \end_layout
41148
41149 \end_inset
41150 </cell>
41151 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41152 \begin_inset Text
41153
41154 \begin_layout Standard
41155
41156 \size footnotesize
41157 None
41158 \end_layout
41159
41160 \end_inset
41161 </cell>
41162 </row>
41163 <row topline="true" bottomline="true">
41164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41165 \begin_inset Text
41166
41167 \begin_layout Standard
41168
41169 \shape slanted
41170 \size footnotesize
41171 (some more have been added)
41172 \end_layout
41173
41174 \end_inset
41175 </cell>
41176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41177 \begin_inset Text
41178
41179 \begin_layout Standard
41180
41181 \end_layout
41182
41183 \end_inset
41184 </cell>
41185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41186 \begin_inset Text
41187
41188 \begin_layout Standard
41189
41190 \end_layout
41191
41192 \end_inset
41193 </cell>
41194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41195 \begin_inset Text
41196
41197 \begin_layout Standard
41198
41199 \shape slanted
41200 \size footnotesize
41201 see f.e.
41202
41203 \shape default
41204  
41205 \family typewriter
41206 \shape slanted
41207 gen51Code()
41208 \family default
41209 \shape default
41210  
41211 \shape slanted
41212 in
41213 \shape default
41214  
41215 \family typewriter
41216 \shape slanted
41217 src/mcs51/gen.c
41218 \end_layout
41219
41220 \end_inset
41221 </cell>
41222 </row>
41223 </lyxtabular>
41224
41225 \end_inset
41226
41227
41228 \end_layout
41229
41230 \begin_layout Standard
41231 \begin_inset Note Note
41232 status collapsed
41233
41234 \begin_layout Standard
41235 In the original article Figure II was announced to be downloadable on 
41236 \shape italic
41237 Circuit Cellar
41238 \shape default
41239 's web site.
41240  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
41241 \end_layout
41242
41243 \end_inset
41244
41245
41246 \end_layout
41247
41248 \begin_layout Paragraph*
41249 ICode Example
41250 \begin_inset LatexCommand index
41251 name "iCode"
41252
41253 \end_inset
41254
41255
41256 \end_layout
41257
41258 \begin_layout Standard
41259 This section shows some details of iCode.
41260  The example C code does not do anything useful; it is used as an example
41261  to illustrate the intermediate code generated by the compiler.
41262 \end_layout
41263
41264 \begin_layout Verse
41265
41266 \family typewriter
41267 1.\InsetSpace ~
41268 xdata int * p;
41269 \newline
41270 2.\InsetSpace ~
41271 int gint;
41272 \newline
41273 3.\InsetSpace ~
41274 /* This function does nothing useful.
41275  It is used
41276 \newline
41277 4.\InsetSpace ~
41278 \InsetSpace ~
41279 \InsetSpace ~
41280 \InsetSpace ~
41281 for the purpose of explaining iCode */
41282 \newline
41283 5.\InsetSpace ~
41284 short function (data
41285  int *x)
41286 \newline
41287 6.\InsetSpace ~
41288 {
41289 \newline
41290 7.\InsetSpace ~
41291 \InsetSpace ~
41292 \InsetSpace ~
41293 short i=10; \InsetSpace ~
41294 \InsetSpace ~
41295 /* dead initialization eliminated */
41296 \newline
41297 8.\InsetSpace ~
41298 \InsetSpace ~
41299 \InsetSpace ~
41300 short sum=10;
41301  /* dead initialization eliminated */
41302 \newline
41303 9.\InsetSpace ~
41304 \InsetSpace ~
41305 \InsetSpace ~
41306 short mul;
41307 \newline
41308 10.\InsetSpace ~
41309 \InsetSpace ~
41310 int j ;
41311 \newline
41312 11.\InsetSpace ~
41313 \InsetSpace ~
41314 while (*x) *x++
41315  = *p++; 
41316 \newline
41317 12.\InsetSpace ~
41318 \InsetSpace ~
41319 \InsetSpace ~
41320 \InsetSpace ~
41321 sum = 0 ; 
41322 \newline
41323 13.\InsetSpace ~
41324 \InsetSpace ~
41325 mul = 0;
41326 \newline
41327 14.\InsetSpace ~
41328 \InsetSpace ~
41329 /* compiler detects i,j to be induction
41330  variables */
41331 \newline
41332 15.\InsetSpace ~
41333 \InsetSpace ~
41334 for (i = 0, j = 10 ; i < 10 ; i++, j
41335 \family default
41336 -
41337 \begin_inset ERT
41338 status collapsed
41339
41340 \begin_layout Standard
41341
41342
41343 \backslash
41344 /
41345 \end_layout
41346
41347 \end_inset
41348
41349 -
41350 \family typewriter
41351 ) {
41352 \newline
41353 16.\InsetSpace ~
41354 \InsetSpace ~
41355 \InsetSpace ~
41356 \InsetSpace ~
41357 sum += i;
41358 \newline
41359 17.\InsetSpace ~
41360 \InsetSpace ~
41361 \InsetSpace ~
41362 \InsetSpace ~
41363 mul += i * 3; \InsetSpace ~
41364 \InsetSpace ~
41365 /* this multiplication remains */
41366 \newline
41367 18.\InsetSpace ~
41368 \InsetSpace ~
41369 \InsetSpace ~
41370 \InsetSpace ~
41371 gint +=
41372  j * 3;\InsetSpace ~
41373 \InsetSpace ~
41374 /* this multiplication changed to addition */
41375 \newline
41376 19.\InsetSpace ~
41377 \InsetSpace ~
41378 }
41379 \newline
41380 20.\InsetSpace ~
41381 \InsetSpace ~
41382 return sum+mul;
41383 \newline
41384 21.\InsetSpace ~
41385 }
41386 \end_layout
41387
41388 \begin_layout Standard
41389 In addition to the operands each iCode contains information about the filename
41390  and line it corresponds to in the source file.
41391  The first field in the listing should be interpreted as follows:
41392 \newline
41393
41394 \shape italic
41395 \size footnotesize
41396 Filename(linenumber: iCode Execution sequence number : ICode hash table
41397  key : loop depth of the iCode).
41398 \shape default
41399 \size default
41400
41401 \newline
41402 Then follows the human readable form of the ICode operation.
41403  Each operand of this triplet form can be of three basic types a) compiler
41404  generated temporary b) user defined variable c) a constant value.
41405  Note that local variables and parameters are replaced by compiler generated
41406  temporaries.
41407  Live ranges
41408 \begin_inset LatexCommand index
41409 name "Live range analysis"
41410
41411 \end_inset
41412
41413  are computed only for temporaries (i.e.
41414  live ranges are not computed for global variables).
41415  Registers
41416 \begin_inset LatexCommand index
41417 name "Register allocation"
41418
41419 \end_inset
41420
41421  are allocated for temporaries only.
41422  Operands are formatted in the following manner:
41423 \newline
41424
41425 \shape italic
41426 \size footnotesize
41427 Operand Name [lr live-from : live-to ] { type information } [ registers
41428  allocated ].
41429 \shape default
41430 \size default
41431
41432 \newline
41433 As mentioned earlier the live ranges are computed in terms of the execution
41434  sequence number of the iCodes, for example 
41435 \newline
41436 the iTemp0 is live from (i.e.
41437  first defined in iCode with execution sequence number 3, and is last used
41438  in the iCode with sequence number 5).
41439  For induction variables such as iTemp21 the live range computation extends
41440  the lifetime from the start to the end of the loop.
41441 \newline
41442 The register allocator
41443  used the live range information to allocate registers, the same registers
41444  may be used for different temporaries if their live ranges do not overlap,
41445  for example r0 is allocated to both iTemp6 and to iTemp17 since their live
41446  ranges do not overlap.
41447  In addition the allocator also takes into consideration the type and usage
41448  of a temporary, for example itemp6 is a pointer to near space and is used
41449  as to fetch data from (i.e.
41450  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
41451  Some short lived temporaries are allocated to special registers which have
41452  meaning to the code generator e.g.
41453  iTemp13 is allocated to a pseudo register CC which tells the back end that
41454  the temporary is used only for a conditional jump the code generation makes
41455  use of this information to optimize a compare and jump ICode.
41456 \newline
41457 There are several
41458  loop optimizations
41459 \begin_inset LatexCommand index
41460 name "Loop optimization"
41461
41462 \end_inset
41463
41464  performed by the compiler.
41465  It can detect induction variables iTemp21(i) and iTemp23(j).
41466  Also note the compiler does selective strength reduction
41467 \begin_inset LatexCommand index
41468 name "Strength reduction"
41469
41470 \end_inset
41471
41472 , i.e.
41473  the multiplication of an induction variable in line 18 (gint = j * 3) is
41474  changed to addition, a new temporary iTemp17 is allocated and assigned
41475  a initial value, a constant 3 is then added for each iteration of the loop.
41476  The compiler does not change the multiplication
41477 \begin_inset LatexCommand index
41478 name "Multiplication"
41479
41480 \end_inset
41481
41482  in line 17 however since the processor does support an 8 * 8 bit multiplication.
41483 \newline
41484
41485 Note the dead code elimination
41486 \begin_inset LatexCommand index
41487 name "Dead-code elimination"
41488
41489 \end_inset
41490
41491  optimization eliminated the dead assignments in line 7 & 8 to I and sum
41492  respectively.
41493 \newline
41494
41495 \end_layout
41496
41497 \begin_layout Standard
41498
41499 \size footnotesize
41500 Sample.c (5:1:0:0) _entry($9) :
41501 \end_layout
41502
41503 \begin_layout Standard
41504
41505 \size footnotesize
41506 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
41507 \end_layout
41508
41509 \begin_layout Standard
41510
41511 \size footnotesize
41512 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
41513 \end_layout
41514
41515 \begin_layout Standard
41516
41517 \size footnotesize
41518 Sample.c(11:4:53:0) preHeaderLbl0($11) :
41519 \end_layout
41520
41521 \begin_layout Standard
41522
41523 \size footnotesize
41524 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
41525  * int}[r2]
41526 \end_layout
41527
41528 \begin_layout Standard
41529
41530 \size footnotesize
41531 Sample.c(11:6:5:1) _whilecontinue_0($1) :
41532 \end_layout
41533
41534 \begin_layout Standard
41535
41536 \size footnotesize
41537 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
41538  int}[r0]]
41539 \end_layout
41540
41541 \begin_layout Standard
41542
41543 \size footnotesize
41544 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
41545 \end_layout
41546
41547 \begin_layout Standard
41548
41549 \size footnotesize
41550 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
41551  * int}
41552 \end_layout
41553
41554 \begin_layout Standard
41555
41556 \size footnotesize
41557 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
41558  {short}
41559 \end_layout
41560
41561 \begin_layout Standard
41562
41563 \size footnotesize
41564 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
41565  * int}[DPTR]]
41566 \end_layout
41567
41568 \begin_layout Standard
41569
41570 \size footnotesize
41571 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
41572 }[r2 r3]
41573 \end_layout
41574
41575 \begin_layout Standard
41576
41577 \size footnotesize
41578 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
41579  * int}[r0] + 0x2 {short}
41580 \end_layout
41581
41582 \begin_layout Standard
41583
41584 \size footnotesize
41585 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
41586 \end_layout
41587
41588 \begin_layout Standard
41589
41590 \size footnotesize
41591 Sample.c(11:17:21:0)_whilebreak_0($3) :
41592 \end_layout
41593
41594 \begin_layout Standard
41595
41596 \size footnotesize
41597 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
41598 \end_layout
41599
41600 \begin_layout Standard
41601
41602 \size footnotesize
41603 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
41604 \end_layout
41605
41606 \begin_layout Standard
41607
41608 \size footnotesize
41609 Sample.c(15:20:54:0)preHeaderLbl1($13) :
41610 \end_layout
41611
41612 \begin_layout Standard
41613
41614 \size footnotesize
41615 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
41616 \end_layout
41617
41618 \begin_layout Standard
41619
41620 \size footnotesize
41621 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
41622 \end_layout
41623
41624 \begin_layout Standard
41625
41626 \size footnotesize
41627 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
41628 \end_layout
41629
41630 \begin_layout Standard
41631
41632 \size footnotesize
41633 Sample.c(15:24:26:1)_forcond_0($4) :
41634 \end_layout
41635
41636 \begin_layout Standard
41637
41638 \size footnotesize
41639 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
41640  < 0xa {short}
41641 \end_layout
41642
41643 \begin_layout Standard
41644
41645 \size footnotesize
41646 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
41647 \end_layout
41648
41649 \begin_layout Standard
41650
41651 \size footnotesize
41652 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
41653  + ITemp21 [lr21:38]{short}[r4]
41654 \end_layout
41655
41656 \begin_layout Standard
41657
41658 \size footnotesize
41659 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
41660  * 0x3 {short}
41661 \end_layout
41662
41663 \begin_layout Standard
41664
41665 \size footnotesize
41666 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
41667  + iTemp15 [lr29:30]{short}[r1]
41668 \end_layout
41669
41670 \begin_layout Standard
41671
41672 \size footnotesize
41673 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
41674  r0]- 0x3 {short}
41675 \end_layout
41676
41677 \begin_layout Standard
41678
41679 \size footnotesize
41680 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
41681 int}[r7 r0]
41682 \end_layout
41683
41684 \begin_layout Standard
41685
41686 \size footnotesize
41687 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
41688  + 0x1 {short}
41689 \end_layout
41690
41691 \begin_layout Standard
41692
41693 \size footnotesize
41694 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
41695  r6]- 0x1 {short}
41696 \end_layout
41697
41698 \begin_layout Standard
41699
41700 \size footnotesize
41701 Sample.c(19:38:47:1) goto _forcond_0($4)
41702 \end_layout
41703
41704 \begin_layout Standard
41705
41706 \size footnotesize
41707 Sample.c(19:39:48:0)_forbreak_0($7) :
41708 \end_layout
41709
41710 \begin_layout Standard
41711
41712 \size footnotesize
41713 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
41714  + ITemp11 [lr19:40]{short}[r3]
41715 \end_layout
41716
41717 \begin_layout Standard
41718
41719 \size footnotesize
41720 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
41721 \end_layout
41722
41723 \begin_layout Standard
41724
41725 \size footnotesize
41726 Sample.c(20:42:51:0)_return($8) :
41727 \end_layout
41728
41729 \begin_layout Standard
41730
41731 \size footnotesize
41732 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
41733 \size default
41734
41735 \newline
41736
41737 \newline
41738 Finally the code generated for this function:
41739 \newline
41740
41741 \end_layout
41742
41743 \begin_layout Standard
41744
41745 \size footnotesize
41746 .area DSEG (DATA)
41747 \end_layout
41748
41749 \begin_layout Standard
41750
41751 \size footnotesize
41752 _p::
41753 \end_layout
41754
41755 \begin_layout Standard
41756
41757 \size footnotesize
41758 \InsetSpace ~
41759 \InsetSpace ~
41760 .ds 2
41761 \end_layout
41762
41763 \begin_layout Standard
41764
41765 \size footnotesize
41766 _gint::
41767 \end_layout
41768
41769 \begin_layout Standard
41770
41771 \size footnotesize
41772 \InsetSpace ~
41773 \InsetSpace ~
41774 .ds 2
41775 \end_layout
41776
41777 \begin_layout Standard
41778
41779 \size footnotesize
41780 ; sample.c 5
41781 \end_layout
41782
41783 \begin_layout Standard
41784
41785 \size footnotesize
41786 ; ----------------------------------------------
41787 \end_layout
41788
41789 \begin_layout Standard
41790
41791 \size footnotesize
41792 ; function function
41793 \end_layout
41794
41795 \begin_layout Standard
41796
41797 \size footnotesize
41798 ; ----------------------------------------------
41799 \end_layout
41800
41801 \begin_layout Standard
41802
41803 \size footnotesize
41804 _function:
41805 \end_layout
41806
41807 \begin_layout Standard
41808
41809 \size footnotesize
41810 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
41811 \end_layout
41812
41813 \begin_layout Standard
41814
41815 \size footnotesize
41816 \InsetSpace ~
41817 \InsetSpace ~
41818 mov r2,dpl
41819 \end_layout
41820
41821 \begin_layout Standard
41822
41823 \size footnotesize
41824 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
41825 \end_layout
41826
41827 \begin_layout Standard
41828
41829 \size footnotesize
41830 \InsetSpace ~
41831 \InsetSpace ~
41832 mov ar0,r2
41833 \end_layout
41834
41835 \begin_layout Standard
41836
41837 \size footnotesize
41838 ;_whilecontinue_0($1) :
41839 \end_layout
41840
41841 \begin_layout Standard
41842
41843 \size footnotesize
41844 00101$:
41845 \end_layout
41846
41847 \begin_layout Standard
41848
41849 \size footnotesize
41850 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
41851 \end_layout
41852
41853 \begin_layout Standard
41854
41855 \size footnotesize
41856 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
41857 \end_layout
41858
41859 \begin_layout Standard
41860
41861 \size footnotesize
41862 \InsetSpace ~
41863 \InsetSpace ~
41864 mov ar2,@r0
41865 \end_layout
41866
41867 \begin_layout Standard
41868
41869 \size footnotesize
41870 \InsetSpace ~
41871 \InsetSpace ~
41872 inc r0
41873 \end_layout
41874
41875 \begin_layout Standard
41876
41877 \size footnotesize
41878 \InsetSpace ~
41879 \InsetSpace ~
41880 mov ar3,@r0
41881 \end_layout
41882
41883 \begin_layout Standard
41884
41885 \size footnotesize
41886 \InsetSpace ~
41887 \InsetSpace ~
41888 dec r0
41889 \end_layout
41890
41891 \begin_layout Standard
41892
41893 \size footnotesize
41894 \InsetSpace ~
41895 \InsetSpace ~
41896 mov a,r2
41897 \end_layout
41898
41899 \begin_layout Standard
41900
41901 \size footnotesize
41902 \InsetSpace ~
41903 \InsetSpace ~
41904 orl a,r3
41905 \end_layout
41906
41907 \begin_layout Standard
41908
41909 \size footnotesize
41910 \InsetSpace ~
41911 \InsetSpace ~
41912 jz 00103$
41913 \end_layout
41914
41915 \begin_layout Standard
41916
41917 \size footnotesize
41918 00114$:
41919 \end_layout
41920
41921 \begin_layout Standard
41922
41923 \size footnotesize
41924 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
41925 \end_layout
41926
41927 \begin_layout Standard
41928
41929 \size footnotesize
41930 \InsetSpace ~
41931 \InsetSpace ~
41932 mov dpl,_p
41933 \end_layout
41934
41935 \begin_layout Standard
41936
41937 \size footnotesize
41938 \InsetSpace ~
41939 \InsetSpace ~
41940 mov dph,(_p + 1)
41941 \end_layout
41942
41943 \begin_layout Standard
41944
41945 \size footnotesize
41946 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
41947 \end_layout
41948
41949 \begin_layout Standard
41950
41951 \size footnotesize
41952 \InsetSpace ~
41953 \InsetSpace ~
41954 mov a,#0x02
41955 \end_layout
41956
41957 \begin_layout Standard
41958
41959 \size footnotesize
41960 \InsetSpace ~
41961 \InsetSpace ~
41962 add a,_p
41963 \end_layout
41964
41965 \begin_layout Standard
41966
41967 \size footnotesize
41968 \InsetSpace ~
41969 \InsetSpace ~
41970 mov _p,a
41971 \end_layout
41972
41973 \begin_layout Standard
41974
41975 \size footnotesize
41976 \InsetSpace ~
41977 \InsetSpace ~
41978 clr a
41979 \end_layout
41980
41981 \begin_layout Standard
41982
41983 \size footnotesize
41984 \InsetSpace ~
41985 \InsetSpace ~
41986 addc a,(_p + 1)
41987 \end_layout
41988
41989 \begin_layout Standard
41990
41991 \size footnotesize
41992 \InsetSpace ~
41993 \InsetSpace ~
41994 mov (_p + 1),a
41995 \end_layout
41996
41997 \begin_layout Standard
41998
41999 \size footnotesize
42000 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
42001 \end_layout
42002
42003 \begin_layout Standard
42004
42005 \size footnotesize
42006 \InsetSpace ~
42007 \InsetSpace ~
42008 movx a,@dptr
42009 \end_layout
42010
42011 \begin_layout Standard
42012
42013 \size footnotesize
42014 \InsetSpace ~
42015 \InsetSpace ~
42016 mov r2,a
42017 \end_layout
42018
42019 \begin_layout Standard
42020
42021 \size footnotesize
42022 \InsetSpace ~
42023 \InsetSpace ~
42024 inc dptr
42025 \end_layout
42026
42027 \begin_layout Standard
42028
42029 \size footnotesize
42030 \InsetSpace ~
42031 \InsetSpace ~
42032 movx a,@dptr
42033 \end_layout
42034
42035 \begin_layout Standard
42036
42037 \size footnotesize
42038 \InsetSpace ~
42039 \InsetSpace ~
42040 mov r3,a
42041 \end_layout
42042
42043 \begin_layout Standard
42044
42045 \size footnotesize
42046 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
42047 \end_layout
42048
42049 \begin_layout Standard
42050
42051 \size footnotesize
42052 \InsetSpace ~
42053 \InsetSpace ~
42054 mov @r0,ar2
42055 \end_layout
42056
42057 \begin_layout Standard
42058
42059 \size footnotesize
42060 \InsetSpace ~
42061 \InsetSpace ~
42062 inc r0
42063 \end_layout
42064
42065 \begin_layout Standard
42066
42067 \size footnotesize
42068 \InsetSpace ~
42069 \InsetSpace ~
42070 mov @r0,ar3
42071 \end_layout
42072
42073 \begin_layout Standard
42074
42075 \size footnotesize
42076 ; iTemp6 [lr5:16]{_near * int}[r0] = 
42077 \end_layout
42078
42079 \begin_layout Standard
42080
42081 \size footnotesize
42082 ; iTemp6 [lr5:16]{_near * int}[r0] + 
42083 \end_layout
42084
42085 \begin_layout Standard
42086
42087 \size footnotesize
42088 ; 0x2 {short}
42089 \end_layout
42090
42091 \begin_layout Standard
42092
42093 \size footnotesize
42094 \InsetSpace ~
42095 \InsetSpace ~
42096 inc r0
42097 \end_layout
42098
42099 \begin_layout Standard
42100
42101 \size footnotesize
42102 ; goto _whilecontinue_0($1)
42103 \end_layout
42104
42105 \begin_layout Standard
42106
42107 \size footnotesize
42108 \InsetSpace ~
42109 \InsetSpace ~
42110 sjmp 00101$
42111 \end_layout
42112
42113 \begin_layout Standard
42114
42115 \size footnotesize
42116 ; _whilebreak_0($3) :
42117 \end_layout
42118
42119 \begin_layout Standard
42120
42121 \size footnotesize
42122 00103$:
42123 \end_layout
42124
42125 \begin_layout Standard
42126
42127 \size footnotesize
42128 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
42129 \end_layout
42130
42131 \begin_layout Standard
42132
42133 \size footnotesize
42134 \InsetSpace ~
42135 \InsetSpace ~
42136 mov r2,#0x00
42137 \end_layout
42138
42139 \begin_layout Standard
42140
42141 \size footnotesize
42142 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
42143 \end_layout
42144
42145 \begin_layout Standard
42146
42147 \size footnotesize
42148 \InsetSpace ~
42149 \InsetSpace ~
42150 mov r3,#0x00
42151 \end_layout
42152
42153 \begin_layout Standard
42154
42155 \size footnotesize
42156 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
42157 \end_layout
42158
42159 \begin_layout Standard
42160
42161 \size footnotesize
42162 \InsetSpace ~
42163 \InsetSpace ~
42164 mov r4,#0x00
42165 \end_layout
42166
42167 \begin_layout Standard
42168
42169 \size footnotesize
42170 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
42171 \end_layout
42172
42173 \begin_layout Standard
42174
42175 \size footnotesize
42176 \InsetSpace ~
42177 \InsetSpace ~
42178 mov r5,#0x0A
42179 \end_layout
42180
42181 \begin_layout Standard
42182
42183 \size footnotesize
42184 \InsetSpace ~
42185 \InsetSpace ~
42186 mov r6,#0x00
42187 \end_layout
42188
42189 \begin_layout Standard
42190
42191 \size footnotesize
42192 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
42193 \end_layout
42194
42195 \begin_layout Standard
42196
42197 \size footnotesize
42198 \InsetSpace ~
42199 \InsetSpace ~
42200 mov r7,#0x1E
42201 \end_layout
42202
42203 \begin_layout Standard
42204
42205 \size footnotesize
42206 \InsetSpace ~
42207 \InsetSpace ~
42208 mov r0,#0x00
42209 \end_layout
42210
42211 \begin_layout Standard
42212
42213 \size footnotesize
42214 ; _forcond_0($4) :
42215 \end_layout
42216
42217 \begin_layout Standard
42218
42219 \size footnotesize
42220 00104$:
42221 \end_layout
42222
42223 \begin_layout Standard
42224
42225 \size footnotesize
42226 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
42227 \end_layout
42228
42229 \begin_layout Standard
42230
42231 \size footnotesize
42232 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
42233 \end_layout
42234
42235 \begin_layout Standard
42236
42237 \size footnotesize
42238 \InsetSpace ~
42239 \InsetSpace ~
42240 clr c
42241 \end_layout
42242
42243 \begin_layout Standard
42244
42245 \size footnotesize
42246 \InsetSpace ~
42247 \InsetSpace ~
42248 mov a,r4
42249 \end_layout
42250
42251 \begin_layout Standard
42252
42253 \size footnotesize
42254 \InsetSpace ~
42255 \InsetSpace ~
42256 xrl a,#0x80
42257 \end_layout
42258
42259 \begin_layout Standard
42260
42261 \size footnotesize
42262 \InsetSpace ~
42263 \InsetSpace ~
42264 subb a,#0x8a
42265 \end_layout
42266
42267 \begin_layout Standard
42268
42269 \size footnotesize
42270 \InsetSpace ~
42271 \InsetSpace ~
42272 jnc 00107$
42273 \end_layout
42274
42275 \begin_layout Standard
42276
42277 \size footnotesize
42278 00115$:
42279 \end_layout
42280
42281 \begin_layout Standard
42282
42283 \size footnotesize
42284 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
42285 \end_layout
42286
42287 \begin_layout Standard
42288
42289 \size footnotesize
42290 ; iTemp21 [lr21:38]{short}[r4]
42291 \end_layout
42292
42293 \begin_layout Standard
42294
42295 \size footnotesize
42296 \InsetSpace ~
42297 \InsetSpace ~
42298 mov a,r4
42299 \end_layout
42300
42301 \begin_layout Standard
42302
42303 \size footnotesize
42304 \InsetSpace ~
42305 \InsetSpace ~
42306 add a,r2
42307 \end_layout
42308
42309 \begin_layout Standard
42310
42311 \size footnotesize
42312 \InsetSpace ~
42313 \InsetSpace ~
42314 mov r2,a
42315 \end_layout
42316
42317 \begin_layout Standard
42318
42319 \size footnotesize
42320 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
42321 \end_layout
42322
42323 \begin_layout Standard
42324
42325 \size footnotesize
42326 \InsetSpace ~
42327 \InsetSpace ~
42328 mov b,#0x03
42329 \end_layout
42330
42331 \begin_layout Standard
42332
42333 \size footnotesize
42334 \InsetSpace ~
42335 \InsetSpace ~
42336 mov a,r4
42337 \end_layout
42338
42339 \begin_layout Standard
42340
42341 \size footnotesize
42342 \InsetSpace ~
42343 \InsetSpace ~
42344 mul ab
42345 \end_layout
42346
42347 \begin_layout Standard
42348
42349 \size footnotesize
42350 \InsetSpace ~
42351 \InsetSpace ~
42352 mov r1,a
42353 \end_layout
42354
42355 \begin_layout Standard
42356
42357 \size footnotesize
42358 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
42359 \end_layout
42360
42361 \begin_layout Standard
42362
42363 \size footnotesize
42364 ; iTemp15 [lr29:30]{short}[r1]
42365 \end_layout
42366
42367 \begin_layout Standard
42368
42369 \size footnotesize
42370 \InsetSpace ~
42371 \InsetSpace ~
42372 add a,r3
42373 \end_layout
42374
42375 \begin_layout Standard
42376
42377 \size footnotesize
42378 \InsetSpace ~
42379 \InsetSpace ~
42380 mov r3,a
42381 \end_layout
42382
42383 \begin_layout Standard
42384
42385 \size footnotesize
42386 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
42387 \end_layout
42388
42389 \begin_layout Standard
42390
42391 \size footnotesize
42392 \InsetSpace ~
42393 \InsetSpace ~
42394 mov a,r7
42395 \end_layout
42396
42397 \begin_layout Standard
42398
42399 \size footnotesize
42400 \InsetSpace ~
42401 \InsetSpace ~
42402 add a,#0xfd
42403 \end_layout
42404
42405 \begin_layout Standard
42406
42407 \size footnotesize
42408 \InsetSpace ~
42409 \InsetSpace ~
42410 mov r7,a
42411 \end_layout
42412
42413 \begin_layout Standard
42414
42415 \size footnotesize
42416 \InsetSpace ~
42417 \InsetSpace ~
42418 mov a,r0
42419 \end_layout
42420
42421 \begin_layout Standard
42422
42423 \size footnotesize
42424 \InsetSpace ~
42425 \InsetSpace ~
42426 addc a,#0xff
42427 \end_layout
42428
42429 \begin_layout Standard
42430
42431 \size footnotesize
42432 \InsetSpace ~
42433 \InsetSpace ~
42434 mov r0,a
42435 \end_layout
42436
42437 \begin_layout Standard
42438
42439 \size footnotesize
42440 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
42441 \end_layout
42442
42443 \begin_layout Standard
42444
42445 \size footnotesize
42446 \InsetSpace ~
42447 \InsetSpace ~
42448 mov a,r7
42449 \end_layout
42450
42451 \begin_layout Standard
42452
42453 \size footnotesize
42454 \InsetSpace ~
42455 \InsetSpace ~
42456 add a,_gint
42457 \end_layout
42458
42459 \begin_layout Standard
42460
42461 \size footnotesize
42462 \InsetSpace ~
42463 \InsetSpace ~
42464 mov _gint,a
42465 \end_layout
42466
42467 \begin_layout Standard
42468
42469 \size footnotesize
42470 \InsetSpace ~
42471 \InsetSpace ~
42472 mov a,r0
42473 \end_layout
42474
42475 \begin_layout Standard
42476
42477 \size footnotesize
42478 \InsetSpace ~
42479 \InsetSpace ~
42480 addc a,(_gint + 1)
42481 \end_layout
42482
42483 \begin_layout Standard
42484
42485 \size footnotesize
42486 \InsetSpace ~
42487 \InsetSpace ~
42488 mov (_gint + 1),a
42489 \end_layout
42490
42491 \begin_layout Standard
42492
42493 \size footnotesize
42494 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
42495 \end_layout
42496
42497 \begin_layout Standard
42498
42499 \size footnotesize
42500 \InsetSpace ~
42501 \InsetSpace ~
42502 inc r4
42503 \end_layout
42504
42505 \begin_layout Standard
42506
42507 \size footnotesize
42508 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
42509 \end_layout
42510
42511 \begin_layout Standard
42512
42513 \size footnotesize
42514 \InsetSpace ~
42515 \InsetSpace ~
42516 dec r5
42517 \end_layout
42518
42519 \begin_layout Standard
42520
42521 \size footnotesize
42522 \InsetSpace ~
42523 \InsetSpace ~
42524 cjne r5,#0xff,00104$
42525 \end_layout
42526
42527 \begin_layout Standard
42528
42529 \size footnotesize
42530 \InsetSpace ~
42531 \InsetSpace ~
42532 dec r6
42533 \end_layout
42534
42535 \begin_layout Standard
42536
42537 \size footnotesize
42538 ; goto _forcond_0($4)
42539 \end_layout
42540
42541 \begin_layout Standard
42542
42543 \size footnotesize
42544 \InsetSpace ~
42545 \InsetSpace ~
42546 sjmp 00104$
42547 \end_layout
42548
42549 \begin_layout Standard
42550
42551 \size footnotesize
42552 ; _forbreak_0($7) :
42553 \end_layout
42554
42555 \begin_layout Standard
42556
42557 \size footnotesize
42558 00107$:
42559 \end_layout
42560
42561 \begin_layout Standard
42562
42563 \size footnotesize
42564 ; ret iTemp24 [lr40:41]{short}
42565 \end_layout
42566
42567 \begin_layout Standard
42568
42569 \size footnotesize
42570 \InsetSpace ~
42571 \InsetSpace ~
42572 mov a,r3
42573 \end_layout
42574
42575 \begin_layout Standard
42576
42577 \size footnotesize
42578 \InsetSpace ~
42579 \InsetSpace ~
42580 add a,r2
42581 \end_layout
42582
42583 \begin_layout Standard
42584
42585 \size footnotesize
42586 \InsetSpace ~
42587 \InsetSpace ~
42588 mov dpl,a
42589 \end_layout
42590
42591 \begin_layout Standard
42592
42593 \size footnotesize
42594 ; _return($8) :
42595 \end_layout
42596
42597 \begin_layout Standard
42598
42599 \size footnotesize
42600 00108$:
42601 \end_layout
42602
42603 \begin_layout Standard
42604
42605 \size footnotesize
42606 \InsetSpace ~
42607 \InsetSpace ~
42608 ret
42609 \newline
42610
42611 \end_layout
42612
42613 \begin_layout Section
42614 A few words about basic block successors, predecessors and dominators
42615 \end_layout
42616
42617 \begin_layout Standard
42618 Successors are basic blocks
42619 \begin_inset LatexCommand index
42620 name "Basic blocks"
42621
42622 \end_inset
42623
42624  that might execute after this basic block.
42625 \newline
42626 Predecessors are basic blocks
42627  that might execute before reaching this basic block.
42628 \newline
42629 Dominators are basic
42630  blocks that WILL execute before reaching this basic block.
42631 \newline
42632
42633 \end_layout
42634
42635 \begin_layout Standard
42636 [basic block 1]
42637 \end_layout
42638
42639 \begin_layout Standard
42640 if (something)
42641 \end_layout
42642
42643 \begin_layout Standard
42644 \InsetSpace ~
42645 \InsetSpace ~
42646 \InsetSpace ~
42647 \InsetSpace ~
42648 [basic block 2]
42649 \end_layout
42650
42651 \begin_layout Standard
42652 else
42653 \end_layout
42654
42655 \begin_layout Standard
42656 \InsetSpace ~
42657 \InsetSpace ~
42658 \InsetSpace ~
42659 \InsetSpace ~
42660 [basic block 3]
42661 \end_layout
42662
42663 \begin_layout Standard
42664 [basic block 4]
42665 \newline
42666
42667 \end_layout
42668
42669 \begin_layout Standard
42670 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
42671 \end_layout
42672
42673 \begin_layout Standard
42674 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
42675 \end_layout
42676
42677 \begin_layout Standard
42678 c) domVect of [BB4] = BB1 ...
42679  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
42680  was executed.
42681 \end_layout
42682
42683 \begin_layout Chapter
42684 Acknowledgments
42685 \end_layout
42686
42687 \begin_layout Standard
42688 \begin_inset LatexCommand url
42689 target "http://sdcc.sourceforge.net/#Who"
42690
42691 \end_inset
42692
42693
42694 \newline
42695
42696 \newline
42697
42698 \emph on
42699 Thanks to all the other volunteer developers who have helped with coding,
42700  testing, web-page creation, distribution sets, etc.
42701  You know who you are :-)
42702 \emph default
42703
42704 \newline
42705
42706 \newline
42707
42708 \emph on
42709 Thanks to Sourceforge 
42710 \begin_inset LatexCommand url
42711 target "http://www.sf.net"
42712
42713 \end_inset
42714
42715  which has hosted the project since 1999 and donates significant download
42716  bandwidth.
42717 \emph default
42718
42719 \newline
42720
42721 \newline
42722
42723 \emph on
42724 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
42725  cycles and bandwidth for snapshot builds.
42726 \newline
42727
42728 \end_layout
42729
42730 \begin_layout Standard
42731 This document was initially written by Sandeep Dutta
42732 \end_layout
42733
42734 \begin_layout Standard
42735 All product names mentioned herein may be trademarks
42736 \begin_inset LatexCommand index
42737 name "Trademarks"
42738
42739 \end_inset
42740
42741  of their respective companies.
42742  
42743 \end_layout
42744
42745 \begin_layout Section*
42746 Alphabetical index
42747 \end_layout
42748
42749 \begin_layout Standard
42750 To avoid confusion, the installation and building options for SDCC itself
42751  (chapter 2) are not part of the index.
42752 \end_layout
42753
42754 \begin_layout Standard
42755 \begin_inset LatexCommand printindex
42756
42757 \end_inset
42758
42759
42760 \end_layout
42761
42762 \end_body
42763 \end_document