* doc/sdccman.lyx doc/cdbfileformat.lyx doc/test_suite_spec.lyx:
[fw/sdcc] / doc / sdccman.lyx
1 #LyX 1.3 created this file. For more info see http://www.lyx.org/
2 \lyxformat 221
3 \textclass book
4 \begin_preamble
5 \pdfoptionpdfminorversion=3
6 \usepackage[
7   pdftitle={SDCC Compiler User Guide},
8   pdfauthor={SDCC development team},
9   pdfsubject={installation, user manual},
10   pdfkeywords={8032 8051 ansi c compiler CPU DS390
11                embedded GPL HC08 manual mcs51 microcontroller PIC Z80},
12   colorlinks=true,
13   linkcolor=blue] {hyperref}
14 %
15 \sloppy
16 \tolerance=500          
17 \emergencystretch=30pt 
18 %
19 \date{}
20 \end_preamble
21 \language english
22 \inputencoding default
23 \fontscheme pslatex
24 \graphics default
25 \paperfontsize default
26 \spacing single 
27 \papersize letterpaper
28 \paperpackage a4
29 \use_geometry 1
30 \use_amsmath 0
31 \use_natbib 0
32 \use_numerical_citations 0
33 \paperorientation portrait
34 \leftmargin 30mm
35 \topmargin 20mm
36 \rightmargin 25mm
37 \bottommargin 20mm
38 \secnumdepth 3
39 \tocdepth 3
40 \paragraph_separation indent
41 \defskip medskip
42 \quotes_language swedish
43 \quotes_times 2
44 \papercolumns 1
45 \papersides 1
46 \paperpagestyle fancy
47
48 \layout Comment
49
50 Please note: double dashed longoptions (e.g.
51  --version) are written this way: -
52 \begin_inset ERT
53 status Collapsed
54
55 \layout Standard
56
57 \backslash 
58 /
59 \end_inset 
60
61 -
62 \layout Comment
63
64 Two resp.
65  three consecutive dashes simply result in a long resp.
66  extra long dash.
67 \layout Comment
68
69 Architecture specific stuff (like memory models, code examples) should maybe
70  later go
71 \layout Comment
72
73 into seperate sections/chapters/appendices (it is hard to document PIC or
74  Z80 in 
75 \layout Comment
76
77 a 8051 centered document) - for now simply add.
78 \layout Title
79
80 SDCC Compiler User Guide
81 \layout Date
82
83
84 \size normal 
85 SDCC 2.5.0
86 \size footnotesize 
87
88 \newline 
89 $Date$ 
90 \newline 
91 $Revision$
92 \layout Comment
93
94 The above strings enclosed in $ are automatically updated by cvs
95 \layout Standard
96
97
98 \begin_inset LatexCommand \tableofcontents{}
99
100 \end_inset 
101
102
103 \layout Chapter
104
105 Introduction
106 \layout Section
107
108 About SDCC
109 \layout Standard
110
111
112 \series bold 
113 SDCC
114 \series default 
115  (
116 \emph on 
117 S
118 \emph default 
119 mall 
120 \emph on 
121 D
122 \emph default 
123 evice 
124 \emph on 
125 C
126 \emph default 
127  
128 \emph on 
129 C
130 \emph default 
131 ompiler) is an open source, retargettable, optimizing ANSI-C compiler by
132  
133 \series bold 
134 Sandeep Dutta
135 \series default 
136  designed for 8 bit Microprocessors.
137  The current version targets Intel MCS51 based Microprocessors (8031, 8032,
138  8051, 8052
139 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
140
141 \end_inset 
142
143 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
144  Zilog Z80 based MCUs.
145  It can be retargetted for other microprocessors, support for Microchip
146  PIC, Atmel AVR is under development.
147  The entire source code for the compiler is distributed under GPL.
148  SDCC uses ASXXXX
149 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
150
151 \end_inset 
152
153  & ASLINK
154 \begin_inset LatexCommand \index{aslink}
155
156 \end_inset 
157
158 , an open source retargettable assembler & linker.
159  SDCC has extensive language extensions suitable for utilizing various microcont
160 rollers and underlying hardware effectively.
161  
162 \newline 
163
164 \newline 
165 In addition to the MCU specific optimizations SDCC also does a host of standard
166  optimizations like:
167 \layout Itemize
168
169 global sub expression elimination, 
170 \layout Itemize
171
172 loop optimizations (loop invariant, strength reduction of induction variables
173  and loop reversing), 
174 \layout Itemize
175
176 constant folding & propagation, 
177 \layout Itemize
178
179 copy propagation, 
180 \layout Itemize
181
182 dead code elimination 
183 \layout Itemize
184
185 jump tables for 
186 \emph on 
187 switch
188 \emph default 
189  statements.
190 \layout Standard
191
192 For the back-end SDCC uses a global register allocation scheme which should
193  be well suited for other 8 bit MCUs.
194  
195 \newline 
196
197 \newline 
198 The peep hole optimizer uses a rule based substitution mechanism which is
199  MCU independent.
200  
201 \newline 
202
203 \newline 
204 Supported data-types are:
205 \layout Itemize
206
207 char (8 bits, 1 byte), 
208 \layout Itemize
209
210 short and int (16 bits, 2 bytes), 
211 \layout Itemize
212
213 long (32 bit, 4 bytes)
214 \layout Itemize
215
216 float (4 byte IEEE).
217  
218 \layout Standard
219
220 The compiler also allows 
221 \emph on 
222 inline assembler code
223 \emph default 
224  to be embedded anywhere in a function.
225  In addition, routines developed in assembly can also be called.
226 \newline 
227
228 \newline 
229 SDCC also provides an option (-
230 \begin_inset ERT
231 status Collapsed
232
233 \layout Standard
234
235 \backslash 
236 /
237 \end_inset 
238
239 -cyclomatic) to report the relative complexity of a function.
240  These functions can then be further optimized, or hand coded in assembly
241  if needed.
242  
243 \newline 
244
245 \newline 
246 SDCC also comes with a companion source level debugger SDCDB, the debugger
247  currently uses ucSim a freeware simulator for 8051 and other micro-controllers.
248  
249 \newline 
250
251 \newline 
252 The latest version can be downloaded from 
253 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
254
255 \end_inset 
256
257 .
258
259 \series bold 
260  
261 \series default 
262 \emph on 
263 Please note: the compiler will probably always be some steps ahead of this
264  documentation
265 \series bold 
266 \emph default 
267
268 \begin_inset LatexCommand \index{Status of documentation}
269
270 \end_inset 
271
272
273 \begin_inset Foot
274 collapsed false
275
276 \layout Standard
277
278 Obviously this has pros and cons
279 \end_inset 
280
281 .
282 \layout Section
283
284 Open Source
285 \layout Standard
286
287 All packages used in this compiler system are 
288 \emph on 
289 open source
290 \emph default 
291  and 
292 \emph on 
293 freeware
294 \emph default 
295 ; source code for all the sub-packages (pre-processor, assemblers, linkers
296  etc) is distributed with the package.
297  This documentation is maintained using a freeware word processor (LyX).
298 \newline 
299 This program is free software; you can redistribute it and/or modify it
300  under the terms of the GNU General Public License
301 \begin_inset LatexCommand \index{GNU General Public License, GPL}
302
303 \end_inset 
304
305  as published by the Free Software Foundation; either version 2, or (at
306  your option) any later version.
307  This program is distributed in the hope that it will be useful, but WITHOUT
308  ANY WARRANTY; without even the implied warranty
309 \begin_inset LatexCommand \index{warranty}
310
311 \end_inset 
312
313  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
314  See the GNU General Public License for more details.
315  You should have received a copy of the GNU General Public License along
316  with this program; if not, write to the Free Software Foundation, 59 Temple
317  Place - Suite 330, Boston, MA 02111-1307, USA.
318  In other words, you are welcome to use, share and improve this program.
319  You are forbidden to forbid anyone else to use, share and improve what
320  you give them.
321  Help stamp out software-hoarding! 
322 \layout Section
323
324 Typographic conventions
325 \begin_inset LatexCommand \index{Typographic conventions}
326
327 \end_inset 
328
329
330 \layout Standard
331
332 Throughout this manual, we will use the following convention.
333  Commands you have to type in are printed in 
334 \family sans 
335 \series bold 
336 "sans serif"
337 \series default 
338 .
339
340 \family default 
341  Code samples are printed in 
342 \family typewriter 
343 typewriter font.
344
345 \family default 
346  Interesting items and new terms are printed in 
347 \emph on 
348 italic.
349 \layout Section
350
351 Compatibility with previous versions
352 \begin_inset LatexCommand \index{Compatibility with previous versions}
353
354 \end_inset 
355
356
357 \layout Standard
358
359 This version has numerous bug fixes compared with the previous version.
360  But we also introduced some incompatibilities with older versions.
361  Not just for the fun of it, but to make the compiler more stable, efficient
362  and ANSI compliant
363 \begin_inset LatexCommand \index{ANSI-compliance}
364
365 \end_inset 
366
367  (see section 
368 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
369
370 \end_inset 
371
372  for ANSI-Compliance).
373  
374 \newline 
375
376 \layout Itemize
377
378 short is now equivalent to int (16 bits), it used to be equivalent to char
379  (8 bits) which is not ANSI compliant.
380 \layout Itemize
381
382 the default directory for gcc-builds where include, library and documentation
383  files are stored is now in /usr/local/share.
384 \layout Itemize
385
386 char type parameters to vararg functions are casted to int unless explicitly
387  casted, e.g.: 
388 \newline 
389
390 \family typewriter 
391 \SpecialChar ~
392 \SpecialChar ~
393 char a=3;
394 \newline 
395 \SpecialChar ~
396 \SpecialChar ~
397 printf ("%d %c
398 \backslash 
399 n", a, (char)a);
400 \family default 
401
402 \newline 
403  will push a as an int and as a char resp.
404 \layout Itemize
405
406 option -
407 \begin_inset ERT
408 status Collapsed
409
410 \layout Standard
411
412 \backslash 
413 /
414 \end_inset 
415
416 -regextend has been removed.
417 \layout Itemize
418
419 option -
420 \begin_inset ERT
421 status Collapsed
422
423 \layout Standard
424
425 \backslash 
426 /
427 \end_inset 
428
429 -noregparms has been removed.
430 \layout Itemize
431
432 option -
433 \begin_inset ERT
434 status Collapsed
435
436 \layout Standard
437
438 \backslash 
439 /
440 \end_inset 
441
442 -stack-after-data has been removed.
443 \layout Itemize
444
445 bit
446 \begin_inset LatexCommand \index{bit}
447
448 \end_inset 
449
450  and sbit
451 \begin_inset LatexCommand \index{sbit}
452
453 \end_inset 
454
455
456 \begin_inset LatexCommand \index{\_\_sbit}
457
458 \end_inset 
459
460  types now consistently behave like the C99 _Bool type with respect to type
461  conversion
462 \begin_inset LatexCommand \index{type conversion}
463
464 \end_inset 
465
466
467 \begin_inset LatexCommand \index{type promotion}
468
469 \end_inset 
470
471 .
472  The most common incompatibility resulting from this change is related to
473  bit toggling
474 \begin_inset LatexCommand \index{Bit toggling}
475
476 \end_inset 
477
478  idioms, e.g.:
479 \newline 
480
481 \family typewriter 
482 \SpecialChar ~
483 \SpecialChar ~
484 bit b;
485 \newline 
486 \SpecialChar ~
487 \SpecialChar ~
488 b = ~b; /* equivalent to b=1 instead of toggling b */
489 \newline 
490 \SpecialChar ~
491 \SpecialChar ~
492 b = !b; /* toggles b */
493 \newline 
494
495 \family default 
496 In previous versions, both forms would have toggled the bit.
497 \layout Standard
498
499
500 \emph on 
501 <pending: more incompatibilities?>
502 \layout Section
503
504 System Requirements
505 \layout Standard
506
507 What do you need before you start installation of SDCC? A computer, and
508  a desire to compute.
509  The preferred method of installation is to compile SDCC from source using
510  GNU gcc and make.
511  For Windows some pre-compiled binary distributions are available for your
512  convenience.
513  You should have some experience with command line tools and compiler use.
514 \layout Section
515
516 Other Resources
517 \layout Standard
518
519 The SDCC home page at 
520 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
521
522 \end_inset 
523
524  is a great place to find distribution sets.
525  You can also find links to the user mailing lists that offer help or discuss
526  SDCC with other SDCC users.
527  Web links to other SDCC related sites can also be found here.
528  This document can be found in the DOC directory of the source package as
529  a text or HTML file.
530  A pdf version of this document is available at 
531 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
532
533 \end_inset 
534
535 .
536  Some of the other tools (simulator and assembler) included with SDCC contain
537  their own documentation and can be found in the source distribution.
538  If you want the latest unreleased software, the complete source package
539  is available directly by anonymous CVS on cvs.sdcc.sourceforge.net.
540 \layout Section
541
542 Wishes for the future
543 \layout Standard
544
545 There are (and always will be) some things that could be done.
546  Here are some I can think of:
547 \newline 
548
549 \layout Standard
550
551
552 \family typewriter 
553 char KernelFunction3(char p) at 0x340;
554 \newline 
555
556 \layout Standard
557
558
559 \family typewriter 
560 code banking
561 \begin_inset LatexCommand \index{code banking (not supported)}
562
563 \end_inset 
564
565  support for mcs51
566 \newline 
567
568 \newline 
569
570 \family default 
571 If you can think of some more, please see the section 
572 \begin_inset LatexCommand \ref{sub:Requesting-Features}
573
574 \end_inset 
575
576  about filing feature requests
577 \begin_inset LatexCommand \index{Requesting features}
578
579 \end_inset 
580
581
582 \begin_inset LatexCommand \index{Feature request}
583
584 \end_inset 
585
586 .
587 \newline 
588
589 \layout Chapter
590
591 Installing SDCC
592 \begin_inset LatexCommand \index{Installation}
593
594 \end_inset 
595
596
597 \layout Standard
598
599 For most users it is sufficient to skip to either section 
600 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
601
602 \end_inset 
603
604  or section 
605 \begin_inset LatexCommand \ref{sub:Windows-Install}
606
607 \end_inset 
608
609 .
610  More detailled instructions follow below.
611 \layout Section
612
613 Configure Options
614 \begin_inset LatexCommand \index{Options SDCC configuration}
615
616 \end_inset 
617
618
619 \layout Standard
620
621 The install paths, search paths and other options are defined when running
622  'configure'.
623  The defaults can be overridden by:
624 \layout List
625 \labelwidthstring 00.00.0000
626
627 -
628 \begin_inset ERT
629 status Collapsed
630
631 \layout Standard
632
633 \backslash 
634 /
635 \end_inset 
636
637 -prefix see table below
638 \layout List
639 \labelwidthstring 00.00.0000
640
641 -
642 \begin_inset ERT
643 status Collapsed
644
645 \layout Standard
646
647 \backslash 
648 /
649 \end_inset 
650
651 -exec_prefix see table below
652 \layout List
653 \labelwidthstring 00.00.0000
654
655 -
656 \begin_inset ERT
657 status Collapsed
658
659 \layout Standard
660
661 \backslash 
662 /
663 \end_inset 
664
665 -bindir see table below
666 \layout List
667 \labelwidthstring 00.00.0000
668
669 -
670 \begin_inset ERT
671 status Collapsed
672
673 \layout Standard
674
675 \backslash 
676 /
677 \end_inset 
678
679 -datadir see table below
680 \layout List
681 \labelwidthstring 00.00.0000
682
683 docdir environment variable, see table below
684 \layout List
685 \labelwidthstring 00.00.0000
686
687 include_dir_suffix environment variable, see table below
688 \layout List
689 \labelwidthstring 00.00.0000
690
691 lib_dir_suffix environment variable, see table below
692 \layout List
693 \labelwidthstring 00.00.0000
694
695 sdccconf_h_dir_separator environment variable, either / or 
696 \backslash 
697
698 \backslash 
699  makes sense here.
700  This character will only be used in sdccconf.h; don't forget it's a C-header,
701  therefore a double-backslash is needed there.
702 \layout List
703 \labelwidthstring 00.00.0000
704
705 -
706 \begin_inset ERT
707 status Collapsed
708
709 \layout Standard
710
711 \backslash 
712 /
713 \end_inset 
714
715 -disable-mcs51-port Excludes the Intel mcs51 port
716 \layout List
717 \labelwidthstring 00.00.0000
718
719 -
720 \begin_inset ERT
721 status Collapsed
722
723 \layout Standard
724
725 \backslash 
726 /
727 \end_inset 
728
729 -disable-gbz80-port Excludes the Gameboy gbz80 port
730 \layout List
731 \labelwidthstring 00.00.0000
732
733 -
734 \begin_inset ERT
735 status Collapsed
736
737 \layout Standard
738
739 \backslash 
740 /
741 \end_inset 
742
743 -disable-z80-port Excludes the z80 port
744 \layout List
745 \labelwidthstring 00.00.0000
746
747 -
748 \begin_inset ERT
749 status Collapsed
750
751 \layout Standard
752
753 \backslash 
754 /
755 \end_inset 
756
757 -disable-avr-port Excludes the AVR port
758 \layout List
759 \labelwidthstring 00.00.0000
760
761 -
762 \begin_inset ERT
763 status Collapsed
764
765 \layout Standard
766
767 \backslash 
768 /
769 \end_inset 
770
771 -disable-ds390-port Excludes the DS390 port
772 \layout List
773 \labelwidthstring 00.00.0000
774
775 -
776 \begin_inset ERT
777 status Collapsed
778
779 \layout Standard
780
781 \backslash 
782 /
783 \end_inset 
784
785 -disable-hc08-port Excludes the HC08 port
786 \layout List
787 \labelwidthstring 00.00.0000
788
789 -
790 \begin_inset ERT
791 status Collapsed
792
793 \layout Standard
794
795 \backslash 
796 /
797 \end_inset 
798
799 -disable-pic-port Excludes the PIC port
800 \layout List
801 \labelwidthstring 00.00.0000
802
803 -
804 \begin_inset ERT
805 status Collapsed
806
807 \layout Standard
808
809 \backslash 
810 /
811 \end_inset 
812
813 -disable-xa51-port Excludes the XA51 port
814 \layout List
815 \labelwidthstring 00.00.0000
816
817 -
818 \begin_inset ERT
819 status Collapsed
820
821 \layout Standard
822
823 \backslash 
824 /
825 \end_inset 
826
827 -disable-ucsim Disables configuring and building of ucsim
828 \layout List
829 \labelwidthstring 00.00.0000
830
831 -
832 \begin_inset ERT
833 status Collapsed
834
835 \layout Standard
836
837 \backslash 
838 /
839 \end_inset 
840
841 -disable-device-lib-build Disables automatically building device libraries
842 \layout List
843 \labelwidthstring 00.00.0000
844
845 -
846 \begin_inset ERT
847 status Collapsed
848
849 \layout Standard
850
851 \backslash 
852 /
853 \end_inset 
854
855 -disable-packihx Disables building packihx
856 \layout List
857 \labelwidthstring 00.00.0000
858
859 -
860 \begin_inset ERT
861 status Collapsed
862
863 \layout Standard
864
865 \backslash 
866 /
867 \end_inset 
868
869 -enable-libgc Use the Bohem memory allocator.
870  Lower runtime footprint.
871 \layout Standard
872
873 Furthermore the environment variables CC, CFLAGS, ...
874  the tools and their arguments can be influenced.
875  Please see `configure -
876 \begin_inset ERT
877 status Collapsed
878
879 \layout Standard
880
881 \backslash 
882 /
883 \end_inset 
884
885 -help` and the man/info pages of `configure` for details.
886 \newline 
887
888 \newline 
889 The names of the standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB,
890  STD_FP_LIB, STD_DS390_LIB, STD_XA51_LIB and the environment variables SDCC_DIR_
891 NAME, SDCC_INCLUDE_NAME, SDCC_LIB_NAME are defined by `configure` too.
892  At the moment it's not possible to change the default settings (it was
893  simply never required).
894 \newline 
895
896 \newline 
897 These configure options are compiled into the binaries, and can only be
898  changed by rerunning 'configure' and recompiling SDCC.
899  The configure options are written in 
900 \emph on 
901 italics
902 \emph default 
903  to distinguish them from run time environment variables (see section search
904  paths).
905 \newline 
906
907 \newline 
908 The settings for 
909 \begin_inset Quotes sld
910 \end_inset 
911
912 Win32 builds
913 \begin_inset Quotes srd
914 \end_inset 
915
916  are used by the SDCC team to build the official Win32 binaries.
917  The SDCC team uses Mingw32 to build the official Windows binaries, because
918  it's
919 \layout Enumerate
920
921 open source, 
922 \layout Enumerate
923
924 a gcc compiler and last but not least
925 \layout Enumerate
926
927 the binaries can be built by cross compiling on Sourceforge's compile farm.
928 \layout Standard
929
930 See the examples, how to pass the Win32 settings to 'configure'.
931  The other Win32 builds using Borland, VC or whatever don't use 'configure',
932  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
933  for Win32.
934 \newline 
935
936 \newline 
937 These defaults are:
938 \newline 
939
940 \layout Standard
941 \align center 
942
943 \begin_inset  Tabular
944 <lyxtabular version="3" rows="8" columns="3">
945 <features>
946 <column alignment="block" valignment="top" leftline="true" width="0in">
947 <column alignment="block" valignment="top" leftline="true" width="0in">
948 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
949 <row topline="true" bottomline="true">
950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
951 \begin_inset Text
952
953 \layout Standard
954
955 Variable
956 \end_inset 
957 </cell>
958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
959 \begin_inset Text
960
961 \layout Standard
962
963 default
964 \end_inset 
965 </cell>
966 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
967 \begin_inset Text
968
969 \layout Standard
970
971 Win32 builds
972 \end_inset 
973 </cell>
974 </row>
975 <row topline="true">
976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
977 \begin_inset Text
978
979 \layout Standard
980
981
982 \emph on 
983 PREFIX
984 \end_inset 
985 </cell>
986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
987 \begin_inset Text
988
989 \layout Standard
990
991 /usr/local
992 \end_inset 
993 </cell>
994 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
995 \begin_inset Text
996
997 \layout Standard
998
999
1000 \backslash 
1001 sdcc
1002 \end_inset 
1003 </cell>
1004 </row>
1005 <row topline="true">
1006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1007 \begin_inset Text
1008
1009 \layout Standard
1010
1011
1012 \emph on 
1013 EXEC_PREFIX
1014 \end_inset 
1015 </cell>
1016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1017 \begin_inset Text
1018
1019 \layout Standard
1020
1021
1022 \emph on 
1023 $PREFIX
1024 \end_inset 
1025 </cell>
1026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1027 \begin_inset Text
1028
1029 \layout Standard
1030
1031
1032 \emph on 
1033 $PREFIX
1034 \end_inset 
1035 </cell>
1036 </row>
1037 <row topline="true">
1038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1039 \begin_inset Text
1040
1041 \layout Standard
1042
1043
1044 \emph on 
1045 BINDIR
1046 \end_inset 
1047 </cell>
1048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1049 \begin_inset Text
1050
1051 \layout Standard
1052
1053
1054 \emph on 
1055 $EXECPREFIX
1056 \emph default 
1057 /bin
1058 \end_inset 
1059 </cell>
1060 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1061 \begin_inset Text
1062
1063 \layout Standard
1064
1065
1066 \emph on 
1067 $EXECPREFIX
1068 \emph default 
1069
1070 \backslash 
1071 bin
1072 \end_inset 
1073 </cell>
1074 </row>
1075 <row topline="true">
1076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1077 \begin_inset Text
1078
1079 \layout Standard
1080
1081
1082 \emph on 
1083 DATADIR
1084 \end_inset 
1085 </cell>
1086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1087 \begin_inset Text
1088
1089 \layout Standard
1090
1091
1092 \emph on 
1093 $PREFIX
1094 \emph default 
1095 /share
1096 \end_inset 
1097 </cell>
1098 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1099 \begin_inset Text
1100
1101 \layout Standard
1102
1103
1104 \emph on 
1105 $PREFIX
1106 \end_inset 
1107 </cell>
1108 </row>
1109 <row topline="true">
1110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1111 \begin_inset Text
1112
1113 \layout Standard
1114
1115
1116 \emph on 
1117 DOCDIR
1118 \end_inset 
1119 </cell>
1120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1121 \begin_inset Text
1122
1123 \layout Standard
1124
1125
1126 \emph on 
1127 $DATADIR
1128 \emph default 
1129 /sdcc/doc
1130 \end_inset 
1131 </cell>
1132 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1133 \begin_inset Text
1134
1135 \layout Standard
1136
1137
1138 \emph on 
1139 $DATADIR
1140 \emph default 
1141
1142 \backslash 
1143 doc
1144 \end_inset 
1145 </cell>
1146 </row>
1147 <row topline="true">
1148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1149 \begin_inset Text
1150
1151 \layout Standard
1152
1153
1154 \emph on 
1155 INCLUDE_DIR_SUFFIX
1156 \end_inset 
1157 </cell>
1158 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1159 \begin_inset Text
1160
1161 \layout Standard
1162
1163 sdcc/include
1164 \end_inset 
1165 </cell>
1166 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1167 \begin_inset Text
1168
1169 \layout Standard
1170
1171 include
1172 \end_inset 
1173 </cell>
1174 </row>
1175 <row topline="true" bottomline="true">
1176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1177 \begin_inset Text
1178
1179 \layout Standard
1180
1181
1182 \emph on 
1183 LIB_DIR_SUFFIX
1184 \end_inset 
1185 </cell>
1186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1187 \begin_inset Text
1188
1189 \layout Standard
1190
1191 sdcc/lib
1192 \end_inset 
1193 </cell>
1194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1195 \begin_inset Text
1196
1197 \layout Standard
1198
1199 lib
1200 \end_inset 
1201 </cell>
1202 </row>
1203 </lyxtabular>
1204
1205 \end_inset 
1206
1207
1208 \newline 
1209
1210 \layout Standard
1211 \noindent 
1212 'configure' also computes relative paths.
1213  This is needed for full relocatability of a binary package and to complete
1214  search paths (see section search paths below):
1215 \newline 
1216  
1217 \layout Standard
1218 \align center 
1219
1220 \begin_inset  Tabular
1221 <lyxtabular version="3" rows="4" columns="3">
1222 <features>
1223 <column alignment="block" valignment="top" leftline="true" width="0in">
1224 <column alignment="block" valignment="top" leftline="true" width="0in">
1225 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1226 <row topline="true" bottomline="true">
1227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1228 \begin_inset Text
1229
1230 \layout Standard
1231
1232 Variable (computed)
1233 \end_inset 
1234 </cell>
1235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1236 \begin_inset Text
1237
1238 \layout Standard
1239
1240 default
1241 \end_inset 
1242 </cell>
1243 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1244 \begin_inset Text
1245
1246 \layout Standard
1247
1248 Win32 builds
1249 \end_inset 
1250 </cell>
1251 </row>
1252 <row topline="true" bottomline="true">
1253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1254 \begin_inset Text
1255
1256 \layout Standard
1257
1258
1259 \emph on 
1260 BIN2DATA_DIR
1261 \end_inset 
1262 </cell>
1263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1264 \begin_inset Text
1265
1266 \layout Standard
1267
1268 ../share
1269 \end_inset 
1270 </cell>
1271 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1272 \begin_inset Text
1273
1274 \layout Standard
1275
1276 ..
1277 \end_inset 
1278 </cell>
1279 </row>
1280 <row bottomline="true">
1281 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1282 \begin_inset Text
1283
1284 \layout Standard
1285
1286
1287 \emph on 
1288 PREFIX2BIN_DIR
1289 \end_inset 
1290 </cell>
1291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1292 \begin_inset Text
1293
1294 \layout Standard
1295
1296 bin
1297 \end_inset 
1298 </cell>
1299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1300 \begin_inset Text
1301
1302 \layout Standard
1303
1304 bin
1305 \end_inset 
1306 </cell>
1307 </row>
1308 <row bottomline="true">
1309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1310 \begin_inset Text
1311
1312 \layout Standard
1313
1314
1315 \emph on 
1316 PREFIX2DATA_DIR
1317 \end_inset 
1318 </cell>
1319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1320 \begin_inset Text
1321
1322 \layout Standard
1323
1324 share/sdcc
1325 \end_inset 
1326 </cell>
1327 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1328 \begin_inset Text
1329
1330 \layout Standard
1331
1332 \end_inset 
1333 </cell>
1334 </row>
1335 </lyxtabular>
1336
1337 \end_inset 
1338
1339
1340 \newline 
1341
1342 \layout Standard
1343 \noindent 
1344 Examples:
1345 \layout LyX-Code
1346
1347 ./configure
1348 \newline 
1349 ./configure -
1350 \begin_inset ERT
1351 status Collapsed
1352
1353 \layout Standard
1354
1355 \backslash 
1356 /
1357 \end_inset 
1358
1359 -prefix=
1360 \begin_inset Quotes srd
1361 \end_inset 
1362
1363 /usr/bin
1364 \begin_inset Quotes srd
1365 \end_inset 
1366
1367  -
1368 \begin_inset ERT
1369 status Collapsed
1370
1371 \layout Standard
1372
1373 \backslash 
1374 /
1375 \end_inset 
1376
1377 -datadir=
1378 \begin_inset Quotes srd
1379 \end_inset 
1380
1381 /usr/share
1382 \begin_inset Quotes srd
1383 \end_inset 
1384
1385
1386 \newline 
1387 ./configure -
1388 \begin_inset ERT
1389 status Collapsed
1390
1391 \layout Standard
1392
1393 \backslash 
1394 /
1395 \end_inset 
1396
1397 -disable-avr-port -
1398 \begin_inset ERT
1399 status Collapsed
1400
1401 \layout Standard
1402
1403 \backslash 
1404 /
1405 \end_inset 
1406
1407 -disable-xa51-port
1408 \layout Standard
1409
1410 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1411 32'):
1412 \layout LyX-Code
1413
1414 ./configure 
1415 \backslash 
1416
1417 \newline 
1418 CC=
1419 \begin_inset Quotes srd
1420 \end_inset 
1421
1422 i586-mingw32msvc-gcc
1423 \begin_inset Quotes srd
1424 \end_inset 
1425
1426  CXX=
1427 \begin_inset Quotes srd
1428 \end_inset 
1429
1430 i586-mingw32msvc-g++
1431 \begin_inset Quotes srd
1432 \end_inset 
1433
1434  
1435 \backslash 
1436  
1437 \newline 
1438 RANLIB=
1439 \begin_inset Quotes srd
1440 \end_inset 
1441
1442 i586-mingw32msvc-ranlib
1443 \begin_inset Quotes srd
1444 \end_inset 
1445
1446  
1447 \backslash 
1448
1449 \newline 
1450 STRIP=
1451 \begin_inset Quotes srd
1452 \end_inset 
1453
1454 i586-mingw32msvc-strip
1455 \begin_inset Quotes srd
1456 \end_inset 
1457
1458  
1459 \backslash 
1460
1461 \newline 
1462 -
1463 \begin_inset ERT
1464 status Collapsed
1465
1466 \layout Standard
1467
1468 \backslash 
1469 /
1470 \end_inset 
1471
1472 -prefix=
1473 \begin_inset Quotes srd
1474 \end_inset 
1475
1476 /sdcc
1477 \begin_inset Quotes srd
1478 \end_inset 
1479
1480  
1481 \backslash 
1482
1483 \newline 
1484 -
1485 \begin_inset ERT
1486 status Collapsed
1487
1488 \layout Standard
1489
1490 \backslash 
1491 /
1492 \end_inset 
1493
1494 -datadir=
1495 \begin_inset Quotes srd
1496 \end_inset 
1497
1498 /sdcc
1499 \begin_inset Quotes srd
1500 \end_inset 
1501
1502  
1503 \backslash 
1504
1505 \newline 
1506 docdir=
1507 \begin_inset Quotes srd
1508 \end_inset 
1509
1510 /sdcc/doc
1511 \begin_inset Quotes srd
1512 \end_inset 
1513
1514  
1515 \backslash 
1516
1517 \newline 
1518 include_dir_suffix=
1519 \begin_inset Quotes srd
1520 \end_inset 
1521
1522 include
1523 \begin_inset Quotes srd
1524 \end_inset 
1525
1526  
1527 \backslash 
1528
1529 \newline 
1530 lib_dir_suffix=
1531 \begin_inset Quotes srd
1532 \end_inset 
1533
1534 lib
1535 \begin_inset Quotes srd
1536 \end_inset 
1537
1538  
1539 \backslash 
1540
1541 \newline 
1542 sdccconf_h_dir_separator=
1543 \begin_inset Quotes srd
1544 \end_inset 
1545
1546
1547 \backslash 
1548
1549 \backslash 
1550
1551 \backslash 
1552
1553 \backslash 
1554
1555 \begin_inset Quotes srd
1556 \end_inset 
1557
1558  
1559 \backslash 
1560
1561 \newline 
1562 -
1563 \begin_inset ERT
1564 status Collapsed
1565
1566 \layout Standard
1567
1568 \backslash 
1569 /
1570 \end_inset 
1571
1572 -disable-device-lib-build
1573 \backslash 
1574
1575 \newline 
1576 -
1577 \begin_inset ERT
1578 status Collapsed
1579
1580 \layout Standard
1581
1582 \backslash 
1583 /
1584 \end_inset 
1585
1586 -disable-ucsim
1587 \backslash 
1588
1589 \newline 
1590 -
1591 \begin_inset ERT
1592 status Collapsed
1593
1594 \layout Standard
1595
1596 \backslash 
1597 /
1598 \end_inset 
1599
1600 -host=i586-mingw32msvc -
1601 \begin_inset ERT
1602 status Collapsed
1603
1604 \layout Standard
1605
1606 \backslash 
1607 /
1608 \end_inset 
1609
1610 -build=unknown-unknown-linux-gnu
1611 \layout Standard
1612
1613 To 
1614 \begin_inset Quotes sld
1615 \end_inset 
1616
1617 cross
1618 \begin_inset Quotes srd
1619 \end_inset 
1620
1621 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
1622 ):
1623 \layout LyX-Code
1624
1625 ./configure -C 
1626 \backslash 
1627
1628 \newline 
1629 CFLAGS=
1630 \begin_inset Quotes srd
1631 \end_inset 
1632
1633 -mno-cygwin -O2
1634 \begin_inset Quotes srd
1635 \end_inset 
1636
1637  
1638 \backslash 
1639
1640 \newline 
1641 LDFLAGS=
1642 \begin_inset Quotes srd
1643 \end_inset 
1644
1645 -mno-cygwin
1646 \begin_inset Quotes srd
1647 \end_inset 
1648
1649  
1650 \backslash 
1651
1652 \newline 
1653 -
1654 \begin_inset ERT
1655 status Collapsed
1656
1657 \layout Standard
1658
1659 \backslash 
1660 /
1661 \end_inset 
1662
1663 -prefix=
1664 \begin_inset Quotes srd
1665 \end_inset 
1666
1667 /sdcc
1668 \begin_inset Quotes srd
1669 \end_inset 
1670
1671  
1672 \backslash 
1673
1674 \newline 
1675 -
1676 \begin_inset ERT
1677 status Collapsed
1678
1679 \layout Standard
1680
1681 \backslash 
1682 /
1683 \end_inset 
1684
1685 -datadir=
1686 \begin_inset Quotes srd
1687 \end_inset 
1688
1689 /sdcc
1690 \begin_inset Quotes srd
1691 \end_inset 
1692
1693  
1694 \backslash 
1695
1696 \newline 
1697 docdir=
1698 \begin_inset Quotes srd
1699 \end_inset 
1700
1701 /sdcc/doc
1702 \begin_inset Quotes srd
1703 \end_inset 
1704
1705  
1706 \backslash 
1707  
1708 \newline 
1709 include_dir_suffix=
1710 \begin_inset Quotes srd
1711 \end_inset 
1712
1713 include
1714 \begin_inset Quotes srd
1715 \end_inset 
1716
1717  
1718 \backslash 
1719
1720 \newline 
1721 lib_dir_suffix=
1722 \begin_inset Quotes srd
1723 \end_inset 
1724
1725 lib
1726 \begin_inset Quotes srd
1727 \end_inset 
1728
1729  
1730 \backslash 
1731
1732 \newline 
1733 sdccconf_h_dir_separator=
1734 \begin_inset Quotes srd
1735 \end_inset 
1736
1737
1738 \backslash 
1739
1740 \backslash 
1741
1742 \backslash 
1743
1744 \backslash 
1745
1746 \begin_inset Quotes srd
1747 \end_inset 
1748
1749  
1750 \backslash 
1751
1752 \newline 
1753 -
1754 \begin_inset ERT
1755 status Collapsed
1756
1757 \layout Standard
1758
1759 \backslash 
1760 /
1761 \end_inset 
1762
1763 -disable-ucsim
1764 \layout Standard
1765
1766 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
1767  The option '-
1768 \begin_inset ERT
1769 status Collapsed
1770
1771 \layout Standard
1772
1773 \backslash 
1774 /
1775 \end_inset 
1776
1777 -C' turns on caching, which gives a little bit extra speed.
1778  However if options are changed, it can be necessary to delete the config.cache
1779  file.
1780 \layout Section
1781
1782 Install paths
1783 \begin_inset LatexCommand \label{sub:Install-paths}
1784
1785 \end_inset 
1786
1787
1788 \begin_inset LatexCommand \index{Install paths}
1789
1790 \end_inset 
1791
1792
1793 \layout Standard
1794 \added_space_top medskip \align center 
1795
1796 \begin_inset  Tabular
1797 <lyxtabular version="3" rows="5" columns="4">
1798 <features>
1799 <column alignment="center" valignment="top" leftline="true" width="0">
1800 <column alignment="center" valignment="top" leftline="true" width="0">
1801 <column alignment="center" valignment="top" leftline="true" width="0">
1802 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
1803 <row topline="true" bottomline="true">
1804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1805 \begin_inset Text
1806
1807 \layout Standard
1808
1809
1810 \series bold 
1811 Description
1812 \end_inset 
1813 </cell>
1814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1815 \begin_inset Text
1816
1817 \layout Standard
1818
1819
1820 \series bold 
1821 Path
1822 \end_inset 
1823 </cell>
1824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1825 \begin_inset Text
1826
1827 \layout Standard
1828
1829
1830 \series bold 
1831 Default
1832 \end_inset 
1833 </cell>
1834 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1835 \begin_inset Text
1836
1837 \layout Standard
1838
1839
1840 \series bold 
1841 Win32 builds
1842 \end_inset 
1843 </cell>
1844 </row>
1845 <row topline="true">
1846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1847 \begin_inset Text
1848
1849 \layout Standard
1850
1851 Binary files*
1852 \end_inset 
1853 </cell>
1854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1855 \begin_inset Text
1856
1857 \layout Standard
1858
1859
1860 \emph on 
1861 $EXEC_PREFIX
1862 \end_inset 
1863 </cell>
1864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1865 \begin_inset Text
1866
1867 \layout Standard
1868
1869 /usr/local/bin
1870 \end_inset 
1871 </cell>
1872 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1873 \begin_inset Text
1874
1875 \layout Standard
1876
1877
1878 \backslash 
1879 sdcc
1880 \backslash 
1881 bin
1882 \end_inset 
1883 </cell>
1884 </row>
1885 <row topline="true">
1886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1887 \begin_inset Text
1888
1889 \layout Standard
1890
1891 Include files
1892 \end_inset 
1893 </cell>
1894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1895 \begin_inset Text
1896
1897 \layout Standard
1898
1899
1900 \emph on 
1901 $DATADIR/ $INCLUDE_DIR_SUFFIX
1902 \end_inset 
1903 </cell>
1904 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1905 \begin_inset Text
1906
1907 \layout Standard
1908
1909 /usr/local/share/sdcc/include
1910 \end_inset 
1911 </cell>
1912 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1913 \begin_inset Text
1914
1915 \layout Standard
1916
1917
1918 \backslash 
1919 sdcc
1920 \backslash 
1921 include
1922 \end_inset 
1923 </cell>
1924 </row>
1925 <row topline="true">
1926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1927 \begin_inset Text
1928
1929 \layout Standard
1930
1931 Library file**
1932 \end_inset 
1933 </cell>
1934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1935 \begin_inset Text
1936
1937 \layout Standard
1938
1939
1940 \emph on 
1941 $DATADIR/$LIB_DIR_SUFFIX
1942 \end_inset 
1943 </cell>
1944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1945 \begin_inset Text
1946
1947 \layout Standard
1948
1949 /usr/local/share/sdcc/lib
1950 \end_inset 
1951 </cell>
1952 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1953 \begin_inset Text
1954
1955 \layout Standard
1956
1957
1958 \backslash 
1959 sdcc
1960 \backslash 
1961 lib
1962 \end_inset 
1963 </cell>
1964 </row>
1965 <row topline="true" bottomline="true">
1966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1967 \begin_inset Text
1968
1969 \layout Standard
1970
1971 Documentation
1972 \end_inset 
1973 </cell>
1974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1975 \begin_inset Text
1976
1977 \layout Standard
1978
1979
1980 \emph on 
1981 $DOCDIR
1982 \end_inset 
1983 </cell>
1984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1985 \begin_inset Text
1986
1987 \layout Standard
1988
1989 /usr/local/share/sdcc/doc
1990 \end_inset 
1991 </cell>
1992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1993 \begin_inset Text
1994
1995 \layout Standard
1996
1997
1998 \backslash 
1999 sdcc
2000 \backslash 
2001 doc
2002 \end_inset 
2003 </cell>
2004 </row>
2005 </lyxtabular>
2006
2007 \end_inset 
2008
2009
2010 \layout Verse
2011
2012
2013 \size footnotesize 
2014 *compiler, preprocessor, assembler, and linker
2015 \newline 
2016 **the 
2017 \shape italic 
2018 model
2019 \shape default 
2020  is auto-appended by the compiler, e.g.
2021  small, large, z80, ds390 etc
2022 \layout Standard
2023 \noindent 
2024 The install paths can still be changed during `make install` with e.g.:
2025 \layout LyX-Code
2026
2027 make install prefix=$(HOME)/local/sdcc
2028 \layout Standard
2029
2030 Of course this doesn't change the search paths compiled into the binaries.
2031 \newline 
2032
2033 \newline 
2034 Moreover the install path can be changed by defining DESTDIR
2035 \begin_inset LatexCommand \index{DESTDIR}
2036
2037 \end_inset 
2038
2039 :
2040 \layout LyX-Code
2041
2042 make install DESTDIR=$(HOME)/sdcc.rpm/
2043 \layout Standard
2044
2045 Please note that DESTDIR must have a trailing slash!
2046 \layout Section
2047
2048 Search Paths
2049 \begin_inset LatexCommand \label{sub:Search-Paths}
2050
2051 \end_inset 
2052
2053
2054 \begin_inset LatexCommand \index{Search path}
2055
2056 \end_inset 
2057
2058
2059 \layout Standard
2060
2061 Some search paths or parts of them are determined by configure variables
2062  (in 
2063 \emph on 
2064 italics
2065 \emph default 
2066 , see section above).
2067  Further search paths are determined by environment variables during runtime.
2068  
2069 \newline 
2070 The paths searched when running the compiler are as follows (the first catch
2071  wins):
2072 \newline 
2073
2074 \newline 
2075 1.
2076  Binary files (preprocessor, assembler and linker)
2077 \newline 
2078
2079 \layout Standard
2080 \align center 
2081
2082 \begin_inset  Tabular
2083 <lyxtabular version="3" rows="4" columns="3">
2084 <features>
2085 <column alignment="block" valignment="top" leftline="true" width="0in">
2086 <column alignment="block" valignment="top" leftline="true" width="0in">
2087 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2088 <row topline="true" bottomline="true">
2089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2090 \begin_inset Text
2091
2092 \layout Standard
2093
2094 Search path
2095 \end_inset 
2096 </cell>
2097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2098 \begin_inset Text
2099
2100 \layout Standard
2101
2102 default
2103 \end_inset 
2104 </cell>
2105 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2106 \begin_inset Text
2107
2108 \layout Standard
2109
2110 Win32 builds
2111 \end_inset 
2112 </cell>
2113 </row>
2114 <row topline="true">
2115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2116 \begin_inset Text
2117
2118 \layout Standard
2119
2120 $SDCC_HOME/
2121 \emph on 
2122 $PPREFIX2BIN_DIR
2123 \end_inset 
2124 </cell>
2125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2126 \begin_inset Text
2127
2128 \layout Standard
2129
2130 $SDCC_HOME/bin
2131 \end_inset 
2132 </cell>
2133 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2134 \begin_inset Text
2135
2136 \layout Standard
2137
2138 $SDCC_HOME
2139 \backslash 
2140 bin
2141 \end_inset 
2142 </cell>
2143 </row>
2144 <row topline="true">
2145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2146 \begin_inset Text
2147
2148 \layout Standard
2149
2150 Path of argv[0] (if available)
2151 \end_inset 
2152 </cell>
2153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2154 \begin_inset Text
2155
2156 \layout Standard
2157
2158 Path of argv[0]
2159 \end_inset 
2160 </cell>
2161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2162 \begin_inset Text
2163
2164 \layout Standard
2165
2166 Path of argv[0]
2167 \end_inset 
2168 </cell>
2169 </row>
2170 <row topline="true" bottomline="true">
2171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2172 \begin_inset Text
2173
2174 \layout Standard
2175
2176 $PATH
2177 \end_inset 
2178 </cell>
2179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2180 \begin_inset Text
2181
2182 \layout Standard
2183
2184 $PATH
2185 \end_inset 
2186 </cell>
2187 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2188 \begin_inset Text
2189
2190 \layout Standard
2191
2192 $PATH
2193 \end_inset 
2194 </cell>
2195 </row>
2196 </lyxtabular>
2197
2198 \end_inset 
2199
2200  
2201 \newline 
2202
2203 \layout Standard
2204 \noindent 
2205 2.
2206  Include files
2207 \newline 
2208
2209 \layout Standard
2210 \align center 
2211
2212 \begin_inset  Tabular
2213 <lyxtabular version="3" rows="6" columns="3">
2214 <features>
2215 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2216 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2217 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2218 <row topline="true" bottomline="true">
2219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2220 \begin_inset Text
2221
2222 \layout Standard
2223
2224 Search path
2225 \end_inset 
2226 </cell>
2227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2228 \begin_inset Text
2229
2230 \layout Standard
2231
2232 default
2233 \end_inset 
2234 </cell>
2235 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2236 \begin_inset Text
2237
2238 \layout Standard
2239
2240 Win32 builds
2241 \end_inset 
2242 </cell>
2243 </row>
2244 <row topline="true">
2245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2246 \begin_inset Text
2247
2248 \layout Standard
2249
2250 -
2251 \begin_inset ERT
2252 status Collapsed
2253
2254 \layout Standard
2255
2256 \backslash 
2257 /
2258 \end_inset 
2259
2260 -I dir
2261 \end_inset 
2262 </cell>
2263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2264 \begin_inset Text
2265
2266 \layout Standard
2267
2268 -
2269 \begin_inset ERT
2270 status Collapsed
2271
2272 \layout Standard
2273
2274 \backslash 
2275 /
2276 \end_inset 
2277
2278 -I dir
2279 \end_inset 
2280 </cell>
2281 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2282 \begin_inset Text
2283
2284 \layout Standard
2285
2286 -
2287 \begin_inset ERT
2288 status Collapsed
2289
2290 \layout Standard
2291
2292 \backslash 
2293 /
2294 \end_inset 
2295
2296 -I dir
2297 \end_inset 
2298 </cell>
2299 </row>
2300 <row topline="true">
2301 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2302 \begin_inset Text
2303
2304 \layout Standard
2305
2306 $SDCC_INCLUDE
2307 \end_inset 
2308 </cell>
2309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2310 \begin_inset Text
2311
2312 \layout Standard
2313
2314 $SDCC_INCLUDE
2315 \end_inset 
2316 </cell>
2317 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2318 \begin_inset Text
2319
2320 \layout Standard
2321
2322 $SDCC_INCLUDE
2323 \end_inset 
2324 </cell>
2325 </row>
2326 <row topline="true">
2327 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2328 \begin_inset Text
2329
2330 \layout Standard
2331
2332 $SDCC_HOME/
2333 \newline 
2334
2335 \emph on 
2336 $PREFIX2DATA_DIR/
2337 \newline 
2338 $INCLUDE_DIR_SUFFIX
2339 \end_inset 
2340 </cell>
2341 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2342 \begin_inset Text
2343
2344 \layout Standard
2345
2346 $SDCC_ HOME/
2347 \newline 
2348 share/sdcc/
2349 \newline 
2350 include
2351 \end_inset 
2352 </cell>
2353 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2354 \begin_inset Text
2355
2356 \layout Standard
2357
2358 $SDCC_HOME
2359 \backslash 
2360 include
2361 \end_inset 
2362 </cell>
2363 </row>
2364 <row topline="true">
2365 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2366 \begin_inset Text
2367
2368 \layout Standard
2369
2370 path(argv[0])/
2371 \newline 
2372
2373 \emph on 
2374 $BIN2DATADIR/
2375 \emph default 
2376
2377 \newline 
2378
2379 \emph on 
2380 $INCLUDE_DIR_SUFFIX
2381 \end_inset 
2382 </cell>
2383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2384 \begin_inset Text
2385
2386 \layout Standard
2387
2388 path(argv[0])/
2389 \newline 
2390 ../sdcc/include
2391 \newline 
2392 \SpecialChar ~
2393 \SpecialChar ~
2394 \SpecialChar ~
2395 \SpecialChar ~
2396 \SpecialChar ~
2397 \SpecialChar ~
2398 \SpecialChar ~
2399 \SpecialChar ~
2400 \SpecialChar ~
2401 \SpecialChar ~
2402 \SpecialChar ~
2403 \SpecialChar ~
2404 \SpecialChar ~
2405 \SpecialChar ~
2406 \SpecialChar ~
2407 \SpecialChar ~
2408 \SpecialChar ~
2409 \SpecialChar ~
2410 \SpecialChar ~
2411 \SpecialChar ~
2412 \SpecialChar ~
2413 \SpecialChar ~
2414 \SpecialChar ~
2415 \SpecialChar ~
2416 \SpecialChar ~
2417 \SpecialChar ~
2418 \SpecialChar ~
2419 \SpecialChar ~
2420 \SpecialChar ~
2421 \SpecialChar ~
2422 \SpecialChar ~
2423 \SpecialChar ~
2424 \SpecialChar ~
2425 \SpecialChar ~
2426 \SpecialChar ~
2427 \SpecialChar ~
2428 \SpecialChar ~
2429 \SpecialChar ~
2430
2431 \end_inset 
2432 </cell>
2433 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2434 \begin_inset Text
2435
2436 \layout Standard
2437
2438 path(argv[0])
2439 \backslash 
2440 ..
2441 \backslash 
2442 include
2443 \end_inset 
2444 </cell>
2445 </row>
2446 <row topline="true" bottomline="true">
2447 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2448 \begin_inset Text
2449
2450 \layout Standard
2451
2452
2453 \emph on 
2454 $DATADIR/
2455 \emph default 
2456
2457 \newline 
2458
2459 \emph on 
2460 $INCLUDE_DIR_SUFFIX
2461 \end_inset 
2462 </cell>
2463 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2464 \begin_inset Text
2465
2466 \layout Standard
2467
2468 /usr/local/share/sdcc/
2469 \newline 
2470 include
2471 \end_inset 
2472 </cell>
2473 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2474 \begin_inset Text
2475
2476 \layout Standard
2477
2478 (not on Win32)
2479 \end_inset 
2480 </cell>
2481 </row>
2482 </lyxtabular>
2483
2484 \end_inset 
2485
2486  
2487 \newline 
2488
2489 \layout Standard
2490 \noindent 
2491 The option -
2492 \begin_inset ERT
2493 status Collapsed
2494
2495 \layout Standard
2496
2497 \backslash 
2498 /
2499 \end_inset 
2500
2501 -nostdinc disables the last two search paths.
2502 \newline 
2503
2504 \newline 
2505 3.
2506  Library files 
2507 \newline 
2508
2509 \layout Standard
2510
2511 With the exception of 
2512 \begin_inset Quotes sld
2513 \end_inset 
2514
2515 -
2516 \begin_inset ERT
2517 status Collapsed
2518
2519 \layout Standard
2520
2521 \backslash 
2522 /
2523 \end_inset 
2524
2525 -L dir
2526 \begin_inset Quotes srd
2527 \end_inset 
2528
2529  the 
2530 \shape italic 
2531 model
2532 \shape default 
2533  is auto-appended by the compiler (e.g.
2534  small, large, z80, ds390 etc.).
2535  
2536 \newline 
2537
2538 \layout Standard
2539 \align center 
2540
2541 \begin_inset  Tabular
2542 <lyxtabular version="3" rows="6" columns="3">
2543 <features>
2544 <column alignment="block" valignment="top" leftline="true" width="1.7in">
2545 <column alignment="block" valignment="top" leftline="true" width="1.2in">
2546 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
2547 <row topline="true" bottomline="true">
2548 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2549 \begin_inset Text
2550
2551 \layout Standard
2552
2553 Search path
2554 \end_inset 
2555 </cell>
2556 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2557 \begin_inset Text
2558
2559 \layout Standard
2560
2561 default
2562 \end_inset 
2563 </cell>
2564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2565 \begin_inset Text
2566
2567 \layout Standard
2568
2569 Win32 builds
2570 \end_inset 
2571 </cell>
2572 </row>
2573 <row topline="true">
2574 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2575 \begin_inset Text
2576
2577 \layout Standard
2578
2579 -
2580 \begin_inset ERT
2581 status Collapsed
2582
2583 \layout Standard
2584
2585 \backslash 
2586 /
2587 \end_inset 
2588
2589 -L dir
2590 \end_inset 
2591 </cell>
2592 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2593 \begin_inset Text
2594
2595 \layout Standard
2596
2597 -
2598 \begin_inset ERT
2599 status Collapsed
2600
2601 \layout Standard
2602
2603 \backslash 
2604 /
2605 \end_inset 
2606
2607 -L dir
2608 \end_inset 
2609 </cell>
2610 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2611 \begin_inset Text
2612
2613 \layout Standard
2614
2615 -
2616 \begin_inset ERT
2617 status Collapsed
2618
2619 \layout Standard
2620
2621 \backslash 
2622 /
2623 \end_inset 
2624
2625 -L dir
2626 \end_inset 
2627 </cell>
2628 </row>
2629 <row topline="true">
2630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2631 \begin_inset Text
2632
2633 \layout Standard
2634
2635 $SDCC_LIB/
2636 \newline 
2637
2638 \emph on 
2639 <model>
2640 \end_inset 
2641 </cell>
2642 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2643 \begin_inset Text
2644
2645 \layout Standard
2646
2647 $SDCC_LIB/
2648 \newline 
2649
2650 \emph on 
2651 <model>
2652 \end_inset 
2653 </cell>
2654 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2655 \begin_inset Text
2656
2657 \layout Standard
2658
2659 $SDCC_LIB
2660 \backslash 
2661
2662 \newline 
2663
2664 \emph on 
2665 <model>
2666 \end_inset 
2667 </cell>
2668 </row>
2669 <row topline="true">
2670 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2671 \begin_inset Text
2672
2673 \layout Standard
2674
2675 $SDCC_HOME/
2676 \newline 
2677
2678 \emph on 
2679 $PREFIX2DATA_DIR/
2680 \newline 
2681 $LIB_DIR_SUFFIX/<model>
2682 \end_inset 
2683 </cell>
2684 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2685 \begin_inset Text
2686
2687 \layout Standard
2688
2689 $SDCC_HOME/
2690 \newline 
2691 share/sdcc/
2692 \newline 
2693 lib/
2694 \emph on 
2695 <model>
2696 \end_inset 
2697 </cell>
2698 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2699 \begin_inset Text
2700
2701 \layout Standard
2702
2703 $SDCC_HOME
2704 \backslash 
2705 lib
2706 \backslash 
2707
2708 \emph on 
2709
2710 \newline 
2711 <model>
2712 \end_inset 
2713 </cell>
2714 </row>
2715 <row topline="true">
2716 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2717 \begin_inset Text
2718
2719 \layout Standard
2720
2721 path(argv[0])/
2722 \newline 
2723
2724 \emph on 
2725 $BIN2DATADIR/
2726 \emph default 
2727
2728 \newline 
2729
2730 \emph on 
2731 $LIB_DIR_SUFFIX/<model>
2732 \end_inset 
2733 </cell>
2734 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2735 \begin_inset Text
2736
2737 \layout Standard
2738
2739 path(argv[0])/
2740 \newline 
2741 ../sdcc/lib/
2742 \emph on 
2743 <model>
2744 \newline 
2745 \SpecialChar ~
2746 \SpecialChar ~
2747 \SpecialChar ~
2748 \SpecialChar ~
2749 \SpecialChar ~
2750 \SpecialChar ~
2751 \SpecialChar ~
2752 \SpecialChar ~
2753 \SpecialChar ~
2754 \SpecialChar ~
2755 \SpecialChar ~
2756 \SpecialChar ~
2757 \SpecialChar ~
2758 \SpecialChar ~
2759 \SpecialChar ~
2760 \SpecialChar ~
2761 \SpecialChar ~
2762 \SpecialChar ~
2763 \SpecialChar ~
2764 \SpecialChar ~
2765 \SpecialChar ~
2766 \SpecialChar ~
2767 \SpecialChar ~
2768 \SpecialChar ~
2769 \SpecialChar ~
2770 \SpecialChar ~
2771 \SpecialChar ~
2772 \SpecialChar ~
2773 \SpecialChar ~
2774 \SpecialChar ~
2775 \SpecialChar ~
2776 \SpecialChar ~
2777 \SpecialChar ~
2778 \SpecialChar ~
2779 \SpecialChar ~
2780 \SpecialChar ~
2781 \SpecialChar ~
2782 \SpecialChar ~
2783 \SpecialChar ~
2784
2785 \end_inset 
2786 </cell>
2787 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2788 \begin_inset Text
2789
2790 \layout Standard
2791
2792 path(argv[0])
2793 \backslash 
2794
2795 \newline 
2796 ..
2797 \backslash 
2798 lib
2799 \backslash 
2800
2801 \emph on 
2802 <model>
2803 \newline 
2804 \SpecialChar ~
2805 \SpecialChar ~
2806 \SpecialChar ~
2807 \SpecialChar ~
2808 \SpecialChar ~
2809 \SpecialChar ~
2810 \SpecialChar ~
2811 \SpecialChar ~
2812 \SpecialChar ~
2813 \SpecialChar ~
2814 \SpecialChar ~
2815 \SpecialChar ~
2816 \SpecialChar ~
2817 \SpecialChar ~
2818 \SpecialChar ~
2819 \SpecialChar ~
2820 \SpecialChar ~
2821 \SpecialChar ~
2822 \SpecialChar ~
2823 \SpecialChar ~
2824 \SpecialChar ~
2825 \SpecialChar ~
2826 \SpecialChar ~
2827 \SpecialChar ~
2828 \SpecialChar ~
2829 \SpecialChar ~
2830 \SpecialChar ~
2831 \SpecialChar ~
2832 \SpecialChar ~
2833 \SpecialChar ~
2834 \SpecialChar ~
2835 \SpecialChar ~
2836 \SpecialChar ~
2837 \SpecialChar ~
2838 \SpecialChar ~
2839
2840 \end_inset 
2841 </cell>
2842 </row>
2843 <row topline="true" bottomline="true">
2844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2845 \begin_inset Text
2846
2847 \layout Standard
2848
2849
2850 \emph on 
2851 $DATADIR/
2852 \newline 
2853 $LIB_DIR_SUFFIX/<model>
2854 \end_inset 
2855 </cell>
2856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2857 \begin_inset Text
2858
2859 \layout Standard
2860
2861 /usr/local/share/sdcc/
2862 \newline 
2863 lib/
2864 \emph on 
2865 <model>
2866 \end_inset 
2867 </cell>
2868 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2869 \begin_inset Text
2870
2871 \layout Standard
2872
2873 (not on Win32)
2874 \end_inset 
2875 </cell>
2876 </row>
2877 </lyxtabular>
2878
2879 \end_inset 
2880
2881
2882 \newline 
2883
2884 \layout Comment
2885
2886 Don't delete any of the stray spaces in the table above without checking
2887  the HTML output (last line)!
2888 \layout Standard
2889
2890 \SpecialChar ~
2891
2892 \newline 
2893 The option -
2894 \begin_inset ERT
2895 status Collapsed
2896
2897 \layout Standard
2898
2899 \backslash 
2900 /
2901 \end_inset 
2902
2903 -nostdlib disables the last two search paths.
2904 \layout Section
2905
2906 Building SDCC
2907 \begin_inset LatexCommand \index{Building SDCC}
2908
2909 \end_inset 
2910
2911
2912 \layout Subsection
2913
2914 Building SDCC on Linux
2915 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
2916
2917 \end_inset 
2918
2919
2920 \layout Enumerate
2921
2922
2923 \series medium 
2924 Download the source package
2925 \series default 
2926  either from the SDCC CVS repository or from the nightly snapshots
2927 \series medium 
2928 , it will be named something like sdcc
2929 \series default 
2930 .src
2931 \series medium 
2932 .t
2933 \series default 
2934 ar.
2935 \series medium 
2936 gz
2937 \series default 
2938  
2939 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
2940
2941 \end_inset 
2942
2943 .
2944 \layout Enumerate
2945
2946
2947 \series medium 
2948 Bring up a command line terminal, such as xterm.
2949 \layout Enumerate
2950
2951
2952 \series medium 
2953 Unpack the file using a command like: 
2954 \family sans 
2955 \series bold 
2956 "tar -xvzf sdcc.src.tar.gz
2957 \family default 
2958 \series default 
2959 "
2960 \series medium 
2961 , this will create a sub-directory called sdcc with all of the sources.
2962 \layout Enumerate
2963
2964 Change directory into the main SDCC directory, for example type: 
2965 \family sans 
2966 \series bold 
2967 "cd sdcc
2968 \series default 
2969 ".
2970 \layout Enumerate
2971
2972
2973 \series medium 
2974 Type 
2975 \family sans 
2976 \series bold 
2977 "./configure
2978 \family default 
2979 \series default 
2980 ".
2981  This configures the package for compilation on your system.
2982 \layout Enumerate
2983
2984
2985 \series medium 
2986 Type 
2987 \family sans 
2988 \series bold 
2989 "make
2990 \family default 
2991 \series default 
2992 "
2993 \series medium 
2994 .
2995
2996 \series default 
2997  All of the source packages will compile, this can take a while.
2998 \layout Enumerate
2999
3000
3001 \series medium 
3002 Type 
3003 \family sans 
3004 \series bold 
3005 "make install"
3006 \family default 
3007 \series default 
3008  as root
3009 \series medium 
3010 .
3011
3012 \series default 
3013  This copies the binary executables, the include files, the libraries and
3014  the documentation to the install directories.
3015  Proceed with section 
3016 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3017
3018 \end_inset 
3019
3020 .
3021 \layout Subsection
3022
3023 Building SDCC on OSX 2.x
3024 \layout Standard
3025
3026 Follow the instruction for Linux.
3027 \newline 
3028
3029 \newline 
3030 On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease
3031 )) fails to compile SDCC.
3032  Fortunately there's also gcc 2.9.x installed, which works fine.
3033  This compiler can be selected by running 'configure' with:
3034 \layout LyX-Code
3035
3036 ./configure CC=gcc2 CXX=g++2
3037 \layout Subsection
3038
3039 Cross compiling SDCC on Linux for Windows
3040 \layout Standard
3041
3042 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3043  See section 'Configure Options'.
3044 \layout Subsection
3045
3046 Building SDCC on Windows 
3047 \layout Standard
3048
3049 With the exception of Cygwin the SDCC binaries uCsim and sdcdb can't be
3050  built on Windows.
3051  They use Unix-sockets, which are not available on Win32.
3052 \layout Subsection
3053
3054 Building SDCC using Cygwin and Mingw32
3055 \layout Standard
3056
3057 For building and installing a Cygwin executable follow the instructions
3058  for Linux.
3059 \newline 
3060
3061 \newline 
3062 On Cygwin a 
3063 \begin_inset Quotes sld
3064 \end_inset 
3065
3066 native
3067 \begin_inset Quotes srd
3068 \end_inset 
3069
3070  Win32-binary can be built, which will not need the Cygwin-DLL.
3071  For the necessary 'configure' options see section 'configure options' or
3072  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
3073 \newline 
3074
3075 \newline 
3076 In order to install Cygwin on Windows download setup.exe from 
3077 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
3078
3079 \end_inset 
3080
3081 .
3082  Run it, set the 
3083 \begin_inset Quotes sld
3084 \end_inset 
3085
3086 default text file type
3087 \begin_inset Quotes srd
3088 \end_inset 
3089
3090  to 
3091 \begin_inset Quotes sld
3092 \end_inset 
3093
3094 unix
3095 \begin_inset Quotes srd
3096 \end_inset 
3097
3098  and download/install at least the following packages.
3099  Some packages are selected by default, others will be automatically selected
3100  because of dependencies with the manually selected packages.
3101  Never deselect these packages!
3102 \layout Itemize
3103
3104 flex
3105 \layout Itemize
3106
3107 bison
3108 \layout Itemize
3109
3110 gcc ; version 3.x is fine, no need to use the old 2.9x
3111 \layout Itemize
3112
3113 binutils ; selected with gcc
3114 \layout Itemize
3115
3116 make
3117 \layout Itemize
3118
3119 rxvt ; a nice console, which makes life much easier under windoze (see below)
3120 \layout Itemize
3121
3122 man ; not really needed for building SDCC, but you'll miss it sooner or
3123  later
3124 \layout Itemize
3125
3126 less ; not really needed for building SDCC, but you'll miss it sooner or
3127  later
3128 \layout Itemize
3129
3130 cvs ; only if you use CVS access
3131 \layout Standard
3132
3133 If you want to develop something you'll need:
3134 \layout Itemize
3135
3136 python ; for the regression tests
3137 \layout Itemize
3138
3139 gdb ; the gnu debugger, together with the nice GUI 
3140 \begin_inset Quotes sld
3141 \end_inset 
3142
3143 insight
3144 \begin_inset Quotes srd
3145 \end_inset 
3146
3147
3148 \layout Itemize
3149
3150 openssh ; to access the CF or commit changes
3151 \layout Itemize
3152
3153 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3154  use autoconf-stable!
3155 \layout Standard
3156
3157 rxvt is a nice console with history.
3158  Replace in your cygwin.bat the line
3159 \layout LyX-Code
3160
3161 bash -
3162 \begin_inset ERT
3163 status Collapsed
3164
3165 \layout Standard
3166
3167 \backslash 
3168 /
3169 \end_inset 
3170
3171 -login -i 
3172 \layout Standard
3173
3174 with (one line):
3175 \layout LyX-Code
3176
3177 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3178 \layout LyX-Code
3179
3180      -bg black -fg white -geometry 100x65 -e bash -
3181 \begin_inset ERT
3182 status Collapsed
3183
3184 \layout Standard
3185
3186 \backslash 
3187 /
3188 \end_inset 
3189
3190 -login
3191 \layout Standard
3192
3193 Text selected with the mouse is automatically copied to the clipboard, pasting
3194  works with shift-insert.
3195 \newline 
3196
3197 \newline 
3198 The other good tip is to make sure you have no //c/-style paths anywhere,
3199  use /cygdrive/c/ instead.
3200  Using // invokes a network lookup which is very slow.
3201  If you think 
3202 \begin_inset Quotes sld
3203 \end_inset 
3204
3205 cygdrive
3206 \begin_inset Quotes srd
3207 \end_inset 
3208
3209  is too long, you can change it with e.g.
3210 \layout LyX-Code
3211
3212 mount -s -u -c /mnt
3213 \layout Standard
3214
3215 SDCC sources use the unix line ending LF.
3216  Life is much easier, if you store the source tree on a drive which is mounted
3217  in binary mode.
3218  And use an editor which can handle LF-only line endings.
3219  Make sure not to commit files with windows line endings.
3220  The tabulator spacing
3221 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
3222
3223 \end_inset 
3224
3225  used in the project is 8.
3226  Although a tabulator spacing of 8 is a sensible choice for programmers
3227  (it's a power of 2 and allows to display 8/16 bit signed variables without
3228  loosing columns) the plan is to move towards using only spaces in the source.
3229 \layout Subsection
3230
3231 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3232 \layout Standard
3233
3234
3235 \series medium 
3236 Download the source package
3237 \series default 
3238  either from the SDCC CVS repository or from the 
3239 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3240
3241 \end_inset 
3242
3243
3244 \series medium 
3245 , it will be named something like sdcc
3246 \series default 
3247 .src
3248 \series medium 
3249 .tgz.
3250
3251 \series default 
3252  SDCC is distributed with all the projects, workspaces, and files you need
3253  to build it using Visual C++ 6.0/NET (except for sdcdb.exe which currently
3254  doesn't build under MSVC).
3255  The workspace name is 'sdcc.dsw'.
3256  Please note that as it is now, all the executables are created in a folder
3257  called sdcc
3258 \backslash 
3259 bin_vc.
3260  Once built you need to copy the executables from sdcc
3261 \backslash 
3262 bin_vc to sdcc
3263 \backslash 
3264 bin before running SDCC.
3265  
3266 \newline 
3267
3268 \newline 
3269 WARNING: Visual studio is very picky with line terminations; it expects
3270  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
3271  If you are getting a message such as "This makefile was not generated by
3272  Developer Studio etc.
3273  etc.
3274 \begin_inset Quotes srd
3275 \end_inset 
3276
3277  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
3278  need to convert the Unix style line endings to DOS style line endings.
3279  To do so you can use the 
3280 \begin_inset Quotes sld
3281 \end_inset 
3282
3283 unix2dos
3284 \begin_inset Quotes srd
3285 \end_inset 
3286
3287  utility freely available on the internet.
3288  Doug Hawkins reported in the sdcc-user list that this works:
3289 \newline 
3290
3291 \newline 
3292 C:
3293 \backslash 
3294 Programming
3295 \backslash 
3296 SDCC> unix2dos sdcc.dsw
3297 \newline 
3298 C:
3299 \backslash 
3300 Programming
3301 \backslash 
3302 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
3303 \newline 
3304
3305 \newline 
3306 In order to build SDCC with MSVC you need win32 executables of bison.exe,
3307  flex.exe, and gawk.exe.
3308  One good place to get them is 
3309 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3310
3311 \end_inset 
3312
3313
3314 \newline 
3315
3316 \newline 
3317 Download the file UnxUtils
3318 \begin_inset LatexCommand \index{UnxUtils}
3319
3320 \end_inset 
3321
3322 .zip.
3323  Now you have to install the utilities and setup MSVC so it can locate the
3324  required programs.
3325  Here there are two alternatives (choose one!):
3326 \layout Enumerate
3327
3328 The easy way:
3329 \newline 
3330
3331 \newline 
3332 a) Extract UnxUtils.zip to your C:
3333 \backslash 
3334  hard disk PRESERVING the original paths, otherwise bison won't work.
3335  (If you are using WinZip make certain that 'Use folder names' is selected)
3336 \newline 
3337
3338 \newline 
3339 b) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3340  in 'Show directories for:' select 'Executable files', and in the directories
3341  window add a new path: 'C:
3342 \backslash 
3343 user
3344 \backslash 
3345 local
3346 \backslash 
3347 wbin', click ok.
3348 \newline 
3349
3350 \newline 
3351 (As a side effect, you get a bunch of Unix utilities that could be useful,
3352  such as diff and patch.)
3353 \layout Enumerate
3354
3355 A more compact way:
3356 \newline 
3357
3358 \newline 
3359 This one avoids extracting a bunch of files you may not use, but requires
3360  some extra work:
3361 \newline 
3362
3363 \newline 
3364 a) Create a directory were to put the tools needed, or use a directory already
3365  present.
3366  Say for example 'C:
3367 \backslash 
3368 util'.
3369 \newline 
3370
3371 \newline 
3372 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and gawk.exe
3373  to such directory WITHOUT preserving the original paths.
3374  (If you are using WinZip make certain that 'Use folder names' is not selected)
3375 \newline 
3376
3377 \newline 
3378 c) Rename bison.exe to '_bison.exe'.
3379 \newline 
3380
3381 \newline 
3382 d) Create a batch file 'bison.bat' in 'C:
3383 \backslash 
3384 util
3385 \backslash 
3386 ' and add these lines: 
3387 \newline 
3388 \SpecialChar ~
3389 \SpecialChar ~
3390 set BISON_SIMPLE=C:
3391 \backslash 
3392 util
3393 \backslash 
3394 bison.simple 
3395 \newline 
3396 \SpecialChar ~
3397 \SpecialChar ~
3398 set BISON_HAIRY=C:
3399 \backslash 
3400 util
3401 \backslash 
3402 bison.hairy
3403 \newline 
3404 \SpecialChar ~
3405 \SpecialChar ~
3406 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3407 \newline 
3408
3409 \newline 
3410 Steps 'c' and 'd' are needed because bison requires by default that the
3411  files 'bison.simple' and 'bison.hairy' reside in some weird Unix directory,
3412  '/usr/local/share/' I think.
3413  So it is necessary to tell bison where those files are located if they
3414  are not in such directory.
3415  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3416 \newline 
3417
3418 \newline 
3419 e) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3420  in 'Show directories for:' select 'Executable files', and in the directories
3421  window add a new path: 'c:
3422 \backslash 
3423 util', click ok.
3424  Note that you can use any other path instead of 'c:
3425 \backslash 
3426 util', even the path where the Visual C++ tools are, probably: 'C:
3427 \backslash 
3428 Program Files
3429 \backslash 
3430 Microsoft Visual Studio
3431 \backslash 
3432 Common
3433 \backslash 
3434 Tools'.
3435  So you don't have to execute step 'e' :)
3436 \layout Standard
3437
3438 That is it.
3439  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
3440  the executables from sdcc
3441 \backslash 
3442 bin_vc to sdcc
3443 \backslash 
3444 bin, and you can compile using SDCC.
3445 \layout Subsection
3446
3447 Building SDCC Using Borland
3448 \layout Enumerate
3449
3450 From the sdcc directory, run the command "make -f Makefile.bcc".
3451  This should regenerate all the .exe files in the bin directory except for
3452  sdcdb.exe (which currently doesn't build under Borland C++).
3453 \layout Enumerate
3454
3455 If you modify any source files and need to rebuild, be aware that the dependenci
3456 es may not be correctly calculated.
3457  The safest option is to delete all .obj files and run the build again.
3458  From a Cygwin BASH prompt, this can easily be done with the command (be
3459  sure you are in the sdcc directory):
3460 \newline 
3461
3462 \newline 
3463
3464 \family sans 
3465 \series bold 
3466 find .
3467  
3468 \backslash 
3469 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
3470 \backslash 
3471 ) -print -exec rm {} 
3472 \backslash 
3473 ;
3474 \family default 
3475 \series default 
3476
3477 \newline 
3478
3479 \newline 
3480 or on Windows NT/2000/XP from the command prompt with the command:
3481 \newline 
3482
3483 \family sans 
3484 \series bold 
3485
3486 \newline 
3487 del /s *.obj *.lib *.rul
3488 \family default 
3489 \series default 
3490  from the sdcc directory.
3491 \layout Subsection
3492
3493 Windows Install Using a ZIP Package
3494 \layout Enumerate
3495
3496 Download the binary zip package from 
3497 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
3498
3499 \end_inset 
3500
3501  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
3502  This should unpack to a group of sub-directories.
3503  An example directory structure after unpacking the mingw32 package is:
3504  c:
3505 \backslash 
3506 sdcc
3507 \backslash 
3508 bin for the executables, c:
3509 \backslash 
3510 sdcc
3511 \backslash 
3512 include and c:
3513 \backslash 
3514 sdcc
3515 \backslash 
3516 lib for the include and libraries.
3517 \layout Enumerate
3518
3519 Adjust your environment variable PATH to include the location of the bin
3520  directory or start sdcc using the full path.
3521 \layout Subsection
3522
3523 Windows Install Using the Setup Program
3524 \begin_inset LatexCommand \label{sub:Windows-Install}
3525
3526 \end_inset 
3527
3528
3529 \layout Standard
3530
3531 Download the setup program 
3532 \emph on 
3533 sdcc-x.y.z-setup.exe
3534 \emph default 
3535  for an official release from 
3536 \newline 
3537
3538 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
3539
3540 \end_inset 
3541
3542  or a setup program for one of the snapshots 
3543 \emph on 
3544 sdcc_yyyymmdd_setup.exe
3545 \emph default 
3546  from 
3547 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
3548
3549 \end_inset 
3550
3551  and execute it.
3552  A windows typical installer will guide you through the installation process.
3553 \layout Section
3554
3555 Building the Documentation
3556 \layout Standard
3557
3558 If the necessary tools (LyX, LaTeX, LaTeX2HTML) are installed it is as easy
3559  as changing into the doc directory and typing 
3560 \family sans 
3561 \series bold 
3562
3563 \begin_inset Quotes srd
3564 \end_inset 
3565
3566 make
3567 \begin_inset Quotes srd
3568 \end_inset 
3569
3570
3571 \family default 
3572 \series default 
3573  there.
3574  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
3575 x).
3576  Using LyX 
3577 \begin_inset LatexCommand \url{http://www.lyx.org}
3578
3579 \end_inset 
3580
3581  as editor this is straightforward.
3582  Prebuilt documentation in html and pdf format is available from 
3583 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
3584
3585 \end_inset 
3586
3587 .
3588 \layout Section
3589
3590 Reading the Documentation
3591 \layout Standard
3592
3593 Currently reading the document in pdf format is recommended, as for unknown
3594  reason the hyperlinks are working there whereas in the html version they
3595  are not
3596 \begin_inset Foot
3597 collapsed false
3598
3599 \layout Standard
3600
3601 If you should know why please drop us a note
3602 \end_inset 
3603
3604 .
3605  
3606 \newline 
3607 You'll find the pdf version
3608 \begin_inset LatexCommand \index{PDF version of this document}
3609
3610 \end_inset 
3611
3612  at 
3613 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
3614
3615 \end_inset 
3616
3617 .
3618  
3619 \newline 
3620 A html version
3621 \begin_inset LatexCommand \index{HTML version of this document}
3622
3623 \end_inset 
3624
3625  should be online at 
3626 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
3627
3628 \end_inset 
3629
3630 .
3631 \newline 
3632 This documentation is in some aspects different from a commercial documentation:
3633  
3634 \layout Itemize
3635
3636 It tries to document SDCC for several processor architectures in one document
3637  (commercially these probably would be separate documents/products).
3638  This document
3639 \begin_inset LatexCommand \index{Status of documentation}
3640
3641 \end_inset 
3642
3643  currently matches SDCC for mcs51 and DS390 best and does give too few informati
3644 on about f.e.
3645  Z80, PIC14, PIC16 and HC08.
3646 \layout Itemize
3647
3648 There are many references pointing away from this documentation.
3649  Don't let this distract you.
3650  If there f.e.
3651  was a reference like 
3652 \begin_inset LatexCommand \url{http://www.opencores.org}
3653
3654 \end_inset 
3655
3656  together with a statement 
3657 \begin_inset Quotes sld
3658 \end_inset 
3659
3660 some processors which are targetted by SDCC can be implemented in a 
3661 \emph on 
3662 f
3663 \emph default 
3664 ield 
3665 \emph on 
3666 p
3667 \emph default 
3668 rogrammable 
3669 \emph on 
3670 g
3671 \emph default 
3672 ate 
3673 \emph on 
3674 a
3675 \emph default 
3676 rray
3677 \begin_inset LatexCommand \index{fpga (field programmable gate array)}
3678
3679 \end_inset 
3680
3681
3682 \begin_inset Quotes srd
3683 \end_inset 
3684
3685  we expect you to have a quick look there and come back.
3686  If you read this you are on the right track.
3687 \layout Itemize
3688
3689 Some sections attribute more space to problems, restrictions and warnings
3690  than to the solution.
3691 \layout Itemize
3692
3693 The installation section and the section about the debugger is intimidating.
3694 \layout Itemize
3695
3696 There are still lots of typos and there are more different writing styles
3697  than pictures.
3698 \layout Section
3699
3700 Testing the SDCC Compiler
3701 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
3702
3703 \end_inset 
3704
3705
3706 \layout Standard
3707
3708 The first thing you should do after installing your SDCC compiler is to
3709  see if it runs.
3710  Type 
3711 \family sans 
3712 \series bold 
3713 "sdcc -
3714 \begin_inset ERT
3715 status Collapsed
3716
3717 \layout Standard
3718
3719 \backslash 
3720 /
3721 \end_inset 
3722
3723 -version"
3724 \begin_inset LatexCommand \index{version}
3725
3726 \end_inset 
3727
3728
3729 \family default 
3730 \series default 
3731  at the prompt, and the program should run and tell you the version.
3732  If it doesn't run, or gives a message about not finding sdcc program, then
3733  you need to check over your installation.
3734  Make sure that the sdcc bin directory is in your executable search path
3735  defined by the PATH environment setting (
3736 \series medium 
3737 see 
3738 \series default 
3739 section 
3740 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3741
3742 \end_inset 
3743
3744 \SpecialChar ~
3745
3746 \series medium 
3747 Install trouble-shooting for suggestions
3748 \series default 
3749 ).
3750  Make sure that the sdcc program is in the bin folder, if not perhaps something
3751  did not install correctly.
3752 \newline 
3753
3754 \newline 
3755
3756 \series medium 
3757 SDCC 
3758 \series default 
3759 is commonly installed as described in section 
3760 \begin_inset Quotes sld
3761 \end_inset 
3762
3763 Install and search paths
3764 \begin_inset Quotes srd
3765 \end_inset 
3766
3767 .
3768 \newline 
3769
3770 \newline 
3771
3772 \series medium 
3773 Make sure the compiler works on a very simple example.
3774  Type in the following test.c program using your favorite 
3775 \series default 
3776 ASCII 
3777 \series medium 
3778 editor:
3779 \layout Verse
3780
3781
3782 \family typewriter 
3783 char test;
3784 \newline 
3785
3786 \newline 
3787 void main(void) {
3788 \newline 
3789 \SpecialChar ~
3790 \SpecialChar ~
3791 \SpecialChar ~
3792 \SpecialChar ~
3793 test=0;
3794 \newline 
3795 }
3796 \layout Standard
3797
3798
3799 \series medium 
3800 Compile this using the following command: 
3801 \family sans 
3802 \series bold 
3803 "sdcc -c test.c".
3804
3805 \family default 
3806 \series default 
3807  
3808 \series medium 
3809 If all goes well, the compiler will generate a test.asm and test.rel file.
3810  Congratulations, you've just compiled your first program with SDCC.
3811  We used the -c option to tell SDCC not to link the generated code, just
3812  to keep things simple for this step.
3813 \series default 
3814
3815 \newline 
3816
3817 \newline 
3818
3819 \series medium 
3820 The next step is to try it with the linker.
3821  Type in 
3822 \family sans 
3823 \series bold 
3824 "sdcc test.c
3825 \family default 
3826 \series default 
3827 "
3828 \series medium 
3829 .
3830  If all goes well the compiler will link with the libraries and produce
3831  a test.ihx output file.
3832  If this step fails
3833 \series default 
3834  
3835 \series medium 
3836 (no test.ihx, and the linker generates warnings), then the problem is most
3837  likely that 
3838 \series default 
3839 SDCC
3840 \series medium 
3841  cannot find the 
3842 \series default 
3843 /
3844 \series medium 
3845 usr/local/share/sdcc/lib directory
3846 \series default 
3847  
3848 \series medium 
3849 (see 
3850 \series default 
3851 section 
3852 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3853
3854 \end_inset 
3855
3856 \SpecialChar ~
3857
3858 \series medium 
3859 Install trouble-shooting for suggestions).
3860 \series default 
3861
3862 \newline 
3863
3864 \newline 
3865
3866 \series medium 
3867 The final test is to ensure 
3868 \series default 
3869 SDCC
3870 \series medium 
3871  can use the 
3872 \series default 
3873 standard
3874 \series medium 
3875  header files and libraries.
3876  Edit test.c and change it to the following:
3877 \layout Verse
3878
3879
3880 \family typewriter 
3881 #include <string.h>
3882 \newline 
3883
3884 \newline 
3885 char str1[10];
3886 \newline 
3887
3888 \newline 
3889 void main(void) {
3890 \newline 
3891 \SpecialChar ~
3892 \SpecialChar ~
3893 strcpy(str1, "testing");
3894 \newline 
3895 }
3896 \layout Standard
3897
3898
3899 \series medium 
3900 Compile this by typing 
3901 \family sans 
3902 \series bold 
3903 "sdcc test.c"
3904 \family default 
3905 \series medium 
3906 .
3907  This should generate a test.ihx output file, and it should give no warnings
3908  such as not finding the string.h file.
3909  If it cannot find the string.h file, then the problem is that 
3910 \series default 
3911 SDCC
3912 \series medium 
3913  cannot find the /usr/local/share/sdcc/include directory
3914 \series default 
3915  
3916 \series medium 
3917 (see the 
3918 \series default 
3919 section 
3920 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3921
3922 \end_inset 
3923
3924 \SpecialChar ~
3925
3926 \series medium 
3927 Install trouble-shooting section for suggestions).
3928
3929 \series default 
3930  Use option 
3931 \series bold 
3932 -
3933 \begin_inset ERT
3934 status Collapsed
3935
3936 \layout Standard
3937
3938 \backslash 
3939 /
3940 \end_inset 
3941
3942 -print-search-dirs
3943 \series default 
3944
3945 \begin_inset LatexCommand \index{-\/-print-search-dirs}
3946
3947 \end_inset 
3948
3949  to find exactly where SDCC is looking for the include and lib files.
3950 \layout Section
3951
3952 Install Trouble-shooting
3953 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
3954
3955 \end_inset 
3956
3957
3958 \begin_inset LatexCommand \index{Install trouble-shooting}
3959
3960 \end_inset 
3961
3962
3963 \layout Subsection
3964
3965 If SDCC does not build correctly
3966 \layout Standard
3967
3968 A thing to try is starting from scratch by unpacking the .tgz source package
3969  again in an empty directory.
3970  Configure it like:
3971 \newline 
3972
3973 \newline 
3974
3975 \family sans 
3976 \series bold 
3977 ./configure 2>&1 | tee configure.log
3978 \family default 
3979 \series default 
3980
3981 \newline 
3982
3983 \newline 
3984 and build it like:
3985 \newline 
3986
3987 \newline 
3988
3989 \family sans 
3990 \series bold 
3991 make 2>&1 | tee make.log
3992 \family default 
3993 \series default 
3994
3995 \newline 
3996
3997 \newline 
3998 If anything goes wrong, you can review the log files to locate the problem.
3999  Or a relevant part of this can be attached to an email that could be helpful
4000  when requesting help from the mailing list.
4001 \layout Subsection
4002
4003 What the 
4004 \begin_inset Quotes sld
4005 \end_inset 
4006
4007 ./configure
4008 \begin_inset Quotes srd
4009 \end_inset 
4010
4011  does
4012 \layout Standard
4013
4014 The 
4015 \begin_inset Quotes sld
4016 \end_inset 
4017
4018 ./configure
4019 \begin_inset Quotes srd
4020 \end_inset 
4021
4022  command is a script that analyzes your system and performs some configuration
4023  to ensure the source package compiles on your system.
4024  It will take a few minutes to run, and will compile a few tests to determine
4025  what compiler features are installed.
4026 \layout Subsection
4027
4028 What the 
4029 \begin_inset Quotes sld
4030 \end_inset 
4031
4032 make
4033 \begin_inset Quotes srd
4034 \end_inset 
4035
4036  does
4037 \layout Standard
4038
4039 This runs the GNU make tool, which automatically compiles all the source
4040  packages into the final installed binary executables.
4041 \layout Subsection
4042
4043 What the 
4044 \begin_inset Quotes sld
4045 \end_inset 
4046
4047 make install
4048 \begin_inset Quotes erd
4049 \end_inset 
4050
4051  command does.
4052 \layout Standard
4053
4054 This will install the compiler, other executables libraries and include
4055  files into the appropriate directories.
4056  See sections 
4057 \begin_inset LatexCommand \ref{sub:Install-paths}
4058
4059 \end_inset 
4060
4061 ,\SpecialChar ~
4062
4063 \begin_inset LatexCommand \ref{sub:Search-Paths}
4064
4065 \end_inset 
4066
4067 \SpecialChar ~
4068 about install and search paths.
4069 \newline 
4070 On most systems you will need super-user privileges to do this.
4071 \layout Section
4072
4073 Components of SDCC
4074 \layout Standard
4075
4076 SDCC is not just a compiler, but a collection of tools by various developers.
4077  These include linkers, assemblers, simulators and other components.
4078  Here is a summary of some of the components.
4079  Note that the included simulator and assembler have separate documentation
4080  which you can find in the source package in their respective directories.
4081  As SDCC grows to include support for other processors, other packages from
4082  various developers are included and may have their own sets of documentation.
4083 \newline 
4084
4085 \newline 
4086 You might want to look at the files which are installed in <installdir>.
4087  At the time of this writing, we find the following programs for gcc-builds:
4088 \newline 
4089  
4090 \newline 
4091 In <installdir>/bin:
4092 \layout Itemize
4093
4094 sdcc - The compiler.
4095 \layout Itemize
4096
4097 sdcpp - The C preprocessor.
4098 \layout Itemize
4099
4100 asx8051 - The assembler for 8051 type processors.
4101 \layout Itemize
4102
4103 as-z80
4104 \series bold 
4105
4106 \series default 
4107 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
4108 \layout Itemize
4109
4110 aslink -The linker for 8051 type processors.
4111 \layout Itemize
4112
4113 link-z80
4114 \series bold 
4115
4116 \series default 
4117 link-gbz80 - The Z80 and GameBoy Z80 linkers.
4118 \layout Itemize
4119
4120 s51 - The ucSim 8051 simulator.
4121 \layout Itemize
4122
4123 sdcdb - The source debugger.
4124 \layout Itemize
4125
4126 packihx - A tool to pack (compress) Intel hex files.
4127 \layout Standard
4128
4129 In <installdir>/share/sdcc/include
4130 \layout Itemize
4131
4132 the include files
4133 \layout Standard
4134
4135 In <installdir>/share/sdcc/lib
4136 \layout Itemize
4137
4138 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
4139  relocatables.
4140 \layout Standard
4141
4142 In <installdir>/share/sdcc/doc
4143 \layout Itemize
4144
4145 the documentation
4146 \layout Standard
4147
4148 As development for other processors proceeds, this list will expand to include
4149  executables to support processors like AVR, PIC, etc.
4150 \layout Subsection
4151
4152 sdcc - The Compiler
4153 \layout Standard
4154
4155 This is the actual compiler, it in turn uses the c-preprocessor and invokes
4156  the assembler and linkage editor.
4157 \layout Subsection
4158
4159 sdcpp - The C-Preprocessor
4160 \layout Standard
4161
4162 The preprocessor
4163 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
4164
4165 \end_inset 
4166
4167  is a modified version of the GNU preprocessor.
4168  The C preprocessor is used to pull in #include sources, process #ifdef
4169  statements, #defines and so on.
4170 \layout Subsection
4171
4172 as
4173 \emph on 
4174 xxxx
4175 \emph default 
4176 , aslink, link-
4177 \emph on 
4178 xxx
4179 \emph default 
4180  - The Assemblers and Linkage Editors
4181 \layout Standard
4182
4183 This is retargettable assembler & linkage editor, it was developed by Alan
4184  Baldwin.
4185  John Hartman created the version for 8051, and I (Sandeep) have made some
4186  enhancements and bug fixes for it to work properly with SDCC.
4187 \layout Subsection
4188
4189 s51 - The Simulator
4190 \layout Standard
4191
4192 S51
4193 \begin_inset LatexCommand \index{s51}
4194
4195 \end_inset 
4196
4197  is a freeware, opensource simulator developed by Daniel Drotos.
4198  The simulator is built as part of the build process.
4199  For more information visit Daniel's web site at: 
4200 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
4201
4202 \end_inset 
4203
4204 .
4205  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
4206  XA51 family.
4207 \layout Subsection
4208
4209 sdcdb - Source Level Debugger
4210 \layout Standard
4211
4212 Sdcdb
4213 \begin_inset LatexCommand \index{sdcdb (debugger)}
4214
4215 \end_inset 
4216
4217  is the companion source level debugger.
4218  More about sdcdb in section 
4219 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
4220
4221 \end_inset 
4222
4223 .
4224  The current version of the debugger uses Daniel's Simulator S51
4225 \begin_inset LatexCommand \index{s51}
4226
4227 \end_inset 
4228
4229 , but can be easily changed to use other simulators.
4230  
4231 \layout Chapter
4232
4233 Using SDCC
4234 \layout Section
4235
4236 Compiling
4237 \layout Subsection
4238
4239 Single Source File Projects
4240 \layout Standard
4241
4242 For single source file 8051 projects the process is very simple.
4243  Compile your programs with the following command 
4244 \family sans 
4245 \series bold 
4246 "sdcc sourcefile.c".
4247
4248 \family default 
4249 \series default 
4250  This will compile, assemble and link your source file.
4251  Output files are as follows:
4252 \layout Itemize
4253
4254 sourcefile.asm
4255 \begin_inset LatexCommand \index{<file>.asm}
4256
4257 \end_inset 
4258
4259  - Assembler source
4260 \begin_inset LatexCommand \index{Assembler source}
4261
4262 \end_inset 
4263
4264  file created by the compiler
4265 \layout Itemize
4266
4267 sourcefile.lst
4268 \begin_inset LatexCommand \index{<file>.lst}
4269
4270 \end_inset 
4271
4272  - Assembler listing
4273 \begin_inset LatexCommand \index{Assembler listing}
4274
4275 \end_inset 
4276
4277  file created by the Assembler
4278 \layout Itemize
4279
4280 sourcefile.rst
4281 \begin_inset LatexCommand \index{<file>.rst}
4282
4283 \end_inset 
4284
4285  - Assembler listing
4286 \begin_inset LatexCommand \index{Assembler listing}
4287
4288 \end_inset 
4289
4290  file updated with linkedit information, created by linkage editor
4291 \layout Itemize
4292
4293 sourcefile.sym
4294 \begin_inset LatexCommand \index{<file>.sym}
4295
4296 \end_inset 
4297
4298  - symbol listing
4299 \begin_inset LatexCommand \index{Symbol listing}
4300
4301 \end_inset 
4302
4303  for the sourcefile, created by the assembler
4304 \layout Itemize
4305
4306 sourcefile.rel
4307 \begin_inset LatexCommand \index{<file>.rel}
4308
4309 \end_inset 
4310
4311  or sourcefile.o
4312 \begin_inset LatexCommand \index{<file>.o}
4313
4314 \end_inset 
4315
4316  - Object file
4317 \begin_inset LatexCommand \index{Object file}
4318
4319 \end_inset 
4320
4321  created by the assembler, input to Linkage editor
4322 \layout Itemize
4323
4324 sourcefile.map
4325 \begin_inset LatexCommand \index{<file>.map}
4326
4327 \end_inset 
4328
4329  - The memory map
4330 \begin_inset LatexCommand \index{Memory map}
4331
4332 \end_inset 
4333
4334  for the load module, created by the Linker
4335 \layout Itemize
4336
4337 sourcefile.mem
4338 \begin_inset LatexCommand \index{<file>.mem}
4339
4340 \end_inset 
4341
4342  - A file with a summary of the memory usage
4343 \layout Itemize
4344
4345 sourcefile.ihx
4346 \begin_inset LatexCommand \index{<file>.ihx}
4347
4348 \end_inset 
4349
4350  - The load module in Intel hex format
4351 \begin_inset LatexCommand \index{Intel hex format}
4352
4353 \end_inset 
4354
4355  (you can select the Motorola S19 format
4356 \begin_inset LatexCommand \index{Motorola S19 format}
4357
4358 \end_inset 
4359
4360  with -
4361 \begin_inset ERT
4362 status Collapsed
4363
4364 \layout Standard
4365
4366 \backslash 
4367 /
4368 \end_inset 
4369
4370 -out-fmt-s19
4371 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
4372
4373 \end_inset 
4374
4375 .
4376  If you need another format you might want to use 
4377 \family sans 
4378 \shape italic 
4379 objdump
4380 \family default 
4381 \shape default 
4382
4383 \begin_inset LatexCommand \index{objdump (tool)}
4384
4385 \end_inset 
4386
4387  or
4388 \family sans 
4389 \shape italic 
4390  srecord
4391 \family default 
4392 \shape default 
4393
4394 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
4395
4396 \end_inset 
4397
4398 ).
4399  Both formats are documented in the documentation of srecord
4400 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
4401
4402 \end_inset 
4403
4404
4405 \layout Itemize
4406
4407 sourcefile.adb
4408 \begin_inset LatexCommand \index{<file>.adb}
4409
4410 \end_inset 
4411
4412  - An intermediate file containing debug information needed to create the
4413  .cdb file (with -
4414 \begin_inset ERT
4415 status Open
4416
4417 \layout Standard
4418
4419 \backslash 
4420 /
4421 \end_inset 
4422
4423 -debug
4424 \begin_inset LatexCommand \index{-\/-debug}
4425
4426 \end_inset 
4427
4428
4429 \layout Itemize
4430
4431 sourcefile.cdb
4432 \begin_inset LatexCommand \index{<file>.cdb}
4433
4434 \end_inset 
4435
4436  - An optional file (with -
4437 \begin_inset ERT
4438 status Collapsed
4439
4440 \layout Standard
4441
4442 \backslash 
4443 /
4444 \end_inset 
4445
4446 -debug) containing debug information.
4447  The format is documented in cdbfileformat.pdf
4448 \layout Itemize
4449
4450 sourcefile.
4451  - (no extension)
4452 \begin_inset LatexCommand \index{<file> (no extension)}
4453
4454 \end_inset 
4455
4456  An optional AOMF or AOMF51
4457 \begin_inset LatexCommand \index{AOMF, AOMF51}
4458
4459 \end_inset 
4460
4461  file containing debug information (generated with option -
4462 \begin_inset ERT
4463 status Collapsed
4464
4465 \layout Standard
4466
4467 \backslash 
4468 /
4469 \end_inset 
4470
4471 -debug).
4472  The (Intel)
4473 \emph on 
4474  a
4475 \emph default 
4476 bsolute 
4477 \emph on 
4478 o
4479 \emph default 
4480 bject 
4481 \emph on 
4482 m
4483 \emph default 
4484 odule 
4485 \emph on 
4486 f
4487 \emph default 
4488 ormat is commonly used by third party tools (debuggers
4489 \begin_inset LatexCommand \index{Debugger}
4490
4491 \end_inset 
4492
4493 , simulators, emulators)
4494 \layout Itemize
4495
4496 sourcefile.dump*
4497 \begin_inset LatexCommand \index{<file>.dump*}
4498
4499 \end_inset 
4500
4501  - Dump file to debug the compiler it self (generated with option -
4502 \begin_inset ERT
4503 status Collapsed
4504
4505 \layout Standard
4506
4507 \backslash 
4508 /
4509 \end_inset 
4510
4511 -dumpall) (see section 
4512 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
4513
4514 \end_inset 
4515
4516 \SpecialChar ~
4517  and section 
4518 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
4519
4520 \end_inset 
4521
4522 \SpecialChar ~
4523
4524 \begin_inset Quotes sld
4525 \end_inset 
4526
4527 Anatomy of the compiler
4528 \begin_inset Quotes srd
4529 \end_inset 
4530
4531 ).
4532 \layout Subsection
4533
4534 Projects with Multiple Source Files
4535 \layout Standard
4536
4537 SDCC can compile only ONE file at a time.
4538  Let us for example assume that you have a project containing the following
4539  files:
4540 \newline 
4541
4542 \newline 
4543 foo1.c (contains some functions)
4544 \newline 
4545 foo2.c (contains some more functions)
4546 \newline 
4547 foomain.c (contains more functions and the function main)
4548 \newline 
4549
4550 \size footnotesize 
4551
4552 \newline 
4553
4554 \size default 
4555 The first two files will need to be compiled separately with the commands:
4556 \size footnotesize 
4557  
4558 \size default 
4559
4560 \newline 
4561
4562 \newline 
4563
4564 \family sans 
4565 \series bold 
4566 sdcc\SpecialChar ~
4567 -c\SpecialChar ~
4568 foo1.c
4569 \family default 
4570 \series default 
4571 \size footnotesize 
4572
4573 \newline 
4574
4575 \family sans 
4576 \series bold 
4577 \size default 
4578 sdcc\SpecialChar ~
4579 -c\SpecialChar ~
4580 foo2.c
4581 \family default 
4582 \series default 
4583
4584 \newline 
4585
4586 \newline 
4587 Then compile the source file containing the 
4588 \emph on 
4589 main()
4590 \emph default 
4591  function and link
4592 \begin_inset LatexCommand \index{Linker}
4593
4594 \end_inset 
4595
4596  the files together with the following command: 
4597 \newline 
4598
4599 \newline 
4600
4601 \family sans 
4602 \series bold 
4603 sdcc\SpecialChar ~
4604 foomain.c\SpecialChar ~
4605 foo1.rel\SpecialChar ~
4606 foo2.rel
4607 \family default 
4608 \series default 
4609
4610 \begin_inset LatexCommand \index{<file>.rel}
4611
4612 \end_inset 
4613
4614
4615 \newline 
4616
4617 \newline 
4618 Alternatively, 
4619 \emph on 
4620 foomain.c 
4621 \emph default 
4622 can be separately compiled as well: 
4623 \family sans 
4624 \series bold 
4625
4626 \newline 
4627
4628 \newline 
4629 sdcc\SpecialChar ~
4630 -c\SpecialChar ~
4631 foomain.c
4632 \newline 
4633 sdcc foomain.rel foo1.rel foo2.rel
4634 \newline 
4635
4636 \newline 
4637
4638 \family default 
4639 \series default 
4640 The file containing the 
4641 \emph on 
4642 main()
4643 \emph default 
4644  function
4645 \emph on 
4646  
4647 \emph default 
4648 \noun on 
4649 must
4650 \noun default 
4651  be the 
4652 \noun on 
4653 first
4654 \noun default 
4655  file specified in the command line, since the linkage editor processes
4656  file in the order they are presented to it.
4657  The linker is invoked from SDCC using a script file with extension .lnk
4658 \begin_inset LatexCommand \index{<file>.lnk}
4659
4660 \end_inset 
4661
4662 .
4663  You can view this file to troubleshoot linking problems such as those arising
4664  from missing libraries.
4665 \layout Subsection
4666
4667 Projects with Additional Libraries
4668 \begin_inset LatexCommand \index{Libraries}
4669
4670 \end_inset 
4671
4672
4673 \layout Standard
4674
4675 Some reusable routines may be compiled into a library, see the documentation
4676  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
4677  for how to create a 
4678 \emph on 
4679 .lib
4680 \begin_inset LatexCommand \index{<file>.lib}
4681
4682 \end_inset 
4683
4684
4685 \emph default 
4686  library file.
4687  Libraries created in this manner can be included in the command line.
4688  Make sure you include the -L <library-path> option to tell the linker where
4689  to look for these files if they are not in the current directory.
4690  Here is an example, assuming you have the source file 
4691 \emph on 
4692 foomain.c
4693 \emph default 
4694  and a library
4695 \emph on 
4696  foolib.lib
4697 \emph default 
4698  in the directory 
4699 \emph on 
4700 mylib
4701 \emph default 
4702  (if that is not the same as your current project):
4703 \newline 
4704
4705 \newline 
4706
4707 \family sans 
4708 \series bold 
4709 sdcc foomain.c foolib.lib -L mylib
4710 \newline 
4711
4712 \newline 
4713
4714 \family default 
4715 \series default 
4716 Note here that
4717 \emph on 
4718  mylib
4719 \emph default 
4720  must be an absolute path name.
4721 \newline 
4722
4723 \newline 
4724 The most efficient way to use libraries is to keep separate modules in separate
4725  source files.
4726  The lib file now should name all the modules.rel
4727 \begin_inset LatexCommand \index{<file>.rel}
4728
4729 \end_inset 
4730
4731  files.
4732  For an example see the standard library file 
4733 \emph on 
4734 libsdcc.lib
4735 \emph default 
4736  in the directory <installdir>/share/lib/small.
4737 \layout Subsection
4738
4739 Using sdcclib to Create and Manage Libraries
4740 \begin_inset LatexCommand \index{sdcclib}
4741
4742 \end_inset 
4743
4744
4745 \layout Standard
4746
4747 Alternatively, instead of having a .rel file for each entry on the library
4748  file as described in the preceding section, sdcclib can be used to embed
4749  all the modules belonging to such library in the library file itself.
4750  This results in a larger library file, but it greatly reduces the number
4751  of disk files accessed by the linker.
4752   Additionally, the packed library file contains an index of all include
4753  modules and symbols that significantly speeds up the linking process.
4754  To display a list of options supported by sdcclib type:
4755 \newline 
4756
4757 \layout Standard
4758
4759
4760 \family sans 
4761 \series bold 
4762 sdcclib -?
4763 \begin_inset LatexCommand \index{sdcclib}
4764
4765 \end_inset 
4766
4767
4768 \newline 
4769
4770 \newline 
4771
4772 \family default 
4773 \series default 
4774 To create a new library file, start by compiling all the required modules.
4775  For example:
4776 \newline 
4777
4778 \layout Standard
4779
4780
4781 \family sans 
4782 \series bold 
4783 sdcc -c _divsint.c
4784 \layout Standard
4785
4786
4787 \family sans 
4788 \series bold 
4789 sdcc -c _divuint.c
4790 \layout Standard
4791
4792
4793 \family sans 
4794 \series bold 
4795 sdcc -c _modsint.c
4796 \layout Standard
4797
4798
4799 \family sans 
4800 \series bold 
4801 sdcc -c _moduint.c
4802 \layout Standard
4803
4804
4805 \family sans 
4806 \series bold 
4807 sdcc -c _mulint.c
4808 \newline 
4809
4810 \layout Standard
4811
4812 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
4813  and _mulint.rel.
4814  The next step is to add the .rel files to the library file:
4815 \newline 
4816
4817 \layout Standard
4818
4819
4820 \family sans 
4821 \series bold 
4822 sdcclib libint.lib _divsint.rel
4823 \family default 
4824
4825 \begin_inset LatexCommand \index{sdcclib}
4826
4827 \end_inset 
4828
4829
4830 \layout Standard
4831
4832
4833 \family sans 
4834 \series bold 
4835 sdcclib libint.lib _divuint.rel
4836 \layout Standard
4837
4838
4839 \family sans 
4840 \series bold 
4841 sdcclib libint.lib _modsint.rel
4842 \layout Standard
4843
4844
4845 \family sans 
4846 \series bold 
4847 sdcclib libint.lib _moduint.rel
4848 \layout Standard
4849
4850
4851 \family sans 
4852 \series bold 
4853 sdcclib libint.lib _mulint.rel
4854 \series default 
4855
4856 \newline 
4857
4858 \layout Standard
4859
4860 If the file already exists in the library, it will be replaced.
4861  To see what modules and symbols are included in the library, options -s
4862  and -m are available.
4863  For example:
4864 \newline 
4865
4866 \newline 
4867
4868 \family sans 
4869 \series bold 
4870 sdcclib -s libint.lib
4871 \family default 
4872
4873 \begin_inset LatexCommand \index{sdcclib}
4874
4875 \end_inset 
4876
4877
4878 \newline 
4879
4880 \family typewriter 
4881 \series default 
4882 _divsint.rel:
4883 \layout Standard
4884
4885
4886 \family typewriter 
4887 __divsint_a_1_1
4888 \layout Standard
4889
4890
4891 \family typewriter 
4892 __divsint_PARM_2
4893 \layout Standard
4894
4895
4896 \family typewriter 
4897 __divsint
4898 \newline 
4899 _divuint.rel:
4900 \layout Standard
4901
4902
4903 \family typewriter 
4904 __divuint_a_1_1
4905 \layout Standard
4906
4907
4908 \family typewriter 
4909 __divuint_PARM_2
4910 \layout Standard
4911
4912
4913 \family typewriter 
4914 __divuint_reste_1_1
4915 \layout Standard
4916
4917
4918 \family typewriter 
4919 __divuint_count_1_1
4920 \layout Standard
4921
4922
4923 \family typewriter 
4924 __divuint
4925 \newline 
4926 _modsint.rel:
4927 \layout Standard
4928
4929
4930 \family typewriter 
4931 __modsint_a_1_1
4932 \layout Standard
4933
4934
4935 \family typewriter 
4936 __modsint_PARM_2
4937 \layout Standard
4938
4939
4940 \family typewriter 
4941 __modsint
4942 \newline 
4943 _moduint.rel:
4944 \layout Standard
4945
4946
4947 \family typewriter 
4948 __moduint_a_1_1
4949 \layout Standard
4950
4951
4952 \family typewriter 
4953 __moduint_PARM_2
4954 \layout Standard
4955
4956
4957 \family typewriter 
4958 __moduint_count_1_1
4959 \layout Standard
4960
4961
4962 \family typewriter 
4963 __moduint
4964 \newline 
4965 _mulint.rel:
4966 \layout Standard
4967
4968
4969 \family typewriter 
4970 __mulint_PARM_2
4971 \layout Standard
4972
4973
4974 \family typewriter 
4975 __mulint
4976 \family default 
4977 \series bold 
4978
4979 \newline 
4980
4981 \layout Standard
4982
4983 If the source files are compiled using -
4984 \begin_inset ERT
4985 status Open
4986
4987 \layout Standard
4988
4989 \backslash 
4990 /
4991 \end_inset 
4992
4993 -debug
4994 \begin_inset LatexCommand \index{-\/-debug}
4995
4996 \end_inset 
4997
4998 , the corresponding debug information file .adb will be include in the library
4999  file as well.
5000  The library files created with sdcclib are plain text files, so they can
5001  be viewed with a text editor.
5002  It is not recomended to modify a library file created with sdcclib using
5003  a text editor, as there are file indexes numbers located accross the file
5004  used by the linker to quickly locate the required module to link.
5005  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
5006  it can be safely deleted, since all the information required for linking
5007  is embedded in the library file itself.
5008  Library files created using sdcclib are used as described in the preceding
5009  sections.
5010 \layout Section
5011
5012 Command Line Options
5013 \begin_inset LatexCommand \index{Command Line Options}
5014
5015 \end_inset 
5016
5017
5018 \layout Subsection
5019
5020 Processor Selection Options
5021 \begin_inset LatexCommand \index{Options processor selection}
5022
5023 \end_inset 
5024
5025
5026 \begin_inset LatexCommand \index{Processor selection options}
5027
5028 \end_inset 
5029
5030
5031 \layout List
5032 \labelwidthstring 00.00.0000
5033
5034
5035 \series bold 
5036 -mmcs51
5037 \begin_inset LatexCommand \index{-mmcs51}
5038
5039 \end_inset 
5040
5041
5042 \series default 
5043  Generate code for the Intel MCS51
5044 \begin_inset LatexCommand \index{MCS51}
5045
5046 \end_inset 
5047
5048  family of processors.
5049  This is the default processor target.
5050 \layout List
5051 \labelwidthstring 00.00.0000
5052
5053
5054 \series bold 
5055 -mds390
5056 \begin_inset LatexCommand \index{-mds390}
5057
5058 \end_inset 
5059
5060
5061 \series default 
5062  Generate code for the Dallas DS80C390
5063 \begin_inset LatexCommand \index{DS80C390}
5064
5065 \end_inset 
5066
5067  processor.
5068 \layout List
5069 \labelwidthstring 00.00.0000
5070
5071
5072 \series bold 
5073 -mds400
5074 \begin_inset LatexCommand \index{-mds400}
5075
5076 \end_inset 
5077
5078
5079 \series default 
5080  Generate code for the Dallas DS80C400
5081 \begin_inset LatexCommand \index{DS80C400}
5082
5083 \end_inset 
5084
5085  processor.
5086 \layout List
5087 \labelwidthstring 00.00.0000
5088
5089
5090 \series bold 
5091 -mhc08
5092 \begin_inset LatexCommand \index{-mhc08}
5093
5094 \end_inset 
5095
5096
5097 \series default 
5098  Generate code for the Freescale/Motorola HC08
5099 \begin_inset LatexCommand \index{HC08}
5100
5101 \end_inset 
5102
5103  family of processors.
5104 \layout List
5105 \labelwidthstring 00.00.0000
5106
5107
5108 \series bold 
5109 -mz80
5110 \begin_inset LatexCommand \index{-mz80}
5111
5112 \end_inset 
5113
5114
5115 \series default 
5116  Generate code for the Zilog Z80
5117 \begin_inset LatexCommand \index{Z80}
5118
5119 \end_inset 
5120
5121  family of processors.
5122 \layout List
5123 \labelwidthstring 00.00.0000
5124
5125
5126 \series bold 
5127 -mgbz80
5128 \begin_inset LatexCommand \index{-mgbz80}
5129
5130 \end_inset 
5131
5132
5133 \series default 
5134  Generate code for the GameBoy Z80
5135 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
5136
5137 \end_inset 
5138
5139  processor (Not actively maintained).
5140 \layout List
5141 \labelwidthstring 00.00.0000
5142
5143
5144 \series bold 
5145 -mavr
5146 \begin_inset LatexCommand \index{-mavr}
5147
5148 \end_inset 
5149
5150
5151 \series default 
5152  Generate code for the Atmel AVR
5153 \begin_inset LatexCommand \index{AVR}
5154
5155 \end_inset 
5156
5157  processor (In development, not complete).
5158  AVR users should probably have a look at winavr 
5159 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
5160
5161 \end_inset 
5162
5163  or 
5164 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
5165
5166 \end_inset 
5167
5168 .
5169 \layout Comment
5170
5171 I think it is fair to direct users there for now.
5172  Open source is also about avoiding unnecessary work .
5173  But I didn't find the 'official' link.
5174 \layout List
5175 \labelwidthstring 00.00.0000
5176
5177
5178 \series bold 
5179 -mpic14
5180 \begin_inset LatexCommand \index{-mpic14}
5181
5182 \end_inset 
5183
5184
5185 \series default 
5186  Generate code for the Microchip PIC 14
5187 \begin_inset LatexCommand \index{PIC14}
5188
5189 \end_inset 
5190
5191 -bit processors (p16f84 and variants.
5192  In development, not complete).
5193 \layout Comment
5194
5195 p16f627 p16f628 p16f84 p16f873 p16f877?
5196 \layout List
5197 \labelwidthstring 00.00.0000
5198
5199
5200 \series bold 
5201 -mpic16
5202 \begin_inset LatexCommand \index{-mpic16}
5203
5204 \end_inset 
5205
5206
5207 \series default 
5208  Generate code for the Microchip PIC 16
5209 \begin_inset LatexCommand \index{PIC16}
5210
5211 \end_inset 
5212
5213 -bit processors (p18f452 and variants.
5214  In development, not complete).
5215 \layout List
5216 \labelwidthstring 00.00.0000
5217
5218
5219 \series bold 
5220 -mtlcs900h
5221 \series default 
5222  Generate code for the Toshiba TLCS-900H
5223 \begin_inset LatexCommand \index{TLCS-900H}
5224
5225 \end_inset 
5226
5227  processor (Not maintained, not complete).
5228 \layout List
5229 \labelwidthstring 00.00.0000
5230
5231
5232 \series bold 
5233 -mxa51
5234 \begin_inset LatexCommand \index{-mxa51}
5235
5236 \end_inset 
5237
5238
5239 \series default 
5240  Generate code for the Phillips XA51
5241 \begin_inset LatexCommand \index{XA51}
5242
5243 \end_inset 
5244
5245  processor (Not maintained, not complete).
5246 \layout Subsection
5247
5248 Preprocessor Options
5249 \begin_inset LatexCommand \index{Options preprocessor}
5250
5251 \end_inset 
5252
5253
5254 \begin_inset LatexCommand \index{Preprocessor options}
5255
5256 \end_inset 
5257
5258
5259 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5260
5261 \end_inset 
5262
5263
5264 \layout List
5265 \labelwidthstring 00.00.0000
5266
5267
5268 \series bold 
5269 -I<path>
5270 \begin_inset LatexCommand \index{-I<path>}
5271
5272 \end_inset 
5273
5274
5275 \series default 
5276  The additional location where the pre processor will look for <..h> or 
5277 \begin_inset Quotes eld
5278 \end_inset 
5279
5280 ..h
5281 \begin_inset Quotes erd
5282 \end_inset 
5283
5284  files.
5285 \layout List
5286 \labelwidthstring 00.00.0000
5287
5288
5289 \series bold 
5290 -D<macro[=value]>
5291 \begin_inset LatexCommand \index{-D<macro[=value]>}
5292
5293 \end_inset 
5294
5295
5296 \series default 
5297  Command line definition of macros.
5298  Passed to the preprocessor.
5299 \layout List
5300 \labelwidthstring 00.00.0000
5301
5302
5303 \series bold 
5304 -M
5305 \begin_inset LatexCommand \index{-M}
5306
5307 \end_inset 
5308
5309
5310 \series default 
5311  Tell the preprocessor to output a rule suitable for make describing the
5312  dependencies of each object file.
5313  For each source file, the preprocessor outputs one make-rule whose target
5314  is the object file name for that source file and whose dependencies are
5315  all the files `#include'd in it.
5316  This rule may be a single line or may be continued with `
5317 \backslash 
5318 '-newline if it is long.
5319  The list of rules is printed on standard output instead of the preprocessed
5320  C program.
5321  `-M' implies `-E
5322 \begin_inset LatexCommand \index{-E}
5323
5324 \end_inset 
5325
5326 '.
5327 \layout List
5328 \labelwidthstring 00.00.0000
5329
5330
5331 \series bold 
5332 -C
5333 \begin_inset LatexCommand \index{-C}
5334
5335 \end_inset 
5336
5337
5338 \series default 
5339  Tell the preprocessor not to discard comments.
5340  Used with the `-E' option.
5341 \layout List
5342 \labelwidthstring 00.00.0000
5343
5344
5345 \series bold 
5346 -MM
5347 \begin_inset LatexCommand \index{-MM}
5348
5349 \end_inset 
5350
5351
5352 \size large 
5353 \bar under 
5354  
5355 \series default 
5356 \size default 
5357 \bar default 
5358 Like `-M' but the output mentions only the user header files included with
5359  `#include 
5360 \begin_inset Quotes eld
5361 \end_inset 
5362
5363 file"'.
5364  System header files included with `#include <file>' are omitted.
5365 \layout List
5366 \labelwidthstring 00.00.0000
5367
5368
5369 \series bold 
5370 -Aquestion(answer)
5371 \begin_inset LatexCommand \index{-Aquestion(answer)}
5372
5373 \end_inset 
5374
5375
5376 \series default 
5377  Assert the answer answer for question, in case it is tested with a preprocessor
5378  conditional such as `#if #question(answer)'.
5379  `-A-' disables the standard assertions that normally describe the target
5380  machine.
5381 \layout List
5382 \labelwidthstring 00.00.0000
5383
5384
5385 \series bold 
5386 -Umacro
5387 \begin_inset LatexCommand \index{-Umacro}
5388
5389 \end_inset 
5390
5391
5392 \series default 
5393  Undefine macro macro.
5394  `-U' options are evaluated after all `-D' options, but before any `-include'
5395  and `-imacros' options.
5396 \layout List
5397 \labelwidthstring 00.00.0000
5398
5399
5400 \series bold 
5401 -dM
5402 \begin_inset LatexCommand \index{-dM}
5403
5404 \end_inset 
5405
5406
5407 \series default 
5408  Tell the preprocessor to output only a list of the macro definitions that
5409  are in effect at the end of preprocessing.
5410  Used with the `-E' option.
5411 \layout List
5412 \labelwidthstring 00.00.0000
5413
5414
5415 \series bold 
5416 -dD
5417 \begin_inset LatexCommand \index{-dD}
5418
5419 \end_inset 
5420
5421
5422 \series default 
5423  Tell the preprocessor to pass all macro definitions into the output, in
5424  their proper sequence in the rest of the output.
5425 \layout List
5426 \labelwidthstring 00.00.0000
5427
5428
5429 \series bold 
5430 -dN
5431 \begin_inset LatexCommand \index{-dN}
5432
5433 \end_inset 
5434
5435
5436 \size large 
5437 \bar under 
5438  
5439 \series default 
5440 \size default 
5441 \bar default 
5442 Like `-dD' except that the macro arguments and contents are omitted.
5443  Only `#define name' is included in the output.
5444 \layout List
5445 \labelwidthstring 00.00.0000
5446
5447
5448 \series bold 
5449 -Wp\SpecialChar ~
5450 preprocessorOption[,preprocessorOption]
5451 \series default 
5452
5453 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
5454
5455 \end_inset 
5456
5457 ...
5458  Pass the preprocessorOption to the preprocessor 
5459 \family typewriter 
5460 sdcpp
5461 \family default 
5462
5463 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5464
5465 \end_inset 
5466
5467 .
5468  SDCC uses an adapted version of the preprocessor cpp of the GNU Compiler
5469  Collection (gcc), if you need more dedicated options please refer to the
5470  documentation at 
5471 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
5472
5473 \end_inset 
5474
5475 .
5476 \layout Subsection
5477
5478 Linker Options
5479 \begin_inset LatexCommand \index{Options linker}
5480
5481 \end_inset 
5482
5483
5484 \begin_inset LatexCommand \index{Linker options}
5485
5486 \end_inset 
5487
5488
5489 \layout List
5490 \labelwidthstring 00.00.0000
5491
5492
5493 \series bold 
5494 -L\SpecialChar ~
5495 -
5496 \series default 
5497
5498 \begin_inset ERT
5499 status Collapsed
5500
5501 \layout Standard
5502
5503 \backslash 
5504 /
5505 \end_inset 
5506
5507
5508 \series bold 
5509 -lib-path
5510 \begin_inset LatexCommand \index{-\/-lib-path <path>}
5511
5512 \end_inset 
5513
5514
5515 \begin_inset LatexCommand \index{-L -\/-lib-path}
5516
5517 \end_inset 
5518
5519
5520 \series default 
5521 \SpecialChar ~
5522 <absolute path to additional libraries> This option is passed to the linkage
5523  editor's additional libraries
5524 \begin_inset LatexCommand \index{Libraries}
5525
5526 \end_inset 
5527
5528  search path.
5529  The path name must be absolute.
5530  Additional library files may be specified in the command line.
5531  See section Compiling programs for more details.
5532 \layout List
5533 \labelwidthstring 00.00.0000
5534
5535
5536 \series bold 
5537 -
5538 \begin_inset ERT
5539 status Collapsed
5540
5541 \layout Standard
5542
5543 \backslash 
5544 /
5545 \end_inset 
5546
5547 -xram-loc
5548 \series default 
5549
5550 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
5551
5552 \end_inset 
5553
5554 \SpecialChar ~
5555 <Value> The start location of the external ram
5556 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
5557
5558 \end_inset 
5559
5560 , default value is 0.
5561  The value entered can be in Hexadecimal or Decimal format, e.g.: -
5562 \begin_inset ERT
5563 status Collapsed
5564
5565 \layout Standard
5566
5567 \backslash 
5568 /
5569 \end_inset 
5570
5571 -xram-loc 0x8000 or -
5572 \begin_inset ERT
5573 status Collapsed
5574
5575 \layout Standard
5576
5577 \backslash 
5578 /
5579 \end_inset 
5580
5581 -xram-loc 32768.
5582 \layout List
5583 \labelwidthstring 00.00.0000
5584
5585
5586 \series bold 
5587 -
5588 \begin_inset ERT
5589 status Collapsed
5590
5591 \layout Standard
5592
5593 \backslash 
5594 /
5595 \end_inset 
5596
5597 -code-loc
5598 \series default 
5599
5600 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
5601
5602 \end_inset 
5603
5604 \SpecialChar ~
5605 <Value> The start location of the code
5606 \begin_inset LatexCommand \index{code}
5607
5608 \end_inset 
5609
5610  segment, default value 0.
5611  Note when this option is used the interrupt vector table is also relocated
5612  to the given address.
5613  The value entered can be in Hexadecimal or Decimal format, e.g.: -
5614 \begin_inset ERT
5615 status Collapsed
5616
5617 \layout Standard
5618
5619 \backslash 
5620 /
5621 \end_inset 
5622
5623 -code-loc 0x8000 or -
5624 \begin_inset ERT
5625 status Collapsed
5626
5627 \layout Standard
5628
5629 \backslash 
5630 /
5631 \end_inset 
5632
5633 -code-loc 32768.
5634 \layout List
5635 \labelwidthstring 00.00.0000
5636
5637
5638 \series bold 
5639 -
5640 \begin_inset ERT
5641 status Collapsed
5642
5643 \layout Standard
5644
5645 \backslash 
5646 /
5647 \end_inset 
5648
5649 -stack-loc
5650 \series default 
5651
5652 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
5653
5654 \end_inset 
5655
5656 \SpecialChar ~
5657 <Value> By default the stack
5658 \begin_inset LatexCommand \index{stack}
5659
5660 \end_inset 
5661
5662  is placed after the data segment.
5663  Using this option the stack can be placed anywhere in the internal memory
5664  space of the 8051.
5665  The value entered can be in Hexadecimal or Decimal format, e.g.
5666  -
5667 \begin_inset ERT
5668 status Collapsed
5669
5670 \layout Standard
5671
5672 \backslash 
5673 /
5674 \end_inset 
5675
5676 -stack-loc 0x20 or -
5677 \begin_inset ERT
5678 status Collapsed
5679
5680 \layout Standard
5681
5682 \backslash 
5683 /
5684 \end_inset 
5685
5686 -stack-loc 32.
5687  Since the sp register is incremented before a push or call, the initial
5688  sp will be set to one byte prior the provided value.
5689  The provided value should not overlap any other memory areas such as used
5690  register banks or the data segment and with enough space for the current
5691  application.
5692  The 
5693 \series bold 
5694 -
5695 \begin_inset ERT
5696 status Collapsed
5697
5698 \layout Standard
5699
5700 \backslash 
5701 /
5702 \end_inset 
5703
5704 -pack-iram
5705 \series default 
5706 \SpecialChar ~
5707
5708 \begin_inset LatexCommand \index{-\/-pack-iram}
5709
5710 \end_inset 
5711
5712  option (which is now a default setting) will override this setting, so
5713  you should also specify the 
5714 \series bold 
5715 -
5716 \begin_inset ERT
5717 status Collapsed
5718
5719 \layout Standard
5720
5721 \backslash 
5722 /
5723 \end_inset 
5724
5725 -no-pack-iram
5726 \series default 
5727 \SpecialChar ~
5728
5729 \begin_inset LatexCommand \index{-\/-no-pack-iram}
5730
5731 \end_inset 
5732
5733  option if you need to manually place the stack.
5734 \layout List
5735 \labelwidthstring 00.00.0000
5736
5737
5738 \series bold 
5739 -
5740 \begin_inset ERT
5741 status Collapsed
5742
5743 \layout Standard
5744
5745 \backslash 
5746 /
5747 \end_inset 
5748
5749 -data-loc
5750 \series default 
5751
5752 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
5753
5754 \end_inset 
5755
5756 \SpecialChar ~
5757 <Value> The start location of the internal ram data
5758 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
5759
5760 \end_inset 
5761
5762  segment.
5763  The value entered can be in Hexadecimal or Decimal format, eg.
5764  -
5765 \begin_inset ERT
5766 status Collapsed
5767
5768 \layout Standard
5769
5770 \backslash 
5771 /
5772 \end_inset 
5773
5774 -data-loc 0x20 or -
5775 \begin_inset ERT
5776 status Collapsed
5777
5778 \layout Standard
5779
5780 \backslash 
5781 /
5782 \end_inset 
5783
5784 -data-loc 32.
5785  (By default, the start location of the internal ram data segment  is set
5786  as low as possible in memory, taking into account the used register banks
5787  and the bit segment at address 0x20.
5788  For example if register banks 0 and 1 are used without bit variables, the
5789  data segment will be set, if -
5790 \begin_inset ERT
5791 status Collapsed
5792
5793 \layout Standard
5794
5795 \backslash 
5796 /
5797 \end_inset 
5798
5799 -data-loc is not used, to location 0x10.)
5800 \layout List
5801 \labelwidthstring 00.00.0000
5802
5803
5804 \series bold 
5805 -
5806 \begin_inset ERT
5807 status Collapsed
5808
5809 \layout Standard
5810
5811 \backslash 
5812 /
5813 \end_inset 
5814
5815 -idata-loc
5816 \series default 
5817
5818 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
5819
5820 \end_inset 
5821
5822 \SpecialChar ~
5823 <Value> The start location of the indirectly addressable internal ram
5824 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
5825
5826 \end_inset 
5827
5828  of the 8051, default value is 0x80.
5829  The value entered can be in Hexadecimal or Decimal format, eg.
5830  -
5831 \begin_inset ERT
5832 status Collapsed
5833
5834 \layout Standard
5835
5836 \backslash 
5837 /
5838 \end_inset 
5839
5840 -idata-loc 0x88 or -
5841 \begin_inset ERT
5842 status Collapsed
5843
5844 \layout Standard
5845
5846 \backslash 
5847 /
5848 \end_inset 
5849
5850 -idata-loc 136.
5851 \layout List
5852 \labelwidthstring 00.00.0000
5853
5854
5855 \series bold 
5856 -
5857 \begin_inset ERT
5858 status Collapsed
5859
5860 \layout Standard
5861
5862 \backslash 
5863 /
5864 \end_inset 
5865
5866 -bit-loc
5867 \series default 
5868 \SpecialChar ~
5869 <Value> The start location of the bit
5870 \begin_inset LatexCommand \index{bit}
5871
5872 \end_inset 
5873
5874  addressable internal ram of the 8051.
5875  This is 
5876 \emph on 
5877 not
5878 \emph default 
5879  implemented yet.
5880  Instead an option can be passed directly to the linker: -Wl\SpecialChar ~
5881 -bBSEG=<Value>.
5882 \layout List
5883 \labelwidthstring 00.00.0000
5884
5885
5886 \series bold 
5887 -
5888 \begin_inset ERT
5889 status Collapsed
5890
5891 \layout Standard
5892
5893 \backslash 
5894 /
5895 \end_inset 
5896
5897 -out-fmt-ihx
5898 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
5899
5900 \end_inset 
5901
5902
5903 \bar under 
5904  
5905 \series default 
5906 \bar default 
5907 The linker output (final object code) is in Intel Hex format.
5908 \begin_inset LatexCommand \index{Intel hex format}
5909
5910 \end_inset 
5911
5912  This is the default option.
5913  The format itself is documented in the documentation of srecord
5914 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5915
5916 \end_inset 
5917
5918 .
5919 \layout List
5920 \labelwidthstring 00.00.0000
5921
5922
5923 \series bold 
5924 -
5925 \begin_inset ERT
5926 status Collapsed
5927
5928 \layout Standard
5929
5930 \backslash 
5931 /
5932 \end_inset 
5933
5934 -out-fmt-s19
5935 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5936
5937 \end_inset 
5938
5939
5940 \bar under 
5941  
5942 \series default 
5943 \bar default 
5944 The linker output (final object code) is in Motorola S19 format
5945 \begin_inset LatexCommand \index{Motorola S19 format}
5946
5947 \end_inset 
5948
5949 .
5950  The format itself is documented in the documentation of srecord.
5951 \layout List
5952 \labelwidthstring 00.00.0000
5953
5954
5955 \series bold 
5956 -
5957 \begin_inset ERT
5958 status Collapsed
5959
5960 \layout Standard
5961
5962 \backslash 
5963 /
5964 \end_inset 
5965
5966 -out-fmt-elf
5967 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5968
5969 \end_inset 
5970
5971
5972 \bar under 
5973  
5974 \series default 
5975 \bar default 
5976 The linker output (final object code) is in ELF format
5977 \begin_inset LatexCommand \index{ELF format}
5978
5979 \end_inset 
5980
5981 .
5982  (Currently only supported for the HC08 processors)
5983 \layout List
5984 \labelwidthstring 00.00.0000
5985
5986
5987 \series bold 
5988 -Wl\SpecialChar ~
5989 linkOption[,linkOption]
5990 \series default 
5991
5992 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
5993
5994 \end_inset 
5995
5996 ...
5997  Pass the linkOption to the linker.
5998  See file sdcc/as/doc/asxhtm.html for more on linker options.
5999 \layout Subsection
6000
6001 MCS51 Options
6002 \begin_inset LatexCommand \index{Options MCS51}
6003
6004 \end_inset 
6005
6006
6007 \begin_inset LatexCommand \index{MCS51 options}
6008
6009 \end_inset 
6010
6011
6012 \layout List
6013 \labelwidthstring 00.00.0000
6014
6015
6016 \series bold 
6017 -
6018 \begin_inset ERT
6019 status Collapsed
6020
6021 \layout Standard
6022
6023 \backslash 
6024 /
6025 \end_inset 
6026
6027 -model-small
6028 \begin_inset LatexCommand \index{-\/-model-small}
6029
6030 \end_inset 
6031
6032
6033 \series default 
6034 \size large 
6035 \emph on 
6036  
6037 \size default 
6038 \emph default 
6039 Generate code for Small Model programs, see section Memory Models for more
6040  details.
6041  This is the default model.
6042 \layout List
6043 \labelwidthstring 00.00.0000
6044
6045
6046 \series bold 
6047 -
6048 \begin_inset ERT
6049 status Collapsed
6050
6051 \layout Standard
6052
6053 \backslash 
6054 /
6055 \end_inset 
6056
6057 -model-large
6058 \begin_inset LatexCommand \index{-\/-model-large}
6059
6060 \end_inset 
6061
6062
6063 \series default 
6064  Generate code for Large model programs, see section Memory Models for more
6065  details.
6066  If this option is used all source files in the project have to be compiled
6067  with this option.
6068 \layout List
6069 \labelwidthstring 00.00.0000
6070
6071
6072 \series bold 
6073 -
6074 \begin_inset ERT
6075 status Collapsed
6076
6077 \layout Standard
6078
6079 \backslash 
6080 /
6081 \end_inset 
6082
6083 -xstack
6084 \begin_inset LatexCommand \index{-\/-xstack}
6085
6086 \end_inset 
6087
6088
6089 \series default 
6090  Uses a pseudo stack in the first 256 bytes in the external ram for allocating
6091  variables and passing parameters.
6092  See section 
6093 \begin_inset LatexCommand \ref{sub:External-Stack}
6094
6095 \end_inset 
6096
6097 \SpecialChar ~
6098  External Stack for more details.
6099 \layout List
6100 \labelwidthstring 00.00.0000
6101
6102
6103 \series bold 
6104 -
6105 \begin_inset ERT
6106 status Collapsed
6107
6108 \layout Standard
6109
6110 \backslash 
6111 /
6112 \end_inset 
6113
6114 -iram-size
6115 \series default 
6116 \SpecialChar ~
6117 <Value>
6118 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
6119
6120 \end_inset 
6121
6122  Causes the linker to check if the internal ram usage is within limits of
6123  the given value.
6124 \layout List
6125 \labelwidthstring 00.00.0000
6126
6127
6128 \series bold 
6129 -
6130 \begin_inset ERT
6131 status Collapsed
6132
6133 \layout Standard
6134
6135 \backslash 
6136 /
6137 \end_inset 
6138
6139 -xram-size
6140 \series default 
6141 \SpecialChar ~
6142 <Value>
6143 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
6144
6145 \end_inset 
6146
6147  Causes the linker to check if the external ram usage is within limits of
6148  the given value.
6149 \layout List
6150 \labelwidthstring 00.00.0000
6151
6152
6153 \series bold 
6154 -
6155 \begin_inset ERT
6156 status Collapsed
6157
6158 \layout Standard
6159
6160 \backslash 
6161 /
6162 \end_inset 
6163
6164 -code-size
6165 \series default 
6166 \SpecialChar ~
6167 <Value>
6168 \begin_inset LatexCommand \index{-\/-code-size <Value>}
6169
6170 \end_inset 
6171
6172  Causes the linker to check if the code memory usage is within limits of
6173  the given value.
6174 \layout List
6175 \labelwidthstring 00.00.0000
6176
6177
6178 \series bold 
6179 -
6180 \begin_inset ERT
6181 status Collapsed
6182
6183 \layout Standard
6184
6185 \backslash 
6186 /
6187 \end_inset 
6188
6189 -stack-size
6190 \series default 
6191 \SpecialChar ~
6192 <Value>
6193 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
6194
6195 \end_inset 
6196
6197  Causes the linker to check if there is at minimum <Value> bytes for stack.
6198 \layout List
6199 \labelwidthstring 00.00.0000
6200
6201
6202 \series bold 
6203 -
6204 \begin_inset ERT
6205 status Collapsed
6206
6207 \layout Standard
6208
6209 \backslash 
6210 /
6211 \end_inset 
6212
6213 -pack-iram
6214 \series default 
6215 \SpecialChar ~
6216
6217 \begin_inset LatexCommand \index{-\/-pack-iram}
6218
6219 \end_inset 
6220
6221  Causes the linker to use unused register banks for data variables and pack
6222  data, idata and stack together.
6223  This is the default now.
6224 \layout List
6225 \labelwidthstring 00.00.0000
6226
6227
6228 \series bold 
6229 -
6230 \begin_inset ERT
6231 status Collapsed
6232
6233 \layout Standard
6234
6235 \backslash 
6236 /
6237 \end_inset 
6238
6239 -no-pack-iram
6240 \series default 
6241 \SpecialChar ~
6242
6243 \begin_inset LatexCommand \index{-\/-no-pack-iram}
6244
6245 \end_inset 
6246
6247  Causes the linker to use old style for allocating memory areas.
6248 \layout Subsection
6249
6250 DS390 / DS400 Options
6251 \begin_inset LatexCommand \index{Options DS390}
6252
6253 \end_inset 
6254
6255
6256 \begin_inset LatexCommand \index{DS390 options}
6257
6258 \end_inset 
6259
6260
6261 \layout List
6262 \labelwidthstring 00.00.0000
6263
6264
6265 \series bold 
6266 -
6267 \begin_inset ERT
6268 status Collapsed
6269
6270 \layout Standard
6271
6272 \backslash 
6273 /
6274 \end_inset 
6275
6276 -model-flat24
6277 \series default 
6278
6279 \begin_inset LatexCommand \index{-\/-model-flat24}
6280
6281 \end_inset 
6282
6283
6284 \size large 
6285 \emph on 
6286  
6287 \size default 
6288 \emph default 
6289 Generate 24-bit flat mode code.
6290  This is the one and only that the ds390 code generator supports right now
6291  and is default when using 
6292 \emph on 
6293 -mds390
6294 \emph default 
6295 .
6296  See section Memory Models for more details.
6297 \layout List
6298 \labelwidthstring 00.00.0000
6299
6300
6301 \series bold 
6302 -
6303 \begin_inset ERT
6304 status Collapsed
6305
6306 \layout Standard
6307
6308 \backslash 
6309 /
6310 \end_inset 
6311
6312 -protect-sp-update
6313 \begin_inset LatexCommand \index{-\/-protect-sp-update}
6314
6315 \end_inset 
6316
6317
6318 \series default 
6319  disable interrupts during ESP:SP updates.
6320 \layout List
6321 \labelwidthstring 00.00.0000
6322
6323
6324 \series bold 
6325 -
6326 \begin_inset ERT
6327 status Collapsed
6328
6329 \layout Standard
6330
6331 \backslash 
6332 /
6333 \end_inset 
6334
6335 -stack-10bit
6336 \series default 
6337
6338 \begin_inset LatexCommand \index{-\/-stack-10bit}
6339
6340 \end_inset 
6341
6342  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
6343  This is the one and only that the ds390 code generator supports right now
6344  and is default when using 
6345 \emph on 
6346 -mds390
6347 \emph default 
6348 .
6349  In this mode, the stack is located in the lower 1K of the internal RAM,
6350  which is mapped to 0x400000.
6351  Note that the support is incomplete, since it still uses a single byte
6352  as the stack pointer.
6353  This means that only the lower 256 bytes of the potential 1K stack space
6354  will actually be used.
6355  However, this does allow you to reclaim the precious 256 bytes of low RAM
6356  for use for the DATA and IDATA segments.
6357  The compiler will not generate any code to put the processor into 10 bit
6358  stack mode.
6359  It is important to ensure that the processor is in this mode before calling
6360  any re-entrant functions compiled with this option.
6361  In principle, this should work with the 
6362 \emph on 
6363 -
6364 \begin_inset ERT
6365 status Collapsed
6366
6367 \layout Standard
6368
6369 \backslash 
6370 /
6371 \end_inset 
6372
6373 -stack-auto
6374 \begin_inset LatexCommand \index{-\/-stack-auto}
6375
6376 \end_inset 
6377
6378
6379 \emph default 
6380  option, but that has not been tested.
6381  It is incompatible with the 
6382 \emph on 
6383 -
6384 \begin_inset ERT
6385 status Collapsed
6386
6387 \layout Standard
6388
6389 \backslash 
6390 /
6391 \end_inset 
6392
6393 -xstack
6394 \begin_inset LatexCommand \index{-\/-xstack}
6395
6396 \end_inset 
6397
6398
6399 \emph default 
6400  option.
6401  It also only makes sense if the processor is in 24 bit contiguous addressing
6402  mode (see the 
6403 \emph on 
6404 -
6405 \begin_inset ERT
6406 status Collapsed
6407
6408 \layout Standard
6409
6410 \backslash 
6411 /
6412 \end_inset 
6413
6414 -model-flat24 option
6415 \emph default 
6416 ).
6417 \layout List
6418 \labelwidthstring 00.00.0000
6419
6420
6421 \series bold 
6422 -
6423 \begin_inset ERT
6424 status Collapsed
6425
6426 \layout Standard
6427
6428 \backslash 
6429 /
6430 \end_inset 
6431
6432 -stack-probe
6433 \begin_inset LatexCommand \index{-\/-stack-probe}
6434
6435 \end_inset 
6436
6437
6438 \series default 
6439  insert call to function __stack_probe at each function prologue.
6440 \layout List
6441 \labelwidthstring 00.00.0000
6442
6443
6444 \series bold 
6445 -
6446 \begin_inset ERT
6447 status Collapsed
6448
6449 \layout Standard
6450
6451 \backslash 
6452 /
6453 \end_inset 
6454
6455 -tini-libid
6456 \begin_inset LatexCommand \index{-\/-tini-libid}
6457
6458 \end_inset 
6459
6460
6461 \series default 
6462  <nnnn> LibraryID used in -mTININative.
6463  
6464 \layout List
6465 \labelwidthstring 00.00.0000
6466
6467
6468 \series bold 
6469 -
6470 \begin_inset ERT
6471 status Collapsed
6472
6473 \layout Standard
6474
6475 \backslash 
6476 /
6477 \end_inset 
6478
6479 -use-accelerator
6480 \begin_inset LatexCommand \index{-\/-use-accelerator}
6481
6482 \end_inset 
6483
6484
6485 \series default 
6486  generate code for DS390 Arithmetic Accelerator.
6487  
6488 \layout Subsection
6489
6490 Z80 Options
6491 \begin_inset LatexCommand \index{Options Z80}
6492
6493 \end_inset 
6494
6495
6496 \begin_inset LatexCommand \index{Z80 options}
6497
6498 \end_inset 
6499
6500
6501 \layout List
6502 \labelwidthstring 00.00.0000
6503
6504
6505 \series bold 
6506 -
6507 \begin_inset ERT
6508 status Collapsed
6509
6510 \layout Standard
6511
6512 \backslash 
6513 /
6514 \end_inset 
6515
6516 -callee-saves-bc
6517 \series default 
6518
6519 \begin_inset LatexCommand \index{-\/-callee-saves-bc}
6520
6521 \end_inset 
6522
6523
6524 \size large 
6525 \emph on 
6526  
6527 \size default 
6528 \emph default 
6529 Force a called function to always save BC.
6530 \layout List
6531 \labelwidthstring 00.00.0000
6532
6533
6534 \series bold 
6535 -
6536 \begin_inset ERT
6537 status Collapsed
6538
6539 \layout Standard
6540
6541 \backslash 
6542 /
6543 \end_inset 
6544
6545 -no-std-crt0
6546 \series default 
6547
6548 \begin_inset LatexCommand \index{-\/-no-std-crt0}
6549
6550 \end_inset 
6551
6552  When linking, skip the standard crt0.o object file.
6553  You must provide your own crt0.o for your system when linking.
6554  
6555 \layout Subsection
6556
6557 Optimization Options
6558 \begin_inset LatexCommand \index{Options optimization}
6559
6560 \end_inset 
6561
6562
6563 \begin_inset LatexCommand \index{Optimization options}
6564
6565 \end_inset 
6566
6567
6568 \layout List
6569 \labelwidthstring 00.00.0000
6570
6571
6572 \series bold 
6573 -
6574 \begin_inset ERT
6575 status Collapsed
6576
6577 \layout Standard
6578
6579 \backslash 
6580 /
6581 \end_inset 
6582
6583 -nogcse
6584 \begin_inset LatexCommand \index{-\/-nogcse}
6585
6586 \end_inset 
6587
6588
6589 \series default 
6590  Will not do global subexpression elimination, this option may be used when
6591  the compiler creates undesirably large stack/data spaces to store compiler
6592  temporaries (
6593 \emph on 
6594 s
6595 \emph default 
6596 pill 
6597 \emph on 
6598 loc
6599 \emph default 
6600 ations, sloc
6601 \begin_inset LatexCommand \index{sloc (spill location)}
6602
6603 \end_inset 
6604
6605 ).
6606  A warning message will be generated when this happens and the compiler
6607  will indicate the number of extra bytes it allocated.
6608  It is recommended that this option NOT be used, #pragma\SpecialChar ~
6609 nogcse
6610 \begin_inset LatexCommand \index{\#pragma nogcse}
6611
6612 \end_inset 
6613
6614  can be used to turn off global subexpression elimination
6615 \begin_inset LatexCommand \index{Subexpression elimination}
6616
6617 \end_inset 
6618
6619  for a given function only.
6620 \layout List
6621 \labelwidthstring 00.00.0000
6622
6623
6624 \series bold 
6625 -
6626 \begin_inset ERT
6627 status Collapsed
6628
6629 \layout Standard
6630
6631 \backslash 
6632 /
6633 \end_inset 
6634
6635 -noinvariant
6636 \begin_inset LatexCommand \index{-\/-noinvariant}
6637
6638 \end_inset 
6639
6640
6641 \series default 
6642  Will not do loop invariant optimizations, this may be turned off for reasons
6643  explained for the previous option.
6644  For more details of loop optimizations performed see Loop Invariants in
6645  section 
6646 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
6647
6648 \end_inset 
6649
6650 .
6651  It is recommended that this option NOT be used, #pragma\SpecialChar ~
6652 noinvariant
6653 \begin_inset LatexCommand \index{\#pragma noinvariant}
6654
6655 \end_inset 
6656
6657  can be used to turn off invariant optimizations for a given function only.
6658 \layout List
6659 \labelwidthstring 00.00.0000
6660
6661
6662 \series bold 
6663 -
6664 \begin_inset ERT
6665 status Collapsed
6666
6667 \layout Standard
6668
6669 \backslash 
6670 /
6671 \end_inset 
6672
6673 -noinduction
6674 \begin_inset LatexCommand \index{-\/-noinduction}
6675
6676 \end_inset 
6677
6678
6679 \series default 
6680  Will not do loop induction optimizations, see section strength reduction
6681  for more details.
6682  It is recommended that this option is NOT used, #pragma\SpecialChar ~
6683 noinduction
6684 \begin_inset LatexCommand \index{\#pragma noinduction}
6685
6686 \end_inset 
6687
6688  can be used to turn off induction optimizations for a given function only.
6689 \layout List
6690 \labelwidthstring 00.00.0000
6691
6692
6693 \series bold 
6694 -
6695 \begin_inset ERT
6696 status Collapsed
6697
6698 \layout Standard
6699
6700 \backslash 
6701 /
6702 \end_inset 
6703
6704 -nojtbound
6705 \begin_inset LatexCommand \index{-\/-nojtbound}
6706
6707 \end_inset 
6708
6709
6710 \size large 
6711 \bar under 
6712  
6713 \series default 
6714 \size default 
6715 \bar default 
6716  Will not generate boundary condition check when switch statements
6717 \begin_inset LatexCommand \index{switch statement}
6718
6719 \end_inset 
6720
6721  are implemented using jump-tables.
6722  See section 
6723 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
6724
6725 \end_inset 
6726
6727 \SpecialChar ~
6728 Switch Statements for more details.
6729  It is recommended that this option is NOT used, #pragma\SpecialChar ~
6730 nojtbound
6731 \begin_inset LatexCommand \index{\#pragma nojtbound}
6732
6733 \end_inset 
6734
6735  can be used to turn off boundary checking for jump tables for a given function
6736  only.
6737 \layout List
6738 \labelwidthstring 00.00.0000
6739
6740
6741 \series bold 
6742 -
6743 \begin_inset ERT
6744 status Collapsed
6745
6746 \layout Standard
6747
6748 \backslash 
6749 /
6750 \end_inset 
6751
6752 -noloopreverse
6753 \begin_inset LatexCommand \index{-\/-noloopreverse}
6754
6755 \end_inset 
6756
6757
6758 \series default 
6759 \size large 
6760  
6761 \size default 
6762 Will not do loop reversal 
6763 \begin_inset LatexCommand \index{Loop reversing}
6764
6765 \end_inset 
6766
6767 optimization.
6768 \layout List
6769 \labelwidthstring 00.00.0000
6770
6771 -
6772 \begin_inset ERT
6773 status Collapsed
6774
6775 \layout Standard
6776
6777 \backslash 
6778 /
6779 \end_inset 
6780
6781 -
6782 \series bold 
6783 nolabelopt
6784 \series default 
6785  
6786 \begin_inset LatexCommand \index{-\/-nolabelopt }
6787
6788 \end_inset 
6789
6790 Will not optimize labels (makes the dumpfiles more readable).
6791 \layout List
6792 \labelwidthstring 00.00.0000
6793
6794
6795 \series bold 
6796 -
6797 \begin_inset ERT
6798 status Collapsed
6799
6800 \layout Standard
6801
6802 \backslash 
6803 /
6804 \end_inset 
6805
6806 -no-xinit-opt
6807 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
6808
6809 \end_inset 
6810
6811
6812 \series default 
6813  Will not memcpy initialized data from code space into xdata space.
6814  This saves a few bytes in code space if you don't have initialized data
6815 \begin_inset LatexCommand \index{Variable initialization}
6816
6817 \end_inset 
6818
6819 .
6820 \layout List
6821 \labelwidthstring 00.00.0000
6822
6823
6824 \series bold 
6825 -
6826 \begin_inset ERT
6827 status Collapsed
6828
6829 \layout Standard
6830
6831 \backslash 
6832 /
6833 \end_inset 
6834
6835 -nooverlay
6836 \begin_inset LatexCommand \index{-\/-nooverlay}
6837
6838 \end_inset 
6839
6840
6841 \series default 
6842   The compiler will not overlay parameters and local variables of any function,
6843  see section Parameters and local variables for more details.
6844 \layout List
6845 \labelwidthstring 00.00.0000
6846
6847
6848 \series bold 
6849 -
6850 \begin_inset ERT
6851 status Collapsed
6852
6853 \layout Standard
6854
6855 \backslash 
6856 /
6857 \end_inset 
6858
6859 -no-peep
6860 \begin_inset LatexCommand \index{-\/-no-peep}
6861
6862 \end_inset 
6863
6864
6865 \series default 
6866  Disable peep-hole optimization.
6867 \layout List
6868 \labelwidthstring 00.00.0000
6869
6870
6871 \series bold 
6872 -
6873 \begin_inset ERT
6874 status Collapsed
6875
6876 \layout Standard
6877
6878 \backslash 
6879 /
6880 \end_inset 
6881
6882 -peep-file
6883 \series default 
6884
6885 \begin_inset LatexCommand \index{-\/-peep-file}
6886
6887 \end_inset 
6888
6889 \SpecialChar ~
6890 <filename> This option can be used to use additional rules to be used by
6891  the peep hole optimizer.
6892  See section 
6893 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
6894
6895 \end_inset 
6896
6897 \SpecialChar ~
6898 Peep Hole optimizations for details on how to write these rules.
6899 \layout List
6900 \labelwidthstring 00.00.0000
6901
6902
6903 \series bold 
6904 -
6905 \begin_inset ERT
6906 status Collapsed
6907
6908 \layout Standard
6909
6910 \backslash 
6911 /
6912 \end_inset 
6913
6914 -peep-asm
6915 \begin_inset LatexCommand \index{-\/-peep-asm}
6916
6917 \end_inset 
6918
6919
6920 \series default 
6921  Pass the inline assembler code through the peep hole optimizer.
6922  This can cause unexpected changes to inline assembler code, please go through
6923  the peephole optimizer
6924 \begin_inset LatexCommand \index{Peephole optimizer}
6925
6926 \end_inset 
6927
6928  rules defined in the source file tree '<target>/peeph.def' before using
6929  this option.
6930 \layout List
6931 \labelwidthstring 00.00.0000
6932
6933
6934 \series bold 
6935 -
6936 \begin_inset ERT
6937 status Collapsed
6938
6939 \layout Standard
6940
6941 \backslash 
6942 /
6943 \end_inset 
6944
6945 -opt-code-speed
6946 \begin_inset LatexCommand \index{-\/-opt-code-speed}
6947
6948 \end_inset 
6949
6950
6951 \series default 
6952  The compiler will optimize code generation towards fast code, possibly
6953  at the expense of code size.
6954 \layout List
6955 \labelwidthstring 00.00.0000
6956
6957
6958 \series bold 
6959 -
6960 \begin_inset ERT
6961 status Collapsed
6962
6963 \layout Standard
6964
6965 \backslash 
6966 /
6967 \end_inset 
6968
6969 -opt-code-size
6970 \begin_inset LatexCommand \index{-\/-opt-code-size}
6971
6972 \end_inset 
6973
6974
6975 \series default 
6976  The compiler will optimize code generation towards compact code, possibly
6977  at the expense of code speed.
6978 \layout Subsection
6979
6980 Other Options
6981 \begin_inset LatexCommand \index{Options other}
6982
6983 \end_inset 
6984
6985
6986 \layout List
6987 \labelwidthstring 00.00.0000
6988
6989
6990 \series bold 
6991 -c\SpecialChar ~
6992 -
6993 \begin_inset ERT
6994 status Collapsed
6995
6996 \layout Standard
6997
6998 \backslash 
6999 /
7000 \end_inset 
7001
7002 -compile-only
7003 \begin_inset LatexCommand \index{-\/-compile-only}
7004
7005 \end_inset 
7006
7007
7008 \begin_inset LatexCommand \index{-c -\/-compile-only}
7009
7010 \end_inset 
7011
7012
7013 \series default 
7014  will compile and assemble the source, but will not call the linkage editor.
7015 \layout List
7016 \labelwidthstring 00.00.0000
7017
7018
7019 \series bold 
7020 -
7021 \series default 
7022
7023 \begin_inset ERT
7024 status Collapsed
7025
7026 \layout Standard
7027
7028 \backslash 
7029 /
7030 \end_inset 
7031
7032
7033 \series bold 
7034 -c1mode
7035 \begin_inset LatexCommand \index{-\/-c1mode}
7036
7037 \end_inset 
7038
7039
7040 \series default 
7041  reads the preprocessed source from standard input and compiles it.
7042  The file name for the assembler output must be specified using the -o option.
7043 \layout List
7044 \labelwidthstring 00.00.0000
7045
7046
7047 \series bold 
7048 -E
7049 \begin_inset LatexCommand \index{-E}
7050
7051 \end_inset 
7052
7053
7054 \series default 
7055  Run only the C preprocessor.
7056  Preprocess all the C source files specified and output the results to standard
7057  output.
7058 \layout List
7059 \labelwidthstring 00.00.0000
7060
7061
7062 \series bold 
7063 -o\SpecialChar ~
7064 <path/file>
7065 \begin_inset LatexCommand \index{-o <path/file>}
7066
7067 \end_inset 
7068
7069  
7070 \series default 
7071 The output path resp.
7072  file where everything will be placed.
7073  If the parameter is a path, it must have a trailing slash (or backslash
7074  for the Windows binaries) to be recognized as a path.
7075  
7076 \layout List
7077 \labelwidthstring 00.00.0000
7078
7079
7080 \series bold 
7081 -
7082 \begin_inset ERT
7083 status Collapsed
7084
7085 \layout Standard
7086
7087 \backslash 
7088 /
7089 \end_inset 
7090
7091 -stack-auto
7092 \begin_inset LatexCommand \index{-\/-stack-auto}
7093
7094 \end_inset 
7095
7096
7097 \series default 
7098 \size large 
7099 \emph on 
7100  
7101 \size default 
7102 \emph default 
7103 All functions in the source file will be compiled as 
7104 \emph on 
7105 reentrant
7106 \emph default 
7107
7108 \begin_inset LatexCommand \index{reentrant}
7109
7110 \end_inset 
7111
7112 , i.e.
7113  the parameters and local variables will be allocated on the stack
7114 \begin_inset LatexCommand \index{stack}
7115
7116 \end_inset 
7117
7118 .
7119  See section 
7120 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
7121
7122 \end_inset 
7123
7124  Parameters and Local Variables for more details.
7125  If this option is used all source files in the project should be compiled
7126  with this option.
7127  It automatically implies --int-long-reent and --float-reent.
7128  
7129 \layout List
7130 \labelwidthstring 00.00.0000
7131
7132
7133 \series bold 
7134 -
7135 \begin_inset ERT
7136 status Collapsed
7137
7138 \layout Standard
7139
7140 \backslash 
7141 /
7142 \end_inset 
7143
7144 -callee-saves
7145 \begin_inset LatexCommand \index{-\/-callee-saves}
7146
7147 \end_inset 
7148
7149  function1[,function2][,function3]....
7150
7151 \series default 
7152  The compiler by default uses a caller saves convention for register saving
7153  across function calls, however this can cause unnecessary register pushing
7154  & popping when calling small functions from larger functions.
7155  This option can be used to switch the register saving convention for the
7156  function names specified.
7157  The compiler will not save registers when calling these functions, no extra
7158  code will be generated at the entry & exit (function prologue
7159 \series bold 
7160
7161 \begin_inset LatexCommand \index{function prologue}
7162
7163 \end_inset 
7164
7165
7166 \series default 
7167  & epilogue
7168 \series bold 
7169
7170 \begin_inset LatexCommand \index{function epilogue}
7171
7172 \end_inset 
7173
7174
7175 \series default 
7176 ) for these functions to save & restore the registers used by these functions,
7177  this can SUBSTANTIALLY reduce code & improve run time performance of the
7178  generated code.
7179  In the future the compiler (with inter procedural analysis) will be able
7180  to determine the appropriate scheme to use for each function call.
7181  DO NOT use this option for built-in functions such as _mulint..., if this
7182  option is used for a library function the appropriate library function
7183  needs to be recompiled with the same option.
7184  If the project consists of multiple source files then all the source file
7185  should be compiled with the same -
7186 \begin_inset ERT
7187 status Collapsed
7188
7189 \layout Standard
7190
7191 \backslash 
7192 /
7193 \end_inset 
7194
7195 -callee-saves option string.
7196  Also see #pragma\SpecialChar ~
7197 callee_saves
7198 \begin_inset LatexCommand \index{\#pragma callee\_saves}
7199
7200 \end_inset 
7201
7202 .
7203 \layout List
7204 \labelwidthstring 00.00.0000
7205
7206
7207 \series bold 
7208 -
7209 \begin_inset ERT
7210 status Collapsed
7211
7212 \layout Standard
7213
7214 \backslash 
7215 /
7216 \end_inset 
7217
7218 -debug
7219 \begin_inset LatexCommand \index{-\/-debug}
7220
7221 \end_inset 
7222
7223
7224 \bar under 
7225  
7226 \series default 
7227 \bar default 
7228 When this option is used the compiler will generate debug information.
7229  The debug information collected in a file with .cdb extension can be used
7230  with the SDCDB.
7231  For more information see documentation for SDCDB.
7232  Another file with no extension contains debug information in AOMF or AOMF51
7233 \begin_inset LatexCommand \index{AOMF, AOMF51}
7234
7235 \end_inset 
7236
7237  format which is commonly used by third party tools.
7238 \layout List
7239 \labelwidthstring 00.00.0000
7240
7241
7242 \series bold 
7243 -S
7244 \begin_inset LatexCommand \index{-S}
7245
7246 \end_inset 
7247
7248
7249 \size large 
7250 \bar under 
7251  
7252 \series default 
7253 \size default 
7254 \bar default 
7255 Stop after the stage of compilation proper; do not assemble.
7256  The output is an assembler code file for the input file specified.
7257 \layout List
7258 \labelwidthstring 00.00.0000
7259
7260
7261 \series bold 
7262 -
7263 \begin_inset ERT
7264 status Collapsed
7265
7266 \layout Standard
7267
7268 \backslash 
7269 /
7270 \end_inset 
7271
7272 -int-long-reent
7273 \begin_inset LatexCommand \index{-\/-int-long-reent}
7274
7275 \end_inset 
7276
7277
7278 \series default 
7279  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
7280  Note by default these libraries are compiled as non-reentrant.
7281  See section Installation for more details.
7282 \layout List
7283 \labelwidthstring 00.00.0000
7284
7285
7286 \series bold 
7287 -
7288 \begin_inset ERT
7289 status Collapsed
7290
7291 \layout Standard
7292
7293 \backslash 
7294 /
7295 \end_inset 
7296
7297 -cyclomatic
7298 \begin_inset LatexCommand \index{-\/-cyclomatic}
7299
7300 \end_inset 
7301
7302
7303 \bar under 
7304  
7305 \series default 
7306 \bar default 
7307 This option will cause the compiler to generate an information message for
7308  each function in the source file.
7309  The message contains some 
7310 \emph on 
7311 important
7312 \emph default 
7313  information about the function.
7314  The number of edges and nodes the compiler detected in the control flow
7315  graph of the function, and most importantly the 
7316 \emph on 
7317 cyclomatic complexity
7318 \begin_inset LatexCommand \index{Cyclomatic complexity}
7319
7320 \end_inset 
7321
7322
7323 \emph default 
7324  see section on Cyclomatic Complexity for more details.
7325 \layout List
7326 \labelwidthstring 00.00.0000
7327
7328
7329 \series bold 
7330 -
7331 \begin_inset ERT
7332 status Collapsed
7333
7334 \layout Standard
7335
7336 \backslash 
7337 /
7338 \end_inset 
7339
7340 -float-reent
7341 \begin_inset LatexCommand \index{-\/-float-reent}
7342
7343 \end_inset 
7344
7345
7346 \series default 
7347  Floating point library is compiled as reentrant
7348 \begin_inset LatexCommand \index{reentrant}
7349
7350 \end_inset 
7351
7352 .
7353  See section Installation for more details.
7354 \layout List
7355 \labelwidthstring 00.00.0000
7356
7357
7358 \series bold 
7359 -
7360 \begin_inset ERT
7361 status Collapsed
7362
7363 \layout Standard
7364
7365 \backslash 
7366 /
7367 \end_inset 
7368
7369 -main-return
7370 \begin_inset LatexCommand \index{-\/-main-return}
7371
7372 \end_inset 
7373
7374
7375 \series default 
7376  This option can be used if the code generated is called by a monitor program
7377  or if the main routine includes an endless loop.
7378  This option might result in slightly smaller code and save two bytes of
7379  stack space.
7380  The return from the 'main'
7381 \begin_inset LatexCommand \index{main return}
7382
7383 \end_inset 
7384
7385  function will return to the function calling main.
7386  The default setting is to lock up i.e.
7387  generate a '
7388 \family typewriter 
7389 sjmp .
7390 \family default 
7391 '.
7392 \layout List
7393 \labelwidthstring 00.00.0000
7394
7395
7396 \series bold 
7397 -
7398 \begin_inset ERT
7399 status Collapsed
7400
7401 \layout Standard
7402
7403 \backslash 
7404 /
7405 \end_inset 
7406
7407 -nostdinc
7408 \begin_inset LatexCommand \index{-\/-nostdinc}
7409
7410 \end_inset 
7411
7412
7413 \series default 
7414  This will prevent the compiler from passing on the default include path
7415  to the preprocessor.
7416 \layout List
7417 \labelwidthstring 00.00.0000
7418
7419
7420 \series bold 
7421 -
7422 \begin_inset ERT
7423 status Collapsed
7424
7425 \layout Standard
7426
7427 \backslash 
7428 /
7429 \end_inset 
7430
7431 -nostdlib
7432 \begin_inset LatexCommand \index{-\/-nostdlib}
7433
7434 \end_inset 
7435
7436
7437 \series default 
7438  This will prevent the compiler from passing on the default library
7439 \begin_inset LatexCommand \index{Libraries}
7440
7441 \end_inset 
7442
7443  path to the linker.
7444 \layout List
7445 \labelwidthstring 00.00.0000
7446
7447
7448 \series bold 
7449 -
7450 \begin_inset ERT
7451 status Collapsed
7452
7453 \layout Standard
7454
7455 \backslash 
7456 /
7457 \end_inset 
7458
7459 -verbose
7460 \begin_inset LatexCommand \index{-\/-verbose}
7461
7462 \end_inset 
7463
7464
7465 \series default 
7466  Shows the various actions the compiler is performing.
7467 \layout List
7468 \labelwidthstring 00.00.0000
7469
7470
7471 \series bold 
7472 -V
7473 \begin_inset LatexCommand \index{-V}
7474
7475 \end_inset 
7476
7477
7478 \series default 
7479  Shows the actual commands the compiler is executing.
7480 \layout List
7481 \labelwidthstring 00.00.0000
7482
7483
7484 \series bold 
7485 -
7486 \begin_inset ERT
7487 status Collapsed
7488
7489 \layout Standard
7490
7491 \backslash 
7492 /
7493 \end_inset 
7494
7495 -no-c-code-in-asm
7496 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
7497
7498 \end_inset 
7499
7500
7501 \series default 
7502  Hides your ugly and inefficient c-code from the asm file, so you can always
7503  blame the compiler :)
7504 \layout List
7505 \labelwidthstring 00.00.0000
7506
7507
7508 \series bold 
7509 -
7510 \begin_inset ERT
7511 status Collapsed
7512
7513 \layout Standard
7514
7515 \backslash 
7516 /
7517 \end_inset 
7518
7519 -no-peep-comments
7520 \begin_inset LatexCommand \index{-\/-no-peep-comments}
7521
7522 \end_inset 
7523
7524
7525 \series default 
7526  Will not include peep-hole comments in the generated files.
7527 \layout List
7528 \labelwidthstring 00.00.0000
7529
7530
7531 \series bold 
7532 -
7533 \begin_inset ERT
7534 status Collapsed
7535
7536 \layout Standard
7537
7538 \backslash 
7539 /
7540 \end_inset 
7541
7542 -i-code-in-asm
7543 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
7544
7545 \end_inset 
7546
7547
7548 \series default 
7549  Include i-codes in the asm file.
7550  Sounds like noise but is most helpful for debugging the compiler itself.
7551 \layout List
7552 \labelwidthstring 00.00.0000
7553
7554
7555 \series bold 
7556 -
7557 \begin_inset ERT
7558 status Collapsed
7559
7560 \layout Standard
7561
7562 \backslash 
7563 /
7564 \end_inset 
7565
7566 -less-pedantic
7567 \begin_inset LatexCommand \index{-\/-less-pedantic}
7568
7569 \end_inset 
7570
7571
7572 \series default 
7573  Disable some of the more pedantic warnings
7574 \begin_inset LatexCommand \index{Warnings}
7575
7576 \end_inset 
7577
7578  (jwk burps: please be more specific here, please!).
7579  If you want rather more than less warnings you should consider using a
7580  separate tool dedicated to syntax checking like splint 
7581 \begin_inset LatexCommand \url{http://www.splint.org}
7582
7583 \end_inset 
7584
7585 .
7586 \layout List
7587 \labelwidthstring 00.00.0000
7588
7589
7590 \series bold 
7591 -
7592 \begin_inset ERT
7593 status Collapsed
7594
7595 \layout Standard
7596
7597 \backslash 
7598 /
7599 \end_inset 
7600
7601 -disable-warning\SpecialChar ~
7602 <nnnn>
7603 \begin_inset LatexCommand \index{-\/-disable-warning}
7604
7605 \end_inset 
7606
7607
7608 \series default 
7609  Disable specific warning with number <nnnn>.
7610 \layout List
7611 \labelwidthstring 00.00.0000
7612
7613
7614 \series bold 
7615 -
7616 \begin_inset ERT
7617 status Collapsed
7618
7619 \layout Standard
7620
7621 \backslash 
7622 /
7623 \end_inset 
7624
7625 -print-search-dirs
7626 \begin_inset LatexCommand \index{-\/-print-search-dirs}
7627
7628 \end_inset 
7629
7630
7631 \series default 
7632  Display the directories in the compiler's search path
7633 \layout List
7634 \labelwidthstring 00.00.0000
7635
7636
7637 \series bold 
7638 -
7639 \begin_inset ERT
7640 status Collapsed
7641
7642 \layout Standard
7643
7644 \backslash 
7645 /
7646 \end_inset 
7647
7648 -vc
7649 \begin_inset LatexCommand \index{-\/-vc}
7650
7651 \end_inset 
7652
7653
7654 \series default 
7655  Display errors and warnings using MSVC style, so you can use SDCC with
7656  visual studio.
7657 \layout List
7658 \labelwidthstring 00.00.0000
7659
7660
7661 \series bold 
7662 -
7663 \begin_inset ERT
7664 status Collapsed
7665
7666 \layout Standard
7667
7668 \backslash 
7669 /
7670 \end_inset 
7671
7672 -use-stdout
7673 \begin_inset LatexCommand \index{-\/-use-stdout}
7674
7675 \end_inset 
7676
7677
7678 \series default 
7679  Send errors and warnings to stdout instead of stderr.
7680 \layout List
7681 \labelwidthstring 00.00.0000
7682
7683
7684 \series bold 
7685 -Wa\SpecialChar ~
7686 asmOption[,asmOption]
7687 \series default 
7688
7689 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
7690
7691 \end_inset 
7692
7693 ...
7694  Pass the asmOption to the assembler
7695 \begin_inset LatexCommand \index{Options assembler}
7696
7697 \end_inset 
7698
7699
7700 \begin_inset LatexCommand \index{Assembler options}
7701
7702 \end_inset 
7703
7704 .
7705  See file sdcc/as/doc/asxhtm.html for assembler options.
7706 \layout List
7707 \labelwidthstring 00.00.0000
7708
7709
7710 \series bold 
7711 -
7712 \begin_inset ERT
7713 status Collapsed
7714
7715 \layout Standard
7716
7717 \backslash 
7718 /
7719 \end_inset 
7720
7721 -std-sdcc89
7722 \begin_inset LatexCommand \index{-\/-std-sdcc89}
7723
7724 \end_inset 
7725
7726
7727 \series default 
7728  Generally follow the C89 standard, but allow SDCC features that conflict
7729  with the standard (default).
7730 \layout List
7731 \labelwidthstring 00.00.0000
7732
7733
7734 \series bold 
7735 -
7736 \begin_inset ERT
7737 status Collapsed
7738
7739 \layout Standard
7740
7741 \backslash 
7742 /
7743 \end_inset 
7744
7745 -std-c89
7746 \begin_inset LatexCommand \index{-\/-std-c89}
7747
7748 \end_inset 
7749
7750
7751 \series default 
7752  Follow the C89 standard and disable SDCC features that conflict with the
7753  standard.
7754 \layout List
7755 \labelwidthstring 00.00.0000
7756
7757
7758 \series bold 
7759 -
7760 \begin_inset ERT
7761 status Collapsed
7762
7763 \layout Standard
7764
7765 \backslash 
7766 /
7767 \end_inset 
7768
7769 -std-sdcc99
7770 \begin_inset LatexCommand \index{-\/-std-sdcc99}
7771
7772 \end_inset 
7773
7774
7775 \series default 
7776  Generally follow the C99 standard, but allow SDCC features that conflict
7777  with the standard (incomplete support).
7778 \layout List
7779 \labelwidthstring 00.00.0000
7780
7781
7782 \series bold 
7783 -
7784 \begin_inset ERT
7785 status Collapsed
7786
7787 \layout Standard
7788
7789 \backslash 
7790 /
7791 \end_inset 
7792
7793 -std-c99
7794 \begin_inset LatexCommand \index{-\/-std-sdcc99}
7795
7796 \end_inset 
7797
7798
7799 \series default 
7800  Follow the C99 standard and disable SDCC features that conflict with the
7801  standard (incomplete support).
7802 \layout Subsection
7803
7804 Intermediate Dump Options
7805 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
7806
7807 \end_inset 
7808
7809
7810 \begin_inset LatexCommand \index{Options intermediate dump}
7811
7812 \end_inset 
7813
7814
7815 \begin_inset LatexCommand \index{Intermediate dump options}
7816
7817 \end_inset 
7818
7819
7820 \layout Standard
7821
7822 The following options are provided for the purpose of retargetting and debugging
7823  the compiler.
7824  They provide a means to dump the intermediate code (iCode
7825 \begin_inset LatexCommand \index{iCode}
7826
7827 \end_inset 
7828
7829 ) generated by the compiler in human readable form at various stages of
7830  the compilation process.
7831  More on iCodes see chapter 
7832 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
7833
7834 \end_inset 
7835
7836  
7837 \begin_inset Quotes srd
7838 \end_inset 
7839
7840 The anatomy of the compiler
7841 \begin_inset Quotes srd
7842 \end_inset 
7843
7844 .
7845 \layout List
7846 \labelwidthstring 00.00.0000
7847
7848
7849 \series bold 
7850 -
7851 \begin_inset ERT
7852 status Collapsed
7853
7854 \layout Standard
7855
7856 \backslash 
7857 /
7858 \end_inset 
7859
7860 -dumpraw
7861 \begin_inset LatexCommand \index{-\/-dumpraw}
7862
7863 \end_inset 
7864
7865
7866 \series default 
7867  This option will cause the compiler to dump the intermediate code into
7868  a file of named 
7869 \emph on 
7870 <source filename>.dumpraw
7871 \emph default 
7872  just after the intermediate code has been generated for a function, i.e.
7873  before any optimizations are done.
7874  The basic blocks
7875 \begin_inset LatexCommand \index{Basic blocks}
7876
7877 \end_inset 
7878
7879  at this stage ordered in the depth first number, so they may not be in
7880  sequence of execution.
7881 \layout List
7882 \labelwidthstring 00.00.0000
7883
7884
7885 \series bold 
7886 -
7887 \begin_inset ERT
7888 status Collapsed
7889
7890 \layout Standard
7891
7892 \backslash 
7893 /
7894 \end_inset 
7895
7896 -dumpgcse
7897 \begin_inset LatexCommand \index{-\/-dumpgcse}
7898
7899 \end_inset 
7900
7901
7902 \series default 
7903  Will create a dump of iCode's, after global subexpression elimination
7904 \begin_inset LatexCommand \index{Global subexpression elimination}
7905
7906 \end_inset 
7907
7908 , into a file named 
7909 \emph on 
7910 <source filename>.dumpgcse.
7911 \layout List
7912 \labelwidthstring 00.00.0000
7913
7914
7915 \series bold 
7916 -
7917 \begin_inset ERT
7918 status Collapsed
7919
7920 \layout Standard
7921
7922 \backslash 
7923 /
7924 \end_inset 
7925
7926 -dumpdeadcode
7927 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
7928
7929 \end_inset 
7930
7931
7932 \series default 
7933  Will create a dump of iCode's, after deadcode elimination
7934 \begin_inset LatexCommand \index{Dead-code elimination}
7935
7936 \end_inset 
7937
7938 , into a file named 
7939 \emph on 
7940 <source filename>.dumpdeadcode.
7941 \layout List
7942 \labelwidthstring 00.00.0000
7943
7944
7945 \series bold 
7946 -
7947 \begin_inset ERT
7948 status Collapsed
7949
7950 \layout Standard
7951
7952 \backslash 
7953 /
7954 \end_inset 
7955
7956 -dumploop
7957 \begin_inset LatexCommand \index{-\/-dumploop}
7958
7959 \end_inset 
7960
7961
7962 \series default 
7963 \size large 
7964  
7965 \size default 
7966 Will create a dump of iCode's, after loop optimizations
7967 \begin_inset LatexCommand \index{Loop optimization}
7968
7969 \end_inset 
7970
7971 , into a file named 
7972 \emph on 
7973 <source filename>.dumploop.
7974 \layout List
7975 \labelwidthstring 00.00.0000
7976
7977
7978 \series bold 
7979 -
7980 \begin_inset ERT
7981 status Collapsed
7982
7983 \layout Standard
7984
7985 \backslash 
7986 /
7987 \end_inset 
7988
7989 -dumprange
7990 \begin_inset LatexCommand \index{-\/-dumprange}
7991
7992 \end_inset 
7993
7994
7995 \series default 
7996 \size large 
7997  
7998 \size default 
7999 Will create a dump of iCode's, after live range analysis
8000 \begin_inset LatexCommand \index{Live range analysis}
8001
8002 \end_inset 
8003
8004 , into a file named 
8005 \emph on 
8006 <source filename>.dumprange.
8007 \layout List
8008 \labelwidthstring 00.00.0000
8009
8010
8011 \series bold 
8012 -
8013 \begin_inset ERT
8014 status Collapsed
8015
8016 \layout Standard
8017
8018 \backslash 
8019 /
8020 \end_inset 
8021
8022 -dumlrange
8023 \begin_inset LatexCommand \index{-\/-dumlrange}
8024
8025 \end_inset 
8026
8027
8028 \series default 
8029  Will dump the life ranges
8030 \begin_inset LatexCommand \index{Live range analysis}
8031
8032 \end_inset 
8033
8034  for all symbols.
8035 \layout List
8036 \labelwidthstring 00.00.0000
8037
8038
8039 \series bold 
8040 -
8041 \begin_inset ERT
8042 status Collapsed
8043
8044 \layout Standard
8045
8046 \backslash 
8047 /
8048 \end_inset 
8049
8050 -dumpregassign
8051 \begin_inset LatexCommand \index{-\/-dumpregassign}
8052
8053 \end_inset 
8054
8055
8056 \bar under 
8057  
8058 \series default 
8059 \bar default 
8060 Will create a dump of iCode's, after register assignment
8061 \begin_inset LatexCommand \index{Register assignment}
8062
8063 \end_inset 
8064
8065 , into a file named 
8066 \emph on 
8067 <source filename>.dumprassgn.
8068 \layout List
8069 \labelwidthstring 00.00.0000
8070
8071
8072 \series bold 
8073 -
8074 \begin_inset ERT
8075 status Collapsed
8076
8077 \layout Standard
8078
8079 \backslash 
8080 /
8081 \end_inset 
8082
8083 -dumplrange
8084 \begin_inset LatexCommand \index{-\/-dumplrange}
8085
8086 \end_inset 
8087
8088
8089 \series default 
8090  Will create a dump of the live ranges of iTemp's
8091 \layout List
8092 \labelwidthstring 00.00.0000
8093
8094
8095 \series bold 
8096 -
8097 \begin_inset ERT
8098 status Collapsed
8099
8100 \layout Standard
8101
8102 \backslash 
8103 /
8104 \end_inset 
8105
8106 -dumpall
8107 \begin_inset LatexCommand \index{-\/-dumpall}
8108
8109 \end_inset 
8110
8111
8112 \size large 
8113 \bar under 
8114  
8115 \series default 
8116 \size default 
8117 \bar default 
8118 Will cause all the above mentioned dumps to be created.
8119 \layout Subsection
8120
8121 Redirecting output on Windows Shells
8122 \layout Standard
8123
8124 By default SDCC writes it's error messages to 
8125 \begin_inset Quotes sld
8126 \end_inset 
8127
8128 standard error
8129 \begin_inset Quotes srd
8130 \end_inset 
8131
8132 .
8133  To force all messages to 
8134 \begin_inset Quotes sld
8135 \end_inset 
8136
8137 standard output
8138 \begin_inset Quotes srd
8139 \end_inset 
8140
8141  use 
8142 \series bold 
8143 -
8144 \series default 
8145 \emph on 
8146
8147 \begin_inset ERT
8148 status Collapsed
8149
8150 \layout Standard
8151
8152 \backslash 
8153 /
8154 \end_inset 
8155
8156
8157 \series bold 
8158 \emph default 
8159 -
8160 \series default 
8161 use-stdout
8162 \begin_inset LatexCommand \index{-\/-use-stdout}
8163
8164 \end_inset 
8165
8166 .
8167  Additionally, if you happen to have visual studio installed in your windows
8168  machine, you can use it to compile your sources using a custom build and
8169  the SDCC -
8170 \emph on 
8171
8172 \begin_inset ERT
8173 status Collapsed
8174
8175 \layout Standard
8176
8177 \backslash 
8178 /
8179 \end_inset 
8180
8181
8182 \emph default 
8183 -vc
8184 \begin_inset LatexCommand \index{-\/-vc}
8185
8186 \end_inset 
8187
8188  option.
8189  Something like this should work:
8190 \newline 
8191
8192 \newline 
8193
8194 \series bold 
8195 c:
8196 \backslash 
8197 sdcc
8198 \backslash 
8199 bin
8200 \backslash 
8201 sdcc.exe -
8202 \series default 
8203 \emph on 
8204
8205 \begin_inset ERT
8206 status Collapsed
8207
8208 \layout Standard
8209
8210 \backslash 
8211 /
8212 \end_inset 
8213
8214
8215 \series bold 
8216 \emph default 
8217 -vc -
8218 \series default 
8219 \emph on 
8220
8221 \begin_inset ERT
8222 status Collapsed
8223
8224 \layout Standard
8225
8226 \backslash 
8227 /
8228 \end_inset 
8229
8230
8231 \series bold 
8232 \emph default 
8233 -model-large -c $(InputPath)
8234 \layout Section
8235
8236 Environment variables
8237 \begin_inset LatexCommand \index{Environment variables}
8238
8239 \end_inset 
8240
8241
8242 \layout Standard
8243
8244 SDCC recognizes the following environment variables:
8245 \layout List
8246 \labelwidthstring 00.00.0000
8247
8248
8249 \series bold 
8250 SDCC_LEAVE_SIGNALS
8251 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
8252
8253 \end_inset 
8254
8255
8256 \series default 
8257  SDCC installs a signal handler
8258 \begin_inset LatexCommand \index{signal handler}
8259
8260 \end_inset 
8261
8262  to be able to delete temporary files after an user break (^C) or an exception.
8263  If this environment variable is set, SDCC won't install the signal handler
8264  in order to be able to debug SDCC.
8265 \layout List
8266 \labelwidthstring 00.00.0000
8267
8268
8269 \series bold 
8270 TMP,\SpecialChar ~
8271 TEMP,\SpecialChar ~
8272 TMPDIR
8273 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
8274
8275 \end_inset 
8276
8277
8278 \series default 
8279  Path, where temporary files will be created.
8280  The order of the variables is the search order.
8281  In a standard *nix environment these variables are not set, and there's
8282  no need to set them.
8283  On Windows it's recommended to set one of them.
8284 \layout List
8285 \labelwidthstring 00.00.0000
8286
8287
8288 \series bold 
8289 SDCC_HOME
8290 \begin_inset LatexCommand \index{SDCC\_HOME}
8291
8292 \end_inset 
8293
8294
8295 \series default 
8296  Path, see section 
8297 \begin_inset LatexCommand \ref{sub:Install-paths}
8298
8299 \end_inset 
8300
8301 \SpecialChar ~
8302
8303 \begin_inset Quotes sld
8304 \end_inset 
8305
8306  Install Paths
8307 \begin_inset Quotes srd
8308 \end_inset 
8309
8310 .
8311 \layout List
8312 \labelwidthstring 00.00.0000
8313
8314
8315 \series bold 
8316 SDCC_INCLUDE
8317 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
8318
8319 \end_inset 
8320
8321
8322 \series default 
8323  Path, see section 
8324 \begin_inset LatexCommand \ref{sub:Search-Paths}
8325
8326 \end_inset 
8327
8328 \SpecialChar ~
8329
8330 \begin_inset Quotes sld
8331 \end_inset 
8332
8333 Search Paths
8334 \begin_inset Quotes srd
8335 \end_inset 
8336
8337 .
8338 \layout List
8339 \labelwidthstring 00.00.0000
8340
8341
8342 \series bold 
8343 SDCC_LIB
8344 \begin_inset LatexCommand \index{SDCC\_LIB}
8345
8346 \end_inset 
8347
8348
8349 \series default 
8350  Path, see section 
8351 \begin_inset LatexCommand \ref{sub:Search-Paths}
8352
8353 \end_inset 
8354
8355 \SpecialChar ~
8356
8357 \begin_inset Quotes sld
8358 \end_inset 
8359
8360 Search Paths
8361 \begin_inset Quotes srd
8362 \end_inset 
8363
8364 ..
8365 \layout Standard
8366
8367 There are some more environment variables recognized by SDCC, but these
8368  are solely used for debugging purposes.
8369  They can change or disappear very quickly, and will never be documented.
8370 \layout Section
8371
8372 Storage Class Language Extensions
8373 \layout Subsection
8374
8375 MCS51/DS390 Storage Class
8376 \begin_inset LatexCommand \index{Storage class}
8377
8378 \end_inset 
8379
8380  Language Extensions
8381 \layout Standard
8382
8383 In addition to the ANSI storage classes SDCC allows the following MCS51
8384  specific storage classes:
8385 \layout Subsubsection
8386
8387 data
8388 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
8389
8390 \end_inset 
8391
8392
8393 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
8394
8395 \end_inset 
8396
8397  / near
8398 \begin_inset LatexCommand \index{near (storage class)}
8399
8400 \end_inset 
8401
8402
8403 \begin_inset LatexCommand \index{\_\_near (storage class)}
8404
8405 \end_inset 
8406
8407
8408 \layout Standard
8409
8410 This is the 
8411 \series bold 
8412 default
8413 \series default 
8414  storage class for the Small Memory model (
8415 \emph on 
8416 data
8417 \emph default 
8418  and 
8419 \emph on 
8420 near
8421 \emph default 
8422  can be used synonymously).
8423  Variables declared with this storage class will be allocated in the directly
8424  addressable portion of the internal RAM of a 8051, e.g.:
8425 \layout Verse
8426
8427
8428 \family typewriter 
8429 data unsigned char test_data;
8430 \layout Standard
8431
8432 Writing 0x01 to this variable generates the assembly code:
8433 \layout Verse
8434
8435
8436 \family typewriter 
8437 75*00 01\SpecialChar ~
8438 \SpecialChar ~
8439 \SpecialChar ~
8440 mov\SpecialChar ~
8441 \SpecialChar ~
8442 _test_data,#0x01 
8443 \layout Subsubsection
8444
8445 xdata
8446 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
8447
8448 \end_inset 
8449
8450
8451 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
8452
8453 \end_inset 
8454
8455  / far
8456 \begin_inset LatexCommand \index{far (storage class)}
8457
8458 \end_inset 
8459
8460
8461 \begin_inset LatexCommand \index{\_\_far (storage class)}
8462
8463 \end_inset 
8464
8465
8466 \layout Standard
8467
8468 Variables declared with this storage class will be placed in the external
8469  RAM.
8470  This is the 
8471 \series bold 
8472 default
8473 \series default 
8474  storage class for the Large Memory model, e.g.:
8475 \layout Verse
8476
8477
8478 \family typewriter 
8479 xdata unsigned char test_xdata;
8480 \layout Standard
8481
8482 Writing 0x01 to this variable generates the assembly code:
8483 \layout Verse
8484
8485
8486 \family typewriter 
8487 90s00r00\SpecialChar ~
8488 \SpecialChar ~
8489 \SpecialChar ~
8490 mov\SpecialChar ~
8491 \SpecialChar ~
8492 dptr,#_test_xdata 
8493 \newline 
8494 74\SpecialChar ~
8495 01\SpecialChar ~
8496 \SpecialChar ~
8497 \SpecialChar ~
8498 \SpecialChar ~
8499 \SpecialChar ~
8500 \SpecialChar ~
8501 mov\SpecialChar ~
8502 \SpecialChar ~
8503 a,#0x01 
8504 \newline 
8505 F0\SpecialChar ~
8506 \SpecialChar ~
8507 \SpecialChar ~
8508 \SpecialChar ~
8509 \SpecialChar ~
8510 \SpecialChar ~
8511 \SpecialChar ~
8512 \SpecialChar ~
8513 \SpecialChar ~
8514 movx\SpecialChar ~
8515 @dptr,a 
8516 \layout Subsubsection
8517
8518 idata
8519 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
8520
8521 \end_inset 
8522
8523
8524 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
8525
8526 \end_inset 
8527
8528
8529 \layout Standard
8530
8531 Variables declared with this storage class will be allocated into the indirectly
8532  addressable portion of the internal ram of a 8051, e.g.:
8533 \layout Verse
8534
8535
8536 \family typewriter 
8537 idata unsigned char test_idata;
8538 \layout Standard
8539
8540 Writing 0x01 to this variable generates the assembly code:
8541 \layout Verse
8542
8543
8544 \family typewriter 
8545 78r00\SpecialChar ~
8546 \SpecialChar ~
8547 \SpecialChar ~
8548 \SpecialChar ~
8549 \SpecialChar ~
8550 \SpecialChar ~
8551 \SpecialChar ~
8552 mov\SpecialChar ~
8553 \SpecialChar ~
8554 r0,#_test_idata
8555 \newline 
8556 76\SpecialChar ~
8557 01\SpecialChar ~
8558 \SpecialChar ~
8559 \SpecialChar ~
8560 \SpecialChar ~
8561 \SpecialChar ~
8562 \SpecialChar ~
8563 \SpecialChar ~
8564 mov\SpecialChar ~
8565 \SpecialChar ~
8566 @r0,#0x01
8567 \layout Standard
8568
8569 Please note, the first 128 byte of idata physically access the same RAM
8570  as the data memory.
8571  The original 8051 had 128 byte idata memory, nowadays most devices have
8572  256 byte idata memory.
8573  The stack
8574 \begin_inset LatexCommand \index{stack}
8575
8576 \end_inset 
8577
8578  is located in idata memory.
8579 \layout Subsubsection
8580
8581 pdata
8582 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
8583
8584 \end_inset 
8585
8586
8587 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
8588
8589 \end_inset 
8590
8591
8592 \layout Standard
8593
8594 Paged xdata access is just as straightforward as using the other addressing
8595  modes of a 8051.
8596  It is typically located at the start of xdata and has a maximum size of
8597  256 bytes.
8598  The following example writes 0x01 to the address pointed to.
8599  Please note, pdata access physically accesses xdata memory.
8600  The high byte of the address is determined by port P2 
8601 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
8602
8603 \end_inset 
8604
8605 (or in case of some 8051 variants by a separate Special Function Register,
8606  see section 
8607 \begin_inset LatexCommand \ref{sub:MCS51-variants}
8608
8609 \end_inset 
8610
8611 ).
8612 \layout Verse
8613
8614
8615 \family typewriter 
8616 pdata unsigned char *test_pdata_ptr;
8617 \newline 
8618
8619 \newline 
8620 void main() 
8621 \newline 
8622
8623 \newline 
8624 \SpecialChar ~
8625 \SpecialChar ~
8626 \SpecialChar ~
8627 \SpecialChar ~
8628 test_pdata_ptr = (pdata *)0xfe; 
8629 \newline 
8630 \SpecialChar ~
8631 \SpecialChar ~
8632 \SpecialChar ~
8633 \SpecialChar ~
8634 *test_pdata_ptr = 1; 
8635 \newline 
8636
8637 \layout Standard
8638
8639 Generates the assembly code:
8640 \layout Verse
8641
8642
8643 \family typewriter 
8644 75*01 FE\SpecialChar ~
8645 \SpecialChar ~
8646 \SpecialChar ~
8647 mov\SpecialChar ~
8648  _test_pdata_ptr,#0xFE
8649 \newline 
8650 78 FE\SpecialChar ~
8651 \SpecialChar ~
8652 \SpecialChar ~
8653 \SpecialChar ~
8654 \SpecialChar ~
8655 \SpecialChar ~
8656 mov\SpecialChar ~
8657  r0,#0xFE 
8658 \newline 
8659 74 01\SpecialChar ~
8660 \SpecialChar ~
8661 \SpecialChar ~
8662 \SpecialChar ~
8663 \SpecialChar ~
8664 \SpecialChar ~
8665 mov\SpecialChar ~
8666  a,#0x01
8667 \newline 
8668 F2\SpecialChar ~
8669 \SpecialChar ~
8670 \SpecialChar ~
8671 \SpecialChar ~
8672 \SpecialChar ~
8673 \SpecialChar ~
8674 \SpecialChar ~
8675 \SpecialChar ~
8676 \SpecialChar ~
8677 movx @r0,a 
8678 \layout Standard
8679
8680 If the -
8681 \begin_inset ERT
8682 status Collapsed
8683
8684 \layout Standard
8685
8686 \backslash 
8687 /
8688 \end_inset 
8689
8690 -xstack
8691 \begin_inset LatexCommand \index{-\/-xstack}
8692
8693 \end_inset 
8694
8695  option is used the pdata memory area is followed by the xstack memory area
8696  and the sum of their sizes is limited to 256 bytes.
8697 \layout Subsubsection
8698
8699 code
8700 \begin_inset LatexCommand \index{code}
8701
8702 \end_inset 
8703
8704
8705 \begin_inset LatexCommand \index{\_\_code}
8706
8707 \end_inset 
8708
8709
8710 \layout Standard
8711
8712 'Variables' declared with this storage class will be placed in the code
8713  memory:
8714 \layout Verse
8715
8716
8717 \family typewriter 
8718 code unsigned char test_code;
8719 \layout Standard
8720
8721 Read access to this variable generates the assembly code:
8722 \layout Verse
8723
8724
8725 \family typewriter 
8726 90s00r6F\SpecialChar ~
8727 \SpecialChar ~
8728 \SpecialChar ~
8729 mov dptr,#_test_code
8730 \newline 
8731 E4\SpecialChar ~
8732 \SpecialChar ~
8733 \SpecialChar ~
8734 \SpecialChar ~
8735 \SpecialChar ~
8736 \SpecialChar ~
8737 \SpecialChar ~
8738 \SpecialChar ~
8739 \SpecialChar ~
8740 clr a
8741 \newline 
8742 93\SpecialChar ~
8743 \SpecialChar ~
8744 \SpecialChar ~
8745 \SpecialChar ~
8746 \SpecialChar ~
8747 \SpecialChar ~
8748 \SpecialChar ~
8749 \SpecialChar ~
8750 \SpecialChar ~
8751 movc a,@a+dptr 
8752 \layout Standard
8753
8754
8755 \family typewriter 
8756 char
8757 \family default 
8758  indexed arrays of characters in code memory can be accessed efficiently:
8759 \layout Verse
8760
8761
8762 \family typewriter 
8763 code char test_array[] = {'c','h','e','a','p'}; 
8764 \layout Standard
8765
8766 Read access to this array using an 8-bit unsigned index generates the assembly
8767  code:
8768 \layout Verse
8769
8770
8771 \family typewriter 
8772 E5*00\SpecialChar ~
8773 \SpecialChar ~
8774 \SpecialChar ~
8775 \SpecialChar ~
8776 \SpecialChar ~
8777 \SpecialChar ~
8778 mov a,_index 
8779 \layout Verse
8780
8781
8782 \family typewriter 
8783 90s00r41\SpecialChar ~
8784 \SpecialChar ~
8785 \SpecialChar ~
8786 mov dptr,#_test_array
8787 \layout Verse
8788
8789
8790 \family typewriter 
8791 93\SpecialChar ~
8792 \SpecialChar ~
8793 \SpecialChar ~
8794 \SpecialChar ~
8795 \SpecialChar ~
8796 \SpecialChar ~
8797 \SpecialChar ~
8798 \SpecialChar ~
8799 \SpecialChar ~
8800 movc a,@a+dptr 
8801 \layout Subsubsection
8802
8803 bit
8804 \begin_inset LatexCommand \index{bit}
8805
8806 \end_inset 
8807
8808
8809 \begin_inset LatexCommand \index{\_\_bit}
8810
8811 \end_inset 
8812
8813
8814 \layout Standard
8815
8816 This is a data-type and a storage class specifier.
8817  When a variable is declared as a bit, it is allocated into the bit addressable
8818  memory of 8051, e.g.:
8819 \layout Verse
8820
8821
8822 \family typewriter 
8823 bit test_bit;
8824 \layout Standard
8825
8826 Writing 1 to this variable generates the assembly code:
8827 \layout Verse
8828
8829
8830 \family typewriter 
8831 D2*00\SpecialChar ~
8832 \SpecialChar ~
8833 \SpecialChar ~
8834 \SpecialChar ~
8835 \SpecialChar ~
8836 \SpecialChar ~
8837 \SpecialChar ~
8838 setb\SpecialChar ~
8839 _test_bit
8840 \layout Standard
8841
8842 The bit addressable memory consists of 128 bits which are located from 0x20
8843  to 0x2f in data memory.
8844  
8845 \newline 
8846 Apart from this 8051 specific storage class most architectures support ANSI-C
8847  bitfields
8848 \begin_inset LatexCommand \index{bitfields}
8849
8850 \end_inset 
8851
8852
8853 \begin_inset Foot
8854 collapsed false
8855
8856 \layout Standard
8857
8858 Not really meant as examples, but nevertheless showing what bitfields are
8859  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
8860 \end_inset 
8861
8862 .
8863  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
8864  signed modifier are implemented as unsigned.
8865 \layout Subsubsection
8866
8867 sfr
8868 \begin_inset LatexCommand \index{sfr}
8869
8870 \end_inset 
8871
8872
8873 \begin_inset LatexCommand \index{\_\_sfr}
8874
8875 \end_inset 
8876
8877  / sbit
8878 \begin_inset LatexCommand \index{\_\_sbit}
8879
8880 \end_inset 
8881
8882
8883 \layout Standard
8884
8885 Like the bit keyword, 
8886 \emph on 
8887 sfr / sbit 
8888 \emph default 
8889 signifies both a data-type and storage class, they are used to describe
8890  the 
8891 \emph on 
8892 s
8893 \emph default 
8894 pecial 
8895 \emph on 
8896 f
8897 \emph default 
8898 unction 
8899 \emph on 
8900 r
8901 \emph default 
8902 egisters and 
8903 \emph on 
8904 s
8905 \emph default 
8906 pecial 
8907 \emph on 
8908 bit
8909 \emph default 
8910  variables of a 8051, eg:
8911 \layout Verse
8912
8913
8914 \family typewriter 
8915 sfr at
8916 \begin_inset LatexCommand \index{at}
8917
8918 \end_inset 
8919
8920
8921 \begin_inset LatexCommand \index{\_\_at}
8922
8923 \end_inset 
8924
8925  0x80 P0;\SpecialChar ~
8926  /* special function register P0 at location 0x80 */
8927 \newline 
8928 sbit at 0xd7 CY; /* CY (Carry Flag
8929 \begin_inset LatexCommand \index{Flags}
8930
8931 \end_inset 
8932
8933
8934 \begin_inset LatexCommand \index{Carry flag}
8935
8936 \end_inset 
8937
8938 ) */
8939 \layout Standard
8940
8941 Special function registers which are located on an address dividable by
8942  8 are bit-addressable, an
8943 \emph on 
8944  sbit
8945 \emph default 
8946  addresses a specific bit within these sfr.
8947 \layout Subsubsection
8948
8949 Pointers
8950 \begin_inset LatexCommand \index{Pointer}
8951
8952 \end_inset 
8953
8954  to MCS51/DS390 specific memory spaces
8955 \layout Standard
8956
8957 SDCC allows (via language extensions) pointers to explicitly point to any
8958  of the memory spaces
8959 \begin_inset LatexCommand \index{Memory model}
8960
8961 \end_inset 
8962
8963  of the 8051.
8964  In addition to the explicit pointers, the compiler uses (by default) generic
8965  pointers which can be used to point to any of the memory spaces.
8966 \newline 
8967
8968 \newline 
8969 Pointer declaration examples:
8970 \layout Verse
8971
8972
8973 \family typewriter 
8974 /* pointer physically in internal ram pointing to object in external ram
8975  */ 
8976 \newline 
8977 xdata unsigned char * data p;
8978 \newline 
8979
8980 \newline 
8981 /* pointer physically in external ram pointing to object in internal ram
8982  */ 
8983 \newline 
8984 data unsigned char * xdata p;
8985 \newline 
8986
8987 \newline 
8988 /* pointer physically in code rom pointing to data in xdata space */ 
8989 \newline 
8990 xdata unsigned char * code p;
8991 \newline 
8992
8993 \newline 
8994 /* pointer physically in code space pointing to data in code space */ 
8995 \newline 
8996 code unsigned char * code p;
8997 \newline 
8998
8999 \newline 
9000 /* the following is a generic pointer physically located in xdata space
9001  */
9002 \newline 
9003 char * xdata p;
9004 \layout Standard
9005
9006 Well you get the idea.
9007  
9008 \newline 
9009
9010 \newline 
9011 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
9012 \emph on 
9013 generic
9014 \emph default 
9015  pointers.
9016  
9017 \size small 
9018
9019 \newline 
9020
9021 \newline 
9022
9023 \size default 
9024 The highest order byte of the 
9025 \emph on 
9026 generic
9027 \emph default 
9028  pointers contains the data space information.
9029  Assembler support routines are called whenever data is stored or retrieved
9030  using 
9031 \emph on 
9032 generic
9033 \emph default 
9034  pointers.
9035  These are useful for developing reusable library
9036 \begin_inset LatexCommand \index{Libraries}
9037
9038 \end_inset 
9039
9040  routines.
9041  Explicitly specifying the pointer type will generate the most efficient
9042  code.
9043 \layout Subsubsection
9044
9045 Notes on MCS51 memory
9046 \begin_inset LatexCommand \index{MCS51 memory}
9047
9048 \end_inset 
9049
9050  layout
9051 \layout Standard
9052
9053 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
9054  RAM memory which is structured as follows:
9055 \newline 
9056
9057 \newline 
9058 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
9059  
9060 \newline 
9061 - Bytes 20-2F - 16 bytes to hold 128 bit
9062 \begin_inset LatexCommand \index{bit}
9063
9064 \end_inset 
9065
9066  variables and, 
9067 \newline 
9068 - Bytes 30-7F - 80 bytes for general purpose use.
9069 \newline 
9070
9071 \layout Standard
9072
9073 Additionally some members of the MCS51 family may have up to 128 bytes of
9074  additional, indirectly addressable, internal RAM memory (
9075 \emph on 
9076 idata
9077 \emph default 
9078
9079 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
9080
9081 \end_inset 
9082
9083
9084 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
9085
9086 \end_inset 
9087
9088 ).
9089  Furthermore, some chips may have some built in external memory (
9090 \emph on 
9091 xdata
9092 \emph default 
9093
9094 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9095
9096 \end_inset 
9097
9098
9099 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
9100
9101 \end_inset 
9102
9103 ) which should not be confused with the internal, directly addressable RAM
9104  memory (
9105 \emph on 
9106 data
9107 \emph default 
9108
9109 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
9110
9111 \end_inset 
9112
9113
9114 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
9115
9116 \end_inset 
9117
9118 ).
9119  Sometimes this built in 
9120 \emph on 
9121 xdata
9122 \emph default 
9123  memory has to be activated before using it (you can probably find this
9124  information on the datasheet of the microcontroller your are using, see
9125  also section 
9126 \begin_inset LatexCommand \ref{sub:Startup-Code}
9127
9128 \end_inset 
9129
9130 \SpecialChar ~
9131 Startup-Code).
9132 \layout Standard
9133
9134 Normally SDCC will only use the first bank
9135 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
9136
9137 \end_inset 
9138
9139  of registers (register bank 0), but it is possible to specify that other
9140  banks of registers (keyword 
9141 \emph on 
9142 using
9143 \emph default 
9144  
9145 \emph on 
9146
9147 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
9148
9149 \end_inset 
9150
9151
9152 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
9153
9154 \end_inset 
9155
9156
9157 \emph default 
9158 ) should be used in interrupt
9159 \begin_inset LatexCommand \index{interrupt}
9160
9161 \end_inset 
9162
9163
9164 \begin_inset LatexCommand \index{\_\_interrupt}
9165
9166 \end_inset 
9167
9168  routines.
9169  By default, the compiler will place the stack after the last byte of allocated
9170  memory for variables.
9171  For example, if the first 2 banks of registers are used, and only four
9172  bytes are used for 
9173 \emph on 
9174 data
9175 \emph default 
9176  variables, it will position the base of the internal stack at address 20
9177  (0x14).
9178  This implies that as the stack
9179 \begin_inset LatexCommand \index{stack}
9180
9181 \end_inset 
9182
9183  grows, it will use up the remaining register banks, and the 16 bytes used
9184  by the 128 bit variables, and 80 bytes for general purpose use.
9185  If any bit variables are used, the data variables will be placed in unused
9186  register banks and after the byte holding the last bit variable.
9187  For example, if register banks 0 and 1 are used, and there are 9 bit variables
9188  (two bytes used), 
9189 \emph on 
9190 data
9191 \emph default 
9192  variables will be placed starting from address 0x10 to 0x20 and continue
9193  at address 0x22.
9194  You can also use -
9195 \begin_inset ERT
9196 status Collapsed
9197
9198 \layout Standard
9199
9200 \backslash 
9201 /
9202 \end_inset 
9203
9204 -data-loc
9205 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
9206
9207 \end_inset 
9208
9209  to specify the start address of the 
9210 \emph on 
9211 data
9212 \emph default 
9213  and -
9214 \begin_inset ERT
9215 status Collapsed
9216
9217 \layout Standard
9218
9219 \backslash 
9220 /
9221 \end_inset 
9222
9223 -iram-size
9224 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
9225
9226 \end_inset 
9227
9228  to specify the size of the total internal RAM (
9229 \emph on 
9230 data
9231 \emph default 
9232 +
9233 \emph on 
9234 idata
9235 \emph default 
9236 ).
9237  
9238 \layout Standard
9239
9240 By default the 8051 linker will place the stack after the last byte of (i)data
9241  variables.
9242  Option -
9243 \begin_inset ERT
9244 status Collapsed
9245
9246 \layout Standard
9247
9248 \backslash 
9249 /
9250 \end_inset 
9251
9252 -stack-loc
9253 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
9254
9255 \end_inset 
9256
9257  allows you to specify the start of the stack, i.e.
9258  you could start it after any data in the general purpose area.
9259  If your microcontroller has additional indirectly addressable internal
9260  RAM (
9261 \emph on 
9262 idata
9263 \emph default 
9264 ) you can place the stack on it.
9265  You may also need to use -
9266 \begin_inset ERT
9267 status Collapsed
9268
9269 \layout Standard
9270
9271 \backslash 
9272 /
9273 \end_inset 
9274
9275 -xdata-loc
9276 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
9277
9278 \end_inset 
9279
9280  to set the start address of the external RAM (
9281 \emph on 
9282 xdata
9283 \emph default 
9284 ) and -
9285 \begin_inset ERT
9286 status Collapsed
9287
9288 \layout Standard
9289
9290 \backslash 
9291 /
9292 \end_inset 
9293
9294 -xram-size
9295 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
9296
9297 \end_inset 
9298
9299  to specify its size.
9300  Same goes for the code memory, using -
9301 \begin_inset ERT
9302 status Collapsed
9303
9304 \layout Standard
9305
9306 \backslash 
9307 /
9308 \end_inset 
9309
9310 -code-loc
9311 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
9312
9313 \end_inset 
9314
9315  and -
9316 \begin_inset ERT
9317 status Collapsed
9318
9319 \layout Standard
9320
9321 \backslash 
9322 /
9323 \end_inset 
9324
9325 -code-size
9326 \begin_inset LatexCommand \index{-\/-code-size <Value>}
9327
9328 \end_inset 
9329
9330 .
9331  If in doubt, don't specify any options and see if the resulting memory
9332  layout is appropriate, then you can adjust it.
9333 \layout Standard
9334
9335 The linker generates two files with memory allocation information.
9336  The first, with extension .map
9337 \begin_inset LatexCommand \index{<file>.map}
9338
9339 \end_inset 
9340
9341  shows all the variables and segments.
9342  The second with extension .mem
9343 \begin_inset LatexCommand \index{<file>.mem}
9344
9345 \end_inset 
9346
9347  shows the final memory layout.
9348  The linker will complain either if memory segments overlap, there is not
9349  enough memory, or there is not enough space for stack.
9350  If you get any linking warnings and/or errors related to stack or segments
9351  allocation, take a look at either the .map or .mem files to find out what
9352  the problem is.
9353  The .mem file may even suggest a solution to the problem.
9354 \layout Subsection
9355
9356 Z80/Z180 Storage Class
9357 \begin_inset LatexCommand \index{Storage class}
9358
9359 \end_inset 
9360
9361  Language Extensions
9362 \layout Subsubsection
9363
9364 sfr
9365 \begin_inset LatexCommand \index{sfr}
9366
9367 \end_inset 
9368
9369
9370 \begin_inset LatexCommand \index{\_\_sfr}
9371
9372 \end_inset 
9373
9374  (in/out to 8-bit addresses)
9375 \layout Standard
9376
9377 The Z80
9378 \begin_inset LatexCommand \index{Z80}
9379
9380 \end_inset 
9381
9382  family has separate address spaces for memory and 
9383 \emph on 
9384 i
9385 \emph default 
9386 nput/
9387 \emph on 
9388 o
9389 \emph default 
9390 utput memory.
9391  I/O memory
9392 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
9393
9394 \end_inset 
9395
9396  is accessed with special instructions, e.g.:
9397 \layout Verse
9398
9399
9400 \family typewriter 
9401 sfr at 0x78 IoPort;\SpecialChar ~
9402 \SpecialChar ~
9403 /* define a var in I/O space at 78h called IoPort */
9404  
9405 \layout Standard
9406
9407 Writing 0x01 to this variable generates the assembly code:
9408 \layout Verse
9409
9410
9411 \family typewriter 
9412 3E 01\SpecialChar ~
9413 \SpecialChar ~
9414 \SpecialChar ~
9415 \SpecialChar ~
9416 \SpecialChar ~
9417 \SpecialChar ~
9418 ld a,#0x01
9419 \newline 
9420 D3 78\SpecialChar ~
9421 \SpecialChar ~
9422 \SpecialChar ~
9423 \SpecialChar ~
9424 \SpecialChar ~
9425 \SpecialChar ~
9426 out (_IoPort),a 
9427 \layout Subsubsection
9428
9429 banked sfr
9430 \begin_inset LatexCommand \index{sfr}
9431
9432 \end_inset 
9433
9434
9435 \begin_inset LatexCommand \index{\_\_sfr}
9436
9437 \end_inset 
9438
9439  (in/out to 16-bit addresses)
9440 \layout Standard
9441
9442 The keyword 
9443 \emph on 
9444 banked
9445 \emph default 
9446  is used to support 16 bit addresses in I/O memory e.g.:
9447 \layout Verse
9448
9449
9450 \family typewriter 
9451 sfr banked at
9452 \begin_inset LatexCommand \index{at}
9453
9454 \end_inset 
9455
9456
9457 \begin_inset LatexCommand \index{\_\_at}
9458
9459 \end_inset 
9460
9461  0x123 IoPort; 
9462 \layout Standard
9463
9464 Writing 0x01 to this variable generates the assembly code:
9465 \layout Verse
9466
9467
9468 \family typewriter 
9469 01 23 01\SpecialChar ~
9470 \SpecialChar ~
9471 \SpecialChar ~
9472 ld bc,#_IoPort
9473 \newline 
9474 3E 01\SpecialChar ~
9475 \SpecialChar ~
9476 \SpecialChar ~
9477 \SpecialChar ~
9478 \SpecialChar ~
9479 \SpecialChar ~
9480 ld a,#0x01 
9481 \newline 
9482 ED 79\SpecialChar ~
9483 \SpecialChar ~
9484 \SpecialChar ~
9485 \SpecialChar ~
9486 \SpecialChar ~
9487 \SpecialChar ~
9488 out (c),a 
9489 \layout Subsubsection
9490
9491 sfr
9492 \begin_inset LatexCommand \index{sfr}
9493
9494 \end_inset 
9495
9496
9497 \begin_inset LatexCommand \index{\_\_sfr}
9498
9499 \end_inset 
9500
9501  (in0/out0 to 8 bit addresses on Z180
9502 \begin_inset LatexCommand \index{Z180}
9503
9504 \end_inset 
9505
9506 /HD64180
9507 \begin_inset LatexCommand \index{HD64180}
9508
9509 \end_inset 
9510
9511 )
9512 \layout Standard
9513
9514 The compiler option -
9515 \begin_inset ERT
9516 status Collapsed
9517
9518 \layout Standard
9519
9520 \backslash 
9521 /
9522 \end_inset 
9523
9524 -portmode=180 (80) and a compiler #pragma\SpecialChar ~
9525 portmode
9526 \begin_inset LatexCommand \index{\#pragma portmode}
9527
9528 \end_inset 
9529
9530 =z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
9531 ns 
9532 \family typewriter 
9533 in0/out0
9534 \family default 
9535  instead of 
9536 \family typewriter 
9537 in/out
9538 \family default 
9539 .
9540  If you include the file z180.h this will be set automatically.
9541 \layout Subsection
9542
9543 HC08 Storage Class
9544 \begin_inset LatexCommand \index{Storage class}
9545
9546 \end_inset 
9547
9548  Language Extensions
9549 \layout Subsubsection
9550
9551 data
9552 \begin_inset LatexCommand \index{data (hc08 storage class)}
9553
9554 \end_inset 
9555
9556
9557 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
9558
9559 \end_inset 
9560
9561  
9562 \layout Standard
9563
9564 The data storage class declares a variable that resides in the first 256
9565  bytes of memory (the direct page).
9566  The HC08 is most efficient at accessing variables (especially pointers)
9567  stored here.
9568 \layout Subsubsection
9569
9570 xdata
9571 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
9572
9573 \end_inset 
9574
9575
9576 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
9577
9578 \end_inset 
9579
9580  
9581 \layout Standard
9582
9583 The xdata storage class declares a variable that can reside anywhere in
9584  memory.
9585  This is the default if no storage class is specified.
9586  
9587 \layout Section
9588
9589 Absolute Addressing
9590 \begin_inset LatexCommand \index{Absolute addressing}
9591
9592 \end_inset 
9593
9594
9595 \layout Standard
9596
9597 Data items can be assigned an absolute address with the 
9598 \emph on 
9599 at
9600 \begin_inset LatexCommand \index{at}
9601
9602 \end_inset 
9603
9604
9605 \begin_inset LatexCommand \index{\_\_at}
9606
9607 \end_inset 
9608
9609  <address>
9610 \emph default 
9611  keyword, in addition to a storage class, e.g.:
9612 \layout Verse
9613
9614
9615 \family typewriter 
9616 xdata
9617 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9618
9619 \end_inset 
9620
9621
9622 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
9623
9624 \end_inset 
9625
9626  at
9627 \begin_inset LatexCommand \index{at}
9628
9629 \end_inset 
9630
9631
9632 \begin_inset LatexCommand \index{\_\_at}
9633
9634 \end_inset 
9635
9636  0x7ffe unsigned int chksum;
9637 \layout Standard
9638
9639 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
9640  of the external ram.
9641  The compiler does 
9642 \emph on 
9643 not
9644 \emph default 
9645  reserve any space for variables declared in this way (they are implemented
9646  with an equate in the assembler).
9647  Thus it is left to the programmer to make sure there are no overlaps with
9648  other variables that are declared without the absolute address.
9649  The assembler listing file (.lst
9650 \begin_inset LatexCommand \index{<file>.lst}
9651
9652 \end_inset 
9653
9654 ) and the linker output files (.rst
9655 \begin_inset LatexCommand \index{<file>.rst}
9656
9657 \end_inset 
9658
9659 ) and (.map
9660 \begin_inset LatexCommand \index{<file>.map}
9661
9662 \end_inset 
9663
9664 ) are good places to look for such overlaps.
9665  Variables with an absolute address are 
9666 \emph on 
9667 not
9668 \emph default 
9669  initialized
9670 \begin_inset LatexCommand \index{Variable initialization}
9671
9672 \end_inset 
9673
9674 .
9675 \layout Standard
9676
9677 In case of memory mapped I/O devices the keyword 
9678 \emph on 
9679 volatile
9680 \emph default 
9681  has to be used to tell the compiler that accesses might not be removed:
9682 \layout Verse
9683
9684
9685 \family typewriter 
9686 volatile
9687 \begin_inset LatexCommand \index{volatile}
9688
9689 \end_inset 
9690
9691  xdata
9692 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9693
9694 \end_inset 
9695
9696  at
9697 \begin_inset LatexCommand \index{at}
9698
9699 \end_inset 
9700
9701  0x8000 unsigned char PORTA_8255;
9702 \layout Standard
9703
9704 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
9705 r) array
9706 \family typewriter 
9707 \size footnotesize 
9708
9709 \begin_inset LatexCommand \index{Aligned array}
9710
9711 \end_inset 
9712
9713
9714 \family default 
9715 \size default 
9716  starts at a block (256 byte) boundary
9717 \begin_inset LatexCommand \index{block boundary}
9718
9719 \end_inset 
9720
9721  (section 
9722 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
9723
9724 \end_inset 
9725
9726  has an example).
9727 \newline 
9728 Absolute addresses can be specified for variables in all storage classes,
9729  e.g.:
9730 \layout Verse
9731
9732
9733 \family typewriter 
9734 bit
9735 \begin_inset LatexCommand \index{bit}
9736
9737 \end_inset 
9738
9739  at
9740 \begin_inset LatexCommand \index{at}
9741
9742 \end_inset 
9743
9744  0x02 bvar;
9745 \layout Standard
9746
9747 The above example will allocate the variable at offset 0x02 in the bit-addressab
9748 le space.
9749  There is no real advantage to assigning absolute addresses to variables
9750  in this manner, unless you want strict control over all the variables allocated.
9751  One possible use would be to write hardware portable code.
9752  For example, if you have a routine that uses one or more of the microcontroller
9753  I/O pins, and such pins are different for two different hardwares, you
9754  can declare the I/O pins in your routine using:
9755 \layout Verse
9756
9757
9758 \family typewriter 
9759 extern volatile
9760 \begin_inset LatexCommand \index{volatile}
9761
9762 \end_inset 
9763
9764  bit MOSI;\SpecialChar ~
9765 \SpecialChar ~
9766 \SpecialChar ~
9767 \SpecialChar ~
9768 /* master out, slave in */
9769 \newline 
9770 extern volatile bit MISO;\SpecialChar ~
9771 \SpecialChar ~
9772 \SpecialChar ~
9773 \SpecialChar ~
9774 /* master in, slave out */
9775 \newline 
9776 extern volatile bit MCLK;\SpecialChar ~
9777 \SpecialChar ~
9778 \SpecialChar ~
9779 \SpecialChar ~
9780 /* master clock */
9781 \newline 
9782
9783 \newline 
9784 /* Input and Output of a byte on a 3-wire serial bus.
9785 \newline 
9786 \SpecialChar ~
9787 \SpecialChar ~
9788 \SpecialChar ~
9789 If needed adapt polarity of clock, polarity of data and bit order
9790 \newline 
9791 \SpecialChar ~
9792 */
9793 \newline 
9794 unsigned char spi_io(unsigned char out_byte) 
9795 \newline 
9796
9797 \newline 
9798 \SpecialChar ~
9799 \SpecialChar ~
9800 \SpecialChar ~
9801 \SpecialChar ~
9802 unsigned char i=8;
9803 \newline 
9804 \SpecialChar ~
9805 \SpecialChar ~
9806 \SpecialChar ~
9807 \SpecialChar ~
9808 do { 
9809 \newline 
9810 \SpecialChar ~
9811 \SpecialChar ~
9812 \SpecialChar ~
9813 \SpecialChar ~
9814 \SpecialChar ~
9815 \SpecialChar ~
9816 \SpecialChar ~
9817 \SpecialChar ~
9818 MOSI = out_byte & 0x80; 
9819 \newline 
9820 \SpecialChar ~
9821 \SpecialChar ~
9822 \SpecialChar ~
9823 \SpecialChar ~
9824 \SpecialChar ~
9825 \SpecialChar ~
9826 \SpecialChar ~
9827 \SpecialChar ~
9828 out_byte <<= 1;
9829 \newline 
9830 \SpecialChar ~
9831 \SpecialChar ~
9832 \SpecialChar ~
9833 \SpecialChar ~
9834 \SpecialChar ~
9835 \SpecialChar ~
9836 \SpecialChar ~
9837 \SpecialChar ~
9838 MCLK = 1; 
9839 \newline 
9840 \SpecialChar ~
9841 \SpecialChar ~
9842 \SpecialChar ~
9843 \SpecialChar ~
9844 \SpecialChar ~
9845 \SpecialChar ~
9846 \SpecialChar ~
9847 \SpecialChar ~
9848 /* _asm nop _endasm; */\SpecialChar ~
9849 \SpecialChar ~
9850 \SpecialChar ~
9851 \SpecialChar ~
9852 \SpecialChar ~
9853 \SpecialChar ~
9854 \SpecialChar ~
9855 \SpecialChar ~
9856 /* for slow peripherals */
9857 \newline 
9858 \SpecialChar ~
9859 \SpecialChar ~
9860 \SpecialChar ~
9861 \SpecialChar ~
9862 \SpecialChar ~
9863 \SpecialChar ~
9864 \SpecialChar ~
9865 \SpecialChar ~
9866 if(MISO) 
9867 \newline 
9868 \SpecialChar ~
9869 \SpecialChar ~
9870 \SpecialChar ~
9871 \SpecialChar ~
9872 \SpecialChar ~
9873 \SpecialChar ~
9874 \SpecialChar ~
9875 \SpecialChar ~
9876 \SpecialChar ~
9877 \SpecialChar ~
9878 \SpecialChar ~
9879 \SpecialChar ~
9880 out_byte += 1; 
9881 \newline 
9882 \SpecialChar ~
9883 \SpecialChar ~
9884 \SpecialChar ~
9885 \SpecialChar ~
9886 \SpecialChar ~
9887 \SpecialChar ~
9888 \SpecialChar ~
9889 \SpecialChar ~
9890 MCLK = 0; 
9891 \newline 
9892 \SpecialChar ~
9893 \SpecialChar ~
9894 \SpecialChar ~
9895 \SpecialChar ~
9896 } while(--i);
9897 \newline 
9898 \SpecialChar ~
9899 \SpecialChar ~
9900 \SpecialChar ~
9901 \SpecialChar ~
9902 return out_byte; 
9903 \newline 
9904 }
9905 \layout Standard
9906
9907 Then, someplace in the code for the first hardware you would use
9908 \layout Verse
9909
9910
9911 \family typewriter 
9912 bit at
9913 \begin_inset LatexCommand \index{at}
9914
9915 \end_inset 
9916
9917
9918 \begin_inset LatexCommand \index{\_\_at}
9919
9920 \end_inset 
9921
9922  0x80 MOSI;\SpecialChar ~
9923 \SpecialChar ~
9924 \SpecialChar ~
9925 \SpecialChar ~
9926 /* I/O port 0, bit 0 */
9927 \newline 
9928 bit at 0x81 MISO;\SpecialChar ~
9929 \SpecialChar ~
9930 \SpecialChar ~
9931 \SpecialChar ~
9932 /* I/O port 0, bit 1 */
9933 \newline 
9934 bit at 0x82 MCLK;\SpecialChar ~
9935 \SpecialChar ~
9936 \SpecialChar ~
9937 \SpecialChar ~
9938 /* I/O port 0, bit 2 */
9939 \layout Standard
9940
9941 Similarly, for the second hardware you would use
9942 \layout Verse
9943
9944
9945 \family typewriter 
9946 bit at 0x83 MOSI;\SpecialChar ~
9947 \SpecialChar ~
9948 \SpecialChar ~
9949 \SpecialChar ~
9950 /* I/O port 0, bit 3 */
9951 \newline 
9952 bit at 0x91 MISO;\SpecialChar ~
9953 \SpecialChar ~
9954 \SpecialChar ~
9955 \SpecialChar ~
9956 /* I/O port 1, bit 1 */
9957 \newline 
9958 bit
9959 \begin_inset LatexCommand \index{bit}
9960
9961 \end_inset 
9962
9963  at 0x92 MCLK;\SpecialChar ~
9964 \SpecialChar ~
9965 \SpecialChar ~
9966 \SpecialChar ~
9967 /* I/O port 1, bit 2 */
9968 \layout Standard
9969
9970 and you can use the same hardware dependent routine without changes, as
9971  for example in a library.
9972  This is somehow similar to sbit, but only one absolute address has to be
9973  specified in the whole project.
9974 \layout Section
9975
9976 Parameters
9977 \begin_inset LatexCommand \index{Parameters}
9978
9979 \end_inset 
9980
9981
9982 \begin_inset LatexCommand \index{function parameter}
9983
9984 \end_inset 
9985
9986  & Local Variables
9987 \begin_inset LatexCommand \index{local variables}
9988
9989 \end_inset 
9990
9991
9992 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
9993
9994 \end_inset 
9995
9996
9997 \layout Standard
9998
9999 Automatic (local) variables and parameters to functions can either be placed
10000  on the stack or in data-space.
10001  The default action of the compiler is to place these variables in the internal
10002  RAM (for small model) or external RAM (for large model).
10003  This in fact makes them similar to 
10004 \emph on 
10005 static
10006 \begin_inset LatexCommand \index{static}
10007
10008 \end_inset 
10009
10010
10011 \emph default 
10012  so by default functions are non-reentrant
10013 \begin_inset LatexCommand \index{reentrant}
10014
10015 \end_inset 
10016
10017 .
10018  
10019 \newline 
10020
10021 \newline 
10022 They can be placed on the stack
10023 \begin_inset LatexCommand \index{stack}
10024
10025 \end_inset 
10026
10027  by using the
10028 \emph on 
10029  -
10030 \begin_inset ERT
10031 status Collapsed
10032
10033 \layout Standard
10034
10035 \backslash 
10036 /
10037 \end_inset 
10038
10039 -stack-auto
10040 \begin_inset LatexCommand \index{-\/-stack-auto}
10041
10042 \end_inset 
10043
10044
10045 \emph default 
10046  option, by using 
10047 \emph on 
10048 #pragma\SpecialChar ~
10049 stackauto
10050 \emph default 
10051
10052 \begin_inset LatexCommand \index{\#pragma stackauto}
10053
10054 \end_inset 
10055
10056  or by using the 
10057 \emph on 
10058 reentrant
10059 \begin_inset LatexCommand \index{reentrant}
10060
10061 \end_inset 
10062
10063
10064 \emph default 
10065  keyword in the function declaration, e.g.:
10066 \layout Verse
10067
10068
10069 \family typewriter 
10070 unsigned char foo(char i) reentrant 
10071 \newline 
10072
10073 \newline 
10074 \SpecialChar ~
10075 \SpecialChar ~
10076 \SpecialChar ~
10077 \SpecialChar ~
10078 ...
10079  
10080 \newline 
10081 }
10082 \layout Standard
10083
10084 Since stack space on 8051 is limited, the 
10085 \emph on 
10086 reentrant 
10087 \emph default 
10088 keyword or the
10089 \emph on 
10090  -
10091 \begin_inset ERT
10092 status Collapsed
10093
10094 \layout Standard
10095
10096 \backslash 
10097 /
10098 \end_inset 
10099
10100 -stack-auto
10101 \emph default 
10102  option should be used sparingly.
10103  Note that the reentrant keyword just means that the parameters & local
10104  variables will be allocated to the stack, it 
10105 \emph on 
10106 does not
10107 \emph default 
10108  mean that the function is register bank
10109 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
10110
10111 \end_inset 
10112
10113  independent.
10114 \newline 
10115
10116 \newline 
10117 Local variables
10118 \begin_inset LatexCommand \index{local variables}
10119
10120 \end_inset 
10121
10122  can be assigned storage classes and absolute
10123 \begin_inset LatexCommand \index{Absolute addressing}
10124
10125 \end_inset 
10126
10127  addresses, e.g.: 
10128 \layout Verse
10129
10130
10131 \family typewriter 
10132 unsigned char foo() 
10133 \newline 
10134 {
10135 \newline 
10136 \SpecialChar ~
10137 \SpecialChar ~
10138 \SpecialChar ~
10139 \SpecialChar ~
10140 xdata unsigned char i;
10141 \newline 
10142 \SpecialChar ~
10143 \SpecialChar ~
10144 \SpecialChar ~
10145 \SpecialChar ~
10146 bit bvar;
10147 \newline 
10148 \SpecialChar ~
10149 \SpecialChar ~
10150 \SpecialChar ~
10151 \SpecialChar ~
10152 data at
10153 \begin_inset LatexCommand \index{at}
10154
10155 \end_inset 
10156
10157  0x31 unsigned char j;
10158 \newline 
10159 \SpecialChar ~
10160 \SpecialChar ~
10161 \SpecialChar ~
10162 \SpecialChar ~
10163 ...
10164  
10165 \newline 
10166 }
10167 \layout Standard
10168
10169 In the above example the variable 
10170 \emph on 
10171 i
10172 \emph default 
10173  will be allocated in the external ram, 
10174 \emph on 
10175 bvar
10176 \emph default 
10177  in bit addressable space and
10178 \emph on 
10179  j
10180 \emph default 
10181  in internal ram.
10182  When compiled with 
10183 \emph on 
10184 -
10185 \begin_inset ERT
10186 status Collapsed
10187
10188 \layout Standard
10189
10190 \backslash 
10191 /
10192 \end_inset 
10193
10194 -stack-auto
10195 \emph default 
10196  or when a function is declared as 
10197 \emph on 
10198 reentrant
10199 \emph default 
10200  this should only be done for static variables.
10201 \layout Standard
10202
10203 Parameters
10204 \begin_inset LatexCommand \index{function parameter}
10205
10206 \end_inset 
10207
10208  however are not allowed any storage class
10209 \begin_inset LatexCommand \index{Storage class}
10210
10211 \end_inset 
10212
10213 , (storage classes for parameters will be ignored), their allocation is
10214  governed by the memory model in use, and the reentrancy options.
10215 \layout Section
10216
10217 Overlaying
10218 \begin_inset LatexCommand \label{sub:Overlaying}
10219
10220 \end_inset 
10221
10222
10223 \begin_inset LatexCommand \index{Overlaying}
10224
10225 \end_inset 
10226
10227
10228 \layout Standard
10229
10230 For non-reentrant
10231 \begin_inset LatexCommand \index{reentrant}
10232
10233 \end_inset 
10234
10235  functions SDCC will try to reduce internal ram space usage by overlaying
10236  parameters and local variables of a function (if possible).
10237  Parameters and local variables
10238 \begin_inset LatexCommand \index{local variables}
10239
10240 \end_inset 
10241
10242  of a function will be allocated to an overlayable segment if the function
10243  has 
10244 \emph on 
10245 no other function calls and the function is non-reentrant and the memory
10246  model
10247 \begin_inset LatexCommand \index{Memory model}
10248
10249 \end_inset 
10250
10251  is small.
10252
10253 \emph default 
10254  If an explicit storage class
10255 \begin_inset LatexCommand \index{Storage class}
10256
10257 \end_inset 
10258
10259  is specified for a local variable, it will NOT be overlayed.
10260 \layout Standard
10261
10262 Note that the compiler (not the linkage editor) makes the decision for overlayin
10263 g the data items.
10264  Functions that are called from an interrupt service routine should be preceded
10265  by a #pragma\SpecialChar ~
10266 nooverlay
10267 \begin_inset LatexCommand \index{\#pragma nooverlay}
10268
10269 \end_inset 
10270
10271  if they are not reentrant.
10272 \layout Standard
10273
10274 Also note that the compiler does not do any processing of inline assembler
10275  code, so the compiler might incorrectly assign local variables and parameters
10276  of a function into the overlay segment if the inline assembler code calls
10277  other c-functions that might use the overlay.
10278  In that case the #pragma\SpecialChar ~
10279 nooverlay should be used.
10280 \layout Standard
10281
10282 Parameters and local variables of functions that contain 16 or 32 bit multiplica
10283 tion
10284 \begin_inset LatexCommand \index{Multiplication}
10285
10286 \end_inset 
10287
10288  or division
10289 \begin_inset LatexCommand \index{Division}
10290
10291 \end_inset 
10292
10293  will NOT be overlayed since these are implemented using external functions,
10294  e.g.:
10295 \layout Verse
10296
10297
10298 \family typewriter 
10299 #pragma save 
10300 \newline 
10301 #pragma nooverlay
10302 \begin_inset LatexCommand \index{\#pragma nooverlay}
10303
10304 \end_inset 
10305
10306  
10307 \newline 
10308 void set_error(unsigned char errcd) 
10309 \newline 
10310 {
10311 \newline 
10312 \SpecialChar ~
10313 \SpecialChar ~
10314 \SpecialChar ~
10315 \SpecialChar ~
10316 P3 = errcd;
10317 \newline 
10318
10319 \newline 
10320 #pragma restore 
10321 \newline 
10322
10323 \newline 
10324 void some_isr () interrupt
10325 \begin_inset LatexCommand \index{interrupt}
10326
10327 \end_inset 
10328
10329  2
10330 \newline 
10331 {
10332 \newline 
10333 \SpecialChar ~
10334 \SpecialChar ~
10335 \SpecialChar ~
10336 \SpecialChar ~
10337 ...
10338 \newline 
10339 \SpecialChar ~
10340 \SpecialChar ~
10341 \SpecialChar ~
10342 \SpecialChar ~
10343 set_error(10);
10344 \newline 
10345 \SpecialChar ~
10346 \SpecialChar ~
10347 \SpecialChar ~
10348 \SpecialChar ~
10349 ...
10350  
10351 \newline 
10352 }
10353 \layout Standard
10354
10355 In the above example the parameter 
10356 \emph on 
10357 errcd
10358 \emph default 
10359  for the function 
10360 \emph on 
10361 set_error
10362 \emph default 
10363  would be assigned to the overlayable segment if the #pragma\SpecialChar ~
10364 nooverlay was
10365  not present, this could cause unpredictable runtime behavior when called
10366  from an interrupt service routine.
10367  The #pragma\SpecialChar ~
10368 nooverlay ensures that the parameters and local variables for
10369  the function are NOT overlayed.
10370 \layout Section
10371
10372 Interrupt Service Routines
10373 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
10374
10375 \end_inset 
10376
10377
10378 \layout Subsection
10379
10380 General Information
10381 \layout Standard
10382
10383 SDCC allows 
10384 \emph on 
10385 i
10386 \emph default 
10387 nterrupt 
10388 \emph on 
10389 s
10390 \emph default 
10391 ervice 
10392 \emph on 
10393 r
10394 \emph default 
10395 outines to be coded in C, with some extended keywords.
10396 \layout Verse
10397
10398
10399 \family typewriter 
10400 void timer_isr (void) interrupt 1 using 1 
10401 \newline 
10402
10403 \newline 
10404 \SpecialChar ~
10405 \SpecialChar ~
10406 \SpecialChar ~
10407 \SpecialChar ~
10408 ...
10409  
10410 \newline 
10411 }
10412 \layout Standard
10413
10414 The optional number following the 
10415 \emph on 
10416 interrupt
10417 \begin_inset LatexCommand \index{interrupt}
10418
10419 \end_inset 
10420
10421
10422 \begin_inset LatexCommand \index{\_\_interrupt}
10423
10424 \end_inset 
10425
10426
10427 \emph default 
10428  keyword is the interrupt number this routine will service.
10429  When present, the compiler will insert a call to this routine in the interrupt
10430  vector table for the interrupt number specified.
10431  If you have multiple source files in your project, interrupt service routines
10432  can be present in any of them, but a prototype of the isr MUST be present
10433  or included in the file that contains the function 
10434 \emph on 
10435 main
10436 \emph default 
10437 .
10438  The optional 
10439 \emph on 
10440 using
10441 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10442
10443 \end_inset 
10444
10445
10446 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
10447
10448 \end_inset 
10449
10450
10451 \emph default 
10452  keyword can be used to tell the compiler to use the specified register
10453  bank (8051 specific) when generating code for this function.
10454  
10455 \newline 
10456
10457 \layout Standard
10458
10459 Interrupt service routines open the door for some very interesting bugs:
10460 \newline 
10461 If an interrupt service routine changes variables which are accessed by
10462  other functions these variables have to be declared 
10463 \emph on 
10464 volatile
10465 \emph default 
10466
10467 \begin_inset LatexCommand \index{volatile}
10468
10469 \end_inset 
10470
10471 .
10472  
10473 \layout Standard
10474
10475 If the access to these variables is not 
10476 \emph on 
10477 atomic
10478 \begin_inset LatexCommand \index{atomic}
10479
10480 \end_inset 
10481
10482
10483 \emph default 
10484  (i.e.
10485  the processor needs more than one instruction for the access and could
10486  be interrupted while accessing the variable) the interrupt must be disabled
10487  during the access to avoid inconsistent data.
10488  Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
10489  and should be protected by disabling interrupts.
10490  You're not automatically on the safe side if you use 8 bit variables though.
10491  We need an example here: f.e.
10492  on the 8051 the harmless looking 
10493 \begin_inset Quotes srd
10494 \end_inset 
10495
10496
10497 \family typewriter 
10498 flags\SpecialChar ~
10499 |=\SpecialChar ~
10500 0x80;
10501 \family default 
10502
10503 \begin_inset Quotes sld
10504 \end_inset 
10505
10506  is not atomic if 
10507 \family typewriter 
10508 flags
10509 \family default 
10510  resides in xdata.
10511  Setting 
10512 \begin_inset Quotes srd
10513 \end_inset 
10514
10515
10516 \family typewriter 
10517 flags\SpecialChar ~
10518 |=\SpecialChar ~
10519 0x40;
10520 \family default 
10521
10522 \begin_inset Quotes sld
10523 \end_inset 
10524
10525  from within an interrupt routine might get lost if the interrupt occurs
10526  at the wrong time.
10527  
10528 \begin_inset Quotes sld
10529 \end_inset 
10530
10531
10532 \family typewriter 
10533 counter\SpecialChar ~
10534 +=\SpecialChar ~
10535 8;
10536 \family default 
10537
10538 \begin_inset Quotes srd
10539 \end_inset 
10540
10541  is not atomic on the 8051 even if 
10542 \family typewriter 
10543 counter
10544 \family default 
10545  is located in data memory.
10546  Bugs like these are hard to reproduce and can cause a lot of trouble.
10547  
10548 \layout Standard
10549
10550 The return address and the registers used in the interrupt service routine
10551  are saved on the stack
10552 \begin_inset LatexCommand \index{stack}
10553
10554 \end_inset 
10555
10556  so there must be sufficient stack space.
10557  If there isn't variables or registers (or even the return address itself)
10558  will be corrupted.
10559  This 
10560 \emph on 
10561 stack overflow
10562 \emph default 
10563
10564 \begin_inset LatexCommand \index{stack overflow}
10565
10566 \end_inset 
10567
10568  is most likely to happen if the interrupt occurs during the 
10569 \begin_inset Quotes sld
10570 \end_inset 
10571
10572 deepest
10573 \begin_inset Quotes srd
10574 \end_inset 
10575
10576  subroutine when the stack is already in use for f.e.
10577  many return addresses.
10578 \layout Standard
10579
10580 A special note here, int (16 bit) and long (32 bit) integer division
10581 \begin_inset LatexCommand \index{Division}
10582
10583 \end_inset 
10584
10585 , multiplication
10586 \begin_inset LatexCommand \index{Multiplication}
10587
10588 \end_inset 
10589
10590  & modulus
10591 \begin_inset LatexCommand \index{Modulus}
10592
10593 \end_inset 
10594
10595  and floating-point
10596 \begin_inset LatexCommand \index{Floating point support}
10597
10598 \end_inset 
10599
10600  operations are implemented using external support routines developed in
10601  ANSI-C.
10602  If an interrupt service routine needs to do any of these operations then
10603  the support routines (as mentioned in a following section) will have to
10604  be recompiled using the
10605 \emph on 
10606  -
10607 \begin_inset ERT
10608 status Collapsed
10609
10610 \layout Standard
10611
10612 \backslash 
10613 /
10614 \end_inset 
10615
10616 -stack-auto
10617 \begin_inset LatexCommand \index{-\/-stack-auto}
10618
10619 \end_inset 
10620
10621
10622 \emph default 
10623  option and the source file will need to be compiled using the 
10624 \emph on 
10625 -
10626 \begin_inset ERT
10627 status Collapsed
10628
10629 \layout Standard
10630
10631 \backslash 
10632 /
10633 \end_inset 
10634
10635 -int-long-reent
10636 \emph default 
10637
10638 \begin_inset LatexCommand \index{-\/-int-long-reent}
10639
10640 \end_inset 
10641
10642  compiler option.
10643 \layout Standard
10644
10645 Calling other functions from an interrupt service routine is not recommended,
10646  avoid it if possible.
10647  Note that when some function is called from an interrupt service routine
10648  it should be preceded by a #pragma\SpecialChar ~
10649 nooverlay
10650 \begin_inset LatexCommand \index{\#pragma nooverlay}
10651
10652 \end_inset 
10653
10654  if it is not reentrant.
10655  Furthermore nonreentrant functions should not be called from the main program
10656  while the interrupt service routine might be active.
10657  
10658 \newline 
10659
10660 \newline 
10661 Also see section 
10662 \begin_inset LatexCommand \ref{sub:Overlaying}
10663
10664 \end_inset 
10665
10666 \SpecialChar ~
10667 about Overlaying and section 
10668 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
10669
10670 \end_inset 
10671
10672 \SpecialChar ~
10673 about Functions using private register banks.
10674 \layout Subsection
10675
10676 MCS51/DS390 Interrupt Service Routines
10677 \layout Standard
10678
10679 Interrupt numbers and the corresponding address & descriptions for the Standard
10680  8051/8052 are listed below.
10681  SDCC will automatically adjust the interrupt vector table to the maximum
10682  interrupt number specified.
10683 \newline 
10684
10685 \layout Standard
10686 \align center 
10687
10688 \begin_inset  Tabular
10689 <lyxtabular version="3" rows="7" columns="3">
10690 <features>
10691 <column alignment="center" valignment="top" leftline="true" width="0in">
10692 <column alignment="center" valignment="top" leftline="true" width="0in">
10693 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0in">
10694 <row topline="true" bottomline="true">
10695 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10696 \begin_inset Text
10697
10698 \layout Standard
10699
10700 Interrupt #
10701 \end_inset 
10702 </cell>
10703 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10704 \begin_inset Text
10705
10706 \layout Standard
10707
10708 Description
10709 \end_inset 
10710 </cell>
10711 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10712 \begin_inset Text
10713
10714 \layout Standard
10715
10716 Vector Address
10717 \end_inset 
10718 </cell>
10719 </row>
10720 <row topline="true">
10721 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10722 \begin_inset Text
10723
10724 \layout Standard
10725
10726 0
10727 \end_inset 
10728 </cell>
10729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10730 \begin_inset Text
10731
10732 \layout Standard
10733
10734 External 0
10735 \end_inset 
10736 </cell>
10737 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10738 \begin_inset Text
10739
10740 \layout Standard
10741
10742 0x0003
10743 \end_inset 
10744 </cell>
10745 </row>
10746 <row topline="true">
10747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10748 \begin_inset Text
10749
10750 \layout Standard
10751
10752 1
10753 \end_inset 
10754 </cell>
10755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10756 \begin_inset Text
10757
10758 \layout Standard
10759
10760 Timer 0
10761 \end_inset 
10762 </cell>
10763 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10764 \begin_inset Text
10765
10766 \layout Standard
10767
10768 0x000B
10769 \end_inset 
10770 </cell>
10771 </row>
10772 <row topline="true">
10773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10774 \begin_inset Text
10775
10776 \layout Standard
10777
10778 2
10779 \end_inset 
10780 </cell>
10781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10782 \begin_inset Text
10783
10784 \layout Standard
10785
10786 External 1
10787 \end_inset 
10788 </cell>
10789 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10790 \begin_inset Text
10791
10792 \layout Standard
10793
10794 0x0013
10795 \end_inset 
10796 </cell>
10797 </row>
10798 <row topline="true">
10799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10800 \begin_inset Text
10801
10802 \layout Standard
10803
10804 3
10805 \end_inset 
10806 </cell>
10807 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10808 \begin_inset Text
10809
10810 \layout Standard
10811
10812 Timer 1
10813 \end_inset 
10814 </cell>
10815 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10816 \begin_inset Text
10817
10818 \layout Standard
10819
10820 0x001B
10821 \end_inset 
10822 </cell>
10823 </row>
10824 <row topline="true">
10825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10826 \begin_inset Text
10827
10828 \layout Standard
10829
10830 4
10831 \end_inset 
10832 </cell>
10833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10834 \begin_inset Text
10835
10836 \layout Standard
10837
10838 Serial
10839 \end_inset 
10840 </cell>
10841 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10842 \begin_inset Text
10843
10844 \layout Standard
10845
10846 0x0023
10847 \end_inset 
10848 </cell>
10849 </row>
10850 <row topline="true" bottomline="true">
10851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10852 \begin_inset Text
10853
10854 \layout Standard
10855
10856 5
10857 \end_inset 
10858 </cell>
10859 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10860 \begin_inset Text
10861
10862 \layout Standard
10863
10864 Timer 2 (8052)
10865 \end_inset 
10866 </cell>
10867 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10868 \begin_inset Text
10869
10870 \layout Standard
10871
10872 0x002B
10873 \end_inset 
10874 </cell>
10875 </row>
10876 </lyxtabular>
10877
10878 \end_inset 
10879
10880
10881 \newline 
10882
10883 \layout Standard
10884
10885 If the interrupt service routine is defined without 
10886 \emph on 
10887 using
10888 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10889
10890 \end_inset 
10891
10892
10893 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
10894
10895 \end_inset 
10896
10897
10898 \emph default 
10899  a register bank or with register bank 0 (
10900 \emph on 
10901 using
10902 \emph default 
10903  0), the compiler will save the registers used by itself on the stack upon
10904  entry and restore them at exit, however if such an interrupt service routine
10905  calls another function then the entire register bank will be saved on the
10906  stack.
10907  This scheme may be advantageous for small interrupt service routines which
10908  have low register usage.
10909 \layout Standard
10910
10911 If the interrupt service routine is defined to be using a specific register
10912  bank then only 
10913 \emph on 
10914 a, b, dptr
10915 \emph default 
10916  & psw are saved and restored, if such an interrupt service routine calls
10917  another function (using another register bank) then the entire register
10918  bank of the called function will be saved on the stack.
10919  This scheme is recommended for larger interrupt service routines.
10920 \layout Subsection
10921
10922 HC08 Interrupt Service Routines
10923 \layout Standard
10924
10925 Since the number of interrupts available is chip specific and the interrupt
10926  vector table always ends at the last byte of memory, the interrupt numbers
10927  corresponds to the interrupt vectors in reverse order of address.
10928  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
10929  2 will use the interrupt vector at 0xfffa, and so on.
10930  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
10931  this way; instead see section 
10932 \begin_inset LatexCommand \ref{sub:Startup-Code}
10933
10934 \end_inset 
10935
10936  for details on customizing startup.
10937 \layout Subsection
10938
10939 Z80 Interrupt Service Routines
10940 \layout Standard
10941
10942 The Z80 uses several different methods for determining the correct interrupt
10943  vector depending on the hardware implementation.
10944  Therefore, SDCC ignores the optional interrupt number and does not attempt
10945  to generate an interrupt vector table.
10946 \layout Standard
10947
10948 By default, SDCC generates code for a maskable interrupt, which uses an
10949  RETI instruction to return from the interrupt.
10950  To write an interrupt handler for the non-maskable interrupt, which needs
10951  an RETN instruction instead, add the 
10952 \emph on 
10953 critical
10954 \emph default 
10955  keyword:
10956 \layout Verse
10957
10958
10959 \family typewriter 
10960 void nmi_isr (void) critical interrupt
10961 \newline 
10962
10963 \newline 
10964 \SpecialChar ~
10965 \SpecialChar ~
10966 \SpecialChar ~
10967 \SpecialChar ~
10968 ...
10969  
10970 \newline 
10971 }
10972 \layout Section
10973
10974 Enabling and Disabling Interrupts
10975 \layout Subsection
10976
10977 Critical Functions and Critical Statements
10978 \layout Standard
10979
10980 A special keyword may be associated with a block or a function declaring
10981  it as 
10982 \emph on 
10983 critical
10984 \emph default 
10985 .
10986  SDCC will generate code to disable all interrupts
10987 \begin_inset LatexCommand \index{interrupt}
10988
10989 \end_inset 
10990
10991  upon entry to a critical function and restore the interrupt enable to the
10992  previous state before returning.
10993  Nesting critical functions will need one additional byte on the stack
10994 \begin_inset LatexCommand \index{stack}
10995
10996 \end_inset 
10997
10998  for each call.
10999 \layout Verse
11000
11001
11002 \family typewriter 
11003 int foo () critical
11004 \begin_inset LatexCommand \index{critical}
11005
11006 \end_inset 
11007
11008
11009 \begin_inset LatexCommand \index{\_\_critical}
11010
11011 \end_inset 
11012
11013  
11014 \newline 
11015
11016 \newline 
11017 \SpecialChar ~
11018 \SpecialChar ~
11019 \SpecialChar ~
11020 \SpecialChar ~
11021 ...
11022  
11023 \newline 
11024 \SpecialChar ~
11025 \SpecialChar ~
11026 \SpecialChar ~
11027 \SpecialChar ~
11028 ...
11029  
11030 \newline 
11031 }
11032 \layout Standard
11033
11034 The critical attribute maybe used with other attributes like 
11035 \emph on 
11036 reentrant.
11037 \emph default 
11038
11039 \newline 
11040 The keyword 
11041 \emph on 
11042 critical
11043 \emph default 
11044  may also be used to disable interrupts more locally:
11045 \layout Verse
11046
11047
11048 \family typewriter 
11049 critical{ i++; }
11050 \layout Standard
11051
11052 More than one statement could have been included in the block.
11053 \layout Subsection
11054
11055 Enabling and Disabling Interrupts directly
11056 \layout Standard
11057
11058 Interrupts
11059 \begin_inset LatexCommand \index{interrupt}
11060
11061 \end_inset 
11062
11063  can also be disabled and enabled directly (8051):
11064 \layout Verse
11065
11066
11067 \family typewriter 
11068 EA = 0;\SpecialChar ~
11069 \SpecialChar ~
11070 \SpecialChar ~
11071 \SpecialChar ~
11072 \SpecialChar ~
11073 \SpecialChar ~
11074 \SpecialChar ~
11075 \SpecialChar ~
11076 \SpecialChar ~
11077 \SpecialChar ~
11078 \SpecialChar ~
11079 \SpecialChar ~
11080 or:\SpecialChar ~
11081 \SpecialChar ~
11082 \SpecialChar ~
11083 \SpecialChar ~
11084 \SpecialChar ~
11085 \SpecialChar ~
11086 \SpecialChar ~
11087 \SpecialChar ~
11088 \SpecialChar ~
11089 \SpecialChar ~
11090 \SpecialChar ~
11091 EA_SAVE = EA;
11092 \layout Verse
11093
11094
11095 \family typewriter 
11096 ...\SpecialChar ~
11097 \SpecialChar ~
11098 \SpecialChar ~
11099 \SpecialChar ~
11100 \SpecialChar ~
11101 \SpecialChar ~
11102 \SpecialChar ~
11103 \SpecialChar ~
11104 \SpecialChar ~
11105 \SpecialChar ~
11106 \SpecialChar ~
11107 \SpecialChar ~
11108 \SpecialChar ~
11109 \SpecialChar ~
11110 \SpecialChar ~
11111 \SpecialChar ~
11112 \SpecialChar ~
11113 \SpecialChar ~
11114 \SpecialChar ~
11115 \SpecialChar ~
11116 \SpecialChar ~
11117 \SpecialChar ~
11118 \SpecialChar ~
11119 \SpecialChar ~
11120 \SpecialChar ~
11121 \SpecialChar ~
11122 \SpecialChar ~
11123 \SpecialChar ~
11124 \SpecialChar ~
11125 \SpecialChar ~
11126 EA = 0;
11127 \layout Verse
11128
11129
11130 \family typewriter 
11131 EA = 1;\SpecialChar ~
11132 \SpecialChar ~
11133 \SpecialChar ~
11134 \SpecialChar ~
11135 \SpecialChar ~
11136 \SpecialChar ~
11137 \SpecialChar ~
11138 \SpecialChar ~
11139 \SpecialChar ~
11140 \SpecialChar ~
11141 \SpecialChar ~
11142 \SpecialChar ~
11143 \SpecialChar ~
11144 \SpecialChar ~
11145 \SpecialChar ~
11146 \SpecialChar ~
11147 \SpecialChar ~
11148 \SpecialChar ~
11149 \SpecialChar ~
11150 \SpecialChar ~
11151 \SpecialChar ~
11152 \SpecialChar ~
11153 \SpecialChar ~
11154 \SpecialChar ~
11155 \SpecialChar ~
11156 \SpecialChar ~
11157 ...
11158 \layout Verse
11159
11160
11161 \family typewriter 
11162 \SpecialChar ~
11163 \SpecialChar ~
11164 \SpecialChar ~
11165 \SpecialChar ~
11166 \SpecialChar ~
11167 \SpecialChar ~
11168 \SpecialChar ~
11169 \SpecialChar ~
11170 \SpecialChar ~
11171 \SpecialChar ~
11172 \SpecialChar ~
11173 \SpecialChar ~
11174 \SpecialChar ~
11175 \SpecialChar ~
11176 \SpecialChar ~
11177 \SpecialChar ~
11178 \SpecialChar ~
11179 \SpecialChar ~
11180 \SpecialChar ~
11181 \SpecialChar ~
11182 \SpecialChar ~
11183 \SpecialChar ~
11184 \SpecialChar ~
11185 \SpecialChar ~
11186 \SpecialChar ~
11187 \SpecialChar ~
11188 \SpecialChar ~
11189 \SpecialChar ~
11190 \SpecialChar ~
11191 \SpecialChar ~
11192 \SpecialChar ~
11193 \SpecialChar ~
11194 \SpecialChar ~
11195 EA = EA_SAVE;
11196 \layout Standard
11197
11198 On other architectures which have seperate opcodes for enabling and disabling
11199  interrupts you might want to make use of defines with inline assembly
11200 \begin_inset LatexCommand \index{Assembler routines}
11201
11202 \end_inset 
11203
11204  (HC08):
11205 \layout Verse
11206
11207
11208 \family typewriter 
11209 #define CLI _asm
11210 \begin_inset LatexCommand \index{\_asm}
11211
11212 \end_inset 
11213
11214 \SpecialChar ~
11215 \SpecialChar ~
11216 cli\SpecialChar ~
11217 \SpecialChar ~
11218 _endasm
11219 \begin_inset LatexCommand \index{\_endasm}
11220
11221 \end_inset 
11222
11223
11224 \layout Verse
11225
11226
11227 \family typewriter 
11228 #define SEI _asm\SpecialChar ~
11229 \SpecialChar ~
11230 sei\SpecialChar ~
11231 \SpecialChar ~
11232 _endasm; 
11233 \layout Verse
11234
11235
11236 \family typewriter 
11237 ...
11238 \layout Standard
11239
11240 Note: it is sometimes sufficient to disable only a specific interrupt source
11241  like f.e.
11242  a timer or serial interrupt by manipulating an 
11243 \emph on 
11244 interrupt mask
11245 \begin_inset LatexCommand \index{interrupt mask}
11246
11247 \end_inset 
11248
11249
11250 \emph default 
11251  register.
11252  
11253 \layout Standard
11254
11255 Usually the time during which interrupts are disabled should be kept as
11256  short as possible.
11257  This minimizes both 
11258 \emph on 
11259 interrupt latency
11260 \emph default 
11261
11262 \begin_inset LatexCommand \index{interrupt latency}
11263
11264 \end_inset 
11265
11266  (the time between the occurrence of the interrupt and the execution of
11267  the first code in the interrupt routine) and 
11268 \emph on 
11269 interrupt jitter
11270 \emph default 
11271
11272 \begin_inset LatexCommand \index{interrupt jitter}
11273
11274 \end_inset 
11275
11276  (the difference between the shortest and the longest interrupt latency).
11277  These really are something different, f.e.
11278  a serial interrupt has to be served before its buffer overruns so it cares
11279  for the maximum interrupt latency, whereas it does not care about jitter.
11280  On a loudspeaker driven via a digital to analog converter which is fed
11281  by an interrupt a latency of a few milliseconds might be tolerable, whereas
11282  a much smaller jitter will be very audible.
11283 \layout Standard
11284
11285 You can reenable interrupts within an interrupt routine and on some architecture
11286 s you can make use of two (or more) levels of 
11287 \emph on 
11288 interrupt priorities
11289 \emph default 
11290
11291 \begin_inset LatexCommand \index{interrupt priority}
11292
11293 \end_inset 
11294
11295 .
11296  On some architectures which don't support interrupt priorities these can
11297  be implemented by manipulating the interrupt mask and reenabling interrupts
11298  within the interrupt routine.
11299  Check there is sufficient space on the stack
11300 \begin_inset LatexCommand \index{stack}
11301
11302 \end_inset 
11303
11304  and don't add complexity unless you have to.
11305  
11306 \layout Subsection
11307
11308 Semaphore
11309 \begin_inset LatexCommand \index{semaphore}
11310
11311 \end_inset 
11312
11313  locking (mcs51/ds390)
11314 \layout Standard
11315
11316 Some architectures (mcs51/ds390) have an atomic
11317 \begin_inset LatexCommand \index{atomic}
11318
11319 \end_inset 
11320
11321  bit test and
11322 \emph on 
11323  
11324 \emph default 
11325 clear
11326 \emph on 
11327  
11328 \emph default 
11329 instruction.
11330  These type of instructions are typically used in preemptive multitasking
11331  systems, where a routine f.e.
11332  claims the use of a data structure ('acquires a lock
11333 \begin_inset LatexCommand \index{lock}
11334
11335 \end_inset 
11336
11337  on it'), makes some modifications and then releases the lock when the data
11338  structure is consistent again.
11339  The instruction may also be used if interrupt and non-interrupt code have
11340  to compete for a resource.
11341  With the atomic bit test and clear instruction interrupts
11342 \begin_inset LatexCommand \index{interrupt}
11343
11344 \end_inset 
11345
11346  don't have to be disabled for the locking operation.
11347  
11348 \layout Standard
11349
11350 SDCC generates this instruction if the source follows this pattern:
11351 \layout Verse
11352
11353
11354 \family typewriter 
11355 volatile
11356 \begin_inset LatexCommand \index{volatile}
11357
11358 \end_inset 
11359
11360  bit resource_is_free; 
11361 \newline 
11362
11363 \newline 
11364 if (resource_is_free) 
11365 \newline 
11366 \SpecialChar ~
11367 \SpecialChar ~
11368
11369 \newline 
11370 \SpecialChar ~
11371 \SpecialChar ~
11372 \SpecialChar ~
11373 \SpecialChar ~
11374 resource_is_free=0; 
11375 \newline 
11376 \SpecialChar ~
11377 \SpecialChar ~
11378 \SpecialChar ~
11379 \SpecialChar ~
11380 ...
11381  
11382 \newline 
11383 \SpecialChar ~
11384 \SpecialChar ~
11385 \SpecialChar ~
11386 \SpecialChar ~
11387 resource_is_free=1;
11388 \newline 
11389 \SpecialChar ~
11390 \SpecialChar ~
11391
11392 \layout Standard
11393
11394 Note, mcs51 and ds390 support only an atomic
11395 \begin_inset LatexCommand \index{atomic}
11396
11397 \end_inset 
11398
11399  bit test and 
11400 \emph on 
11401 clear
11402 \emph default 
11403  instruction (as opposed to atomic bit test and 
11404 \emph on 
11405 set).
11406 \layout Section
11407
11408 Functions using private register banks
11409 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
11410
11411 \end_inset 
11412
11413  (mcs51/ds390)
11414 \layout Standard
11415
11416 Some architectures have support for quickly changing register sets.
11417  SDCC supports this feature with the 
11418 \emph on 
11419 using
11420 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11421
11422 \end_inset 
11423
11424
11425 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11426
11427 \end_inset 
11428
11429
11430 \emph default 
11431  attribute (which tells the compiler to use a register bank
11432 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
11433
11434 \end_inset 
11435
11436  other than the default bank zero).
11437  It should only be applied to 
11438 \emph on 
11439 interrupt
11440 \begin_inset LatexCommand \index{interrupt}
11441
11442 \end_inset 
11443
11444
11445 \emph default 
11446  functions (see footnote below).
11447  This will in most circumstances make the generated ISR code more efficient
11448  since it will not have to save registers on the stack.
11449 \layout Standard
11450
11451 The 
11452 \emph on 
11453 using
11454 \emph default 
11455  attribute will have no effect on the generated code for a 
11456 \emph on 
11457 non-interrupt
11458 \emph default 
11459  function (but may occasionally be useful anyway
11460 \begin_inset Foot
11461 collapsed false
11462
11463 \layout Standard
11464
11465 possible exception: if a function is called ONLY from 'interrupt' functions
11466  using a particular bank, it can be declared with the same 'using' attribute
11467  as the calling 'interrupt' functions.
11468  For instance, if you have several ISRs using bank one, and all of them
11469  call memcpy(), it might make sense to create a specialized version of memcpy()
11470  'using 1', since this would prevent the ISR from having to save bank zero
11471  to the stack on entry and switch to bank zero before calling the function
11472 \end_inset 
11473
11474 ).
11475 \newline 
11476
11477 \emph on 
11478 (pending: I don't think this has been done yet)
11479 \layout Standard
11480
11481 An 
11482 \emph on 
11483 interrupt
11484 \emph default 
11485  function using a non-zero bank will assume that it can trash that register
11486  bank, and will not save it.
11487  Since high-priority interrupts
11488 \begin_inset LatexCommand \index{interrupts}
11489
11490 \end_inset 
11491
11492
11493 \begin_inset LatexCommand \index{interrupt priority}
11494
11495 \end_inset 
11496
11497  can interrupt low-priority ones on the 8051 and friends, this means that
11498  if a high-priority ISR 
11499 \emph on 
11500 using
11501 \emph default 
11502  a particular bank occurs while processing a low-priority ISR 
11503 \emph on 
11504 using
11505 \emph default 
11506  the same bank, terrible and bad things can happen.
11507  To prevent this, no single register bank should be 
11508 \emph on 
11509 used
11510 \emph default 
11511  by both a high priority and a low priority ISR.
11512  This is probably most easily done by having all high priority ISRs use
11513  one bank and all low priority ISRs use another.
11514  If you have an ISR which can change priority at runtime, you're on your
11515  own: I suggest using the default bank zero and taking the small performance
11516  hit.
11517 \layout Standard
11518
11519 It is most efficient if your ISR calls no other functions.
11520  If your ISR must call other functions, it is most efficient if those functions
11521  use the same bank as the ISR (see note 1 below); the next best is if the
11522  called functions use bank zero.
11523  It is very inefficient to call a function using a different, non-zero bank
11524  from an ISR.
11525  
11526 \layout Section
11527
11528 Startup Code
11529 \begin_inset LatexCommand \label{sub:Startup-Code}
11530
11531 \end_inset 
11532
11533
11534 \begin_inset LatexCommand \index{Startup code}
11535
11536 \end_inset 
11537
11538
11539 \layout Subsection
11540
11541 MCS51/DS390 Startup Code
11542 \layout Standard
11543
11544 The compiler inserts a call to the C routine 
11545 \emph on 
11546 _sdcc_external_startup()
11547 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
11548
11549 \end_inset 
11550
11551
11552 \series bold 
11553 \emph default 
11554  
11555 \series default 
11556 at the start of the CODE area.
11557  This routine is in the runtime library
11558 \begin_inset LatexCommand \index{Runtime library}
11559
11560 \end_inset 
11561
11562 .
11563  By default this routine returns 0, if this routine returns a non-zero value,
11564  the static & global variable initialization will be skipped and the function
11565  main will be invoked.
11566  Otherwise static & global variables will be initialized before the function
11567  main is invoked.
11568  You could add a 
11569 \emph on 
11570 _sdcc_external_startup()
11571 \emph default 
11572  routine to your program to override the default if you need to setup hardware
11573  or perform some other critical operation prior to static & global variable
11574  initialization
11575 \begin_inset LatexCommand \index{Variable initialization}
11576
11577 \end_inset 
11578
11579 .
11580  On some mcs51 variants xdata
11581 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11582
11583 \end_inset 
11584
11585  memory has to be explicitly enabled before it can be accessed or if the
11586  watchdog needs to be disabled, this is the place to do it.
11587  The startup code clears all internal data memory, 256 bytes by default,
11588  but from 0 to n-1 if 
11589 \emph on 
11590 -
11591 \begin_inset ERT
11592 status Collapsed
11593
11594 \layout Standard
11595
11596 \backslash 
11597 /
11598 \end_inset 
11599
11600 -iram-size
11601 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
11602
11603 \end_inset 
11604
11605 n
11606 \emph default 
11607  is used.
11608  (recommended for Chipcon CC1010).
11609 \layout Standard
11610
11611 See also the compiler option 
11612 \emph on 
11613 -
11614 \begin_inset ERT
11615 status Collapsed
11616
11617 \layout Standard
11618
11619 \backslash 
11620 /
11621 \end_inset 
11622
11623 -no-xinit
11624 \emph default 
11625 -
11626 \emph on 
11627 opt
11628 \emph default 
11629
11630 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
11631
11632 \end_inset 
11633
11634  and section 
11635 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11636
11637 \end_inset 
11638
11639 \SpecialChar ~
11640 about MCS51-variants.
11641 \layout Subsection
11642
11643 HC08 Startup Code
11644 \layout Standard
11645
11646 The HC08 startup code follows the same scheme as the MCS51 startup code.
11647 \layout Subsection
11648
11649 Z80 Startup Code
11650 \layout Standard
11651
11652 On the Z80 the startup code is inserted by linking with crt0.o which is generated
11653  from sdcc/device/lib/z80/crt0.s.
11654  If you need a different startup code you can use the compiler option 
11655 \emph on 
11656 -
11657 \series bold 
11658 \emph default 
11659
11660 \begin_inset ERT
11661 status Collapsed
11662
11663 \layout Standard
11664
11665 \backslash 
11666 /
11667 \end_inset 
11668
11669
11670 \series default 
11671 \emph on 
11672 -no-std-crt0
11673 \emph default 
11674
11675 \begin_inset LatexCommand \index{-\/-no-std-crt0}
11676
11677 \end_inset 
11678
11679  and provide your own crt0.o.
11680  
11681 \layout Section
11682
11683 Inline Assembler Code
11684 \begin_inset LatexCommand \index{Assembler routines}
11685
11686 \end_inset 
11687
11688
11689 \layout Subsection
11690
11691 A Step by Step Introduction
11692 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
11693
11694 \end_inset 
11695
11696
11697 \layout Standard
11698
11699 Starting from a small snippet of c-code this example shows for the MCS51
11700  how to use inline assembly, access variables, a function parameter and
11701  an array in xdata memory.
11702  The example uses an MCS51 here but is easily adapted for other architectures.
11703  This is a buffer routine which should be optimized:
11704 \layout Verse
11705
11706
11707 \family typewriter 
11708 \size footnotesize 
11709 unsigned char far
11710 \begin_inset LatexCommand \index{far (storage class)}
11711
11712 \end_inset 
11713
11714
11715 \begin_inset LatexCommand \index{\_\_far (storage class)}
11716
11717 \end_inset 
11718
11719  at
11720 \begin_inset LatexCommand \index{at}
11721
11722 \end_inset 
11723
11724
11725 \begin_inset LatexCommand \index{\_\_at}
11726
11727 \end_inset 
11728
11729  0x7f00 buf[0x100];
11730 \begin_inset LatexCommand \index{Aligned array}
11731
11732 \end_inset 
11733
11734
11735 \newline 
11736 unsigned char head,tail;
11737 \newline 
11738
11739 \newline 
11740 void to_buffer( unsigned char c ) 
11741 \newline 
11742 {
11743 \newline 
11744 \SpecialChar ~
11745 \SpecialChar ~
11746 \SpecialChar ~
11747 \SpecialChar ~
11748 if( head != tail-1 ) 
11749 \newline 
11750 \SpecialChar ~
11751 \SpecialChar ~
11752 \SpecialChar ~
11753 \SpecialChar ~
11754 \SpecialChar ~
11755 \SpecialChar ~
11756 \SpecialChar ~
11757 \SpecialChar ~
11758 buf[ head++ ] = c;\SpecialChar ~
11759 \SpecialChar ~
11760 \SpecialChar ~
11761 \SpecialChar ~
11762 /* access to a 256 byte aligned array */
11763 \newline 
11764
11765 \layout Standard
11766
11767 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
11768  then a corresponding buffer.asm file is generated.
11769  We define a new function 
11770 \family typewriter 
11771 to_buffer_asm()
11772 \family default 
11773  in file buffer.c in which we cut and paste the generated code, removing
11774  unwanted comments and some ':'.
11775  Then add 
11776 \begin_inset Quotes sld
11777 \end_inset 
11778
11779 _asm
11780 \begin_inset Quotes srd
11781 \end_inset 
11782
11783  and 
11784 \begin_inset Quotes sld
11785 \end_inset 
11786
11787 _endasm;
11788 \begin_inset Quotes srd
11789 \end_inset 
11790
11791  to the beginning and the end of the function body:
11792 \layout Verse
11793
11794
11795 \family typewriter 
11796 \size footnotesize 
11797 /* With a cut and paste from the .asm file, we have something to start with.
11798 \newline 
11799 \SpecialChar ~
11800 \SpecialChar ~
11801 \SpecialChar ~
11802 The function is not yet OK! (registers aren't saved) */ 
11803 \newline 
11804 void to_buffer_asm( unsigned char c ) 
11805 \newline 
11806
11807 \newline 
11808 \SpecialChar ~
11809 \SpecialChar ~
11810 \SpecialChar ~
11811 \SpecialChar ~
11812 _asm
11813 \begin_inset LatexCommand \index{\_asm}
11814
11815 \end_inset 
11816
11817
11818 \begin_inset LatexCommand \index{\_\_asm}
11819
11820 \end_inset 
11821
11822
11823 \newline 
11824 \SpecialChar ~
11825 \SpecialChar ~
11826 \SpecialChar ~
11827 \SpecialChar ~
11828 mov\SpecialChar ~
11829 \SpecialChar ~
11830 r2,dpl 
11831 \newline 
11832 ;buffer.c if( head != tail-1 ) 
11833 \newline 
11834 \SpecialChar ~
11835 \SpecialChar ~
11836 \SpecialChar ~
11837 \SpecialChar ~
11838 mov\SpecialChar ~
11839 \SpecialChar ~
11840 a,_tail 
11841 \newline 
11842 \SpecialChar ~
11843 \SpecialChar ~
11844 \SpecialChar ~
11845 \SpecialChar ~
11846 dec\SpecialChar ~
11847 \SpecialChar ~
11848
11849 \newline 
11850 \SpecialChar ~
11851 \SpecialChar ~
11852 \SpecialChar ~
11853 \SpecialChar ~
11854 mov\SpecialChar ~
11855 \SpecialChar ~
11856 r3,a 
11857 \newline 
11858 \SpecialChar ~
11859 \SpecialChar ~
11860 \SpecialChar ~
11861 \SpecialChar ~
11862 mov\SpecialChar ~
11863 \SpecialChar ~
11864 a,_head 
11865 \newline 
11866 \SpecialChar ~
11867 \SpecialChar ~
11868 \SpecialChar ~
11869 \SpecialChar ~
11870 cjne a,ar3,00106$ 
11871 \newline 
11872 \SpecialChar ~
11873 \SpecialChar ~
11874 \SpecialChar ~
11875 \SpecialChar ~
11876 ret
11877 \newline 
11878 00106$: 
11879 \newline 
11880 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
11881 \begin_inset LatexCommand \index{Aligned array}
11882
11883 \end_inset 
11884
11885
11886 \newline 
11887 \SpecialChar ~
11888 \SpecialChar ~
11889 \SpecialChar ~
11890 \SpecialChar ~
11891 mov\SpecialChar ~
11892 \SpecialChar ~
11893 r3,_head 
11894 \newline 
11895 \SpecialChar ~
11896 \SpecialChar ~
11897 \SpecialChar ~
11898 \SpecialChar ~
11899 inc\SpecialChar ~
11900 \SpecialChar ~
11901 _head 
11902 \newline 
11903 \SpecialChar ~
11904 \SpecialChar ~
11905 \SpecialChar ~
11906 \SpecialChar ~
11907 mov\SpecialChar ~
11908 \SpecialChar ~
11909 dpl,r3 
11910 \newline 
11911 \SpecialChar ~
11912 \SpecialChar ~
11913 \SpecialChar ~
11914 \SpecialChar ~
11915 mov\SpecialChar ~
11916 \SpecialChar ~
11917 dph,#(_buf >> 8) 
11918 \newline 
11919 \SpecialChar ~
11920 \SpecialChar ~
11921 \SpecialChar ~
11922 \SpecialChar ~
11923 mov\SpecialChar ~
11924 \SpecialChar ~
11925 a,r2 
11926 \newline 
11927 \SpecialChar ~
11928 \SpecialChar ~
11929 \SpecialChar ~
11930 \SpecialChar ~
11931 movx @dptr,a 
11932 \newline 
11933 00103$: 
11934 \newline 
11935 \SpecialChar ~
11936 \SpecialChar ~
11937 \SpecialChar ~
11938 \SpecialChar ~
11939 ret
11940 \newline 
11941 \SpecialChar ~
11942 \SpecialChar ~
11943 \SpecialChar ~
11944 \SpecialChar ~
11945 _endasm
11946 \begin_inset LatexCommand \index{\_endasm}
11947
11948 \end_inset 
11949
11950
11951 \begin_inset LatexCommand \index{\_\_endasm}
11952
11953 \end_inset 
11954
11955 ;
11956 \newline 
11957
11958 \layout Standard
11959
11960 The new file buffer.c should compile with only one warning about the unreferenced
11961  function argument 'c'.
11962  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
11963  (1) and finally have:
11964 \layout Verse
11965
11966
11967 \family typewriter 
11968 \size footnotesize 
11969 unsigned char far at 0x7f00 buf[0x100];
11970 \newline 
11971 unsigned char head,tail;
11972 \newline 
11973 #define USE_ASSEMBLY (1)
11974 \newline 
11975
11976 \newline 
11977 #if !USE_ASSEMBLY
11978 \newline 
11979
11980 \newline 
11981 void to_buffer( unsigned char c )
11982 \newline 
11983 {
11984 \newline 
11985 \SpecialChar ~
11986 \SpecialChar ~
11987 \SpecialChar ~
11988 \SpecialChar ~
11989 if( head != tail-1 )
11990 \newline 
11991 \SpecialChar ~
11992 \SpecialChar ~
11993 \SpecialChar ~
11994 \SpecialChar ~
11995 \SpecialChar ~
11996 \SpecialChar ~
11997 \SpecialChar ~
11998 \SpecialChar ~
11999 buf[ head++ ] = c;
12000 \newline 
12001 }
12002 \newline 
12003
12004 \newline 
12005 #else
12006 \newline 
12007
12008 \newline 
12009 void to_buffer( unsigned char c )
12010 \newline 
12011 {
12012 \newline 
12013 \SpecialChar ~
12014 \SpecialChar ~
12015 \SpecialChar ~
12016 \SpecialChar ~
12017 c; // to avoid warning: unreferenced function argument
12018 \newline 
12019 \SpecialChar ~
12020 \SpecialChar ~
12021 \SpecialChar ~
12022 \SpecialChar ~
12023 _asm
12024 \begin_inset LatexCommand \index{\_asm}
12025
12026 \end_inset 
12027
12028
12029 \begin_inset LatexCommand \index{\_\_asm}
12030
12031 \end_inset 
12032
12033
12034 \newline 
12035 \SpecialChar ~
12036 \SpecialChar ~
12037 \SpecialChar ~
12038 \SpecialChar ~
12039 \SpecialChar ~
12040 \SpecialChar ~
12041 \SpecialChar ~
12042 \SpecialChar ~
12043 ; save used registers here.
12044  
12045 \newline 
12046 \SpecialChar ~
12047 \SpecialChar ~
12048 \SpecialChar ~
12049 \SpecialChar ~
12050 \SpecialChar ~
12051 \SpecialChar ~
12052 \SpecialChar ~
12053 \SpecialChar ~
12054 ; If we were still using r2,r3 we would have to push them here.
12055  
12056 \newline 
12057 ; if( head != tail-1 )
12058 \newline 
12059 \SpecialChar ~
12060 \SpecialChar ~
12061 \SpecialChar ~
12062 \SpecialChar ~
12063 \SpecialChar ~
12064 \SpecialChar ~
12065 \SpecialChar ~
12066 \SpecialChar ~
12067 mov\SpecialChar ~
12068  a,_tail
12069 \newline 
12070 \SpecialChar ~
12071 \SpecialChar ~
12072 \SpecialChar ~
12073 \SpecialChar ~
12074 \SpecialChar ~
12075 \SpecialChar ~
12076 \SpecialChar ~
12077 \SpecialChar ~
12078 dec\SpecialChar ~
12079  a
12080 \newline 
12081 \SpecialChar ~
12082 \SpecialChar ~
12083 \SpecialChar ~
12084 \SpecialChar ~
12085 \SpecialChar ~
12086 \SpecialChar ~
12087 \SpecialChar ~
12088 \SpecialChar ~
12089 xrl\SpecialChar ~
12090  a,_head
12091 \newline 
12092 \SpecialChar ~
12093 \SpecialChar ~
12094 \SpecialChar ~
12095 \SpecialChar ~
12096 \SpecialChar ~
12097 \SpecialChar ~
12098 \SpecialChar ~
12099 \SpecialChar ~
12100 ; we could do an ANL a,#0x0f here to use a smaller buffer (see below)
12101 \newline 
12102 \SpecialChar ~
12103 \SpecialChar ~
12104 \SpecialChar ~
12105 \SpecialChar ~
12106 \SpecialChar ~
12107 \SpecialChar ~
12108 \SpecialChar ~
12109 \SpecialChar ~
12110 jz\SpecialChar ~
12111 \SpecialChar ~
12112  t_b_end$
12113 \newline 
12114 \SpecialChar ~
12115 \SpecialChar ~
12116 \SpecialChar ~
12117 \SpecialChar ~
12118 \SpecialChar ~
12119 \SpecialChar ~
12120 \SpecialChar ~
12121 \SpecialChar ~
12122 ;
12123 \newline 
12124 ; buf[ head++ ] = c;
12125 \newline 
12126 \SpecialChar ~
12127 \SpecialChar ~
12128 \SpecialChar ~
12129 \SpecialChar ~
12130 \SpecialChar ~
12131 \SpecialChar ~
12132 \SpecialChar ~
12133 \SpecialChar ~
12134 mov\SpecialChar ~
12135  a,dpl \SpecialChar ~
12136 \SpecialChar ~
12137 \SpecialChar ~
12138 \SpecialChar ~
12139 \SpecialChar ~
12140 \SpecialChar ~
12141 \SpecialChar ~
12142 ; dpl holds lower byte of function argument
12143 \newline 
12144 \SpecialChar ~
12145 \SpecialChar ~
12146 \SpecialChar ~
12147 \SpecialChar ~
12148 \SpecialChar ~
12149 \SpecialChar ~
12150 \SpecialChar ~
12151 \SpecialChar ~
12152 mov\SpecialChar ~
12153  dpl,_head \SpecialChar ~
12154 \SpecialChar ~
12155 \SpecialChar ~
12156 ; buf is 0x100 byte aligned so head can be used directly
12157 \newline 
12158 \SpecialChar ~
12159 \SpecialChar ~
12160 \SpecialChar ~
12161 \SpecialChar ~
12162 \SpecialChar ~
12163 \SpecialChar ~
12164 \SpecialChar ~
12165 \SpecialChar ~
12166 mov\SpecialChar ~
12167  dph,#(_buf>>8)
12168 \newline 
12169 \SpecialChar ~
12170 \SpecialChar ~
12171 \SpecialChar ~
12172 \SpecialChar ~
12173 \SpecialChar ~
12174 \SpecialChar ~
12175 \SpecialChar ~
12176 \SpecialChar ~
12177 movx @dptr,a
12178 \newline 
12179 \SpecialChar ~
12180 \SpecialChar ~
12181 \SpecialChar ~
12182 \SpecialChar ~
12183 \SpecialChar ~
12184 \SpecialChar ~
12185 \SpecialChar ~
12186 \SpecialChar ~
12187 inc \SpecialChar ~
12188 _head
12189 \newline 
12190 \SpecialChar ~
12191 \SpecialChar ~
12192 \SpecialChar ~
12193 \SpecialChar ~
12194 \SpecialChar ~
12195 \SpecialChar ~
12196 \SpecialChar ~
12197 \SpecialChar ~
12198 ; we could do an ANL _head,#0x0f here to use a smaller buffer (see above)
12199 \newline 
12200 t_b_end$:
12201 \newline 
12202 \SpecialChar ~
12203 \SpecialChar ~
12204 \SpecialChar ~
12205 \SpecialChar ~
12206 \SpecialChar ~
12207 \SpecialChar ~
12208 \SpecialChar ~
12209 \SpecialChar ~
12210 ; restore used registers here 
12211 \newline 
12212 \SpecialChar ~
12213 \SpecialChar ~
12214 \SpecialChar ~
12215 \SpecialChar ~
12216 _endasm
12217 \begin_inset LatexCommand \index{\_endasm}
12218
12219 \end_inset 
12220
12221
12222 \begin_inset LatexCommand \index{\_\_endasm}
12223
12224 \end_inset 
12225
12226 ;
12227 \newline 
12228 }
12229 \newline 
12230 #endif
12231 \layout Standard
12232
12233 The inline assembler code can contain any valid code understood by the assembler
12234 , this includes any assembler directives and comment lines
12235 \begin_inset Foot
12236 collapsed false
12237
12238 \layout Standard
12239
12240 The assembler does not like some characters like ':' or ''' in comments.
12241  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
12242 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
12243
12244 \end_inset 
12245
12246
12247 \begin_inset LatexCommand \index{Assembler documentation}
12248
12249 \end_inset 
12250
12251
12252 \end_inset 
12253
12254 .
12255  The compiler does not do any validation of the code within the 
12256 \family typewriter 
12257 _asm
12258 \begin_inset LatexCommand \index{\_asm}
12259
12260 \end_inset 
12261
12262
12263 \begin_inset LatexCommand \index{\_\_asm}
12264
12265 \end_inset 
12266
12267  ...
12268  _endasm
12269 \size footnotesize 
12270
12271 \begin_inset LatexCommand \index{\_endasm}
12272
12273 \end_inset 
12274
12275
12276 \begin_inset LatexCommand \index{\_\_endasm}
12277
12278 \end_inset 
12279
12280
12281 \size default 
12282 ;
12283 \family default 
12284  keyword pair.
12285  Specifically it will not know which registers are used and thus register
12286  pushing/popping
12287 \begin_inset LatexCommand \index{push/pop}
12288
12289 \end_inset 
12290
12291  has to be done manually.
12292  
12293 \layout Standard
12294
12295 It is recommended that each assembly instruction (including labels) be placed
12296  in a separate line (as the example shows).
12297  When the -
12298 \begin_inset ERT
12299 status Collapsed
12300
12301 \layout Standard
12302
12303 \backslash 
12304 /
12305 \end_inset 
12306
12307 -
12308 \emph on 
12309 peep-asm
12310 \begin_inset LatexCommand \index{-\/-peep-asm}
12311
12312 \end_inset 
12313
12314
12315 \emph default 
12316  command line option is used, the inline assembler code will be passed through
12317  the peephole optimizer
12318 \begin_inset LatexCommand \index{Peephole optimizer}
12319
12320 \end_inset 
12321
12322 .
12323  There are only a few (if any) cases where this option makes sense, it might
12324  cause some unexpected changes in the inline assembler code.
12325  Please go through the peephole optimizer rules defined in file 
12326 \emph on 
12327 SDCCpeeph.def
12328 \emph default 
12329  before using this option.
12330 \layout Subsection
12331
12332 Naked Functions
12333 \begin_inset LatexCommand \label{sub:Naked-Functions}
12334
12335 \end_inset 
12336
12337
12338 \begin_inset LatexCommand \index{Naked functions}
12339
12340 \end_inset 
12341
12342
12343 \layout Standard
12344
12345 A special keyword may be associated with a function declaring it as 
12346 \emph on 
12347 _naked
12348 \begin_inset LatexCommand \index{\_naked}
12349
12350 \end_inset 
12351
12352
12353 \begin_inset LatexCommand \index{\_\_naked}
12354
12355 \end_inset 
12356
12357 .
12358  
12359 \emph default 
12360 The 
12361 \emph on 
12362 _naked
12363 \emph default 
12364  function modifier attribute prevents the compiler from generating prologue
12365 \begin_inset LatexCommand \index{function prologue}
12366
12367 \end_inset 
12368
12369  and epilogue
12370 \begin_inset LatexCommand \index{function epilogue}
12371
12372 \end_inset 
12373
12374  code for that function.
12375  This means that the user is entirely responsible for such things as saving
12376  any registers that may need to be preserved, selecting the proper register
12377  bank, generating the 
12378 \emph on 
12379 return
12380 \emph default 
12381  instruction at the end, etc.
12382  Practically, this means that the contents of the function must be written
12383  in inline assembler.
12384  This is particularly useful for interrupt functions, which can have a large
12385  (and often unnecessary) prologue/epilogue.
12386  For example, compare the code generated by these two functions:
12387 \layout Verse
12388
12389
12390 \family typewriter 
12391 volatile
12392 \begin_inset LatexCommand \index{volatile}
12393
12394 \end_inset 
12395
12396  data unsigned char counter;
12397 \newline 
12398
12399 \newline 
12400 void simpleInterrupt(void) interrupt
12401 \begin_inset LatexCommand \index{interrupt}
12402
12403 \end_inset 
12404
12405
12406 \begin_inset LatexCommand \index{\_\_interrupt}
12407
12408 \end_inset 
12409
12410  1
12411 \newline 
12412 {
12413 \newline 
12414 \SpecialChar ~
12415 \SpecialChar ~
12416 \SpecialChar ~
12417 \SpecialChar ~
12418 counter++;
12419 \newline 
12420 }
12421 \newline 
12422
12423 \newline 
12424 void nakedInterrupt(void) interrupt 2 _naked
12425 \newline 
12426 {
12427 \newline 
12428 \SpecialChar ~
12429 \SpecialChar ~
12430 \SpecialChar ~
12431 \SpecialChar ~
12432 _asm
12433 \begin_inset LatexCommand \index{\_asm}
12434
12435 \end_inset 
12436
12437
12438 \begin_inset LatexCommand \index{\_\_asm}
12439
12440 \end_inset 
12441
12442
12443 \newline 
12444 \SpecialChar ~
12445 \SpecialChar ~
12446 \SpecialChar ~
12447 \SpecialChar ~
12448 \SpecialChar ~
12449 \SpecialChar ~
12450 inc\SpecialChar ~
12451 \SpecialChar ~
12452 \SpecialChar ~
12453 \SpecialChar ~
12454 \SpecialChar ~
12455 _counter ; does not change flags, no need to save psw
12456 \newline 
12457 \SpecialChar ~
12458 \SpecialChar ~
12459 \SpecialChar ~
12460 \SpecialChar ~
12461 \SpecialChar ~
12462 \SpecialChar ~
12463 reti\SpecialChar ~
12464 \SpecialChar ~
12465 \SpecialChar ~
12466 \SpecialChar ~
12467 ; MUST explicitly include ret or reti in _naked function.
12468 \newline 
12469 \SpecialChar ~
12470 \SpecialChar ~
12471 \SpecialChar ~
12472 \SpecialChar ~
12473 _endasm
12474 \begin_inset LatexCommand \index{\_endasm}
12475
12476 \end_inset 
12477
12478
12479 \begin_inset LatexCommand \index{\_\_endasm}
12480
12481 \end_inset 
12482
12483 ;
12484 \newline 
12485 }
12486 \layout Standard
12487
12488 For an 8051 target, the generated simpleInterrupt looks like:
12489 \layout Verse
12490
12491
12492 \family typewriter 
12493 _simpleInterrupt:
12494 \newline 
12495 \SpecialChar ~
12496 \SpecialChar ~
12497 \SpecialChar ~
12498 \SpecialChar ~
12499 push\SpecialChar ~
12500 \SpecialChar ~
12501 \SpecialChar ~
12502 \SpecialChar ~
12503 acc
12504 \newline 
12505 \SpecialChar ~
12506 \SpecialChar ~
12507 \SpecialChar ~
12508 \SpecialChar ~
12509 push\SpecialChar ~
12510 \SpecialChar ~
12511 \SpecialChar ~
12512 \SpecialChar ~
12513 b
12514 \newline 
12515 \SpecialChar ~
12516 \SpecialChar ~
12517 \SpecialChar ~
12518 \SpecialChar ~
12519 push\SpecialChar ~
12520 \SpecialChar ~
12521 \SpecialChar ~
12522 \SpecialChar ~
12523 dpl
12524 \newline 
12525 \SpecialChar ~
12526 \SpecialChar ~
12527 \SpecialChar ~
12528 \SpecialChar ~
12529 push\SpecialChar ~
12530 \SpecialChar ~
12531 \SpecialChar ~
12532 \SpecialChar ~
12533 dph
12534 \newline 
12535 \SpecialChar ~
12536 \SpecialChar ~
12537 \SpecialChar ~
12538 \SpecialChar ~
12539 push\SpecialChar ~
12540 \SpecialChar ~
12541 \SpecialChar ~
12542 \SpecialChar ~
12543 psw
12544 \newline 
12545 \SpecialChar ~
12546 \SpecialChar ~
12547 \SpecialChar ~
12548 \SpecialChar ~
12549 mov\SpecialChar ~
12550 \SpecialChar ~
12551 \SpecialChar ~
12552 \SpecialChar ~
12553 \SpecialChar ~
12554 psw,#0x00
12555 \newline 
12556 \SpecialChar ~
12557 \SpecialChar ~
12558 \SpecialChar ~
12559 \SpecialChar ~
12560 inc\SpecialChar ~
12561 \SpecialChar ~
12562 \SpecialChar ~
12563 \SpecialChar ~
12564 \SpecialChar ~
12565 _counter
12566 \newline 
12567 \SpecialChar ~
12568 \SpecialChar ~
12569 \SpecialChar ~
12570 \SpecialChar ~
12571 pop\SpecialChar ~
12572 \SpecialChar ~
12573 \SpecialChar ~
12574 \SpecialChar ~
12575 \SpecialChar ~
12576 psw
12577 \newline 
12578 \SpecialChar ~
12579 \SpecialChar ~
12580 \SpecialChar ~
12581 \SpecialChar ~
12582 pop\SpecialChar ~
12583 \SpecialChar ~
12584 \SpecialChar ~
12585 \SpecialChar ~
12586 \SpecialChar ~
12587 dph
12588 \newline 
12589 \SpecialChar ~
12590 \SpecialChar ~
12591 \SpecialChar ~
12592 \SpecialChar ~
12593 pop\SpecialChar ~
12594 \SpecialChar ~
12595 \SpecialChar ~
12596 \SpecialChar ~
12597 \SpecialChar ~
12598 dpl
12599 \newline 
12600 \SpecialChar ~
12601 \SpecialChar ~
12602 \SpecialChar ~
12603 \SpecialChar ~
12604 pop\SpecialChar ~
12605 \SpecialChar ~
12606 \SpecialChar ~
12607 \SpecialChar ~
12608 \SpecialChar ~
12609 b
12610 \newline 
12611 \SpecialChar ~
12612 \SpecialChar ~
12613 \SpecialChar ~
12614 \SpecialChar ~
12615 pop\SpecialChar ~
12616 \SpecialChar ~
12617 \SpecialChar ~
12618 \SpecialChar ~
12619 \SpecialChar ~
12620 acc
12621 \newline 
12622 \SpecialChar ~
12623 \SpecialChar ~
12624 \SpecialChar ~
12625 \SpecialChar ~
12626 reti
12627 \layout Standard
12628
12629 whereas nakedInterrupt looks like:
12630 \layout Verse
12631
12632
12633 \family typewriter 
12634 _nakedInterrupt:
12635 \newline 
12636 \SpecialChar ~
12637 \SpecialChar ~
12638 \SpecialChar ~
12639 \SpecialChar ~
12640 inc\SpecialChar ~
12641 \SpecialChar ~
12642 \SpecialChar ~
12643 \SpecialChar ~
12644 _counter ; does not change flags, no need to save psw
12645 \newline 
12646 \SpecialChar ~
12647 \SpecialChar ~
12648 \SpecialChar ~
12649 \SpecialChar ~
12650 reti\SpecialChar ~
12651 \SpecialChar ~
12652 \SpecialChar ~
12653 \SpecialChar ~
12654 \SpecialChar ~
12655 \SpecialChar ~
12656 \SpecialChar ~
12657 \SpecialChar ~
12658 \SpecialChar ~
12659 \SpecialChar ~
12660 \SpecialChar ~
12661 \SpecialChar ~
12662 ; MUST explicitly include ret or reti in _naked function
12663 \layout Standard
12664
12665 The related directive #pragma exclude
12666 \begin_inset LatexCommand \index{\#pragma exclude}
12667
12668 \end_inset 
12669
12670  allows a more fine grained control over pushing & popping
12671 \begin_inset LatexCommand \index{push/pop}
12672
12673 \end_inset 
12674
12675  the registers.
12676 \layout Standard
12677
12678 While there is nothing preventing you from writing C code inside a 
12679 \family typewriter 
12680 _naked
12681 \family default 
12682  function, there are many ways to shoot yourself in the foot doing this,
12683  and it is recommended that you stick to inline assembler.
12684 \layout Subsection
12685
12686 Use of Labels within Inline Assembler
12687 \layout Standard
12688
12689 SDCC allows the use of in-line assembler with a few restrictions regarding
12690  labels.
12691  In older versions of the compiler all labels defined within inline assembler
12692  code 
12693 \emph on 
12694 had to be
12695 \emph default 
12696  of the form 
12697 \emph on 
12698 nnnnn$
12699 \emph default 
12700  where nnnn is a number less than 100 (which implies a limit of utmost 100
12701  inline assembler labels 
12702 \emph on 
12703 per function
12704 \emph default 
12705 \noun on 
12706 )
12707 \noun default 
12708 .
12709  
12710 \layout Verse
12711
12712
12713 \family typewriter 
12714 _asm
12715 \begin_inset LatexCommand \index{\_asm}
12716
12717 \end_inset 
12718
12719
12720 \begin_inset LatexCommand \index{\_\_asm}
12721
12722 \end_inset 
12723
12724  
12725 \newline 
12726 \SpecialChar ~
12727 \SpecialChar ~
12728 \SpecialChar ~
12729 \SpecialChar ~
12730 mov\SpecialChar ~
12731 \SpecialChar ~
12732 \SpecialChar ~
12733 \SpecialChar ~
12734 \SpecialChar ~
12735 b,#10 
12736 \newline 
12737 00001$: 
12738 \newline 
12739 \SpecialChar ~
12740 \SpecialChar ~
12741 \SpecialChar ~
12742 \SpecialChar ~
12743 djnz\SpecialChar ~
12744 \SpecialChar ~
12745 \SpecialChar ~
12746 \SpecialChar ~
12747 b,00001$ 
12748 \newline 
12749 _endasm
12750 \begin_inset LatexCommand \index{\_endasm}
12751
12752 \end_inset 
12753
12754
12755 \begin_inset LatexCommand \index{\_\_endasm}
12756
12757 \end_inset 
12758
12759  ;
12760 \layout Standard
12761
12762 Inline assembler code cannot reference any C-Labels, however it can reference
12763  labels
12764 \begin_inset LatexCommand \index{Labels}
12765
12766 \end_inset 
12767
12768  defined by the inline assembler, e.g.:
12769 \layout Verse
12770
12771
12772 \family typewriter 
12773 foo() { 
12774 \newline 
12775 \SpecialChar ~
12776 \SpecialChar ~
12777 \SpecialChar ~
12778 \SpecialChar ~
12779 /* some c code */ 
12780 \newline 
12781 \SpecialChar ~
12782 \SpecialChar ~
12783 \SpecialChar ~
12784 \SpecialChar ~
12785 _asm 
12786 \newline 
12787 \SpecialChar ~
12788 \SpecialChar ~
12789 \SpecialChar ~
12790 \SpecialChar ~
12791 \SpecialChar ~
12792 \SpecialChar ~
12793 ; some assembler code 
12794 \newline 
12795 \SpecialChar ~
12796 \SpecialChar ~
12797 \SpecialChar ~
12798 \SpecialChar ~
12799 \SpecialChar ~
12800 \SpecialChar ~
12801 ljmp $0003 
12802 \newline 
12803 \SpecialChar ~
12804 \SpecialChar ~
12805 \SpecialChar ~
12806 \SpecialChar ~
12807 _endasm; 
12808 \newline 
12809 \SpecialChar ~
12810 \SpecialChar ~
12811 \SpecialChar ~
12812 \SpecialChar ~
12813 /* some more c code */ 
12814 \newline 
12815 clabel:\SpecialChar ~
12816 \SpecialChar ~
12817 /* inline assembler cannot reference this label */ 
12818 \newline 
12819 \SpecialChar ~
12820 \SpecialChar ~
12821 \SpecialChar ~
12822 \SpecialChar ~
12823 _asm
12824 \newline 
12825 \SpecialChar ~
12826 \SpecialChar ~
12827 \SpecialChar ~
12828 \SpecialChar ~
12829 $0003: ;label (can be referenced by inline assembler only) 
12830 \newline 
12831 \SpecialChar ~
12832 \SpecialChar ~
12833 \SpecialChar ~
12834 \SpecialChar ~
12835 _endasm
12836 \begin_inset LatexCommand \index{\_endasm}
12837
12838 \end_inset 
12839
12840
12841 \begin_inset LatexCommand \index{\_\_endasm}
12842
12843 \end_inset 
12844
12845  ; 
12846 \newline 
12847 \SpecialChar ~
12848 \SpecialChar ~
12849 \SpecialChar ~
12850 \SpecialChar ~
12851 /* some more c code */
12852 \newline 
12853 }
12854 \layout Standard
12855
12856 In other words inline assembly code can access labels defined in inline
12857  assembly within the scope of the function.
12858  The same goes the other way, i.e.
12859  labels defines in inline assembly can not be accessed by C statements.
12860 \layout Section
12861
12862 Interfacing with Assembler Code
12863 \begin_inset LatexCommand \index{Assembler routines}
12864
12865 \end_inset 
12866
12867
12868 \layout Subsection
12869
12870 Global Registers used for Parameter Passing
12871 \begin_inset LatexCommand \index{Parameter passing}
12872
12873 \end_inset 
12874
12875
12876 \layout Standard
12877
12878 The compiler always uses the global registers 
12879 \emph on 
12880 DPL, DPH
12881 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
12882
12883 \end_inset 
12884
12885
12886 \begin_inset LatexCommand \index{DPTR}
12887
12888 \end_inset 
12889
12890 , B
12891 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
12892
12893 \end_inset 
12894
12895  
12896 \emph default 
12897 and
12898 \emph on 
12899  ACC
12900 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
12901
12902 \end_inset 
12903
12904
12905 \emph default 
12906  to pass the first parameter to a routine.
12907  The second parameter onwards is either allocated on the stack (for reentrant
12908  routines or if -
12909 \begin_inset ERT
12910 status Collapsed
12911
12912 \layout Standard
12913
12914 \backslash 
12915 /
12916 \end_inset 
12917
12918 -stack-auto is used) or in data / xdata memory (depending on the memory
12919  model).
12920  
12921 \layout Subsection
12922
12923 Assembler Routine (non-reentrant)
12924 \layout Standard
12925
12926 In the following example
12927 \begin_inset LatexCommand \index{reentrant}
12928
12929 \end_inset 
12930
12931
12932 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
12933
12934 \end_inset 
12935
12936  the function c_func calls an assembler routine asm_func, which takes two
12937  parameters
12938 \begin_inset LatexCommand \index{function parameter}
12939
12940 \end_inset 
12941
12942 .
12943 \layout Verse
12944
12945
12946 \family typewriter 
12947 extern int asm_func(unsigned char, unsigned char);
12948 \newline 
12949
12950 \newline 
12951 int c_func (unsigned char i, unsigned char j)
12952 \newline 
12953 {
12954 \newline 
12955 \SpecialChar ~
12956 \SpecialChar ~
12957 \SpecialChar ~
12958 \SpecialChar ~
12959 return asm_func(i,j);
12960 \newline 
12961 }
12962 \newline 
12963
12964 \newline 
12965 int main()
12966 \newline 
12967 {
12968 \newline 
12969 \SpecialChar ~
12970 \SpecialChar ~
12971 \SpecialChar ~
12972 \SpecialChar ~
12973 return c_func(10,9);
12974 \newline 
12975 }
12976 \layout Standard
12977
12978 The corresponding assembler function is:
12979 \layout Verse
12980
12981
12982 \family typewriter 
12983 .globl _asm_func_PARM_2 
12984 \newline 
12985 \SpecialChar ~
12986 \SpecialChar ~
12987 \SpecialChar ~
12988 \SpecialChar ~
12989 \SpecialChar ~
12990 \SpecialChar ~
12991 \SpecialChar ~
12992 \SpecialChar ~
12993 .globl _asm_func 
12994 \newline 
12995 \SpecialChar ~
12996 \SpecialChar ~
12997 \SpecialChar ~
12998 \SpecialChar ~
12999 \SpecialChar ~
13000 \SpecialChar ~
13001 \SpecialChar ~
13002 \SpecialChar ~
13003 .area OSEG 
13004 \newline 
13005 _asm_func_PARM_2:
13006 \newline 
13007 \SpecialChar ~
13008 \SpecialChar ~
13009 \SpecialChar ~
13010 \SpecialChar ~
13011 \SpecialChar ~
13012 \SpecialChar ~
13013 \SpecialChar ~
13014 \SpecialChar ~
13015 .ds    1 
13016 \newline 
13017 \SpecialChar ~
13018 \SpecialChar ~
13019 \SpecialChar ~
13020 \SpecialChar ~
13021 \SpecialChar ~
13022 \SpecialChar ~
13023 \SpecialChar ~
13024 \SpecialChar ~
13025 .area CSEG 
13026 \newline 
13027 _asm_func: 
13028 \newline 
13029 \SpecialChar ~
13030 \SpecialChar ~
13031 \SpecialChar ~
13032 \SpecialChar ~
13033 \SpecialChar ~
13034 \SpecialChar ~
13035 \SpecialChar ~
13036 \SpecialChar ~
13037 mov\SpecialChar ~
13038 \SpecialChar ~
13039 \SpecialChar ~
13040 \SpecialChar ~
13041 a,dpl 
13042 \newline 
13043 \SpecialChar ~
13044 \SpecialChar ~
13045 \SpecialChar ~
13046 \SpecialChar ~
13047 \SpecialChar ~
13048 \SpecialChar ~
13049 \SpecialChar ~
13050 \SpecialChar ~
13051 add\SpecialChar ~
13052 \SpecialChar ~
13053 \SpecialChar ~
13054 \SpecialChar ~
13055 a,_asm_func_PARM_2 
13056 \newline 
13057 \SpecialChar ~
13058 \SpecialChar ~
13059 \SpecialChar ~
13060 \SpecialChar ~
13061 \SpecialChar ~
13062 \SpecialChar ~
13063 \SpecialChar ~
13064 \SpecialChar ~
13065 mov\SpecialChar ~
13066 \SpecialChar ~
13067 \SpecialChar ~
13068 \SpecialChar ~
13069 dpl,a 
13070 \newline 
13071 \SpecialChar ~
13072 \SpecialChar ~
13073 \SpecialChar ~
13074 \SpecialChar ~
13075 \SpecialChar ~
13076 \SpecialChar ~
13077 \SpecialChar ~
13078 \SpecialChar ~
13079 mov\SpecialChar ~
13080 \SpecialChar ~
13081 \SpecialChar ~
13082 \SpecialChar ~
13083 dph
13084 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
13085
13086 \end_inset 
13087
13088 ,#0x00 
13089 \newline 
13090 \SpecialChar ~
13091 \SpecialChar ~
13092 \SpecialChar ~
13093 \SpecialChar ~
13094 \SpecialChar ~
13095 \SpecialChar ~
13096 \SpecialChar ~
13097 \SpecialChar ~
13098 ret
13099 \layout Standard
13100
13101 Note here that the return values
13102 \begin_inset LatexCommand \index{return value}
13103
13104 \end_inset 
13105
13106  are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
13107  two byte values.
13108  'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
13109 b' & 'acc' for four byte values.
13110 \layout Standard
13111
13112 The parameter naming convention is _<function_name>_PARM_<n>, where n is
13113  the parameter number starting from 1, and counting from the left.
13114  The first parameter is passed in 
13115 \begin_inset Quotes eld
13116 \end_inset 
13117
13118 dpl
13119 \begin_inset Quotes erd
13120 \end_inset 
13121
13122  for a one byte parameter, 
13123 \begin_inset Quotes eld
13124 \end_inset 
13125
13126 dptr
13127 \begin_inset Quotes erd
13128 \end_inset 
13129
13130  for two bytes, 
13131 \begin_inset Quotes eld
13132 \end_inset 
13133
13134 b,dptr
13135 \begin_inset Quotes erd
13136 \end_inset 
13137
13138  for three bytes and 
13139 \begin_inset Quotes eld
13140 \end_inset 
13141
13142 acc,b,dptr
13143 \begin_inset Quotes erd
13144 \end_inset 
13145
13146  for a four bytes parameter.
13147  The variable name for the second parameter will be _<function_name>_PARM_2.
13148 \newline 
13149
13150 \newline 
13151 Assemble the assembler routine with the following command:
13152 \newline 
13153
13154 \newline 
13155
13156 \family sans 
13157 \series bold 
13158 asx8051 -losg asmfunc.asm
13159 \newline 
13160
13161 \newline 
13162
13163 \family default 
13164 \series default 
13165 Then compile and link the assembler routine to the C source file with the
13166  following command:
13167 \newline 
13168
13169 \newline 
13170
13171 \family sans 
13172 \series bold 
13173 sdcc cfunc.c asmfunc.rel
13174 \layout Subsection
13175
13176 Assembler Routine (reentrant)
13177 \layout Standard
13178
13179 In this case
13180 \begin_inset LatexCommand \index{reentrant}
13181
13182 \end_inset 
13183
13184
13185 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
13186
13187 \end_inset 
13188
13189  the second parameter
13190 \begin_inset LatexCommand \index{function parameter}
13191
13192 \end_inset 
13193
13194  onwards will be passed on the stack, the parameters are pushed from right
13195  to left i.e.
13196  after the call the leftmost parameter will be on the top of the stack.
13197  Here is an example:
13198 \layout Verse
13199
13200
13201 \family typewriter 
13202 extern int asm_func(unsigned char, unsigned char);
13203 \newline 
13204
13205 \newline 
13206 int c_func (unsigned char i, unsigned char j) reentrant 
13207 \newline 
13208
13209 \newline 
13210 \SpecialChar ~
13211 \SpecialChar ~
13212 \SpecialChar ~
13213 \SpecialChar ~
13214 return asm_func(i,j); 
13215 \newline 
13216
13217 \newline 
13218
13219 \newline 
13220 int main() 
13221 \newline 
13222
13223 \newline 
13224 \SpecialChar ~
13225 \SpecialChar ~
13226 \SpecialChar ~
13227 \SpecialChar ~
13228 return c_func(10,9); 
13229 \newline 
13230 }
13231 \layout Standard
13232
13233 The corresponding assembler routine is:
13234 \layout Verse
13235
13236
13237 \family typewriter 
13238 .globl _asm_func 
13239 \newline 
13240 _asm_func: 
13241 \newline 
13242 \SpecialChar ~
13243 \SpecialChar ~
13244 \SpecialChar ~
13245 \SpecialChar ~
13246 push  _bp 
13247 \newline 
13248 \SpecialChar ~
13249 \SpecialChar ~
13250 \SpecialChar ~
13251 \SpecialChar ~
13252 mov _bp,sp 
13253 \newline 
13254 \SpecialChar ~
13255 \SpecialChar ~
13256 \SpecialChar ~
13257 \SpecialChar ~
13258 mov r2,dpl
13259 \newline 
13260 \SpecialChar ~
13261 \SpecialChar ~
13262 \SpecialChar ~
13263 \SpecialChar ~
13264 mov a,_bp 
13265 \newline 
13266 \SpecialChar ~
13267 \SpecialChar ~
13268 \SpecialChar ~
13269 \SpecialChar ~
13270 add a,#0xfd 
13271 \newline 
13272 \SpecialChar ~
13273 \SpecialChar ~
13274 \SpecialChar ~
13275 \SpecialChar ~
13276 mov r0,a 
13277 \newline 
13278 \SpecialChar ~
13279 \SpecialChar ~
13280 \SpecialChar ~
13281 \SpecialChar ~
13282 add  a,#0xfc ;?
13283 \newline 
13284 \SpecialChar ~
13285 \SpecialChar ~
13286 \SpecialChar ~
13287 \SpecialChar ~
13288 mov  r1,a 
13289 \newline 
13290 \SpecialChar ~
13291 \SpecialChar ~
13292 \SpecialChar ~
13293 \SpecialChar ~
13294 mov  a,@r0 
13295 \newline 
13296 \SpecialChar ~
13297 \SpecialChar ~
13298 \SpecialChar ~
13299 \SpecialChar ~
13300 add  a,r2 ;?
13301 \newline 
13302 \SpecialChar ~
13303 \SpecialChar ~
13304 \SpecialChar ~
13305 \SpecialChar ~
13306 mov  dpl,a 
13307 \newline 
13308 \SpecialChar ~
13309 \SpecialChar ~
13310 \SpecialChar ~
13311 \SpecialChar ~
13312 mov  dph,#0x00 
13313 \newline 
13314 \SpecialChar ~
13315 \SpecialChar ~
13316 \SpecialChar ~
13317 \SpecialChar ~
13318 mov  sp,_bp 
13319 \newline 
13320 \SpecialChar ~
13321 \SpecialChar ~
13322 \SpecialChar ~
13323 \SpecialChar ~
13324 pop  _bp 
13325 \newline 
13326 \SpecialChar ~
13327 \SpecialChar ~
13328 \SpecialChar ~
13329 \SpecialChar ~
13330 ret
13331 \layout Standard
13332
13333 The compiling and linking procedure remains the same, however note the extra
13334  entry & exit linkage required for the assembler code, _bp is the stack
13335  frame pointer and is used to compute the offset into the stack for parameters
13336  and local variables.
13337 \layout Section
13338
13339 int (16 bit)
13340 \begin_inset LatexCommand \index{int (16 bit)}
13341
13342 \end_inset 
13343
13344  and long (32 bit)
13345 \begin_inset LatexCommand \index{long (32 bit)}
13346
13347 \end_inset 
13348
13349  Support
13350 \layout Standard
13351
13352 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
13353  multiplication and modulus operations are implemented by support routines.
13354  These support routines are all developed in ANSI-C to facilitate porting
13355  to other MCUs, although some model specific assembler optimizations are
13356  used.
13357  The following files contain the described routines, all of them can be
13358  found in <installdir>/share/sdcc/lib.
13359 \newline 
13360
13361 \layout Standard
13362 \align center 
13363
13364 \begin_inset  Tabular
13365 <lyxtabular version="3" rows="11" columns="2">
13366 <features>
13367 <column alignment="center" valignment="top" leftline="true" width="0">
13368 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
13369 <row topline="true" bottomline="true">
13370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13371 \begin_inset Text
13372
13373 \layout Standard
13374
13375
13376 \series bold 
13377 Function
13378 \end_inset 
13379 </cell>
13380 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13381 \begin_inset Text
13382
13383 \layout Standard
13384
13385
13386 \series bold 
13387 Description
13388 \end_inset 
13389 </cell>
13390 </row>
13391 <row topline="true">
13392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13393 \begin_inset Text
13394
13395 \layout Standard
13396
13397 _mulint.c 
13398 \end_inset 
13399 </cell>
13400 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13401 \begin_inset Text
13402
13403 \layout Standard
13404
13405 16 bit multiplication
13406 \end_inset 
13407 </cell>
13408 </row>
13409 <row topline="true">
13410 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13411 \begin_inset Text
13412
13413 \layout Standard
13414
13415 _divsint.c 
13416 \end_inset 
13417 </cell>
13418 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13419 \begin_inset Text
13420
13421 \layout Standard
13422
13423  signed 16 bit division (calls _divuint)
13424 \end_inset 
13425 </cell>
13426 </row>
13427 <row topline="true">
13428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13429 \begin_inset Text
13430
13431 \layout Standard
13432
13433 _divuint.c 
13434 \end_inset 
13435 </cell>
13436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13437 \begin_inset Text
13438
13439 \layout Standard
13440
13441  unsigned 16 bit division
13442 \end_inset 
13443 </cell>
13444 </row>
13445 <row topline="true">
13446 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13447 \begin_inset Text
13448
13449 \layout Standard
13450
13451 _modsint.c
13452 \end_inset 
13453 </cell>
13454 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13455 \begin_inset Text
13456
13457 \layout Standard
13458
13459 signed 16 bit modulus (calls _moduint)
13460 \end_inset 
13461 </cell>
13462 </row>
13463 <row topline="true">
13464 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13465 \begin_inset Text
13466
13467 \layout Standard
13468
13469 _moduint.c
13470 \end_inset 
13471 </cell>
13472 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13473 \begin_inset Text
13474
13475 \layout Standard
13476
13477 unsigned 16 bit modulus
13478 \end_inset 
13479 </cell>
13480 </row>
13481 <row topline="true">
13482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13483 \begin_inset Text
13484
13485 \layout Standard
13486
13487 _mullong.c
13488 \end_inset 
13489 </cell>
13490 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13491 \begin_inset Text
13492
13493 \layout Standard
13494
13495 32 bit multiplication
13496 \end_inset 
13497 </cell>
13498 </row>
13499 <row topline="true">
13500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13501 \begin_inset Text
13502
13503 \layout Standard
13504
13505 _divslong.c 
13506 \end_inset 
13507 </cell>
13508 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13509 \begin_inset Text
13510
13511 \layout Standard
13512
13513  signed 32 division (calls _divulong)
13514 \end_inset 
13515 </cell>
13516 </row>
13517 <row topline="true">
13518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13519 \begin_inset Text
13520
13521 \layout Standard
13522
13523 _divulong.c 
13524 \end_inset 
13525 </cell>
13526 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13527 \begin_inset Text
13528
13529 \layout Standard
13530
13531 unsigned 32 division
13532 \end_inset 
13533 </cell>
13534 </row>
13535 <row topline="true">
13536 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13537 \begin_inset Text
13538
13539 \layout Standard
13540
13541 _modslong.c
13542 \end_inset 
13543 </cell>
13544 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13545 \begin_inset Text
13546
13547 \layout Standard
13548
13549  signed 32 bit modulus (calls _modulong)
13550 \end_inset 
13551 </cell>
13552 </row>
13553 <row topline="true" bottomline="true">
13554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13555 \begin_inset Text
13556
13557 \layout Standard
13558
13559 _modulong.c
13560 \end_inset 
13561 </cell>
13562 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13563 \begin_inset Text
13564
13565 \layout Standard
13566
13567 unsigned 32 bit modulus
13568 \end_inset 
13569 </cell>
13570 </row>
13571 </lyxtabular>
13572
13573 \end_inset 
13574
13575
13576 \newline 
13577
13578 \layout Standard
13579
13580 Since they are compiled as 
13581 \emph on 
13582 non-reentrant
13583 \emph default 
13584
13585 \begin_inset LatexCommand \index{reentrant}
13586
13587 \end_inset 
13588
13589 , interrupt
13590 \begin_inset LatexCommand \index{interrupt}
13591
13592 \end_inset 
13593
13594  service routines should not do any of the above operations.
13595  If this is unavoidable then the above routines will need to be compiled
13596  with the 
13597 \emph on 
13598 -
13599 \begin_inset ERT
13600 status Collapsed
13601
13602 \layout Standard
13603
13604 \backslash 
13605 /
13606 \end_inset 
13607
13608 -stack-auto
13609 \begin_inset LatexCommand \index{-\/-stack-auto}
13610
13611 \end_inset 
13612
13613
13614 \emph default 
13615  option, after which the source program will have to be compiled with 
13616 \emph on 
13617 -
13618 \begin_inset ERT
13619 status Collapsed
13620
13621 \layout Standard
13622
13623 \backslash 
13624 /
13625 \end_inset 
13626
13627 -int-long-reent
13628 \begin_inset LatexCommand \index{-\/-int-long-reent}
13629
13630 \end_inset 
13631
13632
13633 \emph default 
13634  option.
13635  Notice that you don't have to call these routines directly.
13636  The compiler will use them automatically every time an integer operation
13637  is required.
13638 \layout Section
13639
13640 Floating Point Support
13641 \begin_inset LatexCommand \index{Floating point support}
13642
13643 \end_inset 
13644
13645
13646 \layout Standard
13647
13648 SDCC supports IEEE (single precision 4 bytes) floating point numbers.The
13649  floating point support routines are derived from gcc's floatlib.c and consist
13650  of the following routines:
13651 \newline 
13652
13653 \layout Standard
13654 \align center 
13655
13656 \size footnotesize 
13657
13658 \begin_inset  Tabular
13659 <lyxtabular version="3" rows="17" columns="2">
13660 <features>
13661 <column alignment="center" valignment="top" leftline="true" width="0">
13662 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
13663 <row topline="true" bottomline="true">
13664 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13665 \begin_inset Text
13666
13667 \layout Standard
13668
13669
13670 \family roman 
13671 \series medium 
13672 \shape up 
13673 \size normal 
13674 \emph off 
13675 \bar no 
13676 \noun off 
13677 \color none
13678 Function 
13679 \end_inset 
13680 </cell>
13681 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13682 \begin_inset Text
13683
13684 \layout Standard
13685
13686 Description
13687 \end_inset 
13688 </cell>
13689 </row>
13690 <row topline="true">
13691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13692 \begin_inset Text
13693
13694 \layout Standard
13695
13696
13697 \family roman 
13698 \series medium 
13699 \shape up 
13700 \size normal 
13701 \emph off 
13702 \bar no 
13703 \noun off 
13704 \color none
13705 _fsadd.c
13706 \end_inset 
13707 </cell>
13708 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13709 \begin_inset Text
13710
13711 \layout Standard
13712
13713
13714 \family roman 
13715 \series medium 
13716 \shape up 
13717 \size normal 
13718 \emph off 
13719 \bar no 
13720 \noun off 
13721 \color none
13722 add floating point numbers
13723 \end_inset 
13724 </cell>
13725 </row>
13726 <row topline="true">
13727 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13728 \begin_inset Text
13729
13730 \layout Standard
13731
13732
13733 \family roman 
13734 \series medium 
13735 \shape up 
13736 \size normal 
13737 \emph off 
13738 \bar no 
13739 \noun off 
13740 \color none
13741 _fssub.c 
13742 \end_inset 
13743 </cell>
13744 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13745 \begin_inset Text
13746
13747 \layout Standard
13748
13749
13750 \family roman 
13751 \series medium 
13752 \shape up 
13753 \size normal 
13754 \emph off 
13755 \bar no 
13756 \noun off 
13757 \color none
13758 subtract floating point numbers 
13759 \end_inset 
13760 </cell>
13761 </row>
13762 <row topline="true">
13763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13764 \begin_inset Text
13765
13766 \layout Standard
13767
13768
13769 \family roman 
13770 \series medium 
13771 \shape up 
13772 \size normal 
13773 \emph off 
13774 \bar no 
13775 \noun off 
13776 \color none
13777 _fsdiv.c 
13778 \end_inset 
13779 </cell>
13780 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13781 \begin_inset Text
13782
13783 \layout Standard
13784
13785
13786 \family roman 
13787 \series medium 
13788 \shape up 
13789 \size normal 
13790 \emph off 
13791 \bar no 
13792 \noun off 
13793 \color none
13794 divide floating point numbers 
13795 \end_inset 
13796 </cell>
13797 </row>
13798 <row topline="true">
13799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13800 \begin_inset Text
13801
13802 \layout Standard
13803
13804
13805 \family roman 
13806 \series medium 
13807 \shape up 
13808 \size normal 
13809 \emph off 
13810 \bar no 
13811 \noun off 
13812 \color none
13813 _fsmul.c 
13814 \end_inset 
13815 </cell>
13816 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13817 \begin_inset Text
13818
13819 \layout Standard
13820
13821
13822 \family roman 
13823 \series medium 
13824 \shape up 
13825 \size normal 
13826 \emph off 
13827 \bar no 
13828 \noun off 
13829 \color none
13830 multiply floating point numbers 
13831 \end_inset 
13832 </cell>
13833 </row>
13834 <row topline="true">
13835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13836 \begin_inset Text
13837
13838 \layout Standard
13839
13840
13841 \family roman 
13842 \series medium 
13843 \shape up 
13844 \size normal 
13845 \emph off 
13846 \bar no 
13847 \noun off 
13848 \color none
13849 _fs2uchar.c
13850 \end_inset 
13851 </cell>
13852 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13853 \begin_inset Text
13854
13855 \layout Standard
13856
13857
13858 \family roman 
13859 \series medium 
13860 \shape up 
13861 \size normal 
13862 \emph off 
13863 \bar no 
13864 \noun off 
13865 \color none
13866 convert floating point to unsigned char
13867 \end_inset 
13868 </cell>
13869 </row>
13870 <row topline="true">
13871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13872 \begin_inset Text
13873
13874 \layout Standard
13875
13876
13877 \family roman 
13878 \series medium 
13879 \shape up 
13880 \size normal 
13881 \emph off 
13882 \bar no 
13883 \noun off 
13884 \color none
13885 _fs2char.c
13886 \end_inset 
13887 </cell>
13888 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13889 \begin_inset Text
13890
13891 \layout Standard
13892
13893
13894 \family roman 
13895 \series medium 
13896 \shape up 
13897 \size normal 
13898 \emph off 
13899 \bar no 
13900 \noun off 
13901 \color none
13902 convert floating point to signed char
13903 \end_inset 
13904 </cell>
13905 </row>
13906 <row topline="true">
13907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13908 \begin_inset Text
13909
13910 \layout Standard
13911
13912
13913 \family roman 
13914 \series medium 
13915 \shape up 
13916 \size normal 
13917 \emph off 
13918 \bar no 
13919 \noun off 
13920 \color none
13921 _fs2uint.c
13922 \end_inset 
13923 </cell>
13924 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13925 \begin_inset Text
13926
13927 \layout Standard
13928
13929
13930 \family roman 
13931 \series medium 
13932 \shape up 
13933 \size normal 
13934 \emph off 
13935 \bar no 
13936 \noun off 
13937 \color none
13938 convert floating point to unsigned int
13939 \end_inset 
13940 </cell>
13941 </row>
13942 <row topline="true">
13943 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13944 \begin_inset Text
13945
13946 \layout Standard
13947
13948
13949 \family roman 
13950 \series medium 
13951 \shape up 
13952 \size normal 
13953 \emph off 
13954 \bar no 
13955 \noun off 
13956 \color none
13957 _fs2int.c
13958 \end_inset 
13959 </cell>
13960 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13961 \begin_inset Text
13962
13963 \layout Standard
13964
13965
13966 \family roman 
13967 \series medium 
13968 \shape up 
13969 \size normal 
13970 \emph off 
13971 \bar no 
13972 \noun off 
13973 \color none
13974 convert floating point to signed int
13975 \end_inset 
13976 </cell>
13977 </row>
13978 <row topline="true">
13979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13980 \begin_inset Text
13981
13982 \layout Standard
13983
13984
13985 \family roman 
13986 \series medium 
13987 \shape up 
13988 \size normal 
13989 \emph off 
13990 \bar no 
13991 \noun off 
13992 \color none
13993 _fs2ulong.
13994 \family default 
13995 \series default 
13996 \shape default 
13997 \size default 
13998 \emph default 
13999 \bar default 
14000 \noun default 
14001 \color default
14002 c
14003 \end_inset 
14004 </cell>
14005 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14006 \begin_inset Text
14007
14008 \layout Standard
14009
14010
14011 \family roman 
14012 \series medium 
14013 \shape up 
14014 \size normal 
14015 \emph off 
14016 \bar no 
14017 \noun off 
14018 \color none
14019 convert floating point to unsigned long
14020 \end_inset 
14021 </cell>
14022 </row>
14023 <row topline="true">
14024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14025 \begin_inset Text
14026
14027 \layout Standard
14028
14029
14030 \family roman 
14031 \series medium 
14032 \shape up 
14033 \size normal 
14034 \emph off 
14035 \bar no 
14036 \noun off 
14037 \color none
14038 _fs2long.c
14039 \end_inset 
14040 </cell>
14041 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14042 \begin_inset Text
14043
14044 \layout Standard
14045
14046
14047 \family roman 
14048 \series medium 
14049 \shape up 
14050 \size normal 
14051 \emph off 
14052 \bar no 
14053 \noun off 
14054 \color none
14055 convert floating point to signed long
14056 \end_inset 
14057 </cell>
14058 </row>
14059 <row topline="true">
14060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14061 \begin_inset Text
14062
14063 \layout Standard
14064
14065
14066 \family roman 
14067 \series medium 
14068 \shape up 
14069 \size normal 
14070 \emph off 
14071 \bar no 
14072 \noun off 
14073 \color none
14074 _uchar2fs.c
14075 \end_inset 
14076 </cell>
14077 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14078 \begin_inset Text
14079
14080 \layout Standard
14081
14082
14083 \family roman 
14084 \series medium 
14085 \shape up 
14086 \size normal 
14087 \emph off 
14088 \bar no 
14089 \noun off 
14090 \color none
14091 convert unsigned char to floating point
14092 \end_inset 
14093 </cell>
14094 </row>
14095 <row topline="true">
14096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14097 \begin_inset Text
14098
14099 \layout Standard
14100
14101
14102 \family roman 
14103 \series medium 
14104 \shape up 
14105 \size normal 
14106 \emph off 
14107 \bar no 
14108 \noun off 
14109 \color none
14110 _char2fs.c
14111 \end_inset 
14112 </cell>
14113 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14114 \begin_inset Text
14115
14116 \layout Standard
14117
14118
14119 \family roman 
14120 \series medium 
14121 \shape up 
14122 \size normal 
14123 \emph off 
14124 \bar no 
14125 \noun off 
14126 \color none
14127 convert char to floating point number
14128 \end_inset 
14129 </cell>
14130 </row>
14131 <row topline="true">
14132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14133 \begin_inset Text
14134
14135 \layout Standard
14136
14137
14138 \family roman 
14139 \series medium 
14140 \shape up 
14141 \size normal 
14142 \emph off 
14143 \bar no 
14144 \noun off 
14145 \color none
14146 _uint2fs.c
14147 \end_inset 
14148 </cell>
14149 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14150 \begin_inset Text
14151
14152 \layout Standard
14153
14154
14155 \family roman 
14156 \series medium 
14157 \shape up 
14158 \size normal 
14159 \emph off 
14160 \bar no 
14161 \noun off 
14162 \color none
14163 convert unsigned int to floating point
14164 \end_inset 
14165 </cell>
14166 </row>
14167 <row topline="true">
14168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14169 \begin_inset Text
14170
14171 \layout Standard
14172
14173
14174 \family roman 
14175 \series medium 
14176 \shape up 
14177 \size normal 
14178 \emph off 
14179 \bar no 
14180 \noun off 
14181 \color none
14182 _int2fs.c
14183 \end_inset 
14184 </cell>
14185 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14186 \begin_inset Text
14187
14188 \layout Standard
14189
14190
14191 \family roman 
14192 \series medium 
14193 \shape up 
14194 \size normal 
14195 \emph off 
14196 \bar no 
14197 \noun off 
14198 \color none
14199 convert int to floating point numbers
14200 \end_inset 
14201 </cell>
14202 </row>
14203 <row topline="true">
14204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14205 \begin_inset Text
14206
14207 \layout Standard
14208
14209
14210 \family roman 
14211 \series medium 
14212 \shape up 
14213 \size normal 
14214 \emph off 
14215 \bar no 
14216 \noun off 
14217 \color none
14218 _ulong2fs.c
14219 \end_inset 
14220 </cell>
14221 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14222 \begin_inset Text
14223
14224 \layout Standard
14225
14226
14227 \family roman 
14228 \series medium 
14229 \shape up 
14230 \size normal 
14231 \emph off 
14232 \bar no 
14233 \noun off 
14234 \color none
14235 convert unsigned long to floating point number
14236 \end_inset 
14237 </cell>
14238 </row>
14239 <row topline="true" bottomline="true">
14240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14241 \begin_inset Text
14242
14243 \layout Standard
14244
14245
14246 \family roman 
14247 \series medium 
14248 \shape up 
14249 \size normal 
14250 \emph off 
14251 \bar no 
14252 \noun off 
14253 \color none
14254 _long2fs.c
14255 \end_inset 
14256 </cell>
14257 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14258 \begin_inset Text
14259
14260 \layout Standard
14261
14262
14263 \family roman 
14264 \series medium 
14265 \shape up 
14266 \size normal 
14267 \emph off 
14268 \bar no 
14269 \noun off 
14270 \color none
14271 convert long to floating point number
14272 \end_inset 
14273 </cell>
14274 </row>
14275 </lyxtabular>
14276
14277 \end_inset 
14278
14279
14280 \newline 
14281
14282 \layout Standard
14283
14284 These support routines are developed in ANSI-C so there is room for space
14285  and speed improvement
14286 \begin_inset Foot
14287 collapsed false
14288
14289 \layout Standard
14290
14291 The floating point routines for the mcs51 are implemented in assembler
14292 \end_inset 
14293
14294 .
14295  Note if all these routines are used simultaneously the data space might
14296  overflow.
14297  For serious floating point usage the large model might be needed.
14298  Also notice that you don't have to call this routines directly.
14299  The compiler will use them automatically every time a floating point operation
14300  is required.
14301 \layout Section
14302
14303 Library Routines
14304 \begin_inset LatexCommand \index{Libraries}
14305
14306 \end_inset 
14307
14308
14309 \layout Standard
14310
14311
14312 \emph on 
14313 <pending: this is messy and incomplete - a little more information is in
14314  sdcc/doc/libdoc.txt
14315 \emph default 
14316  >
14317 \layout Subsection
14318
14319 Compiler support routines (_gptrget, _mulint etc.)
14320 \layout Subsection
14321
14322 Stdclib functions (puts, printf, strcat etc.)
14323 \layout Subsubsection
14324
14325 <stdio.h>
14326 \layout Standard
14327
14328
14329 \begin_inset LatexCommand \index{<stdio.h>}
14330
14331 \end_inset 
14332
14333 As usual on embedded systems you have to provide your own 
14334 \family typewriter 
14335 getchar()
14336 \begin_inset LatexCommand \index{getchar()}
14337
14338 \end_inset 
14339
14340  
14341 \family default 
14342 and 
14343 \family typewriter 
14344 putchar()
14345 \begin_inset LatexCommand \index{putchar()}
14346
14347 \end_inset 
14348
14349
14350 \family default 
14351  routines.
14352  SDCC does not know whether the system connects to a serial line with or
14353  without handshake, LCD, keyboard or other device.
14354  You'll find examples for serial routines f.e.
14355  in sdcc/device/lib.
14356 \layout Standard
14357
14358 The default
14359 \family typewriter 
14360  printf()
14361 \begin_inset LatexCommand \index{printf()}
14362
14363 \end_inset 
14364
14365
14366 \family default 
14367 implementation in
14368 \family typewriter 
14369  printf_large.c
14370 \family default 
14371  does not support float (except on ds390).
14372  To enable this recompile it with the option 
14373 \emph on 
14374 -
14375 \begin_inset ERT
14376 status Collapsed
14377
14378 \layout Standard
14379
14380 \backslash 
14381 /
14382 \end_inset 
14383
14384 DUSE_FLOATS=1
14385 \begin_inset LatexCommand \index{USE\_FLOATS}
14386
14387 \end_inset 
14388
14389
14390 \emph default 
14391  on the command line.
14392  Use
14393 \emph on 
14394 -
14395 \begin_inset ERT
14396 status Collapsed
14397
14398 \layout Standard
14399
14400 \backslash 
14401 /
14402 \end_inset 
14403
14404 -model-large
14405 \begin_inset LatexCommand \index{-\/-model-large}
14406
14407 \end_inset 
14408
14409
14410 \emph default 
14411  for the mcs51 port, since this uses a lot of memory.
14412 \layout Standard
14413
14414 If you're short on memory you might want to use 
14415 \family typewriter 
14416 printf_small()
14417 \begin_inset LatexCommand \index{printf\_small()}
14418
14419 \end_inset 
14420
14421
14422 \family default 
14423  
14424 \emph on 
14425 instead
14426 \emph default 
14427  of
14428 \family typewriter 
14429  printf().
14430
14431 \family default 
14432  For the mcs51 there additionally are assembly versions 
14433 \family typewriter 
14434 printf_tiny()
14435 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
14436
14437 \end_inset 
14438
14439
14440 \family default 
14441  and 
14442 \family typewriter 
14443 printf_fast()
14444 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
14445
14446 \end_inset 
14447
14448  
14449 \family default 
14450 and
14451 \family typewriter 
14452  printf_fast_f()
14453 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
14454
14455 \end_inset 
14456
14457
14458 \family default 
14459  which should fit the requirements of many embedded systems (printf_fast()
14460  can be customized by unsetting #defines to 
14461 \emph on 
14462 not
14463 \emph default 
14464  support long variables and field widths).
14465 \layout Subsection
14466
14467 Math functions (sin, pow, sqrt etc.)
14468 \layout Subsection
14469
14470 Other libraries
14471 \layout Standard
14472
14473 Libraries
14474 \begin_inset LatexCommand \index{Libraries}
14475
14476 \end_inset 
14477
14478  included in SDCC should have a license at least as liberal as the GNU Lesser
14479  General Public License
14480 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
14481
14482 \end_inset 
14483
14484  
14485 \emph on 
14486 LGPL
14487 \emph default 
14488 .
14489 \layout Comment
14490
14491 license statements for the libraries are missing.
14492  sdcc/device/lib/ser_ir.c
14493 \layout Comment
14494
14495 or _decdptr f.e.
14496  come with a GPL (as opposed to LGPL) License - this will not be liberal
14497  enough for many embedded programmers.
14498 \layout Standard
14499
14500 If you have ported some library or want to share experience about some code
14501  which f.e.
14502  falls into any of these categories Busses (I
14503 \begin_inset Formula $^{\textrm{2}}$
14504 \end_inset 
14505
14506 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
14507  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
14508  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
14509 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
14510
14511 \end_inset 
14512
14513 \SpecialChar ~
14514 would certainly like to hear about it.
14515  Programmers coding for embedded systems are not especially famous for being
14516  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
14517 e these references are very valuable.
14518  Let's help to create a climate where information is shared.
14519 \layout Section
14520
14521 Memory Models
14522 \layout Subsection
14523
14524 MCS51 Memory Models
14525 \begin_inset LatexCommand \index{Memory model}
14526
14527 \end_inset 
14528
14529
14530 \begin_inset LatexCommand \index{MCS51 memory model}
14531
14532 \end_inset 
14533
14534
14535 \layout Subsubsection
14536
14537 Small and Large
14538 \layout Standard
14539
14540 SDCC allows two memory models for MCS51 code, 
14541 \shape slanted 
14542 small
14543 \shape default 
14544  and 
14545 \shape slanted 
14546 large
14547 \shape default 
14548 .
14549  Modules compiled with different memory models should 
14550 \emph on 
14551 never
14552 \emph default 
14553  be combined together or the results would be unpredictable.
14554  The library routines supplied with the compiler are compiled as both small
14555  and large.
14556  The compiled library modules are contained in separate directories as small
14557  and large so that you can link to either set.
14558  
14559 \layout Standard
14560
14561 When the large model is used all variables declared without a storage class
14562  will be allocated into the external ram, this includes all parameters and
14563  local variables (for non-reentrant
14564 \begin_inset LatexCommand \index{reentrant}
14565
14566 \end_inset 
14567
14568  functions).
14569  When the small model is used variables without storage class are allocated
14570  in the internal ram.
14571 \layout Standard
14572
14573 Judicious usage of the processor specific storage classes
14574 \begin_inset LatexCommand \index{Storage class}
14575
14576 \end_inset 
14577
14578  and the 'reentrant' function type will yield much more efficient code,
14579  than using the large model.
14580  Several optimizations are disabled when the program is compiled using the
14581  large model, it is therefore recommended that the small model be used unless
14582  absolutely required.
14583 \layout Subsubsection
14584
14585 External Stack
14586 \begin_inset LatexCommand \label{sub:External-Stack}
14587
14588 \end_inset 
14589
14590
14591 \begin_inset LatexCommand \index{stack}
14592
14593 \end_inset 
14594
14595
14596 \begin_inset LatexCommand \index{External stack (mcs51)}
14597
14598 \end_inset 
14599
14600
14601 \layout Standard
14602
14603 The external stack (-
14604 \begin_inset ERT
14605 status Collapsed
14606
14607 \layout Standard
14608
14609 \backslash 
14610 /
14611 \end_inset 
14612
14613 -xstack option
14614 \begin_inset LatexCommand \index{-\/-xstack}
14615
14616 \end_inset 
14617
14618 ) is located in pdata
14619 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
14620
14621 \end_inset 
14622
14623  memory (usually at the start of the external ram segment) and uses all
14624  unused space in pdata (max.
14625  256 bytes).
14626  When -
14627 \begin_inset ERT
14628 status Collapsed
14629
14630 \layout Standard
14631
14632 \backslash 
14633 /
14634 \end_inset 
14635
14636 -xstack option is used to compile the program, the parameters and local
14637  variables
14638 \begin_inset LatexCommand \index{local variables}
14639
14640 \end_inset 
14641
14642  of all reentrant functions are allocated in this area.
14643  This option is provided for programs with large stack space requirements.
14644  When used with the -
14645 \begin_inset ERT
14646 status Collapsed
14647
14648 \layout Standard
14649
14650 \backslash 
14651 /
14652 \end_inset 
14653
14654 -stack-auto
14655 \begin_inset LatexCommand \index{-\/-stack-auto}
14656
14657 \end_inset 
14658
14659  option, all parameters and local variables are allocated on the external
14660  stack (note: support libraries will need to be recompiled with the same
14661  options.
14662  There is a predefined target in the library makefile).
14663 \layout Standard
14664
14665 The compiler outputs the higher order address byte of the external ram segment
14666  into port P2
14667 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
14668
14669 \end_inset 
14670
14671  (see also section 
14672 \begin_inset LatexCommand \ref{sub:MCS51-variants}
14673
14674 \end_inset 
14675
14676 ), therefore when using the External Stack option, this port 
14677 \emph on 
14678 may not
14679 \emph default 
14680  be used by the application program.
14681 \layout Subsection
14682
14683 DS390 Memory Model
14684 \begin_inset LatexCommand \index{Memory model}
14685
14686 \end_inset 
14687
14688
14689 \begin_inset LatexCommand \index{DS390 memory model}
14690
14691 \end_inset 
14692
14693
14694 \layout Standard
14695
14696 The only model supported is Flat 24
14697 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
14698
14699 \end_inset 
14700
14701 .
14702  This generates code for the 24 bit contiguous addressing mode of the Dallas
14703  DS80C390 part.
14704  In this mode, up to four meg of external RAM or code space can be directly
14705  addressed.
14706  See the data sheets at www.dalsemi.com for further information on this part.
14707 \newline 
14708
14709 \newline 
14710 Note that the compiler does not generate any code to place the processor
14711  into 24 bitmode (although 
14712 \emph on 
14713 tinibios
14714 \emph default 
14715  in the ds390 libraries will do that for you).
14716  If you don't use 
14717 \emph on 
14718 tinibios
14719 \emph default 
14720
14721 \begin_inset LatexCommand \index{Tinibios (DS390)}
14722
14723 \end_inset 
14724
14725 , the boot loader or similar code must ensure that the processor is in 24
14726  bit contiguous addressing mode before calling the SDCC startup code.
14727 \newline 
14728
14729 \newline 
14730 Like the 
14731 \emph on 
14732 -
14733 \begin_inset ERT
14734 status Collapsed
14735
14736 \layout Standard
14737
14738 \backslash 
14739 /
14740 \end_inset 
14741
14742 -model-large
14743 \emph default 
14744  option, variables will by default be placed into the XDATA segment.
14745  
14746 \newline 
14747
14748 \newline 
14749 Segments may be placed anywhere in the 4 meg address space using the usual
14750  -
14751 \begin_inset ERT
14752 status Collapsed
14753
14754 \layout Standard
14755
14756 \backslash 
14757 /
14758 \end_inset 
14759
14760 -*-loc options.
14761  Note that if any segments are located above 64K, the -r flag must be passed
14762  to the linker to generate the proper segment relocations, and the Intel
14763  HEX output format must be used.
14764  The -r flag can be passed to the linker by using the option 
14765 \emph on 
14766 -Wl-r
14767 \emph default 
14768  on the SDCC command line.
14769  However, currently the linker can not handle code segments > 64k.
14770 \layout Section
14771
14772 Pragmas
14773 \begin_inset LatexCommand \index{Pragmas}
14774
14775 \end_inset 
14776
14777
14778 \layout Standard
14779
14780 SDCC supports the following #pragma directives:
14781 \layout Itemize
14782
14783 save
14784 \begin_inset LatexCommand \index{\#pragma save}
14785
14786 \end_inset 
14787
14788  - this will save all current options to the save/restore stack.
14789  See #pragma\SpecialChar ~
14790 restore.
14791 \layout Itemize
14792
14793 restore
14794 \begin_inset LatexCommand \index{\#pragma restore}
14795
14796 \end_inset 
14797
14798  - will restore saved options from the last save.
14799  saves & restores can be nested.
14800  SDCC uses a save/restore stack: save pushes current options to the stack,
14801  restore pulls current options from the stack.
14802  See #pragma\SpecialChar ~
14803 save.
14804 \newline 
14805
14806 \layout Itemize
14807
14808 callee_saves
14809 \begin_inset LatexCommand \index{\#pragma callee\_saves}
14810
14811 \end_inset 
14812
14813
14814 \begin_inset LatexCommand \index{function prologue}
14815
14816 \end_inset 
14817
14818  function1[,function2[,function3...]] - The compiler by default uses a caller
14819  saves convention for register saving across function calls, however this
14820  can cause unnecessary register pushing & popping
14821 \begin_inset LatexCommand \index{push/pop}
14822
14823 \end_inset 
14824
14825  when calling small functions from larger functions.
14826  This option can be used to switch off the register saving convention for
14827  the function names specified.
14828  The compiler will not save registers when calling these functions, extra
14829  code need to be manually inserted at the entry & exit for these functions
14830  to save & restore the registers used by these functions, this can SUBSTANTIALLY
14831  reduce code & improve run time performance of the generated code.
14832  In the future the compiler (with inter procedural analysis) may be able
14833  to determine the appropriate scheme to use for each function call.
14834  If -
14835 \begin_inset ERT
14836 status Collapsed
14837
14838 \layout Standard
14839
14840 \backslash 
14841 /
14842 \end_inset 
14843
14844 -callee-saves command line option is used, the function names specified
14845  in #pragma\SpecialChar ~
14846 callee_saves
14847 \begin_inset LatexCommand \index{\#pragma callee\_saves}
14848
14849 \end_inset 
14850
14851  is appended to the list of functions specified in the command line.
14852 \layout Itemize
14853
14854 exclude
14855 \begin_inset LatexCommand \index{\#pragma exclude}
14856
14857 \end_inset 
14858
14859  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
14860  of pairs of push/pop
14861 \begin_inset LatexCommand \index{push/pop}
14862
14863 \end_inset 
14864
14865  instructions in 
14866 \emph on 
14867 I
14868 \emph default 
14869 nterrupt
14870 \begin_inset LatexCommand \index{interrupt}
14871
14872 \end_inset 
14873
14874  
14875 \emph on 
14876 S
14877 \emph default 
14878 ervice 
14879 \emph on 
14880 R
14881 \emph default 
14882 outines.
14883  The directive should be placed immediately before the ISR function definition
14884  and it affects ALL ISR functions following it.
14885  To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
14886 exclude\SpecialChar ~
14887 none
14888 \begin_inset LatexCommand \index{\#pragma exclude}
14889
14890 \end_inset 
14891
14892 .
14893  See also the related keyword _naked
14894 \begin_inset LatexCommand \index{\_naked}
14895
14896 \end_inset 
14897
14898
14899 \begin_inset LatexCommand \index{\_\_naked}
14900
14901 \end_inset 
14902
14903 .
14904 \layout Itemize
14905
14906 less_pedantic
14907 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
14908
14909 \end_inset 
14910
14911  - the compiler will not warn you anymore for obvious mistakes, you'r on
14912  your own now ;-(
14913 \layout Itemize
14914
14915 disable_warning <nnnn>
14916 \begin_inset LatexCommand \index{\#pragma disable\_warning}
14917
14918 \end_inset 
14919
14920  - the compiler will not warn you anymore about warning number <nnnn>.
14921 \layout Itemize
14922
14923 nogcse
14924 \begin_inset LatexCommand \index{\#pragma nogcse}
14925
14926 \end_inset 
14927
14928  - will stop global common subexpression elimination.
14929 \layout Itemize
14930
14931 noinduction
14932 \begin_inset LatexCommand \index{\#pragma noinduction}
14933
14934 \end_inset 
14935
14936  - will stop loop induction optimizations.
14937 \layout Itemize
14938
14939 noinvariant
14940 \begin_inset LatexCommand \index{\#pragma noinvariant}
14941
14942 \end_inset 
14943
14944  - will not do loop invariant optimizations.
14945  For more details see Loop Invariants in section
14946 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
14947
14948 \end_inset 
14949
14950 .
14951 \layout Itemize
14952
14953 noiv
14954 \begin_inset LatexCommand \index{\#pragma noiv}
14955
14956 \end_inset 
14957
14958  - Do not generate interrupt
14959 \begin_inset LatexCommand \index{interrupt}
14960
14961 \end_inset 
14962
14963  vector table entries for all ISR functions defined after the pragma.
14964  This is useful in cases where the interrupt vector table must be defined
14965  manually, or when there is a secondary, manually defined interrupt vector
14966  table (e.g.
14967  for the autovector feature of the Cypress EZ-USB FX2).
14968  More elegantly this can be achieved by obmitting the optional interrupt
14969  number after the interrupt keyword, see section 
14970 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
14971
14972 \end_inset 
14973
14974 \SpecialChar ~
14975 about interrupts.
14976 \layout Itemize
14977
14978 nojtbound
14979 \begin_inset LatexCommand \index{\#pragma nojtbound}
14980
14981 \end_inset 
14982
14983  - will not generate code for boundary value checking, when switch statements
14984  are turned into jump-tables (dangerous).
14985  For more details see section 
14986 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
14987
14988 \end_inset 
14989
14990 .
14991 \layout Itemize
14992
14993 noloopreverse
14994 \begin_inset LatexCommand \index{\#pragma noloopreverse}
14995
14996 \end_inset 
14997
14998  - Will not do loop reversal optimization
14999 \layout Itemize
15000
15001 nooverlay
15002 \begin_inset LatexCommand \index{\#pragma nooverlay}
15003
15004 \end_inset 
15005
15006  - the compiler will not overlay the parameters and local variables of a
15007  function.
15008 \layout Itemize
15009
15010 stackauto
15011 \begin_inset LatexCommand \index{\#pragma stackauto}
15012
15013 \end_inset 
15014
15015 - See option -
15016 \begin_inset ERT
15017 status Collapsed
15018
15019 \layout Standard
15020
15021 \backslash 
15022 /
15023 \end_inset 
15024
15025 -stack-auto
15026 \begin_inset LatexCommand \index{-\/-stack-auto}
15027
15028 \end_inset 
15029
15030  and section 
15031 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
15032
15033 \end_inset 
15034
15035  Parameters and Local Variables.
15036 \layout Itemize
15037
15038 opt_code_speed 
15039 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
15040
15041 \end_inset 
15042
15043 - The compiler will optimize code generation towards fast code, possibly
15044  at the expense of code size.
15045 \layout Itemize
15046
15047 opt_code_size 
15048 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
15049
15050 \end_inset 
15051
15052 - The compiler will optimize code generation towards compact code, possibly
15053  at the expense of code speed.
15054 \layout Itemize
15055
15056 opt_code_balanced 
15057 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
15058
15059 \end_inset 
15060
15061 - The compiler will attempt to generate code that is both compact and fast,
15062  as long as meeting one goal is not a detriment to the other (this is the
15063  default).
15064  
15065 \layout Itemize
15066
15067 std_sdcc89 
15068 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
15069
15070 \end_inset 
15071
15072 - Generally follow the C89 standard, but allow SDCC features that conflict
15073  with the standard (default).
15074 \layout Itemize
15075
15076 std_c89 
15077 \begin_inset LatexCommand \index{\#pragma std\_c89}
15078
15079 \end_inset 
15080
15081 - Follow the C89 standard and disable SDCC features that conflict with the
15082  standard.
15083 \layout Itemize
15084
15085 std_sdcc99 
15086 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
15087
15088 \end_inset 
15089
15090 - Generally follow the C99 standard, but allow SDCC features that conflict
15091  with the standard (incomplete support).
15092 \layout Itemize
15093
15094 std_c99 
15095 \begin_inset LatexCommand \index{\#pragma std\_c99}
15096
15097 \end_inset 
15098
15099 - Follow the C99 standard and disable SDCC features that conflict with the
15100  standard (incomplete support).
15101 \layout Standard
15102
15103 SDCPP supports the following #pragma directives:
15104 \layout Itemize
15105
15106 preproc_asm
15107 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
15108
15109 \end_inset 
15110
15111  (+ | -) - switch _asm _endasm block preprocessing on / off.
15112  Default is on.
15113 \layout Standard
15114
15115 The pragma's are intended to be used to turn-on or off certain optimizations
15116  which might cause the compiler to generate extra stack / data space to
15117  store compiler generated temporary variables.
15118  This usually happens in large functions.
15119  Pragma directives should be used as shown in the following example, they
15120  are used to control options & optimizations for a given function; pragmas
15121  should be placed before and/or after a function, placing pragma's inside
15122  a function body could have unpredictable results.
15123 \layout Verse
15124
15125
15126 \family typewriter 
15127 #pragma save
15128 \begin_inset LatexCommand \index{\#pragma save}
15129
15130 \end_inset 
15131
15132  \SpecialChar ~
15133 \SpecialChar ~
15134 \SpecialChar ~
15135 \SpecialChar ~
15136 \SpecialChar ~
15137 \SpecialChar ~
15138 \SpecialChar ~
15139 /* save the current settings */ 
15140 \newline 
15141 #pragma nogcse
15142 \begin_inset LatexCommand \index{\#pragma nogcse}
15143
15144 \end_inset 
15145
15146  \SpecialChar ~
15147 \SpecialChar ~
15148 \SpecialChar ~
15149 \SpecialChar ~
15150 \SpecialChar ~
15151 /* turnoff global subexpression elimination */ 
15152 \newline 
15153 #pragma noinduction
15154 \begin_inset LatexCommand \index{\#pragma noinduction}
15155
15156 \end_inset 
15157
15158  /* turn off induction optimizations */ 
15159 \newline 
15160 int foo () 
15161 \newline 
15162
15163 \newline 
15164 \SpecialChar ~
15165  \SpecialChar ~
15166  ...
15167  
15168 \newline 
15169 \SpecialChar ~
15170  \SpecialChar ~
15171  /* large code */ 
15172 \newline 
15173 \SpecialChar ~
15174  \SpecialChar ~
15175  ...
15176  
15177 \newline 
15178
15179 \newline 
15180 #pragma restore
15181 \begin_inset LatexCommand \index{\#pragma restore}
15182
15183 \end_inset 
15184
15185  /* turn the optimizations back on */
15186 \layout Standard
15187
15188 The compiler will generate a warning message when extra space is allocated.
15189  It is strongly recommended that the save and restore pragma's be used when
15190  changing options for a function.
15191 \layout Section
15192
15193 Defines Created by the Compiler
15194 \layout Standard
15195
15196 The compiler creates the following #defines
15197 \begin_inset LatexCommand \index{\#defines}
15198
15199 \end_inset 
15200
15201
15202 \begin_inset LatexCommand \index{Defines created by the compiler}
15203
15204 \end_inset 
15205
15206 :
15207 \newline 
15208
15209 \layout Standard
15210
15211
15212 \begin_inset  Tabular
15213 <lyxtabular version="3" rows="10" columns="2">
15214 <features>
15215 <column alignment="center" valignment="top" leftline="true" width="0">
15216 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15217 <row topline="true" bottomline="true">
15218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15219 \begin_inset Text
15220
15221 \layout Standard
15222
15223
15224 \series bold 
15225 #define
15226 \end_inset 
15227 </cell>
15228 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15229 \begin_inset Text
15230
15231 \layout Standard
15232
15233
15234 \series bold 
15235 Description
15236 \end_inset 
15237 </cell>
15238 </row>
15239 <row topline="true">
15240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15241 \begin_inset Text
15242
15243 \layout Standard
15244
15245 SDCC
15246 \begin_inset LatexCommand \index{SDCC}
15247
15248 \end_inset 
15249
15250  
15251 \end_inset 
15252 </cell>
15253 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15254 \begin_inset Text
15255
15256 \layout Standard
15257
15258 this Symbol is always defined
15259 \end_inset 
15260 </cell>
15261 </row>
15262 <row topline="true">
15263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15264 \begin_inset Text
15265
15266 \layout Standard
15267
15268 SDCC_mcs51
15269 \begin_inset LatexCommand \index{SDCC\_mcs51}
15270
15271 \end_inset 
15272
15273  or SDCC_ds390
15274 \begin_inset LatexCommand \index{SDCC\_ds390}
15275
15276 \end_inset 
15277
15278  or SDCC_z80
15279 \begin_inset LatexCommand \index{SDCC\_z80}
15280
15281 \end_inset 
15282
15283 , etc
15284 \end_inset 
15285 </cell>
15286 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15287 \begin_inset Text
15288
15289 \layout Standard
15290
15291 depending on the model used (e.g.: -mds390
15292 \end_inset 
15293 </cell>
15294 </row>
15295 <row topline="true">
15296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15297 \begin_inset Text
15298
15299 \layout Standard
15300
15301 __mcs51
15302 \begin_inset LatexCommand \index{\_\_mcs51}
15303
15304 \end_inset 
15305
15306 , __ds390
15307 \begin_inset LatexCommand \index{\_\_ds390}
15308
15309 \end_inset 
15310
15311 , __hc08
15312 \begin_inset LatexCommand \index{\_\_hc08}
15313
15314 \end_inset 
15315
15316 , __z80
15317 \begin_inset LatexCommand \index{\_\_z80}
15318
15319 \end_inset 
15320
15321 , etc
15322 \end_inset 
15323 </cell>
15324 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15325 \begin_inset Text
15326
15327 \layout Standard
15328
15329 depending on the model used (e.g.
15330  -mz80)
15331 \end_inset 
15332 </cell>
15333 </row>
15334 <row topline="true">
15335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15336 \begin_inset Text
15337
15338 \layout Standard
15339
15340 SDCC_STACK_AUTO
15341 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
15342
15343 \end_inset 
15344
15345
15346 \end_inset 
15347 </cell>
15348 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15349 \begin_inset Text
15350
15351 \layout Standard
15352
15353 when 
15354 \emph on 
15355 -
15356 \begin_inset ERT
15357 status Collapsed
15358
15359 \layout Standard
15360
15361 \backslash 
15362 /
15363 \end_inset 
15364
15365 -stack-auto
15366 \emph default 
15367  option is used
15368 \end_inset 
15369 </cell>
15370 </row>
15371 <row topline="true">
15372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15373 \begin_inset Text
15374
15375 \layout Standard
15376
15377 SDCC_MODEL_SMALL
15378 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
15379
15380 \end_inset 
15381
15382
15383 \end_inset 
15384 </cell>
15385 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15386 \begin_inset Text
15387
15388 \layout Standard
15389
15390 when 
15391 \emph on 
15392 -
15393 \begin_inset ERT
15394 status Collapsed
15395
15396 \layout Standard
15397
15398 \backslash 
15399 /
15400 \end_inset 
15401
15402 -model-small
15403 \emph default 
15404  is used
15405 \end_inset 
15406 </cell>
15407 </row>
15408 <row topline="true">
15409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15410 \begin_inset Text
15411
15412 \layout Standard
15413
15414 SDCC_MODEL_LARGE
15415 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
15416
15417 \end_inset 
15418
15419
15420 \end_inset 
15421 </cell>
15422 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15423 \begin_inset Text
15424
15425 \layout Standard
15426
15427 when 
15428 \emph on 
15429 -
15430 \begin_inset ERT
15431 status Collapsed
15432
15433 \layout Standard
15434
15435 \backslash 
15436 /
15437 \end_inset 
15438
15439 -model-large
15440 \emph default 
15441  is used
15442 \end_inset 
15443 </cell>
15444 </row>
15445 <row topline="true">
15446 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15447 \begin_inset Text
15448
15449 \layout Standard
15450
15451 SDCC_USE_XSTACK
15452 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
15453
15454 \end_inset 
15455
15456
15457 \end_inset 
15458 </cell>
15459 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15460 \begin_inset Text
15461
15462 \layout Standard
15463
15464 when 
15465 \emph on 
15466 -
15467 \begin_inset ERT
15468 status Collapsed
15469
15470 \layout Standard
15471
15472 \backslash 
15473 /
15474 \end_inset 
15475
15476 -xstack
15477 \emph default 
15478  option is used
15479 \end_inset 
15480 </cell>
15481 </row>
15482 <row topline="true">
15483 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15484 \begin_inset Text
15485
15486 \layout Standard
15487
15488 SDCC_STACK_TENBIT
15489 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
15490
15491 \end_inset 
15492
15493  
15494 \end_inset 
15495 </cell>
15496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15497 \begin_inset Text
15498
15499 \layout Standard
15500
15501 when 
15502 \emph on 
15503 -mds390
15504 \emph default 
15505  is used
15506 \end_inset 
15507 </cell>
15508 </row>
15509 <row topline="true" bottomline="true">
15510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15511 \begin_inset Text
15512
15513 \layout Standard
15514
15515 SDCC_MODEL_FLAT24
15516 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
15517
15518 \end_inset 
15519
15520
15521 \end_inset 
15522 </cell>
15523 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15524 \begin_inset Text
15525
15526 \layout Standard
15527
15528 when 
15529 \emph on 
15530 -mds390
15531 \emph default 
15532  is used
15533 \end_inset 
15534 </cell>
15535 </row>
15536 </lyxtabular>
15537
15538 \end_inset 
15539
15540
15541 \layout Chapter
15542
15543 Notes on supported Processors
15544 \layout Section
15545
15546 MCS51 variants
15547 \begin_inset LatexCommand \label{sub:MCS51-variants}
15548
15549 \end_inset 
15550
15551
15552 \begin_inset LatexCommand \index{MCS51 variants}
15553
15554 \end_inset 
15555
15556
15557 \layout Standard
15558
15559 MCS51 processors are available from many vendors and come in many different
15560  flavours.
15561  While they might differ considerably in respect to Special Function Registers
15562  the core MCS51 is usually not modified or is kept compatible.
15563  
15564 \layout Subsection
15565
15566 pdata access by SFR 
15567 \layout Standard
15568
15569 With the upcome of devices with internal xdata and flash memory devices
15570  using port P2
15571 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
15572
15573 \end_inset 
15574
15575  as dedicated I/O port is becoming more popular.
15576  Switching the high byte for pdata
15577 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
15578
15579 \end_inset 
15580
15581  access which was formerly done by port P2 is then achieved by a Special
15582  Function Register
15583 \begin_inset LatexCommand \index{sfr}
15584
15585 \end_inset 
15586
15587 .
15588  In well-established MCS51 tradition the address of this 
15589 \emph on 
15590 sfr
15591 \emph default 
15592  is where the chip designers decided to put it.
15593  Needless to say that they didn't agree on a common name either.
15594  So that the startup code can correctly initialize xdata variables, you
15595  should define an sfr with the name _XPAGE
15596 \family typewriter 
15597
15598 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
15599
15600 \end_inset 
15601
15602
15603 \family default 
15604  at the appropriate location if the default, port P2, is not used for this.
15605  Some examples are:
15606 \layout Verse
15607
15608
15609 \family typewriter 
15610 sfr at 0x92 _XPAGE; /* Cypress EZ-USB family */
15611 \layout Verse
15612
15613
15614 \family typewriter 
15615 sfr at 0xaf _XPAGE; /* some Silicon Labs (Cygnal) chips */
15616 \layout Verse
15617
15618
15619 \family typewriter 
15620 sfr at 0xaa _XPAGE; /* some Silicon Labs (Cygnal) chips */
15621 \layout Standard
15622
15623 For more exotic implementations further customizations may be needed.
15624  See section 
15625 \begin_inset LatexCommand \ref{sub:Startup-Code}
15626
15627 \end_inset 
15628
15629  for other possibilities.
15630 \layout Subsection
15631
15632 Other Features available by SFR
15633 \layout Standard
15634
15635 Some MCS51 variants offer features like Double DPTR
15636 \begin_inset LatexCommand \index{DPTR}
15637
15638 \end_inset 
15639
15640 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
15641  These are currently not used for the MCS51 port.
15642  If you absolutely need them you can fall back to inline assembly or submit
15643  a patch to SDCC.
15644 \layout Section
15645
15646 DS400 port
15647 \layout Standard
15648
15649 The DS80C400 microcontroller has a rich set of peripherals.
15650  In its built-in ROM library it includes functions to access some of the
15651  features, among them is a TCP stack with IP4 and IP6 support.
15652  Library headers (currently in beta status) and other files are provided
15653  at 
15654 \size footnotesize 
15655
15656 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
15657
15658 \end_inset 
15659
15660 .
15661  
15662 \layout Section
15663
15664 The Z80 and gbz80 port
15665 \layout Standard
15666
15667 SDCC can target both the Zilog 
15668 \begin_inset LatexCommand \index{Z80}
15669
15670 \end_inset 
15671
15672  and the Nintendo Gameboy's Z80-like gbz80
15673 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
15674
15675 \end_inset 
15676
15677 .
15678  The Z80 port is passed through the same 
15679 \emph on 
15680 regressions tests
15681 \begin_inset LatexCommand \index{Regression test}
15682
15683 \end_inset 
15684
15685
15686 \emph default 
15687  as the MCS51 and DS390 ports, so floating point support, support for long
15688  variables and bitfield support is fine.
15689  See mailing lists and forums about interrupt routines.
15690 \layout Standard
15691
15692 As always, the code is the authoritative reference - see z80/ralloc.c and
15693  z80/gen.c.
15694  The stack
15695 \begin_inset LatexCommand \index{stack}
15696
15697 \end_inset 
15698
15699  frame is similar to that generated by the IAR Z80 compiler.
15700  IX is used as the base pointer, HL and IY are used as a temporary registers,
15701  and BC and DE are available for holding variables.
15702  Return values
15703 \begin_inset LatexCommand \index{return value}
15704
15705 \end_inset 
15706
15707  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
15708  bytes).
15709  The gbz80 port use the same set of registers for the return values, but
15710  in a different order of significance: E (one byte), DE (two bytes), or
15711  HLDE (four bytes).
15712 \layout Section
15713
15714 The HC08 port
15715 \layout Standard
15716
15717 The port to the Motorola HC08
15718 \begin_inset LatexCommand \index{HC08}
15719
15720 \end_inset 
15721
15722  family has been added in October 2003, and is still undergoing some basic
15723  development.
15724  The code generator is complete, but the register allocation is still quite
15725  unoptimized.
15726  Some of the SDCC's standard C library functions have embedded non-HC08
15727  inline assembly and so are not yet usable.
15728 \newline 
15729
15730 \newline 
15731
15732 \layout Section
15733
15734 The PIC14 port
15735 \layout Standard
15736
15737 The 14bit PIC
15738 \begin_inset LatexCommand \index{PIC14}
15739
15740 \end_inset 
15741
15742  port still requires a major effort from the development community.
15743  However it can work for very simple code.
15744 \layout Subsection
15745
15746 C code and 14bit PIC code page
15747 \begin_inset LatexCommand \index{code page (pic14)}
15748
15749 \end_inset 
15750
15751  and RAM banks
15752 \begin_inset LatexCommand \index{RAM bank (pic14)}
15753
15754 \end_inset 
15755
15756
15757 \layout Standard
15758
15759 The linker organizes allocation for the code page and RAM banks.
15760  It does not have intimate knowledge of the code flow.
15761  It will put all the code section of a single asm file into a single code
15762  page.
15763  In order to make use of multiple code pages, separate asm files must be
15764  used.
15765  The compiler treats all functions of a single C file as being in the same
15766  code page unless it is non static.
15767  The compiler treats all local variables of a single C file as being in
15768  the same RAM bank unless it is an extern.
15769 \newline 
15770
15771 \newline 
15772 To get the best follow these guide lines:
15773 \layout Enumerate
15774
15775 make local functions static, as non static functions require code page selection
15776  overhead.
15777 \layout Enumerate
15778
15779 Make local variables static as extern variables require RAM bank selection
15780  overhead.
15781 \layout Enumerate
15782
15783 For devices that have multiple code pages it is more efficient to use the
15784  same number of files as pages, i.e.
15785  for the 16F877 use 4 separate files and i.e.
15786  for the 16F874 use 2 separate files.
15787  This way the linker can put the code for each file into different code
15788  pages and the compiler can allocate reusable variables more efficiently
15789  and there's less page selection overhead.
15790  And as for any 8 bit micro (especially for PIC 14 as they have a very simple
15791  instruction set) use 'unsigned char' whereever possible instead of 'int'.
15792 \layout Subsection
15793
15794 Creating a device include file 
15795 \layout Standard
15796
15797 For generating a device include file use the support perl script inc2h.pl
15798  kept in directory support/script.
15799 \layout Subsection
15800
15801 Interrupt code
15802 \layout Standard
15803
15804 For the interrupt function, use the keyword 'interrupt'
15805 \begin_inset LatexCommand \index{interrupt}
15806
15807 \end_inset 
15808
15809  with level number of 0 (PIC14 only has 1 interrupt so this number is only
15810  there to avoid a syntax error - it ought to be fixed).
15811  E.g.:
15812 \layout Verse
15813
15814
15815 \family typewriter 
15816 void Intr(void) interrupt 0
15817 \newline 
15818 {
15819 \newline 
15820 \SpecialChar ~
15821 \SpecialChar ~
15822 T0IF = 0; /* Clear timer interrupt */
15823 \newline 
15824 }
15825 \layout Subsection
15826
15827 Linking and assembling
15828 \layout Standard
15829
15830 For assembling you can use either GPUTILS'
15831 \begin_inset LatexCommand \index{gputils (pic tools)}
15832
15833 \end_inset 
15834
15835  gpasm.exe or MPLAB's mpasmwin.exe.
15836  GPUTILS is available from 
15837 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
15838
15839 \end_inset 
15840
15841 .
15842  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
15843  If you use MPLAB and an interrupt function then the linker script file
15844  vectors section will need to be enlarged to link with mplink.
15845 \newline 
15846
15847 \newline 
15848 Here is a 
15849 \family typewriter 
15850 Makefile
15851 \family default 
15852  using GPUTILS:
15853 \layout Verse
15854
15855
15856 \family typewriter 
15857 .c.o:
15858 \newline 
15859 \SpecialChar ~
15860 \SpecialChar ~
15861 \SpecialChar ~
15862 \SpecialChar ~
15863 \SpecialChar ~
15864 \SpecialChar ~
15865 \SpecialChar ~
15866 \SpecialChar ~
15867 sdcc -S -V -mpic14 -p16F877 $< 
15868 \newline 
15869 \SpecialChar ~
15870 \SpecialChar ~
15871 \SpecialChar ~
15872 \SpecialChar ~
15873 \SpecialChar ~
15874 \SpecialChar ~
15875 \SpecialChar ~
15876 \SpecialChar ~
15877 gpasm -c $*.asm
15878 \newline 
15879
15880 \newline 
15881 $(PRJ).hex: $(OBJS) 
15882 \newline 
15883 \SpecialChar ~
15884 \SpecialChar ~
15885 \SpecialChar ~
15886 \SpecialChar ~
15887 \SpecialChar ~
15888 \SpecialChar ~
15889 \SpecialChar ~
15890 \SpecialChar ~
15891 gplink -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS)
15892 \layout Standard
15893
15894 Here is a 
15895 \family typewriter 
15896 Makefile
15897 \family default 
15898  using MPLAB:
15899 \layout Verse
15900
15901
15902 \family typewriter 
15903 .c.o: 
15904 \newline 
15905 \SpecialChar ~
15906 \SpecialChar ~
15907 \SpecialChar ~
15908 \SpecialChar ~
15909 \SpecialChar ~
15910 \SpecialChar ~
15911 \SpecialChar ~
15912 \SpecialChar ~
15913 sdcc -S -V -mpic14 -p16F877 $< 
15914 \newline 
15915 \SpecialChar ~
15916 \SpecialChar ~
15917 \SpecialChar ~
15918 \SpecialChar ~
15919 \SpecialChar ~
15920 \SpecialChar ~
15921 \SpecialChar ~
15922 \SpecialChar ~
15923 mpasmwin /q /o $*.asm
15924 \newline 
15925
15926 \newline 
15927 $(PRJ).hex: $(OBJS) 
15928 \newline 
15929 \SpecialChar ~
15930 \SpecialChar ~
15931 \SpecialChar ~
15932 \SpecialChar ~
15933 \SpecialChar ~
15934 \SpecialChar ~
15935 \SpecialChar ~
15936 \SpecialChar ~
15937 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS)
15938 \layout Standard
15939
15940 Please note that indentations within a
15941 \family typewriter 
15942  Makefile
15943 \family default 
15944  have to be done with a tabulator character.
15945 \layout Section
15946
15947 The PIC16
15948 \begin_inset LatexCommand \index{PIC16}
15949
15950 \end_inset 
15951
15952  port
15953 \layout Standard
15954
15955 The PIC16
15956 \begin_inset LatexCommand \index{PIC16}
15957
15958 \end_inset 
15959
15960  port is the portion of SDCC that is responsible to produce code for the
15961  Microchip
15962 \begin_inset LatexCommand \index{Microchip}
15963
15964 \end_inset 
15965
15966 (TM) microcontrollers with 16 bit core.
15967  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
15968  Currently supported devices are:
15969 \layout Standard
15970 \align center 
15971
15972 \begin_inset  Tabular
15973 <lyxtabular version="3" rows="4" columns="6">
15974 <features>
15975 <column alignment="center" valignment="top" leftline="true" width="0">
15976 <column alignment="center" valignment="top" leftline="true" width="0">
15977 <column alignment="center" valignment="top" leftline="true" width="0">
15978 <column alignment="center" valignment="top" leftline="true" width="0">
15979 <column alignment="center" valignment="top" leftline="true" width="0">
15980 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15981 <row topline="true">
15982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15983 \begin_inset Text
15984
15985 \layout Standard
15986
15987 18F242
15988 \end_inset 
15989 </cell>
15990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15991 \begin_inset Text
15992
15993 \layout Standard
15994
15995 18F248
15996 \end_inset 
15997 </cell>
15998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15999 \begin_inset Text
16000
16001 \layout Standard
16002
16003 18F252
16004 \end_inset 
16005 </cell>
16006 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16007 \begin_inset Text
16008
16009 \layout Standard
16010
16011 18F258
16012 \end_inset 
16013 </cell>
16014 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16015 \begin_inset Text
16016
16017 \layout Standard
16018
16019 18F442
16020 \end_inset 
16021 </cell>
16022 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16023 \begin_inset Text
16024
16025 \layout Standard
16026
16027 18F448
16028 \end_inset 
16029 </cell>
16030 </row>
16031 <row topline="true">
16032 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16033 \begin_inset Text
16034
16035 \layout Standard
16036
16037 18F452
16038 \end_inset 
16039 </cell>
16040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16041 \begin_inset Text
16042
16043 \layout Standard
16044
16045 18F458
16046 \end_inset 
16047 </cell>
16048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16049 \begin_inset Text
16050
16051 \layout Standard
16052
16053 18F1220
16054 \end_inset 
16055 </cell>
16056 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16057 \begin_inset Text
16058
16059 \layout Standard
16060
16061 18F2220
16062 \end_inset 
16063 </cell>
16064 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16065 \begin_inset Text
16066
16067 \layout Standard
16068
16069 18F2550
16070 \end_inset 
16071 </cell>
16072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16073 \begin_inset Text
16074
16075 \layout Standard
16076
16077 18F4331
16078 \end_inset 
16079 </cell>
16080 </row>
16081 <row topline="true">
16082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16083 \begin_inset Text
16084
16085 \layout Standard
16086
16087 18F4455
16088 \end_inset 
16089 </cell>
16090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16091 \begin_inset Text
16092
16093 \layout Standard
16094
16095 18F6520
16096 \end_inset 
16097 </cell>
16098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16099 \begin_inset Text
16100
16101 \layout Standard
16102
16103 18F6620
16104 \end_inset 
16105 </cell>
16106 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16107 \begin_inset Text
16108
16109 \layout Standard
16110
16111 18F6680
16112 \end_inset 
16113 </cell>
16114 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16115 \begin_inset Text
16116
16117 \layout Standard
16118
16119 18F6720
16120 \end_inset 
16121 </cell>
16122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16123 \begin_inset Text
16124
16125 \layout Standard
16126
16127 18F8520
16128 \end_inset 
16129 </cell>
16130 </row>
16131 <row topline="true" bottomline="true">
16132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16133 \begin_inset Text
16134
16135 \layout Standard
16136
16137 18F8620
16138 \end_inset 
16139 </cell>
16140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16141 \begin_inset Text
16142
16143 \layout Standard
16144
16145 18F8680
16146 \end_inset 
16147 </cell>
16148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16149 \begin_inset Text
16150
16151 \layout Standard
16152
16153 18F8720
16154 \end_inset 
16155 </cell>
16156 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16157 \begin_inset Text
16158
16159 \layout Standard
16160
16161 \end_inset 
16162 </cell>
16163 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16164 \begin_inset Text
16165
16166 \layout Standard
16167
16168 \end_inset 
16169 </cell>
16170 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16171 \begin_inset Text
16172
16173 \layout Standard
16174
16175 \end_inset 
16176 </cell>
16177 </row>
16178 </lyxtabular>
16179
16180 \end_inset 
16181
16182
16183 \layout Subsection
16184
16185 Global Options
16186 \layout Standard
16187
16188 PIC16 port supports the standard command line arguments as supposed, with
16189  the exception of certain cases that will be mentioned in the following
16190  list:
16191 \layout List
16192 \labelwidthstring 00.00.0000
16193
16194 -
16195 \begin_inset ERT
16196 status Collapsed
16197
16198 \layout Standard
16199
16200 \backslash 
16201 /
16202 \end_inset 
16203
16204 -callee-saves See -
16205 \begin_inset ERT
16206 status Collapsed
16207
16208 \layout Standard
16209
16210 \backslash 
16211 /
16212 \end_inset 
16213
16214 -all-callee-saves
16215 \layout List
16216 \labelwidthstring 00.00.0000
16217
16218 -
16219 \begin_inset ERT
16220 status Collapsed
16221
16222 \layout Standard
16223
16224 \backslash 
16225 /
16226 \end_inset 
16227
16228 -all-callee-saves All function arguments are passed on stack by default.
16229  
16230 \emph on 
16231 There is no need to specify this in the command line.
16232 \layout List
16233 \labelwidthstring 00.00.0000
16234
16235 -
16236 \begin_inset ERT
16237 status Collapsed
16238
16239 \layout Standard
16240
16241 \backslash 
16242 /
16243 \end_inset 
16244
16245 -fommit-frame-pointer Frame pointer will be omitted when the function uses
16246  no local variables.
16247 \layout Subsection
16248
16249 Port Specific Options
16250 \begin_inset LatexCommand \index{Options PIC16}
16251
16252 \end_inset 
16253
16254
16255 \layout Standard
16256
16257 The port specific options appear after the global options in the sdcc --help
16258  output.
16259 \layout Subsubsection
16260
16261 General Options
16262 \layout Standard
16263
16264 General options enable certain port features and optimizations.
16265 \layout List
16266 \labelwidthstring 00.00.0000
16267
16268 -
16269 \begin_inset ERT
16270 status Collapsed
16271
16272 \layout Standard
16273
16274 \backslash 
16275 /
16276 \end_inset 
16277
16278 -stack-model=[model] Used in conjuction with the command above.
16279  Defines the stack model to be used, valid stack models are : 
16280 \begin_deeper 
16281 \layout List
16282 \labelwidthstring 00.00.0000
16283
16284
16285 \emph on 
16286 small
16287 \emph default 
16288  Selects small stack model.
16289  8 bit stack and frame pointers.
16290  Supports 256 bytes stack size.
16291 \layout List
16292 \labelwidthstring 00.00.0000
16293
16294
16295 \emph on 
16296 large
16297 \emph default 
16298  Selects large stack model.
16299  16 bit stack and frame pointers.
16300  Supports 65536 bytes stack size.
16301 \end_deeper 
16302 \layout List
16303 \labelwidthstring 00.00.0000
16304
16305 -
16306 \begin_inset ERT
16307 status Collapsed
16308
16309 \layout Standard
16310
16311 \backslash 
16312 /
16313 \end_inset 
16314
16315 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
16316  unitialized data variables with [kword].
16317  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
16318 \layout List
16319 \labelwidthstring 00.00.0000
16320
16321 -
16322 \begin_inset ERT
16323 status Collapsed
16324
16325 \layout Standard
16326
16327 \backslash 
16328 /
16329 \end_inset 
16330
16331 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
16332  Useful for bootloaders.
16333 \layout List
16334 \labelwidthstring 00.00.0000
16335
16336 -
16337 \begin_inset ERT
16338 status Collapsed
16339
16340 \layout Standard
16341
16342 \backslash 
16343 /
16344 \end_inset 
16345
16346 -asm= sets the full path and name of an external assembler to call.
16347 \layout List
16348 \labelwidthstring 00.00.0000
16349
16350 -
16351 \begin_inset ERT
16352 status Collapsed
16353
16354 \layout Standard
16355
16356 \backslash 
16357 /
16358 \end_inset 
16359
16360 -link= sets the full path and name of an external linker to call.
16361 \layout List
16362 \labelwidthstring 00.00.0000
16363
16364 -
16365 \begin_inset ERT
16366 status Collapsed
16367
16368 \layout Standard
16369
16370 \backslash 
16371 /
16372 \end_inset 
16373
16374 -mplab-comp MPLAB compatibility option.
16375  Currently only suppresses special gpasm directives.
16376 \layout Subsubsection
16377
16378 Optimization Options
16379 \layout List
16380 \labelwidthstring 00.00.0000
16381
16382 -
16383 \begin_inset ERT
16384 status Collapsed
16385
16386 \layout Standard
16387
16388 \backslash 
16389 /
16390 \end_inset 
16391
16392 -optimize-goto Try to use (conditional) BRA instead of GOTO
16393 \layout List
16394 \labelwidthstring 00.00.0000
16395
16396 -
16397 \begin_inset ERT
16398 status Collapsed
16399
16400 \layout Standard
16401
16402 \backslash 
16403 /
16404 \end_inset 
16405
16406 -optimize-cmp Try to optimize some compares.
16407 \layout List
16408 \labelwidthstring 00.00.0000
16409
16410 -
16411 \begin_inset ERT
16412 status Collapsed
16413
16414 \layout Standard
16415
16416 \backslash 
16417 /
16418 \end_inset 
16419
16420 -obanksel=nn Set optimization level for inserting BANKSELs.
16421 \newline 
16422
16423 \begin_deeper 
16424 \layout List
16425 \labelwidthstring 00.00.0000
16426
16427 0 no optimization
16428 \layout List
16429 \labelwidthstring 00.00.0000
16430
16431 1 checks previous used register and if it is the same then does not emit
16432  BANKSEL, accounts only for labels.
16433 \layout List
16434 \labelwidthstring 00.00.0000
16435
16436 2 tries to check the location of (even different) symbols and removes BANKSELs
16437  if they are in the same bank.
16438  
16439 \newline 
16440
16441 \emph on 
16442 Important: There might be problems if the linker script has data sections
16443  across bank borders!
16444 \end_deeper 
16445 \layout Subsubsection
16446
16447 Linking Options
16448 \layout List
16449 \labelwidthstring 00.00.0000
16450
16451 -
16452 \begin_inset ERT
16453 status Collapsed
16454
16455 \layout Standard
16456
16457 \backslash 
16458 /
16459 \end_inset 
16460
16461 -nodefaultlibs do not link default libraries when linking
16462 \layout List
16463 \labelwidthstring 00.00.0000
16464
16465 -
16466 \begin_inset ERT
16467 status Collapsed
16468
16469 \layout Standard
16470
16471 \backslash 
16472 /
16473 \end_inset 
16474
16475 -no-crt Don't link the default run-time modules
16476 \layout List
16477 \labelwidthstring 00.00.0000
16478
16479 -
16480 \begin_inset ERT
16481 status Collapsed
16482
16483 \layout Standard
16484
16485 \backslash 
16486 /
16487 \end_inset 
16488
16489 -use-crt= Use a custom run-time module instead of the defaults.
16490 \layout Subsubsection
16491
16492 Debugging Options
16493 \layout Standard
16494
16495 Debugging options enable extra debugging information in the output files.
16496 \layout List
16497 \labelwidthstring 00.00.0000
16498
16499 -
16500 \begin_inset ERT
16501 status Collapsed
16502
16503 \layout Standard
16504
16505 \backslash 
16506 /
16507 \end_inset 
16508
16509 -debug-xtra Similar to -
16510 \begin_inset ERT
16511 status Collapsed
16512
16513 \layout Standard
16514
16515 \backslash 
16516 /
16517 \end_inset 
16518
16519 -debug
16520 \begin_inset LatexCommand \index{-\/-debug}
16521
16522 \end_inset 
16523
16524 , but dumps more information.
16525 \layout List
16526 \labelwidthstring 00.00.0000
16527
16528 -
16529 \begin_inset ERT
16530 status Collapsed
16531
16532 \layout Standard
16533
16534 \backslash 
16535 /
16536 \end_inset 
16537
16538 -debug-ralloc Force register allocator to dump <source>.d file with debugging
16539  information.
16540  <source> is the name of the file compiled.
16541 \layout List
16542 \labelwidthstring 00.00.0000
16543
16544 -
16545 \begin_inset ERT
16546 status Collapsed
16547
16548 \layout Standard
16549
16550 \backslash 
16551 /
16552 \end_inset 
16553
16554 -pcode-verbose Enable pcode debugging information in translation.
16555 \layout List
16556 \labelwidthstring 00.00.0000
16557
16558 -
16559 \begin_inset ERT
16560 status Collapsed
16561
16562 \layout Standard
16563
16564 \backslash 
16565 /
16566 \end_inset 
16567
16568 -denable-peeps Force the usage of peepholes.
16569  Use with care.
16570 \layout List
16571 \labelwidthstring 00.00.0000
16572
16573 -
16574 \begin_inset ERT
16575 status Collapsed
16576
16577 \layout Standard
16578
16579 \backslash 
16580 /
16581 \end_inset 
16582
16583 -gstack Trace push/pops for stack pointer overflow
16584 \layout List
16585 \labelwidthstring 00.00.0000
16586
16587 -
16588 \begin_inset ERT
16589 status Collapsed
16590
16591 \layout Standard
16592
16593 \backslash 
16594 /
16595 \end_inset 
16596
16597 -call-tree dump call tree in .calltree file
16598 \layout Subsection
16599
16600 Enviromental Variables
16601 \layout Standard
16602
16603 There is a number of enviromental variables that can be used when running
16604  SDCC to enable certain optimizations or force a specific program behaviour.
16605  these variables are primarily for debugging purposes so they can be enabled/dis
16606 abled at will.
16607 \layout Standard
16608
16609 Currently there is only two such variables available:
16610 \layout List
16611 \labelwidthstring 00.00.0000
16612
16613 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
16614  bitfields is optimized by directly loading FSR0 with the address of the
16615  bitfield structure.
16616  Normally SDCC will cast the bitfield structure to a bitfield pointer and
16617  then load FSR0.
16618  This step saves data ram and code space for functions that perform heavy
16619  use of bitfields.
16620  (ie.
16621  80 bytes of code space are saved when compiling malloc.c with this option).
16622  
16623 \layout List
16624 \labelwidthstring 00.00.0000
16625
16626 NO_REG_OPT do not perform pCode registers optimization.
16627  This should be used for debugging purposes.
16628  In some where bugs in the pcode optimizer are found, users can benefit
16629  from temporarily disabling the optimizer until the bug is fixed.
16630 \layout Subsection
16631
16632 Preprocessor Macros
16633 \layout Standard
16634
16635 PIC16 port defines the following preprocessor macros while translating a
16636  source.
16637 \layout Standard
16638 \align center 
16639
16640 \begin_inset  Tabular
16641 <lyxtabular version="3" rows="6" columns="2">
16642 <features>
16643 <column alignment="center" valignment="top" leftline="true" width="0">
16644 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
16645 <row topline="true" bottomline="true">
16646 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16647 \begin_inset Text
16648
16649 \layout Standard
16650
16651 Macro
16652 \end_inset 
16653 </cell>
16654 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16655 \begin_inset Text
16656
16657 \layout Standard
16658
16659 Description
16660 \end_inset 
16661 </cell>
16662 </row>
16663 <row topline="true">
16664 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16665 \begin_inset Text
16666
16667 \layout Standard
16668
16669 SDCC_pic16
16670 \end_inset 
16671 </cell>
16672 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16673 \begin_inset Text
16674
16675 \layout Standard
16676
16677 Port identification
16678 \end_inset 
16679 </cell>
16680 </row>
16681 <row topline="true">
16682 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16683 \begin_inset Text
16684
16685 \layout Standard
16686
16687 _
16688 \begin_inset ERT
16689 status Collapsed
16690
16691 \layout Standard
16692
16693 \backslash 
16694 /
16695 \end_inset 
16696
16697 _pic16
16698 \end_inset 
16699 </cell>
16700 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16701 \begin_inset Text
16702
16703 \layout Standard
16704
16705 Port identification (same as above)
16706 \end_inset 
16707 </cell>
16708 </row>
16709 <row topline="true">
16710 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16711 \begin_inset Text
16712
16713 \layout Standard
16714
16715 pic18fxxxx
16716 \end_inset 
16717 </cell>
16718 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16719 \begin_inset Text
16720
16721 \layout Standard
16722
16723 MCU Identification.
16724  
16725 \emph on 
16726 xxxx
16727 \emph default 
16728  is the microcontrol identification number, i.e.
16729  452, 6620, etc
16730 \end_inset 
16731 </cell>
16732 </row>
16733 <row topline="true">
16734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16735 \begin_inset Text
16736
16737 \layout Standard
16738
16739 _
16740 \begin_inset ERT
16741 status Collapsed
16742
16743 \layout Standard
16744
16745 \backslash 
16746 /
16747 \end_inset 
16748
16749 _18Fxxxx
16750 \end_inset 
16751 </cell>
16752 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16753 \begin_inset Text
16754
16755 \layout Standard
16756
16757 MCU Identification (same as above)
16758 \end_inset 
16759 </cell>
16760 </row>
16761 <row topline="true" bottomline="true">
16762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16763 \begin_inset Text
16764
16765 \layout Standard
16766
16767 STACK_MODEL_nnn
16768 \end_inset 
16769 </cell>
16770 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16771 \begin_inset Text
16772
16773 \layout Standard
16774
16775 nnn = SMALL or LARGE respectively according to the stack model used
16776 \end_inset 
16777 </cell>
16778 </row>
16779 </lyxtabular>
16780
16781 \end_inset 
16782
16783
16784 \layout Standard
16785
16786 In addition the following macros are defined when calling assembler:
16787 \layout Standard
16788 \align center 
16789
16790 \begin_inset  Tabular
16791 <lyxtabular version="3" rows="4" columns="2">
16792 <features>
16793 <column alignment="center" valignment="top" leftline="true" width="0">
16794 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
16795 <row topline="true" bottomline="true">
16796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16797 \begin_inset Text
16798
16799 \layout Standard
16800
16801 Macro
16802 \end_inset 
16803 </cell>
16804 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16805 \begin_inset Text
16806
16807 \layout Standard
16808
16809 Description
16810 \end_inset 
16811 </cell>
16812 </row>
16813 <row topline="true">
16814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16815 \begin_inset Text
16816
16817 \layout Standard
16818
16819 __18Fxxxx
16820 \end_inset 
16821 </cell>
16822 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16823 \begin_inset Text
16824
16825 \layout Standard
16826
16827 MCU Identification.
16828  
16829 \emph on 
16830 xxxx
16831 \emph default 
16832  is the microcontrol identification number, i.e.
16833  452, 6620, etc
16834 \end_inset 
16835 </cell>
16836 </row>
16837 <row topline="true">
16838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16839 \begin_inset Text
16840
16841 \layout Standard
16842
16843 SDCC_MODEL_nnn
16844 \end_inset 
16845 </cell>
16846 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16847 \begin_inset Text
16848
16849 \layout Standard
16850
16851 nnn = SMALL or LARGE respectively according to the memory model used for
16852  SDCC
16853 \end_inset 
16854 </cell>
16855 </row>
16856 <row topline="true" bottomline="true">
16857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16858 \begin_inset Text
16859
16860 \layout Standard
16861
16862 STACK_MODEL_nnn
16863 \end_inset 
16864 </cell>
16865 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16866 \begin_inset Text
16867
16868 \layout Standard
16869
16870 nnn = SMALL or LARGE respectively according to the stack model used
16871 \end_inset 
16872 </cell>
16873 </row>
16874 </lyxtabular>
16875
16876 \end_inset 
16877
16878
16879 \layout Subsection
16880
16881 Directories
16882 \layout Standard
16883
16884 PIC16
16885 \begin_inset LatexCommand \index{PIC16}
16886
16887 \end_inset 
16888
16889  port uses the following directories for searching header files and libraries.
16890 \layout Standard
16891 \align center 
16892
16893 \begin_inset  Tabular
16894 <lyxtabular version="3" rows="3" columns="4">
16895 <features>
16896 <column alignment="center" valignment="top" leftline="true" width="0">
16897 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
16898 <column alignment="center" valignment="top" width="0">
16899 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
16900 <row topline="true" bottomline="true">
16901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16902 \begin_inset Text
16903
16904 \layout Standard
16905
16906 Directory
16907 \end_inset 
16908 </cell>
16909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16910 \begin_inset Text
16911
16912 \layout Standard
16913
16914 Description
16915 \end_inset 
16916 </cell>
16917 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16918 \begin_inset Text
16919
16920 \layout Standard
16921
16922 Target
16923 \end_inset 
16924 </cell>
16925 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16926 \begin_inset Text
16927
16928 \layout Standard
16929
16930 Command prefix
16931 \end_inset 
16932 </cell>
16933 </row>
16934 <row topline="true">
16935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16936 \begin_inset Text
16937
16938 \layout Standard
16939
16940 PREFIX/sdcc/include/pic16
16941 \end_inset 
16942 </cell>
16943 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16944 \begin_inset Text
16945
16946 \layout Standard
16947
16948 PIC16 specific headers
16949 \end_inset 
16950 </cell>
16951 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16952 \begin_inset Text
16953
16954 \layout Standard
16955
16956 Compiler
16957 \end_inset 
16958 </cell>
16959 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16960 \begin_inset Text
16961
16962 \layout Standard
16963
16964 -I
16965 \end_inset 
16966 </cell>
16967 </row>
16968 <row topline="true" bottomline="true">
16969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16970 \begin_inset Text
16971
16972 \layout Standard
16973
16974 PREFIX/sdcc/lib/pic16
16975 \end_inset 
16976 </cell>
16977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16978 \begin_inset Text
16979
16980 \layout Standard
16981
16982 PIC16 specific libraries
16983 \end_inset 
16984 </cell>
16985 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16986 \begin_inset Text
16987
16988 \layout Standard
16989
16990 Linker
16991 \end_inset 
16992 </cell>
16993 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16994 \begin_inset Text
16995
16996 \layout Standard
16997
16998 -L
16999 \end_inset 
17000 </cell>
17001 </row>
17002 </lyxtabular>
17003
17004 \end_inset 
17005
17006
17007 \layout Subsection
17008
17009 Pragmas
17010 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
17011
17012 \end_inset 
17013
17014
17015 \layout Standard
17016
17017 PIC16 port currently supports the following pragmas:
17018 \layout List
17019 \labelwidthstring 00.00.0000
17020
17021 stack pragma stack forces the code generator to initialize the stack & frame
17022  pointers at a specific address.
17023  This is an adhoc solution for cases where no STACK directive is available
17024  in the linker script or gplink is not instructed to create a stack section.
17025 \newline 
17026 The stack pragma should be used only once in a project.
17027  Multiple pragmas may result in indeterminate behaviour of the program.
17028 \begin_inset Foot
17029 collapsed false
17030
17031 \layout Standard
17032
17033 The old format (ie.
17034  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
17035  cross page boundaries (or even exceed the available data RAM) and crash
17036  the program.
17037  Make sure that stack does not cross page boundaries when using the SMALL
17038  stack model.
17039 \end_inset 
17040
17041
17042 \newline 
17043 The format is as follows:
17044 \layout LyX-Code
17045
17046 #pragma stack bottom_address [stack_size]
17047 \layout Standard
17048
17049
17050 \emph on 
17051 bottom_address
17052 \emph default 
17053  is the lower bound of the stack section.
17054  The stack pointer initially will point at address (bottom_address+stack_size-1).
17055 \layout LyX-Code
17056
17057 Example:
17058 \layout LyX-Code
17059
17060 \layout LyX-Code
17061
17062 /* initializes stack of 100 bytes at RAM address 0x200 */
17063 \layout LyX-Code
17064
17065 #pragma stack 0x200 100
17066 \layout Standard
17067
17068 If the stack_size field is omitted then a stack is created with the default
17069  size of 64.
17070  This size might be enough for most programs, but its not enough for operations
17071  with deep function nesting or excessive stack usage.
17072 \layout List
17073 \labelwidthstring 00.00.0000
17074
17075 wparam 
17076 \emph on 
17077 This pragma is deprecated.
17078  Its use will cause a warning message to be issued.
17079 \emph default 
17080
17081 \newline 
17082
17083 \layout List
17084 \labelwidthstring 00.00.0000
17085
17086 code place a function symbol at static FLASH address
17087 \layout LyX-Code
17088
17089 Example:
17090 \layout LyX-Code
17091
17092 \layout LyX-Code
17093
17094 /* place function test_func at 0x4000 */
17095 \layout LyX-Code
17096
17097 #pragma code test_func 0x4000
17098 \layout LyX-Code
17099
17100 \layout List
17101 \labelwidthstring 00.00.0000
17102
17103 library instructs the linker to use a library module.
17104 \newline 
17105 Usage:
17106 \layout LyX-Code
17107
17108 #pragma library module_name
17109 \layout Standard
17110
17111
17112 \emph on 
17113 module_name
17114 \emph default 
17115  can be any library or object file (including its path).
17116  Note that there are four reserved keywords which have special meaning.
17117  These are:
17118 \layout Standard
17119 \align center 
17120
17121 \begin_inset  Tabular
17122 <lyxtabular version="3" rows="6" columns="3">
17123 <features>
17124 <column alignment="center" valignment="top" leftline="true" width="0">
17125 <column alignment="block" valignment="top" leftline="true" width="20page%">
17126 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
17127 <row topline="true" bottomline="true">
17128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17129 \begin_inset Text
17130
17131 \layout Standard
17132
17133 Keyword
17134 \end_inset 
17135 </cell>
17136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17137 \begin_inset Text
17138
17139 \layout Standard
17140
17141 Description
17142 \end_inset 
17143 </cell>
17144 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17145 \begin_inset Text
17146
17147 \layout Standard
17148
17149 Module to link
17150 \end_inset 
17151 </cell>
17152 </row>
17153 <row topline="true">
17154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17155 \begin_inset Text
17156
17157 \layout Standard
17158
17159
17160 \series bold 
17161 ignore
17162 \end_inset 
17163 </cell>
17164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17165 \begin_inset Text
17166
17167 \layout Standard
17168
17169 ignore all library pragmas
17170 \end_inset 
17171 </cell>
17172 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17173 \begin_inset Text
17174
17175 \layout Standard
17176
17177
17178 \emph on 
17179 (none)
17180 \end_inset 
17181 </cell>
17182 </row>
17183 <row topline="true">
17184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17185 \begin_inset Text
17186
17187 \layout Standard
17188
17189
17190 \series bold 
17191 c
17192 \end_inset 
17193 </cell>
17194 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17195 \begin_inset Text
17196
17197 \layout Standard
17198
17199 link the C library
17200 \end_inset 
17201 </cell>
17202 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17203 \begin_inset Text
17204
17205 \layout Standard
17206
17207
17208 \emph on 
17209 libc18f
17210 \emph default 
17211 .lib
17212 \end_inset 
17213 </cell>
17214 </row>
17215 <row topline="true">
17216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17217 \begin_inset Text
17218
17219 \layout Standard
17220
17221
17222 \series bold 
17223 math
17224 \end_inset 
17225 </cell>
17226 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17227 \begin_inset Text
17228
17229 \layout Standard
17230
17231 link the Math libarary
17232 \end_inset 
17233 </cell>
17234 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17235 \begin_inset Text
17236
17237 \layout Standard
17238
17239
17240 \emph on 
17241 libm18f
17242 \emph default 
17243 .lib
17244 \end_inset 
17245 </cell>
17246 </row>
17247 <row topline="true">
17248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17249 \begin_inset Text
17250
17251 \layout Standard
17252
17253
17254 \series bold 
17255 io
17256 \end_inset 
17257 </cell>
17258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17259 \begin_inset Text
17260
17261 \layout Standard
17262
17263 link the I/O library
17264 \end_inset 
17265 </cell>
17266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17267 \begin_inset Text
17268
17269 \layout Standard
17270
17271
17272 \emph on 
17273 libio18f*
17274 \emph default 
17275 .lib
17276 \end_inset 
17277 </cell>
17278 </row>
17279 <row topline="true" bottomline="true">
17280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17281 \begin_inset Text
17282
17283 \layout Standard
17284
17285
17286 \series bold 
17287 debug
17288 \end_inset 
17289 </cell>
17290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17291 \begin_inset Text
17292
17293 \layout Standard
17294
17295 link the debug library
17296 \end_inset 
17297 </cell>
17298 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17299 \begin_inset Text
17300
17301 \layout Standard
17302
17303
17304 \emph on 
17305 libdebug
17306 \emph default 
17307 .lib
17308 \end_inset 
17309 </cell>
17310 </row>
17311 </lyxtabular>
17312
17313 \end_inset 
17314
17315
17316 \newline 
17317 * is the device number, i.e.
17318  452 for PIC18F452 MCU.
17319 \layout Standard
17320
17321 This feature allows for linking with specific libraries withoug having to
17322  explicit name them in the command line.
17323  Note that the 
17324 \noun on 
17325 ignore
17326 \noun default 
17327  keyword will reject all modules specified by the library pragma.
17328 \layout List
17329 \labelwidthstring 00.00.0000
17330
17331 udata pragma udata instructs the compiler to emit code so that linker will
17332  place a variable at a specific memory bank
17333 \layout LyX-Code
17334
17335 Example:
17336 \layout LyX-Code
17337
17338 \layout LyX-Code
17339
17340 /* places variable foo at bank2 */
17341 \layout LyX-Code
17342
17343 #pragma udata bank2 foo
17344 \layout LyX-Code
17345
17346 char foo;
17347 \layout Standard
17348
17349 In order for this pragma to work extra SECTION directives should be added
17350  in the .lkr script.
17351  In the following example a sample .lkr file is shown:
17352 \layout LyX-Code
17353
17354 \layout LyX-Code
17355
17356 // Sample linker script for the PIC18F452 processor
17357 \layout LyX-Code
17358
17359 LIBPATH .
17360 \layout LyX-Code
17361
17362 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
17363 \layout LyX-Code
17364
17365 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
17366 \layout LyX-Code
17367
17368 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
17369 \layout LyX-Code
17370
17371 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
17372 \layout LyX-Code
17373
17374 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
17375 \layout LyX-Code
17376
17377 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
17378 \layout LyX-Code
17379
17380 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
17381 \layout LyX-Code
17382
17383 \layout LyX-Code
17384
17385 DATABANK   NAME=gpr0       START=0x80           END=0xFF
17386 \layout LyX-Code
17387
17388 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
17389 \layout LyX-Code
17390
17391 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
17392 \layout LyX-Code
17393
17394 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
17395 \layout LyX-Code
17396
17397 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
17398 \layout LyX-Code
17399
17400 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
17401 \layout LyX-Code
17402
17403 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
17404 \layout LyX-Code
17405
17406 \layout LyX-Code
17407
17408 SECTION    NAME=CONFIG     ROM=config
17409 \layout LyX-Code
17410
17411 \layout LyX-Code
17412
17413 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
17414 \layout LyX-Code
17415
17416 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
17417 \layout LyX-Code
17418
17419 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
17420 \layout LyX-Code
17421
17422 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
17423 \layout LyX-Code
17424
17425 SECTION    NAME=bank4      RAM=gpr4
17426 \layout LyX-Code
17427
17428 SECTION    NAME=bank5      RAM=gpr5
17429 \layout Standard
17430
17431 The linker will recognise the section name set in the pragma statement and
17432  will position the variable at the memory bank set with the RAM field at
17433  the SECTION line in the linker script file.
17434 \layout Subsection
17435
17436 Header Files
17437 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
17438
17439 \end_inset 
17440
17441
17442 \layout Standard
17443
17444 There is one main header file that can be included to the source files using
17445  the pic16 port.
17446  That file is the 
17447 \series bold 
17448 pic18fregs.h
17449 \series default 
17450 .
17451  This header file contains the definitions for the processor special registers,
17452  so it is necessary if the source accesses them.
17453  It can be included by adding the following line in the beginning of the
17454  file:
17455 \layout LyX-Code
17456
17457 #include <pic18fregs.h>
17458 \layout Standard
17459
17460 The specific microcontroller is selected within the pic18fregs.h automatically,
17461  so the same source can be used with a variety of devices.
17462 \layout Subsection
17463
17464 Libraries
17465 \layout Standard
17466
17467 The libraries that PIC16
17468 \begin_inset LatexCommand \index{PIC16}
17469
17470 \end_inset 
17471
17472  port depends on are the microcontroller device libraries which contain
17473  the symbol definitions for the microcontroller special function registers.
17474  These libraries have the format pic18fxxxx.lib, where 
17475 \emph on 
17476 xxxx
17477 \emph default 
17478  is the microcontroller identification number.
17479  The specific library is selected automatically by the compiler at link
17480  stage according to the selected device.
17481 \layout Standard
17482
17483 Libraries are created with gplib which is part of the gputils package 
17484 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
17485
17486 \end_inset 
17487
17488 .
17489 \layout Subsubsection*
17490
17491 Building the libraries
17492 \layout Standard
17493
17494 Before using SDCC/pic16 there are some libraries that need to be compiled.
17495  This process is not done automatically by SDCC since not all users use
17496  SDCC for pic16 projects.
17497  So each user should compile the libraries separately.
17498 \layout Standard
17499
17500 The steps to compile the pic16 libraries under Linux are:
17501 \layout LyX-Code
17502
17503 cd device/lib/pic16
17504 \layout LyX-Code
17505
17506 ./configure
17507 \layout LyX-Code
17508
17509 make
17510 \layout LyX-Code
17511
17512 cd ..
17513 \layout LyX-Code
17514
17515 make model-pic16
17516 \layout LyX-Code
17517
17518 su -c 'make install'     # install the libraries, you need the root password
17519 \layout Standard
17520
17521 If you need to install the headers too, do:
17522 \layout LyX-Code
17523
17524 cd device/include
17525 \layout LyX-Code
17526
17527 su -c 'make install'     # install the headers, you need the root password
17528 \layout Standard
17529
17530 There exist a special target to build the I/O libraries.
17531  This target is not automatically build because it will build the I/O library
17532  for 
17533 \emph on 
17534 every
17535 \emph default 
17536  supported device.
17537  This way building will take quite a lot of time.
17538  Users are advised to edit the 
17539 \series bold 
17540 device/lib/pic16/pics.build
17541 \series default 
17542  file and then execute:
17543 \layout LyX-Code
17544
17545 make lib-io
17546 \layout Subsection
17547
17548 Memory Models
17549 \layout Standard
17550
17551 The following memory models are supported by the PIC16 port:
17552 \layout Itemize
17553
17554 small model
17555 \layout Itemize
17556
17557 large model
17558 \layout Standard
17559
17560 Memory model affects the default size of pointers within the source.
17561  The sizes are shown in the next table:
17562 \layout Standard
17563 \align center 
17564
17565 \begin_inset  Tabular
17566 <lyxtabular version="3" rows="3" columns="3">
17567 <features>
17568 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
17569 <column alignment="center" valignment="top" leftline="true" width="0">
17570 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
17571 <row topline="true" bottomline="true">
17572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17573 \begin_inset Text
17574
17575 \layout Standard
17576
17577 Pointer sizes according to memory model
17578 \end_inset 
17579 </cell>
17580 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17581 \begin_inset Text
17582
17583 \layout Standard
17584
17585 small model
17586 \end_inset 
17587 </cell>
17588 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17589 \begin_inset Text
17590
17591 \layout Standard
17592
17593 large model
17594 \end_inset 
17595 </cell>
17596 </row>
17597 <row topline="true" bottomline="true">
17598 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17599 \begin_inset Text
17600
17601 \layout Standard
17602
17603 code pointers
17604 \end_inset 
17605 </cell>
17606 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17607 \begin_inset Text
17608
17609 \layout Standard
17610
17611 16-bits
17612 \end_inset 
17613 </cell>
17614 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17615 \begin_inset Text
17616
17617 \layout Standard
17618
17619 24-bits
17620 \end_inset 
17621 </cell>
17622 </row>
17623 <row topline="true" bottomline="true">
17624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17625 \begin_inset Text
17626
17627 \layout Standard
17628
17629 data pointers
17630 \end_inset 
17631 </cell>
17632 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
17633 \begin_inset Text
17634
17635 \layout Standard
17636
17637 16-bits
17638 \end_inset 
17639 </cell>
17640 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17641 \begin_inset Text
17642
17643 \layout Standard
17644
17645 16-bits
17646 \end_inset 
17647 </cell>
17648 </row>
17649 </lyxtabular>
17650
17651 \end_inset 
17652
17653
17654 \layout Standard
17655
17656 It is advisable that all sources within a project are compiled with the
17657  same memory model.
17658  If one wants to override the default memory model, this can be done by
17659  declaring a pointer as 
17660 \series bold 
17661 far
17662 \series default 
17663  or 
17664 \series bold 
17665 near
17666 \series default 
17667 .
17668  Far selects large memory model's pointers, while near selects small memory
17669  model's pointers.
17670 \layout Standard
17671
17672 The standard device libraries (see 
17673 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
17674
17675 \end_inset 
17676
17677 ) contain no reference to pointers, so they can be used with both memory
17678  models.
17679 \layout Subsection
17680
17681 Stack
17682 \layout Standard
17683
17684 The stack implementation for the PIC16 port uses two indirect registers,
17685  FSR1 and FSR2.
17686 \layout List
17687 \labelwidthstring 00.00.0000
17688
17689 FSR1 is assigned as stack pointer
17690 \layout List
17691 \labelwidthstring 00.00.0000
17692
17693 FSR2 is assigned as frame pointer
17694 \layout Standard
17695
17696 The following stack models are supported by the PIC16 port
17697 \layout Itemize
17698
17699
17700 \noun on 
17701 small
17702 \noun default 
17703  model
17704 \layout Itemize
17705
17706
17707 \noun on 
17708 large
17709 \noun default 
17710  model
17711 \layout Standard
17712
17713
17714 \noun on 
17715 Small
17716 \noun default 
17717  model means that only the FSRxL byte is used to access stack and frame,
17718  while 
17719 \emph on 
17720 \noun on 
17721 large
17722 \emph default 
17723 \noun default 
17724  uses both FSRxL and FSRxH registers.
17725  The following table shows the stack/frame pointers sizes according to stack
17726  model and the maximum space they can address:
17727 \layout Standard
17728 \align center 
17729
17730 \begin_inset  Tabular
17731 <lyxtabular version="3" rows="3" columns="3">
17732 <features>
17733 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
17734 <column alignment="center" valignment="top" leftline="true" width="0">
17735 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
17736 <row topline="true" bottomline="true">
17737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17738 \begin_inset Text
17739
17740 \layout Standard
17741
17742 Stack & Frame pointer sizes according to stack model
17743 \end_inset 
17744 </cell>
17745 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17746 \begin_inset Text
17747
17748 \layout Standard
17749
17750 small
17751 \end_inset 
17752 </cell>
17753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17754 \begin_inset Text
17755
17756 \layout Standard
17757
17758 large
17759 \end_inset 
17760 </cell>
17761 </row>
17762 <row topline="true">
17763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17764 \begin_inset Text
17765
17766 \layout Standard
17767
17768 Stack pointer FSR1
17769 \end_inset 
17770 </cell>
17771 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17772 \begin_inset Text
17773
17774 \layout Standard
17775
17776 8-bits
17777 \end_inset 
17778 </cell>
17779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17780 \begin_inset Text
17781
17782 \layout Standard
17783
17784 16-bits
17785 \end_inset 
17786 </cell>
17787 </row>
17788 <row topline="true" bottomline="true">
17789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17790 \begin_inset Text
17791
17792 \layout Standard
17793
17794 Frame pointer FSR2
17795 \end_inset 
17796 </cell>
17797 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17798 \begin_inset Text
17799
17800 \layout Standard
17801
17802 8-bits
17803 \end_inset 
17804 </cell>
17805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17806 \begin_inset Text
17807
17808 \layout Standard
17809
17810 16-bits
17811 \end_inset 
17812 </cell>
17813 </row>
17814 </lyxtabular>
17815
17816 \end_inset 
17817
17818
17819 \layout Standard
17820
17821
17822 \noun on 
17823 Large 
17824 \noun default 
17825 stack model is currently not working properly throughout the code generator.
17826  So its use is not advised.
17827  Also there are some other points that need special care:
17828 \newline 
17829
17830 \layout Enumerate
17831
17832 Do not create stack sections with size more than one physical bank (that
17833  is 256 bytes)
17834 \layout Enumerate
17835
17836 Stack sections should no cross physical bank limits (i.e.
17837  #pragma stack 0x50 0x100)
17838 \layout Standard
17839
17840 These limitations are caused by the fact that only FSRxL is modified when
17841  using SMALL stack model, so no more than 256 bytes of stack can be used.
17842  This problem will disappear after LARGE model is fully implemented.
17843 \layout Subsection
17844
17845 Functions
17846 \layout Standard
17847
17848 In addition to the standard SDCC function keywords, PIC16 port makes available
17849  two more:
17850 \layout List
17851 \labelwidthstring 00.00.0000
17852
17853 wparam Use the WREG to pass one byte of the first function argument.
17854  This improves speed but you may not use this for functions with arguments
17855  that are called via function pointers, otherwise the first byte of the
17856  first parameter will get lost.
17857  Usage:
17858 \layout LyX-Code
17859
17860 void func_wparam(int a) wparam
17861 \layout LyX-Code
17862
17863 {
17864 \layout LyX-Code
17865
17866     /* WREG hold the lower part of a */
17867 \layout LyX-Code
17868
17869     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
17870  */
17871 \layout LyX-Code
17872
17873 ...
17874 \layout LyX-Code
17875
17876 }
17877 \layout Standard
17878
17879 This keyword replaces the deprecated wparam pragma.
17880 \layout List
17881 \labelwidthstring 00.00.0000
17882
17883 shadowregs When entering/exiting an ISR, it is possible to take advantage
17884  of the PIC18F hardware shadow registers which hold the values of WREG,
17885  STATUS and BSR registers.
17886  This can be done by adding the keyword 
17887 \emph on 
17888 shadowregs
17889 \emph default 
17890  before the 
17891 \emph on 
17892 interrupt
17893 \emph default 
17894  keyword in the function's header.
17895 \layout LyX-Code
17896
17897 void isr_shadow(void) shadowregs interrupt 1
17898 \layout LyX-Code
17899
17900 {
17901 \layout LyX-Code
17902
17903 ...
17904 \layout LyX-Code
17905
17906 }
17907 \layout Standard
17908
17909
17910 \emph on 
17911 shadowregs
17912 \emph default 
17913  instructs the code generator not to store/restore WREG, STATUS, BSR when
17914  entering/exiting the ISR.
17915 \layout Subsection
17916
17917 Function return values
17918 \layout Standard
17919
17920 Return values from functions are placed to the appropriate registers following
17921  a modified Microchip policy optimized for SDCC.
17922  The following table shows these registers:
17923 \layout Standard
17924 \align center 
17925
17926 \begin_inset  Tabular
17927 <lyxtabular version="3" rows="6" columns="2">
17928 <features>
17929 <column alignment="center" valignment="top" leftline="true" width="0">
17930 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
17931 <row topline="true" bottomline="true">
17932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17933 \begin_inset Text
17934
17935 \layout Standard
17936
17937 size
17938 \end_inset 
17939 </cell>
17940 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17941 \begin_inset Text
17942
17943 \layout Standard
17944
17945 destination register
17946 \end_inset 
17947 </cell>
17948 </row>
17949 <row topline="true">
17950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17951 \begin_inset Text
17952
17953 \layout Standard
17954
17955 8 bits
17956 \end_inset 
17957 </cell>
17958 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17959 \begin_inset Text
17960
17961 \layout Standard
17962
17963 WREG
17964 \end_inset 
17965 </cell>
17966 </row>
17967 <row topline="true">
17968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17969 \begin_inset Text
17970
17971 \layout Standard
17972
17973 16 bits
17974 \end_inset 
17975 </cell>
17976 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17977 \begin_inset Text
17978
17979 \layout Standard
17980
17981 PRODL:WREG
17982 \end_inset 
17983 </cell>
17984 </row>
17985 <row topline="true">
17986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17987 \begin_inset Text
17988
17989 \layout Standard
17990
17991 24 bits
17992 \end_inset 
17993 </cell>
17994 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17995 \begin_inset Text
17996
17997 \layout Standard
17998
17999 PRODH:PRODL:WREG
18000 \end_inset 
18001 </cell>
18002 </row>
18003 <row topline="true">
18004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18005 \begin_inset Text
18006
18007 \layout Standard
18008
18009 32 bits
18010 \end_inset 
18011 </cell>
18012 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18013 \begin_inset Text
18014
18015 \layout Standard
18016
18017 FSR0L:PRODH:PRODL:WREG
18018 \end_inset 
18019 </cell>
18020 </row>
18021 <row topline="true" bottomline="true">
18022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18023 \begin_inset Text
18024
18025 \layout Standard
18026
18027 >32 bits
18028 \end_inset 
18029 </cell>
18030 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18031 \begin_inset Text
18032
18033 \layout Standard
18034
18035 on stack, FSR0 points to the beginning
18036 \end_inset 
18037 </cell>
18038 </row>
18039 </lyxtabular>
18040
18041 \end_inset 
18042
18043
18044 \layout Subsection
18045
18046 Interrupts
18047 \layout Standard
18048
18049 An interrupt servive routine (ISR) is declared using the 
18050 \emph on 
18051 interrupt
18052 \emph default 
18053  keyword.
18054 \layout LyX-Code
18055
18056 void isr(void) interrupt 
18057 \emph on 
18058 n
18059 \layout LyX-Code
18060
18061 {
18062 \layout LyX-Code
18063
18064 ...
18065 \layout LyX-Code
18066
18067 }
18068 \layout Standard
18069
18070
18071 \emph on 
18072 n
18073 \emph default 
18074  is the interrupt number, which for PIC18F devices can be:
18075 \layout Standard
18076 \align center 
18077
18078 \begin_inset  Tabular
18079 <lyxtabular version="3" rows="4" columns="3">
18080 <features>
18081 <column alignment="center" valignment="top" leftline="true" width="0">
18082 <column alignment="center" valignment="top" leftline="true" width="0">
18083 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18084 <row topline="true" bottomline="true">
18085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18086 \begin_inset Text
18087
18088 \layout Standard
18089
18090
18091 \emph on 
18092 n
18093 \end_inset 
18094 </cell>
18095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18096 \begin_inset Text
18097
18098 \layout Standard
18099
18100 Interrupt Vector
18101 \end_inset 
18102 </cell>
18103 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18104 \begin_inset Text
18105
18106 \layout Standard
18107
18108 Interrupt Vector Address
18109 \end_inset 
18110 </cell>
18111 </row>
18112 <row topline="true">
18113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18114 \begin_inset Text
18115
18116 \layout Standard
18117
18118 0
18119 \end_inset 
18120 </cell>
18121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18122 \begin_inset Text
18123
18124 \layout Standard
18125
18126 RESET vector
18127 \end_inset 
18128 </cell>
18129 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18130 \begin_inset Text
18131
18132 \layout Standard
18133
18134 0x000000
18135 \end_inset 
18136 </cell>
18137 </row>
18138 <row topline="true">
18139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18140 \begin_inset Text
18141
18142 \layout Standard
18143
18144
18145 \family roman 
18146 \series medium 
18147 \shape up 
18148 \size normal 
18149 \emph off 
18150 \bar no 
18151 \noun off 
18152 \color none
18153 1
18154 \end_inset 
18155 </cell>
18156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18157 \begin_inset Text
18158
18159 \layout Standard
18160
18161
18162 \family roman 
18163 \series medium 
18164 \shape up 
18165 \size normal 
18166 \emph off 
18167 \bar no 
18168 \noun off 
18169 \color none
18170 HIGH priority interrupts
18171 \end_inset 
18172 </cell>
18173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18174 \begin_inset Text
18175
18176 \layout Standard
18177
18178 0x000008
18179 \end_inset 
18180 </cell>
18181 </row>
18182 <row topline="true" bottomline="true">
18183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18184 \begin_inset Text
18185
18186 \layout Standard
18187
18188 2
18189 \end_inset 
18190 </cell>
18191 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18192 \begin_inset Text
18193
18194 \layout Standard
18195
18196 LOW priority interrupts
18197 \end_inset 
18198 </cell>
18199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18200 \begin_inset Text
18201
18202 \layout Standard
18203
18204 0x000018
18205 \end_inset 
18206 </cell>
18207 </row>
18208 </lyxtabular>
18209
18210 \end_inset 
18211
18212
18213 \layout Standard
18214
18215 When generating assembly code for ISR the code generator places a 
18216 \noun on 
18217 goto 
18218 \noun default 
18219 instruction at the 
18220 \emph on 
18221 Interrupt Vector Address
18222 \emph default 
18223  which points at the genetated ISR.
18224  This single GOTO instruction is part of an automatically generated 
18225 \emph on 
18226 interrupt entry point
18227 \emph default 
18228  function.
18229  The actuall ISR code is placed as normally would in the code space.
18230  Upon interrupt request, the GOTO instruction is executed which jumps to
18231  the ISR code.
18232  When declaring interrupt functions as _naked this GOTO instruction is 
18233 \series bold 
18234 not
18235 \series default 
18236  generated.
18237  The whole interrupt functions is therefore placed at the Interrupt Vector
18238  Address of the specific interrupt.
18239  This is not a problem for the LOW priority interrupts, but it is a problem
18240  for the RESET and the HIGH priority interrupts because code may be written
18241  at the next interrupt´s vector address and cause undeterminate program
18242  behaviour if that interrupt is raised.
18243 \begin_inset Foot
18244 collapsed false
18245
18246 \layout Standard
18247
18248 This is not a problem when
18249 \layout Enumerate
18250
18251 this is a HIGH interrupt ISR and LOW interrupts are 
18252 \emph on 
18253 disabled
18254 \emph default 
18255  or not used.
18256 \layout Enumerate
18257
18258 when the ISR is small enough not to reach the next interrupt´s vector address.
18259 \end_inset 
18260
18261
18262 \layout Standard
18263
18264
18265 \emph on 
18266 n
18267 \emph default 
18268  is possible to be omitted.
18269  This way a function is generated similar to an ISR, but it is not assigned
18270  to any interrupt.
18271 \layout Standard
18272
18273 When entering an interrupt, currently the PIC16
18274 \begin_inset LatexCommand \index{PIC16}
18275
18276 \end_inset 
18277
18278  port automatically saves the following registers:
18279 \layout Itemize
18280
18281 WREG
18282 \layout Itemize
18283
18284 STATUS
18285 \layout Itemize
18286
18287 BSR
18288 \layout Itemize
18289
18290 PROD (PRODL and PRODH)
18291 \layout Itemize
18292
18293 FSR0 (FSR0L and FSR0H)
18294 \layout Standard
18295
18296 These registers are restored upon return from the interrupt routine.
18297 \begin_inset Foot
18298 collapsed false
18299
18300 \layout Standard
18301
18302 NOTE that when the _naked attribute is specified for an interrupt routine,
18303  then NO registers are stored or restored.
18304 \end_inset 
18305
18306
18307 \layout Subsection
18308
18309 Generic Pointers
18310 \layout Standard
18311
18312 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
18313  There are 3 types of generic pointers currently implemented data, code
18314  and eeprom pointers.
18315  They are differentiated by the value of the 7th and 6th bits of the upper
18316  byte:
18317 \layout Standard
18318 \align center 
18319
18320 \begin_inset  Tabular
18321 <lyxtabular version="3" rows="5" columns="5">
18322 <features>
18323 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18324 <column alignment="center" valignment="top" width="0">
18325 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18326 <column alignment="center" valignment="top" width="0">
18327 <column alignment="left" valignment="top" rightline="true" width="0">
18328 <row topline="true" bottomline="true">
18329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18330 \begin_inset Text
18331
18332 \layout Standard
18333
18334 pointer type
18335 \end_inset 
18336 </cell>
18337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18338 \begin_inset Text
18339
18340 \layout Standard
18341
18342 7th bit
18343 \end_inset 
18344 </cell>
18345 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18346 \begin_inset Text
18347
18348 \layout Standard
18349
18350 6th bit
18351 \end_inset 
18352 </cell>
18353 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18354 \begin_inset Text
18355
18356 \layout Standard
18357
18358 rest of the pointer
18359 \end_inset 
18360 </cell>
18361 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18362 \begin_inset Text
18363
18364 \layout Standard
18365
18366 descrption
18367 \end_inset 
18368 </cell>
18369 </row>
18370 <row topline="true" bottomline="true">
18371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18372 \begin_inset Text
18373
18374 \layout Standard
18375
18376 data 
18377 \end_inset 
18378 </cell>
18379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18380 \begin_inset Text
18381
18382 \layout Standard
18383
18384 1
18385 \end_inset 
18386 </cell>
18387 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18388 \begin_inset Text
18389
18390 \layout Standard
18391
18392 0
18393 \end_inset 
18394 </cell>
18395 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18396 \begin_inset Text
18397
18398 \layout Standard
18399
18400
18401 \family typewriter 
18402 \shape slanted 
18403 \emph on 
18404 uuuuuu uuuuxxxx xxxxxxxx
18405 \end_inset 
18406 </cell>
18407 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18408 \begin_inset Text
18409
18410 \layout Standard
18411
18412 a 12-bit data pointer in data RAM memory
18413 \end_inset 
18414 </cell>
18415 </row>
18416 <row bottomline="true">
18417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18418 \begin_inset Text
18419
18420 \layout Standard
18421
18422 code
18423 \end_inset 
18424 </cell>
18425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18426 \begin_inset Text
18427
18428 \layout Standard
18429
18430 0
18431 \end_inset 
18432 </cell>
18433 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18434 \begin_inset Text
18435
18436 \layout Standard
18437
18438 0
18439 \end_inset 
18440 </cell>
18441 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18442 \begin_inset Text
18443
18444 \layout Standard
18445
18446
18447 \family typewriter 
18448 \shape slanted 
18449 \emph on 
18450 uxxxxx xxxxxxxx xxxxxxxx
18451 \end_inset 
18452 </cell>
18453 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18454 \begin_inset Text
18455
18456 \layout Standard
18457
18458 a 21-bit code pointer in FLASH memory
18459 \end_inset 
18460 </cell>
18461 </row>
18462 <row bottomline="true">
18463 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18464 \begin_inset Text
18465
18466 \layout Standard
18467
18468 eeprom
18469 \end_inset 
18470 </cell>
18471 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18472 \begin_inset Text
18473
18474 \layout Standard
18475
18476 0
18477 \end_inset 
18478 </cell>
18479 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18480 \begin_inset Text
18481
18482 \layout Standard
18483
18484 1
18485 \end_inset 
18486 </cell>
18487 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18488 \begin_inset Text
18489
18490 \layout Standard
18491
18492
18493 \family typewriter 
18494 \shape slanted 
18495 \emph on 
18496 uuuuuu uuuuuuxx xxxxxxxx
18497 \end_inset 
18498 </cell>
18499 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18500 \begin_inset Text
18501
18502 \layout Standard
18503
18504 a 10-bit eeprom pointer in EEPROM memory
18505 \end_inset 
18506 </cell>
18507 </row>
18508 <row bottomline="true">
18509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18510 \begin_inset Text
18511
18512 \layout Standard
18513
18514 (unimplemented)
18515 \end_inset 
18516 </cell>
18517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18518 \begin_inset Text
18519
18520 \layout Standard
18521
18522 1
18523 \end_inset 
18524 </cell>
18525 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18526 \begin_inset Text
18527
18528 \layout Standard
18529
18530 1
18531 \end_inset 
18532 </cell>
18533 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18534 \begin_inset Text
18535
18536 \layout Standard
18537
18538
18539 \family typewriter 
18540 \shape slanted 
18541 \emph on 
18542 xxxxxx xxxxxxxx xxxxxxxx
18543 \end_inset 
18544 </cell>
18545 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18546 \begin_inset Text
18547
18548 \layout Standard
18549
18550 unimplemented pointer type
18551 \end_inset 
18552 </cell>
18553 </row>
18554 </lyxtabular>
18555
18556 \end_inset 
18557
18558
18559 \layout Standard
18560
18561 Generic pointer are read and written with a set of library functions which
18562  read/write 1, 2, 3, 4 bytes.
18563 \layout Subsection
18564
18565 PIC16 C Libraries
18566 \layout Subsubsection
18567
18568 Standard I/O Streams
18569 \layout Standard
18570
18571 In the 
18572 \emph on 
18573 stdio.h
18574 \emph default 
18575  the type FILE is defined as:
18576 \layout LyX-Code
18577
18578 typedef char * FILE;
18579 \layout Standard
18580
18581 This type is the stream type implemented I/O in the PIC18F devices.
18582  Also the standard input and output streams are declared in stdio.h:
18583 \layout LyX-Code
18584
18585 extern FILE * stdin;
18586 \layout LyX-Code
18587
18588 extern FILE * stdout;
18589 \layout Standard
18590
18591 The FILE type is actually a generic pointer which defines one more type
18592  of generic pointers, the 
18593 \emph on 
18594 stream 
18595 \emph default 
18596 pointer.
18597  This new type has the format:
18598 \layout Standard
18599 \align center 
18600
18601 \begin_inset  Tabular
18602 <lyxtabular version="3" rows="2" columns="7">
18603 <features>
18604 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18605 <column alignment="center" valignment="top" width="0">
18606 <column alignment="center" valignment="top" leftline="true" width="0">
18607 <column alignment="center" valignment="top" leftline="true" width="0">
18608 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18609 <column alignment="center" valignment="top" width="0">
18610 <column alignment="left" valignment="top" rightline="true" width="0">
18611 <row topline="true" bottomline="true">
18612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18613 \begin_inset Text
18614
18615 \layout Standard
18616
18617 pointer type
18618 \end_inset 
18619 </cell>
18620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18621 \begin_inset Text
18622
18623 \layout Standard
18624
18625 <7:6>
18626 \end_inset 
18627 </cell>
18628 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18629 \begin_inset Text
18630
18631 \layout Standard
18632
18633 <5>
18634 \end_inset 
18635 </cell>
18636 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18637 \begin_inset Text
18638
18639 \layout Standard
18640
18641 <4>
18642 \end_inset 
18643 </cell>
18644 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18645 \begin_inset Text
18646
18647 \layout Standard
18648
18649 <3:0>
18650 \end_inset 
18651 </cell>
18652 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18653 \begin_inset Text
18654
18655 \layout Standard
18656
18657 rest of the pointer
18658 \end_inset 
18659 </cell>
18660 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18661 \begin_inset Text
18662
18663 \layout Standard
18664
18665 descrption
18666 \end_inset 
18667 </cell>
18668 </row>
18669 <row topline="true" bottomline="true">
18670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18671 \begin_inset Text
18672
18673 \layout Standard
18674
18675 stream
18676 \end_inset 
18677 </cell>
18678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18679 \begin_inset Text
18680
18681 \layout Standard
18682
18683 00
18684 \end_inset 
18685 </cell>
18686 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18687 \begin_inset Text
18688
18689 \layout Standard
18690
18691 1
18692 \end_inset 
18693 </cell>
18694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18695 \begin_inset Text
18696
18697 \layout Standard
18698
18699 0
18700 \end_inset 
18701 </cell>
18702 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18703 \begin_inset Text
18704
18705 \layout Standard
18706
18707 nnnn
18708 \end_inset 
18709 </cell>
18710 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18711 \begin_inset Text
18712
18713 \layout Standard
18714
18715
18716 \family typewriter 
18717 \shape slanted 
18718 \emph on 
18719 uuuuuuuu uuuuuuuu
18720 \end_inset 
18721 </cell>
18722 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18723 \begin_inset Text
18724
18725 \layout Standard
18726
18727 upper byte high nubble is 0x2n, the rest are zeroes
18728 \end_inset 
18729 </cell>
18730 </row>
18731 </lyxtabular>
18732
18733 \end_inset 
18734
18735
18736 \layout Standard
18737
18738 Currently implemented there are 3 types of streams defined:
18739 \layout Standard
18740 \align center 
18741
18742 \begin_inset  Tabular
18743 <lyxtabular version="3" rows="4" columns="4">
18744 <features>
18745 <column alignment="center" valignment="top" leftline="true" width="0">
18746 <column alignment="center" valignment="top" leftline="true" width="0">
18747 <column alignment="center" valignment="top" leftline="true" width="0">
18748 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18749 <row topline="true" bottomline="true">
18750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18751 \begin_inset Text
18752
18753 \layout Standard
18754
18755 stream type
18756 \end_inset 
18757 </cell>
18758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18759 \begin_inset Text
18760
18761 \layout Standard
18762
18763 value
18764 \end_inset 
18765 </cell>
18766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18767 \begin_inset Text
18768
18769 \layout Standard
18770
18771 module
18772 \end_inset 
18773 </cell>
18774 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18775 \begin_inset Text
18776
18777 \layout Standard
18778
18779 description
18780 \end_inset 
18781 </cell>
18782 </row>
18783 <row topline="true">
18784 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18785 \begin_inset Text
18786
18787 \layout Standard
18788
18789 STREAM_USART
18790 \end_inset 
18791 </cell>
18792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18793 \begin_inset Text
18794
18795 \layout Standard
18796
18797
18798 \family typewriter 
18799 0x200000UL
18800 \end_inset 
18801 </cell>
18802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18803 \begin_inset Text
18804
18805 \layout Standard
18806
18807 USART
18808 \end_inset 
18809 </cell>
18810 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18811 \begin_inset Text
18812
18813 \layout Standard
18814
18815 Writes/Reads characters via the USART peripheral
18816 \end_inset 
18817 </cell>
18818 </row>
18819 <row topline="true">
18820 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18821 \begin_inset Text
18822
18823 \layout Standard
18824
18825 STREAM_MSSP
18826 \end_inset 
18827 </cell>
18828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18829 \begin_inset Text
18830
18831 \layout Standard
18832
18833
18834 \family typewriter 
18835 0x210000UL
18836 \end_inset 
18837 </cell>
18838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18839 \begin_inset Text
18840
18841 \layout Standard
18842
18843 MSSP
18844 \end_inset 
18845 </cell>
18846 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18847 \begin_inset Text
18848
18849 \layout Standard
18850
18851 Writes/Reads characters via the MSSP peripheral
18852 \end_inset 
18853 </cell>
18854 </row>
18855 <row topline="true" bottomline="true">
18856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18857 \begin_inset Text
18858
18859 \layout Standard
18860
18861 STREAM_USER
18862 \end_inset 
18863 </cell>
18864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18865 \begin_inset Text
18866
18867 \layout Standard
18868
18869
18870 \family typewriter 
18871 0x2f0000UL
18872 \end_inset 
18873 </cell>
18874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18875 \begin_inset Text
18876
18877 \layout Standard
18878
18879 (none)
18880 \end_inset 
18881 </cell>
18882 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18883 \begin_inset Text
18884
18885 \layout Standard
18886
18887 Writes/Reads characters via used defined functions
18888 \end_inset 
18889 </cell>
18890 </row>
18891 </lyxtabular>
18892
18893 \end_inset 
18894
18895
18896 \layout Standard
18897
18898 The stream identifiers are declared as macros in the stdio.h header.
18899 \layout Standard
18900
18901 In the libc library there exist the functions that are used to write to
18902  each of the above streams.
18903  These are
18904 \layout List
18905 \labelwidthstring 00.00.0000
18906
18907 _
18908 \begin_inset ERT
18909 status Collapsed
18910
18911 \layout Standard
18912
18913 \backslash 
18914 /
18915 \end_inset 
18916
18917 _stream_usart_putchar writes a character at the USART stream
18918 \layout List
18919 \labelwidthstring 00.00.0000
18920
18921 _
18922 \begin_inset ERT
18923 status Collapsed
18924
18925 \layout Standard
18926
18927 \backslash 
18928 /
18929 \end_inset 
18930
18931 _stream_mssp_putchar writes a character at the MSSP stream
18932 \layout List
18933 \labelwidthstring 00.00.0000
18934
18935 putchar dummy function.
18936  This writes a character to a user specified manner.
18937 \layout Standard
18938
18939 In order to increase performance 
18940 \emph on 
18941 putchar 
18942 \emph default 
18943 is declared in stdio.h as having its parameter in WREG (it has the wparam
18944  keyword).
18945  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
18946  in a user-friendly way.
18947  
18948 \emph on 
18949 arg
18950 \emph default 
18951  is the name of the variable that holds the character to print.
18952  An example follows:
18953 \layout LyX-Code
18954
18955 #include <pic18fregs.h>
18956 \newline 
18957 #include <stdio.h>
18958 \newline 
18959
18960 \newline 
18961 PUTCHAR( c )
18962 \layout LyX-Code
18963
18964 {
18965 \layout LyX-Code
18966
18967     PORTA = c;    /* dump character c to PORTA */
18968 \layout LyX-Code
18969
18970
18971 \newline 
18972
18973 \newline 
18974 void main(void)
18975 \layout LyX-Code
18976
18977 {
18978 \layout LyX-Code
18979
18980     stdout = STREAM_USER;    /* this is not necessery, since stdout points
18981 \layout LyX-Code
18982
18983                               * by default to STREAM_USER */
18984 \layout LyX-Code
18985
18986     printf (¨This is a printf test
18987 \backslash 
18988 n¨);
18989 \layout LyX-Code
18990
18991 }
18992 \layout LyX-Code
18993
18994 \layout Subsubsection
18995
18996 Printing functions
18997 \layout Standard
18998
18999 PIC16 contains an implementation of the printf-family of functions.
19000  There exist the following functions:
19001 \layout LyX-Code
19002
19003 extern unsigned int sprintf(char *buf, char *fmt, ...);
19004 \layout LyX-Code
19005
19006 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
19007 \layout LyX-Code
19008
19009 \layout LyX-Code
19010
19011 extern unsigned int printf(char *fmt, ...);
19012 \layout LyX-Code
19013
19014 extern unsigned int vprintf(char *fmt, va_lista ap);
19015 \layout LyX-Code
19016
19017 \layout LyX-Code
19018
19019 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
19020 \layout LyX-Code
19021
19022 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
19023 \layout Standard
19024
19025 For sprintf and vsprintf 
19026 \emph on 
19027 buf 
19028 \emph default 
19029 should normally be a data pointer where the resulting string will be placed.
19030  No range checking is done so the user should allocate the necessery buffer.
19031  For fprintf and vfprintf 
19032 \emph on 
19033 fp
19034 \emph default 
19035  should be a stream pointer (i.e.
19036  stdout, STREAM_MSSP, etc...).
19037 \layout Subsubsection
19038
19039 Signals
19040 \layout Standard
19041
19042 The PIC18F family of microcontrollers supports a number of interrupt sources.
19043  A list of these interrupts is shown in the following table:
19044 \layout Standard
19045 \align center 
19046
19047 \begin_inset  Tabular
19048 <lyxtabular version="3" rows="11" columns="4">
19049 <features>
19050 <column alignment="left" valignment="top" leftline="true" width="0">
19051 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19052 <column alignment="left" valignment="top" leftline="true" width="0">
19053 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19054 <row topline="true" bottomline="true">
19055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19056 \begin_inset Text
19057
19058 \layout Standard
19059
19060 signal name
19061 \end_inset 
19062 </cell>
19063 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19064 \begin_inset Text
19065
19066 \layout Standard
19067
19068 description
19069 \end_inset 
19070 </cell>
19071 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19072 \begin_inset Text
19073
19074 \layout Standard
19075
19076 signal name
19077 \end_inset 
19078 </cell>
19079 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19080 \begin_inset Text
19081
19082 \layout Standard
19083
19084 descritpion
19085 \end_inset 
19086 </cell>
19087 </row>
19088 <row topline="true">
19089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19090 \begin_inset Text
19091
19092 \layout Standard
19093
19094 SIG_RB
19095 \end_inset 
19096 </cell>
19097 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19098 \begin_inset Text
19099
19100 \layout Standard
19101
19102 PORTB change interrupt
19103 \end_inset 
19104 </cell>
19105 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19106 \begin_inset Text
19107
19108 \layout Standard
19109
19110 SIG_EE
19111 \end_inset 
19112 </cell>
19113 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19114 \begin_inset Text
19115
19116 \layout Standard
19117
19118 EEPROM/FLASH write complete interrupt
19119 \end_inset 
19120 </cell>
19121 </row>
19122 <row topline="true">
19123 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19124 \begin_inset Text
19125
19126 \layout Standard
19127
19128 SIG_INT0
19129 \end_inset 
19130 </cell>
19131 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19132 \begin_inset Text
19133
19134 \layout Standard
19135
19136 INT0 external interrupt
19137 \end_inset 
19138 </cell>
19139 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19140 \begin_inset Text
19141
19142 \layout Standard
19143
19144 SIG_BCOL
19145 \end_inset 
19146 </cell>
19147 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19148 \begin_inset Text
19149
19150 \layout Standard
19151
19152 Bus collision interrupt
19153 \end_inset 
19154 </cell>
19155 </row>
19156 <row topline="true">
19157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19158 \begin_inset Text
19159
19160 \layout Standard
19161
19162 SIG_INT1
19163 \end_inset 
19164 </cell>
19165 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19166 \begin_inset Text
19167
19168 \layout Standard
19169
19170 INT1 external interrupt
19171 \end_inset 
19172 </cell>
19173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19174 \begin_inset Text
19175
19176 \layout Standard
19177
19178 SIG_LVD
19179 \end_inset 
19180 </cell>
19181 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19182 \begin_inset Text
19183
19184 \layout Standard
19185
19186 Low voltage detect interrupt
19187 \end_inset 
19188 </cell>
19189 </row>
19190 <row topline="true">
19191 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19192 \begin_inset Text
19193
19194 \layout Standard
19195
19196 SIG_INT2
19197 \end_inset 
19198 </cell>
19199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19200 \begin_inset Text
19201
19202 \layout Standard
19203
19204 INT2 external interrupt
19205 \end_inset 
19206 </cell>
19207 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19208 \begin_inset Text
19209
19210 \layout Standard
19211
19212 SIG_PSP
19213 \end_inset 
19214 </cell>
19215 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19216 \begin_inset Text
19217
19218 \layout Standard
19219
19220 Parallel slave port interrupt
19221 \end_inset 
19222 </cell>
19223 </row>
19224 <row topline="true">
19225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19226 \begin_inset Text
19227
19228 \layout Standard
19229
19230 SIG_CCP1
19231 \end_inset 
19232 </cell>
19233 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19234 \begin_inset Text
19235
19236 \layout Standard
19237
19238 CCP1 module interrupt
19239 \end_inset 
19240 </cell>
19241 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19242 \begin_inset Text
19243
19244 \layout Standard
19245
19246 SIG_AD
19247 \end_inset 
19248 </cell>
19249 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19250 \begin_inset Text
19251
19252 \layout Standard
19253
19254 AD convertion complete interrupt
19255 \end_inset 
19256 </cell>
19257 </row>
19258 <row topline="true">
19259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19260 \begin_inset Text
19261
19262 \layout Standard
19263
19264 SIG_CCP2
19265 \end_inset 
19266 </cell>
19267 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19268 \begin_inset Text
19269
19270 \layout Standard
19271
19272 CCP2 module interrupt
19273 \end_inset 
19274 </cell>
19275 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19276 \begin_inset Text
19277
19278 \layout Standard
19279
19280 SIG_RC
19281 \end_inset 
19282 </cell>
19283 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19284 \begin_inset Text
19285
19286 \layout Standard
19287
19288 USART receive interrupt
19289 \end_inset 
19290 </cell>
19291 </row>
19292 <row topline="true">
19293 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19294 \begin_inset Text
19295
19296 \layout Standard
19297
19298 SIG_TMR0
19299 \end_inset 
19300 </cell>
19301 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19302 \begin_inset Text
19303
19304 \layout Standard
19305
19306 TMR0 overflow interrupt
19307 \end_inset 
19308 </cell>
19309 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19310 \begin_inset Text
19311
19312 \layout Standard
19313
19314 SIG_TX
19315 \end_inset 
19316 </cell>
19317 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19318 \begin_inset Text
19319
19320 \layout Standard
19321
19322 USART transmit interrupt
19323 \end_inset 
19324 </cell>
19325 </row>
19326 <row topline="true">
19327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19328 \begin_inset Text
19329
19330 \layout Standard
19331
19332 SIG_TMR1
19333 \end_inset 
19334 </cell>
19335 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19336 \begin_inset Text
19337
19338 \layout Standard
19339
19340 TMR1 overflow interrupt
19341 \end_inset 
19342 </cell>
19343 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19344 \begin_inset Text
19345
19346 \layout Standard
19347
19348 SIG_MSSP
19349 \end_inset 
19350 </cell>
19351 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19352 \begin_inset Text
19353
19354 \layout Standard
19355
19356 SSP receive/transmit interrupt
19357 \end_inset 
19358 </cell>
19359 </row>
19360 <row topline="true">
19361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19362 \begin_inset Text
19363
19364 \layout Standard
19365
19366 SIG_TMR2
19367 \end_inset 
19368 </cell>
19369 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19370 \begin_inset Text
19371
19372 \layout Standard
19373
19374 TMR2 matches PR2 interrupt
19375 \end_inset 
19376 </cell>
19377 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19378 \begin_inset Text
19379
19380 \layout Standard
19381
19382 \end_inset 
19383 </cell>
19384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19385 \begin_inset Text
19386
19387 \layout Standard
19388
19389 \end_inset 
19390 </cell>
19391 </row>
19392 <row topline="true" bottomline="true">
19393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19394 \begin_inset Text
19395
19396 \layout Standard
19397
19398 SIG_TMR3
19399 \end_inset 
19400 </cell>
19401 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19402 \begin_inset Text
19403
19404 \layout Standard
19405
19406 TMR3 overflow interrupt
19407 \end_inset 
19408 </cell>
19409 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19410 \begin_inset Text
19411
19412 \layout Standard
19413
19414 \end_inset 
19415 </cell>
19416 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19417 \begin_inset Text
19418
19419 \layout Standard
19420
19421 \end_inset 
19422 </cell>
19423 </row>
19424 </lyxtabular>
19425
19426 \end_inset 
19427
19428
19429 \layout Standard
19430
19431 The prototypes for these names are defined in the header file 
19432 \emph on 
19433 signal.h
19434 \emph default 
19435  .
19436 \layout Standard
19437
19438 In order to simplify signal handling, a number of macros is provided:
19439 \layout List
19440 \labelwidthstring 00.00.0000
19441
19442 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
19443  high priority interrupts.
19444  
19445 \emph on 
19446 name
19447 \emph default 
19448  is the function name to use.
19449 \layout List
19450 \labelwidthstring 00.00.0000
19451
19452 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
19453  low priority interrupt.
19454  
19455 \emph on 
19456 name
19457 \emph default 
19458  is the function name to use.
19459 \layout List
19460 \labelwidthstring 00.00.0000
19461
19462 DEF_HANDLER(sig,handler) define a handler for signal 
19463 \emph on 
19464 sig.
19465 \layout List
19466 \labelwidthstring 00.00.0000
19467
19468 END_DEF end the declaration of the dispatch table.
19469 \layout Standard
19470
19471 Additionally there are two more macros to simplify the declaration of the
19472  signal handler:
19473 \layout List
19474 \labelwidthstring 00.00.0000
19475
19476
19477 \series medium 
19478 SIGHANDLER(handler) 
19479 \series default 
19480 this declares the function prototype for the 
19481 \emph on 
19482 handler
19483 \emph default 
19484  function.
19485 \layout List
19486 \labelwidthstring 00.00.0000
19487
19488 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
19489 \layout Standard
19490
19491 An example of using the macros above is shown below:
19492 \layout LyX-Code
19493
19494 #include <pic18fregs.h>
19495 \layout LyX-Code
19496
19497 #include <signal.h>
19498 \newline 
19499
19500 \newline 
19501 DEF_INTHIGH(high_int)
19502 \layout LyX-Code
19503
19504 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
19505 \layout LyX-Code
19506
19507 DEF_HANDLER(SIG_BCOL, _bcol_handler)
19508 \layout LyX-Code
19509
19510 END_DEF
19511 \newline 
19512
19513 \newline 
19514 SIGHANDLER(_tmr0_handler)
19515 \layout LyX-Code
19516
19517 {
19518 \layout LyX-Code
19519
19520   /* action to be taken when timer 0 overflows */
19521 \layout LyX-Code
19522
19523 }
19524 \newline 
19525
19526 \newline 
19527 SIGHANDLERNAKED(_bcol_handler)
19528 \layout LyX-Code
19529
19530 {
19531 \layout LyX-Code
19532
19533   _asm
19534 \layout LyX-Code
19535
19536     /* action to be taken when bus collision occurs */
19537 \layout LyX-Code
19538
19539     retfie
19540 \layout LyX-Code
19541
19542  _endasm;
19543 \layout LyX-Code
19544
19545 }
19546 \layout Standard
19547
19548
19549 \series bold 
19550 NOTES:
19551 \series default 
19552  Special care should be taken when using the above scheme:
19553 \layout Itemize
19554
19555 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
19556 \layout Itemize
19557
19558 when declaring SIGHANDLERNAKED handler never forget to use 
19559 \emph on 
19560 retfie
19561 \emph default 
19562  for proper returning.
19563 \layout Subsection
19564
19565 PIC16 Port -- Tips
19566 \layout Standard
19567
19568 Here you can find some general tips for compiling programs with SDCC/pic16.
19569 \layout Subsubsection
19570
19571 Stack size
19572 \layout Standard
19573
19574 The default stack size (that is 64 bytes) probably is enough for many programs.
19575  One must take care that when there are many levels of function nesting,
19576  or there is excessive usage of stack, its size should be extended.
19577  An example of such a case is the printf/sprintf family of functions.
19578  If you encounter problems like not being able to print integers, then you
19579  need to set the stack size around the maximum (256 for small stack model).
19580  The following diagram shows what happens when calling printf to print an
19581  integer:
19582 \layout LyX-Code
19583
19584 printf () --> ltoa () --> ultoa () --> divschar ()
19585 \layout Standard
19586
19587 It is should be understood that stack is easily consumed when calling complicate
19588 d functions.
19589  Using command line arguments like -
19590 \begin_inset ERT
19591 status Collapsed
19592
19593 \layout Standard
19594
19595 \backslash 
19596 /
19597 \end_inset 
19598
19599 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
19600  stack frames.
19601  Other ways to reduce stack usage may exist.
19602 \layout Chapter
19603
19604 Debugging with SDCDB
19605 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
19606
19607 \end_inset 
19608
19609
19610 \begin_inset LatexCommand \index{sdcdb (debugger)}
19611
19612 \end_inset 
19613
19614  
19615 \layout Standard
19616
19617 SDCC is distributed with a source level debugger
19618 \begin_inset LatexCommand \index{Debugger}
19619
19620 \end_inset 
19621
19622 .
19623  The debugger uses a command line interface, the command repertoire of the
19624  debugger has been kept as close to gdb
19625 \begin_inset LatexCommand \index{gdb}
19626
19627 \end_inset 
19628
19629  (the GNU debugger) as possible.
19630  The configuration and build process is part of the standard compiler installati
19631 on, which also builds and installs the debugger in the target directory
19632  specified during configuration.
19633  The debugger allows you debug BOTH at the C source and at the ASM source
19634  level.
19635  Sdcdb is available on Unix platforms only.
19636 \layout Section
19637
19638 Compiling for Debugging
19639 \layout Standard
19640
19641 The -
19642 \begin_inset ERT
19643 status Collapsed
19644
19645 \layout Standard
19646
19647 \backslash 
19648 /
19649 \end_inset 
19650
19651 -debug
19652 \begin_inset LatexCommand \index{-\/-debug}
19653
19654 \end_inset 
19655
19656  option must be specified for all files for which debug information is to
19657  be generated.
19658  The complier generates a .adb file for each of these files.
19659  The linker creates the .cdb
19660 \begin_inset LatexCommand \index{<file>.cdb}
19661
19662 \end_inset 
19663
19664  file from the .adb
19665 \begin_inset LatexCommand \index{<file>.adb}
19666
19667 \end_inset 
19668
19669  files and the address information.
19670  This .cdb is used by the debugger.
19671 \layout Section
19672
19673 How the Debugger Works
19674 \layout Standard
19675
19676 When the -
19677 \begin_inset ERT
19678 status Collapsed
19679
19680 \layout Standard
19681
19682 \backslash 
19683 /
19684 \end_inset 
19685
19686 -debug option is specified the compiler generates extra symbol information
19687  some of which are put into the assembler source and some are put into the
19688  .adb file.
19689   Then the linker creates the .cdb file from the individual .adb files with
19690  the address information for the symbols.
19691  The debugger reads the symbolic information generated by the compiler &
19692  the address information generated by the linker.
19693  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
19694  execution is controlled by the debugger.
19695  When a command is issued for the debugger, it translates it into appropriate
19696  commands for the simulator.
19697 \layout Section
19698
19699 Starting the Debugger
19700 \layout Standard
19701
19702 The debugger can be started using the following command line.
19703  (Assume the file you are debugging has the file name foo).
19704 \newline 
19705
19706 \newline 
19707
19708 \family sans 
19709 \series bold 
19710 sdcdb foo
19711 \newline 
19712
19713 \family default 
19714 \series default 
19715
19716 \newline 
19717 The debugger will look for the following files.
19718 \layout Itemize
19719
19720 foo.c - the source file.
19721 \layout Itemize
19722
19723 foo.cdb - the debugger symbol information file.
19724 \layout Itemize
19725
19726 foo.ihx - the Intel hex format
19727 \begin_inset LatexCommand \index{Intel hex format}
19728
19729 \end_inset 
19730
19731  object file.
19732 \layout Section
19733
19734 Command Line Options.
19735 \layout Itemize
19736
19737 -
19738 \begin_inset ERT
19739 status Collapsed
19740
19741 \layout Standard
19742
19743 \backslash 
19744 /
19745 \end_inset 
19746
19747 -directory=<source file directory> this option can used to specify the directory
19748  search list.
19749  The debugger will look into the directory list specified for source, cdb
19750  & ihx files.
19751  The items in the directory list must be separated by ':', e.g.
19752  if the source files can be in the directories /home/src1 and /home/src2,
19753  the -
19754 \begin_inset ERT
19755 status Collapsed
19756
19757 \layout Standard
19758
19759 \backslash 
19760 /
19761 \end_inset 
19762
19763 -directory option should be -
19764 \begin_inset ERT
19765 status Collapsed
19766
19767 \layout Standard
19768
19769 \backslash 
19770 /
19771 \end_inset 
19772
19773 -directory=/home/src1:/home/src2.
19774  Note there can be no spaces in the option.
19775  
19776 \layout Itemize
19777
19778 -cd <directory> - change to the <directory>.
19779 \layout Itemize
19780
19781 -fullname - used by GUI front ends.
19782 \layout Itemize
19783
19784 -cpu <cpu-type> - this argument is passed to the simulator please see the
19785  simulator docs for details.
19786 \layout Itemize
19787
19788 -X <Clock frequency > this options is passed to the simulator please see
19789  the simulator docs for details.
19790 \layout Itemize
19791
19792 -s <serial port file> passed to simulator see the simulator docs for details.
19793 \layout Itemize
19794
19795 -S <serial in,out> passed to simulator see the simulator docs for details.
19796 \layout Itemize
19797
19798 -k <port number> passed to simulator see the simulator docs for details.
19799 \layout Section
19800
19801 Debugger Commands.
19802 \layout Standard
19803
19804 As mentioned earlier the command interface for the debugger has been deliberatel
19805 y kept as close the GNU debugger gdb, as possible.
19806  This will help the integration with existing graphical user interfaces
19807  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
19808  If you use a graphical user interface for the debugger you can skip the
19809  next sections.
19810 \layout Subsubsection*
19811
19812 break [line | file:line | function | file:function]
19813 \layout Standard
19814
19815 Set breakpoint at specified line or function:
19816 \newline 
19817
19818 \newline 
19819
19820 \family sans 
19821 \series bold 
19822 sdcdb>break 100 
19823 \newline 
19824 sdcdb>break foo.c:100
19825 \newline 
19826 sdcdb>break funcfoo
19827 \newline 
19828 sdcdb>break foo.c:funcfoo
19829 \layout Subsubsection*
19830
19831 clear [line | file:line | function | file:function ]
19832 \layout Standard
19833
19834 Clear breakpoint at specified line or function:
19835 \newline 
19836
19837 \newline 
19838
19839 \family sans 
19840 \series bold 
19841 sdcdb>clear 100
19842 \newline 
19843 sdcdb>clear foo.c:100
19844 \newline 
19845 sdcdb>clear funcfoo
19846 \newline 
19847 sdcdb>clear foo.c:funcfoo
19848 \layout Subsubsection*
19849
19850 continue
19851 \layout Standard
19852
19853 Continue program being debugged, after breakpoint.
19854 \layout Subsubsection*
19855
19856 finish
19857 \layout Standard
19858
19859 Execute till the end of the current function.
19860 \layout Subsubsection*
19861
19862 delete [n]
19863 \layout Standard
19864
19865 Delete breakpoint number 'n'.
19866  If used without any option clear ALL user defined break points.
19867 \layout Subsubsection*
19868
19869 info [break | stack | frame | registers ]
19870 \layout Itemize
19871
19872 info break - list all breakpoints
19873 \layout Itemize
19874
19875 info stack - show the function call stack.
19876 \layout Itemize
19877
19878 info frame - show information about the current execution frame.
19879 \layout Itemize
19880
19881 info registers - show content of all registers.
19882 \layout Subsubsection*
19883
19884 step
19885 \layout Standard
19886
19887 Step program until it reaches a different source line.
19888  Note: pressing <return> repeats the last command.
19889 \layout Subsubsection*
19890
19891 next
19892 \layout Standard
19893
19894 Step program, proceeding through subroutine calls.
19895 \layout Subsubsection*
19896
19897 run
19898 \layout Standard
19899
19900 Start debugged program.
19901 \layout Subsubsection*
19902
19903 ptype variable 
19904 \layout Standard
19905
19906 Print type information of the variable.
19907 \layout Subsubsection*
19908
19909 print variable
19910 \layout Standard
19911
19912 print value of variable.
19913 \layout Subsubsection*
19914
19915 file filename
19916 \layout Standard
19917
19918 load the given file name.
19919  Note this is an alternate method of loading file for debugging.
19920 \layout Subsubsection*
19921
19922 frame
19923 \layout Standard
19924
19925 print information about current frame.
19926 \layout Subsubsection*
19927
19928 set srcmode
19929 \layout Standard
19930
19931 Toggle between C source & assembly source.
19932 \layout Subsubsection*
19933
19934 ! simulator command
19935 \layout Standard
19936
19937 Send the string following '!' to the simulator, the simulator response is
19938  displayed.
19939  Note the debugger does not interpret the command being sent to the simulator,
19940  so if a command like 'go' is sent the debugger can loose its execution
19941  context and may display incorrect values.
19942 \layout Subsubsection*
19943
19944 quit
19945 \layout Standard
19946
19947 "Watch me now.
19948  Iam going Down.
19949  My name is Bobby Brown"
19950 \layout Section
19951
19952 Interfacing with XEmacs
19953 \begin_inset LatexCommand \index{XEmacs}
19954
19955 \end_inset 
19956
19957
19958 \begin_inset LatexCommand \index{Emacs}
19959
19960 \end_inset 
19961
19962 .
19963 \layout Standard
19964
19965 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
19966  sdcdb.el and sdcdbsrc.el.
19967  These two files can be found in the $(prefix)/bin directory after the installat
19968 ion is complete.
19969  These files need to be loaded into XEmacs for the interface to work.
19970  This can be done at XEmacs startup time by inserting the following into
19971  your '.xemacs' file (which can be found in your HOME directory): 
19972 \newline 
19973
19974 \newline 
19975
19976 \family typewriter 
19977 (load-file sdcdbsrc.el) 
19978 \family default 
19979
19980 \newline 
19981
19982 \newline 
19983 .xemacs is a lisp file so the () around the command is REQUIRED.
19984  The files can also be loaded dynamically while XEmacs is running, set the
19985  environment variable 'EMACSLOADPATH' to the installation bin directory
19986  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
19987  To start the interface enter the following command: 
19988 \newline 
19989
19990 \newline 
19991
19992 \family sans 
19993 \series bold 
19994 ESC-x sdcdbsrc
19995 \family default 
19996 \series default 
19997
19998 \newline 
19999
20000 \newline 
20001 You will prompted to enter the file name to be debugged.
20002  
20003 \newline 
20004
20005 \newline 
20006 The command line options that are passed to the simulator directly are bound
20007  to default values in the file sdcdbsrc.el.
20008  The variables are listed below, these values maybe changed as required.
20009 \layout Itemize
20010
20011 sdcdbsrc-cpu-type '51
20012 \layout Itemize
20013
20014 sdcdbsrc-frequency '11059200
20015 \layout Itemize
20016
20017 sdcdbsrc-serial nil
20018 \layout Standard
20019
20020 The following is a list of key mapping for the debugger interface.
20021 \layout Standard
20022
20023 \SpecialChar ~
20024
20025 \family typewriter 
20026
20027 \newline 
20028 ;;\SpecialChar ~
20029 Current Listing :: 
20030 \newline 
20031 ;;key\SpecialChar ~
20032 \SpecialChar ~
20033 \SpecialChar ~
20034 \SpecialChar ~
20035 \SpecialChar ~
20036 \SpecialChar ~
20037 \SpecialChar ~
20038 \SpecialChar ~
20039 \SpecialChar ~
20040 \SpecialChar ~
20041 \SpecialChar ~
20042 \SpecialChar ~
20043 \SpecialChar ~
20044 \SpecialChar ~
20045 binding\SpecialChar ~
20046 \SpecialChar ~
20047 \SpecialChar ~
20048 \SpecialChar ~
20049 \SpecialChar ~
20050 \SpecialChar ~
20051 \SpecialChar ~
20052 \SpecialChar ~
20053 \SpecialChar ~
20054 \SpecialChar ~
20055 \SpecialChar ~
20056 \SpecialChar ~
20057 \SpecialChar ~
20058 \SpecialChar ~
20059 \SpecialChar ~
20060 \SpecialChar ~
20061 \SpecialChar ~
20062 \SpecialChar ~
20063 \SpecialChar ~
20064 \SpecialChar ~
20065 \SpecialChar ~
20066 \SpecialChar ~
20067 Comment 
20068 \newline 
20069 ;;---\SpecialChar ~
20070 \SpecialChar ~
20071 \SpecialChar ~
20072 \SpecialChar ~
20073 \SpecialChar ~
20074 \SpecialChar ~
20075 \SpecialChar ~
20076 \SpecialChar ~
20077 \SpecialChar ~
20078 \SpecialChar ~
20079 \SpecialChar ~
20080 \SpecialChar ~
20081 \SpecialChar ~
20082 \SpecialChar ~
20083 -------\SpecialChar ~
20084 \SpecialChar ~
20085 \SpecialChar ~
20086 \SpecialChar ~
20087 \SpecialChar ~
20088 \SpecialChar ~
20089 \SpecialChar ~
20090 \SpecialChar ~
20091 \SpecialChar ~
20092 \SpecialChar ~
20093 \SpecialChar ~
20094 \SpecialChar ~
20095 \SpecialChar ~
20096 \SpecialChar ~
20097 \SpecialChar ~
20098 \SpecialChar ~
20099 \SpecialChar ~
20100 \SpecialChar ~
20101 \SpecialChar ~
20102 \SpecialChar ~
20103 \SpecialChar ~
20104 \SpecialChar ~
20105 -------
20106 \newline 
20107 ;; 
20108 \newline 
20109 ;;\SpecialChar ~
20110 n\SpecialChar ~
20111 \SpecialChar ~
20112 \SpecialChar ~
20113 \SpecialChar ~
20114 \SpecialChar ~
20115 \SpecialChar ~
20116 \SpecialChar ~
20117 \SpecialChar ~
20118 \SpecialChar ~
20119 \SpecialChar ~
20120 \SpecialChar ~
20121 \SpecialChar ~
20122 \SpecialChar ~
20123 \SpecialChar ~
20124 \SpecialChar ~
20125 sdcdb-next-from-src\SpecialChar ~
20126 \SpecialChar ~
20127 \SpecialChar ~
20128 \SpecialChar ~
20129 \SpecialChar ~
20130 \SpecialChar ~
20131 \SpecialChar ~
20132 \SpecialChar ~
20133 \SpecialChar ~
20134 \SpecialChar ~
20135 SDCDB next command 
20136 \newline 
20137 ;;\SpecialChar ~
20138 b\SpecialChar ~
20139 \SpecialChar ~
20140 \SpecialChar ~
20141 \SpecialChar ~
20142 \SpecialChar ~
20143 \SpecialChar ~
20144 \SpecialChar ~
20145 \SpecialChar ~
20146 \SpecialChar ~
20147 \SpecialChar ~
20148 \SpecialChar ~
20149 \SpecialChar ~
20150 \SpecialChar ~
20151 \SpecialChar ~
20152 \SpecialChar ~
20153 sdcdb-back-from-src\SpecialChar ~
20154 \SpecialChar ~
20155 \SpecialChar ~
20156 \SpecialChar ~
20157 \SpecialChar ~
20158 \SpecialChar ~
20159 \SpecialChar ~
20160 \SpecialChar ~
20161 \SpecialChar ~
20162 \SpecialChar ~
20163 SDCDB back command 
20164 \newline 
20165 ;;\SpecialChar ~
20166 c\SpecialChar ~
20167 \SpecialChar ~
20168 \SpecialChar ~
20169 \SpecialChar ~
20170 \SpecialChar ~
20171 \SpecialChar ~
20172 \SpecialChar ~
20173 \SpecialChar ~
20174 \SpecialChar ~
20175 \SpecialChar ~
20176 \SpecialChar ~
20177 \SpecialChar ~
20178 \SpecialChar ~
20179 \SpecialChar ~
20180 \SpecialChar ~
20181 sdcdb-cont-from-src\SpecialChar ~
20182 \SpecialChar ~
20183 \SpecialChar ~
20184 \SpecialChar ~
20185 \SpecialChar ~
20186 \SpecialChar ~
20187 \SpecialChar ~
20188 \SpecialChar ~
20189 \SpecialChar ~
20190 \SpecialChar ~
20191 SDCDB continue command
20192 \newline 
20193 ;;\SpecialChar ~
20194 s\SpecialChar ~
20195 \SpecialChar ~
20196 \SpecialChar ~
20197 \SpecialChar ~
20198 \SpecialChar ~
20199 \SpecialChar ~
20200 \SpecialChar ~
20201 \SpecialChar ~
20202 \SpecialChar ~
20203 \SpecialChar ~
20204 \SpecialChar ~
20205 \SpecialChar ~
20206 \SpecialChar ~
20207 \SpecialChar ~
20208 \SpecialChar ~
20209 sdcdb-step-from-src\SpecialChar ~
20210 \SpecialChar ~
20211 \SpecialChar ~
20212 \SpecialChar ~
20213 \SpecialChar ~
20214 \SpecialChar ~
20215 \SpecialChar ~
20216 \SpecialChar ~
20217 \SpecialChar ~
20218 \SpecialChar ~
20219 SDCDB step command 
20220 \newline 
20221 ;;\SpecialChar ~
20222 ?\SpecialChar ~
20223 \SpecialChar ~
20224 \SpecialChar ~
20225 \SpecialChar ~
20226 \SpecialChar ~
20227 \SpecialChar ~
20228 \SpecialChar ~
20229 \SpecialChar ~
20230 \SpecialChar ~
20231 \SpecialChar ~
20232 \SpecialChar ~
20233 \SpecialChar ~
20234 \SpecialChar ~
20235 \SpecialChar ~
20236 \SpecialChar ~
20237 sdcdb-whatis-c-sexp\SpecialChar ~
20238 \SpecialChar ~
20239 \SpecialChar ~
20240 \SpecialChar ~
20241 \SpecialChar ~
20242 \SpecialChar ~
20243 \SpecialChar ~
20244 \SpecialChar ~
20245 \SpecialChar ~
20246 \SpecialChar ~
20247 SDCDB ptypecommand for data at 
20248 \newline 
20249 ;;\SpecialChar ~
20250 \SpecialChar ~
20251 \SpecialChar ~
20252 \SpecialChar ~
20253 \SpecialChar ~
20254 \SpecialChar ~
20255 \SpecialChar ~
20256 \SpecialChar ~
20257 \SpecialChar ~
20258 \SpecialChar ~
20259 \SpecialChar ~
20260 \SpecialChar ~
20261 \SpecialChar ~
20262 \SpecialChar ~
20263 \SpecialChar ~
20264 \SpecialChar ~
20265 \SpecialChar ~
20266 \SpecialChar ~
20267 \SpecialChar ~
20268 \SpecialChar ~
20269 \SpecialChar ~
20270 \SpecialChar ~
20271 \SpecialChar ~
20272 \SpecialChar ~
20273 \SpecialChar ~
20274 \SpecialChar ~
20275 \SpecialChar ~
20276 \SpecialChar ~
20277 \SpecialChar ~
20278 \SpecialChar ~
20279 \SpecialChar ~
20280 \SpecialChar ~
20281 \SpecialChar ~
20282 \SpecialChar ~
20283 \SpecialChar ~
20284 \SpecialChar ~
20285 \SpecialChar ~
20286 \SpecialChar ~
20287 \SpecialChar ~
20288 \SpecialChar ~
20289 \SpecialChar ~
20290 \SpecialChar ~
20291 \SpecialChar ~
20292 \SpecialChar ~
20293 \SpecialChar ~
20294 \SpecialChar ~
20295 \SpecialChar ~
20296 buffer point 
20297 \newline 
20298 ;;\SpecialChar ~
20299 x\SpecialChar ~
20300 \SpecialChar ~
20301 \SpecialChar ~
20302 \SpecialChar ~
20303 \SpecialChar ~
20304 \SpecialChar ~
20305 \SpecialChar ~
20306 \SpecialChar ~
20307 \SpecialChar ~
20308 \SpecialChar ~
20309 \SpecialChar ~
20310 \SpecialChar ~
20311 \SpecialChar ~
20312 \SpecialChar ~
20313 \SpecialChar ~
20314 sdcdbsrc-delete\SpecialChar ~
20315 \SpecialChar ~
20316 \SpecialChar ~
20317 \SpecialChar ~
20318 \SpecialChar ~
20319 \SpecialChar ~
20320 \SpecialChar ~
20321 \SpecialChar ~
20322 \SpecialChar ~
20323 \SpecialChar ~
20324 \SpecialChar ~
20325 \SpecialChar ~
20326 \SpecialChar ~
20327 \SpecialChar ~
20328 SDCDB Delete all breakpoints if no arg 
20329 \newline 
20330 ;;\SpecialChar ~
20331 \SpecialChar ~
20332 \SpecialChar ~
20333 \SpecialChar ~
20334 \SpecialChar ~
20335 \SpecialChar ~
20336 \SpecialChar ~
20337 \SpecialChar ~
20338 \SpecialChar ~
20339 \SpecialChar ~
20340 \SpecialChar ~
20341 \SpecialChar ~
20342 \SpecialChar ~
20343 \SpecialChar ~
20344 \SpecialChar ~
20345 \SpecialChar ~
20346 \SpecialChar ~
20347 \SpecialChar ~
20348 \SpecialChar ~
20349 \SpecialChar ~
20350 \SpecialChar ~
20351 \SpecialChar ~
20352 \SpecialChar ~
20353 \SpecialChar ~
20354 \SpecialChar ~
20355 \SpecialChar ~
20356 \SpecialChar ~
20357 \SpecialChar ~
20358 \SpecialChar ~
20359 \SpecialChar ~
20360 \SpecialChar ~
20361 \SpecialChar ~
20362 \SpecialChar ~
20363 \SpecialChar ~
20364 \SpecialChar ~
20365 \SpecialChar ~
20366 \SpecialChar ~
20367 \SpecialChar ~
20368 \SpecialChar ~
20369 \SpecialChar ~
20370 \SpecialChar ~
20371 \SpecialChar ~
20372 \SpecialChar ~
20373 \SpecialChar ~
20374 \SpecialChar ~
20375 \SpecialChar ~
20376 \SpecialChar ~
20377 given or delete arg (C-u arg x) 
20378 \newline 
20379 ;;\SpecialChar ~
20380 m\SpecialChar ~
20381 \SpecialChar ~
20382 \SpecialChar ~
20383 \SpecialChar ~
20384 \SpecialChar ~
20385 \SpecialChar ~
20386 \SpecialChar ~
20387 \SpecialChar ~
20388 \SpecialChar ~
20389 \SpecialChar ~
20390 \SpecialChar ~
20391 \SpecialChar ~
20392 \SpecialChar ~
20393 \SpecialChar ~
20394 \SpecialChar ~
20395 sdcdbsrc-frame\SpecialChar ~
20396 \SpecialChar ~
20397 \SpecialChar ~
20398 \SpecialChar ~
20399 \SpecialChar ~
20400 \SpecialChar ~
20401 \SpecialChar ~
20402 \SpecialChar ~
20403 \SpecialChar ~
20404 \SpecialChar ~
20405 \SpecialChar ~
20406 \SpecialChar ~
20407 \SpecialChar ~
20408 \SpecialChar ~
20409 \SpecialChar ~
20410 SDCDB Display current frame if no arg, 
20411 \newline 
20412 ;;\SpecialChar ~
20413 \SpecialChar ~
20414 \SpecialChar ~
20415 \SpecialChar ~
20416 \SpecialChar ~
20417 \SpecialChar ~
20418 \SpecialChar ~
20419 \SpecialChar ~
20420 \SpecialChar ~
20421 \SpecialChar ~
20422 \SpecialChar ~
20423 \SpecialChar ~
20424 \SpecialChar ~
20425 \SpecialChar ~
20426 \SpecialChar ~
20427 \SpecialChar ~
20428 \SpecialChar ~
20429 \SpecialChar ~
20430 \SpecialChar ~
20431 \SpecialChar ~
20432 \SpecialChar ~
20433 \SpecialChar ~
20434 \SpecialChar ~
20435 \SpecialChar ~
20436 \SpecialChar ~
20437 \SpecialChar ~
20438 \SpecialChar ~
20439 \SpecialChar ~
20440 \SpecialChar ~
20441 \SpecialChar ~
20442 \SpecialChar ~
20443 \SpecialChar ~
20444 \SpecialChar ~
20445 \SpecialChar ~
20446 \SpecialChar ~
20447 \SpecialChar ~
20448 \SpecialChar ~
20449 \SpecialChar ~
20450 \SpecialChar ~
20451 \SpecialChar ~
20452 \SpecialChar ~
20453 \SpecialChar ~
20454 \SpecialChar ~
20455 \SpecialChar ~
20456 \SpecialChar ~
20457 \SpecialChar ~
20458 \SpecialChar ~
20459 given or display frame arg 
20460 \newline 
20461 ;;\SpecialChar ~
20462 \SpecialChar ~
20463 \SpecialChar ~
20464 \SpecialChar ~
20465 \SpecialChar ~
20466 \SpecialChar ~
20467 \SpecialChar ~
20468 \SpecialChar ~
20469 \SpecialChar ~
20470 \SpecialChar ~
20471 \SpecialChar ~
20472 \SpecialChar ~
20473 \SpecialChar ~
20474 \SpecialChar ~
20475 \SpecialChar ~
20476 \SpecialChar ~
20477 \SpecialChar ~
20478 \SpecialChar ~
20479 \SpecialChar ~
20480 \SpecialChar ~
20481 \SpecialChar ~
20482 \SpecialChar ~
20483 \SpecialChar ~
20484 \SpecialChar ~
20485 \SpecialChar ~
20486 \SpecialChar ~
20487 \SpecialChar ~
20488 \SpecialChar ~
20489 \SpecialChar ~
20490 \SpecialChar ~
20491 \SpecialChar ~
20492 \SpecialChar ~
20493 \SpecialChar ~
20494 \SpecialChar ~
20495 \SpecialChar ~
20496 \SpecialChar ~
20497 \SpecialChar ~
20498 \SpecialChar ~
20499 \SpecialChar ~
20500 \SpecialChar ~
20501 \SpecialChar ~
20502 \SpecialChar ~
20503 \SpecialChar ~
20504 \SpecialChar ~
20505 \SpecialChar ~
20506 \SpecialChar ~
20507 \SpecialChar ~
20508 buffer point 
20509 \newline 
20510 ;;\SpecialChar ~
20511 !\SpecialChar ~
20512 \SpecialChar ~
20513 \SpecialChar ~
20514 \SpecialChar ~
20515 \SpecialChar ~
20516 \SpecialChar ~
20517 \SpecialChar ~
20518 \SpecialChar ~
20519 \SpecialChar ~
20520 \SpecialChar ~
20521 \SpecialChar ~
20522 \SpecialChar ~
20523 \SpecialChar ~
20524 \SpecialChar ~
20525 \SpecialChar ~
20526 sdcdbsrc-goto-sdcdb\SpecialChar ~
20527 \SpecialChar ~
20528 \SpecialChar ~
20529 \SpecialChar ~
20530 \SpecialChar ~
20531 \SpecialChar ~
20532 \SpecialChar ~
20533 \SpecialChar ~
20534 \SpecialChar ~
20535 \SpecialChar ~
20536 Goto the SDCDB output buffer 
20537 \newline 
20538 ;;\SpecialChar ~
20539 p\SpecialChar ~
20540 \SpecialChar ~
20541 \SpecialChar ~
20542 \SpecialChar ~
20543 \SpecialChar ~
20544 \SpecialChar ~
20545 \SpecialChar ~
20546 \SpecialChar ~
20547 \SpecialChar ~
20548 \SpecialChar ~
20549 \SpecialChar ~
20550 \SpecialChar ~
20551 \SpecialChar ~
20552 \SpecialChar ~
20553 \SpecialChar ~
20554 sdcdb-print-c-sexp\SpecialChar ~
20555 \SpecialChar ~
20556 \SpecialChar ~
20557 \SpecialChar ~
20558 \SpecialChar ~
20559 \SpecialChar ~
20560 \SpecialChar ~
20561 \SpecialChar ~
20562 \SpecialChar ~
20563 \SpecialChar ~
20564 \SpecialChar ~
20565 SDCDB print command for data at 
20566 \newline 
20567 ;;\SpecialChar ~
20568 \SpecialChar ~
20569 \SpecialChar ~
20570 \SpecialChar ~
20571 \SpecialChar ~
20572 \SpecialChar ~
20573 \SpecialChar ~
20574 \SpecialChar ~
20575 \SpecialChar ~
20576 \SpecialChar ~
20577 \SpecialChar ~
20578 \SpecialChar ~
20579 \SpecialChar ~
20580 \SpecialChar ~
20581 \SpecialChar ~
20582 \SpecialChar ~
20583 \SpecialChar ~
20584 \SpecialChar ~
20585 \SpecialChar ~
20586 \SpecialChar ~
20587 \SpecialChar ~
20588 \SpecialChar ~
20589 \SpecialChar ~
20590 \SpecialChar ~
20591 \SpecialChar ~
20592 \SpecialChar ~
20593 \SpecialChar ~
20594 \SpecialChar ~
20595 \SpecialChar ~
20596 \SpecialChar ~
20597 \SpecialChar ~
20598 \SpecialChar ~
20599 \SpecialChar ~
20600 \SpecialChar ~
20601 \SpecialChar ~
20602 \SpecialChar ~
20603 \SpecialChar ~
20604 \SpecialChar ~
20605 \SpecialChar ~
20606 \SpecialChar ~
20607 \SpecialChar ~
20608 \SpecialChar ~
20609 \SpecialChar ~
20610 \SpecialChar ~
20611 \SpecialChar ~
20612 \SpecialChar ~
20613 \SpecialChar ~
20614 buffer point 
20615 \newline 
20616 ;;\SpecialChar ~
20617 g\SpecialChar ~
20618 \SpecialChar ~
20619 \SpecialChar ~
20620 \SpecialChar ~
20621 \SpecialChar ~
20622 \SpecialChar ~
20623 \SpecialChar ~
20624 \SpecialChar ~
20625 \SpecialChar ~
20626 \SpecialChar ~
20627 \SpecialChar ~
20628 \SpecialChar ~
20629 \SpecialChar ~
20630 \SpecialChar ~
20631 \SpecialChar ~
20632 sdcdbsrc-goto-sdcdb\SpecialChar ~
20633 \SpecialChar ~
20634 \SpecialChar ~
20635 \SpecialChar ~
20636 \SpecialChar ~
20637 \SpecialChar ~
20638 \SpecialChar ~
20639 \SpecialChar ~
20640 \SpecialChar ~
20641 \SpecialChar ~
20642 Goto the SDCDB output buffer 
20643 \newline 
20644 ;;\SpecialChar ~
20645 t\SpecialChar ~
20646 \SpecialChar ~
20647 \SpecialChar ~
20648 \SpecialChar ~
20649 \SpecialChar ~
20650 \SpecialChar ~
20651 \SpecialChar ~
20652 \SpecialChar ~
20653 \SpecialChar ~
20654 \SpecialChar ~
20655 \SpecialChar ~
20656 \SpecialChar ~
20657 \SpecialChar ~
20658 \SpecialChar ~
20659 \SpecialChar ~
20660 sdcdbsrc-mode\SpecialChar ~
20661 \SpecialChar ~
20662 \SpecialChar ~
20663 \SpecialChar ~
20664 \SpecialChar ~
20665 \SpecialChar ~
20666 \SpecialChar ~
20667 \SpecialChar ~
20668 \SpecialChar ~
20669 \SpecialChar ~
20670 \SpecialChar ~
20671 \SpecialChar ~
20672 \SpecialChar ~
20673 \SpecialChar ~
20674 \SpecialChar ~
20675 \SpecialChar ~
20676 Toggles Sdcdbsrc mode (turns it off) 
20677 \newline 
20678 ;; 
20679 \newline 
20680 ;;\SpecialChar ~
20681 C-c\SpecialChar ~
20682 C-f\SpecialChar ~
20683 \SpecialChar ~
20684 \SpecialChar ~
20685 \SpecialChar ~
20686 \SpecialChar ~
20687 \SpecialChar ~
20688 \SpecialChar ~
20689 \SpecialChar ~
20690 \SpecialChar ~
20691 sdcdb-finish-from-src\SpecialChar ~
20692 \SpecialChar ~
20693 \SpecialChar ~
20694 \SpecialChar ~
20695 \SpecialChar ~
20696 \SpecialChar ~
20697 \SpecialChar ~
20698 \SpecialChar ~
20699 SDCDB finish command 
20700 \newline 
20701 ;; 
20702 \newline 
20703 ;;\SpecialChar ~
20704 C-x\SpecialChar ~
20705 SPC\SpecialChar ~
20706 \SpecialChar ~
20707 \SpecialChar ~
20708 \SpecialChar ~
20709 \SpecialChar ~
20710 \SpecialChar ~
20711 \SpecialChar ~
20712 \SpecialChar ~
20713 \SpecialChar ~
20714 sdcdb-break\SpecialChar ~
20715 \SpecialChar ~
20716 \SpecialChar ~
20717 \SpecialChar ~
20718 \SpecialChar ~
20719 \SpecialChar ~
20720 \SpecialChar ~
20721 \SpecialChar ~
20722 \SpecialChar ~
20723 \SpecialChar ~
20724 \SpecialChar ~
20725 \SpecialChar ~
20726 \SpecialChar ~
20727 \SpecialChar ~
20728 \SpecialChar ~
20729 \SpecialChar ~
20730 \SpecialChar ~
20731 \SpecialChar ~
20732 Set break for line with point 
20733 \newline 
20734 ;;\SpecialChar ~
20735 ESC\SpecialChar ~
20736 t\SpecialChar ~
20737 \SpecialChar ~
20738 \SpecialChar ~
20739 \SpecialChar ~
20740 \SpecialChar ~
20741 \SpecialChar ~
20742 \SpecialChar ~
20743 \SpecialChar ~
20744 \SpecialChar ~
20745 \SpecialChar ~
20746 \SpecialChar ~
20747 sdcdbsrc-mode\SpecialChar ~
20748 \SpecialChar ~
20749 \SpecialChar ~
20750 \SpecialChar ~
20751 \SpecialChar ~
20752 \SpecialChar ~
20753 \SpecialChar ~
20754 \SpecialChar ~
20755 \SpecialChar ~
20756 \SpecialChar ~
20757 \SpecialChar ~
20758 \SpecialChar ~
20759 \SpecialChar ~
20760 \SpecialChar ~
20761 \SpecialChar ~
20762 \SpecialChar ~
20763 Toggle Sdcdbsrc mode 
20764 \newline 
20765 ;;\SpecialChar ~
20766 ESC\SpecialChar ~
20767 m\SpecialChar ~
20768 \SpecialChar ~
20769 \SpecialChar ~
20770 \SpecialChar ~
20771 \SpecialChar ~
20772 \SpecialChar ~
20773 \SpecialChar ~
20774 \SpecialChar ~
20775 \SpecialChar ~
20776 \SpecialChar ~
20777 \SpecialChar ~
20778 sdcdbsrc-srcmode\SpecialChar ~
20779 \SpecialChar ~
20780 \SpecialChar ~
20781 \SpecialChar ~
20782 \SpecialChar ~
20783 \SpecialChar ~
20784 \SpecialChar ~
20785 \SpecialChar ~
20786 \SpecialChar ~
20787 \SpecialChar ~
20788 \SpecialChar ~
20789 \SpecialChar ~
20790 \SpecialChar ~
20791 Toggle list mode 
20792 \newline 
20793 ;; 
20794 \newline 
20795
20796 \layout Chapter
20797 \pagebreak_top 
20798 TIPS
20799 \layout Standard
20800
20801 Here are a few guidelines that will help the compiler generate more efficient
20802  code, some of the tips are specific to this compiler others are generally
20803  good programming practice.
20804 \layout Itemize
20805
20806 Use the smallest data type to represent your data-value.
20807  If it is known in advance that the value is going to be less than 256 then
20808  use an 'unsigned char' instead of a 'short' or 'int'.
20809  Please note, that ANSI C requires both signed and unsigned chars to be
20810  promoted to 'signed int' before doing any operation.
20811  This promotion
20812 \begin_inset LatexCommand \index{type promotion}
20813
20814 \end_inset 
20815
20816  can be omitted, if the result is the same.
20817  The effect of the promotion rules together with the sign-extension is often
20818  surprising:
20819 \begin_deeper 
20820 \layout Verse
20821
20822
20823 \family typewriter 
20824 unsigned char uc = 0xfe;
20825 \newline 
20826 if (uc * uc < 0) /* this is true! */
20827 \newline 
20828 {
20829 \newline 
20830 \SpecialChar ~
20831 \SpecialChar ~
20832 \SpecialChar ~
20833 \SpecialChar ~
20834 ....
20835 \newline 
20836 }
20837 \layout Standard
20838
20839
20840 \family typewriter 
20841 uc * uc
20842 \family default 
20843  is evaluated as 
20844 \family typewriter 
20845 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
20846 \family default 
20847 .
20848  
20849 \newline 
20850 Another one:
20851 \layout Verse
20852
20853
20854 \family typewriter 
20855 (unsigned char) -12 / (signed char) -3 = ...
20856 \layout Standard
20857
20858 No, the result is not 4:
20859 \layout Verse
20860
20861
20862 \family typewriter 
20863 (int) (unsigned char) -12 / (int) (signed char) -3 =
20864 \newline 
20865 (int) (unsigned char) 0xf4 / (int) (signed char) 0xfd =
20866 \newline 
20867 (int) 0x00f4 / (int) 0xfffd =
20868 \newline 
20869 (int) 0x00f4 / (int) 0xfffd =
20870 \newline 
20871 (int) 244 / (int) -3 =
20872 \newline 
20873 (int) -81 = (int) 0xffaf;
20874 \layout Standard
20875
20876 Don't complain, that gcc gives you a different result.
20877  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
20878  Therefore the results are different.
20879 \newline 
20880 From 
20881 \begin_inset Quotes sld
20882 \end_inset 
20883
20884 comp.lang.c FAQ
20885 \begin_inset Quotes srd
20886 \end_inset 
20887
20888 :
20889 \layout Quote
20890
20891 If well-defined overflow characteristics are important and negative values
20892  are not, or if you want to steer clear of sign-extension problems when
20893  manipulating bits or bytes, use one of the corresponding unsigned types.
20894  (Beware when mixing signed and unsigned values in expressions, though.)
20895 \newline 
20896 Although character types (especially unsigned char) can be used as "tiny"
20897  integers, doing so is sometimes more trouble than it's worth, due to unpredicta
20898 ble sign extension and increased code size.
20899 \end_deeper 
20900 \layout Itemize
20901
20902 Use unsigned when it is known in advance that the value is not going to
20903  be negative.
20904  This helps especially if you are doing division or multiplication, bit-shifting
20905  or are using an array index.
20906 \layout Itemize
20907
20908 NEVER jump into a LOOP.
20909 \layout Itemize
20910
20911 Declare the variables to be local
20912 \begin_inset LatexCommand \index{local variables}
20913
20914 \end_inset 
20915
20916  whenever possible, especially loop control variables (induction).
20917 \layout Itemize
20918
20919 Since the compiler does not always do implicit integral promotion, the programme
20920 r should do an explicit cast when integral promotion is required.
20921 \layout Itemize
20922
20923 Reducing the size of division, multiplication & modulus operations can reduce
20924  code size substantially.
20925  Take the following code for example.
20926 \begin_deeper 
20927 \layout Verse
20928
20929
20930 \family typewriter 
20931 foobar(unsigned int p1, unsigned char ch)
20932 \newline 
20933 {
20934 \newline 
20935 \SpecialChar ~
20936 \SpecialChar ~
20937 \SpecialChar ~
20938 \SpecialChar ~
20939 unsigned char ch1 = p1 % ch ;
20940 \newline 
20941 \SpecialChar ~
20942 \SpecialChar ~
20943 \SpecialChar ~
20944 \SpecialChar ~
20945 ....
20946 \newline 
20947 }
20948 \layout Standard
20949
20950 For the modulus operation the variable ch will be promoted to unsigned int
20951  first then the modulus operation will be performed (this will lead to a
20952  call to support routine _moduint()), and the result will be casted to a
20953  char.
20954  If the code is changed to 
20955 \layout Verse
20956
20957
20958 \family typewriter 
20959 foobar(unsigned int p1, unsigned char ch)
20960 \newline 
20961 {
20962 \newline 
20963 \SpecialChar ~
20964 \SpecialChar ~
20965 \SpecialChar ~
20966 \SpecialChar ~
20967 unsigned char ch1 = (unsigned char)p1 % ch ;
20968 \newline 
20969 \SpecialChar ~
20970 \SpecialChar ~
20971 \SpecialChar ~
20972 \SpecialChar ~
20973 ....
20974 \newline 
20975 }
20976 \layout Standard
20977
20978 It would substantially reduce the code generated (future versions of the
20979  compiler will be smart enough to detect such optimization opportunities).
20980 \end_deeper 
20981 \layout Itemize
20982
20983 Have a look at the assembly listing to get a 
20984 \begin_inset Quotes sld
20985 \end_inset 
20986
20987 feeling
20988 \begin_inset Quotes srd
20989 \end_inset 
20990
20991  for the code generation.
20992 \layout Section
20993
20994 Tools
20995 \begin_inset LatexCommand \index{Tools}
20996
20997 \end_inset 
20998
20999  included in the distribution
21000 \layout Standard
21001 \align center 
21002
21003 \begin_inset  Tabular
21004 <lyxtabular version="3" rows="12" columns="3">
21005 <features>
21006 <column alignment="center" valignment="top" leftline="true" width="0pt">
21007 <column alignment="center" valignment="top" leftline="true" width="0pt">
21008 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
21009 <row topline="true" bottomline="true">
21010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21011 \begin_inset Text
21012
21013 \layout Standard
21014
21015 Name
21016 \end_inset 
21017 </cell>
21018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21019 \begin_inset Text
21020
21021 \layout Standard
21022
21023 Purpose
21024 \end_inset 
21025 </cell>
21026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21027 \begin_inset Text
21028
21029 \layout Standard
21030
21031 Directory
21032 \end_inset 
21033 </cell>
21034 </row>
21035 <row topline="true">
21036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21037 \begin_inset Text
21038
21039 \layout Standard
21040
21041 uCsim
21042 \end_inset 
21043 </cell>
21044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21045 \begin_inset Text
21046
21047 \layout Standard
21048
21049 Simulator for various architectures
21050 \end_inset 
21051 </cell>
21052 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21053 \begin_inset Text
21054
21055 \layout Standard
21056
21057 sdcc/sim/ucsim
21058 \end_inset 
21059 </cell>
21060 </row>
21061 <row topline="true">
21062 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21063 \begin_inset Text
21064
21065 \layout Standard
21066
21067 keil2sdcc.pl
21068 \end_inset 
21069 </cell>
21070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21071 \begin_inset Text
21072
21073 \layout Standard
21074
21075 header file conversion
21076 \end_inset 
21077 </cell>
21078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21079 \begin_inset Text
21080
21081 \layout Standard
21082
21083 sdcc/support/scripts
21084 \end_inset 
21085 </cell>
21086 </row>
21087 <row topline="true">
21088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21089 \begin_inset Text
21090
21091 \layout Standard
21092
21093 mh2h.c
21094 \end_inset 
21095 </cell>
21096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21097 \begin_inset Text
21098
21099 \layout Standard
21100
21101 header file conversion
21102 \end_inset 
21103 </cell>
21104 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21105 \begin_inset Text
21106
21107 \layout Standard
21108
21109 sdcc/support/scripts
21110 \end_inset 
21111 </cell>
21112 </row>
21113 <row topline="true">
21114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21115 \begin_inset Text
21116
21117 \layout Standard
21118
21119 as-gbz80
21120 \end_inset 
21121 </cell>
21122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21123 \begin_inset Text
21124
21125 \layout Standard
21126
21127 Assembler
21128 \end_inset 
21129 </cell>
21130 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21131 \begin_inset Text
21132
21133 \layout Standard
21134
21135
21136 \family roman 
21137 \series medium 
21138 \shape up 
21139 \size normal 
21140 \emph off 
21141 \bar no 
21142 \noun off 
21143 \color none
21144 sdcc/bin
21145 \end_inset 
21146 </cell>
21147 </row>
21148 <row topline="true">
21149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21150 \begin_inset Text
21151
21152 \layout Standard
21153
21154 as-z80
21155 \end_inset 
21156 </cell>
21157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21158 \begin_inset Text
21159
21160 \layout Standard
21161
21162 Assembler
21163 \end_inset 
21164 </cell>
21165 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21166 \begin_inset Text
21167
21168 \layout Standard
21169
21170
21171 \family roman 
21172 \series medium 
21173 \shape up 
21174 \size normal 
21175 \emph off 
21176 \bar no 
21177 \noun off 
21178 \color none
21179 sdcc/bin
21180 \end_inset 
21181 </cell>
21182 </row>
21183 <row topline="true">
21184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21185 \begin_inset Text
21186
21187 \layout Standard
21188
21189 asx8051
21190 \end_inset 
21191 </cell>
21192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21193 \begin_inset Text
21194
21195 \layout Standard
21196
21197 Assembler
21198 \end_inset 
21199 </cell>
21200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21201 \begin_inset Text
21202
21203 \layout Standard
21204
21205
21206 \family roman 
21207 \series medium 
21208 \shape up 
21209 \size normal 
21210 \emph off 
21211 \bar no 
21212 \noun off 
21213 \color none
21214 sdcc/bin
21215 \end_inset 
21216 </cell>
21217 </row>
21218 <row topline="true">
21219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21220 \begin_inset Text
21221
21222 \layout Standard
21223
21224 sdcdb
21225 \end_inset 
21226 </cell>
21227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21228 \begin_inset Text
21229
21230 \layout Standard
21231
21232 Simulator
21233 \end_inset 
21234 </cell>
21235 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21236 \begin_inset Text
21237
21238 \layout Standard
21239
21240
21241 \family roman 
21242 \series medium 
21243 \shape up 
21244 \size normal 
21245 \emph off 
21246 \bar no 
21247 \noun off 
21248 \color none
21249 sdcc/bin
21250 \end_inset 
21251 </cell>
21252 </row>
21253 <row topline="true">
21254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21255 \begin_inset Text
21256
21257 \layout Standard
21258
21259 aslink
21260 \end_inset 
21261 </cell>
21262 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21263 \begin_inset Text
21264
21265 \layout Standard
21266
21267 Linker
21268 \end_inset 
21269 </cell>
21270 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21271 \begin_inset Text
21272
21273 \layout Standard
21274
21275
21276 \family roman 
21277 \series medium 
21278 \shape up 
21279 \size normal 
21280 \emph off 
21281 \bar no 
21282 \noun off 
21283 \color none
21284 sdcc/bin
21285 \end_inset 
21286 </cell>
21287 </row>
21288 <row topline="true">
21289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21290 \begin_inset Text
21291
21292 \layout Standard
21293
21294 link-z80
21295 \end_inset 
21296 </cell>
21297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21298 \begin_inset Text
21299
21300 \layout Standard
21301
21302 Linker
21303 \end_inset 
21304 </cell>
21305 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21306 \begin_inset Text
21307
21308 \layout Standard
21309
21310
21311 \family roman 
21312 \series medium 
21313 \shape up 
21314 \size normal 
21315 \emph off 
21316 \bar no 
21317 \noun off 
21318 \color none
21319 sdcc/bin
21320 \end_inset 
21321 </cell>
21322 </row>
21323 <row topline="true">
21324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21325 \begin_inset Text
21326
21327 \layout Standard
21328
21329 link-gbz80
21330 \end_inset 
21331 </cell>
21332 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21333 \begin_inset Text
21334
21335 \layout Standard
21336
21337 Linker
21338 \end_inset 
21339 </cell>
21340 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21341 \begin_inset Text
21342
21343 \layout Standard
21344
21345
21346 \family roman 
21347 \series medium 
21348 \shape up 
21349 \size normal 
21350 \emph off 
21351 \bar no 
21352 \noun off 
21353 \color none
21354 sdcc/bin
21355 \end_inset 
21356 </cell>
21357 </row>
21358 <row topline="true" bottomline="true">
21359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21360 \begin_inset Text
21361
21362 \layout Standard
21363
21364 packihx
21365 \end_inset 
21366 </cell>
21367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21368 \begin_inset Text
21369
21370 \layout Standard
21371
21372 ihx packer
21373 \end_inset 
21374 </cell>
21375 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21376 \begin_inset Text
21377
21378 \layout Standard
21379
21380
21381 \family roman 
21382 \series medium 
21383 \shape up 
21384 \size normal 
21385 \emph off 
21386 \bar no 
21387 \noun off 
21388 \color none
21389 sdcc/bin
21390 \end_inset 
21391 </cell>
21392 </row>
21393 </lyxtabular>
21394
21395 \end_inset 
21396
21397
21398 \newline 
21399
21400 \layout Section
21401
21402 Documentation
21403 \begin_inset LatexCommand \index{Documentation}
21404
21405 \end_inset 
21406
21407  included in the distribution
21408 \layout Standard
21409 \align center 
21410
21411 \begin_inset  Tabular
21412 <lyxtabular version="3" rows="10" columns="2">
21413 <features>
21414 <column alignment="left" valignment="top" leftline="true" width="0">
21415 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
21416 <row topline="true" bottomline="true">
21417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21418 \begin_inset Text
21419
21420 \layout Standard
21421
21422 Subject / Title
21423 \end_inset 
21424 </cell>
21425 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21426 \begin_inset Text
21427
21428 \layout Standard
21429
21430 Where to get / filename
21431 \end_inset 
21432 </cell>
21433 </row>
21434 <row topline="true">
21435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21436 \begin_inset Text
21437
21438 \layout Standard
21439
21440 SDCC Compiler User Guide
21441 \end_inset 
21442 </cell>
21443 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21444 \begin_inset Text
21445
21446 \layout Standard
21447
21448 You're reading it right now
21449 \end_inset 
21450 </cell>
21451 </row>
21452 <row topline="true">
21453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21454 \begin_inset Text
21455
21456 \layout Standard
21457
21458 Changelog of SDCC
21459 \end_inset 
21460 </cell>
21461 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21462 \begin_inset Text
21463
21464 \layout Standard
21465
21466 sdcc/Changelog
21467 \end_inset 
21468 </cell>
21469 </row>
21470 <row topline="true">
21471 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21472 \begin_inset Text
21473
21474 \layout Standard
21475
21476 ASXXXX
21477 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
21478
21479 \end_inset 
21480
21481
21482 \begin_inset LatexCommand \index{Assembler documentation}
21483
21484 \end_inset 
21485
21486  Assemblers and ASLINK
21487 \begin_inset LatexCommand \index{aslink}
21488
21489 \end_inset 
21490
21491
21492 \begin_inset LatexCommand \index{Linker documentation}
21493
21494 \end_inset 
21495
21496  Relocating Linker
21497 \end_inset 
21498 </cell>
21499 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21500 \begin_inset Text
21501
21502 \layout Standard
21503
21504 sdcc/as/doc/asxhtm.html
21505 \end_inset 
21506 </cell>
21507 </row>
21508 <row topline="true">
21509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21510 \begin_inset Text
21511
21512 \layout Standard
21513
21514 SDCC regression test
21515 \begin_inset LatexCommand \index{Regression test}
21516
21517 \end_inset 
21518
21519
21520 \end_inset 
21521 </cell>
21522 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21523 \begin_inset Text
21524
21525 \layout Standard
21526
21527 sdcc/doc/test_suite_spec.pdf
21528 \end_inset 
21529 </cell>
21530 </row>
21531 <row topline="true">
21532 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21533 \begin_inset Text
21534
21535 \layout Standard
21536
21537 Various notes
21538 \end_inset 
21539 </cell>
21540 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21541 \begin_inset Text
21542
21543 \layout Standard
21544
21545 sdcc/doc/*
21546 \end_inset 
21547 </cell>
21548 </row>
21549 <row topline="true">
21550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21551 \begin_inset Text
21552
21553 \layout Standard
21554
21555 Notes on debugging with sdcdb
21556 \begin_inset LatexCommand \index{sdcdb (debugger)}
21557
21558 \end_inset 
21559
21560
21561 \end_inset 
21562 </cell>
21563 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21564 \begin_inset Text
21565
21566 \layout Standard
21567
21568 sdcc/debugger/README
21569 \end_inset 
21570 </cell>
21571 </row>
21572 <row topline="true">
21573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21574 \begin_inset Text
21575
21576 \layout Standard
21577
21578 Software simulator for microcontrollers
21579 \end_inset 
21580 </cell>
21581 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21582 \begin_inset Text
21583
21584 \layout Standard
21585
21586
21587 \family roman 
21588 \series medium 
21589 \shape up 
21590 \size normal 
21591 \emph off 
21592 \bar no 
21593 \noun off 
21594 \color none
21595 sdcc/sim/ucsim/doc
21596 \family default 
21597 \series default 
21598 \shape default 
21599 \size default 
21600 \emph default 
21601 \bar default 
21602 \noun default 
21603 \color default
21604 /index.html
21605 \end_inset 
21606 </cell>
21607 </row>
21608 <row topline="true">
21609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21610 \begin_inset Text
21611
21612 \layout Standard
21613
21614 Temporary notes on the pic16
21615 \begin_inset LatexCommand \index{PIC16}
21616
21617 \end_inset 
21618
21619  port
21620 \end_inset 
21621 </cell>
21622 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21623 \begin_inset Text
21624
21625 \layout Standard
21626
21627 sdcc/src/pic16/NOTES
21628 \end_inset 
21629 </cell>
21630 </row>
21631 <row topline="true" bottomline="true">
21632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21633 \begin_inset Text
21634
21635 \layout Standard
21636
21637 SDCC internal documentation (debugging file format)
21638 \end_inset 
21639 </cell>
21640 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21641 \begin_inset Text
21642
21643 \layout Standard
21644
21645 sdcc/doc/
21646 \family roman 
21647 \series medium 
21648 \shape up 
21649 \size normal 
21650 \emph off 
21651 \bar no 
21652 \noun off 
21653 \color none
21654 cdbfileformat.pd
21655 \family default 
21656 \series default 
21657 \shape default 
21658 \size default 
21659 \emph default 
21660 \bar default 
21661 \noun default 
21662 \color default
21663 f
21664 \end_inset 
21665 </cell>
21666 </row>
21667 </lyxtabular>
21668
21669 \end_inset 
21670
21671
21672 \newline 
21673
21674 \layout Section
21675
21676 Related open source tools
21677 \begin_inset LatexCommand \index{Related tools}
21678
21679 \end_inset 
21680
21681
21682 \layout Standard
21683 \align center 
21684
21685 \begin_inset  Tabular
21686 <lyxtabular version="3" rows="11" columns="3">
21687 <features>
21688 <column alignment="center" valignment="top" leftline="true" width="0pt">
21689 <column alignment="block" valignment="top" leftline="true" width="30line%">
21690 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
21691 <row topline="true" bottomline="true">
21692 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21693 \begin_inset Text
21694
21695 \layout Standard
21696
21697 Name
21698 \end_inset 
21699 </cell>
21700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21701 \begin_inset Text
21702
21703 \layout Standard
21704
21705 Purpose
21706 \end_inset 
21707 </cell>
21708 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21709 \begin_inset Text
21710
21711 \layout Standard
21712
21713 Where to get
21714 \end_inset 
21715 </cell>
21716 </row>
21717 <row topline="true">
21718 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21719 \begin_inset Text
21720
21721 \layout Standard
21722
21723 gpsim
21724 \begin_inset LatexCommand \index{gpsim (pic simulator)}
21725
21726 \end_inset 
21727
21728
21729 \end_inset 
21730 </cell>
21731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21732 \begin_inset Text
21733
21734 \layout Standard
21735
21736 PIC simulator
21737 \end_inset 
21738 </cell>
21739 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21740 \begin_inset Text
21741
21742 \layout Standard
21743
21744
21745 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
21746
21747 \end_inset 
21748
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 \layout Standard
21758
21759 gputils
21760 \begin_inset LatexCommand \index{gputils (pic tools)}
21761
21762 \end_inset 
21763
21764
21765 \end_inset 
21766 </cell>
21767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21768 \begin_inset Text
21769
21770 \layout Standard
21771
21772 GNU PIC utilities
21773 \end_inset 
21774 </cell>
21775 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21776 \begin_inset Text
21777
21778 \layout Standard
21779
21780
21781 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
21782
21783 \end_inset 
21784
21785
21786 \end_inset 
21787 </cell>
21788 </row>
21789 <row topline="true">
21790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21791 \begin_inset Text
21792
21793 \layout Standard
21794
21795 flP5
21796 \end_inset 
21797 </cell>
21798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21799 \begin_inset Text
21800
21801 \layout Standard
21802
21803 PIC programmer
21804 \end_inset 
21805 </cell>
21806 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21807 \begin_inset Text
21808
21809 \layout Standard
21810
21811
21812 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
21813
21814 \end_inset 
21815
21816
21817 \end_inset 
21818 </cell>
21819 </row>
21820 <row topline="true">
21821 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21822 \begin_inset Text
21823
21824 \layout Standard
21825
21826 indent
21827 \begin_inset LatexCommand \index{indent (source formatting tool)}
21828
21829 \end_inset 
21830
21831
21832 \end_inset 
21833 </cell>
21834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21835 \begin_inset Text
21836
21837 \layout Standard
21838
21839 Formats C source - Master of the white spaces
21840 \end_inset 
21841 </cell>
21842 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21843 \begin_inset Text
21844
21845 \layout Standard
21846
21847
21848 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
21849
21850 \end_inset 
21851
21852
21853 \end_inset 
21854 </cell>
21855 </row>
21856 <row topline="true">
21857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21858 \begin_inset Text
21859
21860 \layout Standard
21861
21862 srecord
21863 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
21864
21865 \end_inset 
21866
21867
21868 \end_inset 
21869 </cell>
21870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21871 \begin_inset Text
21872
21873 \layout Standard
21874
21875 Object file conversion, checksumming, ...
21876 \end_inset 
21877 </cell>
21878 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21879 \begin_inset Text
21880
21881 \layout Standard
21882
21883
21884 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
21885
21886 \end_inset 
21887
21888
21889 \end_inset 
21890 </cell>
21891 </row>
21892 <row topline="true">
21893 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21894 \begin_inset Text
21895
21896 \layout Standard
21897
21898 objdump
21899 \begin_inset LatexCommand \index{objdump (tool)}
21900
21901 \end_inset 
21902
21903
21904 \end_inset 
21905 </cell>
21906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21907 \begin_inset Text
21908
21909 \layout Standard
21910
21911 Object file conversion, ...
21912 \end_inset 
21913 </cell>
21914 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21915 \begin_inset Text
21916
21917 \layout Standard
21918
21919 Part of binutils (should be there anyway)
21920 \end_inset 
21921 </cell>
21922 </row>
21923 <row topline="true">
21924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21925 \begin_inset Text
21926
21927 \layout Standard
21928
21929 doxygen
21930 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
21931
21932 \end_inset 
21933
21934
21935 \end_inset 
21936 </cell>
21937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21938 \begin_inset Text
21939
21940 \layout Standard
21941
21942 Source code documentation system
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 \layout Standard
21949
21950
21951 \begin_inset LatexCommand \url{http://www.doxygen.org}
21952
21953 \end_inset 
21954
21955
21956 \end_inset 
21957 </cell>
21958 </row>
21959 <row topline="true">
21960 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21961 \begin_inset Text
21962
21963 \layout Standard
21964
21965 kdevelop
21966 \end_inset 
21967 </cell>
21968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21969 \begin_inset Text
21970
21971 \layout Standard
21972
21973 IDE (has anyone tried integrating SDCC & sdcdb? Unix only)
21974 \end_inset 
21975 </cell>
21976 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21977 \begin_inset Text
21978
21979 \layout Standard
21980
21981
21982 \begin_inset LatexCommand \url{http://www.kdevelop.org}
21983
21984 \end_inset 
21985
21986
21987 \end_inset 
21988 </cell>
21989 </row>
21990 <row topline="true">
21991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21992 \begin_inset Text
21993
21994 \layout Standard
21995
21996 splint
21997 \begin_inset LatexCommand \index{splint (syntax checking tool)}
21998
21999 \end_inset 
22000
22001
22002 \end_inset 
22003 </cell>
22004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22005 \begin_inset Text
22006
22007 \layout Standard
22008
22009 Statically checks c sources (has anyone adapted splint for SDCC?)
22010 \end_inset 
22011 </cell>
22012 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22013 \begin_inset Text
22014
22015 \layout Standard
22016
22017
22018 \begin_inset LatexCommand \url{http://www.splint.org}
22019
22020 \end_inset 
22021
22022
22023 \end_inset 
22024 </cell>
22025 </row>
22026 <row topline="true" bottomline="true">
22027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22028 \begin_inset Text
22029
22030 \layout Standard
22031
22032 ddd
22033 \begin_inset LatexCommand \index{ddd (debugger)}
22034
22035 \end_inset 
22036
22037
22038 \end_inset 
22039 </cell>
22040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22041 \begin_inset Text
22042
22043 \layout Standard
22044
22045 Debugger, serves nicely as GUI to sdcdb
22046 \begin_inset LatexCommand \index{sdcdb (debugger)}
22047
22048 \end_inset 
22049
22050  (Unix only)
22051 \end_inset 
22052 </cell>
22053 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22054 \begin_inset Text
22055
22056 \layout Standard
22057
22058
22059 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
22060
22061 \end_inset 
22062
22063
22064 \end_inset 
22065 </cell>
22066 </row>
22067 </lyxtabular>
22068
22069 \end_inset 
22070
22071
22072 \newline 
22073
22074 \layout Section
22075
22076 Related documentation / recommended reading
22077 \layout Standard
22078 \align center 
22079
22080 \begin_inset  Tabular
22081 <lyxtabular version="3" rows="6" columns="3">
22082 <features>
22083 <column alignment="center" valignment="top" leftline="true" width="0pt">
22084 <column alignment="block" valignment="top" leftline="true" width="30line%">
22085 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
22086 <row topline="true" bottomline="true">
22087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22088 \begin_inset Text
22089
22090 \layout Standard
22091
22092 Name
22093 \end_inset 
22094 </cell>
22095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22096 \begin_inset Text
22097
22098 \layout Standard
22099
22100 Subject / Title
22101 \end_inset 
22102 </cell>
22103 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22104 \begin_inset Text
22105
22106 \layout Standard
22107
22108 Where to get
22109 \end_inset 
22110 </cell>
22111 </row>
22112 <row topline="true">
22113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22114 \begin_inset Text
22115
22116 \layout Standard
22117
22118
22119 \family roman 
22120 \series medium 
22121 \shape up 
22122 \size normal 
22123 \emph off 
22124 \bar no 
22125 \noun off 
22126 \color none
22127 c-refcard.pdf
22128 \end_inset 
22129 </cell>
22130 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22131 \begin_inset Text
22132
22133 \layout Standard
22134
22135 C Reference Card
22136 \begin_inset LatexCommand \index{C Reference card}
22137
22138 \end_inset 
22139
22140 , 2 pages
22141 \end_inset 
22142 </cell>
22143 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22144 \begin_inset Text
22145
22146 \layout Standard
22147
22148
22149 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
22150
22151 \end_inset 
22152
22153
22154 \end_inset 
22155 </cell>
22156 </row>
22157 <row topline="true">
22158 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22159 \begin_inset Text
22160
22161 \layout Standard
22162
22163 c-faq
22164 \end_inset 
22165 </cell>
22166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22167 \begin_inset Text
22168
22169 \layout Standard
22170
22171 C-FAQ-list
22172 \end_inset 
22173 </cell>
22174 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22175 \begin_inset Text
22176
22177 \layout Standard
22178
22179
22180 \begin_inset LatexCommand \url{http://www.eskimo.com/~scs/C-faq/top.html}
22181
22182 \end_inset 
22183
22184
22185 \end_inset 
22186 </cell>
22187 </row>
22188 <row topline="true">
22189 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22190 \begin_inset Text
22191
22192 \layout Standard
22193
22194 \end_inset 
22195 </cell>
22196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22197 \begin_inset Text
22198
22199 \layout Standard
22200
22201 Latest datasheet of the target CPU
22202 \end_inset 
22203 </cell>
22204 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22205 \begin_inset Text
22206
22207 \layout Standard
22208
22209 vendor
22210 \end_inset 
22211 </cell>
22212 </row>
22213 <row topline="true">
22214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22215 \begin_inset Text
22216
22217 \layout Standard
22218
22219 \end_inset 
22220 </cell>
22221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22222 \begin_inset Text
22223
22224 \layout Standard
22225
22226 Revision history of datasheet
22227 \end_inset 
22228 </cell>
22229 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22230 \begin_inset Text
22231
22232 \layout Standard
22233
22234 vendor
22235 \end_inset 
22236 </cell>
22237 </row>
22238 <row topline="true" bottomline="true">
22239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22240 \begin_inset Text
22241
22242 \layout Standard
22243
22244 S.
22245  S.
22246  Muchnick
22247 \end_inset 
22248 </cell>
22249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22250 \begin_inset Text
22251
22252 \layout Standard
22253
22254 Advanced Compiler Design and Implementation
22255 \end_inset 
22256 </cell>
22257 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22258 \begin_inset Text
22259
22260 \layout Standard
22261
22262 bookstore (very dedicated, probably read other books first)
22263 \end_inset 
22264 </cell>
22265 </row>
22266 </lyxtabular>
22267
22268 \end_inset 
22269
22270
22271 \newline 
22272
22273 \layout Section
22274
22275 Some Questions
22276 \layout Standard
22277
22278 Some questions answered, some pointers given - it might be time to in turn
22279  ask 
22280 \emph on 
22281 you
22282 \emph default 
22283  some questions: 
22284 \layout Itemize
22285
22286 can you solve your project with the selected microcontroller? Would you
22287  find out early or rather late that your target is too small/slow/whatever?
22288  Can you switch to a slightly better device if it doesn't fit?
22289 \layout Itemize
22290
22291 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
22292  and/or another programming language be more adequate? Would an operating
22293  system on the target device help?
22294 \layout Itemize
22295
22296 if you solved the problem, will the marketing department be happy?
22297 \layout Itemize
22298
22299 if the marketing department is happy, will customers be happy?
22300 \layout Itemize
22301
22302 if you're the project manager, marketing department and maybe even the customer
22303  in one person, have you tried to see the project from the outside?
22304 \layout Itemize
22305
22306 is the project done if you think it is done? Or is just that other interface/pro
22307 tocol/feature/configuration/option missing? How about website, manual(s),
22308  internationali(z|s)ation, packaging, labels, 2nd source for components,
22309  electromagnetic compatability/interference, documentation for production,
22310  production test software, update mechanism, patent issues?
22311 \layout Itemize
22312
22313 is your project adequately positioned in that magic triangle: fame, fortune,
22314  fun?
22315 \layout Standard
22316
22317 Maybe not all answers to these questions are known and some answers may
22318  even be 
22319 \emph on 
22320 no
22321 \emph default 
22322 , nevertheless knowing these questions may help you to avoid burnout
22323 \begin_inset Foot
22324 collapsed false
22325
22326 \layout Standard
22327
22328 burnout is bad for electronic devices, programmers and motorcycle tyres
22329 \end_inset 
22330
22331 .
22332  Chances are you didn't want to hear some of them...
22333 \layout Chapter
22334
22335 Support
22336 \begin_inset LatexCommand \index{Support}
22337
22338 \end_inset 
22339
22340
22341 \layout Standard
22342
22343 SDCC has grown to be a large project.
22344  The compiler alone (without the preprocessor, assembler and linker) is
22345  well over 100,000 lines of code (blank stripped).
22346  The open source nature of this project is a key to its continued growth
22347  and support.
22348  You gain the benefit and support of many active software developers and
22349  end users.
22350  Is SDCC perfect? No, that's why we need your help.
22351  The developers take pride in fixing reported bugs.
22352  You can help by reporting the bugs and helping other SDCC users.
22353  There are lots of ways to contribute, and we encourage you to take part
22354  in making SDCC a great software package.
22355  
22356 \layout Standard
22357
22358 The SDCC project is hosted on the SDCC sourceforge site at 
22359 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
22360
22361 \end_inset 
22362
22363 .
22364  You'll find the complete set of mailing lists
22365 \begin_inset LatexCommand \index{Mailing list(s)}
22366
22367 \end_inset 
22368
22369 , forums, bug reporting system, patch submission
22370 \begin_inset LatexCommand \index{Patch submission}
22371
22372 \end_inset 
22373
22374  system, download
22375 \begin_inset LatexCommand \index{download}
22376
22377 \end_inset 
22378
22379  area and cvs code repository
22380 \begin_inset LatexCommand \index{cvs code repository}
22381
22382 \end_inset 
22383
22384  there.
22385 \layout Section
22386
22387 Reporting Bugs
22388 \begin_inset LatexCommand \index{Bug reporting}
22389
22390 \end_inset 
22391
22392
22393 \begin_inset LatexCommand \index{Reporting bugs}
22394
22395 \end_inset 
22396
22397
22398 \layout Standard
22399
22400 The recommended way of reporting bugs is using the infrastructure of the
22401  sourceforge site.
22402  You can follow the status of bug reports there and have an overview about
22403  the known bugs.
22404 \layout Standard
22405
22406 Bug reports are automatically forwarded to the developer mailing list and
22407  will be fixed ASAP.
22408  When reporting a bug, it is very useful to include a small test program
22409  (the smaller the better) which reproduces the problem.
22410  If you can isolate the problem by looking at the generated assembly code,
22411  this can be very helpful.
22412  Compiling your program with the -
22413 \begin_inset ERT
22414 status Collapsed
22415
22416 \layout Standard
22417
22418 \backslash 
22419 /
22420 \end_inset 
22421
22422 -dumpall
22423 \begin_inset LatexCommand \index{-\/-dumpall}
22424
22425 \end_inset 
22426
22427  option can sometimes be useful in locating optimization problems.
22428  When reporting a bug please maker sure you:
22429 \layout Enumerate
22430
22431 Attach the code you are compiling with SDCC.
22432  
22433 \layout Enumerate
22434
22435 Specify the exact command you use to run SDCC, or attach your Makefile.
22436  
22437 \layout Enumerate
22438
22439 Specify the SDCC version (type "
22440 \family sans 
22441 \series bold 
22442 sdcc -v
22443 \family default 
22444 \series default 
22445 "), your platform, and operating system.
22446  
22447 \layout Enumerate
22448
22449 Provide an exact copy of any error message or incorrect output.
22450  
22451 \layout Enumerate
22452
22453 Put something meaningful in the subject of your message.
22454 \layout Standard
22455
22456 Please attempt to include these 5 important parts, as applicable, in all
22457  requests for support or when reporting any problems or bugs with SDCC.
22458  Though this will make your message lengthy, it will greatly improve your
22459  chance that SDCC users and developers will be able to help you.
22460  Some SDCC developers are frustrated by bug reports without code provided
22461  that they can use to reproduce and ultimately fix the problem, so please
22462  be sure to provide sample code if you are reporting a bug! 
22463 \layout Standard
22464
22465 Please have a short check that you are using a recent version of SDCC and
22466  the bug is not yet known.
22467  This is the link for reporting bugs: 
22468 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
22469
22470 \end_inset 
22471
22472 .
22473 \layout Section
22474
22475 Requesting Features
22476 \begin_inset LatexCommand \label{sub:Requesting-Features}
22477
22478 \end_inset 
22479
22480
22481 \begin_inset LatexCommand \index{Feature request}
22482
22483 \end_inset 
22484
22485
22486 \begin_inset LatexCommand \index{Requesting features}
22487
22488 \end_inset 
22489
22490
22491 \layout Standard
22492
22493 Like bug reports feature requests are forwarded to the developer mailing
22494  list.
22495  This is the link for requesting features: 
22496 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
22497
22498 \end_inset 
22499
22500 .
22501 \layout Section
22502
22503 Submitting patches
22504 \layout Standard
22505
22506 Like bug reports contributed patches are forwarded to the developer mailing
22507  list.
22508  This is the link for submitting patches
22509 \begin_inset LatexCommand \index{Patch submission}
22510
22511 \end_inset 
22512
22513
22514 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
22515
22516 \end_inset 
22517
22518 .
22519 \layout Standard
22520
22521 You need to specify some parameters to the 
22522 \family typewriter 
22523 diff
22524 \family default 
22525  command for the patches to be useful.
22526  If you modified more than one file a patch created f.e.
22527  with 
22528 \family sans 
22529 \series bold 
22530
22531 \begin_inset Quotes sld
22532 \end_inset 
22533
22534 diff -Naur unmodified_directory modified_directory >my_changes.patch
22535 \begin_inset Quotes srd
22536 \end_inset 
22537
22538
22539 \family default 
22540 \series default 
22541  will be fine, otherwise 
22542 \family sans 
22543 \series bold 
22544
22545 \begin_inset Quotes sld
22546 \end_inset 
22547
22548 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
22549 \begin_inset Quotes srd
22550 \end_inset 
22551
22552
22553 \series default 
22554  
22555 \family default 
22556 will do.
22557 \layout Section
22558
22559 Getting Help
22560 \layout Standard
22561
22562 These links should take you directly to the 
22563 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
22564
22565 \end_inset 
22566
22567
22568 \begin_inset Foot
22569 collapsed false
22570
22571 \layout Standard
22572
22573 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
22574  automated messages (mid 2003)
22575 \end_inset 
22576
22577  and the 
22578 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
22579
22580 \end_inset 
22581
22582 , lists
22583 \begin_inset LatexCommand \index{Mailing list(s)}
22584
22585 \end_inset 
22586
22587  and forums are archived and searchable so if you are lucky someone already
22588  had a similar problem.
22589  While mails to the lists themselves are delivered promptly their web front
22590  end on sourceforge sometimes shows a severe time lag (up to several weeks),
22591  if you're seriously using SDCC please consider subscribing to the lists.
22592 \layout Section
22593
22594 ChangeLog
22595 \layout Standard
22596
22597 You can follow the status of the cvs version
22598 \begin_inset LatexCommand \index{version}
22599
22600 \end_inset 
22601
22602  of SDCC by watching the Changelog
22603 \begin_inset LatexCommand \index{Changelog}
22604
22605 \end_inset 
22606
22607  in the cvs-repository
22608 \newline 
22609
22610 \size footnotesize 
22611
22612 \begin_inset LatexCommand \htmlurl{http://cvs.sf.net/cgi-bin/viewcvs.cgi/*checkout*/sdcc/sdcc/ChangeLog?rev=HEAD&content-type=text/plain}
22613
22614 \end_inset 
22615
22616 .
22617 \layout Section
22618
22619 Release policy
22620 \begin_inset LatexCommand \index{Release policy}
22621
22622 \end_inset 
22623
22624
22625 \layout Standard
22626
22627 Historically there often were long delays between official releases and
22628  the sourceforge download area tends to get not updated at all.
22629  Excuses in the past might have referred to problems with live range analysis,
22630  but as this was fixed a while ago, the current problem is that another
22631  excuse has to be found.
22632  Kidding aside, we have to get better there! On the other hand there are
22633  daily snapshots available at 
22634 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
22635
22636 \end_inset 
22637
22638 , and you can always build the very last version (hopefully with many bugs
22639  fixed, and features added) from the source code available at 
22640 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
22641
22642 \end_inset 
22643
22644 .
22645 \layout Section
22646
22647 Examples
22648 \begin_inset LatexCommand \index{Examples}
22649
22650 \end_inset 
22651
22652
22653 \layout Standard
22654
22655 You'll find some small examples in the directory 
22656 \emph on 
22657 sdcc/device/examples/.
22658  
22659 \emph default 
22660 More examples and libraries are available at
22661 \emph on 
22662  The SDCC Open Knowledge Resource 
22663 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
22664
22665 \end_inset 
22666
22667  
22668 \emph default 
22669 web site or at 
22670 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
22671
22672 \end_inset 
22673
22674 .
22675 \layout Comment
22676
22677 I did insert a reference to Paul's web site here although it seems rather
22678  dedicated to a specific 8032 board (I think it's okay because it f.e.
22679  shows LCD/Harddisc interface and has a free 8051 monitor.
22680  Independent 8032 board vendors face hard competition of heavily subsidized
22681  development boards anyway).
22682 \layout Comment
22683
22684 Maybe we should include some links to real world applications.
22685  Preferably pointer to pointers (one for each architecture) so this stays
22686  manageable here?
22687 \layout Section
22688
22689 Quality control
22690 \begin_inset LatexCommand \index{Quality control}
22691
22692 \end_inset 
22693
22694
22695 \layout Standard
22696
22697 The compiler is passed through nightly compile and build checks.
22698  The so called 
22699 \shape italic 
22700 regression tests
22701 \shape default 
22702
22703 \begin_inset LatexCommand \index{Regression test}
22704
22705 \end_inset 
22706
22707  check that SDCC itself compiles flawlessly on several platforms and checks
22708  the quality of the code generated by SDCC by running the code through simulator
22709 s.
22710  There is a separate document 
22711 \shape italic 
22712 test_suite.pdf
22713 \begin_inset LatexCommand \index{Test suite}
22714
22715 \end_inset 
22716
22717
22718 \shape default 
22719  about this.
22720 \layout Standard
22721
22722 You'll find the test code in the directory 
22723 \shape italic 
22724 sdcc/support/regression
22725 \shape default 
22726 .
22727  You can run these tests manually by running 
22728 \family sans 
22729 make
22730 \family default 
22731  in this directory (or f.e.
22732  
22733 \family sans 
22734 \series bold 
22735
22736 \begin_inset Quotes sld
22737 \end_inset 
22738
22739 make test-mcs51
22740 \begin_inset Quotes srd
22741 \end_inset 
22742
22743
22744 \family default 
22745 \series default 
22746  if you don't want to run the complete tests).
22747  The test code might also be interesting if you want to look for examples
22748 \begin_inset LatexCommand \index{Examples}
22749
22750 \end_inset 
22751
22752  checking corner cases of SDCC or if you plan to submit patches
22753 \begin_inset LatexCommand \index{Patch submission}
22754
22755 \end_inset 
22756
22757 .
22758 \layout Standard
22759
22760 The pic port uses a different set of regression tests, you'll find them
22761  in the directory 
22762 \shape italic 
22763 sdcc/src/regression
22764 \shape default 
22765 .
22766 \layout Chapter
22767 \pagebreak_top 
22768 SDCC Technical Data
22769 \layout Section
22770
22771 Optimizations
22772 \begin_inset LatexCommand \index{Optimizations}
22773
22774 \end_inset 
22775
22776
22777 \layout Standard
22778
22779 SDCC performs a host of standard optimizations in addition to some MCU specific
22780  optimizations.
22781  
22782 \layout Subsection
22783
22784 Sub-expression Elimination
22785 \begin_inset LatexCommand \index{Subexpression elimination}
22786
22787 \end_inset 
22788
22789
22790 \layout Standard
22791
22792 The compiler does local and 
22793 \emph on 
22794 g
22795 \emph default 
22796 lobal 
22797 \emph on 
22798 c
22799 \emph default 
22800 ommon 
22801 \emph on 
22802 s
22803 \emph default 
22804 ubexpression 
22805 \emph on 
22806 e
22807 \emph default 
22808 limination, e.g.: 
22809 \layout Verse
22810
22811
22812 \family typewriter 
22813 i = x + y + 1; 
22814 \newline 
22815 j = x + y;
22816 \layout Standard
22817
22818 will be translated to
22819 \layout Verse
22820
22821
22822 \family typewriter 
22823 iTemp = x + y; 
22824 \newline 
22825 i = iTemp + 1; 
22826 \newline 
22827 j = iTemp;
22828 \layout Standard
22829
22830 Some subexpressions are not as obvious as the above example, e.g.:
22831 \layout Verse
22832
22833
22834 \family typewriter 
22835 a->b[i].c = 10; 
22836 \newline 
22837 a->b[i].d = 11;
22838 \layout Standard
22839
22840 In this case the address arithmetic a->b[i] will be computed only once;
22841  the equivalent code in C would be.
22842 \layout Verse
22843
22844
22845 \family typewriter 
22846 iTemp = a->b[i]; 
22847 \newline 
22848 iTemp.c = 10; 
22849 \newline 
22850 iTemp.d = 11;
22851 \layout Standard
22852
22853 The compiler will try to keep these temporary variables in registers.
22854 \layout Subsection
22855
22856 Dead-Code Elimination
22857 \begin_inset LatexCommand \index{Dead-code elimination}
22858
22859 \end_inset 
22860
22861
22862 \layout Verse
22863
22864
22865 \family typewriter 
22866 int global;
22867 \newline 
22868
22869 \newline 
22870 void f () { 
22871 \newline 
22872 \SpecialChar ~
22873 \SpecialChar ~
22874 int i; 
22875 \newline 
22876 \SpecialChar ~
22877 \SpecialChar ~
22878 i = 1; \SpecialChar ~
22879 \SpecialChar ~
22880 \SpecialChar ~
22881 \SpecialChar ~
22882 \SpecialChar ~
22883 /* dead store */ 
22884 \newline 
22885 \SpecialChar ~
22886 \SpecialChar ~
22887 global = 1;\SpecialChar ~
22888 /* dead store */ 
22889 \newline 
22890 \SpecialChar ~
22891 \SpecialChar ~
22892 global = 2; 
22893 \newline 
22894 \SpecialChar ~
22895 \SpecialChar ~
22896 return; 
22897 \newline 
22898 \SpecialChar ~
22899 \SpecialChar ~
22900 global = 3;\SpecialChar ~
22901 /* unreachable */ 
22902 \newline 
22903 }
22904 \layout Standard
22905
22906 will be changed to
22907 \layout Verse
22908
22909
22910 \family typewriter 
22911 int global;
22912 \newline 
22913
22914 \newline 
22915 void f () {
22916 \newline 
22917 \SpecialChar ~
22918 \SpecialChar ~
22919 global = 2; 
22920 \newline 
22921 }
22922 \layout Subsection
22923
22924 Copy-Propagation
22925 \begin_inset LatexCommand \index{Copy propagation}
22926
22927 \end_inset 
22928
22929
22930 \layout Verse
22931
22932
22933 \family typewriter 
22934 int f() { 
22935 \newline 
22936 \SpecialChar ~
22937 \SpecialChar ~
22938 int i, j; 
22939 \newline 
22940 \SpecialChar ~
22941 \SpecialChar ~
22942 i = 10; 
22943 \newline 
22944 \SpecialChar ~
22945 \SpecialChar ~
22946 j = i; 
22947 \newline 
22948 \SpecialChar ~
22949 \SpecialChar ~
22950 return j; 
22951 \newline 
22952 }
22953 \layout Standard
22954
22955 will be changed to 
22956 \layout Verse
22957
22958
22959 \family typewriter 
22960 int f() { 
22961 \newline 
22962 \SpecialChar ~
22963 \SpecialChar ~
22964 int i, j; 
22965 \newline 
22966 \SpecialChar ~
22967 \SpecialChar ~
22968 i = 10; 
22969 \newline 
22970 \SpecialChar ~
22971 \SpecialChar ~
22972 j = 10; 
22973 \newline 
22974 \SpecialChar ~
22975 \SpecialChar ~
22976 return 10; 
22977 \newline 
22978 }
22979 \layout Standard
22980
22981 Note: the dead stores created by this copy propagation will be eliminated
22982  by dead-code elimination.
22983 \layout Subsection
22984
22985 Loop Optimizations
22986 \begin_inset LatexCommand \index{Loop optimization}
22987
22988 \end_inset 
22989
22990
22991 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
22992
22993 \end_inset 
22994
22995
22996 \layout Standard
22997
22998 Two types of loop optimizations are done by SDCC 
22999 \emph on 
23000 loop invariant
23001 \emph default 
23002  lifting and
23003 \emph on 
23004  strength reduction
23005 \emph default 
23006  of loop induction variables.
23007  In addition to the strength reduction the optimizer marks the induction
23008  variables and the register allocator tries to keep the induction variables
23009  in registers for the duration of the loop.
23010  Because of this preference of the register allocator
23011 \begin_inset LatexCommand \index{Register allocation}
23012
23013 \end_inset 
23014
23015 , loop induction optimization causes an increase in register pressure, which
23016  may cause unwanted spilling of other temporary variables into the stack
23017 \begin_inset LatexCommand \index{stack}
23018
23019 \end_inset 
23020
23021  / data space.
23022  The compiler will generate a warning message when it is forced to allocate
23023  extra space either on the stack or data space.
23024  If this extra space allocation is undesirable then induction optimization
23025  can be eliminated either for the entire source file (with -
23026 \begin_inset ERT
23027 status Collapsed
23028
23029 \layout Standard
23030
23031 \backslash 
23032 /
23033 \end_inset 
23034
23035 -noinduction option) or for a given function only using #pragma\SpecialChar ~
23036 noinduction
23037 \begin_inset LatexCommand \index{\#pragma noinduction}
23038
23039 \end_inset 
23040
23041 .
23042 \newline 
23043
23044 \newline 
23045 Loop Invariant:
23046 \layout Verse
23047
23048
23049 \family typewriter 
23050 for (i = 0 ; i < 100 ; i ++) 
23051 \newline 
23052 \SpecialChar ~
23053 \SpecialChar ~
23054 \SpecialChar ~
23055 \SpecialChar ~
23056 f += k + l;
23057 \layout Standard
23058
23059 changed to
23060 \layout Verse
23061
23062
23063 \family typewriter 
23064 itemp = k + l; 
23065 \newline 
23066 for (i = 0; i < 100; i++) 
23067 \newline 
23068 \SpecialChar ~
23069 \SpecialChar ~
23070 \SpecialChar ~
23071 \SpecialChar ~
23072 f += itemp;
23073 \layout Standard
23074
23075 As mentioned previously some loop invariants are not as apparent, all static
23076  address computations are also moved out of the loop.
23077 \newline 
23078
23079 \newline 
23080 Strength Reduction
23081 \begin_inset LatexCommand \index{Strength reduction}
23082
23083 \end_inset 
23084
23085 , this optimization substitutes an expression by a cheaper expression:
23086 \layout Verse
23087
23088
23089 \family typewriter 
23090 for (i=0;i < 100; i++)
23091 \newline 
23092 \SpecialChar ~
23093 \SpecialChar ~
23094 \SpecialChar ~
23095 \SpecialChar ~
23096 ar[i*5] = i*3;
23097 \layout Standard
23098
23099 changed to
23100 \layout Verse
23101
23102
23103 \family typewriter 
23104 itemp1 = 0; 
23105 \newline 
23106 itemp2 = 0; 
23107 \newline 
23108 for (i=0;i< 100;i++) { 
23109 \newline 
23110 \SpecialChar ~
23111 \SpecialChar ~
23112 \SpecialChar ~
23113 \SpecialChar ~
23114 ar[itemp1] = itemp2; 
23115 \newline 
23116 \SpecialChar ~
23117 \SpecialChar ~
23118 \SpecialChar ~
23119 \SpecialChar ~
23120 itemp1 += 5; 
23121 \newline 
23122 \SpecialChar ~
23123 \SpecialChar ~
23124 \SpecialChar ~
23125 \SpecialChar ~
23126 itemp2 += 3; 
23127 \newline 
23128 }
23129 \layout Standard
23130
23131 The more expensive multiplication
23132 \begin_inset LatexCommand \index{Multiplication}
23133
23134 \end_inset 
23135
23136  is changed to a less expensive addition.
23137 \layout Subsection
23138
23139 Loop Reversing
23140 \begin_inset LatexCommand \index{Loop reversing}
23141
23142 \end_inset 
23143
23144
23145 \layout Standard
23146
23147 This optimization is done to reduce the overhead of checking loop boundaries
23148  for every iteration.
23149  Some simple loops can be reversed and implemented using a 
23150 \begin_inset Quotes eld
23151 \end_inset 
23152
23153 decrement and jump if not zero
23154 \begin_inset Quotes erd
23155 \end_inset 
23156
23157  instruction.
23158  SDCC checks for the following criterion to determine if a loop is reversible
23159  (note: more sophisticated compilers use data-dependency analysis to make
23160  this determination, SDCC uses a more simple minded analysis).
23161 \layout Itemize
23162
23163 The 'for' loop is of the form 
23164 \newline 
23165
23166 \newline 
23167
23168 \family typewriter 
23169 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
23170  += 1])
23171 \newline 
23172 \SpecialChar ~
23173 \SpecialChar ~
23174 \SpecialChar ~
23175 \SpecialChar ~
23176 <for body>
23177 \layout Itemize
23178
23179 The <for body> does not contain 
23180 \begin_inset Quotes eld
23181 \end_inset 
23182
23183 continue
23184 \begin_inset Quotes erd
23185 \end_inset 
23186
23187  or 'break
23188 \begin_inset Quotes erd
23189 \end_inset 
23190
23191 .
23192 \layout Itemize
23193
23194 All goto's are contained within the loop.
23195 \layout Itemize
23196
23197 No function calls within the loop.
23198 \layout Itemize
23199
23200 The loop control variable <sym> is not assigned any value within the loop
23201 \layout Itemize
23202
23203 The loop control variable does NOT participate in any arithmetic operation
23204  within the loop.
23205 \layout Itemize
23206
23207 There are NO switch statements in the loop.
23208 \layout Subsection
23209
23210 Algebraic Simplifications
23211 \layout Standard
23212
23213 SDCC does numerous algebraic simplifications, the following is a small sub-set
23214  of these optimizations.
23215 \layout Verse
23216
23217
23218 \family typewriter 
23219 i = j + 0;\SpecialChar ~
23220 \SpecialChar ~
23221 \SpecialChar ~
23222 \SpecialChar ~
23223  /* changed to: */\SpecialChar ~
23224 \SpecialChar ~
23225 \SpecialChar ~
23226 \SpecialChar ~
23227  i = j; 
23228 \newline 
23229 i /= 2;\SpecialChar ~
23230 \SpecialChar ~
23231 \SpecialChar ~
23232 \SpecialChar ~
23233 \SpecialChar ~
23234 \SpecialChar ~
23235 \SpecialChar ~
23236  /* changed to: */\SpecialChar ~
23237 \SpecialChar ~
23238 \SpecialChar ~
23239 \SpecialChar ~
23240  i >>= 1; 
23241 \newline 
23242 i = j - j;\SpecialChar ~
23243 \SpecialChar ~
23244 \SpecialChar ~
23245 \SpecialChar ~
23246  /* changed to: */\SpecialChar ~
23247 \SpecialChar ~
23248 \SpecialChar ~
23249 \SpecialChar ~
23250  i = 0; 
23251 \newline 
23252 i = j / 1;\SpecialChar ~
23253 \SpecialChar ~
23254 \SpecialChar ~
23255 \SpecialChar ~
23256  /* changed to: */\SpecialChar ~
23257 \SpecialChar ~
23258 \SpecialChar ~
23259 \SpecialChar ~
23260  i = j;
23261 \layout Standard
23262
23263 Note the subexpressions
23264 \begin_inset LatexCommand \index{Subexpression}
23265
23266 \end_inset 
23267
23268  given above are generally introduced by macro expansions or as a result
23269  of copy/constant propagation.
23270 \layout Subsection
23271
23272 'switch' Statements
23273 \begin_inset LatexCommand \label{sub:'switch'-Statements}
23274
23275 \end_inset 
23276
23277
23278 \begin_inset LatexCommand \index{switch statement}
23279
23280 \end_inset 
23281
23282
23283 \layout Standard
23284
23285 SDCC can optimize switch statements to jump tables
23286 \begin_inset LatexCommand \index{jump tables}
23287
23288 \end_inset 
23289
23290 .
23291  It makes the decision based on an estimate of the generated code size.
23292  SDCC is quite liberal in the requirements for jump table generation: 
23293 \layout Itemize
23294
23295 The labels need not be in order, and the starting number need not be one
23296  or zero, the case labels are in numerical sequence or not too many case
23297  labels are missing.
23298 \begin_deeper 
23299 \layout Verse
23300
23301
23302 \family typewriter 
23303 switch(i) {\SpecialChar ~
23304 \SpecialChar ~
23305 \SpecialChar ~
23306 \SpecialChar ~
23307 \SpecialChar ~
23308 \SpecialChar ~
23309 \SpecialChar ~
23310 \SpecialChar ~
23311 \SpecialChar ~
23312 \SpecialChar ~
23313 \SpecialChar ~
23314 \SpecialChar ~
23315 \SpecialChar ~
23316 \SpecialChar ~
23317 \SpecialChar ~
23318 \SpecialChar ~
23319 \SpecialChar ~
23320 \SpecialChar ~
23321 \SpecialChar ~
23322 \SpecialChar ~
23323 \SpecialChar ~
23324 \SpecialChar ~
23325 \SpecialChar ~
23326 \SpecialChar ~
23327 \SpecialChar ~
23328 \SpecialChar ~
23329 switch (i) { 
23330 \newline 
23331 \SpecialChar ~
23332 \SpecialChar ~
23333 \SpecialChar ~
23334 case 4: ...\SpecialChar ~
23335 \SpecialChar ~
23336 \SpecialChar ~
23337 \SpecialChar ~
23338 \SpecialChar ~
23339 \SpecialChar ~
23340 \SpecialChar ~
23341 \SpecialChar ~
23342 \SpecialChar ~
23343 \SpecialChar ~
23344 \SpecialChar ~
23345 \SpecialChar ~
23346 \SpecialChar ~
23347 \SpecialChar ~
23348 \SpecialChar ~
23349 \SpecialChar ~
23350 \SpecialChar ~
23351 \SpecialChar ~
23352 \SpecialChar ~
23353 \SpecialChar ~
23354 \SpecialChar ~
23355 \SpecialChar ~
23356 \SpecialChar ~
23357 \SpecialChar ~
23358 \SpecialChar ~
23359 \SpecialChar ~
23360 case 0: ...
23361  
23362 \newline 
23363 \SpecialChar ~
23364 \SpecialChar ~
23365 \SpecialChar ~
23366 case 5: ...\SpecialChar ~
23367 \SpecialChar ~
23368 \SpecialChar ~
23369 \SpecialChar ~
23370 \SpecialChar ~
23371 \SpecialChar ~
23372 \SpecialChar ~
23373 \SpecialChar ~
23374 \SpecialChar ~
23375 \SpecialChar ~
23376 \SpecialChar ~
23377 \SpecialChar ~
23378 \SpecialChar ~
23379 \SpecialChar ~
23380 \SpecialChar ~
23381 \SpecialChar ~
23382 \SpecialChar ~
23383 \SpecialChar ~
23384 \SpecialChar ~
23385 \SpecialChar ~
23386 \SpecialChar ~
23387 \SpecialChar ~
23388 \SpecialChar ~
23389 \SpecialChar ~
23390 \SpecialChar ~
23391 \SpecialChar ~
23392 case 1: ...
23393  
23394 \newline 
23395 \SpecialChar ~
23396 \SpecialChar ~
23397 \SpecialChar ~
23398 case 3: ...\SpecialChar ~
23399 \SpecialChar ~
23400 \SpecialChar ~
23401 \SpecialChar ~
23402 \SpecialChar ~
23403 \SpecialChar ~
23404 \SpecialChar ~
23405 \SpecialChar ~
23406 \SpecialChar ~
23407 \SpecialChar ~
23408 \SpecialChar ~
23409 \SpecialChar ~
23410 \SpecialChar ~
23411 \SpecialChar ~
23412 \SpecialChar ~
23413 \SpecialChar ~
23414 \SpecialChar ~
23415 \SpecialChar ~
23416 \SpecialChar ~
23417 \SpecialChar ~
23418 \SpecialChar ~
23419 \SpecialChar ~
23420 \SpecialChar ~
23421 \SpecialChar ~
23422 \SpecialChar ~
23423 \SpecialChar ~
23424
23425 \newline 
23426 \SpecialChar ~
23427 \SpecialChar ~
23428 \SpecialChar ~
23429 case 6: ...\SpecialChar ~
23430 \SpecialChar ~
23431 \SpecialChar ~
23432 \SpecialChar ~
23433 \SpecialChar ~
23434 \SpecialChar ~
23435 \SpecialChar ~
23436 \SpecialChar ~
23437 \SpecialChar ~
23438 \SpecialChar ~
23439 \SpecialChar ~
23440 \SpecialChar ~
23441 \SpecialChar ~
23442 \SpecialChar ~
23443 \SpecialChar ~
23444 \SpecialChar ~
23445 \SpecialChar ~
23446 \SpecialChar ~
23447 \SpecialChar ~
23448 \SpecialChar ~
23449 \SpecialChar ~
23450 \SpecialChar ~
23451 \SpecialChar ~
23452 \SpecialChar ~
23453 \SpecialChar ~
23454 \SpecialChar ~
23455 case 3: ...
23456  
23457 \newline 
23458 \SpecialChar ~
23459 \SpecialChar ~
23460 \SpecialChar ~
23461 case 7: ...\SpecialChar ~
23462 \SpecialChar ~
23463 \SpecialChar ~
23464 \SpecialChar ~
23465 \SpecialChar ~
23466 \SpecialChar ~
23467 \SpecialChar ~
23468 \SpecialChar ~
23469 \SpecialChar ~
23470 \SpecialChar ~
23471 \SpecialChar ~
23472 \SpecialChar ~
23473 \SpecialChar ~
23474 \SpecialChar ~
23475 \SpecialChar ~
23476 \SpecialChar ~
23477 \SpecialChar ~
23478 \SpecialChar ~
23479 \SpecialChar ~
23480 \SpecialChar ~
23481 \SpecialChar ~
23482 \SpecialChar ~
23483 \SpecialChar ~
23484 \SpecialChar ~
23485 \SpecialChar ~
23486 \SpecialChar ~
23487 case 4: ...
23488  
23489 \newline 
23490 \SpecialChar ~
23491 \SpecialChar ~
23492 \SpecialChar ~
23493 case 8: ...\SpecialChar ~
23494 \SpecialChar ~
23495 \SpecialChar ~
23496 \SpecialChar ~
23497 \SpecialChar ~
23498 \SpecialChar ~
23499 \SpecialChar ~
23500 \SpecialChar ~
23501 \SpecialChar ~
23502 \SpecialChar ~
23503 \SpecialChar ~
23504 \SpecialChar ~
23505 \SpecialChar ~
23506 \SpecialChar ~
23507 \SpecialChar ~
23508 \SpecialChar ~
23509 \SpecialChar ~
23510 \SpecialChar ~
23511 \SpecialChar ~
23512 \SpecialChar ~
23513 \SpecialChar ~
23514 \SpecialChar ~
23515 \SpecialChar ~
23516 \SpecialChar ~
23517 \SpecialChar ~
23518 \SpecialChar ~
23519 case 5: ...
23520  
23521 \newline 
23522 \SpecialChar ~
23523 \SpecialChar ~
23524 \SpecialChar ~
23525 case 9: ...\SpecialChar ~
23526 \SpecialChar ~
23527 \SpecialChar ~
23528 \SpecialChar ~
23529 \SpecialChar ~
23530 \SpecialChar ~
23531 \SpecialChar ~
23532 \SpecialChar ~
23533 \SpecialChar ~
23534 \SpecialChar ~
23535 \SpecialChar ~
23536 \SpecialChar ~
23537 \SpecialChar ~
23538 \SpecialChar ~
23539 \SpecialChar ~
23540 \SpecialChar ~
23541 \SpecialChar ~
23542 \SpecialChar ~
23543 \SpecialChar ~
23544 \SpecialChar ~
23545 \SpecialChar ~
23546 \SpecialChar ~
23547 \SpecialChar ~
23548 \SpecialChar ~
23549 \SpecialChar ~
23550 \SpecialChar ~
23551 case 6: ...
23552  
23553 \newline 
23554 \SpecialChar ~
23555 \SpecialChar ~
23556 \SpecialChar ~
23557 case 10: ...\SpecialChar ~
23558 \SpecialChar ~
23559 \SpecialChar ~
23560 \SpecialChar ~
23561 \SpecialChar ~
23562 \SpecialChar ~
23563 \SpecialChar ~
23564 \SpecialChar ~
23565 \SpecialChar ~
23566 \SpecialChar ~
23567 \SpecialChar ~
23568 \SpecialChar ~
23569 \SpecialChar ~
23570 \SpecialChar ~
23571 \SpecialChar ~
23572 \SpecialChar ~
23573 \SpecialChar ~
23574 \SpecialChar ~
23575 \SpecialChar ~
23576 \SpecialChar ~
23577 \SpecialChar ~
23578 \SpecialChar ~
23579 \SpecialChar ~
23580 \SpecialChar ~
23581 \SpecialChar ~
23582 case 7: ...
23583  
23584 \newline 
23585 \SpecialChar ~
23586 \SpecialChar ~
23587 \SpecialChar ~
23588 case 11: ...\SpecialChar ~
23589 \SpecialChar ~
23590 \SpecialChar ~
23591 \SpecialChar ~
23592 \SpecialChar ~
23593 \SpecialChar ~
23594 \SpecialChar ~
23595 \SpecialChar ~
23596 \SpecialChar ~
23597 \SpecialChar ~
23598 \SpecialChar ~
23599 \SpecialChar ~
23600 \SpecialChar ~
23601 \SpecialChar ~
23602 \SpecialChar ~
23603 \SpecialChar ~
23604 \SpecialChar ~
23605 \SpecialChar ~
23606 \SpecialChar ~
23607 \SpecialChar ~
23608 \SpecialChar ~
23609 \SpecialChar ~
23610 \SpecialChar ~
23611 \SpecialChar ~
23612 \SpecialChar ~
23613 case 8: ...
23614  
23615 \newline 
23616 }\SpecialChar ~
23617 \SpecialChar ~
23618 \SpecialChar ~
23619 \SpecialChar ~
23620 \SpecialChar ~
23621 \SpecialChar ~
23622 \SpecialChar ~
23623 \SpecialChar ~
23624 \SpecialChar ~
23625 \SpecialChar ~
23626 \SpecialChar ~
23627 \SpecialChar ~
23628 \SpecialChar ~
23629 \SpecialChar ~
23630 \SpecialChar ~
23631 \SpecialChar ~
23632 \SpecialChar ~
23633 \SpecialChar ~
23634 \SpecialChar ~
23635 \SpecialChar ~
23636 \SpecialChar ~
23637 \SpecialChar ~
23638 \SpecialChar ~
23639 \SpecialChar ~
23640 \SpecialChar ~
23641 \SpecialChar ~
23642 \SpecialChar ~
23643 \SpecialChar ~
23644 \SpecialChar ~
23645 \SpecialChar ~
23646 \SpecialChar ~
23647 \SpecialChar ~
23648 \SpecialChar ~
23649 \SpecialChar ~
23650 \SpecialChar ~
23651 \SpecialChar ~
23652 }
23653 \layout Standard
23654
23655 Both the above switch statements will be implemented using a jump-table.
23656  The example to the right side is slightly more efficient as the check for
23657  the lower boundary of the jump-table is not needed.
23658 \end_deeper 
23659 \layout Itemize
23660
23661 The number of case labels is not larger than supported by the target architectur
23662 e.
23663 \layout Itemize
23664
23665 If the case labels are not in numerical sequence ('gaps' between cases)
23666  SDCC checks whether a jump table with additionally inserted dummy cases
23667  is still attractive.
23668  
23669 \layout Itemize
23670
23671 If the starting number is not zero and a check for the lower boundary of
23672  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
23673  ...
23674  .
23675 \layout Standard
23676
23677 Switch statements which have large gaps in the numeric sequence or those
23678  that have too many case labels can be split into more than one switch statement
23679  for efficient code generation, e.g.:
23680 \layout Verse
23681
23682
23683 \family typewriter 
23684 switch (i) { 
23685 \newline 
23686 \SpecialChar ~
23687 \SpecialChar ~
23688 case 1: ...
23689  
23690 \newline 
23691 \SpecialChar ~
23692 \SpecialChar ~
23693 case 2: ...
23694  
23695 \newline 
23696 \SpecialChar ~
23697 \SpecialChar ~
23698 case 3: ...
23699  
23700 \newline 
23701 \SpecialChar ~
23702 \SpecialChar ~
23703 case 4: ...
23704  
23705 \newline 
23706 \SpecialChar ~
23707 \SpecialChar ~
23708 case 5: ...
23709  
23710 \newline 
23711 \SpecialChar ~
23712 \SpecialChar ~
23713 case 6: ...
23714  
23715 \newline 
23716 \SpecialChar ~
23717 \SpecialChar ~
23718 case 7: ...
23719  
23720 \newline 
23721 \SpecialChar ~
23722 \SpecialChar ~
23723 case 101: ...
23724  
23725 \newline 
23726 \SpecialChar ~
23727 \SpecialChar ~
23728 case 102: ...
23729  
23730 \newline 
23731 \SpecialChar ~
23732 \SpecialChar ~
23733 case 103: ...
23734  
23735 \newline 
23736 \SpecialChar ~
23737 \SpecialChar ~
23738 case 104: ...
23739  
23740 \newline 
23741 \SpecialChar ~
23742 \SpecialChar ~
23743 case 105: ...
23744  
23745 \newline 
23746 \SpecialChar ~
23747 \SpecialChar ~
23748 case 106: ...
23749  
23750 \newline 
23751 \SpecialChar ~
23752 \SpecialChar ~
23753 case 107: ...
23754  
23755 \newline 
23756 }
23757 \layout Standard
23758
23759 If the above switch statement is broken down into two switch statements
23760 \layout Verse
23761
23762
23763 \family typewriter 
23764 switch (i) { 
23765 \newline 
23766 \SpecialChar ~
23767 \SpecialChar ~
23768 case 1: ...
23769  
23770 \newline 
23771 \SpecialChar ~
23772 \SpecialChar ~
23773 case 2: ...
23774  
23775 \newline 
23776 \SpecialChar ~
23777 \SpecialChar ~
23778 case 3: ...
23779  
23780 \newline 
23781 \SpecialChar ~
23782 \SpecialChar ~
23783 case 4: ...
23784  
23785 \newline 
23786 \SpecialChar ~
23787 \SpecialChar ~
23788 case 5: ...
23789  
23790 \newline 
23791 \SpecialChar ~
23792 \SpecialChar ~
23793 case 6: ...
23794  
23795 \newline 
23796 \SpecialChar ~
23797 \SpecialChar ~
23798 case 7: ...
23799  
23800 \newline 
23801 }
23802 \layout Standard
23803
23804 and
23805 \layout Verse
23806
23807
23808 \family typewriter 
23809 switch (i) { 
23810 \newline 
23811 \SpecialChar ~
23812 \SpecialChar ~
23813 case 101: ...
23814  
23815 \newline 
23816 \SpecialChar ~
23817 \SpecialChar ~
23818 case 102: ...
23819  
23820 \newline 
23821 \SpecialChar ~
23822 \SpecialChar ~
23823 case 103: ...
23824  
23825 \newline 
23826 \SpecialChar ~
23827 \SpecialChar ~
23828 case 104: ...
23829  
23830 \newline 
23831 \SpecialChar ~
23832 \SpecialChar ~
23833 case 105: ...
23834  
23835 \newline 
23836 \SpecialChar ~
23837 \SpecialChar ~
23838 case 106: ...
23839  
23840 \newline 
23841 \SpecialChar ~
23842 \SpecialChar ~
23843 case 107: ...
23844  
23845 \newline 
23846 }
23847 \layout Standard
23848
23849 then both the switch statements will be implemented using jump-tables whereas
23850  the unmodified switch statement will not be.
23851 \layout Comment
23852
23853 There might be reasons which SDCC cannot know about to either favour or
23854  not favour jump tables.
23855  If the target system has to be as quick for the last switch case as for
23856  the first (pro jump table), or if the switch argument is known to be zero
23857  in the majority of the cases (contra jump table).
23858 \layout Standard
23859
23860 The pragma nojtbound
23861 \begin_inset LatexCommand \index{\#pragma nojtbound}
23862
23863 \end_inset 
23864
23865  can be used to turn off checking the 
23866 \emph on 
23867 j
23868 \emph default 
23869 ump 
23870 \emph on 
23871 t
23872 \emph default 
23873 able 
23874 \emph on 
23875 bound
23876 \emph default 
23877 aries.
23878  It has no effect if a default label is supplied.
23879  Use of this pragma is dangerous: if the switch
23880 \begin_inset LatexCommand \index{switch statement}
23881
23882 \end_inset 
23883
23884  argument is not matched by a case statement the processor will happily
23885  jump into Nirvana.
23886 \layout Subsection
23887
23888 Bit-shifting Operations
23889 \begin_inset LatexCommand \index{Bit shifting}
23890
23891 \end_inset 
23892
23893 .
23894 \layout Standard
23895
23896 Bit shifting is one of the most frequently used operation in embedded programmin
23897 g.
23898  SDCC tries to implement bit-shift operations in the most efficient way
23899  possible, e.g.:
23900 \layout Verse
23901
23902
23903 \family typewriter 
23904 unsigned char i;
23905 \newline 
23906 ...
23907  
23908 \newline 
23909 i >>= 4; 
23910 \newline 
23911 ...
23912 \layout Standard
23913
23914 generates the following code:
23915 \layout Verse
23916
23917
23918 \family typewriter 
23919 mov\SpecialChar ~
23920  a,_i 
23921 \newline 
23922 swap a 
23923 \newline 
23924 anl\SpecialChar ~
23925  a,#0x0f 
23926 \newline 
23927 mov\SpecialChar ~
23928  _i,a
23929 \layout Standard
23930
23931 In general SDCC will never setup a loop if the shift count is known.
23932  Another example:
23933 \layout Verse
23934
23935
23936 \family typewriter 
23937 unsigned int i; 
23938 \newline 
23939 ...
23940  
23941 \newline 
23942 i >>= 9; 
23943 \newline 
23944 ...
23945 \layout Standard
23946
23947 will generate:
23948 \layout Verse
23949
23950
23951 \family typewriter 
23952 mov\SpecialChar ~
23953 \SpecialChar ~
23954 a,(_i + 1) 
23955 \newline 
23956 mov\SpecialChar ~
23957 \SpecialChar ~
23958 (_i + 1),#0x00 
23959 \newline 
23960 clr\SpecialChar ~
23961 \SpecialChar ~
23962
23963 \newline 
23964 rrc\SpecialChar ~
23965 \SpecialChar ~
23966
23967 \newline 
23968 mov\SpecialChar ~
23969 \SpecialChar ~
23970 _i,a
23971 \layout Subsection
23972
23973 Bit-rotation
23974 \begin_inset LatexCommand \index{Bit rotation}
23975
23976 \end_inset 
23977
23978
23979 \layout Standard
23980
23981 A special case of the bit-shift operation is bit rotation
23982 \begin_inset LatexCommand \index{rotating bits}
23983
23984 \end_inset 
23985
23986 , SDCC recognizes the following expression to be a left bit-rotation:
23987 \layout Verse
23988
23989
23990 \family typewriter 
23991 \series bold 
23992 unsigned
23993 \series default 
23994 \SpecialChar ~
23995 \SpecialChar ~
23996 char i;\SpecialChar ~
23997 \SpecialChar ~
23998 \SpecialChar ~
23999 \SpecialChar ~
24000 \SpecialChar ~
24001 \SpecialChar ~
24002 \SpecialChar ~
24003 \SpecialChar ~
24004 \SpecialChar ~
24005 \SpecialChar ~
24006 \SpecialChar ~
24007 /* unsigned is needed for rotation */ 
24008 \newline 
24009 ...
24010  
24011 \newline 
24012 i = ((i << 1) | (i >> 7)); 
24013 \family default 
24014
24015 \newline 
24016
24017 \family typewriter 
24018 ...
24019 \layout Standard
24020
24021 will generate the following code:
24022 \layout Verse
24023
24024
24025 \family typewriter 
24026 mov\SpecialChar ~
24027 \SpecialChar ~
24028 a,_i 
24029 \newline 
24030 rl\SpecialChar ~
24031 \SpecialChar ~
24032 \SpecialChar ~
24033
24034 \newline 
24035 mov\SpecialChar ~
24036 \SpecialChar ~
24037 _i,a
24038 \layout Standard
24039
24040 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
24041 ns of this case will also be recognized as bit-rotation, i.e.: 
24042 \layout Verse
24043
24044
24045 \family typewriter 
24046 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
24047 \layout Subsection
24048
24049 Nibble and Byte Swapping
24050 \layout Standard
24051
24052 Other special cases of the bit-shift operations are nibble or byte swapping
24053 \begin_inset LatexCommand \index{swapping nibbles/bytes}
24054
24055 \end_inset 
24056
24057 , SDCC recognizes the following expressions:
24058 \layout Verse
24059
24060
24061 \family typewriter 
24062 \series bold 
24063 unsigned
24064 \series default 
24065 \SpecialChar ~
24066 \SpecialChar ~
24067 char i; 
24068 \newline 
24069
24070 \series bold 
24071 unsigned
24072 \series default 
24073 \SpecialChar ~
24074 \SpecialChar ~
24075 int j; 
24076 \newline 
24077 ...
24078  
24079 \newline 
24080 i = ((i << 4) | (i >> 4)); 
24081 \family default 
24082
24083 \newline 
24084
24085 \family typewriter 
24086 j = ((j << 8) | (j >> 8)); 
24087 \layout Standard
24088
24089 and generates a swap instruction for the nibble swapping
24090 \begin_inset LatexCommand \index{Nibble swapping}
24091
24092 \end_inset 
24093
24094  or move instructions for the byte swapping
24095 \begin_inset LatexCommand \index{Byte swapping}
24096
24097 \end_inset 
24098
24099 .
24100  The 
24101 \begin_inset Quotes sld
24102 \end_inset 
24103
24104 j
24105 \begin_inset Quotes srd
24106 \end_inset 
24107
24108  example can be used to convert from little to big-endian or vice versa.
24109  If you want to change the endianness of a 
24110 \emph on 
24111 signed
24112 \emph default 
24113  integer you have to cast to 
24114 \family typewriter 
24115 (unsigned int)
24116 \family default 
24117  first.
24118 \layout Standard
24119
24120 Note that SDCC stores numbers in little-endian
24121 \begin_inset Foot
24122 collapsed false
24123
24124 \layout Standard
24125
24126 Usually 8-bit processors don't care much about endianness.
24127  This is not the case for the standard 8051 which only has an instruction
24128  to increment its 
24129 \emph on 
24130 dptr
24131 \emph default 
24132
24133 \begin_inset LatexCommand \index{DPTR}
24134
24135 \end_inset 
24136
24137 -datapointer
24138 \emph on 
24139  
24140 \emph default 
24141 so little-endian is the more efficient byte order.
24142 \end_inset 
24143
24144
24145 \begin_inset LatexCommand \index{little-endian}
24146
24147 \end_inset 
24148
24149
24150 \begin_inset LatexCommand \index{Endianness}
24151
24152 \end_inset 
24153
24154  format (i.e.
24155  lowest order first).
24156 \layout Subsection
24157
24158 Highest Order Bit
24159 \begin_inset LatexCommand \index{Highest Order Bit}
24160
24161 \end_inset 
24162
24163
24164 \layout Standard
24165
24166 It is frequently required to obtain the highest order bit of an integral
24167  type (long, int, short or char types).
24168  SDCC recognizes the following expression to yield the highest order bit
24169  and generates optimized code for it, e.g.:
24170 \layout Verse
24171
24172
24173 \family typewriter 
24174 unsigned int gint; 
24175 \newline 
24176
24177 \newline 
24178 foo () { 
24179 \newline 
24180 \SpecialChar ~
24181 \SpecialChar ~
24182 unsigned char hob; 
24183 \newline 
24184 \SpecialChar ~
24185 \SpecialChar ~
24186 ...
24187  
24188 \newline 
24189 \SpecialChar ~
24190 \SpecialChar ~
24191 hob = (gint >> 15) & 1; 
24192 \newline 
24193 \SpecialChar ~
24194 \SpecialChar ~
24195 ..
24196  
24197 \newline 
24198 }
24199 \layout Standard
24200
24201 will generate the following code:
24202 \layout Verse
24203
24204
24205 \family typewriter 
24206 \SpecialChar ~
24207 \SpecialChar ~
24208 \SpecialChar ~
24209 \SpecialChar ~
24210 \SpecialChar ~
24211 \SpecialChar ~
24212 \SpecialChar ~
24213 \SpecialChar ~
24214 \SpecialChar ~
24215 \SpecialChar ~
24216 \SpecialChar ~
24217 \SpecialChar ~
24218 \SpecialChar ~
24219 \SpecialChar ~
24220 \SpecialChar ~
24221 \SpecialChar ~
24222 \SpecialChar ~
24223 \SpecialChar ~
24224 \SpecialChar ~
24225 \SpecialChar ~
24226 \SpecialChar ~
24227 \SpecialChar ~
24228 \SpecialChar ~
24229 \SpecialChar ~
24230 \SpecialChar ~
24231  61 ;\SpecialChar ~
24232  hob.c 7 
24233 \newline 
24234 000A E5*01\SpecialChar ~
24235 \SpecialChar ~
24236 \SpecialChar ~
24237 \SpecialChar ~
24238 \SpecialChar ~
24239 \SpecialChar ~
24240 \SpecialChar ~
24241 \SpecialChar ~
24242 \SpecialChar ~
24243 \SpecialChar ~
24244 \SpecialChar ~
24245 \SpecialChar ~
24246 \SpecialChar ~
24247 \SpecialChar ~
24248 \SpecialChar ~
24249  62\SpecialChar ~
24250 \SpecialChar ~
24251 \SpecialChar ~
24252 \SpecialChar ~
24253 \SpecialChar ~
24254 \SpecialChar ~
24255 \SpecialChar ~
24256 \SpecialChar ~
24257  mov\SpecialChar ~
24258 \SpecialChar ~
24259  a,(_gint + 1) 
24260 \newline 
24261 000C 23\SpecialChar ~
24262 \SpecialChar ~
24263 \SpecialChar ~
24264 \SpecialChar ~
24265 \SpecialChar ~
24266 \SpecialChar ~
24267 \SpecialChar ~
24268 \SpecialChar ~
24269 \SpecialChar ~
24270 \SpecialChar ~
24271 \SpecialChar ~
24272 \SpecialChar ~
24273 \SpecialChar ~
24274 \SpecialChar ~
24275 \SpecialChar ~
24276 \SpecialChar ~
24277 \SpecialChar ~
24278 \SpecialChar ~
24279  63\SpecialChar ~
24280 \SpecialChar ~
24281 \SpecialChar ~
24282 \SpecialChar ~
24283 \SpecialChar ~
24284 \SpecialChar ~
24285 \SpecialChar ~
24286 \SpecialChar ~
24287  rl\SpecialChar ~
24288 \SpecialChar ~
24289 \SpecialChar ~
24290  a 
24291 \newline 
24292 000D 54 01\SpecialChar ~
24293 \SpecialChar ~
24294 \SpecialChar ~
24295 \SpecialChar ~
24296 \SpecialChar ~
24297 \SpecialChar ~
24298 \SpecialChar ~
24299 \SpecialChar ~
24300 \SpecialChar ~
24301 \SpecialChar ~
24302 \SpecialChar ~
24303 \SpecialChar ~
24304 \SpecialChar ~
24305 \SpecialChar ~
24306 \SpecialChar ~
24307  64\SpecialChar ~
24308 \SpecialChar ~
24309 \SpecialChar ~
24310 \SpecialChar ~
24311 \SpecialChar ~
24312 \SpecialChar ~
24313 \SpecialChar ~
24314 \SpecialChar ~
24315  anl\SpecialChar ~
24316 \SpecialChar ~
24317  a,#0x01 
24318 \newline 
24319 000F F5*02\SpecialChar ~
24320 \SpecialChar ~
24321 \SpecialChar ~
24322 \SpecialChar ~
24323 \SpecialChar ~
24324 \SpecialChar ~
24325 \SpecialChar ~
24326 \SpecialChar ~
24327 \SpecialChar ~
24328 \SpecialChar ~
24329 \SpecialChar ~
24330 \SpecialChar ~
24331 \SpecialChar ~
24332 \SpecialChar ~
24333 \SpecialChar ~
24334  65\SpecialChar ~
24335 \SpecialChar ~
24336 \SpecialChar ~
24337 \SpecialChar ~
24338 \SpecialChar ~
24339 \SpecialChar ~
24340 \SpecialChar ~
24341 \SpecialChar ~
24342  mov\SpecialChar ~
24343 \SpecialChar ~
24344  _foo_hob_1_1,a
24345 \layout Standard
24346
24347 Variations of this case however will 
24348 \emph on 
24349 not
24350 \emph default 
24351  be recognized.
24352  It is a standard C expression, so I heartily recommend this be the only
24353  way to get the highest order bit, (it is portable).
24354  Of course it will be recognized even if it is embedded in other expressions,
24355  e.g.:
24356 \layout Verse
24357
24358
24359 \family typewriter 
24360 xyz = gint + ((gint >> 15) & 1);
24361 \layout Standard
24362
24363 will still be recognized.
24364 \layout Subsection
24365
24366 Peephole Optimizer
24367 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
24368
24369 \end_inset 
24370
24371
24372 \begin_inset LatexCommand \index{Peephole optimizer}
24373
24374 \end_inset 
24375
24376
24377 \layout Standard
24378
24379 The compiler uses a rule based, pattern matching and re-writing mechanism
24380  for peep-hole optimization.
24381  It is inspired by 
24382 \emph on 
24383 copt
24384 \emph default 
24385  a peep-hole optimizer by Christopher W.
24386  Fraser (cwfraser\SpecialChar ~
24387 @\SpecialChar ~
24388 microsoft.com).
24389  A default set of rules are compiled into the compiler, additional rules
24390  may be added with the 
24391 \emph on 
24392 -
24393 \begin_inset ERT
24394 status Collapsed
24395
24396 \layout Standard
24397
24398 \backslash 
24399 /
24400 \end_inset 
24401
24402 -peep-file
24403 \begin_inset LatexCommand \index{-\/-peep-file}
24404
24405 \end_inset 
24406
24407  <filename>
24408 \emph default 
24409  option.
24410  The rule language is best illustrated with examples.
24411 \layout Verse
24412
24413
24414 \family typewriter 
24415 replace { 
24416 \newline 
24417 \SpecialChar ~
24418 \SpecialChar ~
24419 mov %1,a 
24420 \newline 
24421 \SpecialChar ~
24422 \SpecialChar ~
24423 mov a,%1
24424 \newline 
24425 } by {
24426 \newline 
24427 \SpecialChar ~
24428 \SpecialChar ~
24429 mov %1,a
24430 \newline 
24431 }
24432 \layout Standard
24433
24434 The above rule will change the following assembly
24435 \begin_inset LatexCommand \index{Assembler routines}
24436
24437 \end_inset 
24438
24439  sequence:
24440 \layout Verse
24441
24442
24443 \family typewriter 
24444 mov r1,a 
24445 \newline 
24446 mov a,r1
24447 \layout Standard
24448
24449 to
24450 \layout Verse
24451
24452
24453 \family typewriter 
24454 mov r1,a
24455 \layout Standard
24456
24457 Note: All occurrences of a 
24458 \emph on 
24459 %n
24460 \emph default 
24461  (pattern variable) must denote the same string.
24462  With the above rule, the assembly sequence:
24463 \layout Verse
24464
24465
24466 \family typewriter 
24467 mov r1,a 
24468 \newline 
24469 mov a,r2
24470 \layout Standard
24471
24472 will remain unmodified.
24473 \newline 
24474
24475 \newline 
24476 Other special case optimizations may be added by the user (via 
24477 \emph on 
24478 -
24479 \begin_inset ERT
24480 status Collapsed
24481
24482 \layout Standard
24483
24484 \backslash 
24485 /
24486 \end_inset 
24487
24488 -peep-file option
24489 \emph default 
24490 ).
24491  E.g.
24492  some variants of the 8051 MCU
24493 \begin_inset LatexCommand \index{MCS51 variants}
24494
24495 \end_inset 
24496
24497  allow only 
24498 \family typewriter 
24499 ajmp
24500 \family default 
24501  and 
24502 \family typewriter 
24503 acall
24504 \family default 
24505 .
24506  The following two rules will change all 
24507 \family typewriter 
24508 ljmp
24509 \family default 
24510  and 
24511 \family typewriter 
24512 lcall
24513 \family default 
24514  to 
24515 \family typewriter 
24516 ajmp
24517 \family default 
24518  and 
24519 \family typewriter 
24520 acall
24521 \layout Verse
24522
24523
24524 \family typewriter 
24525 replace { lcall %1 } by { acall %1 } 
24526 \newline 
24527 replace { ljmp %1 } by { ajmp %1 }
24528 \layout Standard
24529
24530 The 
24531 \emph on 
24532 inline-assembler code
24533 \emph default 
24534  is also passed through the peep hole optimizer, thus the peephole optimizer
24535  can also be used as an assembly level macro expander.
24536  The rules themselves are MCU dependent whereas the rule language infra-structur
24537 e is MCU independent.
24538  Peephole optimization rules for other MCU can be easily programmed using
24539  the rule language.
24540 \newline 
24541
24542 \newline 
24543 The syntax for a rule is as follows:
24544 \layout Verse
24545
24546
24547 \family typewriter 
24548 rule := replace [ restart ] '{' <assembly sequence> '
24549 \backslash 
24550 n' 
24551 \newline 
24552 \SpecialChar ~
24553  \SpecialChar ~
24554  \SpecialChar ~
24555  \SpecialChar ~
24556  \SpecialChar ~
24557  \SpecialChar ~
24558  \SpecialChar ~
24559  \SpecialChar ~
24560  \SpecialChar ~
24561  \SpecialChar ~
24562  \SpecialChar ~
24563  \SpecialChar ~
24564  \SpecialChar ~
24565  \SpecialChar ~
24566  '}' by '{' '
24567 \backslash 
24568 n' 
24569 \newline 
24570 \SpecialChar ~
24571  \SpecialChar ~
24572  \SpecialChar ~
24573  \SpecialChar ~
24574  \SpecialChar ~
24575  \SpecialChar ~
24576  \SpecialChar ~
24577  \SpecialChar ~
24578  \SpecialChar ~
24579  \SpecialChar ~
24580  \SpecialChar ~
24581  \SpecialChar ~
24582  \SpecialChar ~
24583  \SpecialChar ~
24584  \SpecialChar ~
24585  \SpecialChar ~
24586  <assembly sequence> '
24587 \backslash 
24588 n' 
24589 \newline 
24590 \SpecialChar ~
24591  \SpecialChar ~
24592  \SpecialChar ~
24593  \SpecialChar ~
24594  \SpecialChar ~
24595  \SpecialChar ~
24596  \SpecialChar ~
24597  \SpecialChar ~
24598  \SpecialChar ~
24599  \SpecialChar ~
24600  \SpecialChar ~
24601  \SpecialChar ~
24602  \SpecialChar ~
24603  \SpecialChar ~
24604  '}' [if <functionName> ] '
24605 \backslash 
24606 n' 
24607 \layout Standard
24608
24609 <assembly sequence> := assembly instruction (each instruction including
24610  labels must be on a separate line).
24611 \newline 
24612
24613 \newline 
24614 The optimizer will apply to the rules one by one from the top in the sequence
24615  of their appearance, it will terminate when all rules are exhausted.
24616  If the 'restart' option is specified, then the optimizer will start matching
24617  the rules again from the top, this option for a rule is expensive (performance)
24618 , it is intended to be used in situations where a transformation will trigger
24619  the same rule again.
24620  An example of this (not a good one, it has side effects) is the following
24621  rule:
24622 \layout Verse
24623
24624
24625 \family typewriter 
24626 replace restart { 
24627 \newline 
24628 \SpecialChar ~
24629 \SpecialChar ~
24630 pop %1 
24631 \newline 
24632 \SpecialChar ~
24633 \SpecialChar ~
24634 push %1 } by { 
24635 \newline 
24636 \SpecialChar ~
24637 \SpecialChar ~
24638 ; nop 
24639 \newline 
24640 }
24641 \layout Standard
24642
24643 Note that the replace pattern cannot be a blank, but can be a comment line.
24644  Without the 'restart' option only the innermost 'pop' 'push' pair would
24645  be eliminated, i.e.:
24646 \layout Verse
24647
24648
24649 \family typewriter 
24650 pop ar1 
24651 \newline 
24652 pop ar2 
24653 \newline 
24654 push ar2 
24655 \newline 
24656 push ar1
24657 \layout Standard
24658
24659 would result in:
24660 \layout Verse
24661
24662
24663 \family typewriter 
24664 pop ar1 
24665 \newline 
24666 ; nop 
24667 \newline 
24668 push ar1
24669 \layout Standard
24670
24671
24672 \emph on 
24673 with
24674 \emph default 
24675  the restart option the rule will be applied again to the resulting code
24676  and then all the pop-push pairs will be eliminated to yield:
24677 \layout Verse
24678
24679
24680 \family typewriter 
24681 ; nop 
24682 \newline 
24683 ; nop
24684 \layout Standard
24685
24686 A conditional function can be attached to a rule.
24687  Attaching rules are somewhat more involved, let me illustrate this with
24688  an example.
24689 \layout Verse
24690
24691
24692 \family typewriter 
24693 replace { 
24694 \newline 
24695 \SpecialChar ~
24696  \SpecialChar ~
24697  \SpecialChar ~
24698 ljmp %5 
24699 \newline 
24700 %2:
24701 \newline 
24702 } by { 
24703 \newline 
24704 \SpecialChar ~
24705  \SpecialChar ~
24706  \SpecialChar ~
24707 sjmp %5 
24708 \newline 
24709 %2:
24710 \newline 
24711 } if labelInRange
24712 \layout Standard
24713
24714 The optimizer does a look-up of a function name table defined in function
24715  
24716 \emph on 
24717 callFuncByName
24718 \emph default 
24719  in the source file SDCCpeeph.c, with the name 
24720 \emph on 
24721 labelInRange
24722 \emph default 
24723 .
24724  If it finds a corresponding entry the function is called.
24725  Note there can be no parameters specified for these functions, in this
24726  case the use of 
24727 \emph on 
24728 %5
24729 \emph default 
24730  is crucial, since the function 
24731 \emph on 
24732 labelInRange
24733 \emph default 
24734  expects to find the label in that particular variable (the hash table containin
24735 g the variable bindings is passed as a parameter).
24736  If you want to code more such functions, take a close look at the function
24737  labelInRange and the calling mechanism in source file SDCCpeeph.c.
24738  Currently implemented are 
24739 \emph on 
24740 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
24741  24bitMode, portIsDS390, 24bitModeAndPortDS390 
24742 \emph default 
24743 and
24744 \emph on 
24745  notVolatile
24746 \emph default 
24747 .
24748 \layout Standard
24749
24750 I know this whole thing is a little kludgey, but maybe some day we will
24751  have some better means.
24752  If you are looking at this file, you will see the default rules that are
24753  compiled into the compiler, you can add your own rules in the default set
24754  there if you get tired of specifying the -
24755 \begin_inset ERT
24756 status Collapsed
24757
24758 \layout Standard
24759
24760 \backslash 
24761 /
24762 \end_inset 
24763
24764 -peep-file option.
24765 \layout Section
24766
24767 ANSI-Compliance
24768 \begin_inset LatexCommand \index{ANSI-compliance}
24769
24770 \end_inset 
24771
24772
24773 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
24774
24775 \end_inset 
24776
24777
24778 \layout Standard
24779
24780 Deviations from the compliance:
24781 \layout Itemize
24782
24783 functions are not reentrant
24784 \begin_inset LatexCommand \index{reentrant}
24785
24786 \end_inset 
24787
24788  unless explicitly declared as such or the 
24789 \series bold 
24790 -
24791 \begin_inset ERT
24792 status Collapsed
24793
24794 \layout Standard
24795
24796 \backslash 
24797 /
24798 \end_inset 
24799
24800 -stack-auto
24801 \begin_inset LatexCommand \index{-\/-stack-auto}
24802
24803 \end_inset 
24804
24805
24806 \series default 
24807  command line option is specified.
24808 \layout Itemize
24809
24810 structures and unions cannot be assigned values directly, cannot be passed
24811  as function parameters or assigned to each other and cannot be a return
24812  value from a function, e.g.:
24813 \begin_deeper 
24814 \layout Verse
24815
24816
24817 \family typewriter 
24818 struct s { ...
24819  }; 
24820 \newline 
24821 struct s s1, s2; 
24822 \newline 
24823 foo() 
24824 \newline 
24825
24826 \newline 
24827 \SpecialChar ~
24828 \SpecialChar ~
24829 \SpecialChar ~
24830 \SpecialChar ~
24831 ...
24832  
24833 \newline 
24834 \SpecialChar ~
24835 \SpecialChar ~
24836 \SpecialChar ~
24837 \SpecialChar ~
24838 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
24839 \newline 
24840 \SpecialChar ~
24841 \SpecialChar ~
24842 \SpecialChar ~
24843 \SpecialChar ~
24844 ...
24845  
24846 \newline 
24847 }
24848 \newline 
24849 struct s foo1 (struct s parms) /* invalid in SDCC although allowed in ANSI
24850  */
24851 \newline 
24852
24853 \newline 
24854 \SpecialChar ~
24855 \SpecialChar ~
24856 \SpecialChar ~
24857 \SpecialChar ~
24858 struct s rets; 
24859 \newline 
24860 \SpecialChar ~
24861 \SpecialChar ~
24862 \SpecialChar ~
24863 \SpecialChar ~
24864 ...
24865  
24866 \newline 
24867 \SpecialChar ~
24868 \SpecialChar ~
24869 \SpecialChar ~
24870 \SpecialChar ~
24871 return rets;/* is invalid in SDCC although allowed in ANSI */ 
24872 \newline 
24873 }
24874 \end_deeper 
24875 \layout Itemize
24876
24877 'long long
24878 \begin_inset LatexCommand \index{long long (not supported)}
24879
24880 \end_inset 
24881
24882 ' (64 bit integers
24883 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
24884
24885 \end_inset 
24886
24887 ) not supported.
24888 \layout Itemize
24889
24890 'double
24891 \begin_inset LatexCommand \index{double (not supported)}
24892
24893 \end_inset 
24894
24895 ' precision floating point 
24896 \begin_inset LatexCommand \index{Floating point support}
24897
24898 \end_inset 
24899
24900 not supported.
24901 \layout Itemize
24902
24903 No support for setjmp
24904 \begin_inset LatexCommand \index{setjmp (not supported)}
24905
24906 \end_inset 
24907
24908  and longjmp
24909 \begin_inset LatexCommand \index{longjmp (not supported)}
24910
24911 \end_inset 
24912
24913  (for now).
24914 \layout Itemize
24915
24916 Old K&R style
24917 \begin_inset LatexCommand \index{K\&R style}
24918
24919 \end_inset 
24920
24921  function declarations are NOT allowed.
24922 \begin_deeper 
24923 \layout Verse
24924
24925
24926 \family typewriter 
24927 foo(i,j) /* this old style of function declarations */ 
24928 \newline 
24929 int i,j; /* are valid in ANSI but not valid in SDCC */ 
24930 \newline 
24931
24932 \newline 
24933 \SpecialChar ~
24934 \SpecialChar ~
24935 \SpecialChar ~
24936 \SpecialChar ~
24937 ...
24938  
24939 \newline 
24940 }
24941 \end_deeper 
24942 \layout Itemize
24943
24944 Certain words that are valid identifiers in the standard may be reserved
24945  words in SDCC unless the 
24946 \series bold 
24947 -
24948 \begin_inset ERT
24949 status Collapsed
24950
24951 \layout Standard
24952
24953 \backslash 
24954 /
24955 \end_inset 
24956
24957 -std-c89
24958 \begin_inset LatexCommand \index{-\/-std-c89}
24959
24960 \end_inset 
24961
24962  or -
24963 \begin_inset ERT
24964 status Collapsed
24965
24966 \layout Standard
24967
24968 \backslash 
24969 /
24970 \end_inset 
24971
24972 -std-c99
24973 \begin_inset LatexCommand \index{-\/-std-c99}
24974
24975 \end_inset 
24976
24977
24978 \series default 
24979  command line options are used.
24980  These may include (depending on the selected processor): 'at', 'banked',
24981  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
24982 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
24983  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
24984  '_naked'.
24985  Compliant equivalents of these keywords are always available in a form
24986  that begin with two underscores
24987 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
24988
24989 \end_inset 
24990
24991 , f.e.
24992  '__data' instead of 'data'.
24993 \layout Section
24994
24995 Cyclomatic Complexity
24996 \begin_inset LatexCommand \index{Cyclomatic complexity}
24997
24998 \end_inset 
24999
25000
25001 \layout Standard
25002
25003 Cyclomatic complexity of a function is defined as the number of independent
25004  paths the program can take during execution of the function.
25005  This is an important number since it defines the number test cases you
25006  have to generate to validate the function.
25007  The accepted industry standard for complexity number is 10, if the cyclomatic
25008  complexity reported by SDCC exceeds 10 you should think about simplification
25009  of the function logic.
25010  Note that the complexity level is not related to the number of lines of
25011  code in a function.
25012  Large functions can have low complexity, and small functions can have large
25013  complexity levels.
25014  
25015 \newline 
25016
25017 \newline 
25018 SDCC uses the following formula to compute the complexity:
25019 \newline 
25020
25021 \layout Standard
25022
25023 complexity = (number of edges in control flow graph) - (number of nodes
25024  in control flow graph) + 2;
25025 \newline 
25026
25027 \newline 
25028 Having said that the industry standard is 10, you should be aware that in
25029  some cases it be may unavoidable to have a complexity level of less than
25030  10.
25031  For example if you have switch statement with more than 10 case labels,
25032  each case label adds one to the complexity level.
25033  The complexity level is by no means an absolute measure of the algorithmic
25034  complexity of the function, it does however provide a good starting point
25035  for which functions you might look at for further optimization.
25036 \layout Section
25037
25038 Retargetting for other Processors
25039 \layout Standard
25040
25041 The issues for retargetting the compiler are far too numerous to be covered
25042  by this document.
25043  What follows is a brief description of each of the seven phases of the
25044  compiler and its MCU dependency.
25045 \layout Itemize
25046
25047 Parsing the source and building the annotated parse tree.
25048  This phase is largely MCU independent (except for the language extensions).
25049  Syntax & semantic checks are also done in this phase, along with some initial
25050  optimizations like back patching labels and the pattern matching optimizations
25051  like bit-rotation etc.
25052 \layout Itemize
25053
25054 The second phase involves generating an intermediate code which can be easy
25055  manipulated during the later phases.
25056  This phase is entirely MCU independent.
25057  The intermediate code generation assumes the target machine has unlimited
25058  number of registers, and designates them with the name iTemp.
25059  The compiler can be made to dump a human readable form of the code generated
25060  by using the -
25061 \begin_inset ERT
25062 status Collapsed
25063
25064 \layout Standard
25065
25066 \backslash 
25067 /
25068 \end_inset 
25069
25070 -dumpraw option.
25071 \layout Itemize
25072
25073 This phase does the bulk of the standard optimizations and is also MCU independe
25074 nt.
25075  This phase can be broken down into several sub-phases:
25076 \newline 
25077
25078 \newline 
25079 Break down intermediate code (iCode) into basic blocks.
25080 \newline 
25081 Do control flow & data flow analysis on the basic blocks.
25082 \newline 
25083 Do local common subexpression elimination, then global subexpression elimination
25084 \newline 
25085 Dead code elimination
25086 \newline 
25087 Loop optimizations
25088 \newline 
25089 If loop optimizations caused any changes then do 'global subexpression eliminati
25090 on' and 'dead code elimination' again.
25091 \layout Itemize
25092
25093 This phase determines the live-ranges; by live range I mean those iTemp
25094  variables defined by the compiler that still survive after all the optimization
25095 s.
25096  Live range analysis
25097 \begin_inset LatexCommand \index{Live range analysis}
25098
25099 \end_inset 
25100
25101  is essential for register allocation, since these computation determines
25102  which of these iTemps will be assigned to registers, and for how long.
25103 \layout Itemize
25104
25105 Phase five is register allocation.
25106  There are two parts to this process.
25107 \newline 
25108
25109 \newline 
25110 The first part I call 'register packing' (for lack of a better term).
25111  In this case several MCU specific expression folding is done to reduce
25112  register pressure.
25113 \newline 
25114
25115 \newline 
25116 The second part is more MCU independent and deals with allocating registers
25117  to the remaining live ranges.
25118  A lot of MCU specific code does creep into this phase because of the limited
25119  number of index registers available in the 8051.
25120 \layout Itemize
25121
25122 The Code generation phase is (unhappily), entirely MCU dependent and very
25123  little (if any at all) of this code can be reused for other MCU.
25124  However the scheme for allocating a homogenized assembler operand for each
25125  iCode operand may be reused.
25126 \layout Itemize
25127
25128 As mentioned in the optimization section the peep-hole optimizer is rule
25129  based system, which can reprogrammed for other MCUs.
25130 \layout Chapter
25131
25132 Compiler internals
25133 \begin_inset LatexCommand \index{Compiler internals}
25134
25135 \end_inset 
25136
25137
25138 \layout Section
25139
25140 The anatomy of the compiler
25141 \begin_inset LatexCommand \label{sub:The-anatomy-of}
25142
25143 \end_inset 
25144
25145
25146 \layout Standard
25147
25148
25149 \shape italic 
25150 This is an excerpt from an article published in Circuit Cellar Magazine
25151  in 
25152 \series bold 
25153 August 2000
25154 \series default 
25155 .
25156  It's a little outdated (the compiler is much more efficient now and user/develo
25157 per friendly), but pretty well exposes the guts of it all.
25158 \shape default 
25159
25160 \newline 
25161
25162 \newline 
25163 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
25164  It is fairly easy to retarget for other 8-bit MCU.
25165  Here we take a look at some of the internals of the compiler.
25166  
25167 \layout Paragraph*
25168
25169 Parsing
25170 \begin_inset LatexCommand \index{Parsing}
25171
25172 \end_inset 
25173
25174  
25175 \layout Standard
25176
25177 Parsing the input source file and creating an AST (Annotated Syntax Tree
25178 \begin_inset LatexCommand \index{Annotated syntax tree}
25179
25180 \end_inset 
25181
25182 ).
25183  This phase also involves propagating types (annotating each node of the
25184  parse tree with type information) and semantic analysis.
25185  There are some MCU specific parsing rules.
25186  For example the storage classes, the extended storage classes are MCU specific
25187  while there may be a xdata storage class for 8051 there is no such storage
25188  class for z80 or Atmel AVR.
25189  SDCC allows MCU specific storage class extensions, i.e.
25190  xdata will be treated as a storage class specifier when parsing 8051 C
25191  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
25192  C code.
25193 \layout Paragraph*
25194
25195 Generating iCode
25196 \begin_inset LatexCommand \index{iCode}
25197
25198 \end_inset 
25199
25200
25201 \layout Standard
25202
25203 Intermediate code generation.
25204  In this phase the AST is broken down into three-operand form (iCode).
25205  These three operand forms are represented as doubly linked lists.
25206  ICode is the term given to the intermediate form generated by the compiler.
25207  ICode example section shows some examples of iCode generated for some simple
25208  C source functions.
25209 \layout Paragraph*
25210
25211 Optimizations
25212 \begin_inset LatexCommand \index{Optimizations}
25213
25214 \end_inset 
25215
25216 .
25217 \layout Standard
25218
25219 Bulk of the target independent optimizations is performed in this phase.
25220  The optimizations include constant propagation, common sub-expression eliminati
25221 on, loop invariant code movement, strength reduction of loop induction variables
25222  and dead-code elimination.
25223 \layout Paragraph*
25224
25225 Live range analysis
25226 \begin_inset LatexCommand \index{Live range analysis}
25227
25228 \end_inset 
25229
25230
25231 \layout Standard
25232
25233 During intermediate code generation phase, the compiler assumes the target
25234  machine has infinite number of registers and generates a lot of temporary
25235  variables.
25236  The live range computation determines the lifetime of each of these compiler-ge
25237 nerated temporaries.
25238  A picture speaks a thousand words.
25239  ICode example sections show the live range annotations for each of the
25240  operand.
25241  It is important to note here, each iCode is assigned a number in the order
25242  of its execution in the function.
25243  The live ranges are computed in terms of these numbers.
25244  The from number is the number of the iCode which first defines the operand
25245  and the to number signifies the iCode which uses this operand last.
25246 \layout Paragraph*
25247
25248 Register Allocation
25249 \begin_inset LatexCommand \index{Register allocation}
25250
25251 \end_inset 
25252
25253
25254 \layout Standard
25255
25256 The register allocation determines the type and number of registers needed
25257  by each operand.
25258  In most MCUs only a few registers can be used for indirect addressing.
25259  In case of 8051 for example the registers R0 & R1 can be used to indirectly
25260  address the internal ram and DPTR to indirectly address the external ram.
25261  The compiler will try to allocate the appropriate register to pointer variables
25262  if it can.
25263  ICode example section shows the operands annotated with the registers assigned
25264  to them.
25265  The compiler will try to keep operands in registers as much as possible;
25266  there are several schemes the compiler uses to do achieve this.
25267  When the compiler runs out of registers the compiler will check to see
25268  if there are any live operands which is not used or defined in the current
25269  basic block being processed, if there are any found then it will push that
25270  operand and use the registers in this block, the operand will then be popped
25271  at the end of the basic block.
25272  
25273 \layout Standard
25274
25275 There are other MCU specific considerations in this phase.
25276  Some MCUs have an accumulator; very short-lived operands could be assigned
25277  to the accumulator instead of a general-purpose register.
25278 \layout Paragraph*
25279
25280 Code generation
25281 \layout Standard
25282
25283 Figure II gives a table of iCode operations supported by the compiler.
25284  The code generation involves translating these operations into corresponding
25285  assembly code for the processor.
25286  This sounds overly simple but that is the essence of code generation.
25287  Some of the iCode operations are generated on a MCU specific manner for
25288  example, the z80 port does not use registers to pass parameters so the
25289  SEND and RECV iCode operations will not be generated, and it also does
25290  not support JUMPTABLES.
25291  
25292 \newline 
25293
25294 \series bold 
25295 \shape italic 
25296 \color red
25297 <Where is Figure II?>
25298 \layout Comment
25299
25300 In the original article Figure II was announced to be downloadable on 
25301 \shape italic 
25302 Circuit Cellar
25303 \shape default 
25304 's web site.
25305  Unfortunately it never seemed to have shown up there, so: where is Figure
25306  II?
25307 \layout Paragraph*
25308
25309 ICode Example
25310 \begin_inset LatexCommand \index{iCode}
25311
25312 \end_inset 
25313
25314
25315 \layout Standard
25316
25317 This section shows some details of iCode.
25318  The example C code does not do anything useful; it is used as an example
25319  to illustrate the intermediate code generated by the compiler.
25320 \layout Verse
25321
25322
25323 \family typewriter 
25324 1.\SpecialChar ~
25325 xdata int * p;
25326 \newline 
25327 2.\SpecialChar ~
25328 int gint;
25329 \newline 
25330 3.\SpecialChar ~
25331 /* This function does nothing useful.
25332  It is used
25333 \newline 
25334 4.\SpecialChar ~
25335 \SpecialChar ~
25336 \SpecialChar ~
25337 \SpecialChar ~
25338 for the purpose of explaining iCode */
25339 \newline 
25340 5.\SpecialChar ~
25341 short function (data int *x)
25342 \newline 
25343 6.\SpecialChar ~
25344 {
25345 \newline 
25346 7.\SpecialChar ~
25347 \SpecialChar ~
25348 \SpecialChar ~
25349 short i=10; \SpecialChar ~
25350 \SpecialChar ~
25351 /* dead initialization eliminated */
25352 \newline 
25353 8.\SpecialChar ~
25354 \SpecialChar ~
25355 \SpecialChar ~
25356 short sum=10; /* dead initialization eliminated */
25357 \newline 
25358 9.\SpecialChar ~
25359 \SpecialChar ~
25360 \SpecialChar ~
25361 short mul;
25362 \newline 
25363 10.\SpecialChar ~
25364 \SpecialChar ~
25365 int j ;
25366 \newline 
25367 11.\SpecialChar ~
25368 \SpecialChar ~
25369 while (*x) *x++ = *p++; 
25370 \newline 
25371 12.\SpecialChar ~
25372 \SpecialChar ~
25373 \SpecialChar ~
25374 \SpecialChar ~
25375 sum = 0 ; 
25376 \newline 
25377 13.\SpecialChar ~
25378 \SpecialChar ~
25379 mul = 0;
25380 \newline 
25381 14.\SpecialChar ~
25382 \SpecialChar ~
25383 /* compiler detects i,j to be induction variables */
25384 \newline 
25385 15.\SpecialChar ~
25386 \SpecialChar ~
25387 for (i = 0, j = 10 ; i < 10 ; i++, j
25388 \family default 
25389 -
25390 \begin_inset ERT
25391 status Collapsed
25392
25393 \layout Standard
25394
25395 \backslash 
25396 /
25397 \end_inset 
25398
25399 -
25400 \family typewriter 
25401 ) {
25402 \newline 
25403 16.\SpecialChar ~
25404 \SpecialChar ~
25405 \SpecialChar ~
25406 \SpecialChar ~
25407 sum += i;
25408 \newline 
25409 17.\SpecialChar ~
25410 \SpecialChar ~
25411 \SpecialChar ~
25412 \SpecialChar ~
25413 mul += i * 3; \SpecialChar ~
25414 \SpecialChar ~
25415 /* this multiplication remains */
25416 \newline 
25417 18.\SpecialChar ~
25418 \SpecialChar ~
25419 \SpecialChar ~
25420 \SpecialChar ~
25421 gint += j * 3;\SpecialChar ~
25422 \SpecialChar ~
25423 /* this multiplication changed to addition */
25424 \newline 
25425 19.\SpecialChar ~
25426 \SpecialChar ~
25427 }
25428 \newline 
25429 20.\SpecialChar ~
25430 \SpecialChar ~
25431 return sum+mul;
25432 \newline 
25433 21.\SpecialChar ~
25434 }
25435 \layout Standard
25436
25437 In addition to the operands each iCode contains information about the filename
25438  and line it corresponds to in the source file.
25439  The first field in the listing should be interpreted as follows:
25440 \newline 
25441
25442 \shape italic 
25443 \size footnotesize 
25444 Filename(linenumber: iCode Execution sequence number : ICode hash table
25445  key : loop depth of the iCode).
25446 \shape default 
25447 \size default 
25448
25449 \newline 
25450 Then follows the human readable form of the ICode operation.
25451  Each operand of this triplet form can be of three basic types a) compiler
25452  generated temporary b) user defined variable c) a constant value.
25453  Note that local variables and parameters are replaced by compiler generated
25454  temporaries.
25455  Live ranges
25456 \begin_inset LatexCommand \index{Live range analysis}
25457
25458 \end_inset 
25459
25460  are computed only for temporaries (i.e.
25461  live ranges are not computed for global variables).
25462  Registers
25463 \begin_inset LatexCommand \index{Register allocation}
25464
25465 \end_inset 
25466
25467  are allocated for temporaries only.
25468  Operands are formatted in the following manner:
25469 \newline 
25470
25471 \shape italic 
25472 \size footnotesize 
25473 Operand Name [lr live-from : live-to ] { type information } [ registers
25474  allocated ].
25475 \shape default 
25476 \size default 
25477
25478 \newline 
25479 As mentioned earlier the live ranges are computed in terms of the execution
25480  sequence number of the iCodes, for example 
25481 \newline 
25482 the iTemp0 is live from (i.e.
25483  first defined in iCode with execution sequence number 3, and is last used
25484  in the iCode with sequence number 5).
25485  For induction variables such as iTemp21 the live range computation extends
25486  the lifetime from the start to the end of the loop.
25487 \newline 
25488 The register allocator used the live range information to allocate registers,
25489  the same registers may be used for different temporaries if their live
25490  ranges do not overlap, for example r0 is allocated to both iTemp6 and to
25491  iTemp17 since their live ranges do not overlap.
25492  In addition the allocator also takes into consideration the type and usage
25493  of a temporary, for example itemp6 is a pointer to near space and is used
25494  as to fetch data from (i.e.
25495  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
25496  Some short lived temporaries are allocated to special registers which have
25497  meaning to the code generator e.g.
25498  iTemp13 is allocated to a pseudo register CC which tells the back end that
25499  the temporary is used only for a conditional jump the code generation makes
25500  use of this information to optimize a compare and jump ICode.
25501 \newline 
25502 There are several loop optimizations
25503 \begin_inset LatexCommand \index{Loop optimization}
25504
25505 \end_inset 
25506
25507  performed by the compiler.
25508  It can detect induction variables iTemp21(i) and iTemp23(j).
25509  Also note the compiler does selective strength reduction
25510 \begin_inset LatexCommand \index{Strength reduction}
25511
25512 \end_inset 
25513
25514 , i.e.
25515  the multiplication of an induction variable in line 18 (gint = j * 3) is
25516  changed to addition, a new temporary iTemp17 is allocated and assigned
25517  a initial value, a constant 3 is then added for each iteration of the loop.
25518  The compiler does not change the multiplication
25519 \begin_inset LatexCommand \index{Multiplication}
25520
25521 \end_inset 
25522
25523  in line 17 however since the processor does support an 8 * 8 bit multiplication.
25524 \newline 
25525 Note the dead code elimination
25526 \begin_inset LatexCommand \index{Dead-code elimination}
25527
25528 \end_inset 
25529
25530  optimization eliminated the dead assignments in line 7 & 8 to I and sum
25531  respectively.
25532 \newline 
25533
25534 \layout Standard
25535
25536
25537 \size footnotesize 
25538 Sample.c (5:1:0:0) _entry($9) :
25539 \layout Standard
25540
25541
25542 \size footnotesize 
25543 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
25544 \layout Standard
25545
25546
25547 \size footnotesize 
25548 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
25549 \layout Standard
25550
25551
25552 \size footnotesize 
25553 Sample.c(11:4:53:0) preHeaderLbl0($11) :
25554 \layout Standard
25555
25556
25557 \size footnotesize 
25558 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
25559  * int}[r2]
25560 \layout Standard
25561
25562
25563 \size footnotesize 
25564 Sample.c(11:6:5:1) _whilecontinue_0($1) :
25565 \layout Standard
25566
25567
25568 \size footnotesize 
25569 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
25570  int}[r0]]
25571 \layout Standard
25572
25573
25574 \size footnotesize 
25575 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
25576 \layout Standard
25577
25578
25579 \size footnotesize 
25580 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
25581  * int}
25582 \layout Standard
25583
25584
25585 \size footnotesize 
25586 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
25587  {short}
25588 \layout Standard
25589
25590
25591 \size footnotesize 
25592 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
25593  * int}[DPTR]]
25594 \layout Standard
25595
25596
25597 \size footnotesize 
25598 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
25599 }[r2 r3]
25600 \layout Standard
25601
25602
25603 \size footnotesize 
25604 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
25605  * int}[r0] + 0x2 {short}
25606 \layout Standard
25607
25608
25609 \size footnotesize 
25610 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
25611 \layout Standard
25612
25613
25614 \size footnotesize 
25615 Sample.c(11:17:21:0)_whilebreak_0($3) :
25616 \layout Standard
25617
25618
25619 \size footnotesize 
25620 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
25621 \layout Standard
25622
25623
25624 \size footnotesize 
25625 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
25626 \layout Standard
25627
25628
25629 \size footnotesize 
25630 Sample.c(15:20:54:0)preHeaderLbl1($13) :
25631 \layout Standard
25632
25633
25634 \size footnotesize 
25635 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
25636 \layout Standard
25637
25638
25639 \size footnotesize 
25640 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
25641 \layout Standard
25642
25643
25644 \size footnotesize 
25645 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
25646 \layout Standard
25647
25648
25649 \size footnotesize 
25650 Sample.c(15:24:26:1)_forcond_0($4) :
25651 \layout Standard
25652
25653
25654 \size footnotesize 
25655 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
25656  < 0xa {short}
25657 \layout Standard
25658
25659
25660 \size footnotesize 
25661 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
25662 \layout Standard
25663
25664
25665 \size footnotesize 
25666 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
25667  + ITemp21 [lr21:38]{short}[r4]
25668 \layout Standard
25669
25670
25671 \size footnotesize 
25672 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
25673  * 0x3 {short}
25674 \layout Standard
25675
25676
25677 \size footnotesize 
25678 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
25679  + iTemp15 [lr29:30]{short}[r1]
25680 \layout Standard
25681
25682
25683 \size footnotesize 
25684 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
25685  r0]- 0x3 {short}
25686 \layout Standard
25687
25688
25689 \size footnotesize 
25690 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
25691 int}[r7 r0]
25692 \layout Standard
25693
25694
25695 \size footnotesize 
25696 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
25697  + 0x1 {short}
25698 \layout Standard
25699
25700
25701 \size footnotesize 
25702 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
25703  r6]- 0x1 {short}
25704 \layout Standard
25705
25706
25707 \size footnotesize 
25708 Sample.c(19:38:47:1) goto _forcond_0($4)
25709 \layout Standard
25710
25711
25712 \size footnotesize 
25713 Sample.c(19:39:48:0)_forbreak_0($7) :
25714 \layout Standard
25715
25716
25717 \size footnotesize 
25718 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
25719  + ITemp11 [lr19:40]{short}[r3]
25720 \layout Standard
25721
25722
25723 \size footnotesize 
25724 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
25725 \layout Standard
25726
25727
25728 \size footnotesize 
25729 Sample.c(20:42:51:0)_return($8) :
25730 \layout Standard
25731
25732
25733 \size footnotesize 
25734 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
25735 \size default 
25736
25737 \newline 
25738
25739 \newline 
25740 Finally the code generated for this function:
25741 \newline 
25742
25743 \layout Standard
25744
25745
25746 \size footnotesize 
25747 .area DSEG (DATA)
25748 \layout Standard
25749
25750
25751 \size footnotesize 
25752 _p::
25753 \layout Standard
25754
25755
25756 \size footnotesize 
25757 \SpecialChar ~
25758 \SpecialChar ~
25759 .ds 2
25760 \layout Standard
25761
25762
25763 \size footnotesize 
25764 _gint::
25765 \layout Standard
25766
25767
25768 \size footnotesize 
25769 \SpecialChar ~
25770 \SpecialChar ~
25771 .ds 2
25772 \layout Standard
25773
25774
25775 \size footnotesize 
25776 ; sample.c 5
25777 \layout Standard
25778
25779
25780 \size footnotesize 
25781 ; ----------------------------------------------
25782 \layout Standard
25783
25784
25785 \size footnotesize 
25786 ; function function
25787 \layout Standard
25788
25789
25790 \size footnotesize 
25791 ; ----------------------------------------------
25792 \layout Standard
25793
25794
25795 \size footnotesize 
25796 _function:
25797 \layout Standard
25798
25799
25800 \size footnotesize 
25801 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
25802 \layout Standard
25803
25804
25805 \size footnotesize 
25806 \SpecialChar ~
25807 \SpecialChar ~
25808 mov r2,dpl
25809 \layout Standard
25810
25811
25812 \size footnotesize 
25813 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
25814 \layout Standard
25815
25816
25817 \size footnotesize 
25818 \SpecialChar ~
25819 \SpecialChar ~
25820 mov ar0,r2
25821 \layout Standard
25822
25823
25824 \size footnotesize 
25825 ;_whilecontinue_0($1) :
25826 \layout Standard
25827
25828
25829 \size footnotesize 
25830 00101$:
25831 \layout Standard
25832
25833
25834 \size footnotesize 
25835 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
25836 \layout Standard
25837
25838
25839 \size footnotesize 
25840 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
25841 \layout Standard
25842
25843
25844 \size footnotesize 
25845 \SpecialChar ~
25846 \SpecialChar ~
25847 mov ar2,@r0
25848 \layout Standard
25849
25850
25851 \size footnotesize 
25852 \SpecialChar ~
25853 \SpecialChar ~
25854 inc r0
25855 \layout Standard
25856
25857
25858 \size footnotesize 
25859 \SpecialChar ~
25860 \SpecialChar ~
25861 mov ar3,@r0
25862 \layout Standard
25863
25864
25865 \size footnotesize 
25866 \SpecialChar ~
25867 \SpecialChar ~
25868 dec r0
25869 \layout Standard
25870
25871
25872 \size footnotesize 
25873 \SpecialChar ~
25874 \SpecialChar ~
25875 mov a,r2
25876 \layout Standard
25877
25878
25879 \size footnotesize 
25880 \SpecialChar ~
25881 \SpecialChar ~
25882 orl a,r3
25883 \layout Standard
25884
25885
25886 \size footnotesize 
25887 \SpecialChar ~
25888 \SpecialChar ~
25889 jz 00103$
25890 \layout Standard
25891
25892
25893 \size footnotesize 
25894 00114$:
25895 \layout Standard
25896
25897
25898 \size footnotesize 
25899 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
25900 \layout Standard
25901
25902
25903 \size footnotesize 
25904 \SpecialChar ~
25905 \SpecialChar ~
25906 mov dpl,_p
25907 \layout Standard
25908
25909
25910 \size footnotesize 
25911 \SpecialChar ~
25912 \SpecialChar ~
25913 mov dph,(_p + 1)
25914 \layout Standard
25915
25916
25917 \size footnotesize 
25918 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
25919 \layout Standard
25920
25921
25922 \size footnotesize 
25923 \SpecialChar ~
25924 \SpecialChar ~
25925 mov a,#0x02
25926 \layout Standard
25927
25928
25929 \size footnotesize 
25930 \SpecialChar ~
25931 \SpecialChar ~
25932 add a,_p
25933 \layout Standard
25934
25935
25936 \size footnotesize 
25937 \SpecialChar ~
25938 \SpecialChar ~
25939 mov _p,a
25940 \layout Standard
25941
25942
25943 \size footnotesize 
25944 \SpecialChar ~
25945 \SpecialChar ~
25946 clr a
25947 \layout Standard
25948
25949
25950 \size footnotesize 
25951 \SpecialChar ~
25952 \SpecialChar ~
25953 addc a,(_p + 1)
25954 \layout Standard
25955
25956
25957 \size footnotesize 
25958 \SpecialChar ~
25959 \SpecialChar ~
25960 mov (_p + 1),a
25961 \layout Standard
25962
25963
25964 \size footnotesize 
25965 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
25966 \layout Standard
25967
25968
25969 \size footnotesize 
25970 \SpecialChar ~
25971 \SpecialChar ~
25972 movx a,@dptr
25973 \layout Standard
25974
25975
25976 \size footnotesize 
25977 \SpecialChar ~
25978 \SpecialChar ~
25979 mov r2,a
25980 \layout Standard
25981
25982
25983 \size footnotesize 
25984 \SpecialChar ~
25985 \SpecialChar ~
25986 inc dptr
25987 \layout Standard
25988
25989
25990 \size footnotesize 
25991 \SpecialChar ~
25992 \SpecialChar ~
25993 movx a,@dptr
25994 \layout Standard
25995
25996
25997 \size footnotesize 
25998 \SpecialChar ~
25999 \SpecialChar ~
26000 mov r3,a
26001 \layout Standard
26002
26003
26004 \size footnotesize 
26005 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
26006 \layout Standard
26007
26008
26009 \size footnotesize 
26010 \SpecialChar ~
26011 \SpecialChar ~
26012 mov @r0,ar2
26013 \layout Standard
26014
26015
26016 \size footnotesize 
26017 \SpecialChar ~
26018 \SpecialChar ~
26019 inc r0
26020 \layout Standard
26021
26022
26023 \size footnotesize 
26024 \SpecialChar ~
26025 \SpecialChar ~
26026 mov @r0,ar3
26027 \layout Standard
26028
26029
26030 \size footnotesize 
26031 ; iTemp6 [lr5:16]{_near * int}[r0] = 
26032 \layout Standard
26033
26034
26035 \size footnotesize 
26036 ; iTemp6 [lr5:16]{_near * int}[r0] + 
26037 \layout Standard
26038
26039
26040 \size footnotesize 
26041 ; 0x2 {short}
26042 \layout Standard
26043
26044
26045 \size footnotesize 
26046 \SpecialChar ~
26047 \SpecialChar ~
26048 inc r0
26049 \layout Standard
26050
26051
26052 \size footnotesize 
26053 ; goto _whilecontinue_0($1)
26054 \layout Standard
26055
26056
26057 \size footnotesize 
26058 \SpecialChar ~
26059 \SpecialChar ~
26060 sjmp 00101$
26061 \layout Standard
26062
26063
26064 \size footnotesize 
26065 ; _whilebreak_0($3) :
26066 \layout Standard
26067
26068
26069 \size footnotesize 
26070 00103$:
26071 \layout Standard
26072
26073
26074 \size footnotesize 
26075 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
26076 \layout Standard
26077
26078
26079 \size footnotesize 
26080 \SpecialChar ~
26081 \SpecialChar ~
26082 mov r2,#0x00
26083 \layout Standard
26084
26085
26086 \size footnotesize 
26087 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
26088 \layout Standard
26089
26090
26091 \size footnotesize 
26092 \SpecialChar ~
26093 \SpecialChar ~
26094 mov r3,#0x00
26095 \layout Standard
26096
26097
26098 \size footnotesize 
26099 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
26100 \layout Standard
26101
26102
26103 \size footnotesize 
26104 \SpecialChar ~
26105 \SpecialChar ~
26106 mov r4,#0x00
26107 \layout Standard
26108
26109
26110 \size footnotesize 
26111 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
26112 \layout Standard
26113
26114
26115 \size footnotesize 
26116 \SpecialChar ~
26117 \SpecialChar ~
26118 mov r5,#0x0A
26119 \layout Standard
26120
26121
26122 \size footnotesize 
26123 \SpecialChar ~
26124 \SpecialChar ~
26125 mov r6,#0x00
26126 \layout Standard
26127
26128
26129 \size footnotesize 
26130 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
26131 \layout Standard
26132
26133
26134 \size footnotesize 
26135 \SpecialChar ~
26136 \SpecialChar ~
26137 mov r7,#0x1E
26138 \layout Standard
26139
26140
26141 \size footnotesize 
26142 \SpecialChar ~
26143 \SpecialChar ~
26144 mov r0,#0x00
26145 \layout Standard
26146
26147
26148 \size footnotesize 
26149 ; _forcond_0($4) :
26150 \layout Standard
26151
26152
26153 \size footnotesize 
26154 00104$:
26155 \layout Standard
26156
26157
26158 \size footnotesize 
26159 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
26160 \layout Standard
26161
26162
26163 \size footnotesize 
26164 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
26165 \layout Standard
26166
26167
26168 \size footnotesize 
26169 \SpecialChar ~
26170 \SpecialChar ~
26171 clr c
26172 \layout Standard
26173
26174
26175 \size footnotesize 
26176 \SpecialChar ~
26177 \SpecialChar ~
26178 mov a,r4
26179 \layout Standard
26180
26181
26182 \size footnotesize 
26183 \SpecialChar ~
26184 \SpecialChar ~
26185 xrl a,#0x80
26186 \layout Standard
26187
26188
26189 \size footnotesize 
26190 \SpecialChar ~
26191 \SpecialChar ~
26192 subb a,#0x8a
26193 \layout Standard
26194
26195
26196 \size footnotesize 
26197 \SpecialChar ~
26198 \SpecialChar ~
26199 jnc 00107$
26200 \layout Standard
26201
26202
26203 \size footnotesize 
26204 00115$:
26205 \layout Standard
26206
26207
26208 \size footnotesize 
26209 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
26210 \layout Standard
26211
26212
26213 \size footnotesize 
26214 ; iTemp21 [lr21:38]{short}[r4]
26215 \layout Standard
26216
26217
26218 \size footnotesize 
26219 \SpecialChar ~
26220 \SpecialChar ~
26221 mov a,r4
26222 \layout Standard
26223
26224
26225 \size footnotesize 
26226 \SpecialChar ~
26227 \SpecialChar ~
26228 add a,r2
26229 \layout Standard
26230
26231
26232 \size footnotesize 
26233 \SpecialChar ~
26234 \SpecialChar ~
26235 mov r2,a
26236 \layout Standard
26237
26238
26239 \size footnotesize 
26240 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
26241 \layout Standard
26242
26243
26244 \size footnotesize 
26245 \SpecialChar ~
26246 \SpecialChar ~
26247 mov b,#0x03
26248 \layout Standard
26249
26250
26251 \size footnotesize 
26252 \SpecialChar ~
26253 \SpecialChar ~
26254 mov a,r4
26255 \layout Standard
26256
26257
26258 \size footnotesize 
26259 \SpecialChar ~
26260 \SpecialChar ~
26261 mul ab
26262 \layout Standard
26263
26264
26265 \size footnotesize 
26266 \SpecialChar ~
26267 \SpecialChar ~
26268 mov r1,a
26269 \layout Standard
26270
26271
26272 \size footnotesize 
26273 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
26274 \layout Standard
26275
26276
26277 \size footnotesize 
26278 ; iTemp15 [lr29:30]{short}[r1]
26279 \layout Standard
26280
26281
26282 \size footnotesize 
26283 \SpecialChar ~
26284 \SpecialChar ~
26285 add a,r3
26286 \layout Standard
26287
26288
26289 \size footnotesize 
26290 \SpecialChar ~
26291 \SpecialChar ~
26292 mov r3,a
26293 \layout Standard
26294
26295
26296 \size footnotesize 
26297 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
26298 \layout Standard
26299
26300
26301 \size footnotesize 
26302 \SpecialChar ~
26303 \SpecialChar ~
26304 mov a,r7
26305 \layout Standard
26306
26307
26308 \size footnotesize 
26309 \SpecialChar ~
26310 \SpecialChar ~
26311 add a,#0xfd
26312 \layout Standard
26313
26314
26315 \size footnotesize 
26316 \SpecialChar ~
26317 \SpecialChar ~
26318 mov r7,a
26319 \layout Standard
26320
26321
26322 \size footnotesize 
26323 \SpecialChar ~
26324 \SpecialChar ~
26325 mov a,r0
26326 \layout Standard
26327
26328
26329 \size footnotesize 
26330 \SpecialChar ~
26331 \SpecialChar ~
26332 addc a,#0xff
26333 \layout Standard
26334
26335
26336 \size footnotesize 
26337 \SpecialChar ~
26338 \SpecialChar ~
26339 mov r0,a
26340 \layout Standard
26341
26342
26343 \size footnotesize 
26344 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
26345 \layout Standard
26346
26347
26348 \size footnotesize 
26349 \SpecialChar ~
26350 \SpecialChar ~
26351 mov a,r7
26352 \layout Standard
26353
26354
26355 \size footnotesize 
26356 \SpecialChar ~
26357 \SpecialChar ~
26358 add a,_gint
26359 \layout Standard
26360
26361
26362 \size footnotesize 
26363 \SpecialChar ~
26364 \SpecialChar ~
26365 mov _gint,a
26366 \layout Standard
26367
26368
26369 \size footnotesize 
26370 \SpecialChar ~
26371 \SpecialChar ~
26372 mov a,r0
26373 \layout Standard
26374
26375
26376 \size footnotesize 
26377 \SpecialChar ~
26378 \SpecialChar ~
26379 addc a,(_gint + 1)
26380 \layout Standard
26381
26382
26383 \size footnotesize 
26384 \SpecialChar ~
26385 \SpecialChar ~
26386 mov (_gint + 1),a
26387 \layout Standard
26388
26389
26390 \size footnotesize 
26391 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
26392 \layout Standard
26393
26394
26395 \size footnotesize 
26396 \SpecialChar ~
26397 \SpecialChar ~
26398 inc r4
26399 \layout Standard
26400
26401
26402 \size footnotesize 
26403 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
26404 \layout Standard
26405
26406
26407 \size footnotesize 
26408 \SpecialChar ~
26409 \SpecialChar ~
26410 dec r5
26411 \layout Standard
26412
26413
26414 \size footnotesize 
26415 \SpecialChar ~
26416 \SpecialChar ~
26417 cjne r5,#0xff,00104$
26418 \layout Standard
26419
26420
26421 \size footnotesize 
26422 \SpecialChar ~
26423 \SpecialChar ~
26424 dec r6
26425 \layout Standard
26426
26427
26428 \size footnotesize 
26429 ; goto _forcond_0($4)
26430 \layout Standard
26431
26432
26433 \size footnotesize 
26434 \SpecialChar ~
26435 \SpecialChar ~
26436 sjmp 00104$
26437 \layout Standard
26438
26439
26440 \size footnotesize 
26441 ; _forbreak_0($7) :
26442 \layout Standard
26443
26444
26445 \size footnotesize 
26446 00107$:
26447 \layout Standard
26448
26449
26450 \size footnotesize 
26451 ; ret iTemp24 [lr40:41]{short}
26452 \layout Standard
26453
26454
26455 \size footnotesize 
26456 \SpecialChar ~
26457 \SpecialChar ~
26458 mov a,r3
26459 \layout Standard
26460
26461
26462 \size footnotesize 
26463 \SpecialChar ~
26464 \SpecialChar ~
26465 add a,r2
26466 \layout Standard
26467
26468
26469 \size footnotesize 
26470 \SpecialChar ~
26471 \SpecialChar ~
26472 mov dpl,a
26473 \layout Standard
26474
26475
26476 \size footnotesize 
26477 ; _return($8) :
26478 \layout Standard
26479
26480
26481 \size footnotesize 
26482 00108$:
26483 \layout Standard
26484
26485
26486 \size footnotesize 
26487 \SpecialChar ~
26488 \SpecialChar ~
26489 ret
26490 \newline 
26491
26492 \layout Section
26493
26494 A few words about basic block successors, predecessors and dominators
26495 \layout Standard
26496
26497 Successors are basic blocks
26498 \begin_inset LatexCommand \index{Basic blocks}
26499
26500 \end_inset 
26501
26502  that might execute after this basic block.
26503 \newline 
26504 Predecessors are basic blocks that might execute before reaching this basic
26505  block.
26506 \newline 
26507 Dominators are basic blocks that WILL execute before reaching this basic
26508  block.
26509 \newline 
26510
26511 \layout Standard
26512
26513 [basic block 1]
26514 \layout Standard
26515
26516 if (something)
26517 \layout Standard
26518
26519 \SpecialChar ~
26520 \SpecialChar ~
26521 \SpecialChar ~
26522 \SpecialChar ~
26523 [basic block 2]
26524 \layout Standard
26525
26526 else
26527 \layout Standard
26528
26529 \SpecialChar ~
26530 \SpecialChar ~
26531 \SpecialChar ~
26532 \SpecialChar ~
26533 [basic block 3]
26534 \layout Standard
26535
26536 [basic block 4]
26537 \newline 
26538
26539 \layout Standard
26540
26541 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
26542 \layout Standard
26543
26544 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
26545 \layout Standard
26546
26547 c) domVect of [BB4] = BB1 ...
26548  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
26549  was executed.
26550 \layout Chapter
26551
26552 Acknowledgments
26553 \layout Standard
26554
26555
26556 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
26557
26558 \end_inset 
26559
26560
26561 \newline 
26562
26563 \newline 
26564
26565 \emph on 
26566 Thanks to all the other volunteer developers who have helped with coding,
26567  testing, web-page creation, distribution sets, etc.
26568  You know who you are :-)
26569 \emph default 
26570
26571 \newline 
26572
26573 \layout Standard
26574
26575 This document was initially written by Sandeep Dutta
26576 \layout Standard
26577
26578 All product names mentioned herein may be trademarks
26579 \begin_inset LatexCommand \index{Trademarks}
26580
26581 \end_inset 
26582
26583  of their respective companies.
26584  
26585 \layout Section*
26586
26587 Alphabetical index
26588 \layout Standard
26589
26590 To avoid confusion, the installation and building options for SDCC itself
26591  (chapter 2) are not part of the index.
26592 \layout Standard
26593
26594
26595 \begin_inset LatexCommand \printindex{}
26596
26597 \end_inset 
26598
26599
26600 \the_end