* device/lib/Makefile.in: fixed to enable port-specific-objects
[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.4
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  SDCDB and ucSim are currently not available on Win32 platforms.
249  
250 \newline 
251
252 \newline 
253 The latest version can be downloaded from 
254 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
255
256 \end_inset 
257
258 .
259
260 \series bold 
261  
262 \series default 
263 \emph on 
264 Please note: the compiler will probably always be some steps ahead of this
265  documentation
266 \series bold 
267 \emph default 
268
269 \begin_inset LatexCommand \index{Status of documentation}
270
271 \end_inset 
272
273
274 \begin_inset Foot
275 collapsed false
276
277 \layout Standard
278
279 Obviously this has pros and cons
280 \end_inset 
281
282 .
283 \layout Section
284
285 Open Source
286 \layout Standard
287
288 All packages used in this compiler system are 
289 \emph on 
290 open source
291 \emph default 
292  and 
293 \emph on 
294 freeware
295 \emph default 
296 ; source code for all the sub-packages (pre-processor, assemblers, linkers
297  etc) is distributed with the package.
298  This documentation is maintained using a freeware word processor (LyX).
299 \newline 
300 This program is free software; you can redistribute it and/or modify it
301  under the terms of the GNU General Public License
302 \begin_inset LatexCommand \index{GNU General Public License, GPL}
303
304 \end_inset 
305
306  as published by the Free Software Foundation; either version 2, or (at
307  your option) any later version.
308  This program is distributed in the hope that it will be useful, but WITHOUT
309  ANY WARRANTY; without even the implied warranty
310 \begin_inset LatexCommand \index{warranty}
311
312 \end_inset 
313
314  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
315  See the GNU General Public License for more details.
316  You should have received a copy of the GNU General Public License along
317  with this program; if not, write to the Free Software Foundation, 59 Temple
318  Place - Suite 330, Boston, MA 02111-1307, USA.
319  In other words, you are welcome to use, share and improve this program.
320  You are forbidden to forbid anyone else to use, share and improve what
321  you give them.
322  Help stamp out software-hoarding! 
323 \layout Section
324
325 Typographic conventions
326 \begin_inset LatexCommand \index{Typographic conventions}
327
328 \end_inset 
329
330
331 \layout Standard
332
333 Throughout this manual, we will use the following convention.
334  Commands you have to type in are printed in 
335 \family sans 
336 \series bold 
337 "sans serif"
338 \series default 
339 .
340
341 \family default 
342  Code samples are printed in 
343 \family typewriter 
344 typewriter font.
345
346 \family default 
347  Interesting items and new terms are printed in 
348 \emph on 
349 italic.
350 \layout Section
351
352 Compatibility with previous versions
353 \begin_inset LatexCommand \index{Compatibility with previous versions}
354
355 \end_inset 
356
357
358 \layout Standard
359
360 This version has numerous bug fixes compared with the previous version.
361  But we also introduced some incompatibilities with older versions.
362  Not just for the fun of it, but to make the compiler more stable, efficient
363  and ANSI compliant
364 \begin_inset LatexCommand \index{ANSI-compliance}
365
366 \end_inset 
367
368  (see section 
369 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
370
371 \end_inset 
372
373  for ANSI-Compliance).
374  
375 \newline 
376
377 \layout Itemize
378
379 short is now equivalent to int (16 bits), it used to be equivalent to char
380  (8 bits) which is not ANSI compliant.
381 \layout Itemize
382
383 the default directory for gcc-builds where include, library and documentation
384  files are stored is now in /usr/local/share.
385 \layout Itemize
386
387 char type parameters to vararg functions are casted to int unless explicitly
388  casted, e.g.: 
389 \newline 
390
391 \family typewriter 
392 \SpecialChar ~
393 \SpecialChar ~
394 char a=3;
395 \newline 
396 \SpecialChar ~
397 \SpecialChar ~
398 printf ("%d %c
399 \backslash 
400 n", a, (char)a);
401 \family default 
402
403 \newline 
404  will push a as an int and as a char resp.
405 \layout Itemize
406
407 option -
408 \begin_inset ERT
409 status Collapsed
410
411 \layout Standard
412
413 \backslash 
414 /
415 \end_inset 
416
417 -regextend has been removed.
418 \layout Itemize
419
420 option -
421 \begin_inset ERT
422 status Collapsed
423
424 \layout Standard
425
426 \backslash 
427 /
428 \end_inset 
429
430 -noregparms has been removed.
431 \layout Itemize
432
433 option -
434 \begin_inset ERT
435 status Collapsed
436
437 \layout Standard
438
439 \backslash 
440 /
441 \end_inset 
442
443 -stack-after-data has been removed.
444 \layout Itemize
445
446 bit
447 \begin_inset LatexCommand \index{bit}
448
449 \end_inset 
450
451  and sbit
452 \begin_inset LatexCommand \index{sbit}
453
454 \end_inset 
455
456
457 \begin_inset LatexCommand \index{\_\_sbit}
458
459 \end_inset 
460
461  types now consistently behave like the C99 _Bool type with respect to type
462  conversion
463 \begin_inset LatexCommand \index{type conversion}
464
465 \end_inset 
466
467
468 \begin_inset LatexCommand \index{type promotion}
469
470 \end_inset 
471
472 .
473  The most common incompatibility resulting from this change is related to
474  bit toggling
475 \begin_inset LatexCommand \index{Bit toggling}
476
477 \end_inset 
478
479  idioms, e.g.:
480 \newline 
481
482 \family typewriter 
483 \SpecialChar ~
484 \SpecialChar ~
485 bit b;
486 \newline 
487 \SpecialChar ~
488 \SpecialChar ~
489 b = ~b; /* equivalent to b=1 instead of toggling b */
490 \newline 
491 \SpecialChar ~
492 \SpecialChar ~
493 b = !b; /* toggles b */
494 \newline 
495
496 \family default 
497 In previous versions, both forms would have toggled the bit.
498 \layout Standard
499
500
501 \emph on 
502 <pending: more incompatibilities?>
503 \layout Section
504
505 System Requirements
506 \layout Standard
507
508 What do you need before you start installation of SDCC? A computer, and
509  a desire to compute.
510  The preferred method of installation is to compile SDCC from source using
511  GNU gcc and make.
512  For Windows some pre-compiled binary distributions are available for your
513  convenience.
514  You should have some experience with command line tools and compiler use.
515 \layout Section
516
517 Other Resources
518 \layout Standard
519
520 The SDCC home page at 
521 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
522
523 \end_inset 
524
525  is a great place to find distribution sets.
526  You can also find links to the user mailing lists that offer help or discuss
527  SDCC with other SDCC users.
528  Web links to other SDCC related sites can also be found here.
529  This document can be found in the DOC directory of the source package as
530  a text or HTML file.
531  A pdf version of this document is available at 
532 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
533
534 \end_inset 
535
536 .
537  Some of the other tools (simulator and assembler) included with SDCC contain
538  their own documentation and can be found in the source distribution.
539  If you want the latest unreleased software, the complete source package
540  is available directly by anonymous CVS on cvs.sdcc.sourceforge.net.
541 \layout Section
542
543 Wishes for the future
544 \layout Standard
545
546 There are (and always will be) some things that could be done.
547  Here are some I can think of:
548 \newline 
549
550 \layout Standard
551
552
553 \family typewriter 
554 char KernelFunction3(char p) at 0x340;
555 \newline 
556
557 \layout Standard
558
559
560 \family typewriter 
561 better code banking
562 \begin_inset LatexCommand \index{code banking (limited support)}
563
564 \end_inset 
565
566  support for mcs51
567 \newline 
568
569 \newline 
570
571 \family default 
572 If you can think of some more, please see the section 
573 \begin_inset LatexCommand \ref{sub:Requesting-Features}
574
575 \end_inset 
576
577  about filing feature requests
578 \begin_inset LatexCommand \index{Requesting features}
579
580 \end_inset 
581
582
583 \begin_inset LatexCommand \index{Feature request}
584
585 \end_inset 
586
587 .
588 \newline 
589
590 \layout Chapter
591
592 Installing SDCC
593 \begin_inset LatexCommand \index{Installation}
594
595 \end_inset 
596
597
598 \layout Standard
599
600 For most users it is sufficient to skip to either section 
601 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
602
603 \end_inset 
604
605  or section 
606 \begin_inset LatexCommand \ref{sub:Windows-Install}
607
608 \end_inset 
609
610 .
611  More detailled instructions follow below.
612 \layout Section
613
614 Configure Options
615 \begin_inset LatexCommand \index{Options SDCC configuration}
616
617 \end_inset 
618
619
620 \layout Standard
621
622 The install paths, search paths and other options are defined when running
623  'configure'.
624  The defaults can be overridden by:
625 \layout List
626 \labelwidthstring 00.00.0000
627
628 -
629 \begin_inset ERT
630 status Collapsed
631
632 \layout Standard
633
634 \backslash 
635 /
636 \end_inset 
637
638 -prefix see table below
639 \layout List
640 \labelwidthstring 00.00.0000
641
642 -
643 \begin_inset ERT
644 status Collapsed
645
646 \layout Standard
647
648 \backslash 
649 /
650 \end_inset 
651
652 -exec_prefix see table below
653 \layout List
654 \labelwidthstring 00.00.0000
655
656 -
657 \begin_inset ERT
658 status Collapsed
659
660 \layout Standard
661
662 \backslash 
663 /
664 \end_inset 
665
666 -bindir see table below
667 \layout List
668 \labelwidthstring 00.00.0000
669
670 -
671 \begin_inset ERT
672 status Collapsed
673
674 \layout Standard
675
676 \backslash 
677 /
678 \end_inset 
679
680 -datadir see table below
681 \layout List
682 \labelwidthstring 00.00.0000
683
684 docdir environment variable, see table below
685 \layout List
686 \labelwidthstring 00.00.0000
687
688 include_dir_suffix environment variable, see table below
689 \layout List
690 \labelwidthstring 00.00.0000
691
692 lib_dir_suffix environment variable, see table below
693 \layout List
694 \labelwidthstring 00.00.0000
695
696 sdccconf_h_dir_separator environment variable, either / or 
697 \backslash 
698
699 \backslash 
700  makes sense here.
701  This character will only be used in sdccconf.h; don't forget it's a C-header,
702  therefore a double-backslash is needed there.
703 \layout List
704 \labelwidthstring 00.00.0000
705
706 -
707 \begin_inset ERT
708 status Collapsed
709
710 \layout Standard
711
712 \backslash 
713 /
714 \end_inset 
715
716 -disable-mcs51-port Excludes the Intel mcs51 port
717 \layout List
718 \labelwidthstring 00.00.0000
719
720 -
721 \begin_inset ERT
722 status Collapsed
723
724 \layout Standard
725
726 \backslash 
727 /
728 \end_inset 
729
730 -disable-gbz80-port Excludes the Gameboy gbz80 port
731 \layout List
732 \labelwidthstring 00.00.0000
733
734 -
735 \begin_inset ERT
736 status Collapsed
737
738 \layout Standard
739
740 \backslash 
741 /
742 \end_inset 
743
744 -disable-z80-port Excludes the z80 port
745 \layout List
746 \labelwidthstring 00.00.0000
747
748 -
749 \begin_inset ERT
750 status Collapsed
751
752 \layout Standard
753
754 \backslash 
755 /
756 \end_inset 
757
758 -disable-avr-port Excludes the AVR port
759 \layout List
760 \labelwidthstring 00.00.0000
761
762 -
763 \begin_inset ERT
764 status Collapsed
765
766 \layout Standard
767
768 \backslash 
769 /
770 \end_inset 
771
772 -disable-ds390-port Excludes the DS390 port
773 \layout List
774 \labelwidthstring 00.00.0000
775
776 -
777 \begin_inset ERT
778 status Collapsed
779
780 \layout Standard
781
782 \backslash 
783 /
784 \end_inset 
785
786 -disable-hc08-port Excludes the HC08 port
787 \layout List
788 \labelwidthstring 00.00.0000
789
790 -
791 \begin_inset ERT
792 status Collapsed
793
794 \layout Standard
795
796 \backslash 
797 /
798 \end_inset 
799
800 -disable-pic-port Excludes the PIC port
801 \layout List
802 \labelwidthstring 00.00.0000
803
804 -
805 \begin_inset ERT
806 status Collapsed
807
808 \layout Standard
809
810 \backslash 
811 /
812 \end_inset 
813
814 -disable-xa51-port Excludes the XA51 port
815 \layout List
816 \labelwidthstring 00.00.0000
817
818 -
819 \begin_inset ERT
820 status Collapsed
821
822 \layout Standard
823
824 \backslash 
825 /
826 \end_inset 
827
828 -disable-ucsim Disables configuring and building of ucsim
829 \layout List
830 \labelwidthstring 00.00.0000
831
832 -
833 \begin_inset ERT
834 status Collapsed
835
836 \layout Standard
837
838 \backslash 
839 /
840 \end_inset 
841
842 -disable-device-lib-build Disables automatically building device libraries
843 \layout List
844 \labelwidthstring 00.00.0000
845
846 -
847 \begin_inset ERT
848 status Collapsed
849
850 \layout Standard
851
852 \backslash 
853 /
854 \end_inset 
855
856 -disable-packihx Disables building packihx
857 \layout List
858 \labelwidthstring 00.00.0000
859
860 -
861 \begin_inset ERT
862 status Collapsed
863
864 \layout Standard
865
866 \backslash 
867 /
868 \end_inset 
869
870 -enable-libgc Use the Bohem memory allocator.
871  Lower runtime footprint.
872 \layout Standard
873
874 Furthermore the environment variables CC, CFLAGS, ...
875  the tools and their arguments can be influenced.
876  Please see `configure -
877 \begin_inset ERT
878 status Collapsed
879
880 \layout Standard
881
882 \backslash 
883 /
884 \end_inset 
885
886 -help` and the man/info pages of `configure` for details.
887 \newline 
888
889 \newline 
890 The names of the standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB,
891  STD_FP_LIB, STD_DS390_LIB, STD_XA51_LIB and the environment variables SDCC_DIR_
892 NAME, SDCC_INCLUDE_NAME, SDCC_LIB_NAME are defined by `configure` too.
893  At the moment it's not possible to change the default settings (it was
894  simply never required).
895 \newline 
896
897 \newline 
898 These configure options are compiled into the binaries, and can only be
899  changed by rerunning 'configure' and recompiling SDCC.
900  The configure options are written in 
901 \emph on 
902 italics
903 \emph default 
904  to distinguish them from run time environment variables (see section search
905  paths).
906 \newline 
907
908 \newline 
909 The settings for 
910 \begin_inset Quotes sld
911 \end_inset 
912
913 Win32 builds
914 \begin_inset Quotes srd
915 \end_inset 
916
917  are used by the SDCC team to build the official Win32 binaries.
918  The SDCC team uses Mingw32 to build the official Windows binaries, because
919  it's
920 \layout Enumerate
921
922 open source, 
923 \layout Enumerate
924
925 a gcc compiler and last but not least
926 \layout Enumerate
927
928 the binaries can be built by cross compiling on Sourceforge's compile farm.
929 \layout Standard
930
931 See the examples, how to pass the Win32 settings to 'configure'.
932  The other Win32 builds using Borland, VC or whatever don't use 'configure',
933  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
934  for Win32.
935 \newline 
936
937 \newline 
938 These defaults are:
939 \newline 
940
941 \layout Standard
942 \align center 
943
944 \begin_inset  Tabular
945 <lyxtabular version="3" rows="8" columns="3">
946 <features>
947 <column alignment="block" valignment="top" leftline="true" width="0in">
948 <column alignment="block" valignment="top" leftline="true" width="0in">
949 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
950 <row topline="true" bottomline="true">
951 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
952 \begin_inset Text
953
954 \layout Standard
955
956 Variable
957 \end_inset 
958 </cell>
959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
960 \begin_inset Text
961
962 \layout Standard
963
964 default
965 \end_inset 
966 </cell>
967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
968 \begin_inset Text
969
970 \layout Standard
971
972 Win32 builds
973 \end_inset 
974 </cell>
975 </row>
976 <row topline="true">
977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
978 \begin_inset Text
979
980 \layout Standard
981
982
983 \emph on 
984 PREFIX
985 \end_inset 
986 </cell>
987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
988 \begin_inset Text
989
990 \layout Standard
991
992 /usr/local
993 \end_inset 
994 </cell>
995 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
996 \begin_inset Text
997
998 \layout Standard
999
1000
1001 \backslash 
1002 sdcc
1003 \end_inset 
1004 </cell>
1005 </row>
1006 <row topline="true">
1007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1008 \begin_inset Text
1009
1010 \layout Standard
1011
1012
1013 \emph on 
1014 EXEC_PREFIX
1015 \end_inset 
1016 </cell>
1017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1018 \begin_inset Text
1019
1020 \layout Standard
1021
1022
1023 \emph on 
1024 $PREFIX
1025 \end_inset 
1026 </cell>
1027 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1028 \begin_inset Text
1029
1030 \layout Standard
1031
1032
1033 \emph on 
1034 $PREFIX
1035 \end_inset 
1036 </cell>
1037 </row>
1038 <row topline="true">
1039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1040 \begin_inset Text
1041
1042 \layout Standard
1043
1044
1045 \emph on 
1046 BINDIR
1047 \end_inset 
1048 </cell>
1049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1050 \begin_inset Text
1051
1052 \layout Standard
1053
1054
1055 \emph on 
1056 $EXECPREFIX
1057 \emph default 
1058 /bin
1059 \end_inset 
1060 </cell>
1061 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1062 \begin_inset Text
1063
1064 \layout Standard
1065
1066
1067 \emph on 
1068 $EXECPREFIX
1069 \emph default 
1070
1071 \backslash 
1072 bin
1073 \end_inset 
1074 </cell>
1075 </row>
1076 <row topline="true">
1077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1078 \begin_inset Text
1079
1080 \layout Standard
1081
1082
1083 \emph on 
1084 DATADIR
1085 \end_inset 
1086 </cell>
1087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1088 \begin_inset Text
1089
1090 \layout Standard
1091
1092
1093 \emph on 
1094 $PREFIX
1095 \emph default 
1096 /share
1097 \end_inset 
1098 </cell>
1099 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1100 \begin_inset Text
1101
1102 \layout Standard
1103
1104
1105 \emph on 
1106 $PREFIX
1107 \end_inset 
1108 </cell>
1109 </row>
1110 <row topline="true">
1111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1112 \begin_inset Text
1113
1114 \layout Standard
1115
1116
1117 \emph on 
1118 DOCDIR
1119 \end_inset 
1120 </cell>
1121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1122 \begin_inset Text
1123
1124 \layout Standard
1125
1126
1127 \emph on 
1128 $DATADIR
1129 \emph default 
1130 /sdcc/doc
1131 \end_inset 
1132 </cell>
1133 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1134 \begin_inset Text
1135
1136 \layout Standard
1137
1138
1139 \emph on 
1140 $DATADIR
1141 \emph default 
1142
1143 \backslash 
1144 doc
1145 \end_inset 
1146 </cell>
1147 </row>
1148 <row topline="true">
1149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1150 \begin_inset Text
1151
1152 \layout Standard
1153
1154
1155 \emph on 
1156 INCLUDE_DIR_SUFFIX
1157 \end_inset 
1158 </cell>
1159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1160 \begin_inset Text
1161
1162 \layout Standard
1163
1164 sdcc/include
1165 \end_inset 
1166 </cell>
1167 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1168 \begin_inset Text
1169
1170 \layout Standard
1171
1172 include
1173 \end_inset 
1174 </cell>
1175 </row>
1176 <row topline="true" bottomline="true">
1177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1178 \begin_inset Text
1179
1180 \layout Standard
1181
1182
1183 \emph on 
1184 LIB_DIR_SUFFIX
1185 \end_inset 
1186 </cell>
1187 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1188 \begin_inset Text
1189
1190 \layout Standard
1191
1192 sdcc/lib
1193 \end_inset 
1194 </cell>
1195 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1196 \begin_inset Text
1197
1198 \layout Standard
1199
1200 lib
1201 \end_inset 
1202 </cell>
1203 </row>
1204 </lyxtabular>
1205
1206 \end_inset 
1207
1208
1209 \newline 
1210
1211 \layout Standard
1212 \noindent 
1213 'configure' also computes relative paths.
1214  This is needed for full relocatability of a binary package and to complete
1215  search paths (see section search paths below):
1216 \newline 
1217  
1218 \layout Standard
1219 \align center 
1220
1221 \begin_inset  Tabular
1222 <lyxtabular version="3" rows="4" columns="3">
1223 <features>
1224 <column alignment="block" valignment="top" leftline="true" width="0in">
1225 <column alignment="block" valignment="top" leftline="true" width="0in">
1226 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1227 <row topline="true" bottomline="true">
1228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1229 \begin_inset Text
1230
1231 \layout Standard
1232
1233 Variable (computed)
1234 \end_inset 
1235 </cell>
1236 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1237 \begin_inset Text
1238
1239 \layout Standard
1240
1241 default
1242 \end_inset 
1243 </cell>
1244 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1245 \begin_inset Text
1246
1247 \layout Standard
1248
1249 Win32 builds
1250 \end_inset 
1251 </cell>
1252 </row>
1253 <row topline="true" bottomline="true">
1254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1255 \begin_inset Text
1256
1257 \layout Standard
1258
1259
1260 \emph on 
1261 BIN2DATA_DIR
1262 \end_inset 
1263 </cell>
1264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1265 \begin_inset Text
1266
1267 \layout Standard
1268
1269 ../share
1270 \end_inset 
1271 </cell>
1272 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1273 \begin_inset Text
1274
1275 \layout Standard
1276
1277 ..
1278 \end_inset 
1279 </cell>
1280 </row>
1281 <row bottomline="true">
1282 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1283 \begin_inset Text
1284
1285 \layout Standard
1286
1287
1288 \emph on 
1289 PREFIX2BIN_DIR
1290 \end_inset 
1291 </cell>
1292 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1293 \begin_inset Text
1294
1295 \layout Standard
1296
1297 bin
1298 \end_inset 
1299 </cell>
1300 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1301 \begin_inset Text
1302
1303 \layout Standard
1304
1305 bin
1306 \end_inset 
1307 </cell>
1308 </row>
1309 <row bottomline="true">
1310 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1311 \begin_inset Text
1312
1313 \layout Standard
1314
1315
1316 \emph on 
1317 PREFIX2DATA_DIR
1318 \end_inset 
1319 </cell>
1320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1321 \begin_inset Text
1322
1323 \layout Standard
1324
1325 share/sdcc
1326 \end_inset 
1327 </cell>
1328 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1329 \begin_inset Text
1330
1331 \layout Standard
1332
1333 \end_inset 
1334 </cell>
1335 </row>
1336 </lyxtabular>
1337
1338 \end_inset 
1339
1340
1341 \newline 
1342
1343 \layout Standard
1344 \noindent 
1345 Examples:
1346 \layout LyX-Code
1347
1348 ./configure
1349 \newline 
1350 ./configure -
1351 \begin_inset ERT
1352 status Collapsed
1353
1354 \layout Standard
1355
1356 \backslash 
1357 /
1358 \end_inset 
1359
1360 -prefix=
1361 \begin_inset Quotes srd
1362 \end_inset 
1363
1364 /usr/bin
1365 \begin_inset Quotes srd
1366 \end_inset 
1367
1368  -
1369 \begin_inset ERT
1370 status Collapsed
1371
1372 \layout Standard
1373
1374 \backslash 
1375 /
1376 \end_inset 
1377
1378 -datadir=
1379 \begin_inset Quotes srd
1380 \end_inset 
1381
1382 /usr/share
1383 \begin_inset Quotes srd
1384 \end_inset 
1385
1386
1387 \newline 
1388 ./configure -
1389 \begin_inset ERT
1390 status Collapsed
1391
1392 \layout Standard
1393
1394 \backslash 
1395 /
1396 \end_inset 
1397
1398 -disable-avr-port -
1399 \begin_inset ERT
1400 status Collapsed
1401
1402 \layout Standard
1403
1404 \backslash 
1405 /
1406 \end_inset 
1407
1408 -disable-xa51-port
1409 \layout Standard
1410
1411 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1412 32'):
1413 \layout LyX-Code
1414
1415 ./configure 
1416 \backslash 
1417
1418 \newline 
1419 CC=
1420 \begin_inset Quotes srd
1421 \end_inset 
1422
1423 i586-mingw32msvc-gcc
1424 \begin_inset Quotes srd
1425 \end_inset 
1426
1427  CXX=
1428 \begin_inset Quotes srd
1429 \end_inset 
1430
1431 i586-mingw32msvc-g++
1432 \begin_inset Quotes srd
1433 \end_inset 
1434
1435  
1436 \backslash 
1437  
1438 \newline 
1439 RANLIB=
1440 \begin_inset Quotes srd
1441 \end_inset 
1442
1443 i586-mingw32msvc-ranlib
1444 \begin_inset Quotes srd
1445 \end_inset 
1446
1447  
1448 \backslash 
1449
1450 \newline 
1451 STRIP=
1452 \begin_inset Quotes srd
1453 \end_inset 
1454
1455 i586-mingw32msvc-strip
1456 \begin_inset Quotes srd
1457 \end_inset 
1458
1459  
1460 \backslash 
1461
1462 \newline 
1463 -
1464 \begin_inset ERT
1465 status Collapsed
1466
1467 \layout Standard
1468
1469 \backslash 
1470 /
1471 \end_inset 
1472
1473 -prefix=
1474 \begin_inset Quotes srd
1475 \end_inset 
1476
1477 /sdcc
1478 \begin_inset Quotes srd
1479 \end_inset 
1480
1481  
1482 \backslash 
1483
1484 \newline 
1485 -
1486 \begin_inset ERT
1487 status Collapsed
1488
1489 \layout Standard
1490
1491 \backslash 
1492 /
1493 \end_inset 
1494
1495 -datadir=
1496 \begin_inset Quotes srd
1497 \end_inset 
1498
1499 /sdcc
1500 \begin_inset Quotes srd
1501 \end_inset 
1502
1503  
1504 \backslash 
1505
1506 \newline 
1507 docdir=
1508 \begin_inset Quotes srd
1509 \end_inset 
1510
1511 /sdcc/doc
1512 \begin_inset Quotes srd
1513 \end_inset 
1514
1515  
1516 \backslash 
1517
1518 \newline 
1519 include_dir_suffix=
1520 \begin_inset Quotes srd
1521 \end_inset 
1522
1523 include
1524 \begin_inset Quotes srd
1525 \end_inset 
1526
1527  
1528 \backslash 
1529
1530 \newline 
1531 lib_dir_suffix=
1532 \begin_inset Quotes srd
1533 \end_inset 
1534
1535 lib
1536 \begin_inset Quotes srd
1537 \end_inset 
1538
1539  
1540 \backslash 
1541
1542 \newline 
1543 sdccconf_h_dir_separator=
1544 \begin_inset Quotes srd
1545 \end_inset 
1546
1547
1548 \backslash 
1549
1550 \backslash 
1551
1552 \backslash 
1553
1554 \backslash 
1555
1556 \begin_inset Quotes srd
1557 \end_inset 
1558
1559  
1560 \backslash 
1561
1562 \newline 
1563 -
1564 \begin_inset ERT
1565 status Collapsed
1566
1567 \layout Standard
1568
1569 \backslash 
1570 /
1571 \end_inset 
1572
1573 -disable-device-lib-build
1574 \backslash 
1575
1576 \newline 
1577 -
1578 \begin_inset ERT
1579 status Collapsed
1580
1581 \layout Standard
1582
1583 \backslash 
1584 /
1585 \end_inset 
1586
1587 -disable-ucsim
1588 \backslash 
1589
1590 \newline 
1591 -
1592 \begin_inset ERT
1593 status Collapsed
1594
1595 \layout Standard
1596
1597 \backslash 
1598 /
1599 \end_inset 
1600
1601 -host=i586-mingw32msvc -
1602 \begin_inset ERT
1603 status Collapsed
1604
1605 \layout Standard
1606
1607 \backslash 
1608 /
1609 \end_inset 
1610
1611 -build=unknown-unknown-linux-gnu
1612 \layout Standard
1613
1614 To 
1615 \begin_inset Quotes sld
1616 \end_inset 
1617
1618 cross
1619 \begin_inset Quotes srd
1620 \end_inset 
1621
1622 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
1623 ):
1624 \layout LyX-Code
1625
1626 ./configure -C 
1627 \backslash 
1628
1629 \newline 
1630 CFLAGS=
1631 \begin_inset Quotes srd
1632 \end_inset 
1633
1634 -mno-cygwin -O2
1635 \begin_inset Quotes srd
1636 \end_inset 
1637
1638  
1639 \backslash 
1640
1641 \newline 
1642 LDFLAGS=
1643 \begin_inset Quotes srd
1644 \end_inset 
1645
1646 -mno-cygwin
1647 \begin_inset Quotes srd
1648 \end_inset 
1649
1650  
1651 \backslash 
1652
1653 \newline 
1654 -
1655 \begin_inset ERT
1656 status Collapsed
1657
1658 \layout Standard
1659
1660 \backslash 
1661 /
1662 \end_inset 
1663
1664 -prefix=
1665 \begin_inset Quotes srd
1666 \end_inset 
1667
1668 /sdcc
1669 \begin_inset Quotes srd
1670 \end_inset 
1671
1672  
1673 \backslash 
1674
1675 \newline 
1676 -
1677 \begin_inset ERT
1678 status Collapsed
1679
1680 \layout Standard
1681
1682 \backslash 
1683 /
1684 \end_inset 
1685
1686 -datadir=
1687 \begin_inset Quotes srd
1688 \end_inset 
1689
1690 /sdcc
1691 \begin_inset Quotes srd
1692 \end_inset 
1693
1694  
1695 \backslash 
1696
1697 \newline 
1698 docdir=
1699 \begin_inset Quotes srd
1700 \end_inset 
1701
1702 /sdcc/doc
1703 \begin_inset Quotes srd
1704 \end_inset 
1705
1706  
1707 \backslash 
1708  
1709 \newline 
1710 include_dir_suffix=
1711 \begin_inset Quotes srd
1712 \end_inset 
1713
1714 include
1715 \begin_inset Quotes srd
1716 \end_inset 
1717
1718  
1719 \backslash 
1720
1721 \newline 
1722 lib_dir_suffix=
1723 \begin_inset Quotes srd
1724 \end_inset 
1725
1726 lib
1727 \begin_inset Quotes srd
1728 \end_inset 
1729
1730  
1731 \backslash 
1732
1733 \newline 
1734 sdccconf_h_dir_separator=
1735 \begin_inset Quotes srd
1736 \end_inset 
1737
1738
1739 \backslash 
1740
1741 \backslash 
1742
1743 \backslash 
1744
1745 \backslash 
1746
1747 \begin_inset Quotes srd
1748 \end_inset 
1749
1750  
1751 \backslash 
1752
1753 \newline 
1754 -
1755 \begin_inset ERT
1756 status Collapsed
1757
1758 \layout Standard
1759
1760 \backslash 
1761 /
1762 \end_inset 
1763
1764 -disable-ucsim
1765 \layout Standard
1766
1767 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
1768  The option '-
1769 \begin_inset ERT
1770 status Collapsed
1771
1772 \layout Standard
1773
1774 \backslash 
1775 /
1776 \end_inset 
1777
1778 -C' turns on caching, which gives a little bit extra speed.
1779  However if options are changed, it can be necessary to delete the config.cache
1780  file.
1781 \layout Section
1782
1783 Install paths
1784 \begin_inset LatexCommand \label{sub:Install-paths}
1785
1786 \end_inset 
1787
1788
1789 \begin_inset LatexCommand \index{Install paths}
1790
1791 \end_inset 
1792
1793
1794 \layout Standard
1795 \added_space_top medskip \align center 
1796
1797 \begin_inset  Tabular
1798 <lyxtabular version="3" rows="5" columns="4">
1799 <features>
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" width="0">
1803 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
1804 <row topline="true" bottomline="true">
1805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1806 \begin_inset Text
1807
1808 \layout Standard
1809
1810
1811 \series bold 
1812 Description
1813 \end_inset 
1814 </cell>
1815 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1816 \begin_inset Text
1817
1818 \layout Standard
1819
1820
1821 \series bold 
1822 Path
1823 \end_inset 
1824 </cell>
1825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1826 \begin_inset Text
1827
1828 \layout Standard
1829
1830
1831 \series bold 
1832 Default
1833 \end_inset 
1834 </cell>
1835 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1836 \begin_inset Text
1837
1838 \layout Standard
1839
1840
1841 \series bold 
1842 Win32 builds
1843 \end_inset 
1844 </cell>
1845 </row>
1846 <row topline="true">
1847 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1848 \begin_inset Text
1849
1850 \layout Standard
1851
1852 Binary files*
1853 \end_inset 
1854 </cell>
1855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1856 \begin_inset Text
1857
1858 \layout Standard
1859
1860
1861 \emph on 
1862 $EXEC_PREFIX
1863 \end_inset 
1864 </cell>
1865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1866 \begin_inset Text
1867
1868 \layout Standard
1869
1870 /usr/local/bin
1871 \end_inset 
1872 </cell>
1873 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1874 \begin_inset Text
1875
1876 \layout Standard
1877
1878
1879 \backslash 
1880 sdcc
1881 \backslash 
1882 bin
1883 \end_inset 
1884 </cell>
1885 </row>
1886 <row topline="true">
1887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1888 \begin_inset Text
1889
1890 \layout Standard
1891
1892 Include files
1893 \end_inset 
1894 </cell>
1895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1896 \begin_inset Text
1897
1898 \layout Standard
1899
1900
1901 \emph on 
1902 $DATADIR/ $INCLUDE_DIR_SUFFIX
1903 \end_inset 
1904 </cell>
1905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1906 \begin_inset Text
1907
1908 \layout Standard
1909
1910 /usr/local/share/sdcc/include
1911 \end_inset 
1912 </cell>
1913 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1914 \begin_inset Text
1915
1916 \layout Standard
1917
1918
1919 \backslash 
1920 sdcc
1921 \backslash 
1922 include
1923 \end_inset 
1924 </cell>
1925 </row>
1926 <row topline="true">
1927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1928 \begin_inset Text
1929
1930 \layout Standard
1931
1932 Library file**
1933 \end_inset 
1934 </cell>
1935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1936 \begin_inset Text
1937
1938 \layout Standard
1939
1940
1941 \emph on 
1942 $DATADIR/$LIB_DIR_SUFFIX
1943 \end_inset 
1944 </cell>
1945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1946 \begin_inset Text
1947
1948 \layout Standard
1949
1950 /usr/local/share/sdcc/lib
1951 \end_inset 
1952 </cell>
1953 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1954 \begin_inset Text
1955
1956 \layout Standard
1957
1958
1959 \backslash 
1960 sdcc
1961 \backslash 
1962 lib
1963 \end_inset 
1964 </cell>
1965 </row>
1966 <row topline="true" bottomline="true">
1967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1968 \begin_inset Text
1969
1970 \layout Standard
1971
1972 Documentation
1973 \end_inset 
1974 </cell>
1975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1976 \begin_inset Text
1977
1978 \layout Standard
1979
1980
1981 \emph on 
1982 $DOCDIR
1983 \end_inset 
1984 </cell>
1985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1986 \begin_inset Text
1987
1988 \layout Standard
1989
1990 /usr/local/share/sdcc/doc
1991 \end_inset 
1992 </cell>
1993 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1994 \begin_inset Text
1995
1996 \layout Standard
1997
1998
1999 \backslash 
2000 sdcc
2001 \backslash 
2002 doc
2003 \end_inset 
2004 </cell>
2005 </row>
2006 </lyxtabular>
2007
2008 \end_inset 
2009
2010
2011 \layout Verse
2012
2013
2014 \size footnotesize 
2015 *compiler, preprocessor, assembler, and linker
2016 \newline 
2017 **the 
2018 \shape italic 
2019 model
2020 \shape default 
2021  is auto-appended by the compiler, e.g.
2022  small, large, z80, ds390 etc
2023 \layout Standard
2024 \noindent 
2025 The install paths can still be changed during `make install` with e.g.:
2026 \layout LyX-Code
2027
2028 make install prefix=$(HOME)/local/sdcc
2029 \layout Standard
2030
2031 Of course this doesn't change the search paths compiled into the binaries.
2032 \newline 
2033
2034 \newline 
2035 Moreover the install path can be changed by defining DESTDIR
2036 \begin_inset LatexCommand \index{DESTDIR}
2037
2038 \end_inset 
2039
2040 :
2041 \layout LyX-Code
2042
2043 make install DESTDIR=$(HOME)/sdcc.rpm/
2044 \layout Standard
2045
2046 Please note that DESTDIR must have a trailing slash!
2047 \layout Section
2048
2049 Search Paths
2050 \begin_inset LatexCommand \label{sub:Search-Paths}
2051
2052 \end_inset 
2053
2054
2055 \begin_inset LatexCommand \index{Search path}
2056
2057 \end_inset 
2058
2059
2060 \layout Standard
2061
2062 Some search paths or parts of them are determined by configure variables
2063  (in 
2064 \emph on 
2065 italics
2066 \emph default 
2067 , see section above).
2068  Further search paths are determined by environment variables during runtime.
2069  
2070 \newline 
2071 The paths searched when running the compiler are as follows (the first catch
2072  wins):
2073 \newline 
2074
2075 \newline 
2076 1.
2077  Binary files (preprocessor, assembler and linker)
2078 \newline 
2079
2080 \layout Standard
2081 \align center 
2082
2083 \begin_inset  Tabular
2084 <lyxtabular version="3" rows="4" columns="3">
2085 <features>
2086 <column alignment="block" valignment="top" leftline="true" width="0in">
2087 <column alignment="block" valignment="top" leftline="true" width="0in">
2088 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2089 <row topline="true" bottomline="true">
2090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2091 \begin_inset Text
2092
2093 \layout Standard
2094
2095 Search path
2096 \end_inset 
2097 </cell>
2098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2099 \begin_inset Text
2100
2101 \layout Standard
2102
2103 default
2104 \end_inset 
2105 </cell>
2106 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2107 \begin_inset Text
2108
2109 \layout Standard
2110
2111 Win32 builds
2112 \end_inset 
2113 </cell>
2114 </row>
2115 <row topline="true">
2116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2117 \begin_inset Text
2118
2119 \layout Standard
2120
2121 $SDCC_HOME/
2122 \emph on 
2123 $PPREFIX2BIN_DIR
2124 \end_inset 
2125 </cell>
2126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2127 \begin_inset Text
2128
2129 \layout Standard
2130
2131 $SDCC_HOME/bin
2132 \end_inset 
2133 </cell>
2134 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2135 \begin_inset Text
2136
2137 \layout Standard
2138
2139 $SDCC_HOME
2140 \backslash 
2141 bin
2142 \end_inset 
2143 </cell>
2144 </row>
2145 <row topline="true">
2146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2147 \begin_inset Text
2148
2149 \layout Standard
2150
2151 Path of argv[0] (if available)
2152 \end_inset 
2153 </cell>
2154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2155 \begin_inset Text
2156
2157 \layout Standard
2158
2159 Path of argv[0]
2160 \end_inset 
2161 </cell>
2162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2163 \begin_inset Text
2164
2165 \layout Standard
2166
2167 Path of argv[0]
2168 \end_inset 
2169 </cell>
2170 </row>
2171 <row topline="true" bottomline="true">
2172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2173 \begin_inset Text
2174
2175 \layout Standard
2176
2177 $PATH
2178 \end_inset 
2179 </cell>
2180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2181 \begin_inset Text
2182
2183 \layout Standard
2184
2185 $PATH
2186 \end_inset 
2187 </cell>
2188 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2189 \begin_inset Text
2190
2191 \layout Standard
2192
2193 $PATH
2194 \end_inset 
2195 </cell>
2196 </row>
2197 </lyxtabular>
2198
2199 \end_inset 
2200
2201  
2202 \newline 
2203
2204 \layout Standard
2205 \noindent 
2206 2.
2207  Include files
2208 \newline 
2209
2210 \layout Standard
2211 \align center 
2212
2213 \begin_inset  Tabular
2214 <lyxtabular version="3" rows="6" columns="3">
2215 <features>
2216 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2217 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2218 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2219 <row topline="true" bottomline="true">
2220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2221 \begin_inset Text
2222
2223 \layout Standard
2224
2225 Search path
2226 \end_inset 
2227 </cell>
2228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2229 \begin_inset Text
2230
2231 \layout Standard
2232
2233 default
2234 \end_inset 
2235 </cell>
2236 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2237 \begin_inset Text
2238
2239 \layout Standard
2240
2241 Win32 builds
2242 \end_inset 
2243 </cell>
2244 </row>
2245 <row topline="true">
2246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2247 \begin_inset Text
2248
2249 \layout Standard
2250
2251 -
2252 \begin_inset ERT
2253 status Collapsed
2254
2255 \layout Standard
2256
2257 \backslash 
2258 /
2259 \end_inset 
2260
2261 -I dir
2262 \end_inset 
2263 </cell>
2264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2265 \begin_inset Text
2266
2267 \layout Standard
2268
2269 -
2270 \begin_inset ERT
2271 status Collapsed
2272
2273 \layout Standard
2274
2275 \backslash 
2276 /
2277 \end_inset 
2278
2279 -I dir
2280 \end_inset 
2281 </cell>
2282 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2283 \begin_inset Text
2284
2285 \layout Standard
2286
2287 -
2288 \begin_inset ERT
2289 status Collapsed
2290
2291 \layout Standard
2292
2293 \backslash 
2294 /
2295 \end_inset 
2296
2297 -I dir
2298 \end_inset 
2299 </cell>
2300 </row>
2301 <row topline="true">
2302 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2303 \begin_inset Text
2304
2305 \layout Standard
2306
2307 $SDCC_INCLUDE
2308 \end_inset 
2309 </cell>
2310 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2311 \begin_inset Text
2312
2313 \layout Standard
2314
2315 $SDCC_INCLUDE
2316 \end_inset 
2317 </cell>
2318 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2319 \begin_inset Text
2320
2321 \layout Standard
2322
2323 $SDCC_INCLUDE
2324 \end_inset 
2325 </cell>
2326 </row>
2327 <row topline="true">
2328 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2329 \begin_inset Text
2330
2331 \layout Standard
2332
2333 $SDCC_HOME/
2334 \newline 
2335
2336 \emph on 
2337 $PREFIX2DATA_DIR/
2338 \newline 
2339 $INCLUDE_DIR_SUFFIX
2340 \end_inset 
2341 </cell>
2342 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2343 \begin_inset Text
2344
2345 \layout Standard
2346
2347 $SDCC_ HOME/
2348 \newline 
2349 share/sdcc/
2350 \newline 
2351 include
2352 \end_inset 
2353 </cell>
2354 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2355 \begin_inset Text
2356
2357 \layout Standard
2358
2359 $SDCC_HOME
2360 \backslash 
2361 include
2362 \end_inset 
2363 </cell>
2364 </row>
2365 <row topline="true">
2366 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2367 \begin_inset Text
2368
2369 \layout Standard
2370
2371 path(argv[0])/
2372 \newline 
2373
2374 \emph on 
2375 $BIN2DATADIR/
2376 \emph default 
2377
2378 \newline 
2379
2380 \emph on 
2381 $INCLUDE_DIR_SUFFIX
2382 \end_inset 
2383 </cell>
2384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2385 \begin_inset Text
2386
2387 \layout Standard
2388
2389 path(argv[0])/
2390 \newline 
2391 ../sdcc/include
2392 \newline 
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 \SpecialChar ~
2431
2432 \end_inset 
2433 </cell>
2434 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2435 \begin_inset Text
2436
2437 \layout Standard
2438
2439 path(argv[0])
2440 \backslash 
2441 ..
2442 \backslash 
2443 include
2444 \end_inset 
2445 </cell>
2446 </row>
2447 <row topline="true" bottomline="true">
2448 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2449 \begin_inset Text
2450
2451 \layout Standard
2452
2453
2454 \emph on 
2455 $DATADIR/
2456 \emph default 
2457
2458 \newline 
2459
2460 \emph on 
2461 $INCLUDE_DIR_SUFFIX
2462 \end_inset 
2463 </cell>
2464 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2465 \begin_inset Text
2466
2467 \layout Standard
2468
2469 /usr/local/share/sdcc/
2470 \newline 
2471 include
2472 \end_inset 
2473 </cell>
2474 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2475 \begin_inset Text
2476
2477 \layout Standard
2478
2479 (not on Win32)
2480 \end_inset 
2481 </cell>
2482 </row>
2483 </lyxtabular>
2484
2485 \end_inset 
2486
2487  
2488 \newline 
2489
2490 \layout Standard
2491 \noindent 
2492 The option -
2493 \begin_inset ERT
2494 status Collapsed
2495
2496 \layout Standard
2497
2498 \backslash 
2499 /
2500 \end_inset 
2501
2502 -nostdinc disables the last two search paths.
2503 \newline 
2504
2505 \newline 
2506 3.
2507  Library files 
2508 \newline 
2509
2510 \layout Standard
2511
2512 With the exception of 
2513 \begin_inset Quotes sld
2514 \end_inset 
2515
2516 -
2517 \begin_inset ERT
2518 status Collapsed
2519
2520 \layout Standard
2521
2522 \backslash 
2523 /
2524 \end_inset 
2525
2526 -L dir
2527 \begin_inset Quotes srd
2528 \end_inset 
2529
2530  the 
2531 \shape italic 
2532 model
2533 \shape default 
2534  is auto-appended by the compiler (e.g.
2535  small, large, z80, ds390 etc.).
2536  
2537 \newline 
2538
2539 \layout Standard
2540 \align center 
2541
2542 \begin_inset  Tabular
2543 <lyxtabular version="3" rows="6" columns="3">
2544 <features>
2545 <column alignment="block" valignment="top" leftline="true" width="1.7in">
2546 <column alignment="block" valignment="top" leftline="true" width="1.2in">
2547 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
2548 <row topline="true" bottomline="true">
2549 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2550 \begin_inset Text
2551
2552 \layout Standard
2553
2554 Search path
2555 \end_inset 
2556 </cell>
2557 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2558 \begin_inset Text
2559
2560 \layout Standard
2561
2562 default
2563 \end_inset 
2564 </cell>
2565 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2566 \begin_inset Text
2567
2568 \layout Standard
2569
2570 Win32 builds
2571 \end_inset 
2572 </cell>
2573 </row>
2574 <row topline="true">
2575 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2576 \begin_inset Text
2577
2578 \layout Standard
2579
2580 -
2581 \begin_inset ERT
2582 status Collapsed
2583
2584 \layout Standard
2585
2586 \backslash 
2587 /
2588 \end_inset 
2589
2590 -L dir
2591 \end_inset 
2592 </cell>
2593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2594 \begin_inset Text
2595
2596 \layout Standard
2597
2598 -
2599 \begin_inset ERT
2600 status Collapsed
2601
2602 \layout Standard
2603
2604 \backslash 
2605 /
2606 \end_inset 
2607
2608 -L dir
2609 \end_inset 
2610 </cell>
2611 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2612 \begin_inset Text
2613
2614 \layout Standard
2615
2616 -
2617 \begin_inset ERT
2618 status Collapsed
2619
2620 \layout Standard
2621
2622 \backslash 
2623 /
2624 \end_inset 
2625
2626 -L dir
2627 \end_inset 
2628 </cell>
2629 </row>
2630 <row topline="true">
2631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2632 \begin_inset Text
2633
2634 \layout Standard
2635
2636 $SDCC_LIB/
2637 \newline 
2638
2639 \emph on 
2640 <model>
2641 \end_inset 
2642 </cell>
2643 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2644 \begin_inset Text
2645
2646 \layout Standard
2647
2648 $SDCC_LIB/
2649 \newline 
2650
2651 \emph on 
2652 <model>
2653 \end_inset 
2654 </cell>
2655 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2656 \begin_inset Text
2657
2658 \layout Standard
2659
2660 $SDCC_LIB
2661 \backslash 
2662
2663 \newline 
2664
2665 \emph on 
2666 <model>
2667 \end_inset 
2668 </cell>
2669 </row>
2670 <row topline="true">
2671 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2672 \begin_inset Text
2673
2674 \layout Standard
2675
2676 $SDCC_HOME/
2677 \newline 
2678
2679 \emph on 
2680 $PREFIX2DATA_DIR/
2681 \newline 
2682 $LIB_DIR_SUFFIX/<model>
2683 \end_inset 
2684 </cell>
2685 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2686 \begin_inset Text
2687
2688 \layout Standard
2689
2690 $SDCC_HOME/
2691 \newline 
2692 share/sdcc/
2693 \newline 
2694 lib/
2695 \emph on 
2696 <model>
2697 \end_inset 
2698 </cell>
2699 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2700 \begin_inset Text
2701
2702 \layout Standard
2703
2704 $SDCC_HOME
2705 \backslash 
2706 lib
2707 \backslash 
2708
2709 \emph on 
2710
2711 \newline 
2712 <model>
2713 \end_inset 
2714 </cell>
2715 </row>
2716 <row topline="true">
2717 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2718 \begin_inset Text
2719
2720 \layout Standard
2721
2722 path(argv[0])/
2723 \newline 
2724
2725 \emph on 
2726 $BIN2DATADIR/
2727 \emph default 
2728
2729 \newline 
2730
2731 \emph on 
2732 $LIB_DIR_SUFFIX/<model>
2733 \end_inset 
2734 </cell>
2735 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2736 \begin_inset Text
2737
2738 \layout Standard
2739
2740 path(argv[0])/
2741 \newline 
2742 ../sdcc/lib/
2743 \emph on 
2744 <model>
2745 \newline 
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 \SpecialChar ~
2785
2786 \end_inset 
2787 </cell>
2788 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2789 \begin_inset Text
2790
2791 \layout Standard
2792
2793 path(argv[0])
2794 \backslash 
2795
2796 \newline 
2797 ..
2798 \backslash 
2799 lib
2800 \backslash 
2801
2802 \emph on 
2803 <model>
2804 \newline 
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 \SpecialChar ~
2840
2841 \end_inset 
2842 </cell>
2843 </row>
2844 <row topline="true" bottomline="true">
2845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2846 \begin_inset Text
2847
2848 \layout Standard
2849
2850
2851 \emph on 
2852 $DATADIR/
2853 \newline 
2854 $LIB_DIR_SUFFIX/<model>
2855 \end_inset 
2856 </cell>
2857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2858 \begin_inset Text
2859
2860 \layout Standard
2861
2862 /usr/local/share/sdcc/
2863 \newline 
2864 lib/
2865 \emph on 
2866 <model>
2867 \end_inset 
2868 </cell>
2869 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2870 \begin_inset Text
2871
2872 \layout Standard
2873
2874 (not on Win32)
2875 \end_inset 
2876 </cell>
2877 </row>
2878 </lyxtabular>
2879
2880 \end_inset 
2881
2882
2883 \newline 
2884
2885 \layout Comment
2886
2887 Don't delete any of the stray spaces in the table above without checking
2888  the HTML output (last line)!
2889 \layout Standard
2890
2891 \SpecialChar ~
2892
2893 \newline 
2894 The option -
2895 \begin_inset ERT
2896 status Collapsed
2897
2898 \layout Standard
2899
2900 \backslash 
2901 /
2902 \end_inset 
2903
2904 -nostdlib disables the last two search paths.
2905 \layout Section
2906
2907 Building SDCC
2908 \begin_inset LatexCommand \index{Building SDCC}
2909
2910 \end_inset 
2911
2912
2913 \layout Subsection
2914
2915 Building SDCC on Linux
2916 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
2917
2918 \end_inset 
2919
2920
2921 \layout Enumerate
2922
2923
2924 \series medium 
2925 Download the source package
2926 \series default 
2927  either from the SDCC CVS repository or from the nightly snapshots
2928 \series medium 
2929 , it will be named something like sdcc
2930 \series default 
2931 .src
2932 \series medium 
2933 .t
2934 \series default 
2935 ar.
2936 \series medium 
2937 gz
2938 \series default 
2939  
2940 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
2941
2942 \end_inset 
2943
2944 .
2945 \layout Enumerate
2946
2947
2948 \series medium 
2949 Bring up a command line terminal, such as xterm.
2950 \layout Enumerate
2951
2952
2953 \series medium 
2954 Unpack the file using a command like: 
2955 \family sans 
2956 \series bold 
2957 "tar -xvzf sdcc.src.tar.gz
2958 \family default 
2959 \series default 
2960 "
2961 \series medium 
2962 , this will create a sub-directory called sdcc with all of the sources.
2963 \layout Enumerate
2964
2965 Change directory into the main SDCC directory, for example type: 
2966 \family sans 
2967 \series bold 
2968 "cd sdcc
2969 \series default 
2970 ".
2971 \layout Enumerate
2972
2973
2974 \series medium 
2975 Type 
2976 \family sans 
2977 \series bold 
2978 "./configure
2979 \family default 
2980 \series default 
2981 ".
2982  This configures the package for compilation on your system.
2983 \layout Enumerate
2984
2985
2986 \series medium 
2987 Type 
2988 \family sans 
2989 \series bold 
2990 "make
2991 \family default 
2992 \series default 
2993 "
2994 \series medium 
2995 .
2996
2997 \series default 
2998  All of the source packages will compile, this can take a while.
2999 \layout Enumerate
3000
3001
3002 \series medium 
3003 Type 
3004 \family sans 
3005 \series bold 
3006 "make install"
3007 \family default 
3008 \series default 
3009  as root
3010 \series medium 
3011 .
3012
3013 \series default 
3014  This copies the binary executables, the include files, the libraries and
3015  the documentation to the install directories.
3016  Proceed with section 
3017 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3018
3019 \end_inset 
3020
3021 .
3022 \layout Subsection
3023
3024 Building SDCC on OSX 2.x
3025 \layout Standard
3026
3027 Follow the instruction for Linux.
3028 \newline 
3029
3030 \newline 
3031 On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease
3032 )) fails to compile SDCC.
3033  Fortunately there's also gcc 2.9.x installed, which works fine.
3034  This compiler can be selected by running 'configure' with:
3035 \layout LyX-Code
3036
3037 ./configure CC=gcc2 CXX=g++2
3038 \layout Subsection
3039
3040 Cross compiling SDCC on Linux for Windows
3041 \layout Standard
3042
3043 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3044  See section 'Configure Options'.
3045 \layout Subsection
3046
3047 Building SDCC on Windows 
3048 \layout Standard
3049
3050 With the exception of Cygwin the SDCC binaries uCsim and sdcdb can't be
3051  built on Windows.
3052  They use Unix-sockets, which are not available on Win32.
3053 \layout Subsection
3054
3055 Building SDCC using Cygwin and Mingw32
3056 \layout Standard
3057
3058 For building and installing a Cygwin executable follow the instructions
3059  for Linux.
3060 \newline 
3061
3062 \newline 
3063 On Cygwin a 
3064 \begin_inset Quotes sld
3065 \end_inset 
3066
3067 native
3068 \begin_inset Quotes srd
3069 \end_inset 
3070
3071  Win32-binary can be built, which will not need the Cygwin-DLL.
3072  For the necessary 'configure' options see section 'configure options' or
3073  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
3074 \newline 
3075
3076 \newline 
3077 In order to install Cygwin on Windows download setup.exe from 
3078 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
3079
3080 \end_inset 
3081
3082 .
3083  Run it, set the 
3084 \begin_inset Quotes sld
3085 \end_inset 
3086
3087 default text file type
3088 \begin_inset Quotes srd
3089 \end_inset 
3090
3091  to 
3092 \begin_inset Quotes sld
3093 \end_inset 
3094
3095 unix
3096 \begin_inset Quotes srd
3097 \end_inset 
3098
3099  and download/install at least the following packages.
3100  Some packages are selected by default, others will be automatically selected
3101  because of dependencies with the manually selected packages.
3102  Never deselect these packages!
3103 \layout Itemize
3104
3105 flex
3106 \layout Itemize
3107
3108 bison
3109 \layout Itemize
3110
3111 gcc ; version 3.x is fine, no need to use the old 2.9x
3112 \layout Itemize
3113
3114 binutils ; selected with gcc
3115 \layout Itemize
3116
3117 make
3118 \layout Itemize
3119
3120 rxvt ; a nice console, which makes life much easier under windoze (see below)
3121 \layout Itemize
3122
3123 man ; not really needed for building SDCC, but you'll miss it sooner or
3124  later
3125 \layout Itemize
3126
3127 less ; not really needed for building SDCC, but you'll miss it sooner or
3128  later
3129 \layout Itemize
3130
3131 cvs ; only if you use CVS access
3132 \layout Standard
3133
3134 If you want to develop something you'll need:
3135 \layout Itemize
3136
3137 python ; for the regression tests
3138 \layout Itemize
3139
3140 gdb ; the gnu debugger, together with the nice GUI 
3141 \begin_inset Quotes sld
3142 \end_inset 
3143
3144 insight
3145 \begin_inset Quotes srd
3146 \end_inset 
3147
3148
3149 \layout Itemize
3150
3151 openssh ; to access the CF or commit changes
3152 \layout Itemize
3153
3154 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3155  use autoconf-stable!
3156 \layout Standard
3157
3158 rxvt is a nice console with history.
3159  Replace in your cygwin.bat the line
3160 \layout LyX-Code
3161
3162 bash -
3163 \begin_inset ERT
3164 status Collapsed
3165
3166 \layout Standard
3167
3168 \backslash 
3169 /
3170 \end_inset 
3171
3172 -login -i 
3173 \layout Standard
3174
3175 with (one line):
3176 \layout LyX-Code
3177
3178 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3179 \layout LyX-Code
3180
3181      -bg black -fg white -geometry 100x65 -e bash -
3182 \begin_inset ERT
3183 status Collapsed
3184
3185 \layout Standard
3186
3187 \backslash 
3188 /
3189 \end_inset 
3190
3191 -login
3192 \layout Standard
3193
3194 Text selected with the mouse is automatically copied to the clipboard, pasting
3195  works with shift-insert.
3196 \newline 
3197
3198 \newline 
3199 The other good tip is to make sure you have no //c/-style paths anywhere,
3200  use /cygdrive/c/ instead.
3201  Using // invokes a network lookup which is very slow.
3202  If you think 
3203 \begin_inset Quotes sld
3204 \end_inset 
3205
3206 cygdrive
3207 \begin_inset Quotes srd
3208 \end_inset 
3209
3210  is too long, you can change it with e.g.
3211 \layout LyX-Code
3212
3213 mount -s -u -c /mnt
3214 \layout Standard
3215
3216 SDCC sources use the unix line ending LF.
3217  Life is much easier, if you store the source tree on a drive which is mounted
3218  in binary mode.
3219  And use an editor which can handle LF-only line endings.
3220  Make sure not to commit files with windows line endings.
3221  The tabulator spacing
3222 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
3223
3224 \end_inset 
3225
3226  used in the project is 8.
3227  Although a tabulator spacing of 8 is a sensible choice for programmers
3228  (it's a power of 2 and allows to display 8/16 bit signed variables without
3229  loosing columns) the plan is to move towards using only spaces in the source.
3230 \layout Subsection
3231
3232 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3233 \layout Standard
3234
3235
3236 \series medium 
3237 Download the source package
3238 \series default 
3239  either from the SDCC CVS repository or from the 
3240 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3241
3242 \end_inset 
3243
3244
3245 \series medium 
3246 , it will be named something like sdcc
3247 \series default 
3248 .src
3249 \series medium 
3250 .tgz.
3251
3252 \series default 
3253  SDCC is distributed with all the projects, workspaces, and files you need
3254  to build it using Visual C++ 6.0/NET (except for sdcdb.exe which currently
3255  doesn't build under MSVC).
3256  The workspace name is 'sdcc.dsw'.
3257  Please note that as it is now, all the executables are created in a folder
3258  called sdcc
3259 \backslash 
3260 bin_vc.
3261  Once built you need to copy the executables from sdcc
3262 \backslash 
3263 bin_vc to sdcc
3264 \backslash 
3265 bin before running SDCC.
3266  
3267 \newline 
3268
3269 \newline 
3270 WARNING: Visual studio is very picky with line terminations; it expects
3271  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
3272  When using the CVS repository it's easiest to configure the cvs client
3273  to convert automatically for you.
3274  If however you are getting a message such as "This makefile was not generated
3275  by Developer Studio etc.
3276  etc.
3277 \begin_inset Quotes srd
3278 \end_inset 
3279
3280  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
3281  need to convert the Unix style line endings to DOS style line endings.
3282  To do so you can use the 
3283 \begin_inset Quotes sld
3284 \end_inset 
3285
3286 unix2dos
3287 \begin_inset Quotes srd
3288 \end_inset 
3289
3290  utility freely available on the internet.
3291  Doug Hawkins reported in the sdcc-user list that this works:
3292 \newline 
3293
3294 \newline 
3295 C:
3296 \backslash 
3297 Programming
3298 \backslash 
3299 SDCC> unix2dos sdcc.dsw
3300 \newline 
3301 C:
3302 \backslash 
3303 Programming
3304 \backslash 
3305 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
3306 \newline 
3307
3308 \newline 
3309 In order to build SDCC with MSVC you need win32 executables of bison.exe,
3310  flex.exe, and gawk.exe.
3311  One good place to get them is 
3312 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3313
3314 \end_inset 
3315
3316
3317 \newline 
3318
3319 \newline 
3320 Download the file UnxUtils
3321 \begin_inset LatexCommand \index{UnxUtils}
3322
3323 \end_inset 
3324
3325 .zip.
3326  Now you have to install the utilities and setup MSVC so it can locate the
3327  required programs.
3328  Here there are two alternatives (choose one!):
3329 \layout Enumerate
3330
3331 The easy way:
3332 \newline 
3333
3334 \newline 
3335 a) Extract UnxUtils.zip to your C:
3336 \backslash 
3337  hard disk PRESERVING the original paths, otherwise bison won't work.
3338  (If you are using WinZip make certain that 'Use folder names' is selected)
3339 \newline 
3340
3341 \newline 
3342 b) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3343  in 'Show directories for:' select 'Executable files', and in the directories
3344  window add a new path: 'C:
3345 \backslash 
3346 user
3347 \backslash 
3348 local
3349 \backslash 
3350 wbin', click ok.
3351 \newline 
3352
3353 \newline 
3354 (As a side effect, you get a bunch of Unix utilities that could be useful,
3355  such as diff and patch.)
3356 \layout Enumerate
3357
3358 A more compact way:
3359 \newline 
3360
3361 \newline 
3362 This one avoids extracting a bunch of files you may not use, but requires
3363  some extra work:
3364 \newline 
3365
3366 \newline 
3367 a) Create a directory were to put the tools needed, or use a directory already
3368  present.
3369  Say for example 'C:
3370 \backslash 
3371 util'.
3372 \newline 
3373
3374 \newline 
3375 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and gawk.exe
3376  to such directory WITHOUT preserving the original paths.
3377  (If you are using WinZip make certain that 'Use folder names' is not selected)
3378 \newline 
3379
3380 \newline 
3381 c) Rename bison.exe to '_bison.exe'.
3382 \newline 
3383
3384 \newline 
3385 d) Create a batch file 'bison.bat' in 'C:
3386 \backslash 
3387 util
3388 \backslash 
3389 ' and add these lines: 
3390 \newline 
3391 \SpecialChar ~
3392 \SpecialChar ~
3393 set BISON_SIMPLE=C:
3394 \backslash 
3395 util
3396 \backslash 
3397 bison.simple 
3398 \newline 
3399 \SpecialChar ~
3400 \SpecialChar ~
3401 set BISON_HAIRY=C:
3402 \backslash 
3403 util
3404 \backslash 
3405 bison.hairy
3406 \newline 
3407 \SpecialChar ~
3408 \SpecialChar ~
3409 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3410 \newline 
3411
3412 \newline 
3413 Steps 'c' and 'd' are needed because bison requires by default that the
3414  files 'bison.simple' and 'bison.hairy' reside in some weird Unix directory,
3415  '/usr/local/share/' I think.
3416  So it is necessary to tell bison where those files are located if they
3417  are not in such directory.
3418  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3419 \newline 
3420
3421 \newline 
3422 e) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3423  in 'Show directories for:' select 'Executable files', and in the directories
3424  window add a new path: 'c:
3425 \backslash 
3426 util', click ok.
3427  Note that you can use any other path instead of 'c:
3428 \backslash 
3429 util', even the path where the Visual C++ tools are, probably: 'C:
3430 \backslash 
3431 Program Files
3432 \backslash 
3433 Microsoft Visual Studio
3434 \backslash 
3435 Common
3436 \backslash 
3437 Tools'.
3438  So you don't have to execute step 'e' :)
3439 \layout Standard
3440
3441 That is it.
3442  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
3443  the executables from sdcc
3444 \backslash 
3445 bin_vc to sdcc
3446 \backslash 
3447 bin, and you can compile using SDCC.
3448 \layout Subsection
3449
3450 Building SDCC Using Borland
3451 \layout Enumerate
3452
3453 From the sdcc directory, run the command "make -f Makefile.bcc".
3454  This should regenerate all the .exe files in the bin directory except for
3455  sdcdb.exe (which currently doesn't build under Borland C++).
3456 \layout Enumerate
3457
3458 If you modify any source files and need to rebuild, be aware that the dependenci
3459 es may not be correctly calculated.
3460  The safest option is to delete all .obj files and run the build again.
3461  From a Cygwin BASH prompt, this can easily be done with the command (be
3462  sure you are in the sdcc directory):
3463 \newline 
3464
3465 \newline 
3466
3467 \family sans 
3468 \series bold 
3469 find .
3470  
3471 \backslash 
3472 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
3473 \backslash 
3474 ) -print -exec rm {} 
3475 \backslash 
3476 ;
3477 \family default 
3478 \series default 
3479
3480 \newline 
3481
3482 \newline 
3483 or on Windows NT/2000/XP from the command prompt with the command:
3484 \newline 
3485
3486 \family sans 
3487 \series bold 
3488
3489 \newline 
3490 del /s *.obj *.lib *.rul
3491 \family default 
3492 \series default 
3493  from the sdcc directory.
3494 \layout Subsection
3495
3496 Windows Install Using a ZIP Package
3497 \layout Enumerate
3498
3499 Download the binary zip package from 
3500 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
3501
3502 \end_inset 
3503
3504  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
3505  This should unpack to a group of sub-directories.
3506  An example directory structure after unpacking the mingw32 package is:
3507  c:
3508 \backslash 
3509 sdcc
3510 \backslash 
3511 bin for the executables, c:
3512 \backslash 
3513 sdcc
3514 \backslash 
3515 include and c:
3516 \backslash 
3517 sdcc
3518 \backslash 
3519 lib for the include and libraries.
3520 \layout Enumerate
3521
3522 Adjust your environment variable PATH to include the location of the bin
3523  directory or start sdcc using the full path.
3524 \layout Subsection
3525
3526 Windows Install Using the Setup Program
3527 \begin_inset LatexCommand \label{sub:Windows-Install}
3528
3529 \end_inset 
3530
3531
3532 \layout Standard
3533
3534 Download the setup program 
3535 \emph on 
3536 sdcc-x.y.z-setup.exe
3537 \emph default 
3538  for an official release from 
3539 \newline 
3540
3541 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
3542
3543 \end_inset 
3544
3545  or a setup program for one of the snapshots 
3546 \emph on 
3547 sdcc_yyyymmdd_setup.exe
3548 \emph default 
3549  from 
3550 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
3551
3552 \end_inset 
3553
3554  and execute it.
3555  A windows typical installer will guide you through the installation process.
3556 \layout Section
3557
3558 Building the Documentation
3559 \layout Standard
3560
3561 If the necessary tools (LyX, LaTeX, LaTeX2HTML) are installed it is as easy
3562  as changing into the doc directory and typing 
3563 \family sans 
3564 \series bold 
3565
3566 \begin_inset Quotes srd
3567 \end_inset 
3568
3569 make
3570 \begin_inset Quotes srd
3571 \end_inset 
3572
3573
3574 \family default 
3575 \series default 
3576  there.
3577  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
3578 x).
3579  Using LyX 
3580 \begin_inset LatexCommand \url{http://www.lyx.org}
3581
3582 \end_inset 
3583
3584  as editor this is straightforward.
3585  Prebuilt documentation in html and pdf format is available from 
3586 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
3587
3588 \end_inset 
3589
3590 .
3591 \layout Section
3592
3593 Reading the Documentation
3594 \layout Standard
3595
3596 Currently reading the document in pdf format is recommended, as for unknown
3597  reason the hyperlinks are working there whereas in the html version they
3598  are not
3599 \begin_inset Foot
3600 collapsed false
3601
3602 \layout Standard
3603
3604 If you should know why please drop us a note
3605 \end_inset 
3606
3607 .
3608  
3609 \newline 
3610 You'll find the pdf version
3611 \begin_inset LatexCommand \index{PDF version of this document}
3612
3613 \end_inset 
3614
3615  at 
3616 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
3617
3618 \end_inset 
3619
3620 .
3621  
3622 \newline 
3623 A html version
3624 \begin_inset LatexCommand \index{HTML version of this document}
3625
3626 \end_inset 
3627
3628  should be online at 
3629 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
3630
3631 \end_inset 
3632
3633 .
3634 \newline 
3635 This documentation is in some aspects different from a commercial documentation:
3636  
3637 \layout Itemize
3638
3639 It tries to document SDCC for several processor architectures in one document
3640  (commercially these probably would be separate documents/products).
3641  This document
3642 \begin_inset LatexCommand \index{Status of documentation}
3643
3644 \end_inset 
3645
3646  currently matches SDCC for mcs51 and DS390 best and does give too few informati
3647 on about f.e.
3648  Z80, PIC14, PIC16 and HC08.
3649 \layout Itemize
3650
3651 There are many references pointing away from this documentation.
3652  Don't let this distract you.
3653  If there f.e.
3654  was a reference like 
3655 \begin_inset LatexCommand \url{http://www.opencores.org}
3656
3657 \end_inset 
3658
3659  together with a statement 
3660 \begin_inset Quotes sld
3661 \end_inset 
3662
3663 some processors which are targetted by SDCC can be implemented in a 
3664 \emph on 
3665 f
3666 \emph default 
3667 ield 
3668 \emph on 
3669 p
3670 \emph default 
3671 rogrammable 
3672 \emph on 
3673 g
3674 \emph default 
3675 ate 
3676 \emph on 
3677 a
3678 \emph default 
3679 rray
3680 \begin_inset LatexCommand \index{fpga (field programmable gate array)}
3681
3682 \end_inset 
3683
3684
3685 \begin_inset Quotes srd
3686 \end_inset 
3687
3688  we expect you to have a quick look there and come back.
3689  If you read this you are on the right track.
3690 \layout Itemize
3691
3692 Some sections attribute more space to problems, restrictions and warnings
3693  than to the solution.
3694 \layout Itemize
3695
3696 The installation section and the section about the debugger is intimidating.
3697 \layout Itemize
3698
3699 There are still lots of typos and there are more different writing styles
3700  than pictures.
3701 \layout Section
3702
3703 Testing the SDCC Compiler
3704 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
3705
3706 \end_inset 
3707
3708
3709 \layout Standard
3710
3711 The first thing you should do after installing your SDCC compiler is to
3712  see if it runs.
3713  Type 
3714 \family sans 
3715 \series bold 
3716 "sdcc -
3717 \begin_inset ERT
3718 status Collapsed
3719
3720 \layout Standard
3721
3722 \backslash 
3723 /
3724 \end_inset 
3725
3726 -version"
3727 \begin_inset LatexCommand \index{version}
3728
3729 \end_inset 
3730
3731
3732 \family default 
3733 \series default 
3734  at the prompt, and the program should run and tell you the version.
3735  If it doesn't run, or gives a message about not finding sdcc program, then
3736  you need to check over your installation.
3737  Make sure that the sdcc bin directory is in your executable search path
3738  defined by the PATH environment setting (
3739 \series medium 
3740 see 
3741 \series default 
3742 section 
3743 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3744
3745 \end_inset 
3746
3747 \SpecialChar ~
3748
3749 \series medium 
3750 Install trouble-shooting for suggestions
3751 \series default 
3752 ).
3753  Make sure that the sdcc program is in the bin folder, if not perhaps something
3754  did not install correctly.
3755 \newline 
3756
3757 \newline 
3758
3759 \series medium 
3760 SDCC 
3761 \series default 
3762 is commonly installed as described in section 
3763 \begin_inset Quotes sld
3764 \end_inset 
3765
3766 Install and search paths
3767 \begin_inset Quotes srd
3768 \end_inset 
3769
3770 .
3771 \newline 
3772
3773 \newline 
3774
3775 \series medium 
3776 Make sure the compiler works on a very simple example.
3777  Type in the following test.c program using your favorite 
3778 \series default 
3779 ASCII 
3780 \series medium 
3781 editor:
3782 \layout Verse
3783
3784
3785 \family typewriter 
3786 char test;
3787 \newline 
3788
3789 \newline 
3790 void main(void) {
3791 \newline 
3792 \SpecialChar ~
3793 \SpecialChar ~
3794 \SpecialChar ~
3795 \SpecialChar ~
3796 test=0;
3797 \newline 
3798 }
3799 \layout Standard
3800
3801
3802 \series medium 
3803 Compile this using the following command: 
3804 \family sans 
3805 \series bold 
3806 "sdcc -c test.c".
3807
3808 \family default 
3809 \series default 
3810  
3811 \series medium 
3812 If all goes well, the compiler will generate a test.asm and test.rel file.
3813  Congratulations, you've just compiled your first program with SDCC.
3814  We used the -c option to tell SDCC not to link the generated code, just
3815  to keep things simple for this step.
3816 \series default 
3817
3818 \newline 
3819
3820 \newline 
3821
3822 \series medium 
3823 The next step is to try it with the linker.
3824  Type in 
3825 \family sans 
3826 \series bold 
3827 "sdcc test.c
3828 \family default 
3829 \series default 
3830 "
3831 \series medium 
3832 .
3833  If all goes well the compiler will link with the libraries and produce
3834  a test.ihx output file.
3835  If this step fails
3836 \series default 
3837  
3838 \series medium 
3839 (no test.ihx, and the linker generates warnings), then the problem is most
3840  likely that 
3841 \series default 
3842 SDCC
3843 \series medium 
3844  cannot find the 
3845 \series default 
3846 /
3847 \series medium 
3848 usr/local/share/sdcc/lib directory
3849 \series default 
3850  
3851 \series medium 
3852 (see 
3853 \series default 
3854 section 
3855 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3856
3857 \end_inset 
3858
3859 \SpecialChar ~
3860
3861 \series medium 
3862 Install trouble-shooting for suggestions).
3863 \series default 
3864
3865 \newline 
3866
3867 \newline 
3868
3869 \series medium 
3870 The final test is to ensure 
3871 \series default 
3872 SDCC
3873 \series medium 
3874  can use the 
3875 \series default 
3876 standard
3877 \series medium 
3878  header files and libraries.
3879  Edit test.c and change it to the following:
3880 \layout Verse
3881
3882
3883 \family typewriter 
3884 #include <string.h>
3885 \newline 
3886
3887 \newline 
3888 char str1[10];
3889 \newline 
3890
3891 \newline 
3892 void main(void) {
3893 \newline 
3894 \SpecialChar ~
3895 \SpecialChar ~
3896 strcpy(str1, "testing");
3897 \newline 
3898 }
3899 \layout Standard
3900
3901
3902 \series medium 
3903 Compile this by typing 
3904 \family sans 
3905 \series bold 
3906 "sdcc test.c"
3907 \family default 
3908 \series medium 
3909 .
3910  This should generate a test.ihx output file, and it should give no warnings
3911  such as not finding the string.h file.
3912  If it cannot find the string.h file, then the problem is that 
3913 \series default 
3914 SDCC
3915 \series medium 
3916  cannot find the /usr/local/share/sdcc/include directory
3917 \series default 
3918  
3919 \series medium 
3920 (see the 
3921 \series default 
3922 section 
3923 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3924
3925 \end_inset 
3926
3927 \SpecialChar ~
3928
3929 \series medium 
3930 Install trouble-shooting section for suggestions).
3931
3932 \series default 
3933  Use option 
3934 \series bold 
3935 -
3936 \begin_inset ERT
3937 status Collapsed
3938
3939 \layout Standard
3940
3941 \backslash 
3942 /
3943 \end_inset 
3944
3945 -print-search-dirs
3946 \series default 
3947
3948 \begin_inset LatexCommand \index{-\/-print-search-dirs}
3949
3950 \end_inset 
3951
3952  to find exactly where SDCC is looking for the include and lib files.
3953 \layout Section
3954
3955 Install Trouble-shooting
3956 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
3957
3958 \end_inset 
3959
3960
3961 \begin_inset LatexCommand \index{Install trouble-shooting}
3962
3963 \end_inset 
3964
3965
3966 \layout Subsection
3967
3968 If SDCC does not build correctly
3969 \layout Standard
3970
3971 A thing to try is starting from scratch by unpacking the .tgz source package
3972  again in an empty directory.
3973  Configure it like:
3974 \newline 
3975
3976 \newline 
3977
3978 \family sans 
3979 \series bold 
3980 ./configure 2>&1 | tee configure.log
3981 \family default 
3982 \series default 
3983
3984 \newline 
3985
3986 \newline 
3987 and build it like:
3988 \newline 
3989
3990 \newline 
3991
3992 \family sans 
3993 \series bold 
3994 make 2>&1 | tee make.log
3995 \family default 
3996 \series default 
3997
3998 \newline 
3999
4000 \newline 
4001 If anything goes wrong, you can review the log files to locate the problem.
4002  Or a relevant part of this can be attached to an email that could be helpful
4003  when requesting help from the mailing list.
4004 \layout Subsection
4005
4006 What the 
4007 \begin_inset Quotes sld
4008 \end_inset 
4009
4010 ./configure
4011 \begin_inset Quotes srd
4012 \end_inset 
4013
4014  does
4015 \layout Standard
4016
4017 The 
4018 \begin_inset Quotes sld
4019 \end_inset 
4020
4021 ./configure
4022 \begin_inset Quotes srd
4023 \end_inset 
4024
4025  command is a script that analyzes your system and performs some configuration
4026  to ensure the source package compiles on your system.
4027  It will take a few minutes to run, and will compile a few tests to determine
4028  what compiler features are installed.
4029 \layout Subsection
4030
4031 What the 
4032 \begin_inset Quotes sld
4033 \end_inset 
4034
4035 make
4036 \begin_inset Quotes srd
4037 \end_inset 
4038
4039  does
4040 \layout Standard
4041
4042 This runs the GNU make tool, which automatically compiles all the source
4043  packages into the final installed binary executables.
4044 \layout Subsection
4045
4046 What the 
4047 \begin_inset Quotes sld
4048 \end_inset 
4049
4050 make install
4051 \begin_inset Quotes erd
4052 \end_inset 
4053
4054  command does.
4055 \layout Standard
4056
4057 This will install the compiler, other executables libraries and include
4058  files into the appropriate directories.
4059  See sections 
4060 \begin_inset LatexCommand \ref{sub:Install-paths}
4061
4062 \end_inset 
4063
4064 ,\SpecialChar ~
4065
4066 \begin_inset LatexCommand \ref{sub:Search-Paths}
4067
4068 \end_inset 
4069
4070 \SpecialChar ~
4071 about install and search paths.
4072 \newline 
4073 On most systems you will need super-user privileges to do this.
4074 \layout Section
4075
4076 Components of SDCC
4077 \layout Standard
4078
4079 SDCC is not just a compiler, but a collection of tools by various developers.
4080  These include linkers, assemblers, simulators and other components.
4081  Here is a summary of some of the components.
4082  Note that the included simulator and assembler have separate documentation
4083  which you can find in the source package in their respective directories.
4084  As SDCC grows to include support for other processors, other packages from
4085  various developers are included and may have their own sets of documentation.
4086 \newline 
4087
4088 \newline 
4089 You might want to look at the files which are installed in <installdir>.
4090  At the time of this writing, we find the following programs for gcc-builds:
4091 \newline 
4092  
4093 \newline 
4094 In <installdir>/bin:
4095 \layout Itemize
4096
4097 sdcc - The compiler.
4098 \layout Itemize
4099
4100 sdcpp - The C preprocessor.
4101 \layout Itemize
4102
4103 asx8051 - The assembler for 8051 type processors.
4104 \layout Itemize
4105
4106 as-z80
4107 \series bold 
4108
4109 \series default 
4110 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
4111 \layout Itemize
4112
4113 aslink -The linker for 8051 type processors.
4114 \layout Itemize
4115
4116 link-z80
4117 \series bold 
4118
4119 \series default 
4120 link-gbz80 - The Z80 and GameBoy Z80 linkers.
4121 \layout Itemize
4122
4123 s51 - The ucSim 8051 simulator.
4124  Not available on Win32 platforms.
4125 \layout Itemize
4126
4127 sdcdb - The source debugger.
4128  Not available on Win32 platforms.
4129 \layout Itemize
4130
4131 packihx - A tool to pack (compress) Intel hex files.
4132 \layout Standard
4133
4134 In <installdir>/share/sdcc/include
4135 \layout Itemize
4136
4137 the include files
4138 \layout Standard
4139
4140 In <installdir>/share/sdcc/lib
4141 \layout Itemize
4142
4143 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
4144  relocatables.
4145 \layout Standard
4146
4147 In <installdir>/share/sdcc/doc
4148 \layout Itemize
4149
4150 the documentation
4151 \layout Standard
4152
4153 As development for other processors proceeds, this list will expand to include
4154  executables to support processors like AVR, PIC, etc.
4155 \layout Subsection
4156
4157 sdcc - The Compiler
4158 \layout Standard
4159
4160 This is the actual compiler, it in turn uses the c-preprocessor and invokes
4161  the assembler and linkage editor.
4162 \layout Subsection
4163
4164 sdcpp - The C-Preprocessor
4165 \layout Standard
4166
4167 The preprocessor
4168 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
4169
4170 \end_inset 
4171
4172  is a modified version of the GNU preprocessor.
4173  The C preprocessor is used to pull in #include sources, process #ifdef
4174  statements, #defines and so on.
4175 \layout Subsection
4176
4177 as
4178 \emph on 
4179 xxxx
4180 \emph default 
4181 , aslink, link-
4182 \emph on 
4183 xxx
4184 \emph default 
4185  - The Assemblers and Linkage Editors
4186 \layout Standard
4187
4188 This is retargettable assembler & linkage editor, it was developed by Alan
4189  Baldwin.
4190  John Hartman created the version for 8051, and I (Sandeep) have made some
4191  enhancements and bug fixes for it to work properly with SDCC.
4192 \layout Subsection
4193
4194 s51 - The Simulator
4195 \layout Standard
4196
4197 S51
4198 \begin_inset LatexCommand \index{s51}
4199
4200 \end_inset 
4201
4202  is a freeware, opensource simulator developed by Daniel Drotos.
4203  The simulator is built as part of the build process.
4204  For more information visit Daniel's web site at: 
4205 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
4206
4207 \end_inset 
4208
4209 .
4210  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
4211  XA51 family.
4212  S51 is currently not available on Win32 platfors.
4213 \layout Subsection
4214
4215 sdcdb - Source Level Debugger
4216 \layout Standard
4217
4218 Sdcdb
4219 \begin_inset LatexCommand \index{sdcdb (debugger)}
4220
4221 \end_inset 
4222
4223  is the companion source level debugger.
4224  More about sdcdb in section 
4225 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
4226
4227 \end_inset 
4228
4229 .
4230  The current version of the debugger uses Daniel's Simulator S51
4231 \begin_inset LatexCommand \index{s51}
4232
4233 \end_inset 
4234
4235 , but can be easily changed to use other simulators.
4236  Sdcdb is currently not available on Win32 platfors.
4237 \layout Chapter
4238
4239 Using SDCC
4240 \layout Section
4241
4242 Compiling
4243 \layout Subsection
4244
4245 Single Source File Projects
4246 \layout Standard
4247
4248 For single source file 8051 projects the process is very simple.
4249  Compile your programs with the following command 
4250 \family sans 
4251 \series bold 
4252 "sdcc sourcefile.c".
4253
4254 \family default 
4255 \series default 
4256  This will compile, assemble and link your source file.
4257  Output files are as follows:
4258 \layout Itemize
4259
4260 sourcefile.asm
4261 \begin_inset LatexCommand \index{<file>.asm}
4262
4263 \end_inset 
4264
4265  - Assembler source
4266 \begin_inset LatexCommand \index{Assembler source}
4267
4268 \end_inset 
4269
4270  file created by the compiler
4271 \layout Itemize
4272
4273 sourcefile.lst
4274 \begin_inset LatexCommand \index{<file>.lst}
4275
4276 \end_inset 
4277
4278  - Assembler listing
4279 \begin_inset LatexCommand \index{Assembler listing}
4280
4281 \end_inset 
4282
4283  file created by the Assembler
4284 \layout Itemize
4285
4286 sourcefile.rst
4287 \begin_inset LatexCommand \index{<file>.rst}
4288
4289 \end_inset 
4290
4291  - Assembler listing
4292 \begin_inset LatexCommand \index{Assembler listing}
4293
4294 \end_inset 
4295
4296  file updated with linkedit information, created by linkage editor
4297 \layout Itemize
4298
4299 sourcefile.sym
4300 \begin_inset LatexCommand \index{<file>.sym}
4301
4302 \end_inset 
4303
4304  - symbol listing
4305 \begin_inset LatexCommand \index{Symbol listing}
4306
4307 \end_inset 
4308
4309  for the sourcefile, created by the assembler
4310 \layout Itemize
4311
4312 sourcefile.rel
4313 \begin_inset LatexCommand \index{<file>.rel}
4314
4315 \end_inset 
4316
4317  or sourcefile.o
4318 \begin_inset LatexCommand \index{<file>.o}
4319
4320 \end_inset 
4321
4322  - Object file
4323 \begin_inset LatexCommand \index{Object file}
4324
4325 \end_inset 
4326
4327  created by the assembler, input to Linkage editor
4328 \layout Itemize
4329
4330 sourcefile.map
4331 \begin_inset LatexCommand \index{<file>.map}
4332
4333 \end_inset 
4334
4335  - The memory map
4336 \begin_inset LatexCommand \index{Memory map}
4337
4338 \end_inset 
4339
4340  for the load module, created by the Linker
4341 \layout Itemize
4342
4343 sourcefile.mem
4344 \begin_inset LatexCommand \index{<file>.mem}
4345
4346 \end_inset 
4347
4348  - A file with a summary of the memory usage
4349 \layout Itemize
4350
4351 sourcefile.ihx
4352 \begin_inset LatexCommand \index{<file>.ihx}
4353
4354 \end_inset 
4355
4356  - The load module in Intel hex format
4357 \begin_inset LatexCommand \index{Intel hex format}
4358
4359 \end_inset 
4360
4361  (you can select the Motorola S19 format
4362 \begin_inset LatexCommand \index{Motorola S19 format}
4363
4364 \end_inset 
4365
4366  with -
4367 \begin_inset ERT
4368 status Collapsed
4369
4370 \layout Standard
4371
4372 \backslash 
4373 /
4374 \end_inset 
4375
4376 -out-fmt-s19
4377 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
4378
4379 \end_inset 
4380
4381 .
4382  If you need another format you might want to use 
4383 \family sans 
4384 \shape italic 
4385 objdump
4386 \family default 
4387 \shape default 
4388
4389 \begin_inset LatexCommand \index{objdump (tool)}
4390
4391 \end_inset 
4392
4393  or
4394 \family sans 
4395 \shape italic 
4396  srecord
4397 \family default 
4398 \shape default 
4399
4400 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
4401
4402 \end_inset 
4403
4404 ).
4405  Both formats are documented in the documentation of srecord
4406 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
4407
4408 \end_inset 
4409
4410
4411 \layout Itemize
4412
4413 sourcefile.adb
4414 \begin_inset LatexCommand \index{<file>.adb}
4415
4416 \end_inset 
4417
4418  - An intermediate file containing debug information needed to create the
4419  .cdb file (with -
4420 \begin_inset ERT
4421 status Open
4422
4423 \layout Standard
4424
4425 \backslash 
4426 /
4427 \end_inset 
4428
4429 -debug
4430 \begin_inset LatexCommand \index{-\/-debug}
4431
4432 \end_inset 
4433
4434
4435 \layout Itemize
4436
4437 sourcefile.cdb
4438 \begin_inset LatexCommand \index{<file>.cdb}
4439
4440 \end_inset 
4441
4442  - An optional file (with -
4443 \begin_inset ERT
4444 status Collapsed
4445
4446 \layout Standard
4447
4448 \backslash 
4449 /
4450 \end_inset 
4451
4452 -debug) containing debug information.
4453  The format is documented in cdbfileformat.pdf
4454 \layout Itemize
4455
4456 sourcefile.
4457  - (no extension)
4458 \begin_inset LatexCommand \index{<file> (no extension)}
4459
4460 \end_inset 
4461
4462  An optional AOMF or AOMF51
4463 \begin_inset LatexCommand \index{AOMF, AOMF51}
4464
4465 \end_inset 
4466
4467  file containing debug information (generated with option -
4468 \begin_inset ERT
4469 status Collapsed
4470
4471 \layout Standard
4472
4473 \backslash 
4474 /
4475 \end_inset 
4476
4477 -debug).
4478  The (Intel)
4479 \emph on 
4480  a
4481 \emph default 
4482 bsolute 
4483 \emph on 
4484 o
4485 \emph default 
4486 bject 
4487 \emph on 
4488 m
4489 \emph default 
4490 odule 
4491 \emph on 
4492 f
4493 \emph default 
4494 ormat is commonly used by third party tools (debuggers
4495 \begin_inset LatexCommand \index{Debugger}
4496
4497 \end_inset 
4498
4499 , simulators, emulators)
4500 \layout Itemize
4501
4502 sourcefile.dump*
4503 \begin_inset LatexCommand \index{<file>.dump*}
4504
4505 \end_inset 
4506
4507  - Dump file to debug the compiler it self (generated with option -
4508 \begin_inset ERT
4509 status Collapsed
4510
4511 \layout Standard
4512
4513 \backslash 
4514 /
4515 \end_inset 
4516
4517 -dumpall) (see section 
4518 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
4519
4520 \end_inset 
4521
4522 \SpecialChar ~
4523  and section 
4524 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
4525
4526 \end_inset 
4527
4528 \SpecialChar ~
4529
4530 \begin_inset Quotes sld
4531 \end_inset 
4532
4533 Anatomy of the compiler
4534 \begin_inset Quotes srd
4535 \end_inset 
4536
4537 ).
4538 \layout Subsection
4539
4540 Projects with Multiple Source Files
4541 \layout Standard
4542
4543 SDCC can compile only ONE file at a time.
4544  Let us for example assume that you have a project containing the following
4545  files:
4546 \newline 
4547
4548 \newline 
4549 foo1.c (contains some functions)
4550 \newline 
4551 foo2.c (contains some more functions)
4552 \newline 
4553 foomain.c (contains more functions and the function main)
4554 \newline 
4555
4556 \size footnotesize 
4557
4558 \newline 
4559
4560 \size default 
4561 The first two files will need to be compiled separately with the commands:
4562 \size footnotesize 
4563  
4564 \size default 
4565
4566 \newline 
4567
4568 \newline 
4569
4570 \family sans 
4571 \series bold 
4572 sdcc\SpecialChar ~
4573 -c\SpecialChar ~
4574 foo1.c
4575 \family default 
4576 \series default 
4577 \size footnotesize 
4578
4579 \newline 
4580
4581 \family sans 
4582 \series bold 
4583 \size default 
4584 sdcc\SpecialChar ~
4585 -c\SpecialChar ~
4586 foo2.c
4587 \family default 
4588 \series default 
4589
4590 \newline 
4591
4592 \newline 
4593 Then compile the source file containing the 
4594 \emph on 
4595 main()
4596 \emph default 
4597  function and link
4598 \begin_inset LatexCommand \index{Linker}
4599
4600 \end_inset 
4601
4602  the files together with the following command: 
4603 \newline 
4604
4605 \newline 
4606
4607 \family sans 
4608 \series bold 
4609 sdcc\SpecialChar ~
4610 foomain.c\SpecialChar ~
4611 foo1.rel\SpecialChar ~
4612 foo2.rel
4613 \family default 
4614 \series default 
4615
4616 \begin_inset LatexCommand \index{<file>.rel}
4617
4618 \end_inset 
4619
4620
4621 \newline 
4622
4623 \newline 
4624 Alternatively, 
4625 \emph on 
4626 foomain.c 
4627 \emph default 
4628 can be separately compiled as well: 
4629 \family sans 
4630 \series bold 
4631
4632 \newline 
4633
4634 \newline 
4635 sdcc\SpecialChar ~
4636 -c\SpecialChar ~
4637 foomain.c
4638 \newline 
4639 sdcc foomain.rel foo1.rel foo2.rel
4640 \newline 
4641
4642 \newline 
4643
4644 \family default 
4645 \series default 
4646 The file containing the 
4647 \emph on 
4648 main()
4649 \emph default 
4650  function
4651 \emph on 
4652  
4653 \emph default 
4654 \noun on 
4655 must
4656 \noun default 
4657  be the 
4658 \noun on 
4659 first
4660 \noun default 
4661  file specified in the command line, since the linkage editor processes
4662  file in the order they are presented to it.
4663  The linker is invoked from SDCC using a script file with extension .lnk
4664 \begin_inset LatexCommand \index{<file>.lnk}
4665
4666 \end_inset 
4667
4668 .
4669  You can view this file to troubleshoot linking problems such as those arising
4670  from missing libraries.
4671 \layout Subsection
4672
4673 Projects with Additional Libraries
4674 \begin_inset LatexCommand \index{Libraries}
4675
4676 \end_inset 
4677
4678
4679 \layout Standard
4680
4681 Some reusable routines may be compiled into a library, see the documentation
4682  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
4683  for how to create a 
4684 \emph on 
4685 .lib
4686 \begin_inset LatexCommand \index{<file>.lib}
4687
4688 \end_inset 
4689
4690
4691 \emph default 
4692  library file.
4693  Libraries created in this manner can be included in the command line.
4694  Make sure you include the -L <library-path> option to tell the linker where
4695  to look for these files if they are not in the current directory.
4696  Here is an example, assuming you have the source file 
4697 \emph on 
4698 foomain.c
4699 \emph default 
4700  and a library
4701 \emph on 
4702  foolib.lib
4703 \emph default 
4704  in the directory 
4705 \emph on 
4706 mylib
4707 \emph default 
4708  (if that is not the same as your current project):
4709 \newline 
4710
4711 \newline 
4712
4713 \family sans 
4714 \series bold 
4715 sdcc foomain.c foolib.lib -L mylib
4716 \newline 
4717
4718 \newline 
4719
4720 \family default 
4721 \series default 
4722 Note here that
4723 \emph on 
4724  mylib
4725 \emph default 
4726  must be an absolute path name.
4727 \newline 
4728
4729 \newline 
4730 The most efficient way to use libraries is to keep separate modules in separate
4731  source files.
4732  The lib file now should name all the modules.rel
4733 \begin_inset LatexCommand \index{<file>.rel}
4734
4735 \end_inset 
4736
4737  files.
4738  For an example see the standard library file 
4739 \emph on 
4740 libsdcc.lib
4741 \emph default 
4742  in the directory <installdir>/share/lib/small.
4743 \layout Subsection
4744
4745 Using sdcclib to Create and Manage Libraries
4746 \begin_inset LatexCommand \index{sdcclib}
4747
4748 \end_inset 
4749
4750
4751 \layout Standard
4752
4753 Alternatively, instead of having a .rel file for each entry on the library
4754  file as described in the preceding section, sdcclib can be used to embed
4755  all the modules belonging to such library in the library file itself.
4756  This results in a larger library file, but it greatly reduces the number
4757  of disk files accessed by the linker.
4758   Additionally, the packed library file contains an index of all include
4759  modules and symbols that significantly speeds up the linking process.
4760  To display a list of options supported by sdcclib type:
4761 \newline 
4762
4763 \layout Standard
4764
4765
4766 \family sans 
4767 \series bold 
4768 sdcclib -?
4769 \begin_inset LatexCommand \index{sdcclib}
4770
4771 \end_inset 
4772
4773
4774 \newline 
4775
4776 \newline 
4777
4778 \family default 
4779 \series default 
4780 To create a new library file, start by compiling all the required modules.
4781  For example:
4782 \newline 
4783
4784 \layout Standard
4785
4786
4787 \family sans 
4788 \series bold 
4789 sdcc -c _divsint.c
4790 \layout Standard
4791
4792
4793 \family sans 
4794 \series bold 
4795 sdcc -c _divuint.c
4796 \layout Standard
4797
4798
4799 \family sans 
4800 \series bold 
4801 sdcc -c _modsint.c
4802 \layout Standard
4803
4804
4805 \family sans 
4806 \series bold 
4807 sdcc -c _moduint.c
4808 \layout Standard
4809
4810
4811 \family sans 
4812 \series bold 
4813 sdcc -c _mulint.c
4814 \newline 
4815
4816 \layout Standard
4817
4818 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
4819  and _mulint.rel.
4820  The next step is to add the .rel files to the library file:
4821 \newline 
4822
4823 \layout Standard
4824
4825
4826 \family sans 
4827 \series bold 
4828 sdcclib libint.lib _divsint.rel
4829 \family default 
4830
4831 \begin_inset LatexCommand \index{sdcclib}
4832
4833 \end_inset 
4834
4835
4836 \layout Standard
4837
4838
4839 \family sans 
4840 \series bold 
4841 sdcclib libint.lib _divuint.rel
4842 \layout Standard
4843
4844
4845 \family sans 
4846 \series bold 
4847 sdcclib libint.lib _modsint.rel
4848 \layout Standard
4849
4850
4851 \family sans 
4852 \series bold 
4853 sdcclib libint.lib _moduint.rel
4854 \layout Standard
4855
4856
4857 \family sans 
4858 \series bold 
4859 sdcclib libint.lib _mulint.rel
4860 \series default 
4861
4862 \newline 
4863
4864 \layout Standard
4865
4866 If the file already exists in the library, it will be replaced.
4867  To see what modules and symbols are included in the library, options -s
4868  and -m are available.
4869  For example:
4870 \newline 
4871
4872 \newline 
4873
4874 \family sans 
4875 \series bold 
4876 sdcclib -s libint.lib
4877 \family default 
4878
4879 \begin_inset LatexCommand \index{sdcclib}
4880
4881 \end_inset 
4882
4883
4884 \newline 
4885
4886 \family typewriter 
4887 \series default 
4888 _divsint.rel:
4889 \layout Standard
4890
4891
4892 \family typewriter 
4893 __divsint_a_1_1
4894 \layout Standard
4895
4896
4897 \family typewriter 
4898 __divsint_PARM_2
4899 \layout Standard
4900
4901
4902 \family typewriter 
4903 __divsint
4904 \newline 
4905 _divuint.rel:
4906 \layout Standard
4907
4908
4909 \family typewriter 
4910 __divuint_a_1_1
4911 \layout Standard
4912
4913
4914 \family typewriter 
4915 __divuint_PARM_2
4916 \layout Standard
4917
4918
4919 \family typewriter 
4920 __divuint_reste_1_1
4921 \layout Standard
4922
4923
4924 \family typewriter 
4925 __divuint_count_1_1
4926 \layout Standard
4927
4928
4929 \family typewriter 
4930 __divuint
4931 \newline 
4932 _modsint.rel:
4933 \layout Standard
4934
4935
4936 \family typewriter 
4937 __modsint_a_1_1
4938 \layout Standard
4939
4940
4941 \family typewriter 
4942 __modsint_PARM_2
4943 \layout Standard
4944
4945
4946 \family typewriter 
4947 __modsint
4948 \newline 
4949 _moduint.rel:
4950 \layout Standard
4951
4952
4953 \family typewriter 
4954 __moduint_a_1_1
4955 \layout Standard
4956
4957
4958 \family typewriter 
4959 __moduint_PARM_2
4960 \layout Standard
4961
4962
4963 \family typewriter 
4964 __moduint_count_1_1
4965 \layout Standard
4966
4967
4968 \family typewriter 
4969 __moduint
4970 \newline 
4971 _mulint.rel:
4972 \layout Standard
4973
4974
4975 \family typewriter 
4976 __mulint_PARM_2
4977 \layout Standard
4978
4979
4980 \family typewriter 
4981 __mulint
4982 \family default 
4983 \series bold 
4984
4985 \newline 
4986
4987 \layout Standard
4988
4989 If the source files are compiled using -
4990 \begin_inset ERT
4991 status Open
4992
4993 \layout Standard
4994
4995 \backslash 
4996 /
4997 \end_inset 
4998
4999 -debug
5000 \begin_inset LatexCommand \index{-\/-debug}
5001
5002 \end_inset 
5003
5004 , the corresponding debug information file .adb will be include in the library
5005  file as well.
5006  The library files created with sdcclib are plain text files, so they can
5007  be viewed with a text editor.
5008  It is not recomended to modify a library file created with sdcclib using
5009  a text editor, as there are file indexes numbers located accross the file
5010  used by the linker to quickly locate the required module to link.
5011  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
5012  it can be safely deleted, since all the information required for linking
5013  is embedded in the library file itself.
5014  Library files created using sdcclib are used as described in the preceding
5015  sections.
5016 \layout Section
5017
5018 Command Line Options
5019 \begin_inset LatexCommand \index{Command Line Options}
5020
5021 \end_inset 
5022
5023
5024 \layout Subsection
5025
5026 Processor Selection Options
5027 \begin_inset LatexCommand \index{Options processor selection}
5028
5029 \end_inset 
5030
5031
5032 \begin_inset LatexCommand \index{Processor selection options}
5033
5034 \end_inset 
5035
5036
5037 \layout List
5038 \labelwidthstring 00.00.0000
5039
5040
5041 \series bold 
5042 -mmcs51
5043 \begin_inset LatexCommand \index{-mmcs51}
5044
5045 \end_inset 
5046
5047
5048 \series default 
5049  Generate code for the Intel MCS51
5050 \begin_inset LatexCommand \index{MCS51}
5051
5052 \end_inset 
5053
5054  family of processors.
5055  This is the default processor target.
5056 \layout List
5057 \labelwidthstring 00.00.0000
5058
5059
5060 \series bold 
5061 -mds390
5062 \begin_inset LatexCommand \index{-mds390}
5063
5064 \end_inset 
5065
5066
5067 \series default 
5068  Generate code for the Dallas DS80C390
5069 \begin_inset LatexCommand \index{DS80C390}
5070
5071 \end_inset 
5072
5073  processor.
5074 \layout List
5075 \labelwidthstring 00.00.0000
5076
5077
5078 \series bold 
5079 -mds400
5080 \begin_inset LatexCommand \index{-mds400}
5081
5082 \end_inset 
5083
5084
5085 \series default 
5086  Generate code for the Dallas DS80C400
5087 \begin_inset LatexCommand \index{DS80C400}
5088
5089 \end_inset 
5090
5091  processor.
5092 \layout List
5093 \labelwidthstring 00.00.0000
5094
5095
5096 \series bold 
5097 -mhc08
5098 \begin_inset LatexCommand \index{-mhc08}
5099
5100 \end_inset 
5101
5102
5103 \series default 
5104  Generate code for the Freescale/Motorola HC08
5105 \begin_inset LatexCommand \index{HC08}
5106
5107 \end_inset 
5108
5109  family of processors.
5110 \layout List
5111 \labelwidthstring 00.00.0000
5112
5113
5114 \series bold 
5115 -mz80
5116 \begin_inset LatexCommand \index{-mz80}
5117
5118 \end_inset 
5119
5120
5121 \series default 
5122  Generate code for the Zilog Z80
5123 \begin_inset LatexCommand \index{Z80}
5124
5125 \end_inset 
5126
5127  family of processors.
5128 \layout List
5129 \labelwidthstring 00.00.0000
5130
5131
5132 \series bold 
5133 -mgbz80
5134 \begin_inset LatexCommand \index{-mgbz80}
5135
5136 \end_inset 
5137
5138
5139 \series default 
5140  Generate code for the GameBoy Z80
5141 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
5142
5143 \end_inset 
5144
5145  processor (Not actively maintained).
5146 \layout List
5147 \labelwidthstring 00.00.0000
5148
5149
5150 \series bold 
5151 -mavr
5152 \begin_inset LatexCommand \index{-mavr}
5153
5154 \end_inset 
5155
5156
5157 \series default 
5158  Generate code for the Atmel AVR
5159 \begin_inset LatexCommand \index{AVR}
5160
5161 \end_inset 
5162
5163  processor (In development, not complete).
5164  AVR users should probably have a look at winavr 
5165 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
5166
5167 \end_inset 
5168
5169  or 
5170 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
5171
5172 \end_inset 
5173
5174 .
5175 \layout Comment
5176
5177 I think it is fair to direct users there for now.
5178  Open source is also about avoiding unnecessary work .
5179  But I didn't find the 'official' link.
5180 \layout List
5181 \labelwidthstring 00.00.0000
5182
5183
5184 \series bold 
5185 -mpic14
5186 \begin_inset LatexCommand \index{-mpic14}
5187
5188 \end_inset 
5189
5190
5191 \series default 
5192  Generate code for the Microchip PIC 14
5193 \begin_inset LatexCommand \index{PIC14}
5194
5195 \end_inset 
5196
5197 -bit processors (p16f84 and variants.
5198  In development, not complete).
5199 \layout Comment
5200
5201 p16f627 p16f628 p16f84 p16f873 p16f877?
5202 \layout List
5203 \labelwidthstring 00.00.0000
5204
5205
5206 \series bold 
5207 -mpic16
5208 \begin_inset LatexCommand \index{-mpic16}
5209
5210 \end_inset 
5211
5212
5213 \series default 
5214  Generate code for the Microchip PIC 16
5215 \begin_inset LatexCommand \index{PIC16}
5216
5217 \end_inset 
5218
5219 -bit processors (p18f452 and variants.
5220  In development, not complete).
5221 \layout List
5222 \labelwidthstring 00.00.0000
5223
5224
5225 \series bold 
5226 -mtlcs900h
5227 \series default 
5228  Generate code for the Toshiba TLCS-900H
5229 \begin_inset LatexCommand \index{TLCS-900H}
5230
5231 \end_inset 
5232
5233  processor (Not maintained, not complete).
5234 \layout List
5235 \labelwidthstring 00.00.0000
5236
5237
5238 \series bold 
5239 -mxa51
5240 \begin_inset LatexCommand \index{-mxa51}
5241
5242 \end_inset 
5243
5244
5245 \series default 
5246  Generate code for the Phillips XA51
5247 \begin_inset LatexCommand \index{XA51}
5248
5249 \end_inset 
5250
5251  processor (Not maintained, not complete).
5252 \layout Subsection
5253
5254 Preprocessor Options
5255 \begin_inset LatexCommand \index{Options preprocessor}
5256
5257 \end_inset 
5258
5259
5260 \begin_inset LatexCommand \index{Preprocessor options}
5261
5262 \end_inset 
5263
5264
5265 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5266
5267 \end_inset 
5268
5269
5270 \layout List
5271 \labelwidthstring 00.00.0000
5272
5273
5274 \series bold 
5275 -I<path>
5276 \begin_inset LatexCommand \index{-I<path>}
5277
5278 \end_inset 
5279
5280
5281 \series default 
5282  The additional location where the pre processor will look for <..h> or 
5283 \begin_inset Quotes eld
5284 \end_inset 
5285
5286 ..h
5287 \begin_inset Quotes erd
5288 \end_inset 
5289
5290  files.
5291 \layout List
5292 \labelwidthstring 00.00.0000
5293
5294
5295 \series bold 
5296 -D<macro[=value]>
5297 \begin_inset LatexCommand \index{-D<macro[=value]>}
5298
5299 \end_inset 
5300
5301
5302 \series default 
5303  Command line definition of macros.
5304  Passed to the preprocessor.
5305 \layout List
5306 \labelwidthstring 00.00.0000
5307
5308
5309 \series bold 
5310 -M
5311 \begin_inset LatexCommand \index{-M}
5312
5313 \end_inset 
5314
5315
5316 \series default 
5317  Tell the preprocessor to output a rule suitable for make describing the
5318  dependencies of each object file.
5319  For each source file, the preprocessor outputs one make-rule whose target
5320  is the object file name for that source file and whose dependencies are
5321  all the files `#include'd in it.
5322  This rule may be a single line or may be continued with `
5323 \backslash 
5324 '-newline if it is long.
5325  The list of rules is printed on standard output instead of the preprocessed
5326  C program.
5327  `-M' implies `-E
5328 \begin_inset LatexCommand \index{-E}
5329
5330 \end_inset 
5331
5332 '.
5333 \layout List
5334 \labelwidthstring 00.00.0000
5335
5336
5337 \series bold 
5338 -C
5339 \begin_inset LatexCommand \index{-C}
5340
5341 \end_inset 
5342
5343
5344 \series default 
5345  Tell the preprocessor not to discard comments.
5346  Used with the `-E' option.
5347 \layout List
5348 \labelwidthstring 00.00.0000
5349
5350
5351 \series bold 
5352 -MM
5353 \begin_inset LatexCommand \index{-MM}
5354
5355 \end_inset 
5356
5357
5358 \size large 
5359 \bar under 
5360  
5361 \series default 
5362 \size default 
5363 \bar default 
5364 Like `-M' but the output mentions only the user header files included with
5365  `#include 
5366 \begin_inset Quotes eld
5367 \end_inset 
5368
5369 file"'.
5370  System header files included with `#include <file>' are omitted.
5371 \layout List
5372 \labelwidthstring 00.00.0000
5373
5374
5375 \series bold 
5376 -Aquestion(answer)
5377 \begin_inset LatexCommand \index{-Aquestion(answer)}
5378
5379 \end_inset 
5380
5381
5382 \series default 
5383  Assert the answer answer for question, in case it is tested with a preprocessor
5384  conditional such as `#if #question(answer)'.
5385  `-A-' disables the standard assertions that normally describe the target
5386  machine.
5387 \layout List
5388 \labelwidthstring 00.00.0000
5389
5390
5391 \series bold 
5392 -Umacro
5393 \begin_inset LatexCommand \index{-Umacro}
5394
5395 \end_inset 
5396
5397
5398 \series default 
5399  Undefine macro macro.
5400  `-U' options are evaluated after all `-D' options, but before any `-include'
5401  and `-imacros' options.
5402 \layout List
5403 \labelwidthstring 00.00.0000
5404
5405
5406 \series bold 
5407 -dM
5408 \begin_inset LatexCommand \index{-dM}
5409
5410 \end_inset 
5411
5412
5413 \series default 
5414  Tell the preprocessor to output only a list of the macro definitions that
5415  are in effect at the end of preprocessing.
5416  Used with the `-E' option.
5417 \layout List
5418 \labelwidthstring 00.00.0000
5419
5420
5421 \series bold 
5422 -dD
5423 \begin_inset LatexCommand \index{-dD}
5424
5425 \end_inset 
5426
5427
5428 \series default 
5429  Tell the preprocessor to pass all macro definitions into the output, in
5430  their proper sequence in the rest of the output.
5431 \layout List
5432 \labelwidthstring 00.00.0000
5433
5434
5435 \series bold 
5436 -dN
5437 \begin_inset LatexCommand \index{-dN}
5438
5439 \end_inset 
5440
5441
5442 \size large 
5443 \bar under 
5444  
5445 \series default 
5446 \size default 
5447 \bar default 
5448 Like `-dD' except that the macro arguments and contents are omitted.
5449  Only `#define name' is included in the output.
5450 \layout List
5451 \labelwidthstring 00.00.0000
5452
5453
5454 \series bold 
5455 -Wp\SpecialChar ~
5456 preprocessorOption[,preprocessorOption]
5457 \series default 
5458
5459 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
5460
5461 \end_inset 
5462
5463 ...
5464  Pass the preprocessorOption to the preprocessor 
5465 \family typewriter 
5466 sdcpp
5467 \family default 
5468
5469 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5470
5471 \end_inset 
5472
5473 .
5474  SDCC uses an adapted version of the preprocessor cpp of the GNU Compiler
5475  Collection (gcc), if you need more dedicated options please refer to the
5476  documentation at 
5477 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
5478
5479 \end_inset 
5480
5481 .
5482 \layout Subsection
5483
5484 Linker Options
5485 \begin_inset LatexCommand \index{Options linker}
5486
5487 \end_inset 
5488
5489
5490 \begin_inset LatexCommand \index{Linker options}
5491
5492 \end_inset 
5493
5494
5495 \layout List
5496 \labelwidthstring 00.00.0000
5497
5498
5499 \series bold 
5500 -L\SpecialChar ~
5501 -
5502 \series default 
5503
5504 \begin_inset ERT
5505 status Collapsed
5506
5507 \layout Standard
5508
5509 \backslash 
5510 /
5511 \end_inset 
5512
5513
5514 \series bold 
5515 -lib-path
5516 \begin_inset LatexCommand \index{-\/-lib-path <path>}
5517
5518 \end_inset 
5519
5520
5521 \begin_inset LatexCommand \index{-L -\/-lib-path}
5522
5523 \end_inset 
5524
5525
5526 \series default 
5527 \SpecialChar ~
5528 <absolute path to additional libraries> This option is passed to the linkage
5529  editor's additional libraries
5530 \begin_inset LatexCommand \index{Libraries}
5531
5532 \end_inset 
5533
5534  search path.
5535  The path name must be absolute.
5536  Additional library files may be specified in the command line.
5537  See section Compiling programs for more details.
5538 \layout List
5539 \labelwidthstring 00.00.0000
5540
5541
5542 \series bold 
5543 -
5544 \begin_inset ERT
5545 status Collapsed
5546
5547 \layout Standard
5548
5549 \backslash 
5550 /
5551 \end_inset 
5552
5553 -xram-loc
5554 \series default 
5555
5556 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
5557
5558 \end_inset 
5559
5560 \SpecialChar ~
5561 <Value> The start location of the external ram
5562 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
5563
5564 \end_inset 
5565
5566 , default value is 0.
5567  The value entered can be in Hexadecimal or Decimal format, e.g.: -
5568 \begin_inset ERT
5569 status Collapsed
5570
5571 \layout Standard
5572
5573 \backslash 
5574 /
5575 \end_inset 
5576
5577 -xram-loc 0x8000 or -
5578 \begin_inset ERT
5579 status Collapsed
5580
5581 \layout Standard
5582
5583 \backslash 
5584 /
5585 \end_inset 
5586
5587 -xram-loc 32768.
5588 \layout List
5589 \labelwidthstring 00.00.0000
5590
5591
5592 \series bold 
5593 -
5594 \begin_inset ERT
5595 status Collapsed
5596
5597 \layout Standard
5598
5599 \backslash 
5600 /
5601 \end_inset 
5602
5603 -code-loc
5604 \series default 
5605
5606 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
5607
5608 \end_inset 
5609
5610 \SpecialChar ~
5611 <Value> The start location of the code
5612 \begin_inset LatexCommand \index{code}
5613
5614 \end_inset 
5615
5616  segment, default value 0.
5617  Note when this option is used the interrupt vector table is also relocated
5618  to the given address.
5619  The value entered can be in Hexadecimal or Decimal format, e.g.: -
5620 \begin_inset ERT
5621 status Collapsed
5622
5623 \layout Standard
5624
5625 \backslash 
5626 /
5627 \end_inset 
5628
5629 -code-loc 0x8000 or -
5630 \begin_inset ERT
5631 status Collapsed
5632
5633 \layout Standard
5634
5635 \backslash 
5636 /
5637 \end_inset 
5638
5639 -code-loc 32768.
5640 \layout List
5641 \labelwidthstring 00.00.0000
5642
5643
5644 \series bold 
5645 -
5646 \begin_inset ERT
5647 status Collapsed
5648
5649 \layout Standard
5650
5651 \backslash 
5652 /
5653 \end_inset 
5654
5655 -stack-loc
5656 \series default 
5657
5658 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
5659
5660 \end_inset 
5661
5662 \SpecialChar ~
5663 <Value> By default the stack
5664 \begin_inset LatexCommand \index{stack}
5665
5666 \end_inset 
5667
5668  is placed after the data segment.
5669  Using this option the stack can be placed anywhere in the internal memory
5670  space of the 8051.
5671  The value entered can be in Hexadecimal or Decimal format, e.g.
5672  -
5673 \begin_inset ERT
5674 status Collapsed
5675
5676 \layout Standard
5677
5678 \backslash 
5679 /
5680 \end_inset 
5681
5682 -stack-loc 0x20 or -
5683 \begin_inset ERT
5684 status Collapsed
5685
5686 \layout Standard
5687
5688 \backslash 
5689 /
5690 \end_inset 
5691
5692 -stack-loc 32.
5693  Since the sp register is incremented before a push or call, the initial
5694  sp will be set to one byte prior the provided value.
5695  The provided value should not overlap any other memory areas such as used
5696  register banks or the data segment and with enough space for the current
5697  application.
5698  The 
5699 \series bold 
5700 -
5701 \begin_inset ERT
5702 status Collapsed
5703
5704 \layout Standard
5705
5706 \backslash 
5707 /
5708 \end_inset 
5709
5710 -pack-iram
5711 \series default 
5712 \SpecialChar ~
5713
5714 \begin_inset LatexCommand \index{-\/-pack-iram}
5715
5716 \end_inset 
5717
5718  option (which is now a default setting) will override this setting, so
5719  you should also specify the 
5720 \series bold 
5721 -
5722 \begin_inset ERT
5723 status Collapsed
5724
5725 \layout Standard
5726
5727 \backslash 
5728 /
5729 \end_inset 
5730
5731 -no-pack-iram
5732 \series default 
5733 \SpecialChar ~
5734
5735 \begin_inset LatexCommand \index{-\/-no-pack-iram}
5736
5737 \end_inset 
5738
5739  option if you need to manually place the stack.
5740 \layout List
5741 \labelwidthstring 00.00.0000
5742
5743
5744 \series bold 
5745 -
5746 \begin_inset ERT
5747 status Collapsed
5748
5749 \layout Standard
5750
5751 \backslash 
5752 /
5753 \end_inset 
5754
5755 -xstack-loc
5756 \series default 
5757
5758 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
5759
5760 \end_inset 
5761
5762 \SpecialChar ~
5763 <Value> By default the external stack
5764 \begin_inset LatexCommand \index{xstack}
5765
5766 \end_inset 
5767
5768  is placed after the pdata segment.
5769  Using this option the xstack can be placed anywhere in the external memory
5770  space of the 8051.
5771  The value entered can be in Hexadecimal or Decimal format, e.g.
5772  -
5773 \begin_inset ERT
5774 status Collapsed
5775
5776 \layout Standard
5777
5778 \backslash 
5779 /
5780 \end_inset 
5781
5782 -xstack-loc 0x8000 or -
5783 \begin_inset ERT
5784 status Collapsed
5785
5786 \layout Standard
5787
5788 \backslash 
5789 /
5790 \end_inset 
5791
5792 -stack-loc 32768.
5793  The provided value should not overlap any other memory areas such as the
5794  pdata or xdata segment and with enough space for the current application.
5795 \layout List
5796 \labelwidthstring 00.00.0000
5797
5798
5799 \series bold 
5800 -
5801 \begin_inset ERT
5802 status Collapsed
5803
5804 \layout Standard
5805
5806 \backslash 
5807 /
5808 \end_inset 
5809
5810 -data-loc
5811 \series default 
5812
5813 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
5814
5815 \end_inset 
5816
5817 \SpecialChar ~
5818 <Value> The start location of the internal ram data
5819 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
5820
5821 \end_inset 
5822
5823  segment.
5824  The value entered can be in Hexadecimal or Decimal format, eg.
5825  -
5826 \begin_inset ERT
5827 status Collapsed
5828
5829 \layout Standard
5830
5831 \backslash 
5832 /
5833 \end_inset 
5834
5835 -data-loc 0x20 or -
5836 \begin_inset ERT
5837 status Collapsed
5838
5839 \layout Standard
5840
5841 \backslash 
5842 /
5843 \end_inset 
5844
5845 -data-loc 32.
5846  (By default, the start location of the internal ram data segment  is set
5847  as low as possible in memory, taking into account the used register banks
5848  and the bit segment at address 0x20.
5849  For example if register banks 0 and 1 are used without bit variables, the
5850  data segment will be set, if -
5851 \begin_inset ERT
5852 status Collapsed
5853
5854 \layout Standard
5855
5856 \backslash 
5857 /
5858 \end_inset 
5859
5860 -data-loc is not used, to location 0x10.)
5861 \layout List
5862 \labelwidthstring 00.00.0000
5863
5864
5865 \series bold 
5866 -
5867 \begin_inset ERT
5868 status Collapsed
5869
5870 \layout Standard
5871
5872 \backslash 
5873 /
5874 \end_inset 
5875
5876 -idata-loc
5877 \series default 
5878
5879 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
5880
5881 \end_inset 
5882
5883 \SpecialChar ~
5884 <Value> The start location of the indirectly addressable internal ram
5885 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
5886
5887 \end_inset 
5888
5889  of the 8051, default value is 0x80.
5890  The value entered can be in Hexadecimal or Decimal format, eg.
5891  -
5892 \begin_inset ERT
5893 status Collapsed
5894
5895 \layout Standard
5896
5897 \backslash 
5898 /
5899 \end_inset 
5900
5901 -idata-loc 0x88 or -
5902 \begin_inset ERT
5903 status Collapsed
5904
5905 \layout Standard
5906
5907 \backslash 
5908 /
5909 \end_inset 
5910
5911 -idata-loc 136.
5912 \layout List
5913 \labelwidthstring 00.00.0000
5914
5915
5916 \series bold 
5917 -
5918 \begin_inset ERT
5919 status Collapsed
5920
5921 \layout Standard
5922
5923 \backslash 
5924 /
5925 \end_inset 
5926
5927 -bit-loc
5928 \series default 
5929 \SpecialChar ~
5930 <Value> The start location of the bit
5931 \begin_inset LatexCommand \index{bit}
5932
5933 \end_inset 
5934
5935  addressable internal ram of the 8051.
5936  This is 
5937 \emph on 
5938 not
5939 \emph default 
5940  implemented yet.
5941  Instead an option can be passed directly to the linker: -Wl\SpecialChar ~
5942 -bBSEG=<Value>.
5943 \layout List
5944 \labelwidthstring 00.00.0000
5945
5946
5947 \series bold 
5948 -
5949 \begin_inset ERT
5950 status Collapsed
5951
5952 \layout Standard
5953
5954 \backslash 
5955 /
5956 \end_inset 
5957
5958 -out-fmt-ihx
5959 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
5960
5961 \end_inset 
5962
5963
5964 \bar under 
5965  
5966 \series default 
5967 \bar default 
5968 The linker output (final object code) is in Intel Hex format.
5969 \begin_inset LatexCommand \index{Intel hex format}
5970
5971 \end_inset 
5972
5973  This is the default option.
5974  The format itself is documented in the documentation of srecord
5975 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5976
5977 \end_inset 
5978
5979 .
5980 \layout List
5981 \labelwidthstring 00.00.0000
5982
5983
5984 \series bold 
5985 -
5986 \begin_inset ERT
5987 status Collapsed
5988
5989 \layout Standard
5990
5991 \backslash 
5992 /
5993 \end_inset 
5994
5995 -out-fmt-s19
5996 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5997
5998 \end_inset 
5999
6000
6001 \bar under 
6002  
6003 \series default 
6004 \bar default 
6005 The linker output (final object code) is in Motorola S19 format
6006 \begin_inset LatexCommand \index{Motorola S19 format}
6007
6008 \end_inset 
6009
6010 .
6011  The format itself is documented in the documentation of srecord.
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 -out-fmt-elf
6028 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
6029
6030 \end_inset 
6031
6032
6033 \bar under 
6034  
6035 \series default 
6036 \bar default 
6037 The linker output (final object code) is in ELF format
6038 \begin_inset LatexCommand \index{ELF format}
6039
6040 \end_inset 
6041
6042 .
6043  (Currently only supported for the HC08 processors)
6044 \layout List
6045 \labelwidthstring 00.00.0000
6046
6047
6048 \series bold 
6049 -Wl\SpecialChar ~
6050 linkOption[,linkOption]
6051 \series default 
6052
6053 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
6054
6055 \end_inset 
6056
6057 ...
6058  Pass the linkOption to the linker.
6059  See file sdcc/as/doc/asxhtm.html for more on linker options.
6060 \layout Subsection
6061
6062 MCS51 Options
6063 \begin_inset LatexCommand \index{Options MCS51}
6064
6065 \end_inset 
6066
6067
6068 \begin_inset LatexCommand \index{MCS51 options}
6069
6070 \end_inset 
6071
6072
6073 \layout List
6074 \labelwidthstring 00.00.0000
6075
6076
6077 \series bold 
6078 -
6079 \begin_inset ERT
6080 status Collapsed
6081
6082 \layout Standard
6083
6084 \backslash 
6085 /
6086 \end_inset 
6087
6088 -model-small
6089 \begin_inset LatexCommand \index{-\/-model-small}
6090
6091 \end_inset 
6092
6093
6094 \series default 
6095 \size large 
6096 \emph on 
6097  
6098 \size default 
6099 \emph default 
6100 Generate code for Small Model programs, see section Memory Models for more
6101  details.
6102  This is the default model.
6103 \layout List
6104 \labelwidthstring 00.00.0000
6105
6106
6107 \series bold 
6108 -
6109 \begin_inset ERT
6110 status Collapsed
6111
6112 \layout Standard
6113
6114 \backslash 
6115 /
6116 \end_inset 
6117
6118 -model-medium
6119 \begin_inset LatexCommand \index{-\/-model-medium}
6120
6121 \end_inset 
6122
6123
6124 \series default 
6125  Generate code for Medium model programs, see section Memory Models for
6126  more details.
6127  If this option is used all source files in the project have to be compiled
6128  with this option.
6129  It must also be used when invoking the linker.
6130 \layout List
6131 \labelwidthstring 00.00.0000
6132
6133
6134 \series bold 
6135 -
6136 \begin_inset ERT
6137 status Collapsed
6138
6139 \layout Standard
6140
6141 \backslash 
6142 /
6143 \end_inset 
6144
6145 -model-large
6146 \begin_inset LatexCommand \index{-\/-model-large}
6147
6148 \end_inset 
6149
6150
6151 \series default 
6152  Generate code for Large model programs, see section Memory Models for more
6153  details.
6154  If this option is used all source files in the project have to be compiled
6155  with this option.
6156  It must also be used when invoking the linker.
6157 \layout List
6158 \labelwidthstring 00.00.0000
6159
6160
6161 \series bold 
6162 -
6163 \begin_inset ERT
6164 status Collapsed
6165
6166 \layout Standard
6167
6168 \backslash 
6169 /
6170 \end_inset 
6171
6172 -xstack
6173 \begin_inset LatexCommand \index{-\/-xstack}
6174
6175 \end_inset 
6176
6177
6178 \series default 
6179  Uses a pseudo stack in the first 256 bytes in the external ram for allocating
6180  variables and passing parameters.
6181  See section 
6182 \begin_inset LatexCommand \ref{sub:External-Stack}
6183
6184 \end_inset 
6185
6186 \SpecialChar ~
6187  External Stack for more details.
6188 \layout List
6189 \labelwidthstring 00.00.0000
6190
6191
6192 \series bold 
6193 -
6194 \begin_inset ERT
6195 status Collapsed
6196
6197 \layout Standard
6198
6199 \backslash 
6200 /
6201 \end_inset 
6202
6203 -iram-size
6204 \series default 
6205 \SpecialChar ~
6206 <Value>
6207 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
6208
6209 \end_inset 
6210
6211  Causes the linker to check if the internal ram usage is within limits of
6212  the given value.
6213 \layout List
6214 \labelwidthstring 00.00.0000
6215
6216
6217 \series bold 
6218 -
6219 \begin_inset ERT
6220 status Collapsed
6221
6222 \layout Standard
6223
6224 \backslash 
6225 /
6226 \end_inset 
6227
6228 -xram-size
6229 \series default 
6230 \SpecialChar ~
6231 <Value>
6232 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
6233
6234 \end_inset 
6235
6236  Causes the linker to check if the external ram usage is within limits of
6237  the given value.
6238 \layout List
6239 \labelwidthstring 00.00.0000
6240
6241
6242 \series bold 
6243 -
6244 \begin_inset ERT
6245 status Collapsed
6246
6247 \layout Standard
6248
6249 \backslash 
6250 /
6251 \end_inset 
6252
6253 -code-size
6254 \series default 
6255 \SpecialChar ~
6256 <Value>
6257 \begin_inset LatexCommand \index{-\/-code-size <Value>}
6258
6259 \end_inset 
6260
6261  Causes the linker to check if the code memory usage is within limits of
6262  the given value.
6263 \layout List
6264 \labelwidthstring 00.00.0000
6265
6266
6267 \series bold 
6268 -
6269 \begin_inset ERT
6270 status Collapsed
6271
6272 \layout Standard
6273
6274 \backslash 
6275 /
6276 \end_inset 
6277
6278 -stack-size
6279 \series default 
6280 \SpecialChar ~
6281 <Value>
6282 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
6283
6284 \end_inset 
6285
6286  Causes the linker to check if there is at minimum <Value> bytes for stack.
6287 \layout List
6288 \labelwidthstring 00.00.0000
6289
6290
6291 \series bold 
6292 -
6293 \begin_inset ERT
6294 status Collapsed
6295
6296 \layout Standard
6297
6298 \backslash 
6299 /
6300 \end_inset 
6301
6302 -pack-iram
6303 \series default 
6304 \SpecialChar ~
6305
6306 \begin_inset LatexCommand \index{-\/-pack-iram}
6307
6308 \end_inset 
6309
6310  Causes the linker to use unused register banks for data variables and pack
6311  data, idata and stack together.
6312  This is the default now.
6313 \layout List
6314 \labelwidthstring 00.00.0000
6315
6316
6317 \series bold 
6318 -
6319 \begin_inset ERT
6320 status Collapsed
6321
6322 \layout Standard
6323
6324 \backslash 
6325 /
6326 \end_inset 
6327
6328 -no-pack-iram
6329 \series default 
6330 \SpecialChar ~
6331
6332 \begin_inset LatexCommand \index{-\/-no-pack-iram}
6333
6334 \end_inset 
6335
6336  Causes the linker to use old style for allocating memory areas.
6337 \layout Subsection
6338
6339 DS390 / DS400 Options
6340 \begin_inset LatexCommand \index{Options DS390}
6341
6342 \end_inset 
6343
6344
6345 \begin_inset LatexCommand \index{DS390 options}
6346
6347 \end_inset 
6348
6349
6350 \layout List
6351 \labelwidthstring 00.00.0000
6352
6353
6354 \series bold 
6355 -
6356 \begin_inset ERT
6357 status Collapsed
6358
6359 \layout Standard
6360
6361 \backslash 
6362 /
6363 \end_inset 
6364
6365 -model-flat24
6366 \series default 
6367
6368 \begin_inset LatexCommand \index{-\/-model-flat24}
6369
6370 \end_inset 
6371
6372
6373 \size large 
6374 \emph on 
6375  
6376 \size default 
6377 \emph default 
6378 Generate 24-bit flat mode code.
6379  This is the one and only that the ds390 code generator supports right now
6380  and is default when using 
6381 \emph on 
6382 -mds390
6383 \emph default 
6384 .
6385  See section Memory Models for more details.
6386 \layout List
6387 \labelwidthstring 00.00.0000
6388
6389
6390 \series bold 
6391 -
6392 \begin_inset ERT
6393 status Collapsed
6394
6395 \layout Standard
6396
6397 \backslash 
6398 /
6399 \end_inset 
6400
6401 -protect-sp-update
6402 \begin_inset LatexCommand \index{-\/-protect-sp-update}
6403
6404 \end_inset 
6405
6406
6407 \series default 
6408  disable interrupts during ESP:SP updates.
6409 \layout List
6410 \labelwidthstring 00.00.0000
6411
6412
6413 \series bold 
6414 -
6415 \begin_inset ERT
6416 status Collapsed
6417
6418 \layout Standard
6419
6420 \backslash 
6421 /
6422 \end_inset 
6423
6424 -stack-10bit
6425 \series default 
6426
6427 \begin_inset LatexCommand \index{-\/-stack-10bit}
6428
6429 \end_inset 
6430
6431  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
6432  This is the one and only that the ds390 code generator supports right now
6433  and is default when using 
6434 \emph on 
6435 -mds390
6436 \emph default 
6437 .
6438  In this mode, the stack is located in the lower 1K of the internal RAM,
6439  which is mapped to 0x400000.
6440  Note that the support is incomplete, since it still uses a single byte
6441  as the stack pointer.
6442  This means that only the lower 256 bytes of the potential 1K stack space
6443  will actually be used.
6444  However, this does allow you to reclaim the precious 256 bytes of low RAM
6445  for use for the DATA and IDATA segments.
6446  The compiler will not generate any code to put the processor into 10 bit
6447  stack mode.
6448  It is important to ensure that the processor is in this mode before calling
6449  any re-entrant functions compiled with this option.
6450  In principle, this should work with the 
6451 \emph on 
6452 -
6453 \begin_inset ERT
6454 status Collapsed
6455
6456 \layout Standard
6457
6458 \backslash 
6459 /
6460 \end_inset 
6461
6462 -stack-auto
6463 \begin_inset LatexCommand \index{-\/-stack-auto}
6464
6465 \end_inset 
6466
6467
6468 \emph default 
6469  option, but that has not been tested.
6470  It is incompatible with the 
6471 \emph on 
6472 -
6473 \begin_inset ERT
6474 status Collapsed
6475
6476 \layout Standard
6477
6478 \backslash 
6479 /
6480 \end_inset 
6481
6482 -xstack
6483 \begin_inset LatexCommand \index{-\/-xstack}
6484
6485 \end_inset 
6486
6487
6488 \emph default 
6489  option.
6490  It also only makes sense if the processor is in 24 bit contiguous addressing
6491  mode (see the 
6492 \emph on 
6493 -
6494 \begin_inset ERT
6495 status Collapsed
6496
6497 \layout Standard
6498
6499 \backslash 
6500 /
6501 \end_inset 
6502
6503 -model-flat24 option
6504 \emph default 
6505 ).
6506 \layout List
6507 \labelwidthstring 00.00.0000
6508
6509
6510 \series bold 
6511 -
6512 \begin_inset ERT
6513 status Collapsed
6514
6515 \layout Standard
6516
6517 \backslash 
6518 /
6519 \end_inset 
6520
6521 -stack-probe
6522 \begin_inset LatexCommand \index{-\/-stack-probe}
6523
6524 \end_inset 
6525
6526
6527 \series default 
6528  insert call to function __stack_probe at each function prologue.
6529 \layout List
6530 \labelwidthstring 00.00.0000
6531
6532
6533 \series bold 
6534 -
6535 \begin_inset ERT
6536 status Collapsed
6537
6538 \layout Standard
6539
6540 \backslash 
6541 /
6542 \end_inset 
6543
6544 -tini-libid
6545 \begin_inset LatexCommand \index{-\/-tini-libid}
6546
6547 \end_inset 
6548
6549
6550 \series default 
6551  <nnnn> LibraryID used in -mTININative.
6552  
6553 \layout List
6554 \labelwidthstring 00.00.0000
6555
6556
6557 \series bold 
6558 -
6559 \begin_inset ERT
6560 status Collapsed
6561
6562 \layout Standard
6563
6564 \backslash 
6565 /
6566 \end_inset 
6567
6568 -use-accelerator
6569 \begin_inset LatexCommand \index{-\/-use-accelerator}
6570
6571 \end_inset 
6572
6573
6574 \series default 
6575  generate code for DS390 Arithmetic Accelerator.
6576  
6577 \layout Subsection
6578
6579 Z80 Options
6580 \begin_inset LatexCommand \index{Options Z80}
6581
6582 \end_inset 
6583
6584
6585 \begin_inset LatexCommand \index{Z80 options}
6586
6587 \end_inset 
6588
6589
6590 \layout List
6591 \labelwidthstring 00.00.0000
6592
6593
6594 \series bold 
6595 -
6596 \begin_inset ERT
6597 status Collapsed
6598
6599 \layout Standard
6600
6601 \backslash 
6602 /
6603 \end_inset 
6604
6605 -callee-saves-bc
6606 \series default 
6607
6608 \begin_inset LatexCommand \index{-\/-callee-saves-bc}
6609
6610 \end_inset 
6611
6612
6613 \size large 
6614 \emph on 
6615  
6616 \size default 
6617 \emph default 
6618 Force a called function to always save BC.
6619 \layout List
6620 \labelwidthstring 00.00.0000
6621
6622
6623 \series bold 
6624 -
6625 \begin_inset ERT
6626 status Collapsed
6627
6628 \layout Standard
6629
6630 \backslash 
6631 /
6632 \end_inset 
6633
6634 -no-std-crt0
6635 \series default 
6636
6637 \begin_inset LatexCommand \index{-\/-no-std-crt0}
6638
6639 \end_inset 
6640
6641  When linking, skip the standard crt0.o object file.
6642  You must provide your own crt0.o for your system when linking.
6643  
6644 \layout Subsection
6645
6646 Optimization Options
6647 \begin_inset LatexCommand \index{Options optimization}
6648
6649 \end_inset 
6650
6651
6652 \begin_inset LatexCommand \index{Optimization options}
6653
6654 \end_inset 
6655
6656
6657 \layout List
6658 \labelwidthstring 00.00.0000
6659
6660
6661 \series bold 
6662 -
6663 \begin_inset ERT
6664 status Collapsed
6665
6666 \layout Standard
6667
6668 \backslash 
6669 /
6670 \end_inset 
6671
6672 -nogcse
6673 \begin_inset LatexCommand \index{-\/-nogcse}
6674
6675 \end_inset 
6676
6677
6678 \series default 
6679  Will not do global subexpression elimination, this option may be used when
6680  the compiler creates undesirably large stack/data spaces to store compiler
6681  temporaries (
6682 \emph on 
6683 s
6684 \emph default 
6685 pill 
6686 \emph on 
6687 loc
6688 \emph default 
6689 ations, sloc
6690 \begin_inset LatexCommand \index{sloc (spill location)}
6691
6692 \end_inset 
6693
6694 ).
6695  A warning message will be generated when this happens and the compiler
6696  will indicate the number of extra bytes it allocated.
6697  It is recommended that this option NOT be used, #pragma\SpecialChar ~
6698 nogcse
6699 \begin_inset LatexCommand \index{\#pragma nogcse}
6700
6701 \end_inset 
6702
6703  can be used to turn off global subexpression elimination
6704 \begin_inset LatexCommand \index{Subexpression elimination}
6705
6706 \end_inset 
6707
6708  for a given function only.
6709 \layout List
6710 \labelwidthstring 00.00.0000
6711
6712
6713 \series bold 
6714 -
6715 \begin_inset ERT
6716 status Collapsed
6717
6718 \layout Standard
6719
6720 \backslash 
6721 /
6722 \end_inset 
6723
6724 -noinvariant
6725 \begin_inset LatexCommand \index{-\/-noinvariant}
6726
6727 \end_inset 
6728
6729
6730 \series default 
6731  Will not do loop invariant optimizations, this may be turned off for reasons
6732  explained for the previous option.
6733  For more details of loop optimizations performed see Loop Invariants in
6734  section 
6735 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
6736
6737 \end_inset 
6738
6739 .
6740  It is recommended that this option NOT be used, #pragma\SpecialChar ~
6741 noinvariant
6742 \begin_inset LatexCommand \index{\#pragma noinvariant}
6743
6744 \end_inset 
6745
6746  can be used to turn off invariant optimizations for a given function only.
6747 \layout List
6748 \labelwidthstring 00.00.0000
6749
6750
6751 \series bold 
6752 -
6753 \begin_inset ERT
6754 status Collapsed
6755
6756 \layout Standard
6757
6758 \backslash 
6759 /
6760 \end_inset 
6761
6762 -noinduction
6763 \begin_inset LatexCommand \index{-\/-noinduction}
6764
6765 \end_inset 
6766
6767
6768 \series default 
6769  Will not do loop induction optimizations, see section strength reduction
6770  for more details.
6771  It is recommended that this option is NOT used, #pragma\SpecialChar ~
6772 noinduction
6773 \begin_inset LatexCommand \index{\#pragma noinduction}
6774
6775 \end_inset 
6776
6777  can be used to turn off induction optimizations for a given function only.
6778 \layout List
6779 \labelwidthstring 00.00.0000
6780
6781
6782 \series bold 
6783 -
6784 \begin_inset ERT
6785 status Collapsed
6786
6787 \layout Standard
6788
6789 \backslash 
6790 /
6791 \end_inset 
6792
6793 -nojtbound
6794 \begin_inset LatexCommand \index{-\/-nojtbound}
6795
6796 \end_inset 
6797
6798
6799 \size large 
6800 \bar under 
6801  
6802 \series default 
6803 \size default 
6804 \bar default 
6805  Will not generate boundary condition check when switch statements
6806 \begin_inset LatexCommand \index{switch statement}
6807
6808 \end_inset 
6809
6810  are implemented using jump-tables.
6811  See section 
6812 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
6813
6814 \end_inset 
6815
6816 \SpecialChar ~
6817 Switch Statements for more details.
6818  It is recommended that this option is NOT used, #pragma\SpecialChar ~
6819 nojtbound
6820 \begin_inset LatexCommand \index{\#pragma nojtbound}
6821
6822 \end_inset 
6823
6824  can be used to turn off boundary checking for jump tables for a given function
6825  only.
6826 \layout List
6827 \labelwidthstring 00.00.0000
6828
6829
6830 \series bold 
6831 -
6832 \begin_inset ERT
6833 status Collapsed
6834
6835 \layout Standard
6836
6837 \backslash 
6838 /
6839 \end_inset 
6840
6841 -noloopreverse
6842 \begin_inset LatexCommand \index{-\/-noloopreverse}
6843
6844 \end_inset 
6845
6846
6847 \series default 
6848 \size large 
6849  
6850 \size default 
6851 Will not do loop reversal 
6852 \begin_inset LatexCommand \index{Loop reversing}
6853
6854 \end_inset 
6855
6856 optimization.
6857 \layout List
6858 \labelwidthstring 00.00.0000
6859
6860 -
6861 \begin_inset ERT
6862 status Collapsed
6863
6864 \layout Standard
6865
6866 \backslash 
6867 /
6868 \end_inset 
6869
6870 -
6871 \series bold 
6872 nolabelopt
6873 \series default 
6874  
6875 \begin_inset LatexCommand \index{-\/-nolabelopt }
6876
6877 \end_inset 
6878
6879 Will not optimize labels (makes the dumpfiles more readable).
6880 \layout List
6881 \labelwidthstring 00.00.0000
6882
6883
6884 \series bold 
6885 -
6886 \begin_inset ERT
6887 status Collapsed
6888
6889 \layout Standard
6890
6891 \backslash 
6892 /
6893 \end_inset 
6894
6895 -no-xinit-opt
6896 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
6897
6898 \end_inset 
6899
6900
6901 \series default 
6902  Will not memcpy initialized data from code space into xdata space.
6903  This saves a few bytes in code space if you don't have initialized data
6904 \begin_inset LatexCommand \index{Variable initialization}
6905
6906 \end_inset 
6907
6908 .
6909 \layout List
6910 \labelwidthstring 00.00.0000
6911
6912
6913 \series bold 
6914 -
6915 \begin_inset ERT
6916 status Collapsed
6917
6918 \layout Standard
6919
6920 \backslash 
6921 /
6922 \end_inset 
6923
6924 -nooverlay
6925 \begin_inset LatexCommand \index{-\/-nooverlay}
6926
6927 \end_inset 
6928
6929
6930 \series default 
6931   The compiler will not overlay parameters and local variables of any function,
6932  see section Parameters and local variables for more details.
6933 \layout List
6934 \labelwidthstring 00.00.0000
6935
6936
6937 \series bold 
6938 -
6939 \begin_inset ERT
6940 status Collapsed
6941
6942 \layout Standard
6943
6944 \backslash 
6945 /
6946 \end_inset 
6947
6948 -no-peep
6949 \begin_inset LatexCommand \index{-\/-no-peep}
6950
6951 \end_inset 
6952
6953
6954 \series default 
6955  Disable peep-hole optimization.
6956 \layout List
6957 \labelwidthstring 00.00.0000
6958
6959
6960 \series bold 
6961 -
6962 \begin_inset ERT
6963 status Collapsed
6964
6965 \layout Standard
6966
6967 \backslash 
6968 /
6969 \end_inset 
6970
6971 -peep-file
6972 \series default 
6973
6974 \begin_inset LatexCommand \index{-\/-peep-file}
6975
6976 \end_inset 
6977
6978 \SpecialChar ~
6979 <filename> This option can be used to use additional rules to be used by
6980  the peep hole optimizer.
6981  See section 
6982 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
6983
6984 \end_inset 
6985
6986 \SpecialChar ~
6987 Peep Hole optimizations for details on how to write these rules.
6988 \layout List
6989 \labelwidthstring 00.00.0000
6990
6991
6992 \series bold 
6993 -
6994 \begin_inset ERT
6995 status Collapsed
6996
6997 \layout Standard
6998
6999 \backslash 
7000 /
7001 \end_inset 
7002
7003 -peep-asm
7004 \begin_inset LatexCommand \index{-\/-peep-asm}
7005
7006 \end_inset 
7007
7008
7009 \series default 
7010  Pass the inline assembler code through the peep hole optimizer.
7011  This can cause unexpected changes to inline assembler code, please go through
7012  the peephole optimizer
7013 \begin_inset LatexCommand \index{Peephole optimizer}
7014
7015 \end_inset 
7016
7017  rules defined in the source file tree '<target>/peeph.def' before using
7018  this option.
7019 \layout List
7020 \labelwidthstring 00.00.0000
7021
7022
7023 \series bold 
7024 -
7025 \begin_inset ERT
7026 status Collapsed
7027
7028 \layout Standard
7029
7030 \backslash 
7031 /
7032 \end_inset 
7033
7034 -opt-code-speed
7035 \begin_inset LatexCommand \index{-\/-opt-code-speed}
7036
7037 \end_inset 
7038
7039
7040 \series default 
7041  The compiler will optimize code generation towards fast code, possibly
7042  at the expense of code size.
7043 \layout List
7044 \labelwidthstring 00.00.0000
7045
7046
7047 \series bold 
7048 -
7049 \begin_inset ERT
7050 status Collapsed
7051
7052 \layout Standard
7053
7054 \backslash 
7055 /
7056 \end_inset 
7057
7058 -opt-code-size
7059 \begin_inset LatexCommand \index{-\/-opt-code-size}
7060
7061 \end_inset 
7062
7063
7064 \series default 
7065  The compiler will optimize code generation towards compact code, possibly
7066  at the expense of code speed.
7067 \layout Subsection
7068
7069 Other Options
7070 \begin_inset LatexCommand \index{Options other}
7071
7072 \end_inset 
7073
7074
7075 \layout List
7076 \labelwidthstring 00.00.0000
7077
7078
7079 \series bold 
7080 -c\SpecialChar ~
7081 -
7082 \begin_inset ERT
7083 status Collapsed
7084
7085 \layout Standard
7086
7087 \backslash 
7088 /
7089 \end_inset 
7090
7091 -compile-only
7092 \begin_inset LatexCommand \index{-\/-compile-only}
7093
7094 \end_inset 
7095
7096
7097 \begin_inset LatexCommand \index{-c -\/-compile-only}
7098
7099 \end_inset 
7100
7101
7102 \series default 
7103  will compile and assemble the source, but will not call the linkage editor.
7104 \layout List
7105 \labelwidthstring 00.00.0000
7106
7107
7108 \series bold 
7109 -
7110 \series default 
7111
7112 \begin_inset ERT
7113 status Collapsed
7114
7115 \layout Standard
7116
7117 \backslash 
7118 /
7119 \end_inset 
7120
7121
7122 \series bold 
7123 -c1mode
7124 \begin_inset LatexCommand \index{-\/-c1mode}
7125
7126 \end_inset 
7127
7128
7129 \series default 
7130  reads the preprocessed source from standard input and compiles it.
7131  The file name for the assembler output must be specified using the -o option.
7132 \layout List
7133 \labelwidthstring 00.00.0000
7134
7135
7136 \series bold 
7137 -E
7138 \begin_inset LatexCommand \index{-E}
7139
7140 \end_inset 
7141
7142
7143 \series default 
7144  Run only the C preprocessor.
7145  Preprocess all the C source files specified and output the results to standard
7146  output.
7147 \layout List
7148 \labelwidthstring 00.00.0000
7149
7150
7151 \series bold 
7152 -o\SpecialChar ~
7153 <path/file>
7154 \begin_inset LatexCommand \index{-o <path/file>}
7155
7156 \end_inset 
7157
7158  
7159 \series default 
7160 The output path resp.
7161  file where everything will be placed.
7162  If the parameter is a path, it must have a trailing slash (or backslash
7163  for the Windows binaries) to be recognized as a path.
7164  
7165 \layout List
7166 \labelwidthstring 00.00.0000
7167
7168
7169 \series bold 
7170 -
7171 \begin_inset ERT
7172 status Collapsed
7173
7174 \layout Standard
7175
7176 \backslash 
7177 /
7178 \end_inset 
7179
7180 -stack-auto
7181 \begin_inset LatexCommand \index{-\/-stack-auto}
7182
7183 \end_inset 
7184
7185
7186 \series default 
7187 \size large 
7188 \emph on 
7189  
7190 \size default 
7191 \emph default 
7192 All functions in the source file will be compiled as 
7193 \emph on 
7194 reentrant
7195 \emph default 
7196
7197 \begin_inset LatexCommand \index{reentrant}
7198
7199 \end_inset 
7200
7201 , i.e.
7202  the parameters and local variables will be allocated on the stack
7203 \begin_inset LatexCommand \index{stack}
7204
7205 \end_inset 
7206
7207 .
7208  See section 
7209 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
7210
7211 \end_inset 
7212
7213  Parameters and Local Variables for more details.
7214  If this option is used all source files in the project should be compiled
7215  with this option.
7216  It automatically implies --int-long-reent and --float-reent.
7217  
7218 \layout List
7219 \labelwidthstring 00.00.0000
7220
7221
7222 \series bold 
7223 -
7224 \begin_inset ERT
7225 status Collapsed
7226
7227 \layout Standard
7228
7229 \backslash 
7230 /
7231 \end_inset 
7232
7233 -callee-saves
7234 \begin_inset LatexCommand \index{-\/-callee-saves}
7235
7236 \end_inset 
7237
7238  function1[,function2][,function3]....
7239
7240 \series default 
7241  The compiler by default uses a caller saves convention for register saving
7242  across function calls, however this can cause unnecessary register pushing
7243  & popping when calling small functions from larger functions.
7244  This option can be used to switch the register saving convention for the
7245  function names specified.
7246  The compiler will not save registers when calling these functions, no extra
7247  code will be generated at the entry & exit (function prologue
7248 \series bold 
7249
7250 \begin_inset LatexCommand \index{function prologue}
7251
7252 \end_inset 
7253
7254
7255 \series default 
7256  & epilogue
7257 \series bold 
7258
7259 \begin_inset LatexCommand \index{function epilogue}
7260
7261 \end_inset 
7262
7263
7264 \series default 
7265 ) for these functions to save & restore the registers used by these functions,
7266  this can SUBSTANTIALLY reduce code & improve run time performance of the
7267  generated code.
7268  In the future the compiler (with inter procedural analysis) will be able
7269  to determine the appropriate scheme to use for each function call.
7270  DO NOT use this option for built-in functions such as _mulint..., if this
7271  option is used for a library function the appropriate library function
7272  needs to be recompiled with the same option.
7273  If the project consists of multiple source files then all the source file
7274  should be compiled with the same -
7275 \begin_inset ERT
7276 status Collapsed
7277
7278 \layout Standard
7279
7280 \backslash 
7281 /
7282 \end_inset 
7283
7284 -callee-saves option string.
7285  Also see #pragma\SpecialChar ~
7286 callee_saves
7287 \begin_inset LatexCommand \index{\#pragma callee\_saves}
7288
7289 \end_inset 
7290
7291 .
7292 \layout List
7293 \labelwidthstring 00.00.0000
7294
7295
7296 \series bold 
7297 -
7298 \begin_inset ERT
7299 status Collapsed
7300
7301 \layout Standard
7302
7303 \backslash 
7304 /
7305 \end_inset 
7306
7307 -debug
7308 \begin_inset LatexCommand \index{-\/-debug}
7309
7310 \end_inset 
7311
7312
7313 \bar under 
7314  
7315 \series default 
7316 \bar default 
7317 When this option is used the compiler will generate debug information.
7318  The debug information collected in a file with .cdb extension can be used
7319  with the SDCDB.
7320  For more information see documentation for SDCDB.
7321  Another file with no extension contains debug information in AOMF or AOMF51
7322 \begin_inset LatexCommand \index{AOMF, AOMF51}
7323
7324 \end_inset 
7325
7326  format which is commonly used by third party tools.
7327 \layout List
7328 \labelwidthstring 00.00.0000
7329
7330
7331 \series bold 
7332 -S
7333 \begin_inset LatexCommand \index{-S}
7334
7335 \end_inset 
7336
7337
7338 \size large 
7339 \bar under 
7340  
7341 \series default 
7342 \size default 
7343 \bar default 
7344 Stop after the stage of compilation proper; do not assemble.
7345  The output is an assembler code file for the input file specified.
7346 \layout List
7347 \labelwidthstring 00.00.0000
7348
7349
7350 \series bold 
7351 -
7352 \begin_inset ERT
7353 status Collapsed
7354
7355 \layout Standard
7356
7357 \backslash 
7358 /
7359 \end_inset 
7360
7361 -int-long-reent
7362 \begin_inset LatexCommand \index{-\/-int-long-reent}
7363
7364 \end_inset 
7365
7366
7367 \series default 
7368  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
7369  Note by default these libraries are compiled as non-reentrant.
7370  See section Installation for more details.
7371 \layout List
7372 \labelwidthstring 00.00.0000
7373
7374
7375 \series bold 
7376 -
7377 \begin_inset ERT
7378 status Collapsed
7379
7380 \layout Standard
7381
7382 \backslash 
7383 /
7384 \end_inset 
7385
7386 -cyclomatic
7387 \begin_inset LatexCommand \index{-\/-cyclomatic}
7388
7389 \end_inset 
7390
7391
7392 \bar under 
7393  
7394 \series default 
7395 \bar default 
7396 This option will cause the compiler to generate an information message for
7397  each function in the source file.
7398  The message contains some 
7399 \emph on 
7400 important
7401 \emph default 
7402  information about the function.
7403  The number of edges and nodes the compiler detected in the control flow
7404  graph of the function, and most importantly the 
7405 \emph on 
7406 cyclomatic complexity
7407 \begin_inset LatexCommand \index{Cyclomatic complexity}
7408
7409 \end_inset 
7410
7411
7412 \emph default 
7413  see section on Cyclomatic Complexity for more details.
7414 \layout List
7415 \labelwidthstring 00.00.0000
7416
7417
7418 \series bold 
7419 -
7420 \begin_inset ERT
7421 status Collapsed
7422
7423 \layout Standard
7424
7425 \backslash 
7426 /
7427 \end_inset 
7428
7429 -float-reent
7430 \begin_inset LatexCommand \index{-\/-float-reent}
7431
7432 \end_inset 
7433
7434
7435 \series default 
7436  Floating point library is compiled as reentrant
7437 \begin_inset LatexCommand \index{reentrant}
7438
7439 \end_inset 
7440
7441 .
7442  See section Installation for more details.
7443 \layout List
7444 \labelwidthstring 00.00.0000
7445
7446
7447 \series bold 
7448 -
7449 \begin_inset ERT
7450 status Collapsed
7451
7452 \layout Standard
7453
7454 \backslash 
7455 /
7456 \end_inset 
7457
7458 -main-return
7459 \begin_inset LatexCommand \index{-\/-main-return}
7460
7461 \end_inset 
7462
7463
7464 \series default 
7465  This option can be used if the code generated is called by a monitor program
7466  or if the main routine includes an endless loop.
7467  This option might result in slightly smaller code and save two bytes of
7468  stack space.
7469  The return from the 'main'
7470 \begin_inset LatexCommand \index{main return}
7471
7472 \end_inset 
7473
7474  function will return to the function calling main.
7475  The default setting is to lock up i.e.
7476  generate a '
7477 \family typewriter 
7478 sjmp .
7479 \family default 
7480 '.
7481 \layout List
7482 \labelwidthstring 00.00.0000
7483
7484
7485 \series bold 
7486 -
7487 \begin_inset ERT
7488 status Collapsed
7489
7490 \layout Standard
7491
7492 \backslash 
7493 /
7494 \end_inset 
7495
7496 -nostdinc
7497 \begin_inset LatexCommand \index{-\/-nostdinc}
7498
7499 \end_inset 
7500
7501
7502 \series default 
7503  This will prevent the compiler from passing on the default include path
7504  to the preprocessor.
7505 \layout List
7506 \labelwidthstring 00.00.0000
7507
7508
7509 \series bold 
7510 -
7511 \begin_inset ERT
7512 status Collapsed
7513
7514 \layout Standard
7515
7516 \backslash 
7517 /
7518 \end_inset 
7519
7520 -nostdlib
7521 \begin_inset LatexCommand \index{-\/-nostdlib}
7522
7523 \end_inset 
7524
7525
7526 \series default 
7527  This will prevent the compiler from passing on the default library
7528 \begin_inset LatexCommand \index{Libraries}
7529
7530 \end_inset 
7531
7532  path to the linker.
7533 \layout List
7534 \labelwidthstring 00.00.0000
7535
7536
7537 \series bold 
7538 -
7539 \begin_inset ERT
7540 status Collapsed
7541
7542 \layout Standard
7543
7544 \backslash 
7545 /
7546 \end_inset 
7547
7548 -verbose
7549 \begin_inset LatexCommand \index{-\/-verbose}
7550
7551 \end_inset 
7552
7553
7554 \series default 
7555  Shows the various actions the compiler is performing.
7556 \layout List
7557 \labelwidthstring 00.00.0000
7558
7559
7560 \series bold 
7561 -V
7562 \begin_inset LatexCommand \index{-V}
7563
7564 \end_inset 
7565
7566
7567 \series default 
7568  Shows the actual commands the compiler is executing.
7569 \layout List
7570 \labelwidthstring 00.00.0000
7571
7572
7573 \series bold 
7574 -
7575 \begin_inset ERT
7576 status Collapsed
7577
7578 \layout Standard
7579
7580 \backslash 
7581 /
7582 \end_inset 
7583
7584 -no-c-code-in-asm
7585 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
7586
7587 \end_inset 
7588
7589
7590 \series default 
7591  Hides your ugly and inefficient c-code from the asm file, so you can always
7592  blame the compiler :)
7593 \layout List
7594 \labelwidthstring 00.00.0000
7595
7596
7597 \series bold 
7598 -
7599 \begin_inset ERT
7600 status Collapsed
7601
7602 \layout Standard
7603
7604 \backslash 
7605 /
7606 \end_inset 
7607
7608 -no-peep-comments
7609 \begin_inset LatexCommand \index{-\/-no-peep-comments}
7610
7611 \end_inset 
7612
7613
7614 \series default 
7615  Will not include peep-hole comments in the generated files.
7616 \layout List
7617 \labelwidthstring 00.00.0000
7618
7619
7620 \series bold 
7621 -
7622 \begin_inset ERT
7623 status Collapsed
7624
7625 \layout Standard
7626
7627 \backslash 
7628 /
7629 \end_inset 
7630
7631 -i-code-in-asm
7632 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
7633
7634 \end_inset 
7635
7636
7637 \series default 
7638  Include i-codes in the asm file.
7639  Sounds like noise but is most helpful for debugging the compiler itself.
7640 \layout List
7641 \labelwidthstring 00.00.0000
7642
7643
7644 \series bold 
7645 -
7646 \begin_inset ERT
7647 status Collapsed
7648
7649 \layout Standard
7650
7651 \backslash 
7652 /
7653 \end_inset 
7654
7655 -less-pedantic
7656 \begin_inset LatexCommand \index{-\/-less-pedantic}
7657
7658 \end_inset 
7659
7660
7661 \series default 
7662  Disable some of the more pedantic warnings
7663 \begin_inset LatexCommand \index{Warnings}
7664
7665 \end_inset 
7666
7667  (jwk burps: please be more specific here, please!).
7668 \layout List
7669 \labelwidthstring 00.00.0000
7670
7671
7672 \series bold 
7673 -
7674 \begin_inset ERT
7675 status Collapsed
7676
7677 \layout Standard
7678
7679 \backslash 
7680 /
7681 \end_inset 
7682
7683 -disable-warning\SpecialChar ~
7684 <nnnn>
7685 \begin_inset LatexCommand \index{-\/-disable-warning}
7686
7687 \end_inset 
7688
7689
7690 \series default 
7691  Disable specific warning with number <nnnn>.
7692 \layout List
7693 \labelwidthstring 00.00.0000
7694
7695
7696 \series bold 
7697 -
7698 \begin_inset ERT
7699 status Collapsed
7700
7701 \layout Standard
7702
7703 \backslash 
7704 /
7705 \end_inset 
7706
7707 -print-search-dirs
7708 \begin_inset LatexCommand \index{-\/-print-search-dirs}
7709
7710 \end_inset 
7711
7712
7713 \series default 
7714  Display the directories in the compiler's search path
7715 \layout List
7716 \labelwidthstring 00.00.0000
7717
7718
7719 \series bold 
7720 -
7721 \begin_inset ERT
7722 status Collapsed
7723
7724 \layout Standard
7725
7726 \backslash 
7727 /
7728 \end_inset 
7729
7730 -vc
7731 \begin_inset LatexCommand \index{-\/-vc}
7732
7733 \end_inset 
7734
7735
7736 \series default 
7737  Display errors and warnings using MSVC style, so you can use SDCC with
7738  visual studio.
7739 \layout List
7740 \labelwidthstring 00.00.0000
7741
7742
7743 \series bold 
7744 -
7745 \begin_inset ERT
7746 status Collapsed
7747
7748 \layout Standard
7749
7750 \backslash 
7751 /
7752 \end_inset 
7753
7754 -use-stdout
7755 \begin_inset LatexCommand \index{-\/-use-stdout}
7756
7757 \end_inset 
7758
7759
7760 \series default 
7761  Send errors and warnings to stdout instead of stderr.
7762 \layout List
7763 \labelwidthstring 00.00.0000
7764
7765
7766 \series bold 
7767 -Wa\SpecialChar ~
7768 asmOption[,asmOption]
7769 \series default 
7770
7771 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
7772
7773 \end_inset 
7774
7775 ...
7776  Pass the asmOption to the assembler
7777 \begin_inset LatexCommand \index{Options assembler}
7778
7779 \end_inset 
7780
7781
7782 \begin_inset LatexCommand \index{Assembler options}
7783
7784 \end_inset 
7785
7786 .
7787  See file sdcc/as/doc/asxhtm.html for assembler options.cd
7788 \layout List
7789 \labelwidthstring 00.00.0000
7790
7791
7792 \series bold 
7793 -
7794 \begin_inset ERT
7795 status Collapsed
7796
7797 \layout Standard
7798
7799 \backslash 
7800 /
7801 \end_inset 
7802
7803 -std-sdcc89
7804 \begin_inset LatexCommand \index{-\/-std-sdcc89}
7805
7806 \end_inset 
7807
7808
7809 \series default 
7810  Generally follow the C89 standard, but allow SDCC features that conflict
7811  with the standard (default).
7812 \layout List
7813 \labelwidthstring 00.00.0000
7814
7815
7816 \series bold 
7817 -
7818 \begin_inset ERT
7819 status Collapsed
7820
7821 \layout Standard
7822
7823 \backslash 
7824 /
7825 \end_inset 
7826
7827 -std-c89
7828 \begin_inset LatexCommand \index{-\/-std-c89}
7829
7830 \end_inset 
7831
7832
7833 \series default 
7834  Follow the C89 standard and disable SDCC features that conflict with the
7835  standard.
7836 \layout List
7837 \labelwidthstring 00.00.0000
7838
7839
7840 \series bold 
7841 -
7842 \begin_inset ERT
7843 status Collapsed
7844
7845 \layout Standard
7846
7847 \backslash 
7848 /
7849 \end_inset 
7850
7851 -std-sdcc99
7852 \begin_inset LatexCommand \index{-\/-std-sdcc99}
7853
7854 \end_inset 
7855
7856
7857 \series default 
7858  Generally follow the C99 standard, but allow SDCC features that conflict
7859  with the standard (incomplete support).
7860 \layout List
7861 \labelwidthstring 00.00.0000
7862
7863
7864 \series bold 
7865 -
7866 \begin_inset ERT
7867 status Collapsed
7868
7869 \layout Standard
7870
7871 \backslash 
7872 /
7873 \end_inset 
7874
7875 -std-c99
7876 \begin_inset LatexCommand \index{-\/-std-sdcc99}
7877
7878 \end_inset 
7879
7880
7881 \series default 
7882  Follow the C99 standard and disable SDCC features that conflict with the
7883  standard (incomplete support).
7884 \layout List
7885 \labelwidthstring 00.00.0000
7886
7887
7888 \series bold 
7889 -
7890 \begin_inset ERT
7891 status Collapsed
7892
7893 \layout Standard
7894
7895 \backslash 
7896 /
7897 \end_inset 
7898
7899 -codeseg
7900 \series default 
7901
7902 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
7903
7904 \end_inset 
7905
7906 \SpecialChar ~
7907 <Name> The name to be used for the code
7908 \begin_inset LatexCommand \index{code}
7909
7910 \end_inset 
7911
7912  segment, default CSEG.
7913  This is useful if you need to tell the compiler to put the code in a special
7914  segment so you can later on tell the linker to put this segment in a special
7915  place in memory.
7916  Can be used for instance when using bank switching to put the code in a
7917  bank.
7918 \layout List
7919 \labelwidthstring 00.00.0000
7920
7921
7922 \series bold 
7923 -
7924 \begin_inset ERT
7925 status Collapsed
7926
7927 \layout Standard
7928
7929 \backslash 
7930 /
7931 \end_inset 
7932
7933 -constseg
7934 \series default 
7935
7936 \begin_inset LatexCommand \index{-\/-constseg <Value>}
7937
7938 \end_inset 
7939
7940 \SpecialChar ~
7941 <Name> The name to be used for the const
7942 \begin_inset LatexCommand \index{code}
7943
7944 \end_inset 
7945
7946  segment, default CONST.
7947  This is useful if you need to tell the compiler to put the const data in
7948  a special segment so you can later on tell the linker to put this segment
7949  in a special place in memory.
7950  Can be used for instance when using bank switching to put the const data
7951  in a bank.
7952 \layout List
7953 \labelwidthstring 00.00.0000
7954
7955
7956 \series bold 
7957 more-pedantic
7958 \series default 
7959  Actually this is 
7960 \series bold 
7961 \emph on 
7962 not
7963 \series default 
7964 \emph default 
7965  a SDCC compiler option but if you want 
7966 \emph on 
7967 more
7968 \emph default 
7969  warnings you can use a separate tool dedicated to syntax checking like
7970  splint
7971 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
7972
7973 \end_inset 
7974
7975
7976 \begin_inset LatexCommand \index{lint (syntax checking tool)}
7977
7978 \end_inset 
7979
7980  
7981 \begin_inset LatexCommand \url{http://www.splint.org}
7982
7983 \end_inset 
7984
7985 .
7986  To make your source files parseable by splint you will have to include
7987  
7988 \family sans 
7989 lint.h
7990 \family default 
7991
7992 \begin_inset LatexCommand \index{splint (syntax checking tool)}
7993
7994 \end_inset 
7995
7996  in your source file and add brackets around extended keywords (like 
7997 \family sans 
7998
7999 \begin_inset Quotes sld
8000 \end_inset 
8001
8002 __at\SpecialChar ~
8003
8004 \series bold 
8005 (
8006 \series default 
8007 0xab
8008 \series bold 
8009 )
8010 \series default 
8011
8012 \begin_inset Quotes srd
8013 \end_inset 
8014
8015
8016 \family default 
8017  and 
8018 \family sans 
8019
8020 \begin_inset Quotes sld
8021 \end_inset 
8022
8023 __interrupt\SpecialChar ~
8024 (2)
8025 \begin_inset Quotes srd
8026 \end_inset 
8027
8028
8029 \family default 
8030 ).
8031  
8032 \newline 
8033 Splint has an excellent on line manual at 
8034 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
8035
8036 \end_inset 
8037
8038  and it's capabilities go beyond pure syntax checking.
8039  You'll need to tell splint the location of SDCC's include files so a typical
8040  command line could look like this: 
8041 \newline 
8042
8043 \family sans 
8044 splint\SpecialChar ~
8045 -I\SpecialChar ~
8046 /usr/local/share/sdcc/include/mcs51/\SpecialChar ~
8047 \SpecialChar ~
8048 myprogram.c
8049 \layout Subsection
8050
8051 Intermediate Dump Options
8052 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
8053
8054 \end_inset 
8055
8056
8057 \begin_inset LatexCommand \index{Options intermediate dump}
8058
8059 \end_inset 
8060
8061
8062 \begin_inset LatexCommand \index{Intermediate dump options}
8063
8064 \end_inset 
8065
8066
8067 \layout Standard
8068
8069 The following options are provided for the purpose of retargetting and debugging
8070  the compiler.
8071  They provide a means to dump the intermediate code (iCode
8072 \begin_inset LatexCommand \index{iCode}
8073
8074 \end_inset 
8075
8076 ) generated by the compiler in human readable form at various stages of
8077  the compilation process.
8078  More on iCodes see chapter 
8079 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
8080
8081 \end_inset 
8082
8083  
8084 \begin_inset Quotes srd
8085 \end_inset 
8086
8087 The anatomy of the compiler
8088 \begin_inset Quotes srd
8089 \end_inset 
8090
8091 .
8092 \layout List
8093 \labelwidthstring 00.00.0000
8094
8095
8096 \series bold 
8097 -
8098 \begin_inset ERT
8099 status Collapsed
8100
8101 \layout Standard
8102
8103 \backslash 
8104 /
8105 \end_inset 
8106
8107 -dumpraw
8108 \begin_inset LatexCommand \index{-\/-dumpraw}
8109
8110 \end_inset 
8111
8112
8113 \series default 
8114  This option will cause the compiler to dump the intermediate code into
8115  a file of named 
8116 \emph on 
8117 <source filename>.dumpraw
8118 \emph default 
8119  just after the intermediate code has been generated for a function, i.e.
8120  before any optimizations are done.
8121  The basic blocks
8122 \begin_inset LatexCommand \index{Basic blocks}
8123
8124 \end_inset 
8125
8126  at this stage ordered in the depth first number, so they may not be in
8127  sequence of execution.
8128 \layout List
8129 \labelwidthstring 00.00.0000
8130
8131
8132 \series bold 
8133 -
8134 \begin_inset ERT
8135 status Collapsed
8136
8137 \layout Standard
8138
8139 \backslash 
8140 /
8141 \end_inset 
8142
8143 -dumpgcse
8144 \begin_inset LatexCommand \index{-\/-dumpgcse}
8145
8146 \end_inset 
8147
8148
8149 \series default 
8150  Will create a dump of iCode's, after global subexpression elimination
8151 \begin_inset LatexCommand \index{Global subexpression elimination}
8152
8153 \end_inset 
8154
8155 , into a file named 
8156 \emph on 
8157 <source filename>.dumpgcse.
8158 \layout List
8159 \labelwidthstring 00.00.0000
8160
8161
8162 \series bold 
8163 -
8164 \begin_inset ERT
8165 status Collapsed
8166
8167 \layout Standard
8168
8169 \backslash 
8170 /
8171 \end_inset 
8172
8173 -dumpdeadcode
8174 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
8175
8176 \end_inset 
8177
8178
8179 \series default 
8180  Will create a dump of iCode's, after deadcode elimination
8181 \begin_inset LatexCommand \index{Dead-code elimination}
8182
8183 \end_inset 
8184
8185 , into a file named 
8186 \emph on 
8187 <source filename>.dumpdeadcode.
8188 \layout List
8189 \labelwidthstring 00.00.0000
8190
8191
8192 \series bold 
8193 -
8194 \begin_inset ERT
8195 status Collapsed
8196
8197 \layout Standard
8198
8199 \backslash 
8200 /
8201 \end_inset 
8202
8203 -dumploop
8204 \begin_inset LatexCommand \index{-\/-dumploop}
8205
8206 \end_inset 
8207
8208
8209 \series default 
8210 \size large 
8211  
8212 \size default 
8213 Will create a dump of iCode's, after loop optimizations
8214 \begin_inset LatexCommand \index{Loop optimization}
8215
8216 \end_inset 
8217
8218 , into a file named 
8219 \emph on 
8220 <source filename>.dumploop.
8221 \layout List
8222 \labelwidthstring 00.00.0000
8223
8224
8225 \series bold 
8226 -
8227 \begin_inset ERT
8228 status Collapsed
8229
8230 \layout Standard
8231
8232 \backslash 
8233 /
8234 \end_inset 
8235
8236 -dumprange
8237 \begin_inset LatexCommand \index{-\/-dumprange}
8238
8239 \end_inset 
8240
8241
8242 \series default 
8243 \size large 
8244  
8245 \size default 
8246 Will create a dump of iCode's, after live range analysis
8247 \begin_inset LatexCommand \index{Live range analysis}
8248
8249 \end_inset 
8250
8251 , into a file named 
8252 \emph on 
8253 <source filename>.dumprange.
8254 \layout List
8255 \labelwidthstring 00.00.0000
8256
8257
8258 \series bold 
8259 -
8260 \begin_inset ERT
8261 status Collapsed
8262
8263 \layout Standard
8264
8265 \backslash 
8266 /
8267 \end_inset 
8268
8269 -dumlrange
8270 \begin_inset LatexCommand \index{-\/-dumlrange}
8271
8272 \end_inset 
8273
8274
8275 \series default 
8276  Will dump the life ranges
8277 \begin_inset LatexCommand \index{Live range analysis}
8278
8279 \end_inset 
8280
8281  for all symbols.
8282 \layout List
8283 \labelwidthstring 00.00.0000
8284
8285
8286 \series bold 
8287 -
8288 \begin_inset ERT
8289 status Collapsed
8290
8291 \layout Standard
8292
8293 \backslash 
8294 /
8295 \end_inset 
8296
8297 -dumpregassign
8298 \begin_inset LatexCommand \index{-\/-dumpregassign}
8299
8300 \end_inset 
8301
8302
8303 \bar under 
8304  
8305 \series default 
8306 \bar default 
8307 Will create a dump of iCode's, after register assignment
8308 \begin_inset LatexCommand \index{Register assignment}
8309
8310 \end_inset 
8311
8312 , into a file named 
8313 \emph on 
8314 <source filename>.dumprassgn.
8315 \layout List
8316 \labelwidthstring 00.00.0000
8317
8318
8319 \series bold 
8320 -
8321 \begin_inset ERT
8322 status Collapsed
8323
8324 \layout Standard
8325
8326 \backslash 
8327 /
8328 \end_inset 
8329
8330 -dumplrange
8331 \begin_inset LatexCommand \index{-\/-dumplrange}
8332
8333 \end_inset 
8334
8335
8336 \series default 
8337  Will create a dump of the live ranges of iTemp's
8338 \layout List
8339 \labelwidthstring 00.00.0000
8340
8341
8342 \series bold 
8343 -
8344 \begin_inset ERT
8345 status Collapsed
8346
8347 \layout Standard
8348
8349 \backslash 
8350 /
8351 \end_inset 
8352
8353 -dumpall
8354 \begin_inset LatexCommand \index{-\/-dumpall}
8355
8356 \end_inset 
8357
8358
8359 \size large 
8360 \bar under 
8361  
8362 \series default 
8363 \size default 
8364 \bar default 
8365 Will cause all the above mentioned dumps to be created.
8366 \layout Subsection
8367
8368 Redirecting output on Windows Shells
8369 \layout Standard
8370
8371 By default SDCC writes it's error messages to 
8372 \begin_inset Quotes sld
8373 \end_inset 
8374
8375 standard error
8376 \begin_inset Quotes srd
8377 \end_inset 
8378
8379 .
8380  To force all messages to 
8381 \begin_inset Quotes sld
8382 \end_inset 
8383
8384 standard output
8385 \begin_inset Quotes srd
8386 \end_inset 
8387
8388  use 
8389 \series bold 
8390 -
8391 \series default 
8392 \emph on 
8393
8394 \begin_inset ERT
8395 status Collapsed
8396
8397 \layout Standard
8398
8399 \backslash 
8400 /
8401 \end_inset 
8402
8403
8404 \series bold 
8405 \emph default 
8406 -
8407 \series default 
8408 use-stdout
8409 \begin_inset LatexCommand \index{-\/-use-stdout}
8410
8411 \end_inset 
8412
8413 .
8414  Additionally, if you happen to have visual studio installed in your windows
8415  machine, you can use it to compile your sources using a custom build and
8416  the SDCC -
8417 \emph on 
8418
8419 \begin_inset ERT
8420 status Collapsed
8421
8422 \layout Standard
8423
8424 \backslash 
8425 /
8426 \end_inset 
8427
8428
8429 \emph default 
8430 -vc
8431 \begin_inset LatexCommand \index{-\/-vc}
8432
8433 \end_inset 
8434
8435  option.
8436  Something like this should work:
8437 \newline 
8438
8439 \newline 
8440
8441 \series bold 
8442 c:
8443 \backslash 
8444 sdcc
8445 \backslash 
8446 bin
8447 \backslash 
8448 sdcc.exe -
8449 \series default 
8450 \emph on 
8451
8452 \begin_inset ERT
8453 status Collapsed
8454
8455 \layout Standard
8456
8457 \backslash 
8458 /
8459 \end_inset 
8460
8461
8462 \series bold 
8463 \emph default 
8464 -vc -
8465 \series default 
8466 \emph on 
8467
8468 \begin_inset ERT
8469 status Collapsed
8470
8471 \layout Standard
8472
8473 \backslash 
8474 /
8475 \end_inset 
8476
8477
8478 \series bold 
8479 \emph default 
8480 -model-large -c $(InputPath)
8481 \layout Section
8482
8483 Environment variables
8484 \begin_inset LatexCommand \index{Environment variables}
8485
8486 \end_inset 
8487
8488
8489 \layout Standard
8490
8491 SDCC recognizes the following environment variables:
8492 \layout List
8493 \labelwidthstring 00.00.0000
8494
8495
8496 \series bold 
8497 SDCC_LEAVE_SIGNALS
8498 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
8499
8500 \end_inset 
8501
8502
8503 \series default 
8504  SDCC installs a signal handler
8505 \begin_inset LatexCommand \index{signal handler}
8506
8507 \end_inset 
8508
8509  to be able to delete temporary files after an user break (^C) or an exception.
8510  If this environment variable is set, SDCC won't install the signal handler
8511  in order to be able to debug SDCC.
8512 \layout List
8513 \labelwidthstring 00.00.0000
8514
8515
8516 \series bold 
8517 TMP,\SpecialChar ~
8518 TEMP,\SpecialChar ~
8519 TMPDIR
8520 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
8521
8522 \end_inset 
8523
8524
8525 \series default 
8526  Path, where temporary files will be created.
8527  The order of the variables is the search order.
8528  In a standard *nix environment these variables are not set, and there's
8529  no need to set them.
8530  On Windows it's recommended to set one of them.
8531 \layout List
8532 \labelwidthstring 00.00.0000
8533
8534
8535 \series bold 
8536 SDCC_HOME
8537 \begin_inset LatexCommand \index{SDCC\_HOME}
8538
8539 \end_inset 
8540
8541
8542 \series default 
8543  Path, see section 
8544 \begin_inset LatexCommand \ref{sub:Install-paths}
8545
8546 \end_inset 
8547
8548 \SpecialChar ~
8549
8550 \begin_inset Quotes sld
8551 \end_inset 
8552
8553  Install Paths
8554 \begin_inset Quotes srd
8555 \end_inset 
8556
8557 .
8558 \layout List
8559 \labelwidthstring 00.00.0000
8560
8561
8562 \series bold 
8563 SDCC_INCLUDE
8564 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
8565
8566 \end_inset 
8567
8568
8569 \series default 
8570  Path, see section 
8571 \begin_inset LatexCommand \ref{sub:Search-Paths}
8572
8573 \end_inset 
8574
8575 \SpecialChar ~
8576
8577 \begin_inset Quotes sld
8578 \end_inset 
8579
8580 Search Paths
8581 \begin_inset Quotes srd
8582 \end_inset 
8583
8584 .
8585 \layout List
8586 \labelwidthstring 00.00.0000
8587
8588
8589 \series bold 
8590 SDCC_LIB
8591 \begin_inset LatexCommand \index{SDCC\_LIB}
8592
8593 \end_inset 
8594
8595
8596 \series default 
8597  Path, see section 
8598 \begin_inset LatexCommand \ref{sub:Search-Paths}
8599
8600 \end_inset 
8601
8602 \SpecialChar ~
8603
8604 \begin_inset Quotes sld
8605 \end_inset 
8606
8607 Search Paths
8608 \begin_inset Quotes srd
8609 \end_inset 
8610
8611 ..
8612 \layout Standard
8613
8614 There are some more environment variables recognized by SDCC, but these
8615  are solely used for debugging purposes.
8616  They can change or disappear very quickly, and will never be documented.
8617 \layout Section
8618
8619 Storage Class Language Extensions
8620 \layout Subsection
8621
8622 MCS51/DS390 Storage Class
8623 \begin_inset LatexCommand \index{Storage class}
8624
8625 \end_inset 
8626
8627  Language Extensions
8628 \layout Standard
8629
8630 In addition to the ANSI storage classes SDCC allows the following MCS51
8631  specific storage classes:
8632 \layout Subsubsection
8633
8634 data
8635 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
8636
8637 \end_inset 
8638
8639
8640 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
8641
8642 \end_inset 
8643
8644  / near
8645 \begin_inset LatexCommand \index{near (storage class)}
8646
8647 \end_inset 
8648
8649
8650 \begin_inset LatexCommand \index{\_\_near (storage class)}
8651
8652 \end_inset 
8653
8654
8655 \layout Standard
8656
8657 This is the 
8658 \series bold 
8659 default
8660 \series default 
8661  storage class for the Small Memory model (
8662 \emph on 
8663 data
8664 \emph default 
8665  and 
8666 \emph on 
8667 near
8668 \emph default 
8669  can be used synonymously).
8670  Variables declared with this storage class will be allocated in the directly
8671  addressable portion of the internal RAM of a 8051, e.g.:
8672 \layout Verse
8673
8674
8675 \family typewriter 
8676 data unsigned char test_data;
8677 \layout Standard
8678
8679 Writing 0x01 to this variable generates the assembly code:
8680 \layout Verse
8681
8682
8683 \family typewriter 
8684 75*00 01\SpecialChar ~
8685 \SpecialChar ~
8686 \SpecialChar ~
8687 mov\SpecialChar ~
8688 \SpecialChar ~
8689 _test_data,#0x01 
8690 \layout Subsubsection
8691
8692 xdata
8693 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
8694
8695 \end_inset 
8696
8697
8698 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
8699
8700 \end_inset 
8701
8702  / far
8703 \begin_inset LatexCommand \index{far (storage class)}
8704
8705 \end_inset 
8706
8707
8708 \begin_inset LatexCommand \index{\_\_far (storage class)}
8709
8710 \end_inset 
8711
8712
8713 \layout Standard
8714
8715 Variables declared with this storage class will be placed in the external
8716  RAM.
8717  This is the 
8718 \series bold 
8719 default
8720 \series default 
8721  storage class for the Large Memory model, e.g.:
8722 \layout Verse
8723
8724
8725 \family typewriter 
8726 xdata unsigned char test_xdata;
8727 \layout Standard
8728
8729 Writing 0x01 to this variable generates the assembly code:
8730 \layout Verse
8731
8732
8733 \family typewriter 
8734 90s00r00\SpecialChar ~
8735 \SpecialChar ~
8736 \SpecialChar ~
8737 mov\SpecialChar ~
8738 \SpecialChar ~
8739 dptr,#_test_xdata 
8740 \newline 
8741 74\SpecialChar ~
8742 01\SpecialChar ~
8743 \SpecialChar ~
8744 \SpecialChar ~
8745 \SpecialChar ~
8746 \SpecialChar ~
8747 \SpecialChar ~
8748 mov\SpecialChar ~
8749 \SpecialChar ~
8750 a,#0x01 
8751 \newline 
8752 F0\SpecialChar ~
8753 \SpecialChar ~
8754 \SpecialChar ~
8755 \SpecialChar ~
8756 \SpecialChar ~
8757 \SpecialChar ~
8758 \SpecialChar ~
8759 \SpecialChar ~
8760 \SpecialChar ~
8761 movx\SpecialChar ~
8762 @dptr,a 
8763 \layout Subsubsection
8764
8765 idata
8766 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
8767
8768 \end_inset 
8769
8770
8771 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
8772
8773 \end_inset 
8774
8775
8776 \layout Standard
8777
8778 Variables declared with this storage class will be allocated into the indirectly
8779  addressable portion of the internal ram of a 8051, e.g.:
8780 \layout Verse
8781
8782
8783 \family typewriter 
8784 idata unsigned char test_idata;
8785 \layout Standard
8786
8787 Writing 0x01 to this variable generates the assembly code:
8788 \layout Verse
8789
8790
8791 \family typewriter 
8792 78r00\SpecialChar ~
8793 \SpecialChar ~
8794 \SpecialChar ~
8795 \SpecialChar ~
8796 \SpecialChar ~
8797 \SpecialChar ~
8798 \SpecialChar ~
8799 mov\SpecialChar ~
8800 \SpecialChar ~
8801 r0,#_test_idata
8802 \newline 
8803 76\SpecialChar ~
8804 01\SpecialChar ~
8805 \SpecialChar ~
8806 \SpecialChar ~
8807 \SpecialChar ~
8808 \SpecialChar ~
8809 \SpecialChar ~
8810 \SpecialChar ~
8811 mov\SpecialChar ~
8812 \SpecialChar ~
8813 @r0,#0x01
8814 \layout Standard
8815
8816 Please note, the first 128 byte of idata physically access the same RAM
8817  as the data memory.
8818  The original 8051 had 128 byte idata memory, nowadays most devices have
8819  256 byte idata memory.
8820  The stack
8821 \begin_inset LatexCommand \index{stack}
8822
8823 \end_inset 
8824
8825  is located in idata memory.
8826 \layout Subsubsection
8827
8828 pdata
8829 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
8830
8831 \end_inset 
8832
8833
8834 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
8835
8836 \end_inset 
8837
8838
8839 \layout Standard
8840
8841 Paged xdata access is just as straightforward as using the other addressing
8842  modes of a 8051.
8843  It is typically located at the start of xdata and has a maximum size of
8844  256 bytes.
8845  The following example writes 0x01 to the pdata variable.
8846  Please note, pdata access physically accesses xdata memory.
8847  The high byte of the address is determined by port P2 
8848 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
8849
8850 \end_inset 
8851
8852 (or in case of some 8051 variants by a separate Special Function Register,
8853  see section 
8854 \begin_inset LatexCommand \ref{sub:MCS51-variants}
8855
8856 \end_inset 
8857
8858 ).
8859  This is the 
8860 \series bold 
8861 default
8862 \series default 
8863  storage class for the Medium Memory model, e.g.:
8864 \layout Verse
8865
8866
8867 \family typewriter 
8868 pdata unsigned char test_pdata;
8869 \layout Standard
8870
8871 Writing 0x01 to this variable generates the assembly code:
8872 \layout Verse
8873
8874
8875 \family typewriter 
8876 78r00\SpecialChar ~
8877 \SpecialChar ~
8878 \SpecialChar ~
8879 \SpecialChar ~
8880 \SpecialChar ~
8881 \SpecialChar ~
8882 mov r0,#_test_pdata
8883 \newline 
8884 74 01\SpecialChar ~
8885 \SpecialChar ~
8886 \SpecialChar ~
8887 \SpecialChar ~
8888 \SpecialChar ~
8889 \SpecialChar ~
8890 mov a,#0x01 
8891 \newline 
8892 F2\SpecialChar ~
8893 \SpecialChar ~
8894 \SpecialChar ~
8895 \SpecialChar ~
8896 \SpecialChar ~
8897 \SpecialChar ~
8898 \SpecialChar ~
8899 \SpecialChar ~
8900 \SpecialChar ~
8901 movx @r0,a
8902 \layout Standard
8903
8904 If the -
8905 \begin_inset ERT
8906 status Collapsed
8907
8908 \layout Standard
8909
8910 \backslash 
8911 /
8912 \end_inset 
8913
8914 -xstack
8915 \begin_inset LatexCommand \index{-\/-xstack}
8916
8917 \end_inset 
8918
8919  option is used the pdata memory area is followed by the xstack memory area
8920  and the sum of their sizes is limited to 256 bytes.
8921 \layout Subsubsection
8922
8923 code
8924 \begin_inset LatexCommand \index{code}
8925
8926 \end_inset 
8927
8928
8929 \begin_inset LatexCommand \index{\_\_code}
8930
8931 \end_inset 
8932
8933
8934 \layout Standard
8935
8936 'Variables' declared with this storage class will be placed in the code
8937  memory:
8938 \layout Verse
8939
8940
8941 \family typewriter 
8942 code unsigned char test_code;
8943 \layout Standard
8944
8945 Read access to this variable generates the assembly code:
8946 \layout Verse
8947
8948
8949 \family typewriter 
8950 90s00r6F\SpecialChar ~
8951 \SpecialChar ~
8952 \SpecialChar ~
8953 mov dptr,#_test_code
8954 \newline 
8955 E4\SpecialChar ~
8956 \SpecialChar ~
8957 \SpecialChar ~
8958 \SpecialChar ~
8959 \SpecialChar ~
8960 \SpecialChar ~
8961 \SpecialChar ~
8962 \SpecialChar ~
8963 \SpecialChar ~
8964 clr a
8965 \newline 
8966 93\SpecialChar ~
8967 \SpecialChar ~
8968 \SpecialChar ~
8969 \SpecialChar ~
8970 \SpecialChar ~
8971 \SpecialChar ~
8972 \SpecialChar ~
8973 \SpecialChar ~
8974 \SpecialChar ~
8975 movc a,@a+dptr 
8976 \layout Standard
8977
8978
8979 \family typewriter 
8980 char
8981 \family default 
8982  indexed arrays of characters in code memory can be accessed efficiently:
8983 \layout Verse
8984
8985
8986 \family typewriter 
8987 code char test_array[] = {'c','h','e','a','p'}; 
8988 \layout Standard
8989
8990 Read access to this array using an 8-bit unsigned index generates the assembly
8991  code:
8992 \layout Verse
8993
8994
8995 \family typewriter 
8996 E5*00\SpecialChar ~
8997 \SpecialChar ~
8998 \SpecialChar ~
8999 \SpecialChar ~
9000 \SpecialChar ~
9001 \SpecialChar ~
9002 mov a,_index 
9003 \layout Verse
9004
9005
9006 \family typewriter 
9007 90s00r41\SpecialChar ~
9008 \SpecialChar ~
9009 \SpecialChar ~
9010 mov dptr,#_test_array
9011 \layout Verse
9012
9013
9014 \family typewriter 
9015 93\SpecialChar ~
9016 \SpecialChar ~
9017 \SpecialChar ~
9018 \SpecialChar ~
9019 \SpecialChar ~
9020 \SpecialChar ~
9021 \SpecialChar ~
9022 \SpecialChar ~
9023 \SpecialChar ~
9024 movc a,@a+dptr 
9025 \layout Subsubsection
9026
9027 bit
9028 \begin_inset LatexCommand \index{bit}
9029
9030 \end_inset 
9031
9032
9033 \begin_inset LatexCommand \index{\_\_bit}
9034
9035 \end_inset 
9036
9037
9038 \layout Standard
9039
9040 This is a data-type and a storage class specifier.
9041  When a variable is declared as a bit, it is allocated into the bit addressable
9042  memory of 8051, e.g.:
9043 \layout Verse
9044
9045
9046 \family typewriter 
9047 bit test_bit;
9048 \layout Standard
9049
9050 Writing 1 to this variable generates the assembly code:
9051 \layout Verse
9052
9053
9054 \family typewriter 
9055 D2*00\SpecialChar ~
9056 \SpecialChar ~
9057 \SpecialChar ~
9058 \SpecialChar ~
9059 \SpecialChar ~
9060 \SpecialChar ~
9061 \SpecialChar ~
9062 setb\SpecialChar ~
9063 _test_bit
9064 \layout Standard
9065
9066 The bit addressable memory consists of 128 bits which are located from 0x20
9067  to 0x2f in data memory.
9068  
9069 \newline 
9070 Apart from this 8051 specific storage class most architectures support ANSI-C
9071  bitfields
9072 \begin_inset LatexCommand \index{bitfields}
9073
9074 \end_inset 
9075
9076
9077 \begin_inset Foot
9078 collapsed false
9079
9080 \layout Standard
9081
9082 Not really meant as examples, but nevertheless showing what bitfields are
9083  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
9084 \end_inset 
9085
9086 .
9087  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
9088  signed modifier are implemented as unsigned.
9089 \layout Subsubsection
9090
9091 sfr
9092 \begin_inset LatexCommand \index{sfr}
9093
9094 \end_inset 
9095
9096
9097 \begin_inset LatexCommand \index{\_\_sfr}
9098
9099 \end_inset 
9100
9101  / sfr16
9102 \begin_inset LatexCommand \index{sfr16}
9103
9104 \end_inset 
9105
9106
9107 \begin_inset LatexCommand \index{\_\_sfr16}
9108
9109 \end_inset 
9110
9111  / sfr32
9112 \begin_inset LatexCommand \index{sfr32}
9113
9114 \end_inset 
9115
9116
9117 \begin_inset LatexCommand \index{\_\_sfr32}
9118
9119 \end_inset 
9120
9121  / sbit
9122 \begin_inset LatexCommand \index{\_\_sbit}
9123
9124 \end_inset 
9125
9126
9127 \layout Standard
9128
9129 Like the bit keyword, 
9130 \emph on 
9131 sfr / sfr16 / sfr32 / sbit 
9132 \emph default 
9133 signify both a data-type and storage class, they are used to describe the
9134  
9135 \emph on 
9136 s
9137 \emph default 
9138 pecial 
9139 \emph on 
9140 f
9141 \emph default 
9142 unction 
9143 \emph on 
9144 r
9145 \emph default 
9146 egisters and 
9147 \emph on 
9148 s
9149 \emph default 
9150 pecial 
9151 \emph on 
9152 bit
9153 \emph default 
9154  variables of a 8051, eg:
9155 \layout Verse
9156
9157
9158 \family typewriter 
9159 sfr at
9160 \begin_inset LatexCommand \index{at}
9161
9162 \end_inset 
9163
9164
9165 \begin_inset LatexCommand \index{\_\_at}
9166
9167 \end_inset 
9168
9169  0x80 P0;\SpecialChar ~
9170  /* special function register P0 at location 0x80 */
9171 \newline 
9172 /* 16 bit special function register combination for timer 0 */
9173 \newline 
9174 /* with the high byte at location 0x8C and the low byte at location 0x8A
9175  */
9176 \newline 
9177 sfr16 at
9178 \begin_inset LatexCommand \index{at}
9179
9180 \end_inset 
9181
9182
9183 \begin_inset LatexCommand \index{\_\_at}
9184
9185 \end_inset 
9186
9187  0x8C8A TMR0;
9188 \newline 
9189 sbit at 0xd7 CY; /* CY (Carry Flag
9190 \begin_inset LatexCommand \index{Flags}
9191
9192 \end_inset 
9193
9194
9195 \begin_inset LatexCommand \index{Carry flag}
9196
9197 \end_inset 
9198
9199 ) */
9200 \layout Standard
9201
9202 Special function registers which are located on an address dividable by
9203  8 are bit-addressable, an
9204 \emph on 
9205  sbit
9206 \emph default 
9207  addresses a specific bit within these sfr.
9208 \newline 
9209 16 Bit and 32 bit special function register combinations which require a
9210  certain access order are better not declared using 
9211 \emph on 
9212 sfr16
9213 \emph default 
9214  or 
9215 \emph on 
9216 sfr32.
9217
9218 \emph default 
9219  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
9220  this is not guaranteed.
9221 \layout Subsubsection
9222
9223 Pointers
9224 \begin_inset LatexCommand \index{Pointer}
9225
9226 \end_inset 
9227
9228  to MCS51/DS390 specific memory spaces
9229 \layout Standard
9230
9231 SDCC allows (via language extensions) pointers to explicitly point to any
9232  of the memory spaces
9233 \begin_inset LatexCommand \index{Memory model}
9234
9235 \end_inset 
9236
9237  of the 8051.
9238  In addition to the explicit pointers, the compiler uses (by default) generic
9239  pointers which can be used to point to any of the memory spaces.
9240 \newline 
9241
9242 \newline 
9243 Pointer declaration examples:
9244 \layout Verse
9245
9246
9247 \family typewriter 
9248 /* pointer physically in internal ram pointing to object in external ram
9249  */ 
9250 \newline 
9251 xdata unsigned char * data p;
9252 \newline 
9253
9254 \newline 
9255 /* pointer physically in external ram pointing to object in internal ram
9256  */ 
9257 \newline 
9258 data unsigned char * xdata p;
9259 \newline 
9260
9261 \newline 
9262 /* pointer physically in code rom pointing to data in xdata space */ 
9263 \newline 
9264 xdata unsigned char * code p;
9265 \newline 
9266
9267 \newline 
9268 /* pointer physically in code space pointing to data in code space */ 
9269 \newline 
9270 code unsigned char * code p;
9271 \newline 
9272
9273 \newline 
9274 /* the following is a generic pointer physically located in xdata space
9275  */
9276 \newline 
9277 char * xdata p;
9278 \newline 
9279
9280 \newline 
9281 /* the following is a function pointer physically located in data space
9282  */
9283 \newline 
9284 char (* data fp)(void);
9285 \layout Standard
9286
9287 Well you get the idea.
9288  
9289 \newline 
9290
9291 \newline 
9292 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
9293 \emph on 
9294 generic
9295 \emph default 
9296  pointers.
9297  
9298 \size small 
9299
9300 \newline 
9301
9302 \newline 
9303
9304 \size default 
9305 The highest order byte of the 
9306 \emph on 
9307 generic
9308 \emph default 
9309  pointers contains the data space information.
9310  Assembler support routines are called whenever data is stored or retrieved
9311  using 
9312 \emph on 
9313 generic
9314 \emph default 
9315  pointers.
9316  These are useful for developing reusable library
9317 \begin_inset LatexCommand \index{Libraries}
9318
9319 \end_inset 
9320
9321  routines.
9322  Explicitly specifying the pointer type will generate the most efficient
9323  code.
9324 \layout Subsubsection
9325
9326 Notes on MCS51 memory
9327 \begin_inset LatexCommand \index{MCS51 memory}
9328
9329 \end_inset 
9330
9331  layout
9332 \layout Standard
9333
9334 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
9335  RAM memory which is structured as follows:
9336 \newline 
9337
9338 \newline 
9339 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
9340  
9341 \newline 
9342 - Bytes 20-2F - 16 bytes to hold 128 bit
9343 \begin_inset LatexCommand \index{bit}
9344
9345 \end_inset 
9346
9347  variables and, 
9348 \newline 
9349 - Bytes 30-7F - 80 bytes for general purpose use.
9350 \newline 
9351
9352 \layout Standard
9353
9354 Additionally some members of the MCS51 family may have up to 128 bytes of
9355  additional, indirectly addressable, internal RAM memory (
9356 \emph on 
9357 idata
9358 \emph default 
9359
9360 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
9361
9362 \end_inset 
9363
9364
9365 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
9366
9367 \end_inset 
9368
9369 ).
9370  Furthermore, some chips may have some built in external memory (
9371 \emph on 
9372 xdata
9373 \emph default 
9374
9375 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9376
9377 \end_inset 
9378
9379
9380 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
9381
9382 \end_inset 
9383
9384 ) which should not be confused with the internal, directly addressable RAM
9385  memory (
9386 \emph on 
9387 data
9388 \emph default 
9389
9390 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
9391
9392 \end_inset 
9393
9394
9395 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
9396
9397 \end_inset 
9398
9399 ).
9400  Sometimes this built in 
9401 \emph on 
9402 xdata
9403 \emph default 
9404  memory has to be activated before using it (you can probably find this
9405  information on the datasheet of the microcontroller your are using, see
9406  also section 
9407 \begin_inset LatexCommand \ref{sub:Startup-Code}
9408
9409 \end_inset 
9410
9411 \SpecialChar ~
9412 Startup-Code).
9413 \layout Standard
9414
9415 Normally SDCC will only use the first bank
9416 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
9417
9418 \end_inset 
9419
9420  of registers (register bank 0), but it is possible to specify that other
9421  banks of registers (keyword 
9422 \emph on 
9423 using
9424 \emph default 
9425  
9426 \emph on 
9427
9428 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
9429
9430 \end_inset 
9431
9432
9433 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
9434
9435 \end_inset 
9436
9437
9438 \emph default 
9439 ) should be used in interrupt
9440 \begin_inset LatexCommand \index{interrupt}
9441
9442 \end_inset 
9443
9444
9445 \begin_inset LatexCommand \index{\_\_interrupt}
9446
9447 \end_inset 
9448
9449  routines.
9450  By default, the compiler will place the stack after the last byte of allocated
9451  memory for variables.
9452  For example, if the first 2 banks of registers are used, and only four
9453  bytes are used for 
9454 \emph on 
9455 data
9456 \emph default 
9457  variables, it will position the base of the internal stack at address 20
9458  (0x14).
9459  This implies that as the stack
9460 \begin_inset LatexCommand \index{stack}
9461
9462 \end_inset 
9463
9464  grows, it will use up the remaining register banks, and the 16 bytes used
9465  by the 128 bit variables, and 80 bytes for general purpose use.
9466  If any bit variables are used, the data variables will be placed in unused
9467  register banks and after the byte holding the last bit variable.
9468  For example, if register banks 0 and 1 are used, and there are 9 bit variables
9469  (two bytes used), 
9470 \emph on 
9471 data
9472 \emph default 
9473  variables will be placed starting from address 0x10 to 0x20 and continue
9474  at address 0x22.
9475  You can also use -
9476 \begin_inset ERT
9477 status Collapsed
9478
9479 \layout Standard
9480
9481 \backslash 
9482 /
9483 \end_inset 
9484
9485 -data-loc
9486 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
9487
9488 \end_inset 
9489
9490  to specify the start address of the 
9491 \emph on 
9492 data
9493 \emph default 
9494  and -
9495 \begin_inset ERT
9496 status Collapsed
9497
9498 \layout Standard
9499
9500 \backslash 
9501 /
9502 \end_inset 
9503
9504 -iram-size
9505 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
9506
9507 \end_inset 
9508
9509  to specify the size of the total internal RAM (
9510 \emph on 
9511 data
9512 \emph default 
9513 +
9514 \emph on 
9515 idata
9516 \emph default 
9517 ).
9518  
9519 \layout Standard
9520
9521 By default the 8051 linker will place the stack after the last byte of (i)data
9522  variables.
9523  Option -
9524 \begin_inset ERT
9525 status Collapsed
9526
9527 \layout Standard
9528
9529 \backslash 
9530 /
9531 \end_inset 
9532
9533 -stack-loc
9534 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
9535
9536 \end_inset 
9537
9538  allows you to specify the start of the stack, i.e.
9539  you could start it after any data in the general purpose area.
9540  If your microcontroller has additional indirectly addressable internal
9541  RAM (
9542 \emph on 
9543 idata
9544 \emph default 
9545 ) you can place the stack on it.
9546  You may also need to use -
9547 \begin_inset ERT
9548 status Collapsed
9549
9550 \layout Standard
9551
9552 \backslash 
9553 /
9554 \end_inset 
9555
9556 -xdata-loc
9557 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
9558
9559 \end_inset 
9560
9561  to set the start address of the external RAM (
9562 \emph on 
9563 xdata
9564 \emph default 
9565 ) and -
9566 \begin_inset ERT
9567 status Collapsed
9568
9569 \layout Standard
9570
9571 \backslash 
9572 /
9573 \end_inset 
9574
9575 -xram-size
9576 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
9577
9578 \end_inset 
9579
9580  to specify its size.
9581  Same goes for the code memory, using -
9582 \begin_inset ERT
9583 status Collapsed
9584
9585 \layout Standard
9586
9587 \backslash 
9588 /
9589 \end_inset 
9590
9591 -code-loc
9592 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
9593
9594 \end_inset 
9595
9596  and -
9597 \begin_inset ERT
9598 status Collapsed
9599
9600 \layout Standard
9601
9602 \backslash 
9603 /
9604 \end_inset 
9605
9606 -code-size
9607 \begin_inset LatexCommand \index{-\/-code-size <Value>}
9608
9609 \end_inset 
9610
9611 .
9612  If in doubt, don't specify any options and see if the resulting memory
9613  layout is appropriate, then you can adjust it.
9614 \layout Standard
9615
9616 The linker generates two files with memory allocation information.
9617  The first, with extension .map
9618 \begin_inset LatexCommand \index{<file>.map}
9619
9620 \end_inset 
9621
9622  shows all the variables and segments.
9623  The second with extension .mem
9624 \begin_inset LatexCommand \index{<file>.mem}
9625
9626 \end_inset 
9627
9628  shows the final memory layout.
9629  The linker will complain either if memory segments overlap, there is not
9630  enough memory, or there is not enough space for stack.
9631  If you get any linking warnings and/or errors related to stack or segments
9632  allocation, take a look at either the .map or .mem files to find out what
9633  the problem is.
9634  The .mem file may even suggest a solution to the problem.
9635 \layout Subsection
9636
9637 Z80/Z180 Storage Class
9638 \begin_inset LatexCommand \index{Storage class}
9639
9640 \end_inset 
9641
9642  Language Extensions
9643 \layout Subsubsection
9644
9645 sfr
9646 \begin_inset LatexCommand \index{sfr}
9647
9648 \end_inset 
9649
9650
9651 \begin_inset LatexCommand \index{\_\_sfr}
9652
9653 \end_inset 
9654
9655  (in/out to 8-bit addresses)
9656 \layout Standard
9657
9658 The Z80
9659 \begin_inset LatexCommand \index{Z80}
9660
9661 \end_inset 
9662
9663  family has separate address spaces for memory and 
9664 \emph on 
9665 i
9666 \emph default 
9667 nput/
9668 \emph on 
9669 o
9670 \emph default 
9671 utput memory.
9672  I/O memory
9673 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
9674
9675 \end_inset 
9676
9677  is accessed with special instructions, e.g.:
9678 \layout Verse
9679
9680
9681 \family typewriter 
9682 sfr at 0x78 IoPort;\SpecialChar ~
9683 \SpecialChar ~
9684 /* define a var in I/O space at 78h called IoPort */
9685  
9686 \layout Standard
9687
9688 Writing 0x01 to this variable generates the assembly code:
9689 \layout Verse
9690
9691
9692 \family typewriter 
9693 3E 01\SpecialChar ~
9694 \SpecialChar ~
9695 \SpecialChar ~
9696 \SpecialChar ~
9697 \SpecialChar ~
9698 \SpecialChar ~
9699 ld a,#0x01
9700 \newline 
9701 D3 78\SpecialChar ~
9702 \SpecialChar ~
9703 \SpecialChar ~
9704 \SpecialChar ~
9705 \SpecialChar ~
9706 \SpecialChar ~
9707 out (_IoPort),a 
9708 \layout Subsubsection
9709
9710 banked sfr
9711 \begin_inset LatexCommand \index{sfr}
9712
9713 \end_inset 
9714
9715
9716 \begin_inset LatexCommand \index{\_\_sfr}
9717
9718 \end_inset 
9719
9720  (in/out to 16-bit addresses)
9721 \layout Standard
9722
9723 The keyword 
9724 \emph on 
9725 banked
9726 \emph default 
9727  is used to support 16 bit addresses in I/O memory e.g.:
9728 \layout Verse
9729
9730
9731 \family typewriter 
9732 sfr banked at
9733 \begin_inset LatexCommand \index{at}
9734
9735 \end_inset 
9736
9737
9738 \begin_inset LatexCommand \index{\_\_at}
9739
9740 \end_inset 
9741
9742  0x123 IoPort; 
9743 \layout Standard
9744
9745 Writing 0x01 to this variable generates the assembly code:
9746 \layout Verse
9747
9748
9749 \family typewriter 
9750 01 23 01\SpecialChar ~
9751 \SpecialChar ~
9752 \SpecialChar ~
9753 ld bc,#_IoPort
9754 \newline 
9755 3E 01\SpecialChar ~
9756 \SpecialChar ~
9757 \SpecialChar ~
9758 \SpecialChar ~
9759 \SpecialChar ~
9760 \SpecialChar ~
9761 ld a,#0x01 
9762 \newline 
9763 ED 79\SpecialChar ~
9764 \SpecialChar ~
9765 \SpecialChar ~
9766 \SpecialChar ~
9767 \SpecialChar ~
9768 \SpecialChar ~
9769 out (c),a 
9770 \layout Subsubsection
9771
9772 sfr
9773 \begin_inset LatexCommand \index{sfr}
9774
9775 \end_inset 
9776
9777
9778 \begin_inset LatexCommand \index{\_\_sfr}
9779
9780 \end_inset 
9781
9782  (in0/out0 to 8 bit addresses on Z180
9783 \begin_inset LatexCommand \index{Z180}
9784
9785 \end_inset 
9786
9787 /HD64180
9788 \begin_inset LatexCommand \index{HD64180}
9789
9790 \end_inset 
9791
9792 )
9793 \layout Standard
9794
9795 The compiler option -
9796 \begin_inset ERT
9797 status Collapsed
9798
9799 \layout Standard
9800
9801 \backslash 
9802 /
9803 \end_inset 
9804
9805 -portmode=180 (80) and a compiler #pragma\SpecialChar ~
9806 portmode
9807 \begin_inset LatexCommand \index{\#pragma portmode}
9808
9809 \end_inset 
9810
9811 =z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
9812 ns 
9813 \family typewriter 
9814 in0/out0
9815 \family default 
9816  instead of 
9817 \family typewriter 
9818 in/out
9819 \family default 
9820 .
9821  If you include the file z180.h this will be set automatically.
9822 \layout Subsection
9823
9824 HC08 Storage Class
9825 \begin_inset LatexCommand \index{Storage class}
9826
9827 \end_inset 
9828
9829  Language Extensions
9830 \layout Subsubsection
9831
9832 data
9833 \begin_inset LatexCommand \index{data (hc08 storage class)}
9834
9835 \end_inset 
9836
9837
9838 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
9839
9840 \end_inset 
9841
9842  
9843 \layout Standard
9844
9845 The data storage class declares a variable that resides in the first 256
9846  bytes of memory (the direct page).
9847  The HC08 is most efficient at accessing variables (especially pointers)
9848  stored here.
9849 \layout Subsubsection
9850
9851 xdata
9852 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
9853
9854 \end_inset 
9855
9856
9857 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
9858
9859 \end_inset 
9860
9861  
9862 \layout Standard
9863
9864 The xdata storage class declares a variable that can reside anywhere in
9865  memory.
9866  This is the default if no storage class is specified.
9867  
9868 \layout Section
9869
9870 Absolute Addressing
9871 \begin_inset LatexCommand \index{Absolute addressing}
9872
9873 \end_inset 
9874
9875
9876 \layout Standard
9877
9878 Data items can be assigned an absolute address with the 
9879 \emph on 
9880 at
9881 \begin_inset LatexCommand \index{at}
9882
9883 \end_inset 
9884
9885
9886 \begin_inset LatexCommand \index{\_\_at}
9887
9888 \end_inset 
9889
9890  <address>
9891 \emph default 
9892  keyword, in addition to a storage class, e.g.:
9893 \layout Verse
9894
9895
9896 \family typewriter 
9897 xdata
9898 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9899
9900 \end_inset 
9901
9902
9903 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
9904
9905 \end_inset 
9906
9907  at
9908 \begin_inset LatexCommand \index{at}
9909
9910 \end_inset 
9911
9912
9913 \begin_inset LatexCommand \index{\_\_at}
9914
9915 \end_inset 
9916
9917  0x7ffe unsigned int chksum;
9918 \layout Standard
9919
9920 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
9921  of the external ram.
9922  The compiler does 
9923 \emph on 
9924 not
9925 \emph default 
9926  reserve any space for variables declared in this way (they are implemented
9927  with an equate in the assembler).
9928  Thus it is left to the programmer to make sure there are no overlaps with
9929  other variables that are declared without the absolute address.
9930  The assembler listing file (.lst
9931 \begin_inset LatexCommand \index{<file>.lst}
9932
9933 \end_inset 
9934
9935 ) and the linker output files (.rst
9936 \begin_inset LatexCommand \index{<file>.rst}
9937
9938 \end_inset 
9939
9940 ) and (.map
9941 \begin_inset LatexCommand \index{<file>.map}
9942
9943 \end_inset 
9944
9945 ) are good places to look for such overlaps.
9946  Variables with an absolute address are 
9947 \emph on 
9948 not
9949 \emph default 
9950  initialized
9951 \begin_inset LatexCommand \index{Variable initialization}
9952
9953 \end_inset 
9954
9955 .
9956 \layout Standard
9957
9958 In case of memory mapped I/O devices the keyword 
9959 \emph on 
9960 volatile
9961 \emph default 
9962  has to be used to tell the compiler that accesses might not be removed:
9963 \layout Verse
9964
9965
9966 \family typewriter 
9967 volatile
9968 \begin_inset LatexCommand \index{volatile}
9969
9970 \end_inset 
9971
9972  xdata
9973 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9974
9975 \end_inset 
9976
9977  at
9978 \begin_inset LatexCommand \index{at}
9979
9980 \end_inset 
9981
9982  0x8000 unsigned char PORTA_8255;
9983 \layout Standard
9984
9985 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
9986 r) array
9987 \family typewriter 
9988 \size footnotesize 
9989
9990 \begin_inset LatexCommand \index{Aligned array}
9991
9992 \end_inset 
9993
9994
9995 \family default 
9996 \size default 
9997  starts at a block (256 byte) boundary
9998 \begin_inset LatexCommand \index{block boundary}
9999
10000 \end_inset 
10001
10002  (section 
10003 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
10004
10005 \end_inset 
10006
10007  has an example).
10008 \newline 
10009 Absolute addresses can be specified for variables in all storage classes,
10010  e.g.:
10011 \layout Verse
10012
10013
10014 \family typewriter 
10015 bit
10016 \begin_inset LatexCommand \index{bit}
10017
10018 \end_inset 
10019
10020  at
10021 \begin_inset LatexCommand \index{at}
10022
10023 \end_inset 
10024
10025  0x02 bvar;
10026 \layout Standard
10027
10028 The above example will allocate the variable at offset 0x02 in the bit-addressab
10029 le space.
10030  There is no real advantage to assigning absolute addresses to variables
10031  in this manner, unless you want strict control over all the variables allocated.
10032  One possible use would be to write hardware portable code.
10033  For example, if you have a routine that uses one or more of the microcontroller
10034  I/O pins, and such pins are different for two different hardwares, you
10035  can declare the I/O pins in your routine using:
10036 \layout Verse
10037
10038
10039 \family typewriter 
10040 extern volatile
10041 \begin_inset LatexCommand \index{volatile}
10042
10043 \end_inset 
10044
10045  bit MOSI;\SpecialChar ~
10046 \SpecialChar ~
10047 \SpecialChar ~
10048 \SpecialChar ~
10049 /* master out, slave in */
10050 \newline 
10051 extern volatile bit MISO;\SpecialChar ~
10052 \SpecialChar ~
10053 \SpecialChar ~
10054 \SpecialChar ~
10055 /* master in, slave out */
10056 \newline 
10057 extern volatile bit MCLK;\SpecialChar ~
10058 \SpecialChar ~
10059 \SpecialChar ~
10060 \SpecialChar ~
10061 /* master clock */
10062 \newline 
10063
10064 \newline 
10065 /* Input and Output of a byte on a 3-wire serial bus.
10066 \newline 
10067 \SpecialChar ~
10068 \SpecialChar ~
10069 \SpecialChar ~
10070 If needed adapt polarity of clock, polarity of data and bit order
10071 \newline 
10072 \SpecialChar ~
10073 */
10074 \newline 
10075 unsigned char spi_io(unsigned char out_byte) 
10076 \newline 
10077
10078 \newline 
10079 \SpecialChar ~
10080 \SpecialChar ~
10081 \SpecialChar ~
10082 \SpecialChar ~
10083 unsigned char i=8;
10084 \newline 
10085 \SpecialChar ~
10086 \SpecialChar ~
10087 \SpecialChar ~
10088 \SpecialChar ~
10089 do { 
10090 \newline 
10091 \SpecialChar ~
10092 \SpecialChar ~
10093 \SpecialChar ~
10094 \SpecialChar ~
10095 \SpecialChar ~
10096 \SpecialChar ~
10097 \SpecialChar ~
10098 \SpecialChar ~
10099 MOSI = out_byte & 0x80; 
10100 \newline 
10101 \SpecialChar ~
10102 \SpecialChar ~
10103 \SpecialChar ~
10104 \SpecialChar ~
10105 \SpecialChar ~
10106 \SpecialChar ~
10107 \SpecialChar ~
10108 \SpecialChar ~
10109 out_byte <<= 1;
10110 \newline 
10111 \SpecialChar ~
10112 \SpecialChar ~
10113 \SpecialChar ~
10114 \SpecialChar ~
10115 \SpecialChar ~
10116 \SpecialChar ~
10117 \SpecialChar ~
10118 \SpecialChar ~
10119 MCLK = 1; 
10120 \newline 
10121 \SpecialChar ~
10122 \SpecialChar ~
10123 \SpecialChar ~
10124 \SpecialChar ~
10125 \SpecialChar ~
10126 \SpecialChar ~
10127 \SpecialChar ~
10128 \SpecialChar ~
10129 /* _asm nop _endasm; */\SpecialChar ~
10130 \SpecialChar ~
10131 \SpecialChar ~
10132 \SpecialChar ~
10133 \SpecialChar ~
10134 \SpecialChar ~
10135 \SpecialChar ~
10136 \SpecialChar ~
10137 /* for slow peripherals */
10138 \newline 
10139 \SpecialChar ~
10140 \SpecialChar ~
10141 \SpecialChar ~
10142 \SpecialChar ~
10143 \SpecialChar ~
10144 \SpecialChar ~
10145 \SpecialChar ~
10146 \SpecialChar ~
10147 if(MISO) 
10148 \newline 
10149 \SpecialChar ~
10150 \SpecialChar ~
10151 \SpecialChar ~
10152 \SpecialChar ~
10153 \SpecialChar ~
10154 \SpecialChar ~
10155 \SpecialChar ~
10156 \SpecialChar ~
10157 \SpecialChar ~
10158 \SpecialChar ~
10159 \SpecialChar ~
10160 \SpecialChar ~
10161 out_byte += 1; 
10162 \newline 
10163 \SpecialChar ~
10164 \SpecialChar ~
10165 \SpecialChar ~
10166 \SpecialChar ~
10167 \SpecialChar ~
10168 \SpecialChar ~
10169 \SpecialChar ~
10170 \SpecialChar ~
10171 MCLK = 0; 
10172 \newline 
10173 \SpecialChar ~
10174 \SpecialChar ~
10175 \SpecialChar ~
10176 \SpecialChar ~
10177 } while(--i);
10178 \newline 
10179 \SpecialChar ~
10180 \SpecialChar ~
10181 \SpecialChar ~
10182 \SpecialChar ~
10183 return out_byte; 
10184 \newline 
10185 }
10186 \layout Standard
10187
10188 Then, someplace in the code for the first hardware you would use
10189 \layout Verse
10190
10191
10192 \family typewriter 
10193 bit at
10194 \begin_inset LatexCommand \index{at}
10195
10196 \end_inset 
10197
10198
10199 \begin_inset LatexCommand \index{\_\_at}
10200
10201 \end_inset 
10202
10203  0x80 MOSI;\SpecialChar ~
10204 \SpecialChar ~
10205 \SpecialChar ~
10206 \SpecialChar ~
10207 /* I/O port 0, bit 0 */
10208 \newline 
10209 bit at 0x81 MISO;\SpecialChar ~
10210 \SpecialChar ~
10211 \SpecialChar ~
10212 \SpecialChar ~
10213 /* I/O port 0, bit 1 */
10214 \newline 
10215 bit at 0x82 MCLK;\SpecialChar ~
10216 \SpecialChar ~
10217 \SpecialChar ~
10218 \SpecialChar ~
10219 /* I/O port 0, bit 2 */
10220 \layout Standard
10221
10222 Similarly, for the second hardware you would use
10223 \layout Verse
10224
10225
10226 \family typewriter 
10227 bit at 0x83 MOSI;\SpecialChar ~
10228 \SpecialChar ~
10229 \SpecialChar ~
10230 \SpecialChar ~
10231 /* I/O port 0, bit 3 */
10232 \newline 
10233 bit at 0x91 MISO;\SpecialChar ~
10234 \SpecialChar ~
10235 \SpecialChar ~
10236 \SpecialChar ~
10237 /* I/O port 1, bit 1 */
10238 \newline 
10239 bit
10240 \begin_inset LatexCommand \index{bit}
10241
10242 \end_inset 
10243
10244  at 0x92 MCLK;\SpecialChar ~
10245 \SpecialChar ~
10246 \SpecialChar ~
10247 \SpecialChar ~
10248 /* I/O port 1, bit 2 */
10249 \layout Standard
10250
10251 and you can use the same hardware dependent routine without changes, as
10252  for example in a library.
10253  This is somehow similar to sbit, but only one absolute address has to be
10254  specified in the whole project.
10255 \layout Section
10256
10257 Parameters
10258 \begin_inset LatexCommand \index{Parameters}
10259
10260 \end_inset 
10261
10262
10263 \begin_inset LatexCommand \index{function parameter}
10264
10265 \end_inset 
10266
10267  & Local Variables
10268 \begin_inset LatexCommand \index{local variables}
10269
10270 \end_inset 
10271
10272
10273 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
10274
10275 \end_inset 
10276
10277
10278 \layout Standard
10279
10280 Automatic (local) variables and parameters to functions can either be placed
10281  on the stack or in data-space.
10282  The default action of the compiler is to place these variables in the internal
10283  RAM (for small model) or external RAM (for large model).
10284  This in fact makes them similar to 
10285 \emph on 
10286 static
10287 \begin_inset LatexCommand \index{static}
10288
10289 \end_inset 
10290
10291
10292 \emph default 
10293  so by default functions are non-reentrant
10294 \begin_inset LatexCommand \index{reentrant}
10295
10296 \end_inset 
10297
10298 .
10299  
10300 \newline 
10301
10302 \newline 
10303 They can be placed on the stack
10304 \begin_inset LatexCommand \index{stack}
10305
10306 \end_inset 
10307
10308  by using the
10309 \emph on 
10310  -
10311 \begin_inset ERT
10312 status Collapsed
10313
10314 \layout Standard
10315
10316 \backslash 
10317 /
10318 \end_inset 
10319
10320 -stack-auto
10321 \begin_inset LatexCommand \index{-\/-stack-auto}
10322
10323 \end_inset 
10324
10325
10326 \emph default 
10327  option, by using 
10328 \emph on 
10329 #pragma\SpecialChar ~
10330 stackauto
10331 \emph default 
10332
10333 \begin_inset LatexCommand \index{\#pragma stackauto}
10334
10335 \end_inset 
10336
10337  or by using the 
10338 \emph on 
10339 reentrant
10340 \begin_inset LatexCommand \index{reentrant}
10341
10342 \end_inset 
10343
10344
10345 \emph default 
10346  keyword in the function declaration, e.g.:
10347 \layout Verse
10348
10349
10350 \family typewriter 
10351 unsigned char foo(char i) reentrant 
10352 \newline 
10353
10354 \newline 
10355 \SpecialChar ~
10356 \SpecialChar ~
10357 \SpecialChar ~
10358 \SpecialChar ~
10359 ...
10360  
10361 \newline 
10362 }
10363 \layout Standard
10364
10365 Since stack space on 8051 is limited, the 
10366 \emph on 
10367 reentrant 
10368 \emph default 
10369 keyword or the
10370 \emph on 
10371  -
10372 \begin_inset ERT
10373 status Collapsed
10374
10375 \layout Standard
10376
10377 \backslash 
10378 /
10379 \end_inset 
10380
10381 -stack-auto
10382 \emph default 
10383  option should be used sparingly.
10384  Note that the reentrant keyword just means that the parameters & local
10385  variables will be allocated to the stack, it 
10386 \emph on 
10387 does not
10388 \emph default 
10389  mean that the function is register bank
10390 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
10391
10392 \end_inset 
10393
10394  independent.
10395 \newline 
10396
10397 \newline 
10398 Local variables
10399 \begin_inset LatexCommand \index{local variables}
10400
10401 \end_inset 
10402
10403  can be assigned storage classes and absolute
10404 \begin_inset LatexCommand \index{Absolute addressing}
10405
10406 \end_inset 
10407
10408  addresses, e.g.: 
10409 \layout Verse
10410
10411
10412 \family typewriter 
10413 unsigned char foo() 
10414 \newline 
10415 {
10416 \newline 
10417 \SpecialChar ~
10418 \SpecialChar ~
10419 \SpecialChar ~
10420 \SpecialChar ~
10421 xdata unsigned char i;
10422 \newline 
10423 \SpecialChar ~
10424 \SpecialChar ~
10425 \SpecialChar ~
10426 \SpecialChar ~
10427 bit bvar;
10428 \newline 
10429 \SpecialChar ~
10430 \SpecialChar ~
10431 \SpecialChar ~
10432 \SpecialChar ~
10433 data at
10434 \begin_inset LatexCommand \index{at}
10435
10436 \end_inset 
10437
10438  0x31 unsigned char j;
10439 \newline 
10440 \SpecialChar ~
10441 \SpecialChar ~
10442 \SpecialChar ~
10443 \SpecialChar ~
10444 ...
10445  
10446 \newline 
10447 }
10448 \layout Standard
10449
10450 In the above example the variable 
10451 \emph on 
10452 i
10453 \emph default 
10454  will be allocated in the external ram, 
10455 \emph on 
10456 bvar
10457 \emph default 
10458  in bit addressable space and
10459 \emph on 
10460  j
10461 \emph default 
10462  in internal ram.
10463  When compiled with 
10464 \emph on 
10465 -
10466 \begin_inset ERT
10467 status Collapsed
10468
10469 \layout Standard
10470
10471 \backslash 
10472 /
10473 \end_inset 
10474
10475 -stack-auto
10476 \emph default 
10477  or when a function is declared as 
10478 \emph on 
10479 reentrant
10480 \emph default 
10481  this should only be done for static variables.
10482 \layout Standard
10483
10484 Parameters
10485 \begin_inset LatexCommand \index{function parameter}
10486
10487 \end_inset 
10488
10489  however are not allowed any storage class
10490 \begin_inset LatexCommand \index{Storage class}
10491
10492 \end_inset 
10493
10494 , (storage classes for parameters will be ignored), their allocation is
10495  governed by the memory model in use, and the reentrancy options.
10496 \layout Standard
10497
10498 It is however allowed to use bit parameters in reentrant functions and also
10499  non-static local bit variables are supported.
10500  Efficient use is limited to 8 semi-bitregisters in bit space.
10501  They are pushed and popped to stack as a single byte just like the normal
10502  registers.
10503 \layout Section
10504
10505 Overlaying
10506 \begin_inset LatexCommand \label{sub:Overlaying}
10507
10508 \end_inset 
10509
10510
10511 \begin_inset LatexCommand \index{Overlaying}
10512
10513 \end_inset 
10514
10515
10516 \layout Standard
10517
10518 For non-reentrant
10519 \begin_inset LatexCommand \index{reentrant}
10520
10521 \end_inset 
10522
10523  functions SDCC will try to reduce internal ram space usage by overlaying
10524  parameters and local variables of a function (if possible).
10525  Parameters and local variables
10526 \begin_inset LatexCommand \index{local variables}
10527
10528 \end_inset 
10529
10530  of a function will be allocated to an overlayable segment if the function
10531  has 
10532 \emph on 
10533 no other function calls and the function is non-reentrant and the memory
10534  model
10535 \begin_inset LatexCommand \index{Memory model}
10536
10537 \end_inset 
10538
10539  is small.
10540
10541 \emph default 
10542  If an explicit storage class
10543 \begin_inset LatexCommand \index{Storage class}
10544
10545 \end_inset 
10546
10547  is specified for a local variable, it will NOT be overlayed.
10548 \layout Standard
10549
10550 Note that the compiler (not the linkage editor) makes the decision for overlayin
10551 g the data items.
10552  Functions that are called from an interrupt service routine should be preceded
10553  by a #pragma\SpecialChar ~
10554 nooverlay
10555 \begin_inset LatexCommand \index{\#pragma nooverlay}
10556
10557 \end_inset 
10558
10559  if they are not reentrant.
10560 \layout Standard
10561
10562 Also note that the compiler does not do any processing of inline assembler
10563  code, so the compiler might incorrectly assign local variables and parameters
10564  of a function into the overlay segment if the inline assembler code calls
10565  other c-functions that might use the overlay.
10566  In that case the #pragma\SpecialChar ~
10567 nooverlay should be used.
10568 \layout Standard
10569
10570 Parameters and local variables of functions that contain 16 or 32 bit multiplica
10571 tion
10572 \begin_inset LatexCommand \index{Multiplication}
10573
10574 \end_inset 
10575
10576  or division
10577 \begin_inset LatexCommand \index{Division}
10578
10579 \end_inset 
10580
10581  will NOT be overlayed since these are implemented using external functions,
10582  e.g.:
10583 \layout Verse
10584
10585
10586 \family typewriter 
10587 #pragma save 
10588 \newline 
10589 #pragma nooverlay
10590 \begin_inset LatexCommand \index{\#pragma nooverlay}
10591
10592 \end_inset 
10593
10594  
10595 \newline 
10596 void set_error(unsigned char errcd) 
10597 \newline 
10598 {
10599 \newline 
10600 \SpecialChar ~
10601 \SpecialChar ~
10602 \SpecialChar ~
10603 \SpecialChar ~
10604 P3 = errcd;
10605 \newline 
10606
10607 \newline 
10608 #pragma restore 
10609 \newline 
10610
10611 \newline 
10612 void some_isr () interrupt
10613 \begin_inset LatexCommand \index{interrupt}
10614
10615 \end_inset 
10616
10617  2
10618 \newline 
10619 {
10620 \newline 
10621 \SpecialChar ~
10622 \SpecialChar ~
10623 \SpecialChar ~
10624 \SpecialChar ~
10625 ...
10626 \newline 
10627 \SpecialChar ~
10628 \SpecialChar ~
10629 \SpecialChar ~
10630 \SpecialChar ~
10631 set_error(10);
10632 \newline 
10633 \SpecialChar ~
10634 \SpecialChar ~
10635 \SpecialChar ~
10636 \SpecialChar ~
10637 ...
10638  
10639 \newline 
10640 }
10641 \layout Standard
10642
10643 In the above example the parameter 
10644 \emph on 
10645 errcd
10646 \emph default 
10647  for the function 
10648 \emph on 
10649 set_error
10650 \emph default 
10651  would be assigned to the overlayable segment if the #pragma\SpecialChar ~
10652 nooverlay was
10653  not present, this could cause unpredictable runtime behavior when called
10654  from an interrupt service routine.
10655  The #pragma\SpecialChar ~
10656 nooverlay ensures that the parameters and local variables for
10657  the function are NOT overlayed.
10658 \layout Section
10659
10660 Interrupt Service Routines
10661 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
10662
10663 \end_inset 
10664
10665
10666 \layout Subsection
10667
10668 General Information
10669 \layout Standard
10670
10671 SDCC allows 
10672 \emph on 
10673 i
10674 \emph default 
10675 nterrupt 
10676 \emph on 
10677 s
10678 \emph default 
10679 ervice 
10680 \emph on 
10681 r
10682 \emph default 
10683 outines to be coded in C, with some extended keywords.
10684 \layout Verse
10685
10686
10687 \family typewriter 
10688 void timer_isr (void) interrupt 1 using 1 
10689 \newline 
10690
10691 \newline 
10692 \SpecialChar ~
10693 \SpecialChar ~
10694 \SpecialChar ~
10695 \SpecialChar ~
10696 ...
10697  
10698 \newline 
10699 }
10700 \layout Standard
10701
10702 The optional number following the 
10703 \emph on 
10704 interrupt
10705 \begin_inset LatexCommand \index{interrupt}
10706
10707 \end_inset 
10708
10709
10710 \begin_inset LatexCommand \index{\_\_interrupt}
10711
10712 \end_inset 
10713
10714
10715 \emph default 
10716  keyword is the interrupt number this routine will service.
10717  When present, the compiler will insert a call to this routine in the interrupt
10718  vector table for the interrupt number specified.
10719  If you have multiple source files in your project, interrupt service routines
10720  can be present in any of them, but a prototype of the isr MUST be present
10721  or included in the file that contains the function 
10722 \emph on 
10723 main
10724 \emph default 
10725 .
10726  The optional 
10727 \emph on 
10728 using
10729 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10730
10731 \end_inset 
10732
10733
10734 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
10735
10736 \end_inset 
10737
10738
10739 \emph default 
10740  keyword can be used to tell the compiler to use the specified register
10741  bank (8051 specific) when generating code for this function.
10742  
10743 \newline 
10744
10745 \layout Standard
10746
10747 Interrupt service routines open the door for some very interesting bugs:
10748 \newline 
10749 If an interrupt service routine changes variables which are accessed by
10750  other functions these variables have to be declared 
10751 \emph on 
10752 volatile
10753 \emph default 
10754
10755 \begin_inset LatexCommand \index{volatile}
10756
10757 \end_inset 
10758
10759 .
10760  
10761 \layout Standard
10762
10763 If the access to these variables is not 
10764 \emph on 
10765 atomic
10766 \begin_inset LatexCommand \index{atomic}
10767
10768 \end_inset 
10769
10770
10771 \emph default 
10772  (i.e.
10773  the processor needs more than one instruction for the access and could
10774  be interrupted while accessing the variable) the interrupt must be disabled
10775  during the access to avoid inconsistent data.
10776  Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
10777  and should be protected by disabling interrupts.
10778  You're not automatically on the safe side if you use 8 bit variables though.
10779  We need an example here: f.e.
10780  on the 8051 the harmless looking 
10781 \begin_inset Quotes srd
10782 \end_inset 
10783
10784
10785 \family typewriter 
10786 flags\SpecialChar ~
10787 |=\SpecialChar ~
10788 0x80;
10789 \family default 
10790
10791 \begin_inset Quotes sld
10792 \end_inset 
10793
10794  is not atomic if 
10795 \family typewriter 
10796 flags
10797 \family default 
10798  resides in xdata.
10799  Setting 
10800 \begin_inset Quotes srd
10801 \end_inset 
10802
10803
10804 \family typewriter 
10805 flags\SpecialChar ~
10806 |=\SpecialChar ~
10807 0x40;
10808 \family default 
10809
10810 \begin_inset Quotes sld
10811 \end_inset 
10812
10813  from within an interrupt routine might get lost if the interrupt occurs
10814  at the wrong time.
10815  
10816 \begin_inset Quotes sld
10817 \end_inset 
10818
10819
10820 \family typewriter 
10821 counter\SpecialChar ~
10822 +=\SpecialChar ~
10823 8;
10824 \family default 
10825
10826 \begin_inset Quotes srd
10827 \end_inset 
10828
10829  is not atomic on the 8051 even if 
10830 \family typewriter 
10831 counter
10832 \family default 
10833  is located in data memory.
10834  Bugs like these are hard to reproduce and can cause a lot of trouble.
10835  
10836 \layout Standard
10837
10838 The return address and the registers used in the interrupt service routine
10839  are saved on the stack
10840 \begin_inset LatexCommand \index{stack}
10841
10842 \end_inset 
10843
10844  so there must be sufficient stack space.
10845  If there isn't variables or registers (or even the return address itself)
10846  will be corrupted.
10847  This 
10848 \emph on 
10849 stack overflow
10850 \emph default 
10851
10852 \begin_inset LatexCommand \index{stack overflow}
10853
10854 \end_inset 
10855
10856  is most likely to happen if the interrupt occurs during the 
10857 \begin_inset Quotes sld
10858 \end_inset 
10859
10860 deepest
10861 \begin_inset Quotes srd
10862 \end_inset 
10863
10864  subroutine when the stack is already in use for f.e.
10865  many return addresses.
10866 \layout Standard
10867
10868 A special note here, int (16 bit) and long (32 bit) integer division
10869 \begin_inset LatexCommand \index{Division}
10870
10871 \end_inset 
10872
10873 , multiplication
10874 \begin_inset LatexCommand \index{Multiplication}
10875
10876 \end_inset 
10877
10878  & modulus
10879 \begin_inset LatexCommand \index{Modulus}
10880
10881 \end_inset 
10882
10883  and floating-point
10884 \begin_inset LatexCommand \index{Floating point support}
10885
10886 \end_inset 
10887
10888  operations are implemented using external support routines developed in
10889  ANSI-C.
10890  If an interrupt service routine needs to do any of these operations then
10891  the support routines (as mentioned in a following section) will have to
10892  be recompiled using the
10893 \emph on 
10894  -
10895 \begin_inset ERT
10896 status Collapsed
10897
10898 \layout Standard
10899
10900 \backslash 
10901 /
10902 \end_inset 
10903
10904 -stack-auto
10905 \begin_inset LatexCommand \index{-\/-stack-auto}
10906
10907 \end_inset 
10908
10909
10910 \emph default 
10911  option and the source file will need to be compiled using the 
10912 \emph on 
10913 -
10914 \begin_inset ERT
10915 status Collapsed
10916
10917 \layout Standard
10918
10919 \backslash 
10920 /
10921 \end_inset 
10922
10923 -int-long-reent
10924 \emph default 
10925
10926 \begin_inset LatexCommand \index{-\/-int-long-reent}
10927
10928 \end_inset 
10929
10930  compiler option.
10931 \layout Standard
10932
10933 Calling other functions from an interrupt service routine is not recommended,
10934  avoid it if possible.
10935  Note that when some function is called from an interrupt service routine
10936  it should be preceded by a #pragma\SpecialChar ~
10937 nooverlay
10938 \begin_inset LatexCommand \index{\#pragma nooverlay}
10939
10940 \end_inset 
10941
10942  if it is not reentrant.
10943  Furthermore nonreentrant functions should not be called from the main program
10944  while the interrupt service routine might be active.
10945  They also must not be called from low priority interrupt service routines
10946  while a high priority interrupt service routine might be active. You could use
10947  semaphores or make the function
10948 \emph on 
10949  critical
10950 \emph default 
10951  if all parameters are passed in registers.
10952 \newline 
10953
10954 \newline 
10955 Also see section 
10956 \begin_inset LatexCommand \ref{sub:Overlaying}
10957
10958 \end_inset 
10959
10960 \SpecialChar ~
10961 about Overlaying and section 
10962 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
10963
10964 \end_inset 
10965
10966 \SpecialChar ~
10967 about Functions using private register banks.
10968 \layout Subsection
10969
10970 MCS51/DS390 Interrupt Service Routines
10971 \layout Standard
10972
10973 Interrupt numbers and the corresponding address & descriptions for the Standard
10974  8051/8052 are listed below.
10975  SDCC will automatically adjust the interrupt vector table to the maximum
10976  interrupt number specified.
10977 \newline 
10978
10979 \layout Standard
10980 \align center 
10981
10982 \begin_inset  Tabular
10983 <lyxtabular version="3" rows="7" columns="3">
10984 <features>
10985 <column alignment="center" valignment="top" leftline="true" width="0in">
10986 <column alignment="center" valignment="top" leftline="true" width="0in">
10987 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0in">
10988 <row topline="true" bottomline="true">
10989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10990 \begin_inset Text
10991
10992 \layout Standard
10993
10994 Interrupt #
10995 \end_inset 
10996 </cell>
10997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10998 \begin_inset Text
10999
11000 \layout Standard
11001
11002 Description
11003 \end_inset 
11004 </cell>
11005 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11006 \begin_inset Text
11007
11008 \layout Standard
11009
11010 Vector Address
11011 \end_inset 
11012 </cell>
11013 </row>
11014 <row topline="true">
11015 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11016 \begin_inset Text
11017
11018 \layout Standard
11019
11020 0
11021 \end_inset 
11022 </cell>
11023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11024 \begin_inset Text
11025
11026 \layout Standard
11027
11028 External 0
11029 \end_inset 
11030 </cell>
11031 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11032 \begin_inset Text
11033
11034 \layout Standard
11035
11036 0x0003
11037 \end_inset 
11038 </cell>
11039 </row>
11040 <row topline="true">
11041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11042 \begin_inset Text
11043
11044 \layout Standard
11045
11046 1
11047 \end_inset 
11048 </cell>
11049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11050 \begin_inset Text
11051
11052 \layout Standard
11053
11054 Timer 0
11055 \end_inset 
11056 </cell>
11057 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11058 \begin_inset Text
11059
11060 \layout Standard
11061
11062 0x000B
11063 \end_inset 
11064 </cell>
11065 </row>
11066 <row topline="true">
11067 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11068 \begin_inset Text
11069
11070 \layout Standard
11071
11072 2
11073 \end_inset 
11074 </cell>
11075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11076 \begin_inset Text
11077
11078 \layout Standard
11079
11080 External 1
11081 \end_inset 
11082 </cell>
11083 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11084 \begin_inset Text
11085
11086 \layout Standard
11087
11088 0x0013
11089 \end_inset 
11090 </cell>
11091 </row>
11092 <row topline="true">
11093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11094 \begin_inset Text
11095
11096 \layout Standard
11097
11098 3
11099 \end_inset 
11100 </cell>
11101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11102 \begin_inset Text
11103
11104 \layout Standard
11105
11106 Timer 1
11107 \end_inset 
11108 </cell>
11109 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11110 \begin_inset Text
11111
11112 \layout Standard
11113
11114 0x001B
11115 \end_inset 
11116 </cell>
11117 </row>
11118 <row topline="true">
11119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11120 \begin_inset Text
11121
11122 \layout Standard
11123
11124 4
11125 \end_inset 
11126 </cell>
11127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11128 \begin_inset Text
11129
11130 \layout Standard
11131
11132 Serial
11133 \end_inset 
11134 </cell>
11135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11136 \begin_inset Text
11137
11138 \layout Standard
11139
11140 0x0023
11141 \end_inset 
11142 </cell>
11143 </row>
11144 <row topline="true" bottomline="true">
11145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11146 \begin_inset Text
11147
11148 \layout Standard
11149
11150 5
11151 \end_inset 
11152 </cell>
11153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11154 \begin_inset Text
11155
11156 \layout Standard
11157
11158 Timer 2 (8052)
11159 \end_inset 
11160 </cell>
11161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11162 \begin_inset Text
11163
11164 \layout Standard
11165
11166 0x002B
11167 \end_inset 
11168 </cell>
11169 </row>
11170 </lyxtabular>
11171
11172 \end_inset 
11173
11174
11175 \newline 
11176
11177 \layout Standard
11178
11179 If the interrupt service routine is defined without 
11180 \emph on 
11181 using
11182 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11183
11184 \end_inset 
11185
11186
11187 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11188
11189 \end_inset 
11190
11191
11192 \emph default 
11193  a register bank or with register bank 0 (
11194 \emph on 
11195 using
11196 \emph default 
11197  0), the compiler will save the registers used by itself on the stack upon
11198  entry and restore them at exit, however if such an interrupt service routine
11199  calls another function then the entire register bank will be saved on the
11200  stack.
11201  This scheme may be advantageous for small interrupt service routines which
11202  have low register usage.
11203 \layout Standard
11204
11205 If the interrupt service routine is defined to be using a specific register
11206  bank then only 
11207 \emph on 
11208 a, b, dptr
11209 \emph default 
11210  & psw are saved and restored, if such an interrupt service routine calls
11211  another function (using another register bank) then the entire register
11212  bank of the called function will be saved on the stack.
11213  This scheme is recommended for larger interrupt service routines.
11214 \layout Subsection
11215
11216 HC08 Interrupt Service Routines
11217 \layout Standard
11218
11219 Since the number of interrupts available is chip specific and the interrupt
11220  vector table always ends at the last byte of memory, the interrupt numbers
11221  corresponds to the interrupt vectors in reverse order of address.
11222  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
11223  2 will use the interrupt vector at 0xfffa, and so on.
11224  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
11225  this way; instead see section 
11226 \begin_inset LatexCommand \ref{sub:Startup-Code}
11227
11228 \end_inset 
11229
11230  for details on customizing startup.
11231 \layout Subsection
11232
11233 Z80 Interrupt Service Routines
11234 \layout Standard
11235
11236 The Z80 uses several different methods for determining the correct interrupt
11237  vector depending on the hardware implementation.
11238  Therefore, SDCC ignores the optional interrupt number and does not attempt
11239  to generate an interrupt vector table.
11240 \layout Standard
11241
11242 By default, SDCC generates code for a maskable interrupt, which uses an
11243  RETI instruction to return from the interrupt.
11244  To write an interrupt handler for the non-maskable interrupt, which needs
11245  an RETN instruction instead, add the 
11246 \emph on 
11247 critical
11248 \emph default 
11249  keyword:
11250 \layout Verse
11251
11252
11253 \family typewriter 
11254 void nmi_isr (void) critical interrupt
11255 \newline 
11256
11257 \newline 
11258 \SpecialChar ~
11259 \SpecialChar ~
11260 \SpecialChar ~
11261 \SpecialChar ~
11262 ...
11263  
11264 \newline 
11265 }
11266 \layout Section
11267
11268 Enabling and Disabling Interrupts
11269 \layout Subsection
11270
11271 Critical Functions and Critical Statements
11272 \layout Standard
11273
11274 A special keyword may be associated with a block or a function declaring
11275  it as 
11276 \emph on 
11277 critical
11278 \emph default 
11279 .
11280  SDCC will generate code to disable all interrupts
11281 \begin_inset LatexCommand \index{interrupt}
11282
11283 \end_inset 
11284
11285  upon entry to a critical function and restore the interrupt enable to the
11286  previous state before returning.
11287  Nesting critical functions will need one additional byte on the stack
11288 \begin_inset LatexCommand \index{stack}
11289
11290 \end_inset 
11291
11292  for each call.
11293 \layout Verse
11294
11295
11296 \family typewriter 
11297 int foo () critical
11298 \begin_inset LatexCommand \index{critical}
11299
11300 \end_inset 
11301
11302
11303 \begin_inset LatexCommand \index{\_\_critical}
11304
11305 \end_inset 
11306
11307  
11308 \newline 
11309
11310 \newline 
11311 \SpecialChar ~
11312 \SpecialChar ~
11313 \SpecialChar ~
11314 \SpecialChar ~
11315 ...
11316  
11317 \newline 
11318 \SpecialChar ~
11319 \SpecialChar ~
11320 \SpecialChar ~
11321 \SpecialChar ~
11322 ...
11323  
11324 \newline 
11325 }
11326 \layout Standard
11327
11328 The critical attribute maybe used with other attributes like 
11329 \emph on 
11330 reentrant.
11331 \emph default 
11332
11333 \newline 
11334 The keyword 
11335 \emph on 
11336 critical
11337 \emph default 
11338  may also be used to disable interrupts more locally:
11339 \layout Verse
11340
11341
11342 \family typewriter 
11343 critical{ i++; }
11344 \layout Standard
11345
11346 More than one statement could have been included in the block.
11347 \layout Subsection
11348
11349 Enabling and Disabling Interrupts directly
11350 \layout Standard
11351
11352 Interrupts
11353 \begin_inset LatexCommand \index{interrupt}
11354
11355 \end_inset 
11356
11357  can also be disabled and enabled directly (8051):
11358 \layout Verse
11359
11360
11361 \family typewriter 
11362 EA = 0;\SpecialChar ~
11363 \SpecialChar ~
11364 \SpecialChar ~
11365 \SpecialChar ~
11366 \SpecialChar ~
11367 \SpecialChar ~
11368 \SpecialChar ~
11369 \SpecialChar ~
11370 \SpecialChar ~
11371 \SpecialChar ~
11372 \SpecialChar ~
11373 \SpecialChar ~
11374 or:\SpecialChar ~
11375 \SpecialChar ~
11376 \SpecialChar ~
11377 \SpecialChar ~
11378 \SpecialChar ~
11379 \SpecialChar ~
11380 \SpecialChar ~
11381 \SpecialChar ~
11382 \SpecialChar ~
11383 \SpecialChar ~
11384 \SpecialChar ~
11385 EA_SAVE = EA;
11386 \layout Verse
11387
11388
11389 \family typewriter 
11390 ...\SpecialChar ~
11391 \SpecialChar ~
11392 \SpecialChar ~
11393 \SpecialChar ~
11394 \SpecialChar ~
11395 \SpecialChar ~
11396 \SpecialChar ~
11397 \SpecialChar ~
11398 \SpecialChar ~
11399 \SpecialChar ~
11400 \SpecialChar ~
11401 \SpecialChar ~
11402 \SpecialChar ~
11403 \SpecialChar ~
11404 \SpecialChar ~
11405 \SpecialChar ~
11406 \SpecialChar ~
11407 \SpecialChar ~
11408 \SpecialChar ~
11409 \SpecialChar ~
11410 \SpecialChar ~
11411 \SpecialChar ~
11412 \SpecialChar ~
11413 \SpecialChar ~
11414 \SpecialChar ~
11415 \SpecialChar ~
11416 \SpecialChar ~
11417 \SpecialChar ~
11418 \SpecialChar ~
11419 \SpecialChar ~
11420 EA = 0;
11421 \layout Verse
11422
11423
11424 \family typewriter 
11425 EA = 1;\SpecialChar ~
11426 \SpecialChar ~
11427 \SpecialChar ~
11428 \SpecialChar ~
11429 \SpecialChar ~
11430 \SpecialChar ~
11431 \SpecialChar ~
11432 \SpecialChar ~
11433 \SpecialChar ~
11434 \SpecialChar ~
11435 \SpecialChar ~
11436 \SpecialChar ~
11437 \SpecialChar ~
11438 \SpecialChar ~
11439 \SpecialChar ~
11440 \SpecialChar ~
11441 \SpecialChar ~
11442 \SpecialChar ~
11443 \SpecialChar ~
11444 \SpecialChar ~
11445 \SpecialChar ~
11446 \SpecialChar ~
11447 \SpecialChar ~
11448 \SpecialChar ~
11449 \SpecialChar ~
11450 \SpecialChar ~
11451 ...
11452 \layout Verse
11453
11454
11455 \family typewriter 
11456 \SpecialChar ~
11457 \SpecialChar ~
11458 \SpecialChar ~
11459 \SpecialChar ~
11460 \SpecialChar ~
11461 \SpecialChar ~
11462 \SpecialChar ~
11463 \SpecialChar ~
11464 \SpecialChar ~
11465 \SpecialChar ~
11466 \SpecialChar ~
11467 \SpecialChar ~
11468 \SpecialChar ~
11469 \SpecialChar ~
11470 \SpecialChar ~
11471 \SpecialChar ~
11472 \SpecialChar ~
11473 \SpecialChar ~
11474 \SpecialChar ~
11475 \SpecialChar ~
11476 \SpecialChar ~
11477 \SpecialChar ~
11478 \SpecialChar ~
11479 \SpecialChar ~
11480 \SpecialChar ~
11481 \SpecialChar ~
11482 \SpecialChar ~
11483 \SpecialChar ~
11484 \SpecialChar ~
11485 \SpecialChar ~
11486 \SpecialChar ~
11487 \SpecialChar ~
11488 \SpecialChar ~
11489 EA = EA_SAVE;
11490 \layout Standard
11491
11492 On other architectures which have seperate opcodes for enabling and disabling
11493  interrupts you might want to make use of defines with inline assembly
11494 \begin_inset LatexCommand \index{Assembler routines}
11495
11496 \end_inset 
11497
11498  (HC08):
11499 \layout Verse
11500
11501
11502 \family typewriter 
11503 #define CLI _asm
11504 \begin_inset LatexCommand \index{\_asm}
11505
11506 \end_inset 
11507
11508 \SpecialChar ~
11509 \SpecialChar ~
11510 cli\SpecialChar ~
11511 \SpecialChar ~
11512 _endasm
11513 \begin_inset LatexCommand \index{\_endasm}
11514
11515 \end_inset 
11516
11517
11518 \layout Verse
11519
11520
11521 \family typewriter 
11522 #define SEI _asm\SpecialChar ~
11523 \SpecialChar ~
11524 sei\SpecialChar ~
11525 \SpecialChar ~
11526 _endasm; 
11527 \layout Verse
11528
11529
11530 \family typewriter 
11531 ...
11532 \layout Standard
11533
11534 Note: it is sometimes sufficient to disable only a specific interrupt source
11535  like f.e.
11536  a timer or serial interrupt by manipulating an 
11537 \emph on 
11538 interrupt mask
11539 \begin_inset LatexCommand \index{interrupt mask}
11540
11541 \end_inset 
11542
11543
11544 \emph default 
11545  register.
11546  
11547 \layout Standard
11548
11549 Usually the time during which interrupts are disabled should be kept as
11550  short as possible.
11551  This minimizes both 
11552 \emph on 
11553 interrupt latency
11554 \emph default 
11555
11556 \begin_inset LatexCommand \index{interrupt latency}
11557
11558 \end_inset 
11559
11560  (the time between the occurrence of the interrupt and the execution of
11561  the first code in the interrupt routine) and 
11562 \emph on 
11563 interrupt jitter
11564 \emph default 
11565
11566 \begin_inset LatexCommand \index{interrupt jitter}
11567
11568 \end_inset 
11569
11570  (the difference between the shortest and the longest interrupt latency).
11571  These really are something different, f.e.
11572  a serial interrupt has to be served before its buffer overruns so it cares
11573  for the maximum interrupt latency, whereas it does not care about jitter.
11574  On a loudspeaker driven via a digital to analog converter which is fed
11575  by an interrupt a latency of a few milliseconds might be tolerable, whereas
11576  a much smaller jitter will be very audible.
11577 \layout Standard
11578
11579 You can reenable interrupts within an interrupt routine and on some architecture
11580 s you can make use of two (or more) levels of 
11581 \emph on 
11582 interrupt priorities
11583 \emph default 
11584
11585 \begin_inset LatexCommand \index{interrupt priority}
11586
11587 \end_inset 
11588
11589 .
11590  On some architectures which don't support interrupt priorities these can
11591  be implemented by manipulating the interrupt mask and reenabling interrupts
11592  within the interrupt routine.
11593  Check there is sufficient space on the stack
11594 \begin_inset LatexCommand \index{stack}
11595
11596 \end_inset 
11597
11598  and don't add complexity unless you have to.
11599  
11600 \layout Subsection
11601
11602 Semaphore
11603 \begin_inset LatexCommand \index{semaphore}
11604
11605 \end_inset 
11606
11607  locking (mcs51/ds390)
11608 \layout Standard
11609
11610 Some architectures (mcs51/ds390) have an atomic
11611 \begin_inset LatexCommand \index{atomic}
11612
11613 \end_inset 
11614
11615  bit test and
11616 \emph on 
11617  
11618 \emph default 
11619 clear
11620 \emph on 
11621  
11622 \emph default 
11623 instruction.
11624  These type of instructions are typically used in preemptive multitasking
11625  systems, where a routine f.e.
11626  claims the use of a data structure ('acquires a lock
11627 \begin_inset LatexCommand \index{lock}
11628
11629 \end_inset 
11630
11631  on it'), makes some modifications and then releases the lock when the data
11632  structure is consistent again.
11633  The instruction may also be used if interrupt and non-interrupt code have
11634  to compete for a resource.
11635  With the atomic bit test and clear instruction interrupts
11636 \begin_inset LatexCommand \index{interrupt}
11637
11638 \end_inset 
11639
11640  don't have to be disabled for the locking operation.
11641  
11642 \layout Standard
11643
11644 SDCC generates this instruction if the source follows this pattern:
11645 \layout Verse
11646
11647
11648 \family typewriter 
11649 volatile
11650 \begin_inset LatexCommand \index{volatile}
11651
11652 \end_inset 
11653
11654  bit resource_is_free; 
11655 \newline 
11656
11657 \newline 
11658 if (resource_is_free) 
11659 \newline 
11660 \SpecialChar ~
11661 \SpecialChar ~
11662
11663 \newline 
11664 \SpecialChar ~
11665 \SpecialChar ~
11666 \SpecialChar ~
11667 \SpecialChar ~
11668 resource_is_free=0; 
11669 \newline 
11670 \SpecialChar ~
11671 \SpecialChar ~
11672 \SpecialChar ~
11673 \SpecialChar ~
11674 ...
11675  
11676 \newline 
11677 \SpecialChar ~
11678 \SpecialChar ~
11679 \SpecialChar ~
11680 \SpecialChar ~
11681 resource_is_free=1;
11682 \newline 
11683 \SpecialChar ~
11684 \SpecialChar ~
11685
11686 \layout Standard
11687
11688 Note, mcs51 and ds390 support only an atomic
11689 \begin_inset LatexCommand \index{atomic}
11690
11691 \end_inset 
11692
11693  bit test and 
11694 \emph on 
11695 clear
11696 \emph default 
11697  instruction (as opposed to atomic bit test and 
11698 \emph on 
11699 set).
11700 \layout Section
11701
11702 Functions using private register banks
11703 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
11704
11705 \end_inset 
11706
11707  (mcs51/ds390)
11708 \layout Standard
11709
11710 Some architectures have support for quickly changing register sets.
11711  SDCC supports this feature with the 
11712 \emph on 
11713 using
11714 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11715
11716 \end_inset 
11717
11718
11719 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11720
11721 \end_inset 
11722
11723
11724 \emph default 
11725  attribute (which tells the compiler to use a register bank
11726 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
11727
11728 \end_inset 
11729
11730  other than the default bank zero).
11731  It should only be applied to 
11732 \emph on 
11733 interrupt
11734 \begin_inset LatexCommand \index{interrupt}
11735
11736 \end_inset 
11737
11738
11739 \emph default 
11740  functions (see footnote below).
11741  This will in most circumstances make the generated ISR code more efficient
11742  since it will not have to save registers on the stack.
11743 \layout Standard
11744
11745 The 
11746 \emph on 
11747 using
11748 \emph default 
11749  attribute will have no effect on the generated code for a 
11750 \emph on 
11751 non-interrupt
11752 \emph default 
11753  function (but may occasionally be useful anyway
11754 \begin_inset Foot
11755 collapsed false
11756
11757 \layout Standard
11758
11759 possible exception: if a function is called ONLY from 'interrupt' functions
11760  using a particular bank, it can be declared with the same 'using' attribute
11761  as the calling 'interrupt' functions.
11762  For instance, if you have several ISRs using bank one, and all of them
11763  call memcpy(), it might make sense to create a specialized version of memcpy()
11764  'using 1', since this would prevent the ISR from having to save bank zero
11765  to the stack on entry and switch to bank zero before calling the function
11766 \end_inset 
11767
11768 ).
11769 \newline 
11770
11771 \emph on 
11772 (pending: I don't think this has been done yet)
11773 \layout Standard
11774
11775 An 
11776 \emph on 
11777 interrupt
11778 \emph default 
11779  function using a non-zero bank will assume that it can trash that register
11780  bank, and will not save it.
11781  Since high-priority interrupts
11782 \begin_inset LatexCommand \index{interrupts}
11783
11784 \end_inset 
11785
11786
11787 \begin_inset LatexCommand \index{interrupt priority}
11788
11789 \end_inset 
11790
11791  can interrupt low-priority ones on the 8051 and friends, this means that
11792  if a high-priority ISR 
11793 \emph on 
11794 using
11795 \emph default 
11796  a particular bank occurs while processing a low-priority ISR 
11797 \emph on 
11798 using
11799 \emph default 
11800  the same bank, terrible and bad things can happen.
11801  To prevent this, no single register bank should be 
11802 \emph on 
11803 used
11804 \emph default 
11805  by both a high priority and a low priority ISR.
11806  This is probably most easily done by having all high priority ISRs use
11807  one bank and all low priority ISRs use another.
11808  If you have an ISR which can change priority at runtime, you're on your
11809  own: I suggest using the default bank zero and taking the small performance
11810  hit.
11811 \layout Standard
11812
11813 It is most efficient if your ISR calls no other functions.
11814  If your ISR must call other functions, it is most efficient if those functions
11815  use the same bank as the ISR (see note 1 below); the next best is if the
11816  called functions use bank zero.
11817  It is very inefficient to call a function using a different, non-zero bank
11818  from an ISR.
11819  
11820 \layout Section
11821
11822 Startup Code
11823 \begin_inset LatexCommand \label{sub:Startup-Code}
11824
11825 \end_inset 
11826
11827
11828 \begin_inset LatexCommand \index{Startup code}
11829
11830 \end_inset 
11831
11832
11833 \layout Subsection
11834
11835 MCS51/DS390 Startup Code
11836 \layout Standard
11837
11838 The compiler inserts a call to the C routine 
11839 \emph on 
11840 _sdcc_external_startup()
11841 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
11842
11843 \end_inset 
11844
11845
11846 \series bold 
11847 \emph default 
11848  
11849 \series default 
11850 at the start of the CODE area.
11851  This routine is in the runtime library
11852 \begin_inset LatexCommand \index{Runtime library}
11853
11854 \end_inset 
11855
11856 .
11857  By default this routine returns 0, if this routine returns a non-zero value,
11858  the static & global variable initialization will be skipped and the function
11859  main will be invoked.
11860  Otherwise static & global variables will be initialized before the function
11861  main is invoked.
11862  You could add a 
11863 \emph on 
11864 _sdcc_external_startup()
11865 \emph default 
11866  routine to your program to override the default if you need to setup hardware
11867  or perform some other critical operation prior to static & global variable
11868  initialization
11869 \begin_inset LatexCommand \index{Variable initialization}
11870
11871 \end_inset 
11872
11873 .
11874  On some mcs51 variants xdata
11875 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11876
11877 \end_inset 
11878
11879  memory has to be explicitly enabled before it can be accessed or if the
11880  watchdog needs to be disabled, this is the place to do it.
11881  The startup code clears all internal data memory, 256 bytes by default,
11882  but from 0 to n-1 if 
11883 \emph on 
11884 -
11885 \begin_inset ERT
11886 status Collapsed
11887
11888 \layout Standard
11889
11890 \backslash 
11891 /
11892 \end_inset 
11893
11894 -iram-size
11895 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
11896
11897 \end_inset 
11898
11899 n
11900 \emph default 
11901  is used.
11902  (recommended for Chipcon CC1010).
11903 \layout Standard
11904
11905 See also the compiler option 
11906 \emph on 
11907 -
11908 \begin_inset ERT
11909 status Collapsed
11910
11911 \layout Standard
11912
11913 \backslash 
11914 /
11915 \end_inset 
11916
11917 -no-xinit
11918 \emph default 
11919 -
11920 \emph on 
11921 opt
11922 \emph default 
11923
11924 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
11925
11926 \end_inset 
11927
11928  and section 
11929 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11930
11931 \end_inset 
11932
11933 \SpecialChar ~
11934 about MCS51-variants.
11935 \layout Subsection
11936
11937 HC08 Startup Code
11938 \layout Standard
11939
11940 The HC08 startup code follows the same scheme as the MCS51 startup code.
11941 \layout Subsection
11942
11943 Z80 Startup Code
11944 \layout Standard
11945
11946 On the Z80 the startup code is inserted by linking with crt0.o which is generated
11947  from sdcc/device/lib/z80/crt0.s.
11948  If you need a different startup code you can use the compiler option 
11949 \emph on 
11950 -
11951 \series bold 
11952 \emph default 
11953
11954 \begin_inset ERT
11955 status Collapsed
11956
11957 \layout Standard
11958
11959 \backslash 
11960 /
11961 \end_inset 
11962
11963
11964 \series default 
11965 \emph on 
11966 -no-std-crt0
11967 \emph default 
11968
11969 \begin_inset LatexCommand \index{-\/-no-std-crt0}
11970
11971 \end_inset 
11972
11973  and provide your own crt0.o.
11974  
11975 \layout Section
11976
11977 Inline Assembler Code
11978 \begin_inset LatexCommand \index{Assembler routines}
11979
11980 \end_inset 
11981
11982
11983 \layout Subsection
11984
11985 A Step by Step Introduction
11986 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
11987
11988 \end_inset 
11989
11990
11991 \layout Standard
11992
11993 Starting from a small snippet of c-code this example shows for the MCS51
11994  how to use inline assembly, access variables, a function parameter and
11995  an array in xdata memory.
11996  The example uses an MCS51 here but is easily adapted for other architectures.
11997  This is a buffer routine which should be optimized:
11998 \layout Verse
11999
12000
12001 \family typewriter 
12002 \size footnotesize 
12003 unsigned char far
12004 \begin_inset LatexCommand \index{far (storage class)}
12005
12006 \end_inset 
12007
12008
12009 \begin_inset LatexCommand \index{\_\_far (storage class)}
12010
12011 \end_inset 
12012
12013  at
12014 \begin_inset LatexCommand \index{at}
12015
12016 \end_inset 
12017
12018
12019 \begin_inset LatexCommand \index{\_\_at}
12020
12021 \end_inset 
12022
12023  0x7f00 buf[0x100];
12024 \begin_inset LatexCommand \index{Aligned array}
12025
12026 \end_inset 
12027
12028
12029 \newline 
12030 unsigned char head,tail;
12031 \newline 
12032
12033 \newline 
12034 void to_buffer( unsigned char c ) 
12035 \newline 
12036 {
12037 \newline 
12038 \SpecialChar ~
12039 \SpecialChar ~
12040 \SpecialChar ~
12041 \SpecialChar ~
12042 if( head != tail-1 ) 
12043 \newline 
12044 \SpecialChar ~
12045 \SpecialChar ~
12046 \SpecialChar ~
12047 \SpecialChar ~
12048 \SpecialChar ~
12049 \SpecialChar ~
12050 \SpecialChar ~
12051 \SpecialChar ~
12052 buf[ head++ ] = c;\SpecialChar ~
12053 \SpecialChar ~
12054 \SpecialChar ~
12055 \SpecialChar ~
12056 /* access to a 256 byte aligned array */
12057 \newline 
12058
12059 \layout Standard
12060
12061 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
12062  then a corresponding buffer.asm file is generated.
12063  We define a new function 
12064 \family typewriter 
12065 to_buffer_asm()
12066 \family default 
12067  in file buffer.c in which we cut and paste the generated code, removing
12068  unwanted comments and some ':'.
12069  Then add 
12070 \begin_inset Quotes sld
12071 \end_inset 
12072
12073 _asm
12074 \begin_inset Quotes srd
12075 \end_inset 
12076
12077  and 
12078 \begin_inset Quotes sld
12079 \end_inset 
12080
12081 _endasm;
12082 \begin_inset Quotes srd
12083 \end_inset 
12084
12085  to the beginning and the end of the function body:
12086 \layout Verse
12087
12088
12089 \family typewriter 
12090 \size footnotesize 
12091 /* With a cut and paste from the .asm file, we have something to start with.
12092 \newline 
12093 \SpecialChar ~
12094 \SpecialChar ~
12095 \SpecialChar ~
12096 The function is not yet OK! (registers aren't saved) */ 
12097 \newline 
12098 void to_buffer_asm( unsigned char c ) 
12099 \newline 
12100
12101 \newline 
12102 \SpecialChar ~
12103 \SpecialChar ~
12104 \SpecialChar ~
12105 \SpecialChar ~
12106 _asm
12107 \begin_inset LatexCommand \index{\_asm}
12108
12109 \end_inset 
12110
12111
12112 \begin_inset LatexCommand \index{\_\_asm}
12113
12114 \end_inset 
12115
12116
12117 \newline 
12118 \SpecialChar ~
12119 \SpecialChar ~
12120 \SpecialChar ~
12121 \SpecialChar ~
12122 mov\SpecialChar ~
12123 \SpecialChar ~
12124 r2,dpl 
12125 \newline 
12126 ;buffer.c if( head != tail-1 ) 
12127 \newline 
12128 \SpecialChar ~
12129 \SpecialChar ~
12130 \SpecialChar ~
12131 \SpecialChar ~
12132 mov\SpecialChar ~
12133 \SpecialChar ~
12134 a,_tail 
12135 \newline 
12136 \SpecialChar ~
12137 \SpecialChar ~
12138 \SpecialChar ~
12139 \SpecialChar ~
12140 dec\SpecialChar ~
12141 \SpecialChar ~
12142
12143 \newline 
12144 \SpecialChar ~
12145 \SpecialChar ~
12146 \SpecialChar ~
12147 \SpecialChar ~
12148 mov\SpecialChar ~
12149 \SpecialChar ~
12150 r3,a 
12151 \newline 
12152 \SpecialChar ~
12153 \SpecialChar ~
12154 \SpecialChar ~
12155 \SpecialChar ~
12156 mov\SpecialChar ~
12157 \SpecialChar ~
12158 a,_head 
12159 \newline 
12160 \SpecialChar ~
12161 \SpecialChar ~
12162 \SpecialChar ~
12163 \SpecialChar ~
12164 cjne a,ar3,00106$ 
12165 \newline 
12166 \SpecialChar ~
12167 \SpecialChar ~
12168 \SpecialChar ~
12169 \SpecialChar ~
12170 ret
12171 \newline 
12172 00106$: 
12173 \newline 
12174 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
12175 \begin_inset LatexCommand \index{Aligned array}
12176
12177 \end_inset 
12178
12179
12180 \newline 
12181 \SpecialChar ~
12182 \SpecialChar ~
12183 \SpecialChar ~
12184 \SpecialChar ~
12185 mov\SpecialChar ~
12186 \SpecialChar ~
12187 r3,_head 
12188 \newline 
12189 \SpecialChar ~
12190 \SpecialChar ~
12191 \SpecialChar ~
12192 \SpecialChar ~
12193 inc\SpecialChar ~
12194 \SpecialChar ~
12195 _head 
12196 \newline 
12197 \SpecialChar ~
12198 \SpecialChar ~
12199 \SpecialChar ~
12200 \SpecialChar ~
12201 mov\SpecialChar ~
12202 \SpecialChar ~
12203 dpl,r3 
12204 \newline 
12205 \SpecialChar ~
12206 \SpecialChar ~
12207 \SpecialChar ~
12208 \SpecialChar ~
12209 mov\SpecialChar ~
12210 \SpecialChar ~
12211 dph,#(_buf >> 8) 
12212 \newline 
12213 \SpecialChar ~
12214 \SpecialChar ~
12215 \SpecialChar ~
12216 \SpecialChar ~
12217 mov\SpecialChar ~
12218 \SpecialChar ~
12219 a,r2 
12220 \newline 
12221 \SpecialChar ~
12222 \SpecialChar ~
12223 \SpecialChar ~
12224 \SpecialChar ~
12225 movx @dptr,a 
12226 \newline 
12227 00103$: 
12228 \newline 
12229 \SpecialChar ~
12230 \SpecialChar ~
12231 \SpecialChar ~
12232 \SpecialChar ~
12233 ret
12234 \newline 
12235 \SpecialChar ~
12236 \SpecialChar ~
12237 \SpecialChar ~
12238 \SpecialChar ~
12239 _endasm
12240 \begin_inset LatexCommand \index{\_endasm}
12241
12242 \end_inset 
12243
12244
12245 \begin_inset LatexCommand \index{\_\_endasm}
12246
12247 \end_inset 
12248
12249 ;
12250 \newline 
12251
12252 \layout Standard
12253
12254 The new file buffer.c should compile with only one warning about the unreferenced
12255  function argument 'c'.
12256  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
12257  (1) and finally have:
12258 \layout Verse
12259
12260
12261 \family typewriter 
12262 \size footnotesize 
12263 unsigned char far at 0x7f00 buf[0x100];
12264 \newline 
12265 unsigned char head,tail;
12266 \newline 
12267 #define USE_ASSEMBLY (1)
12268 \newline 
12269
12270 \newline 
12271 #if !USE_ASSEMBLY
12272 \newline 
12273
12274 \newline 
12275 void to_buffer( unsigned char c )
12276 \newline 
12277 {
12278 \newline 
12279 \SpecialChar ~
12280 \SpecialChar ~
12281 \SpecialChar ~
12282 \SpecialChar ~
12283 if( head != tail-1 )
12284 \newline 
12285 \SpecialChar ~
12286 \SpecialChar ~
12287 \SpecialChar ~
12288 \SpecialChar ~
12289 \SpecialChar ~
12290 \SpecialChar ~
12291 \SpecialChar ~
12292 \SpecialChar ~
12293 buf[ head++ ] = c;
12294 \newline 
12295 }
12296 \newline 
12297
12298 \newline 
12299 #else
12300 \newline 
12301
12302 \newline 
12303 void to_buffer( unsigned char c )
12304 \newline 
12305 {
12306 \newline 
12307 \SpecialChar ~
12308 \SpecialChar ~
12309 \SpecialChar ~
12310 \SpecialChar ~
12311 c; // to avoid warning: unreferenced function argument
12312 \newline 
12313 \SpecialChar ~
12314 \SpecialChar ~
12315 \SpecialChar ~
12316 \SpecialChar ~
12317 _asm
12318 \begin_inset LatexCommand \index{\_asm}
12319
12320 \end_inset 
12321
12322
12323 \begin_inset LatexCommand \index{\_\_asm}
12324
12325 \end_inset 
12326
12327
12328 \newline 
12329 \SpecialChar ~
12330 \SpecialChar ~
12331 \SpecialChar ~
12332 \SpecialChar ~
12333 \SpecialChar ~
12334 \SpecialChar ~
12335 \SpecialChar ~
12336 \SpecialChar ~
12337 ; save used registers here.
12338  
12339 \newline 
12340 \SpecialChar ~
12341 \SpecialChar ~
12342 \SpecialChar ~
12343 \SpecialChar ~
12344 \SpecialChar ~
12345 \SpecialChar ~
12346 \SpecialChar ~
12347 \SpecialChar ~
12348 ; If we were still using r2,r3 we would have to push them here.
12349  
12350 \newline 
12351 ; if( head != tail-1 )
12352 \newline 
12353 \SpecialChar ~
12354 \SpecialChar ~
12355 \SpecialChar ~
12356 \SpecialChar ~
12357 \SpecialChar ~
12358 \SpecialChar ~
12359 \SpecialChar ~
12360 \SpecialChar ~
12361 mov\SpecialChar ~
12362  a,_tail
12363 \newline 
12364 \SpecialChar ~
12365 \SpecialChar ~
12366 \SpecialChar ~
12367 \SpecialChar ~
12368 \SpecialChar ~
12369 \SpecialChar ~
12370 \SpecialChar ~
12371 \SpecialChar ~
12372 dec\SpecialChar ~
12373  a
12374 \newline 
12375 \SpecialChar ~
12376 \SpecialChar ~
12377 \SpecialChar ~
12378 \SpecialChar ~
12379 \SpecialChar ~
12380 \SpecialChar ~
12381 \SpecialChar ~
12382 \SpecialChar ~
12383 xrl\SpecialChar ~
12384  a,_head
12385 \newline 
12386 \SpecialChar ~
12387 \SpecialChar ~
12388 \SpecialChar ~
12389 \SpecialChar ~
12390 \SpecialChar ~
12391 \SpecialChar ~
12392 \SpecialChar ~
12393 \SpecialChar ~
12394 ; we could do an ANL a,#0x0f here to use a smaller buffer (see below)
12395 \newline 
12396 \SpecialChar ~
12397 \SpecialChar ~
12398 \SpecialChar ~
12399 \SpecialChar ~
12400 \SpecialChar ~
12401 \SpecialChar ~
12402 \SpecialChar ~
12403 \SpecialChar ~
12404 jz\SpecialChar ~
12405 \SpecialChar ~
12406  t_b_end$
12407 \newline 
12408 \SpecialChar ~
12409 \SpecialChar ~
12410 \SpecialChar ~
12411 \SpecialChar ~
12412 \SpecialChar ~
12413 \SpecialChar ~
12414 \SpecialChar ~
12415 \SpecialChar ~
12416 ;
12417 \newline 
12418 ; buf[ head++ ] = c;
12419 \newline 
12420 \SpecialChar ~
12421 \SpecialChar ~
12422 \SpecialChar ~
12423 \SpecialChar ~
12424 \SpecialChar ~
12425 \SpecialChar ~
12426 \SpecialChar ~
12427 \SpecialChar ~
12428 mov\SpecialChar ~
12429  a,dpl \SpecialChar ~
12430 \SpecialChar ~
12431 \SpecialChar ~
12432 \SpecialChar ~
12433 \SpecialChar ~
12434 \SpecialChar ~
12435 \SpecialChar ~
12436 ; dpl holds lower byte of function argument
12437 \newline 
12438 \SpecialChar ~
12439 \SpecialChar ~
12440 \SpecialChar ~
12441 \SpecialChar ~
12442 \SpecialChar ~
12443 \SpecialChar ~
12444 \SpecialChar ~
12445 \SpecialChar ~
12446 mov\SpecialChar ~
12447  dpl,_head \SpecialChar ~
12448 \SpecialChar ~
12449 \SpecialChar ~
12450 ; buf is 0x100 byte aligned so head can be used directly
12451 \newline 
12452 \SpecialChar ~
12453 \SpecialChar ~
12454 \SpecialChar ~
12455 \SpecialChar ~
12456 \SpecialChar ~
12457 \SpecialChar ~
12458 \SpecialChar ~
12459 \SpecialChar ~
12460 mov\SpecialChar ~
12461  dph,#(_buf>>8)
12462 \newline 
12463 \SpecialChar ~
12464 \SpecialChar ~
12465 \SpecialChar ~
12466 \SpecialChar ~
12467 \SpecialChar ~
12468 \SpecialChar ~
12469 \SpecialChar ~
12470 \SpecialChar ~
12471 movx @dptr,a
12472 \newline 
12473 \SpecialChar ~
12474 \SpecialChar ~
12475 \SpecialChar ~
12476 \SpecialChar ~
12477 \SpecialChar ~
12478 \SpecialChar ~
12479 \SpecialChar ~
12480 \SpecialChar ~
12481 inc \SpecialChar ~
12482 _head
12483 \newline 
12484 \SpecialChar ~
12485 \SpecialChar ~
12486 \SpecialChar ~
12487 \SpecialChar ~
12488 \SpecialChar ~
12489 \SpecialChar ~
12490 \SpecialChar ~
12491 \SpecialChar ~
12492 ; we could do an ANL _head,#0x0f here to use a smaller buffer (see above)
12493 \newline 
12494 t_b_end$:
12495 \newline 
12496 \SpecialChar ~
12497 \SpecialChar ~
12498 \SpecialChar ~
12499 \SpecialChar ~
12500 \SpecialChar ~
12501 \SpecialChar ~
12502 \SpecialChar ~
12503 \SpecialChar ~
12504 ; restore used registers here 
12505 \newline 
12506 \SpecialChar ~
12507 \SpecialChar ~
12508 \SpecialChar ~
12509 \SpecialChar ~
12510 _endasm
12511 \begin_inset LatexCommand \index{\_endasm}
12512
12513 \end_inset 
12514
12515
12516 \begin_inset LatexCommand \index{\_\_endasm}
12517
12518 \end_inset 
12519
12520 ;
12521 \newline 
12522 }
12523 \newline 
12524 #endif
12525 \layout Standard
12526
12527 The inline assembler code can contain any valid code understood by the assembler
12528 , this includes any assembler directives and comment lines
12529 \begin_inset Foot
12530 collapsed false
12531
12532 \layout Standard
12533
12534 The assembler does not like some characters like ':' or ''' in comments.
12535  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
12536 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
12537
12538 \end_inset 
12539
12540
12541 \begin_inset LatexCommand \index{Assembler documentation}
12542
12543 \end_inset 
12544
12545
12546 \end_inset 
12547
12548 .
12549  The compiler does not do any validation of the code within the 
12550 \family typewriter 
12551 _asm
12552 \begin_inset LatexCommand \index{\_asm}
12553
12554 \end_inset 
12555
12556
12557 \begin_inset LatexCommand \index{\_\_asm}
12558
12559 \end_inset 
12560
12561  ...
12562  _endasm
12563 \size footnotesize 
12564
12565 \begin_inset LatexCommand \index{\_endasm}
12566
12567 \end_inset 
12568
12569
12570 \begin_inset LatexCommand \index{\_\_endasm}
12571
12572 \end_inset 
12573
12574
12575 \size default 
12576 ;
12577 \family default 
12578  keyword pair.
12579  Specifically it will not know which registers are used and thus register
12580  pushing/popping
12581 \begin_inset LatexCommand \index{push/pop}
12582
12583 \end_inset 
12584
12585  has to be done manually.
12586  
12587 \layout Standard
12588
12589 It is recommended that each assembly instruction (including labels) be placed
12590  in a separate line (as the example shows).
12591  When the -
12592 \begin_inset ERT
12593 status Collapsed
12594
12595 \layout Standard
12596
12597 \backslash 
12598 /
12599 \end_inset 
12600
12601 -
12602 \emph on 
12603 peep-asm
12604 \begin_inset LatexCommand \index{-\/-peep-asm}
12605
12606 \end_inset 
12607
12608
12609 \emph default 
12610  command line option is used, the inline assembler code will be passed through
12611  the peephole optimizer
12612 \begin_inset LatexCommand \index{Peephole optimizer}
12613
12614 \end_inset 
12615
12616 .
12617  There are only a few (if any) cases where this option makes sense, it might
12618  cause some unexpected changes in the inline assembler code.
12619  Please go through the peephole optimizer rules defined in file 
12620 \emph on 
12621 SDCCpeeph.def
12622 \emph default 
12623  before using this option.
12624 \layout Subsection
12625
12626 Naked Functions
12627 \begin_inset LatexCommand \label{sub:Naked-Functions}
12628
12629 \end_inset 
12630
12631
12632 \begin_inset LatexCommand \index{Naked functions}
12633
12634 \end_inset 
12635
12636
12637 \layout Standard
12638
12639 A special keyword may be associated with a function declaring it as 
12640 \emph on 
12641 _naked
12642 \begin_inset LatexCommand \index{\_naked}
12643
12644 \end_inset 
12645
12646
12647 \begin_inset LatexCommand \index{\_\_naked}
12648
12649 \end_inset 
12650
12651 .
12652  
12653 \emph default 
12654 The 
12655 \emph on 
12656 _naked
12657 \emph default 
12658  function modifier attribute prevents the compiler from generating prologue
12659 \begin_inset LatexCommand \index{function prologue}
12660
12661 \end_inset 
12662
12663  and epilogue
12664 \begin_inset LatexCommand \index{function epilogue}
12665
12666 \end_inset 
12667
12668  code for that function.
12669  This means that the user is entirely responsible for such things as saving
12670  any registers that may need to be preserved, selecting the proper register
12671  bank, generating the 
12672 \emph on 
12673 return
12674 \emph default 
12675  instruction at the end, etc.
12676  Practically, this means that the contents of the function must be written
12677  in inline assembler.
12678  This is particularly useful for interrupt functions, which can have a large
12679  (and often unnecessary) prologue/epilogue.
12680  For example, compare the code generated by these two functions:
12681 \layout Verse
12682
12683
12684 \family typewriter 
12685 volatile
12686 \begin_inset LatexCommand \index{volatile}
12687
12688 \end_inset 
12689
12690  data unsigned char counter;
12691 \newline 
12692
12693 \newline 
12694 void simpleInterrupt(void) interrupt
12695 \begin_inset LatexCommand \index{interrupt}
12696
12697 \end_inset 
12698
12699
12700 \begin_inset LatexCommand \index{\_\_interrupt}
12701
12702 \end_inset 
12703
12704  1
12705 \newline 
12706 {
12707 \newline 
12708 \SpecialChar ~
12709 \SpecialChar ~
12710 \SpecialChar ~
12711 \SpecialChar ~
12712 counter++;
12713 \newline 
12714 }
12715 \newline 
12716
12717 \newline 
12718 void nakedInterrupt(void) interrupt 2 _naked
12719 \newline 
12720 {
12721 \newline 
12722 \SpecialChar ~
12723 \SpecialChar ~
12724 \SpecialChar ~
12725 \SpecialChar ~
12726 _asm
12727 \begin_inset LatexCommand \index{\_asm}
12728
12729 \end_inset 
12730
12731
12732 \begin_inset LatexCommand \index{\_\_asm}
12733
12734 \end_inset 
12735
12736
12737 \newline 
12738 \SpecialChar ~
12739 \SpecialChar ~
12740 \SpecialChar ~
12741 \SpecialChar ~
12742 \SpecialChar ~
12743 \SpecialChar ~
12744 inc\SpecialChar ~
12745 \SpecialChar ~
12746 \SpecialChar ~
12747 \SpecialChar ~
12748 \SpecialChar ~
12749 _counter ; does not change flags, no need to save psw
12750 \newline 
12751 \SpecialChar ~
12752 \SpecialChar ~
12753 \SpecialChar ~
12754 \SpecialChar ~
12755 \SpecialChar ~
12756 \SpecialChar ~
12757 reti\SpecialChar ~
12758 \SpecialChar ~
12759 \SpecialChar ~
12760 \SpecialChar ~
12761 ; MUST explicitly include ret or reti in _naked function.
12762 \newline 
12763 \SpecialChar ~
12764 \SpecialChar ~
12765 \SpecialChar ~
12766 \SpecialChar ~
12767 _endasm
12768 \begin_inset LatexCommand \index{\_endasm}
12769
12770 \end_inset 
12771
12772
12773 \begin_inset LatexCommand \index{\_\_endasm}
12774
12775 \end_inset 
12776
12777 ;
12778 \newline 
12779 }
12780 \layout Standard
12781
12782 For an 8051 target, the generated simpleInterrupt looks like:
12783 \layout Verse
12784
12785
12786 \family typewriter 
12787 _simpleInterrupt:
12788 \newline 
12789 \SpecialChar ~
12790 \SpecialChar ~
12791 \SpecialChar ~
12792 \SpecialChar ~
12793 push\SpecialChar ~
12794 \SpecialChar ~
12795 \SpecialChar ~
12796 \SpecialChar ~
12797 acc
12798 \newline 
12799 \SpecialChar ~
12800 \SpecialChar ~
12801 \SpecialChar ~
12802 \SpecialChar ~
12803 push\SpecialChar ~
12804 \SpecialChar ~
12805 \SpecialChar ~
12806 \SpecialChar ~
12807 b
12808 \newline 
12809 \SpecialChar ~
12810 \SpecialChar ~
12811 \SpecialChar ~
12812 \SpecialChar ~
12813 push\SpecialChar ~
12814 \SpecialChar ~
12815 \SpecialChar ~
12816 \SpecialChar ~
12817 dpl
12818 \newline 
12819 \SpecialChar ~
12820 \SpecialChar ~
12821 \SpecialChar ~
12822 \SpecialChar ~
12823 push\SpecialChar ~
12824 \SpecialChar ~
12825 \SpecialChar ~
12826 \SpecialChar ~
12827 dph
12828 \newline 
12829 \SpecialChar ~
12830 \SpecialChar ~
12831 \SpecialChar ~
12832 \SpecialChar ~
12833 push\SpecialChar ~
12834 \SpecialChar ~
12835 \SpecialChar ~
12836 \SpecialChar ~
12837 psw
12838 \newline 
12839 \SpecialChar ~
12840 \SpecialChar ~
12841 \SpecialChar ~
12842 \SpecialChar ~
12843 mov\SpecialChar ~
12844 \SpecialChar ~
12845 \SpecialChar ~
12846 \SpecialChar ~
12847 \SpecialChar ~
12848 psw,#0x00
12849 \newline 
12850 \SpecialChar ~
12851 \SpecialChar ~
12852 \SpecialChar ~
12853 \SpecialChar ~
12854 inc\SpecialChar ~
12855 \SpecialChar ~
12856 \SpecialChar ~
12857 \SpecialChar ~
12858 \SpecialChar ~
12859 _counter
12860 \newline 
12861 \SpecialChar ~
12862 \SpecialChar ~
12863 \SpecialChar ~
12864 \SpecialChar ~
12865 pop\SpecialChar ~
12866 \SpecialChar ~
12867 \SpecialChar ~
12868 \SpecialChar ~
12869 \SpecialChar ~
12870 psw
12871 \newline 
12872 \SpecialChar ~
12873 \SpecialChar ~
12874 \SpecialChar ~
12875 \SpecialChar ~
12876 pop\SpecialChar ~
12877 \SpecialChar ~
12878 \SpecialChar ~
12879 \SpecialChar ~
12880 \SpecialChar ~
12881 dph
12882 \newline 
12883 \SpecialChar ~
12884 \SpecialChar ~
12885 \SpecialChar ~
12886 \SpecialChar ~
12887 pop\SpecialChar ~
12888 \SpecialChar ~
12889 \SpecialChar ~
12890 \SpecialChar ~
12891 \SpecialChar ~
12892 dpl
12893 \newline 
12894 \SpecialChar ~
12895 \SpecialChar ~
12896 \SpecialChar ~
12897 \SpecialChar ~
12898 pop\SpecialChar ~
12899 \SpecialChar ~
12900 \SpecialChar ~
12901 \SpecialChar ~
12902 \SpecialChar ~
12903 b
12904 \newline 
12905 \SpecialChar ~
12906 \SpecialChar ~
12907 \SpecialChar ~
12908 \SpecialChar ~
12909 pop\SpecialChar ~
12910 \SpecialChar ~
12911 \SpecialChar ~
12912 \SpecialChar ~
12913 \SpecialChar ~
12914 acc
12915 \newline 
12916 \SpecialChar ~
12917 \SpecialChar ~
12918 \SpecialChar ~
12919 \SpecialChar ~
12920 reti
12921 \layout Standard
12922
12923 whereas nakedInterrupt looks like:
12924 \layout Verse
12925
12926
12927 \family typewriter 
12928 _nakedInterrupt:
12929 \newline 
12930 \SpecialChar ~
12931 \SpecialChar ~
12932 \SpecialChar ~
12933 \SpecialChar ~
12934 inc\SpecialChar ~
12935 \SpecialChar ~
12936 \SpecialChar ~
12937 \SpecialChar ~
12938 _counter ; does not change flags, no need to save psw
12939 \newline 
12940 \SpecialChar ~
12941 \SpecialChar ~
12942 \SpecialChar ~
12943 \SpecialChar ~
12944 reti\SpecialChar ~
12945 \SpecialChar ~
12946 \SpecialChar ~
12947 \SpecialChar ~
12948 \SpecialChar ~
12949 \SpecialChar ~
12950 \SpecialChar ~
12951 \SpecialChar ~
12952 \SpecialChar ~
12953 \SpecialChar ~
12954 \SpecialChar ~
12955 \SpecialChar ~
12956 ; MUST explicitly include ret or reti in _naked function
12957 \layout Standard
12958
12959 The related directive #pragma exclude
12960 \begin_inset LatexCommand \index{\#pragma exclude}
12961
12962 \end_inset 
12963
12964  allows a more fine grained control over pushing & popping
12965 \begin_inset LatexCommand \index{push/pop}
12966
12967 \end_inset 
12968
12969  the registers.
12970 \layout Standard
12971
12972 While there is nothing preventing you from writing C code inside a 
12973 \family typewriter 
12974 _naked
12975 \family default 
12976  function, there are many ways to shoot yourself in the foot doing this,
12977  and it is recommended that you stick to inline assembler.
12978 \layout Subsection
12979
12980 Use of Labels within Inline Assembler
12981 \layout Standard
12982
12983 SDCC allows the use of in-line assembler with a few restrictions regarding
12984  labels.
12985  In older versions of the compiler all labels defined within inline assembler
12986  code 
12987 \emph on 
12988 had to be
12989 \emph default 
12990  of the form 
12991 \emph on 
12992 nnnnn$
12993 \emph default 
12994  where nnnn is a number less than 100 (which implies a limit of utmost 100
12995  inline assembler labels 
12996 \emph on 
12997 per function
12998 \emph default 
12999 \noun on 
13000 )
13001 \noun default 
13002 .
13003  
13004 \layout Verse
13005
13006
13007 \family typewriter 
13008 _asm
13009 \begin_inset LatexCommand \index{\_asm}
13010
13011 \end_inset 
13012
13013
13014 \begin_inset LatexCommand \index{\_\_asm}
13015
13016 \end_inset 
13017
13018  
13019 \newline 
13020 \SpecialChar ~
13021 \SpecialChar ~
13022 \SpecialChar ~
13023 \SpecialChar ~
13024 mov\SpecialChar ~
13025 \SpecialChar ~
13026 \SpecialChar ~
13027 \SpecialChar ~
13028 \SpecialChar ~
13029 b,#10 
13030 \newline 
13031 00001$: 
13032 \newline 
13033 \SpecialChar ~
13034 \SpecialChar ~
13035 \SpecialChar ~
13036 \SpecialChar ~
13037 djnz\SpecialChar ~
13038 \SpecialChar ~
13039 \SpecialChar ~
13040 \SpecialChar ~
13041 b,00001$ 
13042 \newline 
13043 _endasm
13044 \begin_inset LatexCommand \index{\_endasm}
13045
13046 \end_inset 
13047
13048
13049 \begin_inset LatexCommand \index{\_\_endasm}
13050
13051 \end_inset 
13052
13053  ;
13054 \layout Standard
13055
13056 Inline assembler code cannot reference any C-Labels, however it can reference
13057  labels
13058 \begin_inset LatexCommand \index{Labels}
13059
13060 \end_inset 
13061
13062  defined by the inline assembler, e.g.:
13063 \layout Verse
13064
13065
13066 \family typewriter 
13067 foo() { 
13068 \newline 
13069 \SpecialChar ~
13070 \SpecialChar ~
13071 \SpecialChar ~
13072 \SpecialChar ~
13073 /* some c code */ 
13074 \newline 
13075 \SpecialChar ~
13076 \SpecialChar ~
13077 \SpecialChar ~
13078 \SpecialChar ~
13079 _asm 
13080 \newline 
13081 \SpecialChar ~
13082 \SpecialChar ~
13083 \SpecialChar ~
13084 \SpecialChar ~
13085 \SpecialChar ~
13086 \SpecialChar ~
13087 ; some assembler code 
13088 \newline 
13089 \SpecialChar ~
13090 \SpecialChar ~
13091 \SpecialChar ~
13092 \SpecialChar ~
13093 \SpecialChar ~
13094 \SpecialChar ~
13095 ljmp $0003 
13096 \newline 
13097 \SpecialChar ~
13098 \SpecialChar ~
13099 \SpecialChar ~
13100 \SpecialChar ~
13101 _endasm; 
13102 \newline 
13103 \SpecialChar ~
13104 \SpecialChar ~
13105 \SpecialChar ~
13106 \SpecialChar ~
13107 /* some more c code */ 
13108 \newline 
13109 clabel:\SpecialChar ~
13110 \SpecialChar ~
13111 /* inline assembler cannot reference this label */ 
13112 \newline 
13113 \SpecialChar ~
13114 \SpecialChar ~
13115 \SpecialChar ~
13116 \SpecialChar ~
13117 _asm
13118 \newline 
13119 \SpecialChar ~
13120 \SpecialChar ~
13121 \SpecialChar ~
13122 \SpecialChar ~
13123 $0003: ;label (can be referenced by inline assembler only) 
13124 \newline 
13125 \SpecialChar ~
13126 \SpecialChar ~
13127 \SpecialChar ~
13128 \SpecialChar ~
13129 _endasm
13130 \begin_inset LatexCommand \index{\_endasm}
13131
13132 \end_inset 
13133
13134
13135 \begin_inset LatexCommand \index{\_\_endasm}
13136
13137 \end_inset 
13138
13139  ; 
13140 \newline 
13141 \SpecialChar ~
13142 \SpecialChar ~
13143 \SpecialChar ~
13144 \SpecialChar ~
13145 /* some more c code */
13146 \newline 
13147 }
13148 \layout Standard
13149
13150 In other words inline assembly code can access labels defined in inline
13151  assembly within the scope of the function.
13152  The same goes the other way, i.e.
13153  labels defines in inline assembly can not be accessed by C statements.
13154 \layout Section
13155
13156 Interfacing with Assembler Code
13157 \begin_inset LatexCommand \index{Assembler routines}
13158
13159 \end_inset 
13160
13161
13162 \layout Subsection
13163
13164 Global Registers used for Parameter Passing
13165 \begin_inset LatexCommand \index{Parameter passing}
13166
13167 \end_inset 
13168
13169
13170 \layout Standard
13171
13172 The compiler always uses the global registers 
13173 \emph on 
13174 DPL, DPH
13175 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
13176
13177 \end_inset 
13178
13179
13180 \begin_inset LatexCommand \index{DPTR}
13181
13182 \end_inset 
13183
13184 , B
13185 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
13186
13187 \end_inset 
13188
13189  
13190 \emph default 
13191 and
13192 \emph on 
13193  ACC
13194 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
13195
13196 \end_inset 
13197
13198
13199 \emph default 
13200  to pass the first parameter to a routine.
13201  The second parameter onwards is either allocated on the stack (for reentrant
13202  routines or if -
13203 \begin_inset ERT
13204 status Collapsed
13205
13206 \layout Standard
13207
13208 \backslash 
13209 /
13210 \end_inset 
13211
13212 -stack-auto is used) or in data / xdata memory (depending on the memory
13213  model).
13214  
13215 \layout Subsection
13216
13217 Assembler Routine (non-reentrant)
13218 \layout Standard
13219
13220 In the following example
13221 \begin_inset LatexCommand \index{reentrant}
13222
13223 \end_inset 
13224
13225
13226 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
13227
13228 \end_inset 
13229
13230  the function c_func calls an assembler routine asm_func, which takes two
13231  parameters
13232 \begin_inset LatexCommand \index{function parameter}
13233
13234 \end_inset 
13235
13236 .
13237 \layout Verse
13238
13239
13240 \family typewriter 
13241 extern int asm_func(unsigned char, unsigned char);
13242 \newline 
13243
13244 \newline 
13245 int c_func (unsigned char i, unsigned char j)
13246 \newline 
13247 {
13248 \newline 
13249 \SpecialChar ~
13250 \SpecialChar ~
13251 \SpecialChar ~
13252 \SpecialChar ~
13253 return asm_func(i,j);
13254 \newline 
13255 }
13256 \newline 
13257
13258 \newline 
13259 int main()
13260 \newline 
13261 {
13262 \newline 
13263 \SpecialChar ~
13264 \SpecialChar ~
13265 \SpecialChar ~
13266 \SpecialChar ~
13267 return c_func(10,9);
13268 \newline 
13269 }
13270 \layout Standard
13271
13272 The corresponding assembler function is:
13273 \layout Verse
13274
13275
13276 \family typewriter 
13277 .globl _asm_func_PARM_2 
13278 \newline 
13279 \SpecialChar ~
13280 \SpecialChar ~
13281 \SpecialChar ~
13282 \SpecialChar ~
13283 \SpecialChar ~
13284 \SpecialChar ~
13285 \SpecialChar ~
13286 \SpecialChar ~
13287 .globl _asm_func 
13288 \newline 
13289 \SpecialChar ~
13290 \SpecialChar ~
13291 \SpecialChar ~
13292 \SpecialChar ~
13293 \SpecialChar ~
13294 \SpecialChar ~
13295 \SpecialChar ~
13296 \SpecialChar ~
13297 .area OSEG 
13298 \newline 
13299 _asm_func_PARM_2:
13300 \newline 
13301 \SpecialChar ~
13302 \SpecialChar ~
13303 \SpecialChar ~
13304 \SpecialChar ~
13305 \SpecialChar ~
13306 \SpecialChar ~
13307 \SpecialChar ~
13308 \SpecialChar ~
13309 .ds    1 
13310 \newline 
13311 \SpecialChar ~
13312 \SpecialChar ~
13313 \SpecialChar ~
13314 \SpecialChar ~
13315 \SpecialChar ~
13316 \SpecialChar ~
13317 \SpecialChar ~
13318 \SpecialChar ~
13319 .area CSEG 
13320 \newline 
13321 _asm_func: 
13322 \newline 
13323 \SpecialChar ~
13324 \SpecialChar ~
13325 \SpecialChar ~
13326 \SpecialChar ~
13327 \SpecialChar ~
13328 \SpecialChar ~
13329 \SpecialChar ~
13330 \SpecialChar ~
13331 mov\SpecialChar ~
13332 \SpecialChar ~
13333 \SpecialChar ~
13334 \SpecialChar ~
13335 a,dpl 
13336 \newline 
13337 \SpecialChar ~
13338 \SpecialChar ~
13339 \SpecialChar ~
13340 \SpecialChar ~
13341 \SpecialChar ~
13342 \SpecialChar ~
13343 \SpecialChar ~
13344 \SpecialChar ~
13345 add\SpecialChar ~
13346 \SpecialChar ~
13347 \SpecialChar ~
13348 \SpecialChar ~
13349 a,_asm_func_PARM_2 
13350 \newline 
13351 \SpecialChar ~
13352 \SpecialChar ~
13353 \SpecialChar ~
13354 \SpecialChar ~
13355 \SpecialChar ~
13356 \SpecialChar ~
13357 \SpecialChar ~
13358 \SpecialChar ~
13359 mov\SpecialChar ~
13360 \SpecialChar ~
13361 \SpecialChar ~
13362 \SpecialChar ~
13363 dpl,a 
13364 \newline 
13365 \SpecialChar ~
13366 \SpecialChar ~
13367 \SpecialChar ~
13368 \SpecialChar ~
13369 \SpecialChar ~
13370 \SpecialChar ~
13371 \SpecialChar ~
13372 \SpecialChar ~
13373 mov\SpecialChar ~
13374 \SpecialChar ~
13375 \SpecialChar ~
13376 \SpecialChar ~
13377 dph
13378 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
13379
13380 \end_inset 
13381
13382 ,#0x00 
13383 \newline 
13384 \SpecialChar ~
13385 \SpecialChar ~
13386 \SpecialChar ~
13387 \SpecialChar ~
13388 \SpecialChar ~
13389 \SpecialChar ~
13390 \SpecialChar ~
13391 \SpecialChar ~
13392 ret
13393 \layout Standard
13394
13395 Note here that the return values
13396 \begin_inset LatexCommand \index{return value}
13397
13398 \end_inset 
13399
13400  are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
13401  two byte values.
13402  'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
13403 b' & 'acc' for four byte values.
13404 \layout Standard
13405
13406 The parameter naming convention is _<function_name>_PARM_<n>, where n is
13407  the parameter number starting from 1, and counting from the left.
13408  The first parameter is passed in 
13409 \begin_inset Quotes eld
13410 \end_inset 
13411
13412 dpl
13413 \begin_inset Quotes erd
13414 \end_inset 
13415
13416  for a one byte parameter, 
13417 \begin_inset Quotes eld
13418 \end_inset 
13419
13420 dptr
13421 \begin_inset Quotes erd
13422 \end_inset 
13423
13424  for two bytes, 
13425 \begin_inset Quotes eld
13426 \end_inset 
13427
13428 b,dptr
13429 \begin_inset Quotes erd
13430 \end_inset 
13431
13432  for three bytes and 
13433 \begin_inset Quotes eld
13434 \end_inset 
13435
13436 acc,b,dptr
13437 \begin_inset Quotes erd
13438 \end_inset 
13439
13440  for a four bytes parameter.
13441  The variable name for the second parameter will be _<function_name>_PARM_2.
13442 \newline 
13443
13444 \newline 
13445 Assemble the assembler routine with the following command:
13446 \newline 
13447
13448 \newline 
13449
13450 \family sans 
13451 \series bold 
13452 asx8051 -losg asmfunc.asm
13453 \newline 
13454
13455 \newline 
13456
13457 \family default 
13458 \series default 
13459 Then compile and link the assembler routine to the C source file with the
13460  following command:
13461 \newline 
13462
13463 \newline 
13464
13465 \family sans 
13466 \series bold 
13467 sdcc cfunc.c asmfunc.rel
13468 \layout Subsection
13469
13470 Assembler Routine (reentrant)
13471 \layout Standard
13472
13473 In this case
13474 \begin_inset LatexCommand \index{reentrant}
13475
13476 \end_inset 
13477
13478
13479 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
13480
13481 \end_inset 
13482
13483  the second parameter
13484 \begin_inset LatexCommand \index{function parameter}
13485
13486 \end_inset 
13487
13488  onwards will be passed on the stack, the parameters are pushed from right
13489  to left i.e.
13490  after the call the leftmost parameter will be on the top of the stack.
13491  Here is an example:
13492 \layout Verse
13493
13494
13495 \family typewriter 
13496 extern int asm_func(unsigned char, unsigned char);
13497 \newline 
13498
13499 \newline 
13500 int c_func (unsigned char i, unsigned char j) reentrant 
13501 \newline 
13502
13503 \newline 
13504 \SpecialChar ~
13505 \SpecialChar ~
13506 \SpecialChar ~
13507 \SpecialChar ~
13508 return asm_func(i,j); 
13509 \newline 
13510
13511 \newline 
13512
13513 \newline 
13514 int main() 
13515 \newline 
13516
13517 \newline 
13518 \SpecialChar ~
13519 \SpecialChar ~
13520 \SpecialChar ~
13521 \SpecialChar ~
13522 return c_func(10,9); 
13523 \newline 
13524 }
13525 \layout Standard
13526
13527 The corresponding assembler routine is:
13528 \layout Verse
13529
13530
13531 \family typewriter 
13532 .globl _asm_func 
13533 \newline 
13534 _asm_func: 
13535 \newline 
13536 \SpecialChar ~
13537 \SpecialChar ~
13538 \SpecialChar ~
13539 \SpecialChar ~
13540 push  _bp 
13541 \newline 
13542 \SpecialChar ~
13543 \SpecialChar ~
13544 \SpecialChar ~
13545 \SpecialChar ~
13546 mov _bp,sp 
13547 \newline 
13548 \SpecialChar ~
13549 \SpecialChar ~
13550 \SpecialChar ~
13551 \SpecialChar ~
13552 mov r2,dpl
13553 \newline 
13554 \SpecialChar ~
13555 \SpecialChar ~
13556 \SpecialChar ~
13557 \SpecialChar ~
13558 mov a,_bp 
13559 \newline 
13560 \SpecialChar ~
13561 \SpecialChar ~
13562 \SpecialChar ~
13563 \SpecialChar ~
13564 add a,#0xfd 
13565 \newline 
13566 \SpecialChar ~
13567 \SpecialChar ~
13568 \SpecialChar ~
13569 \SpecialChar ~
13570 mov r0,a 
13571 \newline 
13572 \SpecialChar ~
13573 \SpecialChar ~
13574 \SpecialChar ~
13575 \SpecialChar ~
13576 add  a,#0xfc ;?
13577 \newline 
13578 \SpecialChar ~
13579 \SpecialChar ~
13580 \SpecialChar ~
13581 \SpecialChar ~
13582 mov  r1,a 
13583 \newline 
13584 \SpecialChar ~
13585 \SpecialChar ~
13586 \SpecialChar ~
13587 \SpecialChar ~
13588 mov  a,@r0 
13589 \newline 
13590 \SpecialChar ~
13591 \SpecialChar ~
13592 \SpecialChar ~
13593 \SpecialChar ~
13594 add  a,r2 ;?
13595 \newline 
13596 \SpecialChar ~
13597 \SpecialChar ~
13598 \SpecialChar ~
13599 \SpecialChar ~
13600 mov  dpl,a 
13601 \newline 
13602 \SpecialChar ~
13603 \SpecialChar ~
13604 \SpecialChar ~
13605 \SpecialChar ~
13606 mov  dph,#0x00 
13607 \newline 
13608 \SpecialChar ~
13609 \SpecialChar ~
13610 \SpecialChar ~
13611 \SpecialChar ~
13612 mov  sp,_bp 
13613 \newline 
13614 \SpecialChar ~
13615 \SpecialChar ~
13616 \SpecialChar ~
13617 \SpecialChar ~
13618 pop  _bp 
13619 \newline 
13620 \SpecialChar ~
13621 \SpecialChar ~
13622 \SpecialChar ~
13623 \SpecialChar ~
13624 ret
13625 \layout Standard
13626
13627 The compiling and linking procedure remains the same, however note the extra
13628  entry & exit linkage required for the assembler code, _bp is the stack
13629  frame pointer and is used to compute the offset into the stack for parameters
13630  and local variables.
13631 \layout Section
13632
13633 int (16 bit)
13634 \begin_inset LatexCommand \index{int (16 bit)}
13635
13636 \end_inset 
13637
13638  and long (32 bit)
13639 \begin_inset LatexCommand \index{long (32 bit)}
13640
13641 \end_inset 
13642
13643  Support
13644 \layout Standard
13645
13646 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
13647  multiplication and modulus operations are implemented by support routines.
13648  These support routines are all developed in ANSI-C to facilitate porting
13649  to other MCUs, although some model specific assembler optimizations are
13650  used.
13651  The following files contain the described routines, all of them can be
13652  found in <installdir>/share/sdcc/lib.
13653 \newline 
13654
13655 \layout Standard
13656 \align center 
13657
13658 \begin_inset  Tabular
13659 <lyxtabular version="3" rows="11" 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 \series bold 
13671 Function
13672 \end_inset 
13673 </cell>
13674 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13675 \begin_inset Text
13676
13677 \layout Standard
13678
13679
13680 \series bold 
13681 Description
13682 \end_inset 
13683 </cell>
13684 </row>
13685 <row topline="true">
13686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13687 \begin_inset Text
13688
13689 \layout Standard
13690
13691 _mulint.c 
13692 \end_inset 
13693 </cell>
13694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13695 \begin_inset Text
13696
13697 \layout Standard
13698
13699 16 bit multiplication
13700 \end_inset 
13701 </cell>
13702 </row>
13703 <row topline="true">
13704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13705 \begin_inset Text
13706
13707 \layout Standard
13708
13709 _divsint.c 
13710 \end_inset 
13711 </cell>
13712 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13713 \begin_inset Text
13714
13715 \layout Standard
13716
13717  signed 16 bit division (calls _divuint)
13718 \end_inset 
13719 </cell>
13720 </row>
13721 <row topline="true">
13722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13723 \begin_inset Text
13724
13725 \layout Standard
13726
13727 _divuint.c 
13728 \end_inset 
13729 </cell>
13730 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13731 \begin_inset Text
13732
13733 \layout Standard
13734
13735  unsigned 16 bit division
13736 \end_inset 
13737 </cell>
13738 </row>
13739 <row topline="true">
13740 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13741 \begin_inset Text
13742
13743 \layout Standard
13744
13745 _modsint.c
13746 \end_inset 
13747 </cell>
13748 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13749 \begin_inset Text
13750
13751 \layout Standard
13752
13753 signed 16 bit modulus (calls _moduint)
13754 \end_inset 
13755 </cell>
13756 </row>
13757 <row topline="true">
13758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13759 \begin_inset Text
13760
13761 \layout Standard
13762
13763 _moduint.c
13764 \end_inset 
13765 </cell>
13766 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13767 \begin_inset Text
13768
13769 \layout Standard
13770
13771 unsigned 16 bit modulus
13772 \end_inset 
13773 </cell>
13774 </row>
13775 <row topline="true">
13776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13777 \begin_inset Text
13778
13779 \layout Standard
13780
13781 _mullong.c
13782 \end_inset 
13783 </cell>
13784 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13785 \begin_inset Text
13786
13787 \layout Standard
13788
13789 32 bit multiplication
13790 \end_inset 
13791 </cell>
13792 </row>
13793 <row topline="true">
13794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13795 \begin_inset Text
13796
13797 \layout Standard
13798
13799 _divslong.c 
13800 \end_inset 
13801 </cell>
13802 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13803 \begin_inset Text
13804
13805 \layout Standard
13806
13807  signed 32 division (calls _divulong)
13808 \end_inset 
13809 </cell>
13810 </row>
13811 <row topline="true">
13812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13813 \begin_inset Text
13814
13815 \layout Standard
13816
13817 _divulong.c 
13818 \end_inset 
13819 </cell>
13820 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13821 \begin_inset Text
13822
13823 \layout Standard
13824
13825 unsigned 32 division
13826 \end_inset 
13827 </cell>
13828 </row>
13829 <row topline="true">
13830 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13831 \begin_inset Text
13832
13833 \layout Standard
13834
13835 _modslong.c
13836 \end_inset 
13837 </cell>
13838 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13839 \begin_inset Text
13840
13841 \layout Standard
13842
13843  signed 32 bit modulus (calls _modulong)
13844 \end_inset 
13845 </cell>
13846 </row>
13847 <row topline="true" bottomline="true">
13848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13849 \begin_inset Text
13850
13851 \layout Standard
13852
13853 _modulong.c
13854 \end_inset 
13855 </cell>
13856 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13857 \begin_inset Text
13858
13859 \layout Standard
13860
13861 unsigned 32 bit modulus
13862 \end_inset 
13863 </cell>
13864 </row>
13865 </lyxtabular>
13866
13867 \end_inset 
13868
13869
13870 \newline 
13871
13872 \layout Standard
13873
13874 Since they are compiled as 
13875 \emph on 
13876 non-reentrant
13877 \emph default 
13878
13879 \begin_inset LatexCommand \index{reentrant}
13880
13881 \end_inset 
13882
13883 , interrupt
13884 \begin_inset LatexCommand \index{interrupt}
13885
13886 \end_inset 
13887
13888  service routines should not do any of the above operations.
13889  If this is unavoidable then the above routines will need to be compiled
13890  with the 
13891 \emph on 
13892 -
13893 \begin_inset ERT
13894 status Collapsed
13895
13896 \layout Standard
13897
13898 \backslash 
13899 /
13900 \end_inset 
13901
13902 -stack-auto
13903 \begin_inset LatexCommand \index{-\/-stack-auto}
13904
13905 \end_inset 
13906
13907
13908 \emph default 
13909  option, after which the source program will have to be compiled with 
13910 \emph on 
13911 -
13912 \begin_inset ERT
13913 status Collapsed
13914
13915 \layout Standard
13916
13917 \backslash 
13918 /
13919 \end_inset 
13920
13921 -int-long-reent
13922 \begin_inset LatexCommand \index{-\/-int-long-reent}
13923
13924 \end_inset 
13925
13926
13927 \emph default 
13928  option.
13929  Notice that you don't have to call these routines directly.
13930  The compiler will use them automatically every time an integer operation
13931  is required.
13932 \layout Section
13933
13934 Floating Point Support
13935 \begin_inset LatexCommand \index{Floating point support}
13936
13937 \end_inset 
13938
13939
13940 \layout Standard
13941
13942 SDCC supports IEEE (single precision 4 bytes) floating point numbers.The
13943  floating point support routines are derived from gcc's floatlib.c and consist
13944  of the following routines:
13945 \newline 
13946
13947 \layout Standard
13948 \align center 
13949
13950 \size footnotesize 
13951
13952 \begin_inset  Tabular
13953 <lyxtabular version="3" rows="17" columns="2">
13954 <features>
13955 <column alignment="center" valignment="top" leftline="true" width="0">
13956 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
13957 <row topline="true" bottomline="true">
13958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13959 \begin_inset Text
13960
13961 \layout Standard
13962
13963
13964 \family roman 
13965 \series medium 
13966 \shape up 
13967 \size normal 
13968 \emph off 
13969 \bar no 
13970 \noun off 
13971 \color none
13972 Function 
13973 \end_inset 
13974 </cell>
13975 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13976 \begin_inset Text
13977
13978 \layout Standard
13979
13980 Description
13981 \end_inset 
13982 </cell>
13983 </row>
13984 <row topline="true">
13985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13986 \begin_inset Text
13987
13988 \layout Standard
13989
13990
13991 \family roman 
13992 \series medium 
13993 \shape up 
13994 \size normal 
13995 \emph off 
13996 \bar no 
13997 \noun off 
13998 \color none
13999 _fsadd.c
14000 \end_inset 
14001 </cell>
14002 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14003 \begin_inset Text
14004
14005 \layout Standard
14006
14007
14008 \family roman 
14009 \series medium 
14010 \shape up 
14011 \size normal 
14012 \emph off 
14013 \bar no 
14014 \noun off 
14015 \color none
14016 add floating point numbers
14017 \end_inset 
14018 </cell>
14019 </row>
14020 <row topline="true">
14021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14022 \begin_inset Text
14023
14024 \layout Standard
14025
14026
14027 \family roman 
14028 \series medium 
14029 \shape up 
14030 \size normal 
14031 \emph off 
14032 \bar no 
14033 \noun off 
14034 \color none
14035 _fssub.c 
14036 \end_inset 
14037 </cell>
14038 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14039 \begin_inset Text
14040
14041 \layout Standard
14042
14043
14044 \family roman 
14045 \series medium 
14046 \shape up 
14047 \size normal 
14048 \emph off 
14049 \bar no 
14050 \noun off 
14051 \color none
14052 subtract floating point numbers 
14053 \end_inset 
14054 </cell>
14055 </row>
14056 <row topline="true">
14057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14058 \begin_inset Text
14059
14060 \layout Standard
14061
14062
14063 \family roman 
14064 \series medium 
14065 \shape up 
14066 \size normal 
14067 \emph off 
14068 \bar no 
14069 \noun off 
14070 \color none
14071 _fsdiv.c 
14072 \end_inset 
14073 </cell>
14074 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14075 \begin_inset Text
14076
14077 \layout Standard
14078
14079
14080 \family roman 
14081 \series medium 
14082 \shape up 
14083 \size normal 
14084 \emph off 
14085 \bar no 
14086 \noun off 
14087 \color none
14088 divide floating point numbers 
14089 \end_inset 
14090 </cell>
14091 </row>
14092 <row topline="true">
14093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14094 \begin_inset Text
14095
14096 \layout Standard
14097
14098
14099 \family roman 
14100 \series medium 
14101 \shape up 
14102 \size normal 
14103 \emph off 
14104 \bar no 
14105 \noun off 
14106 \color none
14107 _fsmul.c 
14108 \end_inset 
14109 </cell>
14110 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14111 \begin_inset Text
14112
14113 \layout Standard
14114
14115
14116 \family roman 
14117 \series medium 
14118 \shape up 
14119 \size normal 
14120 \emph off 
14121 \bar no 
14122 \noun off 
14123 \color none
14124 multiply floating point numbers 
14125 \end_inset 
14126 </cell>
14127 </row>
14128 <row topline="true">
14129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14130 \begin_inset Text
14131
14132 \layout Standard
14133
14134
14135 \family roman 
14136 \series medium 
14137 \shape up 
14138 \size normal 
14139 \emph off 
14140 \bar no 
14141 \noun off 
14142 \color none
14143 _fs2uchar.c
14144 \end_inset 
14145 </cell>
14146 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14147 \begin_inset Text
14148
14149 \layout Standard
14150
14151
14152 \family roman 
14153 \series medium 
14154 \shape up 
14155 \size normal 
14156 \emph off 
14157 \bar no 
14158 \noun off 
14159 \color none
14160 convert floating point to unsigned char
14161 \end_inset 
14162 </cell>
14163 </row>
14164 <row topline="true">
14165 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14166 \begin_inset Text
14167
14168 \layout Standard
14169
14170
14171 \family roman 
14172 \series medium 
14173 \shape up 
14174 \size normal 
14175 \emph off 
14176 \bar no 
14177 \noun off 
14178 \color none
14179 _fs2char.c
14180 \end_inset 
14181 </cell>
14182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14183 \begin_inset Text
14184
14185 \layout Standard
14186
14187
14188 \family roman 
14189 \series medium 
14190 \shape up 
14191 \size normal 
14192 \emph off 
14193 \bar no 
14194 \noun off 
14195 \color none
14196 convert floating point to signed char
14197 \end_inset 
14198 </cell>
14199 </row>
14200 <row topline="true">
14201 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14202 \begin_inset Text
14203
14204 \layout Standard
14205
14206
14207 \family roman 
14208 \series medium 
14209 \shape up 
14210 \size normal 
14211 \emph off 
14212 \bar no 
14213 \noun off 
14214 \color none
14215 _fs2uint.c
14216 \end_inset 
14217 </cell>
14218 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14219 \begin_inset Text
14220
14221 \layout Standard
14222
14223
14224 \family roman 
14225 \series medium 
14226 \shape up 
14227 \size normal 
14228 \emph off 
14229 \bar no 
14230 \noun off 
14231 \color none
14232 convert floating point to unsigned int
14233 \end_inset 
14234 </cell>
14235 </row>
14236 <row topline="true">
14237 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14238 \begin_inset Text
14239
14240 \layout Standard
14241
14242
14243 \family roman 
14244 \series medium 
14245 \shape up 
14246 \size normal 
14247 \emph off 
14248 \bar no 
14249 \noun off 
14250 \color none
14251 _fs2int.c
14252 \end_inset 
14253 </cell>
14254 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14255 \begin_inset Text
14256
14257 \layout Standard
14258
14259
14260 \family roman 
14261 \series medium 
14262 \shape up 
14263 \size normal 
14264 \emph off 
14265 \bar no 
14266 \noun off 
14267 \color none
14268 convert floating point to signed int
14269 \end_inset 
14270 </cell>
14271 </row>
14272 <row topline="true">
14273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14274 \begin_inset Text
14275
14276 \layout Standard
14277
14278
14279 \family roman 
14280 \series medium 
14281 \shape up 
14282 \size normal 
14283 \emph off 
14284 \bar no 
14285 \noun off 
14286 \color none
14287 _fs2ulong.
14288 \family default 
14289 \series default 
14290 \shape default 
14291 \size default 
14292 \emph default 
14293 \bar default 
14294 \noun default 
14295 \color default
14296 c
14297 \end_inset 
14298 </cell>
14299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14300 \begin_inset Text
14301
14302 \layout Standard
14303
14304
14305 \family roman 
14306 \series medium 
14307 \shape up 
14308 \size normal 
14309 \emph off 
14310 \bar no 
14311 \noun off 
14312 \color none
14313 convert floating point to unsigned long
14314 \end_inset 
14315 </cell>
14316 </row>
14317 <row topline="true">
14318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14319 \begin_inset Text
14320
14321 \layout Standard
14322
14323
14324 \family roman 
14325 \series medium 
14326 \shape up 
14327 \size normal 
14328 \emph off 
14329 \bar no 
14330 \noun off 
14331 \color none
14332 _fs2long.c
14333 \end_inset 
14334 </cell>
14335 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14336 \begin_inset Text
14337
14338 \layout Standard
14339
14340
14341 \family roman 
14342 \series medium 
14343 \shape up 
14344 \size normal 
14345 \emph off 
14346 \bar no 
14347 \noun off 
14348 \color none
14349 convert floating point to signed long
14350 \end_inset 
14351 </cell>
14352 </row>
14353 <row topline="true">
14354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14355 \begin_inset Text
14356
14357 \layout Standard
14358
14359
14360 \family roman 
14361 \series medium 
14362 \shape up 
14363 \size normal 
14364 \emph off 
14365 \bar no 
14366 \noun off 
14367 \color none
14368 _uchar2fs.c
14369 \end_inset 
14370 </cell>
14371 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14372 \begin_inset Text
14373
14374 \layout Standard
14375
14376
14377 \family roman 
14378 \series medium 
14379 \shape up 
14380 \size normal 
14381 \emph off 
14382 \bar no 
14383 \noun off 
14384 \color none
14385 convert unsigned char to floating point
14386 \end_inset 
14387 </cell>
14388 </row>
14389 <row topline="true">
14390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14391 \begin_inset Text
14392
14393 \layout Standard
14394
14395
14396 \family roman 
14397 \series medium 
14398 \shape up 
14399 \size normal 
14400 \emph off 
14401 \bar no 
14402 \noun off 
14403 \color none
14404 _char2fs.c
14405 \end_inset 
14406 </cell>
14407 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14408 \begin_inset Text
14409
14410 \layout Standard
14411
14412
14413 \family roman 
14414 \series medium 
14415 \shape up 
14416 \size normal 
14417 \emph off 
14418 \bar no 
14419 \noun off 
14420 \color none
14421 convert char to floating point number
14422 \end_inset 
14423 </cell>
14424 </row>
14425 <row topline="true">
14426 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14427 \begin_inset Text
14428
14429 \layout Standard
14430
14431
14432 \family roman 
14433 \series medium 
14434 \shape up 
14435 \size normal 
14436 \emph off 
14437 \bar no 
14438 \noun off 
14439 \color none
14440 _uint2fs.c
14441 \end_inset 
14442 </cell>
14443 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14444 \begin_inset Text
14445
14446 \layout Standard
14447
14448
14449 \family roman 
14450 \series medium 
14451 \shape up 
14452 \size normal 
14453 \emph off 
14454 \bar no 
14455 \noun off 
14456 \color none
14457 convert unsigned int to floating point
14458 \end_inset 
14459 </cell>
14460 </row>
14461 <row topline="true">
14462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14463 \begin_inset Text
14464
14465 \layout Standard
14466
14467
14468 \family roman 
14469 \series medium 
14470 \shape up 
14471 \size normal 
14472 \emph off 
14473 \bar no 
14474 \noun off 
14475 \color none
14476 _int2fs.c
14477 \end_inset 
14478 </cell>
14479 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14480 \begin_inset Text
14481
14482 \layout Standard
14483
14484
14485 \family roman 
14486 \series medium 
14487 \shape up 
14488 \size normal 
14489 \emph off 
14490 \bar no 
14491 \noun off 
14492 \color none
14493 convert int to floating point numbers
14494 \end_inset 
14495 </cell>
14496 </row>
14497 <row topline="true">
14498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14499 \begin_inset Text
14500
14501 \layout Standard
14502
14503
14504 \family roman 
14505 \series medium 
14506 \shape up 
14507 \size normal 
14508 \emph off 
14509 \bar no 
14510 \noun off 
14511 \color none
14512 _ulong2fs.c
14513 \end_inset 
14514 </cell>
14515 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14516 \begin_inset Text
14517
14518 \layout Standard
14519
14520
14521 \family roman 
14522 \series medium 
14523 \shape up 
14524 \size normal 
14525 \emph off 
14526 \bar no 
14527 \noun off 
14528 \color none
14529 convert unsigned long to floating point number
14530 \end_inset 
14531 </cell>
14532 </row>
14533 <row topline="true" bottomline="true">
14534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14535 \begin_inset Text
14536
14537 \layout Standard
14538
14539
14540 \family roman 
14541 \series medium 
14542 \shape up 
14543 \size normal 
14544 \emph off 
14545 \bar no 
14546 \noun off 
14547 \color none
14548 _long2fs.c
14549 \end_inset 
14550 </cell>
14551 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14552 \begin_inset Text
14553
14554 \layout Standard
14555
14556
14557 \family roman 
14558 \series medium 
14559 \shape up 
14560 \size normal 
14561 \emph off 
14562 \bar no 
14563 \noun off 
14564 \color none
14565 convert long to floating point number
14566 \end_inset 
14567 </cell>
14568 </row>
14569 </lyxtabular>
14570
14571 \end_inset 
14572
14573
14574 \newline 
14575
14576 \layout Standard
14577
14578 These support routines are developed in ANSI-C so there is room for space
14579  and speed improvement
14580 \begin_inset Foot
14581 collapsed false
14582
14583 \layout Standard
14584
14585 The floating point routines for the mcs51 are implemented in assembler
14586 \end_inset 
14587
14588 .
14589  Note if all these routines are used simultaneously the data space might
14590  overflow.
14591  For serious floating point usage the large model might be needed.
14592  Also notice that you don't have to call this routines directly.
14593  The compiler will use them automatically every time a floating point operation
14594  is required.
14595 \layout Section
14596
14597 Library Routines
14598 \begin_inset LatexCommand \index{Libraries}
14599
14600 \end_inset 
14601
14602
14603 \layout Standard
14604
14605
14606 \emph on 
14607 <pending: this is messy and incomplete - a little more information is in
14608  sdcc/doc/libdoc.txt
14609 \emph default 
14610  >
14611 \layout Subsection
14612
14613 Compiler support routines (_gptrget, _mulint etc.)
14614 \layout Subsection
14615
14616 Stdclib functions (puts, printf, strcat etc.)
14617 \layout Subsubsection
14618
14619 <stdio.h>
14620 \layout Standard
14621
14622
14623 \begin_inset LatexCommand \index{<stdio.h>}
14624
14625 \end_inset 
14626
14627 As usual on embedded systems you have to provide your own 
14628 \family typewriter 
14629 getchar()
14630 \begin_inset LatexCommand \index{getchar()}
14631
14632 \end_inset 
14633
14634  
14635 \family default 
14636 and 
14637 \family typewriter 
14638 putchar()
14639 \begin_inset LatexCommand \index{putchar()}
14640
14641 \end_inset 
14642
14643
14644 \family default 
14645  routines.
14646  SDCC does not know whether the system connects to a serial line with or
14647  without handshake, LCD, keyboard or other device.
14648  You'll find examples for serial routines f.e.
14649  in sdcc/device/lib.
14650 \layout Standard
14651
14652 The default
14653 \family typewriter 
14654  printf()
14655 \begin_inset LatexCommand \index{printf()}
14656
14657 \end_inset 
14658
14659
14660 \family default 
14661 implementation in
14662 \family typewriter 
14663  printf_large.c
14664 \family default 
14665  does not support float (except on ds390).
14666  To enable this recompile it with the option 
14667 \emph on 
14668 -
14669 \begin_inset ERT
14670 status Collapsed
14671
14672 \layout Standard
14673
14674 \backslash 
14675 /
14676 \end_inset 
14677
14678 DUSE_FLOATS=1
14679 \begin_inset LatexCommand \index{USE\_FLOATS}
14680
14681 \end_inset 
14682
14683
14684 \emph default 
14685  on the command line.
14686  Use
14687 \emph on 
14688 -
14689 \begin_inset ERT
14690 status Collapsed
14691
14692 \layout Standard
14693
14694 \backslash 
14695 /
14696 \end_inset 
14697
14698 -model-large
14699 \begin_inset LatexCommand \index{-\/-model-large}
14700
14701 \end_inset 
14702
14703
14704 \emph default 
14705  for the mcs51 port, since this uses a lot of memory.
14706 \layout Standard
14707
14708 If you're short on memory you might want to use 
14709 \family typewriter 
14710 printf_small()
14711 \begin_inset LatexCommand \index{printf\_small()}
14712
14713 \end_inset 
14714
14715
14716 \family default 
14717  
14718 \emph on 
14719 instead
14720 \emph default 
14721  of
14722 \family typewriter 
14723  printf().
14724
14725 \family default 
14726  For the mcs51 there additionally are assembly versions 
14727 \family typewriter 
14728 printf_tiny()
14729 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
14730
14731 \end_inset 
14732
14733
14734 \family default 
14735  and 
14736 \family typewriter 
14737 printf_fast()
14738 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
14739
14740 \end_inset 
14741
14742  
14743 \family default 
14744 and
14745 \family typewriter 
14746  printf_fast_f()
14747 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
14748
14749 \end_inset 
14750
14751
14752 \family default 
14753  which should fit the requirements of many embedded systems (printf_fast()
14754  can be customized by unsetting #defines to 
14755 \emph on 
14756 not
14757 \emph default 
14758  support long variables and field widths).
14759 \layout Subsection
14760
14761 Math functions (sin, pow, sqrt etc.)
14762 \layout Subsection
14763
14764 Other libraries
14765 \layout Standard
14766
14767 Libraries
14768 \begin_inset LatexCommand \index{Libraries}
14769
14770 \end_inset 
14771
14772  included in SDCC should have a license at least as liberal as the GNU Lesser
14773  General Public License
14774 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
14775
14776 \end_inset 
14777
14778  
14779 \emph on 
14780 LGPL
14781 \emph default 
14782 .
14783 \layout Comment
14784
14785 license statements for the libraries are missing.
14786  sdcc/device/lib/ser_ir.c
14787 \layout Comment
14788
14789 or _decdptr f.e.
14790  come with a GPL (as opposed to LGPL) License - this will not be liberal
14791  enough for many embedded programmers.
14792 \layout Standard
14793
14794 If you have ported some library or want to share experience about some code
14795  which f.e.
14796  falls into any of these categories Busses (I
14797 \begin_inset Formula $^{\textrm{2}}$
14798 \end_inset 
14799
14800 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
14801  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
14802  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
14803 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
14804
14805 \end_inset 
14806
14807 \SpecialChar ~
14808 would certainly like to hear about it.
14809  Programmers coding for embedded systems are not especially famous for being
14810  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
14811 e these references are very valuable.
14812  Let's help to create a climate where information is shared.
14813 \layout Section
14814
14815 Memory Models
14816 \layout Subsection
14817
14818 MCS51 Memory Models
14819 \begin_inset LatexCommand \index{Memory model}
14820
14821 \end_inset 
14822
14823
14824 \begin_inset LatexCommand \index{MCS51 memory model}
14825
14826 \end_inset 
14827
14828
14829 \layout Subsubsection
14830
14831 Small, Medium and Large
14832 \layout Standard
14833
14834 SDCC allows three memory models for MCS51 code, 
14835 \shape slanted 
14836 small, medium
14837 \shape default 
14838  and 
14839 \shape slanted 
14840 large
14841 \shape default 
14842 .
14843  Modules compiled with different memory models should 
14844 \emph on 
14845 never
14846 \emph default 
14847  be combined together or the results would be unpredictable.
14848  The library routines supplied with the compiler are compiled as small,
14849  medium and large.
14850  The compiled library modules are contained in separate directories as small,
14851  medium and large so that you can link to the appropriate set.
14852 \layout Standard
14853
14854 When the medium or large model is used all variables declared without a
14855  storage class will be allocated into the external ram, this includes all
14856  parameters and local variables (for non-reentrant
14857 \begin_inset LatexCommand \index{reentrant}
14858
14859 \end_inset 
14860
14861  functions).
14862  When the small model is used variables without storage class are allocated
14863  in the internal ram.
14864 \layout Standard
14865
14866 Judicious usage of the processor specific storage classes
14867 \begin_inset LatexCommand \index{Storage class}
14868
14869 \end_inset 
14870
14871  and the 'reentrant' function type will yield much more efficient code,
14872  than using the large model.
14873  Several optimizations are disabled when the program is compiled using the
14874  large model, it is therefore recommended that the small model be used unless
14875  absolutely required.
14876 \layout Subsubsection
14877
14878 External Stack
14879 \begin_inset LatexCommand \label{sub:External-Stack}
14880
14881 \end_inset 
14882
14883
14884 \begin_inset LatexCommand \index{stack}
14885
14886 \end_inset 
14887
14888
14889 \begin_inset LatexCommand \index{External stack (mcs51)}
14890
14891 \end_inset 
14892
14893
14894 \layout Standard
14895
14896 The external stack (-
14897 \begin_inset ERT
14898 status Collapsed
14899
14900 \layout Standard
14901
14902 \backslash 
14903 /
14904 \end_inset 
14905
14906 -xstack option
14907 \begin_inset LatexCommand \index{-\/-xstack}
14908
14909 \end_inset 
14910
14911 ) is located in pdata
14912 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
14913
14914 \end_inset 
14915
14916  memory (usually at the start of the external ram segment) and uses all
14917  unused space in pdata (max.
14918  256 bytes).
14919  When -
14920 \begin_inset ERT
14921 status Collapsed
14922
14923 \layout Standard
14924
14925 \backslash 
14926 /
14927 \end_inset 
14928
14929 -xstack option is used to compile the program, the parameters and local
14930  variables
14931 \begin_inset LatexCommand \index{local variables}
14932
14933 \end_inset 
14934
14935  of all reentrant functions are allocated in this area.
14936  This option is provided for programs with large stack space requirements.
14937  When used with the -
14938 \begin_inset ERT
14939 status Collapsed
14940
14941 \layout Standard
14942
14943 \backslash 
14944 /
14945 \end_inset 
14946
14947 -stack-auto
14948 \begin_inset LatexCommand \index{-\/-stack-auto}
14949
14950 \end_inset 
14951
14952  option, all parameters and local variables are allocated on the external
14953  stack (note: support libraries will need to be recompiled with the same
14954  options.
14955  There is a predefined target in the library makefile).
14956 \layout Standard
14957
14958 The compiler outputs the higher order address byte of the external ram segment
14959  into port P2
14960 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
14961
14962 \end_inset 
14963
14964  (see also section 
14965 \begin_inset LatexCommand \ref{sub:MCS51-variants}
14966
14967 \end_inset 
14968
14969 ), therefore when using the External Stack option, this port 
14970 \emph on 
14971 may not
14972 \emph default 
14973  be used by the application program.
14974 \layout Subsection
14975
14976 DS390 Memory Model
14977 \begin_inset LatexCommand \index{Memory model}
14978
14979 \end_inset 
14980
14981
14982 \begin_inset LatexCommand \index{DS390 memory model}
14983
14984 \end_inset 
14985
14986
14987 \layout Standard
14988
14989 The only model supported is Flat 24
14990 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
14991
14992 \end_inset 
14993
14994 .
14995  This generates code for the 24 bit contiguous addressing mode of the Dallas
14996  DS80C390 part.
14997  In this mode, up to four meg of external RAM or code space can be directly
14998  addressed.
14999  See the data sheets at www.dalsemi.com for further information on this part.
15000 \newline 
15001
15002 \newline 
15003 Note that the compiler does not generate any code to place the processor
15004  into 24 bitmode (although 
15005 \emph on 
15006 tinibios
15007 \emph default 
15008  in the ds390 libraries will do that for you).
15009  If you don't use 
15010 \emph on 
15011 tinibios
15012 \emph default 
15013
15014 \begin_inset LatexCommand \index{Tinibios (DS390)}
15015
15016 \end_inset 
15017
15018 , the boot loader or similar code must ensure that the processor is in 24
15019  bit contiguous addressing mode before calling the SDCC startup code.
15020 \newline 
15021
15022 \newline 
15023 Like the 
15024 \emph on 
15025 -
15026 \begin_inset ERT
15027 status Collapsed
15028
15029 \layout Standard
15030
15031 \backslash 
15032 /
15033 \end_inset 
15034
15035 -model-large
15036 \emph default 
15037  option, variables will by default be placed into the XDATA segment.
15038  
15039 \newline 
15040
15041 \newline 
15042 Segments may be placed anywhere in the 4 meg address space using the usual
15043  -
15044 \begin_inset ERT
15045 status Collapsed
15046
15047 \layout Standard
15048
15049 \backslash 
15050 /
15051 \end_inset 
15052
15053 -*-loc options.
15054  Note that if any segments are located above 64K, the -r flag must be passed
15055  to the linker to generate the proper segment relocations, and the Intel
15056  HEX output format must be used.
15057  The -r flag can be passed to the linker by using the option 
15058 \emph on 
15059 -Wl-r
15060 \emph default 
15061  on the SDCC command line.
15062  However, currently the linker can not handle code segments > 64k.
15063 \layout Section
15064
15065 Pragmas
15066 \begin_inset LatexCommand \index{Pragmas}
15067
15068 \end_inset 
15069
15070
15071 \layout Standard
15072
15073 SDCC supports the following #pragma directives:
15074 \layout Itemize
15075
15076 save
15077 \begin_inset LatexCommand \index{\#pragma save}
15078
15079 \end_inset 
15080
15081  - this will save all current options to the save/restore stack.
15082  See #pragma\SpecialChar ~
15083 restore.
15084 \layout Itemize
15085
15086 restore
15087 \begin_inset LatexCommand \index{\#pragma restore}
15088
15089 \end_inset 
15090
15091  - will restore saved options from the last save.
15092  saves & restores can be nested.
15093  SDCC uses a save/restore stack: save pushes current options to the stack,
15094  restore pulls current options from the stack.
15095  See #pragma\SpecialChar ~
15096 save.
15097 \newline 
15098
15099 \layout Itemize
15100
15101 callee_saves
15102 \begin_inset LatexCommand \index{\#pragma callee\_saves}
15103
15104 \end_inset 
15105
15106
15107 \begin_inset LatexCommand \index{function prologue}
15108
15109 \end_inset 
15110
15111  function1[,function2[,function3...]] - The compiler by default uses a caller
15112  saves convention for register saving across function calls, however this
15113  can cause unnecessary register pushing & popping
15114 \begin_inset LatexCommand \index{push/pop}
15115
15116 \end_inset 
15117
15118  when calling small functions from larger functions.
15119  This option can be used to switch off the register saving convention for
15120  the function names specified.
15121  The compiler will not save registers when calling these functions, extra
15122  code need to be manually inserted at the entry & exit for these functions
15123  to save & restore the registers used by these functions, this can SUBSTANTIALLY
15124  reduce code & improve run time performance of the generated code.
15125  In the future the compiler (with inter procedural analysis) may be able
15126  to determine the appropriate scheme to use for each function call.
15127  If -
15128 \begin_inset ERT
15129 status Collapsed
15130
15131 \layout Standard
15132
15133 \backslash 
15134 /
15135 \end_inset 
15136
15137 -callee-saves command line option is used, the function names specified
15138  in #pragma\SpecialChar ~
15139 callee_saves
15140 \begin_inset LatexCommand \index{\#pragma callee\_saves}
15141
15142 \end_inset 
15143
15144  is appended to the list of functions specified in the command line.
15145 \layout Itemize
15146
15147 exclude
15148 \begin_inset LatexCommand \index{\#pragma exclude}
15149
15150 \end_inset 
15151
15152  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
15153  of pairs of push/pop
15154 \begin_inset LatexCommand \index{push/pop}
15155
15156 \end_inset 
15157
15158  instructions in 
15159 \emph on 
15160 I
15161 \emph default 
15162 nterrupt
15163 \begin_inset LatexCommand \index{interrupt}
15164
15165 \end_inset 
15166
15167  
15168 \emph on 
15169 S
15170 \emph default 
15171 ervice 
15172 \emph on 
15173 R
15174 \emph default 
15175 outines.
15176  The directive should be placed immediately before the ISR function definition
15177  and it affects ALL ISR functions following it.
15178  To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
15179 exclude\SpecialChar ~
15180 none
15181 \begin_inset LatexCommand \index{\#pragma exclude}
15182
15183 \end_inset 
15184
15185 .
15186  See also the related keyword _naked
15187 \begin_inset LatexCommand \index{\_naked}
15188
15189 \end_inset 
15190
15191
15192 \begin_inset LatexCommand \index{\_\_naked}
15193
15194 \end_inset 
15195
15196 .
15197 \layout Itemize
15198
15199 less_pedantic
15200 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
15201
15202 \end_inset 
15203
15204  - the compiler will not warn you anymore for obvious mistakes, you'r on
15205  your own now ;-(
15206 \layout Itemize
15207
15208 disable_warning <nnnn>
15209 \begin_inset LatexCommand \index{\#pragma disable\_warning}
15210
15211 \end_inset 
15212
15213  - the compiler will not warn you anymore about warning number <nnnn>.
15214 \layout Itemize
15215
15216 nogcse
15217 \begin_inset LatexCommand \index{\#pragma nogcse}
15218
15219 \end_inset 
15220
15221  - will stop global common subexpression elimination.
15222 \layout Itemize
15223
15224 noinduction
15225 \begin_inset LatexCommand \index{\#pragma noinduction}
15226
15227 \end_inset 
15228
15229  - will stop loop induction optimizations.
15230 \layout Itemize
15231
15232 noinvariant
15233 \begin_inset LatexCommand \index{\#pragma noinvariant}
15234
15235 \end_inset 
15236
15237  - will not do loop invariant optimizations.
15238  For more details see Loop Invariants in section
15239 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
15240
15241 \end_inset 
15242
15243 .
15244 \layout Itemize
15245
15246 noiv
15247 \begin_inset LatexCommand \index{\#pragma noiv}
15248
15249 \end_inset 
15250
15251  - Do not generate interrupt
15252 \begin_inset LatexCommand \index{interrupt}
15253
15254 \end_inset 
15255
15256  vector table entries for all ISR functions defined after the pragma.
15257  This is useful in cases where the interrupt vector table must be defined
15258  manually, or when there is a secondary, manually defined interrupt vector
15259  table (e.g.
15260  for the autovector feature of the Cypress EZ-USB FX2).
15261  More elegantly this can be achieved by obmitting the optional interrupt
15262  number after the interrupt keyword, see section 
15263 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
15264
15265 \end_inset 
15266
15267 \SpecialChar ~
15268 about interrupts.
15269 \layout Itemize
15270
15271 nojtbound
15272 \begin_inset LatexCommand \index{\#pragma nojtbound}
15273
15274 \end_inset 
15275
15276  - will not generate code for boundary value checking, when switch statements
15277  are turned into jump-tables (dangerous).
15278  For more details see section 
15279 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
15280
15281 \end_inset 
15282
15283 .
15284 \layout Itemize
15285
15286 noloopreverse
15287 \begin_inset LatexCommand \index{\#pragma noloopreverse}
15288
15289 \end_inset 
15290
15291  - Will not do loop reversal optimization
15292 \layout Itemize
15293
15294 nooverlay
15295 \begin_inset LatexCommand \index{\#pragma nooverlay}
15296
15297 \end_inset 
15298
15299  - the compiler will not overlay the parameters and local variables of a
15300  function.
15301 \layout Itemize
15302
15303 stackauto
15304 \begin_inset LatexCommand \index{\#pragma stackauto}
15305
15306 \end_inset 
15307
15308 - See option -
15309 \begin_inset ERT
15310 status Collapsed
15311
15312 \layout Standard
15313
15314 \backslash 
15315 /
15316 \end_inset 
15317
15318 -stack-auto
15319 \begin_inset LatexCommand \index{-\/-stack-auto}
15320
15321 \end_inset 
15322
15323  and section 
15324 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
15325
15326 \end_inset 
15327
15328  Parameters and Local Variables.
15329 \layout Itemize
15330
15331 opt_code_speed 
15332 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
15333
15334 \end_inset 
15335
15336 - The compiler will optimize code generation towards fast code, possibly
15337  at the expense of code size.
15338 \layout Itemize
15339
15340 opt_code_size 
15341 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
15342
15343 \end_inset 
15344
15345 - The compiler will optimize code generation towards compact code, possibly
15346  at the expense of code speed.
15347 \layout Itemize
15348
15349 opt_code_balanced 
15350 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
15351
15352 \end_inset 
15353
15354 - The compiler will attempt to generate code that is both compact and fast,
15355  as long as meeting one goal is not a detriment to the other (this is the
15356  default).
15357  
15358 \layout Itemize
15359
15360 std_sdcc89 
15361 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
15362
15363 \end_inset 
15364
15365 - Generally follow the C89 standard, but allow SDCC features that conflict
15366  with the standard (default).
15367 \layout Itemize
15368
15369 std_c89 
15370 \begin_inset LatexCommand \index{\#pragma std\_c89}
15371
15372 \end_inset 
15373
15374 - Follow the C89 standard and disable SDCC features that conflict with the
15375  standard.
15376 \layout Itemize
15377
15378 std_sdcc99 
15379 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
15380
15381 \end_inset 
15382
15383 - Generally follow the C99 standard, but allow SDCC features that conflict
15384  with the standard (incomplete support).
15385 \layout Itemize
15386
15387 std_c99 
15388 \begin_inset LatexCommand \index{\#pragma std\_c99}
15389
15390 \end_inset 
15391
15392 - Follow the C99 standard and disable SDCC features that conflict with the
15393  standard (incomplete support).
15394 \layout Itemize
15395
15396 codeseg <name>
15397 \begin_inset LatexCommand \index{\#pragma codeseg}
15398
15399 \end_inset 
15400
15401 - Use this name (max.
15402  8 characters) for the code segment.
15403 \layout Itemize
15404
15405 constseg <name>
15406 \begin_inset LatexCommand \index{\#pragma constseg}
15407
15408 \end_inset 
15409
15410 - Use this name (max.
15411  8 characters) for the const segment.
15412 \layout Standard
15413
15414 SDCPP supports the following #pragma directives:
15415 \layout Itemize
15416
15417 preproc_asm
15418 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
15419
15420 \end_inset 
15421
15422  (+ | -) - switch _asm _endasm block preprocessing on / off.
15423  Default is on.
15424 \layout Standard
15425
15426 The pragma's are intended to be used to turn-on or off certain optimizations
15427  which might cause the compiler to generate extra stack / data space to
15428  store compiler generated temporary variables.
15429  This usually happens in large functions.
15430  Pragma directives should be used as shown in the following example, they
15431  are used to control options & optimizations for a given function; pragmas
15432  should be placed before and/or after a function, placing pragma's inside
15433  a function body could have unpredictable results.
15434 \layout Verse
15435
15436
15437 \family typewriter 
15438 #pragma save
15439 \begin_inset LatexCommand \index{\#pragma save}
15440
15441 \end_inset 
15442
15443  \SpecialChar ~
15444 \SpecialChar ~
15445 \SpecialChar ~
15446 \SpecialChar ~
15447 \SpecialChar ~
15448 \SpecialChar ~
15449 \SpecialChar ~
15450 /* save the current settings */ 
15451 \newline 
15452 #pragma nogcse
15453 \begin_inset LatexCommand \index{\#pragma nogcse}
15454
15455 \end_inset 
15456
15457  \SpecialChar ~
15458 \SpecialChar ~
15459 \SpecialChar ~
15460 \SpecialChar ~
15461 \SpecialChar ~
15462 /* turnoff global subexpression elimination */ 
15463 \newline 
15464 #pragma noinduction
15465 \begin_inset LatexCommand \index{\#pragma noinduction}
15466
15467 \end_inset 
15468
15469  /* turn off induction optimizations */ 
15470 \newline 
15471 int foo () 
15472 \newline 
15473
15474 \newline 
15475 \SpecialChar ~
15476  \SpecialChar ~
15477  ...
15478  
15479 \newline 
15480 \SpecialChar ~
15481  \SpecialChar ~
15482  /* large code */ 
15483 \newline 
15484 \SpecialChar ~
15485  \SpecialChar ~
15486  ...
15487  
15488 \newline 
15489
15490 \newline 
15491 #pragma restore
15492 \begin_inset LatexCommand \index{\#pragma restore}
15493
15494 \end_inset 
15495
15496  /* turn the optimizations back on */
15497 \layout Standard
15498
15499 The compiler will generate a warning message when extra space is allocated.
15500  It is strongly recommended that the save and restore pragma's be used when
15501  changing options for a function.
15502 \layout Section
15503
15504 Defines Created by the Compiler
15505 \layout Standard
15506
15507 The compiler creates the following #defines
15508 \begin_inset LatexCommand \index{\#defines}
15509
15510 \end_inset 
15511
15512
15513 \begin_inset LatexCommand \index{Defines created by the compiler}
15514
15515 \end_inset 
15516
15517 :
15518 \newline 
15519
15520 \layout Standard
15521
15522
15523 \begin_inset  Tabular
15524 <lyxtabular version="3" rows="11" columns="2">
15525 <features>
15526 <column alignment="center" valignment="top" leftline="true" width="0">
15527 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15528 <row topline="true" bottomline="true">
15529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15530 \begin_inset Text
15531
15532 \layout Standard
15533
15534
15535 \series bold 
15536 #define
15537 \end_inset 
15538 </cell>
15539 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15540 \begin_inset Text
15541
15542 \layout Standard
15543
15544
15545 \series bold 
15546 Description
15547 \end_inset 
15548 </cell>
15549 </row>
15550 <row topline="true">
15551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15552 \begin_inset Text
15553
15554 \layout Standard
15555
15556 SDCC
15557 \begin_inset LatexCommand \index{SDCC}
15558
15559 \end_inset 
15560
15561  
15562 \end_inset 
15563 </cell>
15564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15565 \begin_inset Text
15566
15567 \layout Standard
15568
15569 this Symbol is always defined
15570 \end_inset 
15571 </cell>
15572 </row>
15573 <row topline="true">
15574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15575 \begin_inset Text
15576
15577 \layout Standard
15578
15579 SDCC_mcs51
15580 \begin_inset LatexCommand \index{SDCC\_mcs51}
15581
15582 \end_inset 
15583
15584  or SDCC_ds390
15585 \begin_inset LatexCommand \index{SDCC\_ds390}
15586
15587 \end_inset 
15588
15589  or SDCC_z80
15590 \begin_inset LatexCommand \index{SDCC\_z80}
15591
15592 \end_inset 
15593
15594 , etc
15595 \end_inset 
15596 </cell>
15597 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15598 \begin_inset Text
15599
15600 \layout Standard
15601
15602 depending on the model used (e.g.: -mds390
15603 \end_inset 
15604 </cell>
15605 </row>
15606 <row topline="true">
15607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15608 \begin_inset Text
15609
15610 \layout Standard
15611
15612 __mcs51
15613 \begin_inset LatexCommand \index{\_\_mcs51}
15614
15615 \end_inset 
15616
15617 , __ds390
15618 \begin_inset LatexCommand \index{\_\_ds390}
15619
15620 \end_inset 
15621
15622 , __hc08
15623 \begin_inset LatexCommand \index{\_\_hc08}
15624
15625 \end_inset 
15626
15627 , __z80
15628 \begin_inset LatexCommand \index{\_\_z80}
15629
15630 \end_inset 
15631
15632 , etc
15633 \end_inset 
15634 </cell>
15635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15636 \begin_inset Text
15637
15638 \layout Standard
15639
15640 depending on the model used (e.g.
15641  -mz80)
15642 \end_inset 
15643 </cell>
15644 </row>
15645 <row topline="true">
15646 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15647 \begin_inset Text
15648
15649 \layout Standard
15650
15651 SDCC_STACK_AUTO
15652 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
15653
15654 \end_inset 
15655
15656
15657 \end_inset 
15658 </cell>
15659 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15660 \begin_inset Text
15661
15662 \layout Standard
15663
15664 when 
15665 \emph on 
15666 -
15667 \begin_inset ERT
15668 status Collapsed
15669
15670 \layout Standard
15671
15672 \backslash 
15673 /
15674 \end_inset 
15675
15676 -stack-auto
15677 \emph default 
15678  option is used
15679 \end_inset 
15680 </cell>
15681 </row>
15682 <row topline="true">
15683 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15684 \begin_inset Text
15685
15686 \layout Standard
15687
15688 SDCC_MODEL_SMALL
15689 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
15690
15691 \end_inset 
15692
15693
15694 \end_inset 
15695 </cell>
15696 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15697 \begin_inset Text
15698
15699 \layout Standard
15700
15701 when 
15702 \emph on 
15703 -
15704 \begin_inset ERT
15705 status Collapsed
15706
15707 \layout Standard
15708
15709 \backslash 
15710 /
15711 \end_inset 
15712
15713 -model-small
15714 \emph default 
15715  is used
15716 \end_inset 
15717 </cell>
15718 </row>
15719 <row topline="true">
15720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15721 \begin_inset Text
15722
15723 \layout Standard
15724
15725 SDCC_MODEL_MEDIUM
15726 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
15727
15728 \end_inset 
15729
15730
15731 \end_inset 
15732 </cell>
15733 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15734 \begin_inset Text
15735
15736 \layout Standard
15737
15738 when 
15739 \emph on 
15740 -
15741 \begin_inset ERT
15742 status Collapsed
15743
15744 \layout Standard
15745
15746 \backslash 
15747 /
15748 \end_inset 
15749
15750 -model-medium
15751 \emph default 
15752  is used
15753 \end_inset 
15754 </cell>
15755 </row>
15756 <row topline="true">
15757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15758 \begin_inset Text
15759
15760 \layout Standard
15761
15762 SDCC_MODEL_LARGE
15763 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
15764
15765 \end_inset 
15766
15767
15768 \end_inset 
15769 </cell>
15770 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15771 \begin_inset Text
15772
15773 \layout Standard
15774
15775 when 
15776 \emph on 
15777 -
15778 \begin_inset ERT
15779 status Collapsed
15780
15781 \layout Standard
15782
15783 \backslash 
15784 /
15785 \end_inset 
15786
15787 -model-large
15788 \emph default 
15789  is used
15790 \end_inset 
15791 </cell>
15792 </row>
15793 <row topline="true">
15794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15795 \begin_inset Text
15796
15797 \layout Standard
15798
15799 SDCC_USE_XSTACK
15800 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
15801
15802 \end_inset 
15803
15804
15805 \end_inset 
15806 </cell>
15807 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15808 \begin_inset Text
15809
15810 \layout Standard
15811
15812 when 
15813 \emph on 
15814 -
15815 \begin_inset ERT
15816 status Collapsed
15817
15818 \layout Standard
15819
15820 \backslash 
15821 /
15822 \end_inset 
15823
15824 -xstack
15825 \emph default 
15826  option is used
15827 \end_inset 
15828 </cell>
15829 </row>
15830 <row topline="true">
15831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15832 \begin_inset Text
15833
15834 \layout Standard
15835
15836 SDCC_STACK_TENBIT
15837 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
15838
15839 \end_inset 
15840
15841  
15842 \end_inset 
15843 </cell>
15844 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15845 \begin_inset Text
15846
15847 \layout Standard
15848
15849 when 
15850 \emph on 
15851 -mds390
15852 \emph default 
15853  is used
15854 \end_inset 
15855 </cell>
15856 </row>
15857 <row topline="true" bottomline="true">
15858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15859 \begin_inset Text
15860
15861 \layout Standard
15862
15863 SDCC_MODEL_FLAT24
15864 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
15865
15866 \end_inset 
15867
15868
15869 \end_inset 
15870 </cell>
15871 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15872 \begin_inset Text
15873
15874 \layout Standard
15875
15876 when 
15877 \emph on 
15878 -mds390
15879 \emph default 
15880  is used
15881 \end_inset 
15882 </cell>
15883 </row>
15884 </lyxtabular>
15885
15886 \end_inset 
15887
15888
15889 \layout Chapter
15890
15891 Notes on supported Processors
15892 \layout Section
15893
15894 MCS51 variants
15895 \begin_inset LatexCommand \label{sub:MCS51-variants}
15896
15897 \end_inset 
15898
15899
15900 \begin_inset LatexCommand \index{MCS51 variants}
15901
15902 \end_inset 
15903
15904
15905 \layout Standard
15906
15907 MCS51 processors are available from many vendors and come in many different
15908  flavours.
15909  While they might differ considerably in respect to Special Function Registers
15910  the core MCS51 is usually not modified or is kept compatible.
15911  
15912 \layout Subsection
15913
15914 pdata access by SFR 
15915 \layout Standard
15916
15917 With the upcome of devices with internal xdata and flash memory devices
15918  using port P2
15919 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
15920
15921 \end_inset 
15922
15923  as dedicated I/O port is becoming more popular.
15924  Switching the high byte for pdata
15925 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
15926
15927 \end_inset 
15928
15929  access which was formerly done by port P2 is then achieved by a Special
15930  Function Register
15931 \begin_inset LatexCommand \index{sfr}
15932
15933 \end_inset 
15934
15935 .
15936  In well-established MCS51 tradition the address of this 
15937 \emph on 
15938 sfr
15939 \emph default 
15940  is where the chip designers decided to put it.
15941  Needless to say that they didn't agree on a common name either.
15942  So that the startup code can correctly initialize xdata variables, you
15943  should define an sfr with the name _XPAGE
15944 \family typewriter 
15945
15946 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
15947
15948 \end_inset 
15949
15950
15951 \family default 
15952  at the appropriate location if the default, port P2, is not used for this.
15953  Some examples are:
15954 \layout Verse
15955
15956
15957 \family typewriter 
15958 sfr at 0x92 _XPAGE; /* Cypress EZ-USB family */
15959 \layout Verse
15960
15961
15962 \family typewriter 
15963 sfr at 0xaf _XPAGE; /* some Silicon Labs (Cygnal) chips */
15964 \layout Verse
15965
15966
15967 \family typewriter 
15968 sfr at 0xaa _XPAGE; /* some Silicon Labs (Cygnal) chips */
15969 \layout Standard
15970
15971 For more exotic implementations further customizations may be needed.
15972  See section 
15973 \begin_inset LatexCommand \ref{sub:Startup-Code}
15974
15975 \end_inset 
15976
15977  for other possibilities.
15978 \layout Subsection
15979
15980 Other Features available by SFR
15981 \layout Standard
15982
15983 Some MCS51 variants offer features like Double DPTR
15984 \begin_inset LatexCommand \index{DPTR}
15985
15986 \end_inset 
15987
15988 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
15989  These are currently not used for the MCS51 port.
15990  If you absolutely need them you can fall back to inline assembly or submit
15991  a patch to SDCC.
15992 \layout Section
15993
15994 DS400 port
15995 \layout Standard
15996
15997 The DS80C400 microcontroller has a rich set of peripherals.
15998  In its built-in ROM library it includes functions to access some of the
15999  features, among them is a TCP stack with IP4 and IP6 support.
16000  Library headers (currently in beta status) and other files are provided
16001  at 
16002 \size footnotesize 
16003
16004 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
16005
16006 \end_inset 
16007
16008 .
16009  
16010 \layout Section
16011
16012 The Z80 and gbz80 port
16013 \layout Standard
16014
16015 SDCC can target both the Zilog 
16016 \begin_inset LatexCommand \index{Z80}
16017
16018 \end_inset 
16019
16020  and the Nintendo Gameboy's Z80-like gbz80
16021 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
16022
16023 \end_inset 
16024
16025 .
16026  The Z80 port is passed through the same 
16027 \emph on 
16028 regressions tests
16029 \begin_inset LatexCommand \index{Regression test}
16030
16031 \end_inset 
16032
16033
16034 \emph default 
16035  as the MCS51 and DS390 ports, so floating point support, support for long
16036  variables and bitfield support is fine.
16037  See mailing lists and forums about interrupt routines.
16038 \layout Standard
16039
16040 As always, the code is the authoritative reference - see z80/ralloc.c and
16041  z80/gen.c.
16042  The stack
16043 \begin_inset LatexCommand \index{stack}
16044
16045 \end_inset 
16046
16047  frame is similar to that generated by the IAR Z80 compiler.
16048  IX is used as the base pointer, HL and IY are used as a temporary registers,
16049  and BC and DE are available for holding variables.
16050  Return values
16051 \begin_inset LatexCommand \index{return value}
16052
16053 \end_inset 
16054
16055  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
16056  bytes).
16057  The gbz80 port use the same set of registers for the return values, but
16058  in a different order of significance: E (one byte), DE (two bytes), or
16059  HLDE (four bytes).
16060 \layout Section
16061
16062 The HC08 port
16063 \layout Standard
16064
16065 The port to the Motorola HC08
16066 \begin_inset LatexCommand \index{HC08}
16067
16068 \end_inset 
16069
16070  family has been added in October 2003, and is still undergoing some basic
16071  development.
16072  The code generator is complete, but the register allocation is still quite
16073  unoptimized.
16074  Some of the SDCC's standard C library functions have embedded non-HC08
16075  inline assembly and so are not yet usable.
16076 \newline 
16077
16078 \newline 
16079
16080 \layout Section
16081
16082 The PIC14 port
16083 \layout Standard
16084
16085 The 14bit PIC
16086 \begin_inset LatexCommand \index{PIC14}
16087
16088 \end_inset 
16089
16090  port still requires a major effort from the development community.
16091  However it can work for very simple code.
16092 \layout Subsection
16093
16094 C code and 14bit PIC code page
16095 \begin_inset LatexCommand \index{code page (pic14)}
16096
16097 \end_inset 
16098
16099  and RAM banks
16100 \begin_inset LatexCommand \index{RAM bank (pic14)}
16101
16102 \end_inset 
16103
16104
16105 \layout Standard
16106
16107 The linker organizes allocation for the code page and RAM banks.
16108  It does not have intimate knowledge of the code flow.
16109  It will put all the code section of a single asm file into a single code
16110  page.
16111  In order to make use of multiple code pages, separate asm files must be
16112  used.
16113  The compiler treats all functions of a single C file as being in the same
16114  code page unless it is non static.
16115  The compiler treats all local variables of a single C file as being in
16116  the same RAM bank unless it is an extern.
16117 \newline 
16118
16119 \newline 
16120 To get the best follow these guide lines:
16121 \layout Enumerate
16122
16123 make local functions static, as non static functions require code page selection
16124  overhead.
16125 \layout Enumerate
16126
16127 Make local variables static as extern variables require RAM bank selection
16128  overhead.
16129 \layout Enumerate
16130
16131 For devices that have multiple code pages it is more efficient to use the
16132  same number of files as pages, i.e.
16133  for the 16F877 use 4 separate files and i.e.
16134  for the 16F874 use 2 separate files.
16135  This way the linker can put the code for each file into different code
16136  pages and the compiler can allocate reusable variables more efficiently
16137  and there's less page selection overhead.
16138  And as for any 8 bit micro (especially for PIC 14 as they have a very simple
16139  instruction set) use 'unsigned char' whereever possible instead of 'int'.
16140 \layout Subsection
16141
16142 Creating a device include file 
16143 \layout Standard
16144
16145 For generating a device include file use the support perl script inc2h.pl
16146  kept in directory support/script.
16147 \layout Subsection
16148
16149 Interrupt code
16150 \layout Standard
16151
16152 For the interrupt function, use the keyword 'interrupt'
16153 \begin_inset LatexCommand \index{interrupt}
16154
16155 \end_inset 
16156
16157  with level number of 0 (PIC14 only has 1 interrupt so this number is only
16158  there to avoid a syntax error - it ought to be fixed).
16159  E.g.:
16160 \layout Verse
16161
16162
16163 \family typewriter 
16164 void Intr(void) interrupt 0
16165 \newline 
16166 {
16167 \newline 
16168 \SpecialChar ~
16169 \SpecialChar ~
16170 T0IF = 0; /* Clear timer interrupt */
16171 \newline 
16172 }
16173 \layout Subsection
16174
16175 Linking and assembling
16176 \layout Standard
16177
16178 For assembling you can use either GPUTILS'
16179 \begin_inset LatexCommand \index{gputils (pic tools)}
16180
16181 \end_inset 
16182
16183  gpasm.exe or MPLAB's mpasmwin.exe.
16184  GPUTILS is available from 
16185 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
16186
16187 \end_inset 
16188
16189 .
16190  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
16191  If you use MPLAB and an interrupt function then the linker script file
16192  vectors section will need to be enlarged to link with mplink.
16193 \newline 
16194
16195 \newline 
16196 Here is a 
16197 \family typewriter 
16198 Makefile
16199 \family default 
16200  using GPUTILS:
16201 \layout Verse
16202
16203
16204 \family typewriter 
16205 .c.o:
16206 \newline 
16207 \SpecialChar ~
16208 \SpecialChar ~
16209 \SpecialChar ~
16210 \SpecialChar ~
16211 \SpecialChar ~
16212 \SpecialChar ~
16213 \SpecialChar ~
16214 \SpecialChar ~
16215 sdcc -S -V -mpic14 -p16F877 $< 
16216 \newline 
16217 \SpecialChar ~
16218 \SpecialChar ~
16219 \SpecialChar ~
16220 \SpecialChar ~
16221 \SpecialChar ~
16222 \SpecialChar ~
16223 \SpecialChar ~
16224 \SpecialChar ~
16225 gpasm -c $*.asm
16226 \newline 
16227
16228 \newline 
16229 $(PRJ).hex: $(OBJS) 
16230 \newline 
16231 \SpecialChar ~
16232 \SpecialChar ~
16233 \SpecialChar ~
16234 \SpecialChar ~
16235 \SpecialChar ~
16236 \SpecialChar ~
16237 \SpecialChar ~
16238 \SpecialChar ~
16239 gplink -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
16240 \layout Standard
16241
16242 Here is a 
16243 \family typewriter 
16244 Makefile
16245 \family default 
16246  using MPLAB:
16247 \layout Verse
16248
16249
16250 \family typewriter 
16251 .c.o: 
16252 \newline 
16253 \SpecialChar ~
16254 \SpecialChar ~
16255 \SpecialChar ~
16256 \SpecialChar ~
16257 \SpecialChar ~
16258 \SpecialChar ~
16259 \SpecialChar ~
16260 \SpecialChar ~
16261 sdcc -S -V -mpic14 -p16F877 $< 
16262 \newline 
16263 \SpecialChar ~
16264 \SpecialChar ~
16265 \SpecialChar ~
16266 \SpecialChar ~
16267 \SpecialChar ~
16268 \SpecialChar ~
16269 \SpecialChar ~
16270 \SpecialChar ~
16271 mpasmwin /q /o $*.asm
16272 \newline 
16273
16274 \newline 
16275 $(PRJ).hex: $(OBJS) 
16276 \newline 
16277 \SpecialChar ~
16278 \SpecialChar ~
16279 \SpecialChar ~
16280 \SpecialChar ~
16281 \SpecialChar ~
16282 \SpecialChar ~
16283 \SpecialChar ~
16284 \SpecialChar ~
16285 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
16286 \layout Standard
16287
16288 Please note that indentations within a
16289 \family typewriter 
16290  Makefile
16291 \family default 
16292  have to be done with a tabulator character.
16293 \layout Subsection
16294
16295 Command-line options
16296 \layout Standard
16297
16298 Besides the switches common to all SDCC backends, the PIC14 port accepts
16299  the following options (for an updated list see sdcc -
16300 \begin_inset ERT
16301 status Collapsed
16302
16303 \layout Standard
16304
16305 \backslash 
16306 /
16307 \end_inset 
16308
16309 -help):
16310 \layout List
16311 \labelwidthstring 00.00.0000
16312
16313 -
16314 \begin_inset ERT
16315 status Collapsed
16316
16317 \layout Standard
16318
16319 \backslash 
16320 /
16321 \end_inset 
16322
16323 -debug-extra emit debug info in assembly output
16324 \layout List
16325 \labelwidthstring 00.00.0000
16326
16327 -
16328 \begin_inset ERT
16329 status Collapsed
16330
16331 \layout Standard
16332
16333 \backslash 
16334 /
16335 \end_inset 
16336
16337 -no-pcode-opt disable (slightly faulty) optimization on pCode
16338 \layout Subsection
16339
16340 The library
16341 \layout Subsubsection
16342
16343 error: missing definition for symbol 
16344 \begin_inset Quotes sld
16345 \end_inset 
16346
16347 __gptrget1
16348 \begin_inset Quotes srd
16349 \end_inset 
16350
16351
16352 \layout Standard
16353
16354 The PIC14 port uses library routines to provide more complex operations
16355  like multiplication, division/modulus and (generic) pointer dereferencing.
16356  In order to add these routines to your project, you must link with PIC14's
16357  
16358 \family typewriter 
16359 libsdcc.lib
16360 \family default 
16361 .
16362  For single source file projects this is done automatically, more complex
16363  projects must add 
16364 \family typewriter 
16365 libsdcc.lib
16366 \family default 
16367  to the linker's arguments.
16368  Make sure you also add an include path for the library (using the -I switch
16369  to the linker)!
16370 \layout Subsubsection
16371
16372 Processor mismatch in file 
16373 \begin_inset Quotes sld
16374 \end_inset 
16375
16376 XXX
16377 \begin_inset Quotes srd
16378 \end_inset 
16379
16380 .
16381 \layout Standard
16382
16383 This warning can usually be ignored due to the very good compatibility amongst
16384  14 bit PIC devices.
16385 \layout Standard
16386
16387 You might also consider recompiling the library for your specific device
16388  by changing the ARCH=p16f877 (default target) entry in 
16389 \family typewriter 
16390 device/lib/pic/Makefile.in
16391 \family default 
16392  and 
16393 \family typewriter 
16394 device/lib/pic/Makefile
16395 \family default 
16396  to reflect your device.
16397  This might even improve performance for smaller devices as unneccesary
16398  BANKSELs migth be removed.
16399 \layout Subsection
16400
16401 Known bugs
16402 \layout Subsubsection
16403
16404 initialized data
16405 \layout Standard
16406
16407 Currently, data can only be initialized if it resides in the source file
16408  together with 
16409 \emph on 
16410 main()
16411 \emph default 
16412 .
16413  Data in other source files will silently 
16414 \series bold 
16415 not
16416 \series default 
16417  be initialized.
16418 \layout Section
16419
16420 The PIC16
16421 \begin_inset LatexCommand \index{PIC16}
16422
16423 \end_inset 
16424
16425  port
16426 \layout Standard
16427
16428 The PIC16
16429 \begin_inset LatexCommand \index{PIC16}
16430
16431 \end_inset 
16432
16433  port is the portion of SDCC that is responsible to produce code for the
16434  Microchip
16435 \begin_inset LatexCommand \index{Microchip}
16436
16437 \end_inset 
16438
16439 (TM) microcontrollers with 16 bit core.
16440  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
16441  Currently supported devices are:
16442 \layout Standard
16443 \align center 
16444
16445 \begin_inset  Tabular
16446 <lyxtabular version="3" rows="4" columns="6">
16447 <features>
16448 <column alignment="center" valignment="top" leftline="true" width="0">
16449 <column alignment="center" valignment="top" leftline="true" width="0">
16450 <column alignment="center" valignment="top" leftline="true" width="0">
16451 <column alignment="center" valignment="top" leftline="true" width="0">
16452 <column alignment="center" valignment="top" leftline="true" width="0">
16453 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
16454 <row topline="true">
16455 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16456 \begin_inset Text
16457
16458 \layout Standard
16459
16460 18F242
16461 \end_inset 
16462 </cell>
16463 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16464 \begin_inset Text
16465
16466 \layout Standard
16467
16468 18F248
16469 \end_inset 
16470 </cell>
16471 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16472 \begin_inset Text
16473
16474 \layout Standard
16475
16476 18F252
16477 \end_inset 
16478 </cell>
16479 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16480 \begin_inset Text
16481
16482 \layout Standard
16483
16484 18F258
16485 \end_inset 
16486 </cell>
16487 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16488 \begin_inset Text
16489
16490 \layout Standard
16491
16492 18F442
16493 \end_inset 
16494 </cell>
16495 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16496 \begin_inset Text
16497
16498 \layout Standard
16499
16500 18F448
16501 \end_inset 
16502 </cell>
16503 </row>
16504 <row topline="true">
16505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16506 \begin_inset Text
16507
16508 \layout Standard
16509
16510 18F452
16511 \end_inset 
16512 </cell>
16513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16514 \begin_inset Text
16515
16516 \layout Standard
16517
16518 18F458
16519 \end_inset 
16520 </cell>
16521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16522 \begin_inset Text
16523
16524 \layout Standard
16525
16526 18F1220
16527 \end_inset 
16528 </cell>
16529 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16530 \begin_inset Text
16531
16532 \layout Standard
16533
16534 18F2220
16535 \end_inset 
16536 </cell>
16537 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16538 \begin_inset Text
16539
16540 \layout Standard
16541
16542 18F2550
16543 \end_inset 
16544 </cell>
16545 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16546 \begin_inset Text
16547
16548 \layout Standard
16549
16550 18F4331
16551 \end_inset 
16552 </cell>
16553 </row>
16554 <row topline="true">
16555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16556 \begin_inset Text
16557
16558 \layout Standard
16559
16560 18F4455
16561 \end_inset 
16562 </cell>
16563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16564 \begin_inset Text
16565
16566 \layout Standard
16567
16568 18F6520
16569 \end_inset 
16570 </cell>
16571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16572 \begin_inset Text
16573
16574 \layout Standard
16575
16576 18F6620
16577 \end_inset 
16578 </cell>
16579 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16580 \begin_inset Text
16581
16582 \layout Standard
16583
16584 18F6680
16585 \end_inset 
16586 </cell>
16587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16588 \begin_inset Text
16589
16590 \layout Standard
16591
16592 18F6720
16593 \end_inset 
16594 </cell>
16595 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16596 \begin_inset Text
16597
16598 \layout Standard
16599
16600 18F8520
16601 \end_inset 
16602 </cell>
16603 </row>
16604 <row topline="true" bottomline="true">
16605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16606 \begin_inset Text
16607
16608 \layout Standard
16609
16610 18F8620
16611 \end_inset 
16612 </cell>
16613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16614 \begin_inset Text
16615
16616 \layout Standard
16617
16618 18F8680
16619 \end_inset 
16620 </cell>
16621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16622 \begin_inset Text
16623
16624 \layout Standard
16625
16626 18F8720
16627 \end_inset 
16628 </cell>
16629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16630 \begin_inset Text
16631
16632 \layout Standard
16633
16634 \end_inset 
16635 </cell>
16636 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16637 \begin_inset Text
16638
16639 \layout Standard
16640
16641 \end_inset 
16642 </cell>
16643 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16644 \begin_inset Text
16645
16646 \layout Standard
16647
16648 \end_inset 
16649 </cell>
16650 </row>
16651 </lyxtabular>
16652
16653 \end_inset 
16654
16655
16656 \layout Subsection
16657
16658 Global Options
16659 \layout Standard
16660
16661 PIC16 port supports the standard command line arguments as supposed, with
16662  the exception of certain cases that will be mentioned in the following
16663  list:
16664 \layout List
16665 \labelwidthstring 00.00.0000
16666
16667 -
16668 \begin_inset ERT
16669 status Collapsed
16670
16671 \layout Standard
16672
16673 \backslash 
16674 /
16675 \end_inset 
16676
16677 -callee-saves See -
16678 \begin_inset ERT
16679 status Collapsed
16680
16681 \layout Standard
16682
16683 \backslash 
16684 /
16685 \end_inset 
16686
16687 -all-callee-saves
16688 \layout List
16689 \labelwidthstring 00.00.0000
16690
16691 -
16692 \begin_inset ERT
16693 status Collapsed
16694
16695 \layout Standard
16696
16697 \backslash 
16698 /
16699 \end_inset 
16700
16701 -all-callee-saves All function arguments are passed on stack by default.
16702  
16703 \emph on 
16704 There is no need to specify this in the command line.
16705 \layout List
16706 \labelwidthstring 00.00.0000
16707
16708 -
16709 \begin_inset ERT
16710 status Collapsed
16711
16712 \layout Standard
16713
16714 \backslash 
16715 /
16716 \end_inset 
16717
16718 -fommit-frame-pointer Frame pointer will be omitted when the function uses
16719  no local variables.
16720 \layout Subsection
16721
16722 Port Specific Options
16723 \begin_inset LatexCommand \index{Options PIC16}
16724
16725 \end_inset 
16726
16727
16728 \layout Standard
16729
16730 The port specific options appear after the global options in the sdcc --help
16731  output.
16732 \layout Subsubsection
16733
16734 General Options
16735 \layout Standard
16736
16737 General options enable certain port features and optimizations.
16738 \layout List
16739 \labelwidthstring 00.00.0000
16740
16741 -
16742 \begin_inset ERT
16743 status Collapsed
16744
16745 \layout Standard
16746
16747 \backslash 
16748 /
16749 \end_inset 
16750
16751 -stack-model=[model] Used in conjuction with the command above.
16752  Defines the stack model to be used, valid stack models are : 
16753 \begin_deeper 
16754 \layout List
16755 \labelwidthstring 00.00.0000
16756
16757
16758 \emph on 
16759 small
16760 \emph default 
16761  Selects small stack model.
16762  8 bit stack and frame pointers.
16763  Supports 256 bytes stack size.
16764 \layout List
16765 \labelwidthstring 00.00.0000
16766
16767
16768 \emph on 
16769 large
16770 \emph default 
16771  Selects large stack model.
16772  16 bit stack and frame pointers.
16773  Supports 65536 bytes stack size.
16774 \end_deeper 
16775 \layout List
16776 \labelwidthstring 00.00.0000
16777
16778 -
16779 \begin_inset ERT
16780 status Collapsed
16781
16782 \layout Standard
16783
16784 \backslash 
16785 /
16786 \end_inset 
16787
16788 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
16789  unitialized data variables with [kword].
16790  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
16791 \layout List
16792 \labelwidthstring 00.00.0000
16793
16794 -
16795 \begin_inset ERT
16796 status Collapsed
16797
16798 \layout Standard
16799
16800 \backslash 
16801 /
16802 \end_inset 
16803
16804 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
16805  Useful for bootloaders.
16806 \layout List
16807 \labelwidthstring 00.00.0000
16808
16809 -
16810 \begin_inset ERT
16811 status Collapsed
16812
16813 \layout Standard
16814
16815 \backslash 
16816 /
16817 \end_inset 
16818
16819 -asm= sets the full path and name of an external assembler to call.
16820 \layout List
16821 \labelwidthstring 00.00.0000
16822
16823 -
16824 \begin_inset ERT
16825 status Collapsed
16826
16827 \layout Standard
16828
16829 \backslash 
16830 /
16831 \end_inset 
16832
16833 -link= sets the full path and name of an external linker to call.
16834 \layout List
16835 \labelwidthstring 00.00.0000
16836
16837 -
16838 \begin_inset ERT
16839 status Collapsed
16840
16841 \layout Standard
16842
16843 \backslash 
16844 /
16845 \end_inset 
16846
16847 -mplab-comp MPLAB compatibility option.
16848  Currently only suppresses special gpasm directives.
16849 \layout Subsubsection
16850
16851 Optimization Options
16852 \layout List
16853 \labelwidthstring 00.00.0000
16854
16855 -
16856 \begin_inset ERT
16857 status Collapsed
16858
16859 \layout Standard
16860
16861 \backslash 
16862 /
16863 \end_inset 
16864
16865 -optimize-goto Try to use (conditional) BRA instead of GOTO
16866 \layout List
16867 \labelwidthstring 00.00.0000
16868
16869 -
16870 \begin_inset ERT
16871 status Collapsed
16872
16873 \layout Standard
16874
16875 \backslash 
16876 /
16877 \end_inset 
16878
16879 -optimize-cmp Try to optimize some compares.
16880 \layout List
16881 \labelwidthstring 00.00.0000
16882
16883 -
16884 \begin_inset ERT
16885 status Collapsed
16886
16887 \layout Standard
16888
16889 \backslash 
16890 /
16891 \end_inset 
16892
16893 -optimize-df Analyze the dataflow of the generated code and improve it.
16894 \layout List
16895 \labelwidthstring 00.00.0000
16896
16897 -
16898 \begin_inset ERT
16899 status Collapsed
16900
16901 \layout Standard
16902
16903 \backslash 
16904 /
16905 \end_inset 
16906
16907 -obanksel=nn Set optimization level for inserting BANKSELs.
16908 \newline 
16909
16910 \begin_deeper 
16911 \layout List
16912 \labelwidthstring 00.00.0000
16913
16914 0 no optimization
16915 \layout List
16916 \labelwidthstring 00.00.0000
16917
16918 1 checks previous used register and if it is the same then does not emit
16919  BANKSEL, accounts only for labels.
16920 \layout List
16921 \labelwidthstring 00.00.0000
16922
16923 2 tries to check the location of (even different) symbols and removes BANKSELs
16924  if they are in the same bank.
16925  
16926 \newline 
16927
16928 \emph on 
16929 Important: There might be problems if the linker script has data sections
16930  across bank borders!
16931 \end_deeper 
16932 \layout Subsubsection
16933
16934 Linking Options
16935 \layout List
16936 \labelwidthstring 00.00.0000
16937
16938 -
16939 \begin_inset ERT
16940 status Collapsed
16941
16942 \layout Standard
16943
16944 \backslash 
16945 /
16946 \end_inset 
16947
16948 -nodefaultlibs do not link default libraries when linking
16949 \layout List
16950 \labelwidthstring 00.00.0000
16951
16952 -
16953 \begin_inset ERT
16954 status Collapsed
16955
16956 \layout Standard
16957
16958 \backslash 
16959 /
16960 \end_inset 
16961
16962 -no-crt Don't link the default run-time modules
16963 \layout List
16964 \labelwidthstring 00.00.0000
16965
16966 -
16967 \begin_inset ERT
16968 status Collapsed
16969
16970 \layout Standard
16971
16972 \backslash 
16973 /
16974 \end_inset 
16975
16976 -use-crt= Use a custom run-time module instead of the defaults.
16977 \layout Subsubsection
16978
16979 Debugging Options
16980 \layout Standard
16981
16982 Debugging options enable extra debugging information in the output files.
16983 \layout List
16984 \labelwidthstring 00.00.0000
16985
16986 -
16987 \begin_inset ERT
16988 status Collapsed
16989
16990 \layout Standard
16991
16992 \backslash 
16993 /
16994 \end_inset 
16995
16996 -debug-xtra Similar to -
16997 \begin_inset ERT
16998 status Collapsed
16999
17000 \layout Standard
17001
17002 \backslash 
17003 /
17004 \end_inset 
17005
17006 -debug
17007 \begin_inset LatexCommand \index{-\/-debug}
17008
17009 \end_inset 
17010
17011 , but dumps more information.
17012 \layout List
17013 \labelwidthstring 00.00.0000
17014
17015 -
17016 \begin_inset ERT
17017 status Collapsed
17018
17019 \layout Standard
17020
17021 \backslash 
17022 /
17023 \end_inset 
17024
17025 -debug-ralloc Force register allocator to dump <source>.d file with debugging
17026  information.
17027  <source> is the name of the file compiled.
17028 \layout List
17029 \labelwidthstring 00.00.0000
17030
17031 -
17032 \begin_inset ERT
17033 status Collapsed
17034
17035 \layout Standard
17036
17037 \backslash 
17038 /
17039 \end_inset 
17040
17041 -pcode-verbose Enable pcode debugging information in translation.
17042 \layout List
17043 \labelwidthstring 00.00.0000
17044
17045 -
17046 \begin_inset ERT
17047 status Collapsed
17048
17049 \layout Standard
17050
17051 \backslash 
17052 /
17053 \end_inset 
17054
17055 -denable-peeps Force the usage of peepholes.
17056  Use with care.
17057 \layout List
17058 \labelwidthstring 00.00.0000
17059
17060 -
17061 \begin_inset ERT
17062 status Collapsed
17063
17064 \layout Standard
17065
17066 \backslash 
17067 /
17068 \end_inset 
17069
17070 -gstack Trace push/pops for stack pointer overflow
17071 \layout List
17072 \labelwidthstring 00.00.0000
17073
17074 -
17075 \begin_inset ERT
17076 status Collapsed
17077
17078 \layout Standard
17079
17080 \backslash 
17081 /
17082 \end_inset 
17083
17084 -call-tree dump call tree in .calltree file
17085 \layout Subsection
17086
17087 Enviromental Variables
17088 \layout Standard
17089
17090 There is a number of enviromental variables that can be used when running
17091  SDCC to enable certain optimizations or force a specific program behaviour.
17092  these variables are primarily for debugging purposes so they can be enabled/dis
17093 abled at will.
17094 \layout Standard
17095
17096 Currently there is only two such variables available:
17097 \layout List
17098 \labelwidthstring 00.00.0000
17099
17100 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
17101  bitfields is optimized by directly loading FSR0 with the address of the
17102  bitfield structure.
17103  Normally SDCC will cast the bitfield structure to a bitfield pointer and
17104  then load FSR0.
17105  This step saves data ram and code space for functions that perform heavy
17106  use of bitfields.
17107  (ie.
17108  80 bytes of code space are saved when compiling malloc.c with this option).
17109  
17110 \layout List
17111 \labelwidthstring 00.00.0000
17112
17113 NO_REG_OPT do not perform pCode registers optimization.
17114  This should be used for debugging purposes.
17115  In some where bugs in the pcode optimizer are found, users can benefit
17116  from temporarily disabling the optimizer until the bug is fixed.
17117 \layout Subsection
17118
17119 Preprocessor Macros
17120 \layout Standard
17121
17122 PIC16 port defines the following preprocessor macros while translating a
17123  source.
17124 \layout Standard
17125 \align center 
17126
17127 \begin_inset  Tabular
17128 <lyxtabular version="3" rows="6" columns="2">
17129 <features>
17130 <column alignment="center" valignment="top" leftline="true" width="0">
17131 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
17132 <row topline="true" bottomline="true">
17133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17134 \begin_inset Text
17135
17136 \layout Standard
17137
17138 Macro
17139 \end_inset 
17140 </cell>
17141 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17142 \begin_inset Text
17143
17144 \layout Standard
17145
17146 Description
17147 \end_inset 
17148 </cell>
17149 </row>
17150 <row topline="true">
17151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17152 \begin_inset Text
17153
17154 \layout Standard
17155
17156 SDCC_pic16
17157 \end_inset 
17158 </cell>
17159 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17160 \begin_inset Text
17161
17162 \layout Standard
17163
17164 Port identification
17165 \end_inset 
17166 </cell>
17167 </row>
17168 <row topline="true">
17169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17170 \begin_inset Text
17171
17172 \layout Standard
17173
17174 _
17175 \begin_inset ERT
17176 status Collapsed
17177
17178 \layout Standard
17179
17180 \backslash 
17181 /
17182 \end_inset 
17183
17184 _pic16
17185 \end_inset 
17186 </cell>
17187 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17188 \begin_inset Text
17189
17190 \layout Standard
17191
17192 Port identification (same as above)
17193 \end_inset 
17194 </cell>
17195 </row>
17196 <row topline="true">
17197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17198 \begin_inset Text
17199
17200 \layout Standard
17201
17202 pic18fxxxx
17203 \end_inset 
17204 </cell>
17205 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17206 \begin_inset Text
17207
17208 \layout Standard
17209
17210 MCU Identification.
17211  
17212 \emph on 
17213 xxxx
17214 \emph default 
17215  is the microcontrol identification number, i.e.
17216  452, 6620, etc
17217 \end_inset 
17218 </cell>
17219 </row>
17220 <row topline="true">
17221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17222 \begin_inset Text
17223
17224 \layout Standard
17225
17226 _
17227 \begin_inset ERT
17228 status Collapsed
17229
17230 \layout Standard
17231
17232 \backslash 
17233 /
17234 \end_inset 
17235
17236 _18Fxxxx
17237 \end_inset 
17238 </cell>
17239 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17240 \begin_inset Text
17241
17242 \layout Standard
17243
17244 MCU Identification (same as above)
17245 \end_inset 
17246 </cell>
17247 </row>
17248 <row topline="true" bottomline="true">
17249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17250 \begin_inset Text
17251
17252 \layout Standard
17253
17254 STACK_MODEL_nnn
17255 \end_inset 
17256 </cell>
17257 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17258 \begin_inset Text
17259
17260 \layout Standard
17261
17262 nnn = SMALL or LARGE respectively according to the stack model used
17263 \end_inset 
17264 </cell>
17265 </row>
17266 </lyxtabular>
17267
17268 \end_inset 
17269
17270
17271 \layout Standard
17272
17273 In addition the following macros are defined when calling assembler:
17274 \layout Standard
17275 \align center 
17276
17277 \begin_inset  Tabular
17278 <lyxtabular version="3" rows="4" columns="2">
17279 <features>
17280 <column alignment="center" valignment="top" leftline="true" width="0">
17281 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
17282 <row topline="true" bottomline="true">
17283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17284 \begin_inset Text
17285
17286 \layout Standard
17287
17288 Macro
17289 \end_inset 
17290 </cell>
17291 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17292 \begin_inset Text
17293
17294 \layout Standard
17295
17296 Description
17297 \end_inset 
17298 </cell>
17299 </row>
17300 <row topline="true">
17301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17302 \begin_inset Text
17303
17304 \layout Standard
17305
17306 __18Fxxxx
17307 \end_inset 
17308 </cell>
17309 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17310 \begin_inset Text
17311
17312 \layout Standard
17313
17314 MCU Identification.
17315  
17316 \emph on 
17317 xxxx
17318 \emph default 
17319  is the microcontrol identification number, i.e.
17320  452, 6620, etc
17321 \end_inset 
17322 </cell>
17323 </row>
17324 <row topline="true">
17325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17326 \begin_inset Text
17327
17328 \layout Standard
17329
17330 SDCC_MODEL_nnn
17331 \end_inset 
17332 </cell>
17333 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17334 \begin_inset Text
17335
17336 \layout Standard
17337
17338 nnn = SMALL or LARGE respectively according to the memory model used for
17339  SDCC
17340 \end_inset 
17341 </cell>
17342 </row>
17343 <row topline="true" bottomline="true">
17344 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17345 \begin_inset Text
17346
17347 \layout Standard
17348
17349 STACK_MODEL_nnn
17350 \end_inset 
17351 </cell>
17352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17353 \begin_inset Text
17354
17355 \layout Standard
17356
17357 nnn = SMALL or LARGE respectively according to the stack model used
17358 \end_inset 
17359 </cell>
17360 </row>
17361 </lyxtabular>
17362
17363 \end_inset 
17364
17365
17366 \layout Subsection
17367
17368 Directories
17369 \layout Standard
17370
17371 PIC16
17372 \begin_inset LatexCommand \index{PIC16}
17373
17374 \end_inset 
17375
17376  port uses the following directories for searching header files and libraries.
17377 \layout Standard
17378 \align center 
17379
17380 \begin_inset  Tabular
17381 <lyxtabular version="3" rows="3" columns="4">
17382 <features>
17383 <column alignment="center" valignment="top" leftline="true" width="0">
17384 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
17385 <column alignment="center" valignment="top" width="0">
17386 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
17387 <row topline="true" bottomline="true">
17388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17389 \begin_inset Text
17390
17391 \layout Standard
17392
17393 Directory
17394 \end_inset 
17395 </cell>
17396 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17397 \begin_inset Text
17398
17399 \layout Standard
17400
17401 Description
17402 \end_inset 
17403 </cell>
17404 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17405 \begin_inset Text
17406
17407 \layout Standard
17408
17409 Target
17410 \end_inset 
17411 </cell>
17412 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17413 \begin_inset Text
17414
17415 \layout Standard
17416
17417 Command prefix
17418 \end_inset 
17419 </cell>
17420 </row>
17421 <row topline="true">
17422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17423 \begin_inset Text
17424
17425 \layout Standard
17426
17427 PREFIX/sdcc/include/pic16
17428 \end_inset 
17429 </cell>
17430 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17431 \begin_inset Text
17432
17433 \layout Standard
17434
17435 PIC16 specific headers
17436 \end_inset 
17437 </cell>
17438 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17439 \begin_inset Text
17440
17441 \layout Standard
17442
17443 Compiler
17444 \end_inset 
17445 </cell>
17446 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17447 \begin_inset Text
17448
17449 \layout Standard
17450
17451 -I
17452 \end_inset 
17453 </cell>
17454 </row>
17455 <row topline="true" bottomline="true">
17456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17457 \begin_inset Text
17458
17459 \layout Standard
17460
17461 PREFIX/sdcc/lib/pic16
17462 \end_inset 
17463 </cell>
17464 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17465 \begin_inset Text
17466
17467 \layout Standard
17468
17469 PIC16 specific libraries
17470 \end_inset 
17471 </cell>
17472 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17473 \begin_inset Text
17474
17475 \layout Standard
17476
17477 Linker
17478 \end_inset 
17479 </cell>
17480 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17481 \begin_inset Text
17482
17483 \layout Standard
17484
17485 -L
17486 \end_inset 
17487 </cell>
17488 </row>
17489 </lyxtabular>
17490
17491 \end_inset 
17492
17493
17494 \layout Subsection
17495
17496 Pragmas
17497 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
17498
17499 \end_inset 
17500
17501
17502 \layout Standard
17503
17504 PIC16 port currently supports the following pragmas:
17505 \layout List
17506 \labelwidthstring 00.00.0000
17507
17508 stack pragma stack forces the code generator to initialize the stack & frame
17509  pointers at a specific address.
17510  This is an adhoc solution for cases where no STACK directive is available
17511  in the linker script or gplink is not instructed to create a stack section.
17512 \newline 
17513 The stack pragma should be used only once in a project.
17514  Multiple pragmas may result in indeterminate behaviour of the program.
17515 \begin_inset Foot
17516 collapsed false
17517
17518 \layout Standard
17519
17520 The old format (ie.
17521  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
17522  cross page boundaries (or even exceed the available data RAM) and crash
17523  the program.
17524  Make sure that stack does not cross page boundaries when using the SMALL
17525  stack model.
17526 \end_inset 
17527
17528
17529 \newline 
17530 The format is as follows:
17531 \layout LyX-Code
17532
17533 #pragma stack bottom_address [stack_size]
17534 \layout Standard
17535
17536
17537 \emph on 
17538 bottom_address
17539 \emph default 
17540  is the lower bound of the stack section.
17541  The stack pointer initially will point at address (bottom_address+stack_size-1).
17542 \layout LyX-Code
17543
17544 Example:
17545 \layout LyX-Code
17546
17547 \layout LyX-Code
17548
17549 /* initializes stack of 100 bytes at RAM address 0x200 */
17550 \layout LyX-Code
17551
17552 #pragma stack 0x200 100
17553 \layout Standard
17554
17555 If the stack_size field is omitted then a stack is created with the default
17556  size of 64.
17557  This size might be enough for most programs, but its not enough for operations
17558  with deep function nesting or excessive stack usage.
17559 \layout List
17560 \labelwidthstring 00.00.0000
17561
17562 wparam 
17563 \emph on 
17564 This pragma is deprecated.
17565  Its use will cause a warning message to be issued.
17566 \emph default 
17567
17568 \newline 
17569
17570 \layout List
17571 \labelwidthstring 00.00.0000
17572
17573 code place a function symbol at static FLASH address
17574 \layout LyX-Code
17575
17576 Example:
17577 \layout LyX-Code
17578
17579 \layout LyX-Code
17580
17581 /* place function test_func at 0x4000 */
17582 \layout LyX-Code
17583
17584 #pragma code test_func 0x4000
17585 \layout LyX-Code
17586
17587 \layout List
17588 \labelwidthstring 00.00.0000
17589
17590 library instructs the linker to use a library module.
17591 \newline 
17592 Usage:
17593 \layout LyX-Code
17594
17595 #pragma library module_name
17596 \layout Standard
17597
17598
17599 \emph on 
17600 module_name
17601 \emph default 
17602  can be any library or object file (including its path).
17603  Note that there are four reserved keywords which have special meaning.
17604  These are:
17605 \layout Standard
17606 \align center 
17607
17608 \begin_inset  Tabular
17609 <lyxtabular version="3" rows="6" columns="3">
17610 <features>
17611 <column alignment="center" valignment="top" leftline="true" width="0">
17612 <column alignment="block" valignment="top" leftline="true" width="20page%">
17613 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
17614 <row topline="true" bottomline="true">
17615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17616 \begin_inset Text
17617
17618 \layout Standard
17619
17620 Keyword
17621 \end_inset 
17622 </cell>
17623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17624 \begin_inset Text
17625
17626 \layout Standard
17627
17628 Description
17629 \end_inset 
17630 </cell>
17631 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17632 \begin_inset Text
17633
17634 \layout Standard
17635
17636 Module to link
17637 \end_inset 
17638 </cell>
17639 </row>
17640 <row topline="true">
17641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17642 \begin_inset Text
17643
17644 \layout Standard
17645
17646
17647 \series bold 
17648 ignore
17649 \end_inset 
17650 </cell>
17651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17652 \begin_inset Text
17653
17654 \layout Standard
17655
17656 ignore all library pragmas
17657 \end_inset 
17658 </cell>
17659 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17660 \begin_inset Text
17661
17662 \layout Standard
17663
17664
17665 \emph on 
17666 (none)
17667 \end_inset 
17668 </cell>
17669 </row>
17670 <row topline="true">
17671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17672 \begin_inset Text
17673
17674 \layout Standard
17675
17676
17677 \series bold 
17678 c
17679 \end_inset 
17680 </cell>
17681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17682 \begin_inset Text
17683
17684 \layout Standard
17685
17686 link the C library
17687 \end_inset 
17688 </cell>
17689 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17690 \begin_inset Text
17691
17692 \layout Standard
17693
17694
17695 \emph on 
17696 libc18f
17697 \emph default 
17698 .lib
17699 \end_inset 
17700 </cell>
17701 </row>
17702 <row topline="true">
17703 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17704 \begin_inset Text
17705
17706 \layout Standard
17707
17708
17709 \series bold 
17710 math
17711 \end_inset 
17712 </cell>
17713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17714 \begin_inset Text
17715
17716 \layout Standard
17717
17718 link the Math libarary
17719 \end_inset 
17720 </cell>
17721 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17722 \begin_inset Text
17723
17724 \layout Standard
17725
17726
17727 \emph on 
17728 libm18f
17729 \emph default 
17730 .lib
17731 \end_inset 
17732 </cell>
17733 </row>
17734 <row topline="true">
17735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17736 \begin_inset Text
17737
17738 \layout Standard
17739
17740
17741 \series bold 
17742 io
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 link the I/O library
17751 \end_inset 
17752 </cell>
17753 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17754 \begin_inset Text
17755
17756 \layout Standard
17757
17758
17759 \emph on 
17760 libio18f*
17761 \emph default 
17762 .lib
17763 \end_inset 
17764 </cell>
17765 </row>
17766 <row topline="true" bottomline="true">
17767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17768 \begin_inset Text
17769
17770 \layout Standard
17771
17772
17773 \series bold 
17774 debug
17775 \end_inset 
17776 </cell>
17777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17778 \begin_inset Text
17779
17780 \layout Standard
17781
17782 link the debug library
17783 \end_inset 
17784 </cell>
17785 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17786 \begin_inset Text
17787
17788 \layout Standard
17789
17790
17791 \emph on 
17792 libdebug
17793 \emph default 
17794 .lib
17795 \end_inset 
17796 </cell>
17797 </row>
17798 </lyxtabular>
17799
17800 \end_inset 
17801
17802
17803 \newline 
17804 * is the device number, i.e.
17805  452 for PIC18F452 MCU.
17806 \layout Standard
17807
17808 This feature allows for linking with specific libraries withoug having to
17809  explicit name them in the command line.
17810  Note that the 
17811 \noun on 
17812 ignore
17813 \noun default 
17814  keyword will reject all modules specified by the library pragma.
17815 \layout List
17816 \labelwidthstring 00.00.0000
17817
17818 udata pragma udata instructs the compiler to emit code so that linker will
17819  place a variable at a specific memory bank
17820 \layout LyX-Code
17821
17822 Example:
17823 \layout LyX-Code
17824
17825 \layout LyX-Code
17826
17827 /* places variable foo at bank2 */
17828 \layout LyX-Code
17829
17830 #pragma udata bank2 foo
17831 \layout LyX-Code
17832
17833 char foo;
17834 \layout Standard
17835
17836 In order for this pragma to work extra SECTION directives should be added
17837  in the .lkr script.
17838  In the following example a sample .lkr file is shown:
17839 \layout LyX-Code
17840
17841 \layout LyX-Code
17842
17843 // Sample linker script for the PIC18F452 processor
17844 \layout LyX-Code
17845
17846 LIBPATH .
17847 \layout LyX-Code
17848
17849 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
17850 \layout LyX-Code
17851
17852 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
17853 \layout LyX-Code
17854
17855 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
17856 \layout LyX-Code
17857
17858 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
17859 \layout LyX-Code
17860
17861 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
17862 \layout LyX-Code
17863
17864 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
17865 \layout LyX-Code
17866
17867 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
17868 \layout LyX-Code
17869
17870 \layout LyX-Code
17871
17872 DATABANK   NAME=gpr0       START=0x80           END=0xFF
17873 \layout LyX-Code
17874
17875 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
17876 \layout LyX-Code
17877
17878 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
17879 \layout LyX-Code
17880
17881 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
17882 \layout LyX-Code
17883
17884 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
17885 \layout LyX-Code
17886
17887 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
17888 \layout LyX-Code
17889
17890 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
17891 \layout LyX-Code
17892
17893 \layout LyX-Code
17894
17895 SECTION    NAME=CONFIG     ROM=config
17896 \layout LyX-Code
17897
17898 \layout LyX-Code
17899
17900 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
17901 \layout LyX-Code
17902
17903 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
17904 \layout LyX-Code
17905
17906 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
17907 \layout LyX-Code
17908
17909 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
17910 \layout LyX-Code
17911
17912 SECTION    NAME=bank4      RAM=gpr4
17913 \layout LyX-Code
17914
17915 SECTION    NAME=bank5      RAM=gpr5
17916 \layout Standard
17917
17918 The linker will recognise the section name set in the pragma statement and
17919  will position the variable at the memory bank set with the RAM field at
17920  the SECTION line in the linker script file.
17921 \layout Subsection
17922
17923 Header Files
17924 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
17925
17926 \end_inset 
17927
17928
17929 \layout Standard
17930
17931 There is one main header file that can be included to the source files using
17932  the pic16 port.
17933  That file is the 
17934 \series bold 
17935 pic18fregs.h
17936 \series default 
17937 .
17938  This header file contains the definitions for the processor special registers,
17939  so it is necessary if the source accesses them.
17940  It can be included by adding the following line in the beginning of the
17941  file:
17942 \layout LyX-Code
17943
17944 #include <pic18fregs.h>
17945 \layout Standard
17946
17947 The specific microcontroller is selected within the pic18fregs.h automatically,
17948  so the same source can be used with a variety of devices.
17949 \layout Subsection
17950
17951 Libraries
17952 \layout Standard
17953
17954 The libraries that PIC16
17955 \begin_inset LatexCommand \index{PIC16}
17956
17957 \end_inset 
17958
17959  port depends on are the microcontroller device libraries which contain
17960  the symbol definitions for the microcontroller special function registers.
17961  These libraries have the format pic18fxxxx.lib, where 
17962 \emph on 
17963 xxxx
17964 \emph default 
17965  is the microcontroller identification number.
17966  The specific library is selected automatically by the compiler at link
17967  stage according to the selected device.
17968 \layout Standard
17969
17970 Libraries are created with gplib which is part of the gputils package 
17971 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
17972
17973 \end_inset 
17974
17975 .
17976 \layout Subsubsection*
17977
17978 Building the libraries
17979 \layout Standard
17980
17981 Before using SDCC/pic16 there are some libraries that need to be compiled.
17982  This process is not done automatically by SDCC since not all users use
17983  SDCC for pic16 projects.
17984  So each user should compile the libraries separately.
17985 \layout Standard
17986
17987 The steps to compile the pic16 libraries under Linux are:
17988 \layout LyX-Code
17989
17990 cd device/lib/pic16
17991 \layout LyX-Code
17992
17993 ./configure
17994 \layout LyX-Code
17995
17996 make
17997 \layout LyX-Code
17998
17999 cd ..
18000 \layout LyX-Code
18001
18002 make model-pic16
18003 \layout LyX-Code
18004
18005 su -c 'make install'     # install the libraries, you need the root password
18006 \layout Standard
18007
18008 If you need to install the headers too, do:
18009 \layout LyX-Code
18010
18011 cd device/include
18012 \layout LyX-Code
18013
18014 su -c 'make install'     # install the headers, you need the root password
18015 \layout Standard
18016
18017 There exist a special target to build the I/O libraries.
18018  This target is not automatically build because it will build the I/O library
18019  for 
18020 \emph on 
18021 every
18022 \emph default 
18023  supported device.
18024  This way building will take quite a lot of time.
18025  Users are advised to edit the 
18026 \series bold 
18027 device/lib/pic16/pics.build
18028 \series default 
18029  file and then execute:
18030 \layout LyX-Code
18031
18032 make lib-io
18033 \layout Subsection
18034
18035 Memory Models
18036 \layout Standard
18037
18038 The following memory models are supported by the PIC16 port:
18039 \layout Itemize
18040
18041 small model
18042 \layout Itemize
18043
18044 large model
18045 \layout Standard
18046
18047 Memory model affects the default size of pointers within the source.
18048  The sizes are shown in the next table:
18049 \layout Standard
18050 \align center 
18051
18052 \begin_inset  Tabular
18053 <lyxtabular version="3" rows="3" columns="3">
18054 <features>
18055 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18056 <column alignment="center" valignment="top" leftline="true" width="0">
18057 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18058 <row topline="true" bottomline="true">
18059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18060 \begin_inset Text
18061
18062 \layout Standard
18063
18064 Pointer sizes according to memory model
18065 \end_inset 
18066 </cell>
18067 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18068 \begin_inset Text
18069
18070 \layout Standard
18071
18072 small model
18073 \end_inset 
18074 </cell>
18075 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18076 \begin_inset Text
18077
18078 \layout Standard
18079
18080 large model
18081 \end_inset 
18082 </cell>
18083 </row>
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 code pointers
18091 \end_inset 
18092 </cell>
18093 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18094 \begin_inset Text
18095
18096 \layout Standard
18097
18098 16-bits
18099 \end_inset 
18100 </cell>
18101 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18102 \begin_inset Text
18103
18104 \layout Standard
18105
18106 24-bits
18107 \end_inset 
18108 </cell>
18109 </row>
18110 <row topline="true" bottomline="true">
18111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18112 \begin_inset Text
18113
18114 \layout Standard
18115
18116 data pointers
18117 \end_inset 
18118 </cell>
18119 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
18120 \begin_inset Text
18121
18122 \layout Standard
18123
18124 16-bits
18125 \end_inset 
18126 </cell>
18127 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18128 \begin_inset Text
18129
18130 \layout Standard
18131
18132 16-bits
18133 \end_inset 
18134 </cell>
18135 </row>
18136 </lyxtabular>
18137
18138 \end_inset 
18139
18140
18141 \layout Standard
18142
18143 It is advisable that all sources within a project are compiled with the
18144  same memory model.
18145  If one wants to override the default memory model, this can be done by
18146  declaring a pointer as 
18147 \series bold 
18148 far
18149 \series default 
18150  or 
18151 \series bold 
18152 near
18153 \series default 
18154 .
18155  Far selects large memory model's pointers, while near selects small memory
18156  model's pointers.
18157 \layout Standard
18158
18159 The standard device libraries (see 
18160 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
18161
18162 \end_inset 
18163
18164 ) contain no reference to pointers, so they can be used with both memory
18165  models.
18166 \layout Subsection
18167
18168 Stack
18169 \layout Standard
18170
18171 The stack implementation for the PIC16 port uses two indirect registers,
18172  FSR1 and FSR2.
18173 \layout List
18174 \labelwidthstring 00.00.0000
18175
18176 FSR1 is assigned as stack pointer
18177 \layout List
18178 \labelwidthstring 00.00.0000
18179
18180 FSR2 is assigned as frame pointer
18181 \layout Standard
18182
18183 The following stack models are supported by the PIC16 port
18184 \layout Itemize
18185
18186
18187 \noun on 
18188 small
18189 \noun default 
18190  model
18191 \layout Itemize
18192
18193
18194 \noun on 
18195 large
18196 \noun default 
18197  model
18198 \layout Standard
18199
18200
18201 \noun on 
18202 Small
18203 \noun default 
18204  model means that only the FSRxL byte is used to access stack and frame,
18205  while 
18206 \emph on 
18207 \noun on 
18208 large
18209 \emph default 
18210 \noun default 
18211  uses both FSRxL and FSRxH registers.
18212  The following table shows the stack/frame pointers sizes according to stack
18213  model and the maximum space they can address:
18214 \layout Standard
18215 \align center 
18216
18217 \begin_inset  Tabular
18218 <lyxtabular version="3" rows="3" columns="3">
18219 <features>
18220 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18221 <column alignment="center" valignment="top" leftline="true" width="0">
18222 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18223 <row topline="true" bottomline="true">
18224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18225 \begin_inset Text
18226
18227 \layout Standard
18228
18229 Stack & Frame pointer sizes according to stack model
18230 \end_inset 
18231 </cell>
18232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18233 \begin_inset Text
18234
18235 \layout Standard
18236
18237 small
18238 \end_inset 
18239 </cell>
18240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18241 \begin_inset Text
18242
18243 \layout Standard
18244
18245 large
18246 \end_inset 
18247 </cell>
18248 </row>
18249 <row topline="true">
18250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18251 \begin_inset Text
18252
18253 \layout Standard
18254
18255 Stack pointer FSR1
18256 \end_inset 
18257 </cell>
18258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18259 \begin_inset Text
18260
18261 \layout Standard
18262
18263 8-bits
18264 \end_inset 
18265 </cell>
18266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18267 \begin_inset Text
18268
18269 \layout Standard
18270
18271 16-bits
18272 \end_inset 
18273 </cell>
18274 </row>
18275 <row topline="true" bottomline="true">
18276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18277 \begin_inset Text
18278
18279 \layout Standard
18280
18281 Frame pointer FSR2
18282 \end_inset 
18283 </cell>
18284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18285 \begin_inset Text
18286
18287 \layout Standard
18288
18289 8-bits
18290 \end_inset 
18291 </cell>
18292 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18293 \begin_inset Text
18294
18295 \layout Standard
18296
18297 16-bits
18298 \end_inset 
18299 </cell>
18300 </row>
18301 </lyxtabular>
18302
18303 \end_inset 
18304
18305
18306 \layout Standard
18307
18308
18309 \noun on 
18310 Large 
18311 \noun default 
18312 stack model is currently not working properly throughout the code generator.
18313  So its use is not advised.
18314  Also there are some other points that need special care:
18315 \newline 
18316
18317 \layout Enumerate
18318
18319 Do not create stack sections with size more than one physical bank (that
18320  is 256 bytes)
18321 \layout Enumerate
18322
18323 Stack sections should no cross physical bank limits (i.e.
18324  #pragma stack 0x50 0x100)
18325 \layout Standard
18326
18327 These limitations are caused by the fact that only FSRxL is modified when
18328  using SMALL stack model, so no more than 256 bytes of stack can be used.
18329  This problem will disappear after LARGE model is fully implemented.
18330 \layout Subsection
18331
18332 Functions
18333 \layout Standard
18334
18335 In addition to the standard SDCC function keywords, PIC16 port makes available
18336  two more:
18337 \layout List
18338 \labelwidthstring 00.00.0000
18339
18340 wparam Use the WREG to pass one byte of the first function argument.
18341  This improves speed but you may not use this for functions with arguments
18342  that are called via function pointers, otherwise the first byte of the
18343  first parameter will get lost.
18344  Usage:
18345 \layout LyX-Code
18346
18347 void func_wparam(int a) wparam
18348 \layout LyX-Code
18349
18350 {
18351 \layout LyX-Code
18352
18353     /* WREG hold the lower part of a */
18354 \layout LyX-Code
18355
18356     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
18357  */
18358 \layout LyX-Code
18359
18360 ...
18361 \layout LyX-Code
18362
18363 }
18364 \layout Standard
18365
18366 This keyword replaces the deprecated wparam pragma.
18367 \layout List
18368 \labelwidthstring 00.00.0000
18369
18370 shadowregs When entering/exiting an ISR, it is possible to take advantage
18371  of the PIC18F hardware shadow registers which hold the values of WREG,
18372  STATUS and BSR registers.
18373  This can be done by adding the keyword 
18374 \emph on 
18375 shadowregs
18376 \emph default 
18377  before the 
18378 \emph on 
18379 interrupt
18380 \emph default 
18381  keyword in the function's header.
18382 \layout LyX-Code
18383
18384 void isr_shadow(void) shadowregs interrupt 1
18385 \layout LyX-Code
18386
18387 {
18388 \layout LyX-Code
18389
18390 ...
18391 \layout LyX-Code
18392
18393 }
18394 \layout Standard
18395
18396
18397 \emph on 
18398 shadowregs
18399 \emph default 
18400  instructs the code generator not to store/restore WREG, STATUS, BSR when
18401  entering/exiting the ISR.
18402 \layout Subsection
18403
18404 Function return values
18405 \layout Standard
18406
18407 Return values from functions are placed to the appropriate registers following
18408  a modified Microchip policy optimized for SDCC.
18409  The following table shows these registers:
18410 \layout Standard
18411 \align center 
18412
18413 \begin_inset  Tabular
18414 <lyxtabular version="3" rows="6" columns="2">
18415 <features>
18416 <column alignment="center" valignment="top" leftline="true" width="0">
18417 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18418 <row topline="true" bottomline="true">
18419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18420 \begin_inset Text
18421
18422 \layout Standard
18423
18424 size
18425 \end_inset 
18426 </cell>
18427 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18428 \begin_inset Text
18429
18430 \layout Standard
18431
18432 destination register
18433 \end_inset 
18434 </cell>
18435 </row>
18436 <row topline="true">
18437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18438 \begin_inset Text
18439
18440 \layout Standard
18441
18442 8 bits
18443 \end_inset 
18444 </cell>
18445 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18446 \begin_inset Text
18447
18448 \layout Standard
18449
18450 WREG
18451 \end_inset 
18452 </cell>
18453 </row>
18454 <row topline="true">
18455 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18456 \begin_inset Text
18457
18458 \layout Standard
18459
18460 16 bits
18461 \end_inset 
18462 </cell>
18463 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18464 \begin_inset Text
18465
18466 \layout Standard
18467
18468 PRODL:WREG
18469 \end_inset 
18470 </cell>
18471 </row>
18472 <row topline="true">
18473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18474 \begin_inset Text
18475
18476 \layout Standard
18477
18478 24 bits
18479 \end_inset 
18480 </cell>
18481 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18482 \begin_inset Text
18483
18484 \layout Standard
18485
18486 PRODH:PRODL:WREG
18487 \end_inset 
18488 </cell>
18489 </row>
18490 <row topline="true">
18491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18492 \begin_inset Text
18493
18494 \layout Standard
18495
18496 32 bits
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 FSR0L:PRODH:PRODL:WREG
18505 \end_inset 
18506 </cell>
18507 </row>
18508 <row topline="true" bottomline="true">
18509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18510 \begin_inset Text
18511
18512 \layout Standard
18513
18514 >32 bits
18515 \end_inset 
18516 </cell>
18517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18518 \begin_inset Text
18519
18520 \layout Standard
18521
18522 on stack, FSR0 points to the beginning
18523 \end_inset 
18524 </cell>
18525 </row>
18526 </lyxtabular>
18527
18528 \end_inset 
18529
18530
18531 \layout Subsection
18532
18533 Interrupts
18534 \layout Standard
18535
18536 An interrupt servive routine (ISR) is declared using the 
18537 \emph on 
18538 interrupt
18539 \emph default 
18540  keyword.
18541 \layout LyX-Code
18542
18543 void isr(void) interrupt 
18544 \emph on 
18545 n
18546 \layout LyX-Code
18547
18548 {
18549 \layout LyX-Code
18550
18551 ...
18552 \layout LyX-Code
18553
18554 }
18555 \layout Standard
18556
18557
18558 \emph on 
18559 n
18560 \emph default 
18561  is the interrupt number, which for PIC18F devices can be:
18562 \layout Standard
18563 \align center 
18564
18565 \begin_inset  Tabular
18566 <lyxtabular version="3" rows="4" columns="3">
18567 <features>
18568 <column alignment="center" valignment="top" leftline="true" width="0">
18569 <column alignment="center" valignment="top" leftline="true" width="0">
18570 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18571 <row topline="true" bottomline="true">
18572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18573 \begin_inset Text
18574
18575 \layout Standard
18576
18577
18578 \emph on 
18579 n
18580 \end_inset 
18581 </cell>
18582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18583 \begin_inset Text
18584
18585 \layout Standard
18586
18587 Interrupt Vector
18588 \end_inset 
18589 </cell>
18590 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18591 \begin_inset Text
18592
18593 \layout Standard
18594
18595 Interrupt Vector Address
18596 \end_inset 
18597 </cell>
18598 </row>
18599 <row topline="true">
18600 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18601 \begin_inset Text
18602
18603 \layout Standard
18604
18605 0
18606 \end_inset 
18607 </cell>
18608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18609 \begin_inset Text
18610
18611 \layout Standard
18612
18613 RESET vector
18614 \end_inset 
18615 </cell>
18616 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18617 \begin_inset Text
18618
18619 \layout Standard
18620
18621 0x000000
18622 \end_inset 
18623 </cell>
18624 </row>
18625 <row topline="true">
18626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18627 \begin_inset Text
18628
18629 \layout Standard
18630
18631
18632 \family roman 
18633 \series medium 
18634 \shape up 
18635 \size normal 
18636 \emph off 
18637 \bar no 
18638 \noun off 
18639 \color none
18640 1
18641 \end_inset 
18642 </cell>
18643 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18644 \begin_inset Text
18645
18646 \layout Standard
18647
18648
18649 \family roman 
18650 \series medium 
18651 \shape up 
18652 \size normal 
18653 \emph off 
18654 \bar no 
18655 \noun off 
18656 \color none
18657 HIGH priority interrupts
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 0x000008
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 2
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 LOW priority interrupts
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 0x000018
18692 \end_inset 
18693 </cell>
18694 </row>
18695 </lyxtabular>
18696
18697 \end_inset 
18698
18699
18700 \layout Standard
18701
18702 When generating assembly code for ISR the code generator places a 
18703 \noun on 
18704 goto 
18705 \noun default 
18706 instruction at the 
18707 \emph on 
18708 Interrupt Vector Address
18709 \emph default 
18710  which points at the genetated ISR.
18711  This single GOTO instruction is part of an automatically generated 
18712 \emph on 
18713 interrupt entry point
18714 \emph default 
18715  function.
18716  The actuall ISR code is placed as normally would in the code space.
18717  Upon interrupt request, the GOTO instruction is executed which jumps to
18718  the ISR code.
18719  When declaring interrupt functions as _naked this GOTO instruction is 
18720 \series bold 
18721 not
18722 \series default 
18723  generated.
18724  The whole interrupt functions is therefore placed at the Interrupt Vector
18725  Address of the specific interrupt.
18726  This is not a problem for the LOW priority interrupts, but it is a problem
18727  for the RESET and the HIGH priority interrupts because code may be written
18728  at the next interrupt´s vector address and cause undeterminate program
18729  behaviour if that interrupt is raised.
18730 \begin_inset Foot
18731 collapsed false
18732
18733 \layout Standard
18734
18735 This is not a problem when
18736 \layout Enumerate
18737
18738 this is a HIGH interrupt ISR and LOW interrupts are 
18739 \emph on 
18740 disabled
18741 \emph default 
18742  or not used.
18743 \layout Enumerate
18744
18745 when the ISR is small enough not to reach the next interrupt´s vector address.
18746 \end_inset 
18747
18748
18749 \layout Standard
18750
18751
18752 \emph on 
18753 n
18754 \emph default 
18755  is possible to be omitted.
18756  This way a function is generated similar to an ISR, but it is not assigned
18757  to any interrupt.
18758 \layout Standard
18759
18760 When entering an interrupt, currently the PIC16
18761 \begin_inset LatexCommand \index{PIC16}
18762
18763 \end_inset 
18764
18765  port automatically saves the following registers:
18766 \layout Itemize
18767
18768 WREG
18769 \layout Itemize
18770
18771 STATUS
18772 \layout Itemize
18773
18774 BSR
18775 \layout Itemize
18776
18777 PROD (PRODL and PRODH)
18778 \layout Itemize
18779
18780 FSR0 (FSR0L and FSR0H)
18781 \layout Standard
18782
18783 These registers are restored upon return from the interrupt routine.
18784 \begin_inset Foot
18785 collapsed false
18786
18787 \layout Standard
18788
18789 NOTE that when the _naked attribute is specified for an interrupt routine,
18790  then NO registers are stored or restored.
18791 \end_inset 
18792
18793
18794 \layout Subsection
18795
18796 Generic Pointers
18797 \layout Standard
18798
18799 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
18800  There are 3 types of generic pointers currently implemented data, code
18801  and eeprom pointers.
18802  They are differentiated by the value of the 7th and 6th bits of the upper
18803  byte:
18804 \layout Standard
18805 \align center 
18806
18807 \begin_inset  Tabular
18808 <lyxtabular version="3" rows="5" columns="5">
18809 <features>
18810 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18811 <column alignment="center" valignment="top" width="0">
18812 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18813 <column alignment="center" valignment="top" width="0">
18814 <column alignment="left" valignment="top" rightline="true" width="0">
18815 <row topline="true" bottomline="true">
18816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18817 \begin_inset Text
18818
18819 \layout Standard
18820
18821 pointer type
18822 \end_inset 
18823 </cell>
18824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18825 \begin_inset Text
18826
18827 \layout Standard
18828
18829 7th bit
18830 \end_inset 
18831 </cell>
18832 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18833 \begin_inset Text
18834
18835 \layout Standard
18836
18837 6th bit
18838 \end_inset 
18839 </cell>
18840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18841 \begin_inset Text
18842
18843 \layout Standard
18844
18845 rest of the pointer
18846 \end_inset 
18847 </cell>
18848 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18849 \begin_inset Text
18850
18851 \layout Standard
18852
18853 descrption
18854 \end_inset 
18855 </cell>
18856 </row>
18857 <row topline="true" bottomline="true">
18858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18859 \begin_inset Text
18860
18861 \layout Standard
18862
18863 data 
18864 \end_inset 
18865 </cell>
18866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18867 \begin_inset Text
18868
18869 \layout Standard
18870
18871 1
18872 \end_inset 
18873 </cell>
18874 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18875 \begin_inset Text
18876
18877 \layout Standard
18878
18879 0
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
18888 \family typewriter 
18889 \shape slanted 
18890 \emph on 
18891 uuuuuu uuuuxxxx xxxxxxxx
18892 \end_inset 
18893 </cell>
18894 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18895 \begin_inset Text
18896
18897 \layout Standard
18898
18899 a 12-bit data pointer in data RAM memory
18900 \end_inset 
18901 </cell>
18902 </row>
18903 <row bottomline="true">
18904 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18905 \begin_inset Text
18906
18907 \layout Standard
18908
18909 code
18910 \end_inset 
18911 </cell>
18912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18913 \begin_inset Text
18914
18915 \layout Standard
18916
18917 0
18918 \end_inset 
18919 </cell>
18920 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18921 \begin_inset Text
18922
18923 \layout Standard
18924
18925 0
18926 \end_inset 
18927 </cell>
18928 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18929 \begin_inset Text
18930
18931 \layout Standard
18932
18933
18934 \family typewriter 
18935 \shape slanted 
18936 \emph on 
18937 uxxxxx xxxxxxxx xxxxxxxx
18938 \end_inset 
18939 </cell>
18940 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18941 \begin_inset Text
18942
18943 \layout Standard
18944
18945 a 21-bit code pointer in FLASH memory
18946 \end_inset 
18947 </cell>
18948 </row>
18949 <row bottomline="true">
18950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18951 \begin_inset Text
18952
18953 \layout Standard
18954
18955 eeprom
18956 \end_inset 
18957 </cell>
18958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18959 \begin_inset Text
18960
18961 \layout Standard
18962
18963 0
18964 \end_inset 
18965 </cell>
18966 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18967 \begin_inset Text
18968
18969 \layout Standard
18970
18971 1
18972 \end_inset 
18973 </cell>
18974 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18975 \begin_inset Text
18976
18977 \layout Standard
18978
18979
18980 \family typewriter 
18981 \shape slanted 
18982 \emph on 
18983 uuuuuu uuuuuuxx xxxxxxxx
18984 \end_inset 
18985 </cell>
18986 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18987 \begin_inset Text
18988
18989 \layout Standard
18990
18991 a 10-bit eeprom pointer in EEPROM memory
18992 \end_inset 
18993 </cell>
18994 </row>
18995 <row bottomline="true">
18996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18997 \begin_inset Text
18998
18999 \layout Standard
19000
19001 (unimplemented)
19002 \end_inset 
19003 </cell>
19004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19005 \begin_inset Text
19006
19007 \layout Standard
19008
19009 1
19010 \end_inset 
19011 </cell>
19012 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19013 \begin_inset Text
19014
19015 \layout Standard
19016
19017 1
19018 \end_inset 
19019 </cell>
19020 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19021 \begin_inset Text
19022
19023 \layout Standard
19024
19025
19026 \family typewriter 
19027 \shape slanted 
19028 \emph on 
19029 xxxxxx xxxxxxxx xxxxxxxx
19030 \end_inset 
19031 </cell>
19032 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19033 \begin_inset Text
19034
19035 \layout Standard
19036
19037 unimplemented pointer type
19038 \end_inset 
19039 </cell>
19040 </row>
19041 </lyxtabular>
19042
19043 \end_inset 
19044
19045
19046 \layout Standard
19047
19048 Generic pointer are read and written with a set of library functions which
19049  read/write 1, 2, 3, 4 bytes.
19050 \layout Subsection
19051
19052 PIC16 C Libraries
19053 \layout Subsubsection
19054
19055 Standard I/O Streams
19056 \layout Standard
19057
19058 In the 
19059 \emph on 
19060 stdio.h
19061 \emph default 
19062  the type FILE is defined as:
19063 \layout LyX-Code
19064
19065 typedef char * FILE;
19066 \layout Standard
19067
19068 This type is the stream type implemented I/O in the PIC18F devices.
19069  Also the standard input and output streams are declared in stdio.h:
19070 \layout LyX-Code
19071
19072 extern FILE * stdin;
19073 \layout LyX-Code
19074
19075 extern FILE * stdout;
19076 \layout Standard
19077
19078 The FILE type is actually a generic pointer which defines one more type
19079  of generic pointers, the 
19080 \emph on 
19081 stream 
19082 \emph default 
19083 pointer.
19084  This new type has the format:
19085 \layout Standard
19086 \align center 
19087
19088 \begin_inset  Tabular
19089 <lyxtabular version="3" rows="2" columns="7">
19090 <features>
19091 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19092 <column alignment="center" valignment="top" width="0">
19093 <column alignment="center" valignment="top" leftline="true" width="0">
19094 <column alignment="center" valignment="top" leftline="true" width="0">
19095 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19096 <column alignment="center" valignment="top" width="0">
19097 <column alignment="left" valignment="top" rightline="true" width="0">
19098 <row topline="true" bottomline="true">
19099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19100 \begin_inset Text
19101
19102 \layout Standard
19103
19104 pointer type
19105 \end_inset 
19106 </cell>
19107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19108 \begin_inset Text
19109
19110 \layout Standard
19111
19112 <7:6>
19113 \end_inset 
19114 </cell>
19115 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19116 \begin_inset Text
19117
19118 \layout Standard
19119
19120 <5>
19121 \end_inset 
19122 </cell>
19123 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19124 \begin_inset Text
19125
19126 \layout Standard
19127
19128 <4>
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 <3:0>
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 rest of the pointer
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 descrption
19153 \end_inset 
19154 </cell>
19155 </row>
19156 <row topline="true" bottomline="true">
19157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19158 \begin_inset Text
19159
19160 \layout Standard
19161
19162 stream
19163 \end_inset 
19164 </cell>
19165 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19166 \begin_inset Text
19167
19168 \layout Standard
19169
19170 00
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 1
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 0
19187 \end_inset 
19188 </cell>
19189 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19190 \begin_inset Text
19191
19192 \layout Standard
19193
19194 nnnn
19195 \end_inset 
19196 </cell>
19197 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19198 \begin_inset Text
19199
19200 \layout Standard
19201
19202
19203 \family typewriter 
19204 \shape slanted 
19205 \emph on 
19206 uuuuuuuu uuuuuuuu
19207 \end_inset 
19208 </cell>
19209 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19210 \begin_inset Text
19211
19212 \layout Standard
19213
19214 upper byte high nubble is 0x2n, the rest are zeroes
19215 \end_inset 
19216 </cell>
19217 </row>
19218 </lyxtabular>
19219
19220 \end_inset 
19221
19222
19223 \layout Standard
19224
19225 Currently implemented there are 3 types of streams defined:
19226 \layout Standard
19227 \align center 
19228
19229 \begin_inset  Tabular
19230 <lyxtabular version="3" rows="4" columns="4">
19231 <features>
19232 <column alignment="center" valignment="top" leftline="true" width="0">
19233 <column alignment="center" valignment="top" leftline="true" width="0">
19234 <column alignment="center" valignment="top" leftline="true" width="0">
19235 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19236 <row topline="true" bottomline="true">
19237 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19238 \begin_inset Text
19239
19240 \layout Standard
19241
19242 stream type
19243 \end_inset 
19244 </cell>
19245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19246 \begin_inset Text
19247
19248 \layout Standard
19249
19250 value
19251 \end_inset 
19252 </cell>
19253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19254 \begin_inset Text
19255
19256 \layout Standard
19257
19258 module
19259 \end_inset 
19260 </cell>
19261 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19262 \begin_inset Text
19263
19264 \layout Standard
19265
19266 description
19267 \end_inset 
19268 </cell>
19269 </row>
19270 <row topline="true">
19271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19272 \begin_inset Text
19273
19274 \layout Standard
19275
19276 STREAM_USART
19277 \end_inset 
19278 </cell>
19279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19280 \begin_inset Text
19281
19282 \layout Standard
19283
19284
19285 \family typewriter 
19286 0x200000UL
19287 \end_inset 
19288 </cell>
19289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19290 \begin_inset Text
19291
19292 \layout Standard
19293
19294 USART
19295 \end_inset 
19296 </cell>
19297 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19298 \begin_inset Text
19299
19300 \layout Standard
19301
19302 Writes/Reads characters via the USART peripheral
19303 \end_inset 
19304 </cell>
19305 </row>
19306 <row topline="true">
19307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19308 \begin_inset Text
19309
19310 \layout Standard
19311
19312 STREAM_MSSP
19313 \end_inset 
19314 </cell>
19315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19316 \begin_inset Text
19317
19318 \layout Standard
19319
19320
19321 \family typewriter 
19322 0x210000UL
19323 \end_inset 
19324 </cell>
19325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19326 \begin_inset Text
19327
19328 \layout Standard
19329
19330 MSSP
19331 \end_inset 
19332 </cell>
19333 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19334 \begin_inset Text
19335
19336 \layout Standard
19337
19338 Writes/Reads characters via the MSSP peripheral
19339 \end_inset 
19340 </cell>
19341 </row>
19342 <row topline="true" bottomline="true">
19343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19344 \begin_inset Text
19345
19346 \layout Standard
19347
19348 STREAM_USER
19349 \end_inset 
19350 </cell>
19351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19352 \begin_inset Text
19353
19354 \layout Standard
19355
19356
19357 \family typewriter 
19358 0x2f0000UL
19359 \end_inset 
19360 </cell>
19361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19362 \begin_inset Text
19363
19364 \layout Standard
19365
19366 (none)
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 Writes/Reads characters via used defined functions
19375 \end_inset 
19376 </cell>
19377 </row>
19378 </lyxtabular>
19379
19380 \end_inset 
19381
19382
19383 \layout Standard
19384
19385 The stream identifiers are declared as macros in the stdio.h header.
19386 \layout Standard
19387
19388 In the libc library there exist the functions that are used to write to
19389  each of the above streams.
19390  These are
19391 \layout List
19392 \labelwidthstring 00.00.0000
19393
19394 _
19395 \begin_inset ERT
19396 status Collapsed
19397
19398 \layout Standard
19399
19400 \backslash 
19401 /
19402 \end_inset 
19403
19404 _stream_usart_putchar writes a character at the USART stream
19405 \layout List
19406 \labelwidthstring 00.00.0000
19407
19408 _
19409 \begin_inset ERT
19410 status Collapsed
19411
19412 \layout Standard
19413
19414 \backslash 
19415 /
19416 \end_inset 
19417
19418 _stream_mssp_putchar writes a character at the MSSP stream
19419 \layout List
19420 \labelwidthstring 00.00.0000
19421
19422 putchar dummy function.
19423  This writes a character to a user specified manner.
19424 \layout Standard
19425
19426 In order to increase performance 
19427 \emph on 
19428 putchar 
19429 \emph default 
19430 is declared in stdio.h as having its parameter in WREG (it has the wparam
19431  keyword).
19432  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
19433  in a user-friendly way.
19434  
19435 \emph on 
19436 arg
19437 \emph default 
19438  is the name of the variable that holds the character to print.
19439  An example follows:
19440 \layout LyX-Code
19441
19442 #include <pic18fregs.h>
19443 \newline 
19444 #include <stdio.h>
19445 \newline 
19446
19447 \newline 
19448 PUTCHAR( c )
19449 \layout LyX-Code
19450
19451 {
19452 \layout LyX-Code
19453
19454     PORTA = c;    /* dump character c to PORTA */
19455 \layout LyX-Code
19456
19457
19458 \newline 
19459
19460 \newline 
19461 void main(void)
19462 \layout LyX-Code
19463
19464 {
19465 \layout LyX-Code
19466
19467     stdout = STREAM_USER;    /* this is not necessery, since stdout points
19468 \layout LyX-Code
19469
19470                               * by default to STREAM_USER */
19471 \layout LyX-Code
19472
19473     printf (¨This is a printf test
19474 \backslash 
19475 n¨);
19476 \layout LyX-Code
19477
19478 }
19479 \layout LyX-Code
19480
19481 \layout Subsubsection
19482
19483 Printing functions
19484 \layout Standard
19485
19486 PIC16 contains an implementation of the printf-family of functions.
19487  There exist the following functions:
19488 \layout LyX-Code
19489
19490 extern unsigned int sprintf(char *buf, char *fmt, ...);
19491 \layout LyX-Code
19492
19493 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
19494 \layout LyX-Code
19495
19496 \layout LyX-Code
19497
19498 extern unsigned int printf(char *fmt, ...);
19499 \layout LyX-Code
19500
19501 extern unsigned int vprintf(char *fmt, va_lista ap);
19502 \layout LyX-Code
19503
19504 \layout LyX-Code
19505
19506 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
19507 \layout LyX-Code
19508
19509 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
19510 \layout Standard
19511
19512 For sprintf and vsprintf 
19513 \emph on 
19514 buf 
19515 \emph default 
19516 should normally be a data pointer where the resulting string will be placed.
19517  No range checking is done so the user should allocate the necessery buffer.
19518  For fprintf and vfprintf 
19519 \emph on 
19520 fp
19521 \emph default 
19522  should be a stream pointer (i.e.
19523  stdout, STREAM_MSSP, etc...).
19524 \layout Subsubsection
19525
19526 Signals
19527 \layout Standard
19528
19529 The PIC18F family of microcontrollers supports a number of interrupt sources.
19530  A list of these interrupts is shown in the following table:
19531 \layout Standard
19532 \align center 
19533
19534 \begin_inset  Tabular
19535 <lyxtabular version="3" rows="11" columns="4">
19536 <features>
19537 <column alignment="left" valignment="top" leftline="true" width="0">
19538 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19539 <column alignment="left" valignment="top" leftline="true" width="0">
19540 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19541 <row topline="true" bottomline="true">
19542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19543 \begin_inset Text
19544
19545 \layout Standard
19546
19547 signal name
19548 \end_inset 
19549 </cell>
19550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19551 \begin_inset Text
19552
19553 \layout Standard
19554
19555 description
19556 \end_inset 
19557 </cell>
19558 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19559 \begin_inset Text
19560
19561 \layout Standard
19562
19563 signal name
19564 \end_inset 
19565 </cell>
19566 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19567 \begin_inset Text
19568
19569 \layout Standard
19570
19571 descritpion
19572 \end_inset 
19573 </cell>
19574 </row>
19575 <row topline="true">
19576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19577 \begin_inset Text
19578
19579 \layout Standard
19580
19581 SIG_RB
19582 \end_inset 
19583 </cell>
19584 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19585 \begin_inset Text
19586
19587 \layout Standard
19588
19589 PORTB change interrupt
19590 \end_inset 
19591 </cell>
19592 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19593 \begin_inset Text
19594
19595 \layout Standard
19596
19597 SIG_EE
19598 \end_inset 
19599 </cell>
19600 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19601 \begin_inset Text
19602
19603 \layout Standard
19604
19605 EEPROM/FLASH write complete interrupt
19606 \end_inset 
19607 </cell>
19608 </row>
19609 <row topline="true">
19610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19611 \begin_inset Text
19612
19613 \layout Standard
19614
19615 SIG_INT0
19616 \end_inset 
19617 </cell>
19618 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19619 \begin_inset Text
19620
19621 \layout Standard
19622
19623 INT0 external interrupt
19624 \end_inset 
19625 </cell>
19626 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19627 \begin_inset Text
19628
19629 \layout Standard
19630
19631 SIG_BCOL
19632 \end_inset 
19633 </cell>
19634 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19635 \begin_inset Text
19636
19637 \layout Standard
19638
19639 Bus collision interrupt
19640 \end_inset 
19641 </cell>
19642 </row>
19643 <row topline="true">
19644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19645 \begin_inset Text
19646
19647 \layout Standard
19648
19649 SIG_INT1
19650 \end_inset 
19651 </cell>
19652 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19653 \begin_inset Text
19654
19655 \layout Standard
19656
19657 INT1 external interrupt
19658 \end_inset 
19659 </cell>
19660 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19661 \begin_inset Text
19662
19663 \layout Standard
19664
19665 SIG_LVD
19666 \end_inset 
19667 </cell>
19668 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19669 \begin_inset Text
19670
19671 \layout Standard
19672
19673 Low voltage detect interrupt
19674 \end_inset 
19675 </cell>
19676 </row>
19677 <row topline="true">
19678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19679 \begin_inset Text
19680
19681 \layout Standard
19682
19683 SIG_INT2
19684 \end_inset 
19685 </cell>
19686 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19687 \begin_inset Text
19688
19689 \layout Standard
19690
19691 INT2 external interrupt
19692 \end_inset 
19693 </cell>
19694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19695 \begin_inset Text
19696
19697 \layout Standard
19698
19699 SIG_PSP
19700 \end_inset 
19701 </cell>
19702 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19703 \begin_inset Text
19704
19705 \layout Standard
19706
19707 Parallel slave port interrupt
19708 \end_inset 
19709 </cell>
19710 </row>
19711 <row topline="true">
19712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19713 \begin_inset Text
19714
19715 \layout Standard
19716
19717 SIG_CCP1
19718 \end_inset 
19719 </cell>
19720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19721 \begin_inset Text
19722
19723 \layout Standard
19724
19725 CCP1 module interrupt
19726 \end_inset 
19727 </cell>
19728 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19729 \begin_inset Text
19730
19731 \layout Standard
19732
19733 SIG_AD
19734 \end_inset 
19735 </cell>
19736 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19737 \begin_inset Text
19738
19739 \layout Standard
19740
19741 AD convertion complete interrupt
19742 \end_inset 
19743 </cell>
19744 </row>
19745 <row topline="true">
19746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19747 \begin_inset Text
19748
19749 \layout Standard
19750
19751 SIG_CCP2
19752 \end_inset 
19753 </cell>
19754 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19755 \begin_inset Text
19756
19757 \layout Standard
19758
19759 CCP2 module interrupt
19760 \end_inset 
19761 </cell>
19762 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19763 \begin_inset Text
19764
19765 \layout Standard
19766
19767 SIG_RC
19768 \end_inset 
19769 </cell>
19770 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19771 \begin_inset Text
19772
19773 \layout Standard
19774
19775 USART receive interrupt
19776 \end_inset 
19777 </cell>
19778 </row>
19779 <row topline="true">
19780 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19781 \begin_inset Text
19782
19783 \layout Standard
19784
19785 SIG_TMR0
19786 \end_inset 
19787 </cell>
19788 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19789 \begin_inset Text
19790
19791 \layout Standard
19792
19793 TMR0 overflow interrupt
19794 \end_inset 
19795 </cell>
19796 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19797 \begin_inset Text
19798
19799 \layout Standard
19800
19801 SIG_TX
19802 \end_inset 
19803 </cell>
19804 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19805 \begin_inset Text
19806
19807 \layout Standard
19808
19809 USART transmit interrupt
19810 \end_inset 
19811 </cell>
19812 </row>
19813 <row topline="true">
19814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19815 \begin_inset Text
19816
19817 \layout Standard
19818
19819 SIG_TMR1
19820 \end_inset 
19821 </cell>
19822 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19823 \begin_inset Text
19824
19825 \layout Standard
19826
19827 TMR1 overflow interrupt
19828 \end_inset 
19829 </cell>
19830 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19831 \begin_inset Text
19832
19833 \layout Standard
19834
19835 SIG_MSSP
19836 \end_inset 
19837 </cell>
19838 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19839 \begin_inset Text
19840
19841 \layout Standard
19842
19843 SSP receive/transmit interrupt
19844 \end_inset 
19845 </cell>
19846 </row>
19847 <row topline="true">
19848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19849 \begin_inset Text
19850
19851 \layout Standard
19852
19853 SIG_TMR2
19854 \end_inset 
19855 </cell>
19856 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19857 \begin_inset Text
19858
19859 \layout Standard
19860
19861 TMR2 matches PR2 interrupt
19862 \end_inset 
19863 </cell>
19864 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19865 \begin_inset Text
19866
19867 \layout Standard
19868
19869 \end_inset 
19870 </cell>
19871 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19872 \begin_inset Text
19873
19874 \layout Standard
19875
19876 \end_inset 
19877 </cell>
19878 </row>
19879 <row topline="true" bottomline="true">
19880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19881 \begin_inset Text
19882
19883 \layout Standard
19884
19885 SIG_TMR3
19886 \end_inset 
19887 </cell>
19888 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19889 \begin_inset Text
19890
19891 \layout Standard
19892
19893 TMR3 overflow interrupt
19894 \end_inset 
19895 </cell>
19896 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19897 \begin_inset Text
19898
19899 \layout Standard
19900
19901 \end_inset 
19902 </cell>
19903 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19904 \begin_inset Text
19905
19906 \layout Standard
19907
19908 \end_inset 
19909 </cell>
19910 </row>
19911 </lyxtabular>
19912
19913 \end_inset 
19914
19915
19916 \layout Standard
19917
19918 The prototypes for these names are defined in the header file 
19919 \emph on 
19920 signal.h
19921 \emph default 
19922  .
19923 \layout Standard
19924
19925 In order to simplify signal handling, a number of macros is provided:
19926 \layout List
19927 \labelwidthstring 00.00.0000
19928
19929 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
19930  high priority interrupts.
19931  
19932 \emph on 
19933 name
19934 \emph default 
19935  is the function name to use.
19936 \layout List
19937 \labelwidthstring 00.00.0000
19938
19939 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
19940  low priority interrupt.
19941  
19942 \emph on 
19943 name
19944 \emph default 
19945  is the function name to use.
19946 \layout List
19947 \labelwidthstring 00.00.0000
19948
19949 DEF_HANDLER(sig,handler) define a handler for signal 
19950 \emph on 
19951 sig.
19952 \layout List
19953 \labelwidthstring 00.00.0000
19954
19955 END_DEF end the declaration of the dispatch table.
19956 \layout Standard
19957
19958 Additionally there are two more macros to simplify the declaration of the
19959  signal handler:
19960 \layout List
19961 \labelwidthstring 00.00.0000
19962
19963
19964 \series medium 
19965 SIGHANDLER(handler) 
19966 \series default 
19967 this declares the function prototype for the 
19968 \emph on 
19969 handler
19970 \emph default 
19971  function.
19972 \layout List
19973 \labelwidthstring 00.00.0000
19974
19975 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
19976 \layout Standard
19977
19978 An example of using the macros above is shown below:
19979 \layout LyX-Code
19980
19981 #include <pic18fregs.h>
19982 \layout LyX-Code
19983
19984 #include <signal.h>
19985 \newline 
19986
19987 \newline 
19988 DEF_INTHIGH(high_int)
19989 \layout LyX-Code
19990
19991 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
19992 \layout LyX-Code
19993
19994 DEF_HANDLER(SIG_BCOL, _bcol_handler)
19995 \layout LyX-Code
19996
19997 END_DEF
19998 \newline 
19999
20000 \newline 
20001 SIGHANDLER(_tmr0_handler)
20002 \layout LyX-Code
20003
20004 {
20005 \layout LyX-Code
20006
20007   /* action to be taken when timer 0 overflows */
20008 \layout LyX-Code
20009
20010 }
20011 \newline 
20012
20013 \newline 
20014 SIGHANDLERNAKED(_bcol_handler)
20015 \layout LyX-Code
20016
20017 {
20018 \layout LyX-Code
20019
20020   _asm
20021 \layout LyX-Code
20022
20023     /* action to be taken when bus collision occurs */
20024 \layout LyX-Code
20025
20026     retfie
20027 \layout LyX-Code
20028
20029  _endasm;
20030 \layout LyX-Code
20031
20032 }
20033 \layout Standard
20034
20035
20036 \series bold 
20037 NOTES:
20038 \series default 
20039  Special care should be taken when using the above scheme:
20040 \layout Itemize
20041
20042 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
20043 \layout Itemize
20044
20045 when declaring SIGHANDLERNAKED handler never forget to use 
20046 \emph on 
20047 retfie
20048 \emph default 
20049  for proper returning.
20050 \layout Subsection
20051
20052 PIC16 Port -- Tips
20053 \layout Standard
20054
20055 Here you can find some general tips for compiling programs with SDCC/pic16.
20056 \layout Subsubsection
20057
20058 Stack size
20059 \layout Standard
20060
20061 The default stack size (that is 64 bytes) probably is enough for many programs.
20062  One must take care that when there are many levels of function nesting,
20063  or there is excessive usage of stack, its size should be extended.
20064  An example of such a case is the printf/sprintf family of functions.
20065  If you encounter problems like not being able to print integers, then you
20066  need to set the stack size around the maximum (256 for small stack model).
20067  The following diagram shows what happens when calling printf to print an
20068  integer:
20069 \layout LyX-Code
20070
20071 printf () --> ltoa () --> ultoa () --> divschar ()
20072 \layout Standard
20073
20074 It is should be understood that stack is easily consumed when calling complicate
20075 d functions.
20076  Using command line arguments like -
20077 \begin_inset ERT
20078 status Collapsed
20079
20080 \layout Standard
20081
20082 \backslash 
20083 /
20084 \end_inset 
20085
20086 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
20087  stack frames.
20088  Other ways to reduce stack usage may exist.
20089 \layout Chapter
20090
20091 Debugging with SDCDB
20092 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
20093
20094 \end_inset 
20095
20096
20097 \begin_inset LatexCommand \index{sdcdb (debugger)}
20098
20099 \end_inset 
20100
20101  
20102 \layout Standard
20103
20104 SDCC is distributed with a source level debugger
20105 \begin_inset LatexCommand \index{Debugger}
20106
20107 \end_inset 
20108
20109 .
20110  The debugger uses a command line interface, the command repertoire of the
20111  debugger has been kept as close to gdb
20112 \begin_inset LatexCommand \index{gdb}
20113
20114 \end_inset 
20115
20116  (the GNU debugger) as possible.
20117  The configuration and build process is part of the standard compiler installati
20118 on, which also builds and installs the debugger in the target directory
20119  specified during configuration.
20120  The debugger allows you debug BOTH at the C source and at the ASM source
20121  level.
20122  Sdcdb is currently not available on Win32 platforms.
20123 \layout Section
20124
20125 Compiling for Debugging
20126 \layout Standard
20127
20128 The -
20129 \begin_inset ERT
20130 status Collapsed
20131
20132 \layout Standard
20133
20134 \backslash 
20135 /
20136 \end_inset 
20137
20138 -debug
20139 \begin_inset LatexCommand \index{-\/-debug}
20140
20141 \end_inset 
20142
20143  option must be specified for all files for which debug information is to
20144  be generated.
20145  The complier generates a .adb file for each of these files.
20146  The linker creates the .cdb
20147 \begin_inset LatexCommand \index{<file>.cdb}
20148
20149 \end_inset 
20150
20151  file from the .adb
20152 \begin_inset LatexCommand \index{<file>.adb}
20153
20154 \end_inset 
20155
20156  files and the address information.
20157  This .cdb is used by the debugger.
20158 \layout Section
20159
20160 How the Debugger Works
20161 \layout Standard
20162
20163 When the -
20164 \begin_inset ERT
20165 status Collapsed
20166
20167 \layout Standard
20168
20169 \backslash 
20170 /
20171 \end_inset 
20172
20173 -debug option is specified the compiler generates extra symbol information
20174  some of which are put into the assembler source and some are put into the
20175  .adb file.
20176   Then the linker creates the .cdb file from the individual .adb files with
20177  the address information for the symbols.
20178  The debugger reads the symbolic information generated by the compiler &
20179  the address information generated by the linker.
20180  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
20181  execution is controlled by the debugger.
20182  When a command is issued for the debugger, it translates it into appropriate
20183  commands for the simulator.
20184 \layout Section
20185
20186 Starting the Debugger
20187 \layout Standard
20188
20189 The debugger can be started using the following command line.
20190  (Assume the file you are debugging has the file name foo).
20191 \newline 
20192
20193 \newline 
20194
20195 \family sans 
20196 \series bold 
20197 sdcdb foo
20198 \newline 
20199
20200 \family default 
20201 \series default 
20202
20203 \newline 
20204 The debugger will look for the following files.
20205 \layout Itemize
20206
20207 foo.c - the source file.
20208 \layout Itemize
20209
20210 foo.cdb - the debugger symbol information file.
20211 \layout Itemize
20212
20213 foo.ihx - the Intel hex format
20214 \begin_inset LatexCommand \index{Intel hex format}
20215
20216 \end_inset 
20217
20218  object file.
20219 \layout Section
20220
20221 Command Line Options
20222 \layout Itemize
20223
20224 -
20225 \begin_inset ERT
20226 status Collapsed
20227
20228 \layout Standard
20229
20230 \backslash 
20231 /
20232 \end_inset 
20233
20234 -directory=<source file directory> this option can used to specify the directory
20235  search list.
20236  The debugger will look into the directory list specified for source, cdb
20237  & ihx files.
20238  The items in the directory list must be separated by ':', e.g.
20239  if the source files can be in the directories /home/src1 and /home/src2,
20240  the -
20241 \begin_inset ERT
20242 status Collapsed
20243
20244 \layout Standard
20245
20246 \backslash 
20247 /
20248 \end_inset 
20249
20250 -directory option should be -
20251 \begin_inset ERT
20252 status Collapsed
20253
20254 \layout Standard
20255
20256 \backslash 
20257 /
20258 \end_inset 
20259
20260 -directory=/home/src1:/home/src2.
20261  Note there can be no spaces in the option.
20262  
20263 \layout Itemize
20264
20265 -cd <directory> - change to the <directory>.
20266 \layout Itemize
20267
20268 -fullname - used by GUI front ends.
20269 \layout Itemize
20270
20271 -cpu <cpu-type> - this argument is passed to the simulator please see the
20272  simulator docs for details.
20273 \layout Itemize
20274
20275 -X <Clock frequency > this options is passed to the simulator please see
20276  the simulator docs for details.
20277 \layout Itemize
20278
20279 -s <serial port file> passed to simulator see the simulator docs for details.
20280 \layout Itemize
20281
20282 -S <serial in,out> passed to simulator see the simulator docs for details.
20283 \layout Itemize
20284
20285 -k <port number> passed to simulator see the simulator docs for details.
20286 \layout Section
20287
20288 Debugger Commands
20289 \layout Standard
20290
20291 As mentioned earlier the command interface for the debugger has been deliberatel
20292 y kept as close the GNU debugger gdb, as possible.
20293  This will help the integration with existing graphical user interfaces
20294  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
20295  If you use a graphical user interface for the debugger you can skip this
20296  section.
20297 \layout Subsubsection*
20298
20299 break [line | file:line | function | file:function]
20300 \layout Standard
20301
20302 Set breakpoint at specified line or function:
20303 \newline 
20304
20305 \newline 
20306
20307 \family sans 
20308 \series bold 
20309 sdcdb>break 100 
20310 \newline 
20311 sdcdb>break foo.c:100
20312 \newline 
20313 sdcdb>break funcfoo
20314 \newline 
20315 sdcdb>break foo.c:funcfoo
20316 \layout Subsubsection*
20317
20318 clear [line | file:line | function | file:function ]
20319 \layout Standard
20320
20321 Clear breakpoint at specified line or function:
20322 \newline 
20323
20324 \newline 
20325
20326 \family sans 
20327 \series bold 
20328 sdcdb>clear 100
20329 \newline 
20330 sdcdb>clear foo.c:100
20331 \newline 
20332 sdcdb>clear funcfoo
20333 \newline 
20334 sdcdb>clear foo.c:funcfoo
20335 \layout Subsubsection*
20336
20337 continue
20338 \layout Standard
20339
20340 Continue program being debugged, after breakpoint.
20341 \layout Subsubsection*
20342
20343 finish
20344 \layout Standard
20345
20346 Execute till the end of the current function.
20347 \layout Subsubsection*
20348
20349 delete [n]
20350 \layout Standard
20351
20352 Delete breakpoint number 'n'.
20353  If used without any option clear ALL user defined break points.
20354 \layout Subsubsection*
20355
20356 info [break | stack | frame | registers ]
20357 \layout Itemize
20358
20359 info break - list all breakpoints
20360 \layout Itemize
20361
20362 info stack - show the function call stack.
20363 \layout Itemize
20364
20365 info frame - show information about the current execution frame.
20366 \layout Itemize
20367
20368 info registers - show content of all registers.
20369 \layout Subsubsection*
20370
20371 step
20372 \layout Standard
20373
20374 Step program until it reaches a different source line.
20375  Note: pressing <return> repeats the last command.
20376 \layout Subsubsection*
20377
20378 next
20379 \layout Standard
20380
20381 Step program, proceeding through subroutine calls.
20382 \layout Subsubsection*
20383
20384 run
20385 \layout Standard
20386
20387 Start debugged program.
20388 \layout Subsubsection*
20389
20390 ptype variable 
20391 \layout Standard
20392
20393 Print type information of the variable.
20394 \layout Subsubsection*
20395
20396 print variable
20397 \layout Standard
20398
20399 print value of variable.
20400 \layout Subsubsection*
20401
20402 file filename
20403 \layout Standard
20404
20405 load the given file name.
20406  Note this is an alternate method of loading file for debugging.
20407 \layout Subsubsection*
20408
20409 frame
20410 \layout Standard
20411
20412 print information about current frame.
20413 \layout Subsubsection*
20414
20415 set srcmode
20416 \layout Standard
20417
20418 Toggle between C source & assembly source.
20419 \layout Subsubsection*
20420
20421 ! simulator command
20422 \layout Standard
20423
20424 Send the string following '!' to the simulator, the simulator response is
20425  displayed.
20426  Note the debugger does not interpret the command being sent to the simulator,
20427  so if a command like 'go' is sent the debugger can loose its execution
20428  context and may display incorrect values.
20429 \layout Subsubsection*
20430
20431 quit
20432 \layout Standard
20433
20434 "Watch me now.
20435  Iam going Down.
20436  My name is Bobby Brown"
20437 \layout Section
20438
20439 Interfacing with DDD
20440 \layout Comment
20441
20442 The screenshot was converted from png to eps with: 
20443 \begin_inset Quotes sld
20444 \end_inset 
20445
20446 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
20447 \begin_inset Quotes srd
20448 \end_inset 
20449
20450  which produces a pretty compact eps file which is free from compression
20451  artifacts.
20452 \layout Comment
20453
20454 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
20455  as this broke the build system on Sourceforge (pdf-file was broken).
20456 \layout Standard
20457
20458 The .eps File 
20459 \size footnotesize 
20460
20461 \begin_inset LatexCommand \url{http://cvs.sourceforge.net/viewcvs.py/*checkout*/sdcc/sdcc/doc/figures/ddd_example.eps}
20462
20463 \end_inset 
20464
20465
20466 \size default 
20467  shows a screenshot of a debugging session with DDD
20468 \begin_inset LatexCommand \index{DDD (debugger)}
20469
20470 \end_inset 
20471
20472  (Unix only) on a simulated 8032.
20473  The debugging session might not run as smoothly as the screenshot suggests.
20474  The debugger allows setting of breakpoints, displaying and changing variables,
20475  single stepping through C and assembler code.
20476  
20477 \newline 
20478 The source was compiled with 
20479 \family sans 
20480 \series bold 
20481
20482 \newline 
20483
20484 \newline 
20485 sdcc -
20486 \family default 
20487 \series default 
20488
20489 \begin_inset ERT
20490 status Collapsed
20491
20492 \layout Standard
20493
20494 \backslash 
20495 /
20496 \end_inset 
20497
20498
20499 \family sans 
20500 \series bold 
20501 -debug ddd_example.c
20502 \family default 
20503 \series default 
20504  
20505 \family sans 
20506 \series bold 
20507
20508 \newline 
20509
20510 \family default 
20511 \series default 
20512
20513 \newline 
20514 and DDD was invoked with 
20515 \family sans 
20516 \series bold 
20517
20518 \newline 
20519
20520 \newline 
20521 ddd -debugger 'sdcdb -cpu 8032 ddd_example'
20522 \layout Section
20523
20524 Interfacing with XEmacs
20525 \begin_inset LatexCommand \index{XEmacs}
20526
20527 \end_inset 
20528
20529
20530 \begin_inset LatexCommand \index{Emacs}
20531
20532 \end_inset 
20533
20534
20535 \layout Standard
20536
20537 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
20538  sdcdb.el and sdcdbsrc.el.
20539  These two files can be found in the $(prefix)/bin directory after the installat
20540 ion is complete.
20541  These files need to be loaded into XEmacs for the interface to work.
20542  This can be done at XEmacs startup time by inserting the following into
20543  your '.xemacs' file (which can be found in your HOME directory): 
20544 \newline 
20545
20546 \newline 
20547
20548 \family typewriter 
20549 (load-file sdcdbsrc.el) 
20550 \family default 
20551
20552 \newline 
20553
20554 \newline 
20555 .xemacs is a lisp file so the () around the command is REQUIRED.
20556  The files can also be loaded dynamically while XEmacs is running, set the
20557  environment variable 'EMACSLOADPATH' to the installation bin directory
20558  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
20559  To start the interface enter the following command: 
20560 \newline 
20561
20562 \newline 
20563
20564 \family sans 
20565 \series bold 
20566 ESC-x sdcdbsrc
20567 \family default 
20568 \series default 
20569
20570 \newline 
20571
20572 \newline 
20573 You will prompted to enter the file name to be debugged.
20574  
20575 \newline 
20576
20577 \newline 
20578 The command line options that are passed to the simulator directly are bound
20579  to default values in the file sdcdbsrc.el.
20580  The variables are listed below, these values maybe changed as required.
20581 \layout Itemize
20582
20583 sdcdbsrc-cpu-type '51
20584 \layout Itemize
20585
20586 sdcdbsrc-frequency '11059200
20587 \layout Itemize
20588
20589 sdcdbsrc-serial nil
20590 \layout Standard
20591
20592 The following is a list of key mapping for the debugger interface.
20593 \layout Standard
20594
20595 \SpecialChar ~
20596
20597 \family typewriter 
20598
20599 \newline 
20600 ;;\SpecialChar ~
20601 Current Listing :: 
20602 \newline 
20603 ;;key\SpecialChar ~
20604 \SpecialChar ~
20605 \SpecialChar ~
20606 \SpecialChar ~
20607 \SpecialChar ~
20608 \SpecialChar ~
20609 \SpecialChar ~
20610 \SpecialChar ~
20611 \SpecialChar ~
20612 \SpecialChar ~
20613 \SpecialChar ~
20614 \SpecialChar ~
20615 \SpecialChar ~
20616 \SpecialChar ~
20617 binding\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 \SpecialChar ~
20633 \SpecialChar ~
20634 \SpecialChar ~
20635 \SpecialChar ~
20636 \SpecialChar ~
20637 \SpecialChar ~
20638 \SpecialChar ~
20639 Comment 
20640 \newline 
20641 ;;---\SpecialChar ~
20642 \SpecialChar ~
20643 \SpecialChar ~
20644 \SpecialChar ~
20645 \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 \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 \SpecialChar ~
20677 -------
20678 \newline 
20679 ;; 
20680 \newline 
20681 ;;\SpecialChar ~
20682 n\SpecialChar ~
20683 \SpecialChar ~
20684 \SpecialChar ~
20685 \SpecialChar ~
20686 \SpecialChar ~
20687 \SpecialChar ~
20688 \SpecialChar ~
20689 \SpecialChar ~
20690 \SpecialChar ~
20691 \SpecialChar ~
20692 \SpecialChar ~
20693 \SpecialChar ~
20694 \SpecialChar ~
20695 \SpecialChar ~
20696 \SpecialChar ~
20697 sdcdb-next-from-src\SpecialChar ~
20698 \SpecialChar ~
20699 \SpecialChar ~
20700 \SpecialChar ~
20701 \SpecialChar ~
20702 \SpecialChar ~
20703 \SpecialChar ~
20704 \SpecialChar ~
20705 \SpecialChar ~
20706 \SpecialChar ~
20707 SDCDB next command 
20708 \newline 
20709 ;;\SpecialChar ~
20710 b\SpecialChar ~
20711 \SpecialChar ~
20712 \SpecialChar ~
20713 \SpecialChar ~
20714 \SpecialChar ~
20715 \SpecialChar ~
20716 \SpecialChar ~
20717 \SpecialChar ~
20718 \SpecialChar ~
20719 \SpecialChar ~
20720 \SpecialChar ~
20721 \SpecialChar ~
20722 \SpecialChar ~
20723 \SpecialChar ~
20724 \SpecialChar ~
20725 sdcdb-back-from-src\SpecialChar ~
20726 \SpecialChar ~
20727 \SpecialChar ~
20728 \SpecialChar ~
20729 \SpecialChar ~
20730 \SpecialChar ~
20731 \SpecialChar ~
20732 \SpecialChar ~
20733 \SpecialChar ~
20734 \SpecialChar ~
20735 SDCDB back command 
20736 \newline 
20737 ;;\SpecialChar ~
20738 c\SpecialChar ~
20739 \SpecialChar ~
20740 \SpecialChar ~
20741 \SpecialChar ~
20742 \SpecialChar ~
20743 \SpecialChar ~
20744 \SpecialChar ~
20745 \SpecialChar ~
20746 \SpecialChar ~
20747 \SpecialChar ~
20748 \SpecialChar ~
20749 \SpecialChar ~
20750 \SpecialChar ~
20751 \SpecialChar ~
20752 \SpecialChar ~
20753 sdcdb-cont-from-src\SpecialChar ~
20754 \SpecialChar ~
20755 \SpecialChar ~
20756 \SpecialChar ~
20757 \SpecialChar ~
20758 \SpecialChar ~
20759 \SpecialChar ~
20760 \SpecialChar ~
20761 \SpecialChar ~
20762 \SpecialChar ~
20763 SDCDB continue command
20764 \newline 
20765 ;;\SpecialChar ~
20766 s\SpecialChar ~
20767 \SpecialChar ~
20768 \SpecialChar ~
20769 \SpecialChar ~
20770 \SpecialChar ~
20771 \SpecialChar ~
20772 \SpecialChar ~
20773 \SpecialChar ~
20774 \SpecialChar ~
20775 \SpecialChar ~
20776 \SpecialChar ~
20777 \SpecialChar ~
20778 \SpecialChar ~
20779 \SpecialChar ~
20780 \SpecialChar ~
20781 sdcdb-step-from-src\SpecialChar ~
20782 \SpecialChar ~
20783 \SpecialChar ~
20784 \SpecialChar ~
20785 \SpecialChar ~
20786 \SpecialChar ~
20787 \SpecialChar ~
20788 \SpecialChar ~
20789 \SpecialChar ~
20790 \SpecialChar ~
20791 SDCDB step command 
20792 \newline 
20793 ;;\SpecialChar ~
20794 ?\SpecialChar ~
20795 \SpecialChar ~
20796 \SpecialChar ~
20797 \SpecialChar ~
20798 \SpecialChar ~
20799 \SpecialChar ~
20800 \SpecialChar ~
20801 \SpecialChar ~
20802 \SpecialChar ~
20803 \SpecialChar ~
20804 \SpecialChar ~
20805 \SpecialChar ~
20806 \SpecialChar ~
20807 \SpecialChar ~
20808 \SpecialChar ~
20809 sdcdb-whatis-c-sexp\SpecialChar ~
20810 \SpecialChar ~
20811 \SpecialChar ~
20812 \SpecialChar ~
20813 \SpecialChar ~
20814 \SpecialChar ~
20815 \SpecialChar ~
20816 \SpecialChar ~
20817 \SpecialChar ~
20818 \SpecialChar ~
20819 SDCDB ptypecommand for data at 
20820 \newline 
20821 ;;\SpecialChar ~
20822 \SpecialChar ~
20823 \SpecialChar ~
20824 \SpecialChar ~
20825 \SpecialChar ~
20826 \SpecialChar ~
20827 \SpecialChar ~
20828 \SpecialChar ~
20829 \SpecialChar ~
20830 \SpecialChar ~
20831 \SpecialChar ~
20832 \SpecialChar ~
20833 \SpecialChar ~
20834 \SpecialChar ~
20835 \SpecialChar ~
20836 \SpecialChar ~
20837 \SpecialChar ~
20838 \SpecialChar ~
20839 \SpecialChar ~
20840 \SpecialChar ~
20841 \SpecialChar ~
20842 \SpecialChar ~
20843 \SpecialChar ~
20844 \SpecialChar ~
20845 \SpecialChar ~
20846 \SpecialChar ~
20847 \SpecialChar ~
20848 \SpecialChar ~
20849 \SpecialChar ~
20850 \SpecialChar ~
20851 \SpecialChar ~
20852 \SpecialChar ~
20853 \SpecialChar ~
20854 \SpecialChar ~
20855 \SpecialChar ~
20856 \SpecialChar ~
20857 \SpecialChar ~
20858 \SpecialChar ~
20859 \SpecialChar ~
20860 \SpecialChar ~
20861 \SpecialChar ~
20862 \SpecialChar ~
20863 \SpecialChar ~
20864 \SpecialChar ~
20865 \SpecialChar ~
20866 \SpecialChar ~
20867 \SpecialChar ~
20868 buffer point 
20869 \newline 
20870 ;;\SpecialChar ~
20871 x\SpecialChar ~
20872 \SpecialChar ~
20873 \SpecialChar ~
20874 \SpecialChar ~
20875 \SpecialChar ~
20876 \SpecialChar ~
20877 \SpecialChar ~
20878 \SpecialChar ~
20879 \SpecialChar ~
20880 \SpecialChar ~
20881 \SpecialChar ~
20882 \SpecialChar ~
20883 \SpecialChar ~
20884 \SpecialChar ~
20885 \SpecialChar ~
20886 sdcdbsrc-delete\SpecialChar ~
20887 \SpecialChar ~
20888 \SpecialChar ~
20889 \SpecialChar ~
20890 \SpecialChar ~
20891 \SpecialChar ~
20892 \SpecialChar ~
20893 \SpecialChar ~
20894 \SpecialChar ~
20895 \SpecialChar ~
20896 \SpecialChar ~
20897 \SpecialChar ~
20898 \SpecialChar ~
20899 \SpecialChar ~
20900 SDCDB Delete all breakpoints if no arg 
20901 \newline 
20902 ;;\SpecialChar ~
20903 \SpecialChar ~
20904 \SpecialChar ~
20905 \SpecialChar ~
20906 \SpecialChar ~
20907 \SpecialChar ~
20908 \SpecialChar ~
20909 \SpecialChar ~
20910 \SpecialChar ~
20911 \SpecialChar ~
20912 \SpecialChar ~
20913 \SpecialChar ~
20914 \SpecialChar ~
20915 \SpecialChar ~
20916 \SpecialChar ~
20917 \SpecialChar ~
20918 \SpecialChar ~
20919 \SpecialChar ~
20920 \SpecialChar ~
20921 \SpecialChar ~
20922 \SpecialChar ~
20923 \SpecialChar ~
20924 \SpecialChar ~
20925 \SpecialChar ~
20926 \SpecialChar ~
20927 \SpecialChar ~
20928 \SpecialChar ~
20929 \SpecialChar ~
20930 \SpecialChar ~
20931 \SpecialChar ~
20932 \SpecialChar ~
20933 \SpecialChar ~
20934 \SpecialChar ~
20935 \SpecialChar ~
20936 \SpecialChar ~
20937 \SpecialChar ~
20938 \SpecialChar ~
20939 \SpecialChar ~
20940 \SpecialChar ~
20941 \SpecialChar ~
20942 \SpecialChar ~
20943 \SpecialChar ~
20944 \SpecialChar ~
20945 \SpecialChar ~
20946 \SpecialChar ~
20947 \SpecialChar ~
20948 \SpecialChar ~
20949 given or delete arg (C-u arg x) 
20950 \newline 
20951 ;;\SpecialChar ~
20952 m\SpecialChar ~
20953 \SpecialChar ~
20954 \SpecialChar ~
20955 \SpecialChar ~
20956 \SpecialChar ~
20957 \SpecialChar ~
20958 \SpecialChar ~
20959 \SpecialChar ~
20960 \SpecialChar ~
20961 \SpecialChar ~
20962 \SpecialChar ~
20963 \SpecialChar ~
20964 \SpecialChar ~
20965 \SpecialChar ~
20966 \SpecialChar ~
20967 sdcdbsrc-frame\SpecialChar ~
20968 \SpecialChar ~
20969 \SpecialChar ~
20970 \SpecialChar ~
20971 \SpecialChar ~
20972 \SpecialChar ~
20973 \SpecialChar ~
20974 \SpecialChar ~
20975 \SpecialChar ~
20976 \SpecialChar ~
20977 \SpecialChar ~
20978 \SpecialChar ~
20979 \SpecialChar ~
20980 \SpecialChar ~
20981 \SpecialChar ~
20982 SDCDB Display current frame if no arg, 
20983 \newline 
20984 ;;\SpecialChar ~
20985 \SpecialChar ~
20986 \SpecialChar ~
20987 \SpecialChar ~
20988 \SpecialChar ~
20989 \SpecialChar ~
20990 \SpecialChar ~
20991 \SpecialChar ~
20992 \SpecialChar ~
20993 \SpecialChar ~
20994 \SpecialChar ~
20995 \SpecialChar ~
20996 \SpecialChar ~
20997 \SpecialChar ~
20998 \SpecialChar ~
20999 \SpecialChar ~
21000 \SpecialChar ~
21001 \SpecialChar ~
21002 \SpecialChar ~
21003 \SpecialChar ~
21004 \SpecialChar ~
21005 \SpecialChar ~
21006 \SpecialChar ~
21007 \SpecialChar ~
21008 \SpecialChar ~
21009 \SpecialChar ~
21010 \SpecialChar ~
21011 \SpecialChar ~
21012 \SpecialChar ~
21013 \SpecialChar ~
21014 \SpecialChar ~
21015 \SpecialChar ~
21016 \SpecialChar ~
21017 \SpecialChar ~
21018 \SpecialChar ~
21019 \SpecialChar ~
21020 \SpecialChar ~
21021 \SpecialChar ~
21022 \SpecialChar ~
21023 \SpecialChar ~
21024 \SpecialChar ~
21025 \SpecialChar ~
21026 \SpecialChar ~
21027 \SpecialChar ~
21028 \SpecialChar ~
21029 \SpecialChar ~
21030 \SpecialChar ~
21031 given or display frame arg 
21032 \newline 
21033 ;;\SpecialChar ~
21034 \SpecialChar ~
21035 \SpecialChar ~
21036 \SpecialChar ~
21037 \SpecialChar ~
21038 \SpecialChar ~
21039 \SpecialChar ~
21040 \SpecialChar ~
21041 \SpecialChar ~
21042 \SpecialChar ~
21043 \SpecialChar ~
21044 \SpecialChar ~
21045 \SpecialChar ~
21046 \SpecialChar ~
21047 \SpecialChar ~
21048 \SpecialChar ~
21049 \SpecialChar ~
21050 \SpecialChar ~
21051 \SpecialChar ~
21052 \SpecialChar ~
21053 \SpecialChar ~
21054 \SpecialChar ~
21055 \SpecialChar ~
21056 \SpecialChar ~
21057 \SpecialChar ~
21058 \SpecialChar ~
21059 \SpecialChar ~
21060 \SpecialChar ~
21061 \SpecialChar ~
21062 \SpecialChar ~
21063 \SpecialChar ~
21064 \SpecialChar ~
21065 \SpecialChar ~
21066 \SpecialChar ~
21067 \SpecialChar ~
21068 \SpecialChar ~
21069 \SpecialChar ~
21070 \SpecialChar ~
21071 \SpecialChar ~
21072 \SpecialChar ~
21073 \SpecialChar ~
21074 \SpecialChar ~
21075 \SpecialChar ~
21076 \SpecialChar ~
21077 \SpecialChar ~
21078 \SpecialChar ~
21079 \SpecialChar ~
21080 buffer point 
21081 \newline 
21082 ;;\SpecialChar ~
21083 !\SpecialChar ~
21084 \SpecialChar ~
21085 \SpecialChar ~
21086 \SpecialChar ~
21087 \SpecialChar ~
21088 \SpecialChar ~
21089 \SpecialChar ~
21090 \SpecialChar ~
21091 \SpecialChar ~
21092 \SpecialChar ~
21093 \SpecialChar ~
21094 \SpecialChar ~
21095 \SpecialChar ~
21096 \SpecialChar ~
21097 \SpecialChar ~
21098 sdcdbsrc-goto-sdcdb\SpecialChar ~
21099 \SpecialChar ~
21100 \SpecialChar ~
21101 \SpecialChar ~
21102 \SpecialChar ~
21103 \SpecialChar ~
21104 \SpecialChar ~
21105 \SpecialChar ~
21106 \SpecialChar ~
21107 \SpecialChar ~
21108 Goto the SDCDB output buffer 
21109 \newline 
21110 ;;\SpecialChar ~
21111 p\SpecialChar ~
21112 \SpecialChar ~
21113 \SpecialChar ~
21114 \SpecialChar ~
21115 \SpecialChar ~
21116 \SpecialChar ~
21117 \SpecialChar ~
21118 \SpecialChar ~
21119 \SpecialChar ~
21120 \SpecialChar ~
21121 \SpecialChar ~
21122 \SpecialChar ~
21123 \SpecialChar ~
21124 \SpecialChar ~
21125 \SpecialChar ~
21126 sdcdb-print-c-sexp\SpecialChar ~
21127 \SpecialChar ~
21128 \SpecialChar ~
21129 \SpecialChar ~
21130 \SpecialChar ~
21131 \SpecialChar ~
21132 \SpecialChar ~
21133 \SpecialChar ~
21134 \SpecialChar ~
21135 \SpecialChar ~
21136 \SpecialChar ~
21137 SDCDB print command for data at 
21138 \newline 
21139 ;;\SpecialChar ~
21140 \SpecialChar ~
21141 \SpecialChar ~
21142 \SpecialChar ~
21143 \SpecialChar ~
21144 \SpecialChar ~
21145 \SpecialChar ~
21146 \SpecialChar ~
21147 \SpecialChar ~
21148 \SpecialChar ~
21149 \SpecialChar ~
21150 \SpecialChar ~
21151 \SpecialChar ~
21152 \SpecialChar ~
21153 \SpecialChar ~
21154 \SpecialChar ~
21155 \SpecialChar ~
21156 \SpecialChar ~
21157 \SpecialChar ~
21158 \SpecialChar ~
21159 \SpecialChar ~
21160 \SpecialChar ~
21161 \SpecialChar ~
21162 \SpecialChar ~
21163 \SpecialChar ~
21164 \SpecialChar ~
21165 \SpecialChar ~
21166 \SpecialChar ~
21167 \SpecialChar ~
21168 \SpecialChar ~
21169 \SpecialChar ~
21170 \SpecialChar ~
21171 \SpecialChar ~
21172 \SpecialChar ~
21173 \SpecialChar ~
21174 \SpecialChar ~
21175 \SpecialChar ~
21176 \SpecialChar ~
21177 \SpecialChar ~
21178 \SpecialChar ~
21179 \SpecialChar ~
21180 \SpecialChar ~
21181 \SpecialChar ~
21182 \SpecialChar ~
21183 \SpecialChar ~
21184 \SpecialChar ~
21185 \SpecialChar ~
21186 buffer point 
21187 \newline 
21188 ;;\SpecialChar ~
21189 g\SpecialChar ~
21190 \SpecialChar ~
21191 \SpecialChar ~
21192 \SpecialChar ~
21193 \SpecialChar ~
21194 \SpecialChar ~
21195 \SpecialChar ~
21196 \SpecialChar ~
21197 \SpecialChar ~
21198 \SpecialChar ~
21199 \SpecialChar ~
21200 \SpecialChar ~
21201 \SpecialChar ~
21202 \SpecialChar ~
21203 \SpecialChar ~
21204 sdcdbsrc-goto-sdcdb\SpecialChar ~
21205 \SpecialChar ~
21206 \SpecialChar ~
21207 \SpecialChar ~
21208 \SpecialChar ~
21209 \SpecialChar ~
21210 \SpecialChar ~
21211 \SpecialChar ~
21212 \SpecialChar ~
21213 \SpecialChar ~
21214 Goto the SDCDB output buffer 
21215 \newline 
21216 ;;\SpecialChar ~
21217 t\SpecialChar ~
21218 \SpecialChar ~
21219 \SpecialChar ~
21220 \SpecialChar ~
21221 \SpecialChar ~
21222 \SpecialChar ~
21223 \SpecialChar ~
21224 \SpecialChar ~
21225 \SpecialChar ~
21226 \SpecialChar ~
21227 \SpecialChar ~
21228 \SpecialChar ~
21229 \SpecialChar ~
21230 \SpecialChar ~
21231 \SpecialChar ~
21232 sdcdbsrc-mode\SpecialChar ~
21233 \SpecialChar ~
21234 \SpecialChar ~
21235 \SpecialChar ~
21236 \SpecialChar ~
21237 \SpecialChar ~
21238 \SpecialChar ~
21239 \SpecialChar ~
21240 \SpecialChar ~
21241 \SpecialChar ~
21242 \SpecialChar ~
21243 \SpecialChar ~
21244 \SpecialChar ~
21245 \SpecialChar ~
21246 \SpecialChar ~
21247 \SpecialChar ~
21248 Toggles Sdcdbsrc mode (turns it off) 
21249 \newline 
21250 ;; 
21251 \newline 
21252 ;;\SpecialChar ~
21253 C-c\SpecialChar ~
21254 C-f\SpecialChar ~
21255 \SpecialChar ~
21256 \SpecialChar ~
21257 \SpecialChar ~
21258 \SpecialChar ~
21259 \SpecialChar ~
21260 \SpecialChar ~
21261 \SpecialChar ~
21262 \SpecialChar ~
21263 sdcdb-finish-from-src\SpecialChar ~
21264 \SpecialChar ~
21265 \SpecialChar ~
21266 \SpecialChar ~
21267 \SpecialChar ~
21268 \SpecialChar ~
21269 \SpecialChar ~
21270 \SpecialChar ~
21271 SDCDB finish command 
21272 \newline 
21273 ;; 
21274 \newline 
21275 ;;\SpecialChar ~
21276 C-x\SpecialChar ~
21277 SPC\SpecialChar ~
21278 \SpecialChar ~
21279 \SpecialChar ~
21280 \SpecialChar ~
21281 \SpecialChar ~
21282 \SpecialChar ~
21283 \SpecialChar ~
21284 \SpecialChar ~
21285 \SpecialChar ~
21286 sdcdb-break\SpecialChar ~
21287 \SpecialChar ~
21288 \SpecialChar ~
21289 \SpecialChar ~
21290 \SpecialChar ~
21291 \SpecialChar ~
21292 \SpecialChar ~
21293 \SpecialChar ~
21294 \SpecialChar ~
21295 \SpecialChar ~
21296 \SpecialChar ~
21297 \SpecialChar ~
21298 \SpecialChar ~
21299 \SpecialChar ~
21300 \SpecialChar ~
21301 \SpecialChar ~
21302 \SpecialChar ~
21303 \SpecialChar ~
21304 Set break for line with point 
21305 \newline 
21306 ;;\SpecialChar ~
21307 ESC\SpecialChar ~
21308 t\SpecialChar ~
21309 \SpecialChar ~
21310 \SpecialChar ~
21311 \SpecialChar ~
21312 \SpecialChar ~
21313 \SpecialChar ~
21314 \SpecialChar ~
21315 \SpecialChar ~
21316 \SpecialChar ~
21317 \SpecialChar ~
21318 \SpecialChar ~
21319 sdcdbsrc-mode\SpecialChar ~
21320 \SpecialChar ~
21321 \SpecialChar ~
21322 \SpecialChar ~
21323 \SpecialChar ~
21324 \SpecialChar ~
21325 \SpecialChar ~
21326 \SpecialChar ~
21327 \SpecialChar ~
21328 \SpecialChar ~
21329 \SpecialChar ~
21330 \SpecialChar ~
21331 \SpecialChar ~
21332 \SpecialChar ~
21333 \SpecialChar ~
21334 \SpecialChar ~
21335 Toggle Sdcdbsrc mode 
21336 \newline 
21337 ;;\SpecialChar ~
21338 ESC\SpecialChar ~
21339 m\SpecialChar ~
21340 \SpecialChar ~
21341 \SpecialChar ~
21342 \SpecialChar ~
21343 \SpecialChar ~
21344 \SpecialChar ~
21345 \SpecialChar ~
21346 \SpecialChar ~
21347 \SpecialChar ~
21348 \SpecialChar ~
21349 \SpecialChar ~
21350 sdcdbsrc-srcmode\SpecialChar ~
21351 \SpecialChar ~
21352 \SpecialChar ~
21353 \SpecialChar ~
21354 \SpecialChar ~
21355 \SpecialChar ~
21356 \SpecialChar ~
21357 \SpecialChar ~
21358 \SpecialChar ~
21359 \SpecialChar ~
21360 \SpecialChar ~
21361 \SpecialChar ~
21362 \SpecialChar ~
21363 Toggle list mode 
21364 \newline 
21365 ;; 
21366 \newline 
21367
21368 \layout Chapter
21369 \pagebreak_top 
21370 TIPS
21371 \layout Standard
21372
21373 Here are a few guidelines that will help the compiler generate more efficient
21374  code, some of the tips are specific to this compiler others are generally
21375  good programming practice.
21376 \layout Itemize
21377
21378 Use the smallest data type to represent your data-value.
21379  If it is known in advance that the value is going to be less than 256 then
21380  use an 'unsigned char' instead of a 'short' or 'int'.
21381  Please note, that ANSI C requires both signed and unsigned chars to be
21382  promoted to 'signed int' before doing any operation.
21383  This promotion
21384 \begin_inset LatexCommand \index{type promotion}
21385
21386 \end_inset 
21387
21388  can be omitted, if the result is the same.
21389  The effect of the promotion rules together with the sign-extension is often
21390  surprising:
21391 \begin_deeper 
21392 \layout Verse
21393
21394
21395 \family typewriter 
21396 unsigned char uc = 0xfe;
21397 \newline 
21398 if (uc * uc < 0) /* this is true! */
21399 \newline 
21400 {
21401 \newline 
21402 \SpecialChar ~
21403 \SpecialChar ~
21404 \SpecialChar ~
21405 \SpecialChar ~
21406 ....
21407 \newline 
21408 }
21409 \layout Standard
21410
21411
21412 \family typewriter 
21413 uc * uc
21414 \family default 
21415  is evaluated as 
21416 \family typewriter 
21417 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
21418 \family default 
21419 .
21420  
21421 \newline 
21422 Another one:
21423 \layout Verse
21424
21425
21426 \family typewriter 
21427 (unsigned char) -12 / (signed char) -3 = ...
21428 \layout Standard
21429
21430 No, the result is not 4:
21431 \layout Verse
21432
21433
21434 \family typewriter 
21435 (int) (unsigned char) -12 / (int) (signed char) -3 =
21436 \newline 
21437 (int) (unsigned char) 0xf4 / (int) (signed char) 0xfd =
21438 \newline 
21439 (int) 0x00f4 / (int) 0xfffd =
21440 \newline 
21441 (int) 0x00f4 / (int) 0xfffd =
21442 \newline 
21443 (int) 244 / (int) -3 =
21444 \newline 
21445 (int) -81 = (int) 0xffaf;
21446 \layout Standard
21447
21448 Don't complain, that gcc gives you a different result.
21449  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
21450  Therefore the results are different.
21451 \newline 
21452 From 
21453 \begin_inset Quotes sld
21454 \end_inset 
21455
21456 comp.lang.c FAQ
21457 \begin_inset Quotes srd
21458 \end_inset 
21459
21460 :
21461 \layout Quote
21462
21463 If well-defined overflow characteristics are important and negative values
21464  are not, or if you want to steer clear of sign-extension problems when
21465  manipulating bits or bytes, use one of the corresponding unsigned types.
21466  (Beware when mixing signed and unsigned values in expressions, though.)
21467 \newline 
21468 Although character types (especially unsigned char) can be used as "tiny"
21469  integers, doing so is sometimes more trouble than it's worth, due to unpredicta
21470 ble sign extension and increased code size.
21471 \end_deeper 
21472 \layout Itemize
21473
21474 Use unsigned when it is known in advance that the value is not going to
21475  be negative.
21476  This helps especially if you are doing division or multiplication, bit-shifting
21477  or are using an array index.
21478 \layout Itemize
21479
21480 NEVER jump into a LOOP.
21481 \layout Itemize
21482
21483 Declare the variables to be local
21484 \begin_inset LatexCommand \index{local variables}
21485
21486 \end_inset 
21487
21488  whenever possible, especially loop control variables (induction).
21489 \layout Itemize
21490
21491 Since the compiler does not always do implicit integral promotion, the programme
21492 r should do an explicit cast when integral promotion is required.
21493 \layout Itemize
21494
21495 Reducing the size of division, multiplication & modulus operations can reduce
21496  code size substantially.
21497  Take the following code for example.
21498 \begin_deeper 
21499 \layout Verse
21500
21501
21502 \family typewriter 
21503 foobar(unsigned int p1, unsigned char ch)
21504 \newline 
21505 {
21506 \newline 
21507 \SpecialChar ~
21508 \SpecialChar ~
21509 \SpecialChar ~
21510 \SpecialChar ~
21511 unsigned char ch1 = p1 % ch ;
21512 \newline 
21513 \SpecialChar ~
21514 \SpecialChar ~
21515 \SpecialChar ~
21516 \SpecialChar ~
21517 ....
21518 \newline 
21519 }
21520 \layout Standard
21521
21522 For the modulus operation the variable ch will be promoted to unsigned int
21523  first then the modulus operation will be performed (this will lead to a
21524  call to support routine _moduint()), and the result will be casted to a
21525  char.
21526  If the code is changed to 
21527 \layout Verse
21528
21529
21530 \family typewriter 
21531 foobar(unsigned int p1, unsigned char ch)
21532 \newline 
21533 {
21534 \newline 
21535 \SpecialChar ~
21536 \SpecialChar ~
21537 \SpecialChar ~
21538 \SpecialChar ~
21539 unsigned char ch1 = (unsigned char)p1 % ch ;
21540 \newline 
21541 \SpecialChar ~
21542 \SpecialChar ~
21543 \SpecialChar ~
21544 \SpecialChar ~
21545 ....
21546 \newline 
21547 }
21548 \layout Standard
21549
21550 It would substantially reduce the code generated (future versions of the
21551  compiler will be smart enough to detect such optimization opportunities).
21552 \end_deeper 
21553 \layout Itemize
21554
21555 Have a look at the assembly listing to get a 
21556 \begin_inset Quotes sld
21557 \end_inset 
21558
21559 feeling
21560 \begin_inset Quotes srd
21561 \end_inset 
21562
21563  for the code generation.
21564 \layout Section
21565
21566 Tools
21567 \begin_inset LatexCommand \index{Tools}
21568
21569 \end_inset 
21570
21571  included in the distribution
21572 \layout Standard
21573 \align center 
21574
21575 \begin_inset  Tabular
21576 <lyxtabular version="3" rows="12" columns="3">
21577 <features>
21578 <column alignment="center" valignment="top" leftline="true" width="0pt">
21579 <column alignment="center" valignment="top" leftline="true" width="0pt">
21580 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
21581 <row topline="true" bottomline="true">
21582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21583 \begin_inset Text
21584
21585 \layout Standard
21586
21587 Name
21588 \end_inset 
21589 </cell>
21590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21591 \begin_inset Text
21592
21593 \layout Standard
21594
21595 Purpose
21596 \end_inset 
21597 </cell>
21598 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21599 \begin_inset Text
21600
21601 \layout Standard
21602
21603 Directory
21604 \end_inset 
21605 </cell>
21606 </row>
21607 <row topline="true">
21608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21609 \begin_inset Text
21610
21611 \layout Standard
21612
21613 uCsim
21614 \end_inset 
21615 </cell>
21616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21617 \begin_inset Text
21618
21619 \layout Standard
21620
21621 Simulator for various architectures
21622 \end_inset 
21623 </cell>
21624 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21625 \begin_inset Text
21626
21627 \layout Standard
21628
21629 sdcc/sim/ucsim
21630 \end_inset 
21631 </cell>
21632 </row>
21633 <row topline="true">
21634 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21635 \begin_inset Text
21636
21637 \layout Standard
21638
21639 keil2sdcc.pl
21640 \end_inset 
21641 </cell>
21642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21643 \begin_inset Text
21644
21645 \layout Standard
21646
21647 header file conversion
21648 \end_inset 
21649 </cell>
21650 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21651 \begin_inset Text
21652
21653 \layout Standard
21654
21655 sdcc/support/scripts
21656 \end_inset 
21657 </cell>
21658 </row>
21659 <row topline="true">
21660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21661 \begin_inset Text
21662
21663 \layout Standard
21664
21665 mh2h.c
21666 \end_inset 
21667 </cell>
21668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21669 \begin_inset Text
21670
21671 \layout Standard
21672
21673 header file conversion
21674 \end_inset 
21675 </cell>
21676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21677 \begin_inset Text
21678
21679 \layout Standard
21680
21681 sdcc/support/scripts
21682 \end_inset 
21683 </cell>
21684 </row>
21685 <row topline="true">
21686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21687 \begin_inset Text
21688
21689 \layout Standard
21690
21691 as-gbz80
21692 \end_inset 
21693 </cell>
21694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21695 \begin_inset Text
21696
21697 \layout Standard
21698
21699 Assembler
21700 \end_inset 
21701 </cell>
21702 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21703 \begin_inset Text
21704
21705 \layout Standard
21706
21707
21708 \family roman 
21709 \series medium 
21710 \shape up 
21711 \size normal 
21712 \emph off 
21713 \bar no 
21714 \noun off 
21715 \color none
21716 sdcc/bin
21717 \end_inset 
21718 </cell>
21719 </row>
21720 <row topline="true">
21721 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21722 \begin_inset Text
21723
21724 \layout Standard
21725
21726 as-z80
21727 \end_inset 
21728 </cell>
21729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21730 \begin_inset Text
21731
21732 \layout Standard
21733
21734 Assembler
21735 \end_inset 
21736 </cell>
21737 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21738 \begin_inset Text
21739
21740 \layout Standard
21741
21742
21743 \family roman 
21744 \series medium 
21745 \shape up 
21746 \size normal 
21747 \emph off 
21748 \bar no 
21749 \noun off 
21750 \color none
21751 sdcc/bin
21752 \end_inset 
21753 </cell>
21754 </row>
21755 <row topline="true">
21756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21757 \begin_inset Text
21758
21759 \layout Standard
21760
21761 asx8051
21762 \end_inset 
21763 </cell>
21764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21765 \begin_inset Text
21766
21767 \layout Standard
21768
21769 Assembler
21770 \end_inset 
21771 </cell>
21772 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21773 \begin_inset Text
21774
21775 \layout Standard
21776
21777
21778 \family roman 
21779 \series medium 
21780 \shape up 
21781 \size normal 
21782 \emph off 
21783 \bar no 
21784 \noun off 
21785 \color none
21786 sdcc/bin
21787 \end_inset 
21788 </cell>
21789 </row>
21790 <row topline="true">
21791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21792 \begin_inset Text
21793
21794 \layout Standard
21795
21796 sdcdb
21797 \end_inset 
21798 </cell>
21799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21800 \begin_inset Text
21801
21802 \layout Standard
21803
21804 Simulator
21805 \end_inset 
21806 </cell>
21807 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21808 \begin_inset Text
21809
21810 \layout Standard
21811
21812
21813 \family roman 
21814 \series medium 
21815 \shape up 
21816 \size normal 
21817 \emph off 
21818 \bar no 
21819 \noun off 
21820 \color none
21821 sdcc/bin
21822 \end_inset 
21823 </cell>
21824 </row>
21825 <row topline="true">
21826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21827 \begin_inset Text
21828
21829 \layout Standard
21830
21831 aslink
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 Linker
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 \family roman 
21849 \series medium 
21850 \shape up 
21851 \size normal 
21852 \emph off 
21853 \bar no 
21854 \noun off 
21855 \color none
21856 sdcc/bin
21857 \end_inset 
21858 </cell>
21859 </row>
21860 <row topline="true">
21861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21862 \begin_inset Text
21863
21864 \layout Standard
21865
21866 link-z80
21867 \end_inset 
21868 </cell>
21869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21870 \begin_inset Text
21871
21872 \layout Standard
21873
21874 Linker
21875 \end_inset 
21876 </cell>
21877 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21878 \begin_inset Text
21879
21880 \layout Standard
21881
21882
21883 \family roman 
21884 \series medium 
21885 \shape up 
21886 \size normal 
21887 \emph off 
21888 \bar no 
21889 \noun off 
21890 \color none
21891 sdcc/bin
21892 \end_inset 
21893 </cell>
21894 </row>
21895 <row topline="true">
21896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21897 \begin_inset Text
21898
21899 \layout Standard
21900
21901 link-gbz80
21902 \end_inset 
21903 </cell>
21904 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21905 \begin_inset Text
21906
21907 \layout Standard
21908
21909 Linker
21910 \end_inset 
21911 </cell>
21912 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21913 \begin_inset Text
21914
21915 \layout Standard
21916
21917
21918 \family roman 
21919 \series medium 
21920 \shape up 
21921 \size normal 
21922 \emph off 
21923 \bar no 
21924 \noun off 
21925 \color none
21926 sdcc/bin
21927 \end_inset 
21928 </cell>
21929 </row>
21930 <row topline="true" bottomline="true">
21931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21932 \begin_inset Text
21933
21934 \layout Standard
21935
21936 packihx
21937 \end_inset 
21938 </cell>
21939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21940 \begin_inset Text
21941
21942 \layout Standard
21943
21944 ihx packer
21945 \end_inset 
21946 </cell>
21947 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21948 \begin_inset Text
21949
21950 \layout Standard
21951
21952
21953 \family roman 
21954 \series medium 
21955 \shape up 
21956 \size normal 
21957 \emph off 
21958 \bar no 
21959 \noun off 
21960 \color none
21961 sdcc/bin
21962 \end_inset 
21963 </cell>
21964 </row>
21965 </lyxtabular>
21966
21967 \end_inset 
21968
21969
21970 \newline 
21971
21972 \layout Section
21973
21974 Documentation
21975 \begin_inset LatexCommand \index{Documentation}
21976
21977 \end_inset 
21978
21979  included in the distribution
21980 \layout Standard
21981 \align center 
21982
21983 \begin_inset  Tabular
21984 <lyxtabular version="3" rows="10" columns="2">
21985 <features>
21986 <column alignment="left" valignment="top" leftline="true" width="0">
21987 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
21988 <row topline="true" bottomline="true">
21989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21990 \begin_inset Text
21991
21992 \layout Standard
21993
21994 Subject / Title
21995 \end_inset 
21996 </cell>
21997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21998 \begin_inset Text
21999
22000 \layout Standard
22001
22002 Where to get / filename
22003 \end_inset 
22004 </cell>
22005 </row>
22006 <row topline="true">
22007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22008 \begin_inset Text
22009
22010 \layout Standard
22011
22012 SDCC Compiler User Guide
22013 \end_inset 
22014 </cell>
22015 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22016 \begin_inset Text
22017
22018 \layout Standard
22019
22020 You're reading it right now
22021 \end_inset 
22022 </cell>
22023 </row>
22024 <row topline="true">
22025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22026 \begin_inset Text
22027
22028 \layout Standard
22029
22030 Changelog of SDCC
22031 \end_inset 
22032 </cell>
22033 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22034 \begin_inset Text
22035
22036 \layout Standard
22037
22038 sdcc/Changelog
22039 \end_inset 
22040 </cell>
22041 </row>
22042 <row topline="true">
22043 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22044 \begin_inset Text
22045
22046 \layout Standard
22047
22048 ASXXXX
22049 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
22050
22051 \end_inset 
22052
22053
22054 \begin_inset LatexCommand \index{Assembler documentation}
22055
22056 \end_inset 
22057
22058  Assemblers and ASLINK
22059 \begin_inset LatexCommand \index{aslink}
22060
22061 \end_inset 
22062
22063
22064 \begin_inset LatexCommand \index{Linker documentation}
22065
22066 \end_inset 
22067
22068  Relocating Linker
22069 \end_inset 
22070 </cell>
22071 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22072 \begin_inset Text
22073
22074 \layout Standard
22075
22076 sdcc/as/doc/asxhtm.html
22077 \end_inset 
22078 </cell>
22079 </row>
22080 <row topline="true">
22081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22082 \begin_inset Text
22083
22084 \layout Standard
22085
22086 SDCC regression test
22087 \begin_inset LatexCommand \index{Regression test}
22088
22089 \end_inset 
22090
22091
22092 \end_inset 
22093 </cell>
22094 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22095 \begin_inset Text
22096
22097 \layout Standard
22098
22099 sdcc/doc/test_suite_spec.pdf
22100 \end_inset 
22101 </cell>
22102 </row>
22103 <row topline="true">
22104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22105 \begin_inset Text
22106
22107 \layout Standard
22108
22109 Various notes
22110 \end_inset 
22111 </cell>
22112 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22113 \begin_inset Text
22114
22115 \layout Standard
22116
22117 sdcc/doc/*
22118 \end_inset 
22119 </cell>
22120 </row>
22121 <row topline="true">
22122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22123 \begin_inset Text
22124
22125 \layout Standard
22126
22127 Notes on debugging with sdcdb
22128 \begin_inset LatexCommand \index{sdcdb (debugger)}
22129
22130 \end_inset 
22131
22132
22133 \end_inset 
22134 </cell>
22135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22136 \begin_inset Text
22137
22138 \layout Standard
22139
22140 sdcc/debugger/README
22141 \end_inset 
22142 </cell>
22143 </row>
22144 <row topline="true">
22145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22146 \begin_inset Text
22147
22148 \layout Standard
22149
22150 Software simulator for microcontrollers
22151 \end_inset 
22152 </cell>
22153 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22154 \begin_inset Text
22155
22156 \layout Standard
22157
22158
22159 \family roman 
22160 \series medium 
22161 \shape up 
22162 \size normal 
22163 \emph off 
22164 \bar no 
22165 \noun off 
22166 \color none
22167 sdcc/sim/ucsim/doc
22168 \family default 
22169 \series default 
22170 \shape default 
22171 \size default 
22172 \emph default 
22173 \bar default 
22174 \noun default 
22175 \color default
22176 /index.html
22177 \end_inset 
22178 </cell>
22179 </row>
22180 <row topline="true">
22181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22182 \begin_inset Text
22183
22184 \layout Standard
22185
22186 Temporary notes on the pic16
22187 \begin_inset LatexCommand \index{PIC16}
22188
22189 \end_inset 
22190
22191  port
22192 \end_inset 
22193 </cell>
22194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22195 \begin_inset Text
22196
22197 \layout Standard
22198
22199 sdcc/src/pic16/NOTES
22200 \end_inset 
22201 </cell>
22202 </row>
22203 <row topline="true" bottomline="true">
22204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22205 \begin_inset Text
22206
22207 \layout Standard
22208
22209 SDCC internal documentation (debugging file format)
22210 \end_inset 
22211 </cell>
22212 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22213 \begin_inset Text
22214
22215 \layout Standard
22216
22217 sdcc/doc/
22218 \family roman 
22219 \series medium 
22220 \shape up 
22221 \size normal 
22222 \emph off 
22223 \bar no 
22224 \noun off 
22225 \color none
22226 cdbfileformat.pd
22227 \family default 
22228 \series default 
22229 \shape default 
22230 \size default 
22231 \emph default 
22232 \bar default 
22233 \noun default 
22234 \color default
22235 f
22236 \end_inset 
22237 </cell>
22238 </row>
22239 </lyxtabular>
22240
22241 \end_inset 
22242
22243
22244 \newline 
22245
22246 \layout Section
22247
22248 Related open source tools
22249 \begin_inset LatexCommand \index{Related tools}
22250
22251 \end_inset 
22252
22253
22254 \layout Standard
22255 \align center 
22256
22257 \begin_inset  Tabular
22258 <lyxtabular version="3" rows="11" columns="3">
22259 <features>
22260 <column alignment="center" valignment="top" leftline="true" width="0pt">
22261 <column alignment="block" valignment="top" leftline="true" width="30line%">
22262 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
22263 <row topline="true" bottomline="true">
22264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22265 \begin_inset Text
22266
22267 \layout Standard
22268
22269 Name
22270 \end_inset 
22271 </cell>
22272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22273 \begin_inset Text
22274
22275 \layout Standard
22276
22277 Purpose
22278 \end_inset 
22279 </cell>
22280 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22281 \begin_inset Text
22282
22283 \layout Standard
22284
22285 Where to get
22286 \end_inset 
22287 </cell>
22288 </row>
22289 <row topline="true">
22290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22291 \begin_inset Text
22292
22293 \layout Standard
22294
22295 gpsim
22296 \begin_inset LatexCommand \index{gpsim (pic simulator)}
22297
22298 \end_inset 
22299
22300
22301 \end_inset 
22302 </cell>
22303 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22304 \begin_inset Text
22305
22306 \layout Standard
22307
22308 PIC simulator
22309 \end_inset 
22310 </cell>
22311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22312 \begin_inset Text
22313
22314 \layout Standard
22315
22316
22317 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
22318
22319 \end_inset 
22320
22321
22322 \end_inset 
22323 </cell>
22324 </row>
22325 <row topline="true">
22326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22327 \begin_inset Text
22328
22329 \layout Standard
22330
22331 gputils
22332 \begin_inset LatexCommand \index{gputils (pic tools)}
22333
22334 \end_inset 
22335
22336
22337 \end_inset 
22338 </cell>
22339 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22340 \begin_inset Text
22341
22342 \layout Standard
22343
22344 GNU PIC utilities
22345 \end_inset 
22346 </cell>
22347 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22348 \begin_inset Text
22349
22350 \layout Standard
22351
22352
22353 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
22354
22355 \end_inset 
22356
22357
22358 \end_inset 
22359 </cell>
22360 </row>
22361 <row topline="true">
22362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22363 \begin_inset Text
22364
22365 \layout Standard
22366
22367 flP5
22368 \end_inset 
22369 </cell>
22370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22371 \begin_inset Text
22372
22373 \layout Standard
22374
22375 PIC programmer
22376 \end_inset 
22377 </cell>
22378 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22379 \begin_inset Text
22380
22381 \layout Standard
22382
22383
22384 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
22385
22386 \end_inset 
22387
22388
22389 \end_inset 
22390 </cell>
22391 </row>
22392 <row topline="true">
22393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22394 \begin_inset Text
22395
22396 \layout Standard
22397
22398 indent
22399 \begin_inset LatexCommand \index{indent (source formatting tool)}
22400
22401 \end_inset 
22402
22403
22404 \end_inset 
22405 </cell>
22406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22407 \begin_inset Text
22408
22409 \layout Standard
22410
22411 Formats C source - Master of the white spaces
22412 \end_inset 
22413 </cell>
22414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22415 \begin_inset Text
22416
22417 \layout Standard
22418
22419
22420 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
22421
22422 \end_inset 
22423
22424
22425 \end_inset 
22426 </cell>
22427 </row>
22428 <row topline="true">
22429 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22430 \begin_inset Text
22431
22432 \layout Standard
22433
22434 srecord
22435 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
22436
22437 \end_inset 
22438
22439
22440 \end_inset 
22441 </cell>
22442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22443 \begin_inset Text
22444
22445 \layout Standard
22446
22447 Object file conversion, checksumming, ...
22448 \end_inset 
22449 </cell>
22450 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22451 \begin_inset Text
22452
22453 \layout Standard
22454
22455
22456 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
22457
22458 \end_inset 
22459
22460
22461 \end_inset 
22462 </cell>
22463 </row>
22464 <row topline="true">
22465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22466 \begin_inset Text
22467
22468 \layout Standard
22469
22470 objdump
22471 \begin_inset LatexCommand \index{objdump (tool)}
22472
22473 \end_inset 
22474
22475
22476 \end_inset 
22477 </cell>
22478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22479 \begin_inset Text
22480
22481 \layout Standard
22482
22483 Object file conversion, ...
22484 \end_inset 
22485 </cell>
22486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22487 \begin_inset Text
22488
22489 \layout Standard
22490
22491 Part of binutils (should be there anyway)
22492 \end_inset 
22493 </cell>
22494 </row>
22495 <row topline="true">
22496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22497 \begin_inset Text
22498
22499 \layout Standard
22500
22501 doxygen
22502 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
22503
22504 \end_inset 
22505
22506
22507 \end_inset 
22508 </cell>
22509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22510 \begin_inset Text
22511
22512 \layout Standard
22513
22514 Source code documentation system
22515 \end_inset 
22516 </cell>
22517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22518 \begin_inset Text
22519
22520 \layout Standard
22521
22522
22523 \begin_inset LatexCommand \url{http://www.doxygen.org}
22524
22525 \end_inset 
22526
22527
22528 \end_inset 
22529 </cell>
22530 </row>
22531 <row topline="true">
22532 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22533 \begin_inset Text
22534
22535 \layout Standard
22536
22537 kdevelop
22538 \end_inset 
22539 </cell>
22540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22541 \begin_inset Text
22542
22543 \layout Standard
22544
22545 IDE (has anyone tried integrating SDCC & sdcdb? Unix only)
22546 \end_inset 
22547 </cell>
22548 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22549 \begin_inset Text
22550
22551 \layout Standard
22552
22553
22554 \begin_inset LatexCommand \url{http://www.kdevelop.org}
22555
22556 \end_inset 
22557
22558
22559 \end_inset 
22560 </cell>
22561 </row>
22562 <row topline="true">
22563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22564 \begin_inset Text
22565
22566 \layout Standard
22567
22568 splint
22569 \begin_inset LatexCommand \index{splint (syntax checking tool)}
22570
22571 \end_inset 
22572
22573
22574 \end_inset 
22575 </cell>
22576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22577 \begin_inset Text
22578
22579 \layout Standard
22580
22581 Statically checks c sources (see 
22582 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
22583
22584 \end_inset 
22585
22586 )
22587 \end_inset 
22588 </cell>
22589 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22590 \begin_inset Text
22591
22592 \layout Standard
22593
22594
22595 \begin_inset LatexCommand \url{http://www.splint.org}
22596
22597 \end_inset 
22598
22599
22600 \end_inset 
22601 </cell>
22602 </row>
22603 <row topline="true" bottomline="true">
22604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22605 \begin_inset Text
22606
22607 \layout Standard
22608
22609 ddd
22610 \begin_inset LatexCommand \index{ddd (debugger)}
22611
22612 \end_inset 
22613
22614
22615 \end_inset 
22616 </cell>
22617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22618 \begin_inset Text
22619
22620 \layout Standard
22621
22622 Debugger, serves nicely as GUI to sdcdb
22623 \begin_inset LatexCommand \index{sdcdb (debugger)}
22624
22625 \end_inset 
22626
22627  (Unix only)
22628 \end_inset 
22629 </cell>
22630 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22631 \begin_inset Text
22632
22633 \layout Standard
22634
22635
22636 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
22637
22638 \end_inset 
22639
22640
22641 \end_inset 
22642 </cell>
22643 </row>
22644 </lyxtabular>
22645
22646 \end_inset 
22647
22648
22649 \newline 
22650
22651 \layout Section
22652
22653 Related documentation / recommended reading
22654 \layout Standard
22655 \align center 
22656
22657 \begin_inset  Tabular
22658 <lyxtabular version="3" rows="6" columns="3">
22659 <features>
22660 <column alignment="center" valignment="top" leftline="true" width="0pt">
22661 <column alignment="block" valignment="top" leftline="true" width="30line%">
22662 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
22663 <row topline="true" bottomline="true">
22664 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22665 \begin_inset Text
22666
22667 \layout Standard
22668
22669 Name
22670 \end_inset 
22671 </cell>
22672 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22673 \begin_inset Text
22674
22675 \layout Standard
22676
22677 Subject / Title
22678 \end_inset 
22679 </cell>
22680 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22681 \begin_inset Text
22682
22683 \layout Standard
22684
22685 Where to get
22686 \end_inset 
22687 </cell>
22688 </row>
22689 <row topline="true">
22690 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22691 \begin_inset Text
22692
22693 \layout Standard
22694
22695
22696 \family roman 
22697 \series medium 
22698 \shape up 
22699 \size normal 
22700 \emph off 
22701 \bar no 
22702 \noun off 
22703 \color none
22704 c-refcard.pdf
22705 \end_inset 
22706 </cell>
22707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22708 \begin_inset Text
22709
22710 \layout Standard
22711
22712 C Reference Card
22713 \begin_inset LatexCommand \index{C Reference card}
22714
22715 \end_inset 
22716
22717 , 2 pages
22718 \end_inset 
22719 </cell>
22720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22721 \begin_inset Text
22722
22723 \layout Standard
22724
22725
22726 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
22727
22728 \end_inset 
22729
22730
22731 \end_inset 
22732 </cell>
22733 </row>
22734 <row topline="true">
22735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22736 \begin_inset Text
22737
22738 \layout Standard
22739
22740 c-faq
22741 \end_inset 
22742 </cell>
22743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22744 \begin_inset Text
22745
22746 \layout Standard
22747
22748 C-FAQ-list
22749 \end_inset 
22750 </cell>
22751 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22752 \begin_inset Text
22753
22754 \layout Standard
22755
22756
22757 \begin_inset LatexCommand \url{http://www.eskimo.com/~scs/C-faq/top.html}
22758
22759 \end_inset 
22760
22761
22762 \end_inset 
22763 </cell>
22764 </row>
22765 <row topline="true">
22766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22767 \begin_inset Text
22768
22769 \layout Standard
22770
22771 \end_inset 
22772 </cell>
22773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22774 \begin_inset Text
22775
22776 \layout Standard
22777
22778 Latest datasheet of the target CPU
22779 \end_inset 
22780 </cell>
22781 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22782 \begin_inset Text
22783
22784 \layout Standard
22785
22786 vendor
22787 \end_inset 
22788 </cell>
22789 </row>
22790 <row topline="true">
22791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22792 \begin_inset Text
22793
22794 \layout Standard
22795
22796 \end_inset 
22797 </cell>
22798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22799 \begin_inset Text
22800
22801 \layout Standard
22802
22803 Revision history of datasheet
22804 \end_inset 
22805 </cell>
22806 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22807 \begin_inset Text
22808
22809 \layout Standard
22810
22811 vendor
22812 \end_inset 
22813 </cell>
22814 </row>
22815 <row topline="true" bottomline="true">
22816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22817 \begin_inset Text
22818
22819 \layout Standard
22820
22821 S.
22822  S.
22823  Muchnick
22824 \end_inset 
22825 </cell>
22826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22827 \begin_inset Text
22828
22829 \layout Standard
22830
22831 Advanced Compiler Design and Implementation
22832 \end_inset 
22833 </cell>
22834 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22835 \begin_inset Text
22836
22837 \layout Standard
22838
22839 bookstore (very dedicated, probably read other books first)
22840 \end_inset 
22841 </cell>
22842 </row>
22843 </lyxtabular>
22844
22845 \end_inset 
22846
22847
22848 \newline 
22849
22850 \layout Section
22851
22852 Some Questions
22853 \layout Standard
22854
22855 Some questions answered, some pointers given - it might be time to in turn
22856  ask 
22857 \emph on 
22858 you
22859 \emph default 
22860  some questions: 
22861 \layout Itemize
22862
22863 can you solve your project with the selected microcontroller? Would you
22864  find out early or rather late that your target is too small/slow/whatever?
22865  Can you switch to a slightly better device if it doesn't fit?
22866 \layout Itemize
22867
22868 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
22869  and/or another programming language be more adequate? Would an operating
22870  system on the target device help?
22871 \layout Itemize
22872
22873 if you solved the problem, will the marketing department be happy?
22874 \layout Itemize
22875
22876 if the marketing department is happy, will customers be happy?
22877 \layout Itemize
22878
22879 if you're the project manager, marketing department and maybe even the customer
22880  in one person, have you tried to see the project from the outside?
22881 \layout Itemize
22882
22883 is the project done if you think it is done? Or is just that other interface/pro
22884 tocol/feature/configuration/option missing? How about website, manual(s),
22885  internationali(z|s)ation, packaging, labels, 2nd source for components,
22886  electromagnetic compatability/interference, documentation for production,
22887  production test software, update mechanism, patent issues?
22888 \layout Itemize
22889
22890 is your project adequately positioned in that magic triangle: fame, fortune,
22891  fun?
22892 \layout Standard
22893
22894 Maybe not all answers to these questions are known and some answers may
22895  even be 
22896 \emph on 
22897 no
22898 \emph default 
22899 , nevertheless knowing these questions may help you to avoid burnout
22900 \begin_inset Foot
22901 collapsed false
22902
22903 \layout Standard
22904
22905 burnout is bad for electronic devices, programmers and motorcycle tyres
22906 \end_inset 
22907
22908 .
22909  Chances are you didn't want to hear some of them...
22910 \layout Chapter
22911
22912 Support
22913 \begin_inset LatexCommand \index{Support}
22914
22915 \end_inset 
22916
22917
22918 \layout Standard
22919
22920 SDCC has grown to be a large project.
22921  The compiler alone (without the preprocessor, assembler and linker) is
22922  well over 100,000 lines of code (blank stripped).
22923  The open source nature of this project is a key to its continued growth
22924  and support.
22925  You gain the benefit and support of many active software developers and
22926  end users.
22927  Is SDCC perfect? No, that's why we need your help.
22928  The developers take pride in fixing reported bugs.
22929  You can help by reporting the bugs and helping other SDCC users.
22930  There are lots of ways to contribute, and we encourage you to take part
22931  in making SDCC a great software package.
22932  
22933 \layout Standard
22934
22935 The SDCC project is hosted on the SDCC sourceforge site at 
22936 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
22937
22938 \end_inset 
22939
22940 .
22941  You'll find the complete set of mailing lists
22942 \begin_inset LatexCommand \index{Mailing list(s)}
22943
22944 \end_inset 
22945
22946 , forums, bug reporting system, patch submission
22947 \begin_inset LatexCommand \index{Patch submission}
22948
22949 \end_inset 
22950
22951  system, download
22952 \begin_inset LatexCommand \index{download}
22953
22954 \end_inset 
22955
22956  area and cvs code repository
22957 \begin_inset LatexCommand \index{cvs code repository}
22958
22959 \end_inset 
22960
22961  there.
22962 \layout Section
22963
22964 Reporting Bugs
22965 \begin_inset LatexCommand \index{Bug reporting}
22966
22967 \end_inset 
22968
22969
22970 \begin_inset LatexCommand \index{Reporting bugs}
22971
22972 \end_inset 
22973
22974
22975 \layout Standard
22976
22977 The recommended way of reporting bugs is using the infrastructure of the
22978  sourceforge site.
22979  You can follow the status of bug reports there and have an overview about
22980  the known bugs.
22981 \layout Standard
22982
22983 Bug reports are automatically forwarded to the developer mailing list and
22984  will be fixed ASAP.
22985  When reporting a bug, it is very useful to include a small test program
22986  (the smaller the better) which reproduces the problem.
22987  If you can isolate the problem by looking at the generated assembly code,
22988  this can be very helpful.
22989  Compiling your program with the -
22990 \begin_inset ERT
22991 status Collapsed
22992
22993 \layout Standard
22994
22995 \backslash 
22996 /
22997 \end_inset 
22998
22999 -dumpall
23000 \begin_inset LatexCommand \index{-\/-dumpall}
23001
23002 \end_inset 
23003
23004  option can sometimes be useful in locating optimization problems.
23005  When reporting a bug please maker sure you:
23006 \layout Enumerate
23007
23008 Attach the code you are compiling with SDCC.
23009  
23010 \layout Enumerate
23011
23012 Specify the exact command you use to run SDCC, or attach your Makefile.
23013  
23014 \layout Enumerate
23015
23016 Specify the SDCC version (type "
23017 \family sans 
23018 \series bold 
23019 sdcc -v
23020 \family default 
23021 \series default 
23022 "), your platform, and operating system.
23023  
23024 \layout Enumerate
23025
23026 Provide an exact copy of any error message or incorrect output.
23027  
23028 \layout Enumerate
23029
23030 Put something meaningful in the subject of your message.
23031 \layout Standard
23032
23033 Please attempt to include these 5 important parts, as applicable, in all
23034  requests for support or when reporting any problems or bugs with SDCC.
23035  Though this will make your message lengthy, it will greatly improve your
23036  chance that SDCC users and developers will be able to help you.
23037  Some SDCC developers are frustrated by bug reports without code provided
23038  that they can use to reproduce and ultimately fix the problem, so please
23039  be sure to provide sample code if you are reporting a bug! 
23040 \layout Standard
23041
23042 Please have a short check that you are using a recent version of SDCC and
23043  the bug is not yet known.
23044  This is the link for reporting bugs: 
23045 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
23046
23047 \end_inset 
23048
23049 .
23050 \layout Section
23051
23052 Requesting Features
23053 \begin_inset LatexCommand \label{sub:Requesting-Features}
23054
23055 \end_inset 
23056
23057
23058 \begin_inset LatexCommand \index{Feature request}
23059
23060 \end_inset 
23061
23062
23063 \begin_inset LatexCommand \index{Requesting features}
23064
23065 \end_inset 
23066
23067
23068 \layout Standard
23069
23070 Like bug reports feature requests are forwarded to the developer mailing
23071  list.
23072  This is the link for requesting features: 
23073 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
23074
23075 \end_inset 
23076
23077 .
23078 \layout Section
23079
23080 Submitting patches
23081 \layout Standard
23082
23083 Like bug reports contributed patches are forwarded to the developer mailing
23084  list.
23085  This is the link for submitting patches
23086 \begin_inset LatexCommand \index{Patch submission}
23087
23088 \end_inset 
23089
23090
23091 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
23092
23093 \end_inset 
23094
23095 .
23096 \layout Standard
23097
23098 You need to specify some parameters to the 
23099 \family typewriter 
23100 diff
23101 \family default 
23102  command for the patches to be useful.
23103  If you modified more than one file a patch created f.e.
23104  with 
23105 \family sans 
23106 \series bold 
23107
23108 \begin_inset Quotes sld
23109 \end_inset 
23110
23111 diff -Naur unmodified_directory modified_directory >my_changes.patch
23112 \begin_inset Quotes srd
23113 \end_inset 
23114
23115
23116 \family default 
23117 \series default 
23118  will be fine, otherwise 
23119 \family sans 
23120 \series bold 
23121
23122 \begin_inset Quotes sld
23123 \end_inset 
23124
23125 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
23126 \begin_inset Quotes srd
23127 \end_inset 
23128
23129
23130 \series default 
23131  
23132 \family default 
23133 will do.
23134 \layout Section
23135
23136 Getting Help
23137 \layout Standard
23138
23139 These links should take you directly to the 
23140 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
23141
23142 \end_inset 
23143
23144
23145 \begin_inset Foot
23146 collapsed false
23147
23148 \layout Standard
23149
23150 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
23151  automated messages (mid 2003)
23152 \end_inset 
23153
23154  and the 
23155 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
23156
23157 \end_inset 
23158
23159 , lists
23160 \begin_inset LatexCommand \index{Mailing list(s)}
23161
23162 \end_inset 
23163
23164  and forums are archived and searchable so if you are lucky someone already
23165  had a similar problem.
23166  While mails to the lists themselves are delivered promptly their web front
23167  end on sourceforge sometimes shows a severe time lag (up to several weeks),
23168  if you're seriously using SDCC please consider subscribing to the lists.
23169 \layout Section
23170
23171 ChangeLog
23172 \layout Standard
23173
23174 You can follow the status of the cvs version
23175 \begin_inset LatexCommand \index{version}
23176
23177 \end_inset 
23178
23179  of SDCC by watching the Changelog
23180 \begin_inset LatexCommand \index{Changelog}
23181
23182 \end_inset 
23183
23184  in the cvs-repository
23185 \newline 
23186
23187 \size footnotesize 
23188
23189 \begin_inset LatexCommand \htmlurl{http://cvs.sf.net/cgi-bin/viewcvs.cgi/*checkout*/sdcc/sdcc/ChangeLog?rev=HEAD&content-type=text/plain}
23190
23191 \end_inset 
23192
23193 .
23194 \layout Section
23195
23196 Release policy
23197 \begin_inset LatexCommand \index{Release policy}
23198
23199 \end_inset 
23200
23201
23202 \layout Standard
23203
23204 Historically there often were long delays between official releases and
23205  the sourceforge download area tends to get not updated at all.
23206  Excuses in the past might have referred to problems with live range analysis,
23207  but as this was fixed a while ago, the current problem is that another
23208  excuse has to be found.
23209  Kidding aside, we have to get better there! On the other hand there are
23210  daily snapshots available at 
23211 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
23212
23213 \end_inset 
23214
23215 , and you can always build the very last version (hopefully with many bugs
23216  fixed, and features added) from the source code available at 
23217 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
23218
23219 \end_inset 
23220
23221 .
23222 \layout Section
23223
23224 Examples
23225 \begin_inset LatexCommand \index{Examples}
23226
23227 \end_inset 
23228
23229
23230 \layout Standard
23231
23232 You'll find some small examples in the directory 
23233 \emph on 
23234 sdcc/device/examples/.
23235  
23236 \emph default 
23237 More examples and libraries are available at
23238 \emph on 
23239  The SDCC Open Knowledge Resource 
23240 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
23241
23242 \end_inset 
23243
23244  
23245 \emph default 
23246 web site or at 
23247 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
23248
23249 \end_inset 
23250
23251 .
23252 \layout Comment
23253
23254 I did insert a reference to Paul's web site here although it seems rather
23255  dedicated to a specific 8032 board (I think it's okay because it f.e.
23256  shows LCD/Harddisc interface and has a free 8051 monitor.
23257  Independent 8032 board vendors face hard competition of heavily subsidized
23258  development boards anyway).
23259 \layout Comment
23260
23261 Maybe we should include some links to real world applications.
23262  Preferably pointer to pointers (one for each architecture) so this stays
23263  manageable here?
23264 \layout Section
23265
23266 Quality control
23267 \begin_inset LatexCommand \index{Quality control}
23268
23269 \end_inset 
23270
23271
23272 \layout Standard
23273
23274 The compiler is passed through nightly compile and build checks.
23275  The so called 
23276 \shape italic 
23277 regression tests
23278 \shape default 
23279
23280 \begin_inset LatexCommand \index{Regression test}
23281
23282 \end_inset 
23283
23284  check that SDCC itself compiles flawlessly on several platforms and checks
23285  the quality of the code generated by SDCC by running the code through simulator
23286 s.
23287  There is a separate document 
23288 \shape italic 
23289 test_suite.pdf
23290 \begin_inset LatexCommand \index{Test suite}
23291
23292 \end_inset 
23293
23294
23295 \shape default 
23296  about this.
23297 \layout Standard
23298
23299 You'll find the test code in the directory 
23300 \shape italic 
23301 sdcc/support/regression
23302 \shape default 
23303 .
23304  You can run these tests manually by running 
23305 \family sans 
23306 make
23307 \family default 
23308  in this directory (or f.e.
23309  
23310 \family sans 
23311 \series bold 
23312
23313 \begin_inset Quotes sld
23314 \end_inset 
23315
23316 make test-mcs51
23317 \begin_inset Quotes srd
23318 \end_inset 
23319
23320
23321 \family default 
23322 \series default 
23323  if you don't want to run the complete tests).
23324  The test code might also be interesting if you want to look for examples
23325 \begin_inset LatexCommand \index{Examples}
23326
23327 \end_inset 
23328
23329  checking corner cases of SDCC or if you plan to submit patches
23330 \begin_inset LatexCommand \index{Patch submission}
23331
23332 \end_inset 
23333
23334 .
23335 \layout Standard
23336
23337 The pic port uses a different set of regression tests, you'll find them
23338  in the directory 
23339 \shape italic 
23340 sdcc/src/regression
23341 \shape default 
23342 .
23343 \layout Chapter
23344 \pagebreak_top 
23345 SDCC Technical Data
23346 \layout Section
23347
23348 Optimizations
23349 \begin_inset LatexCommand \index{Optimizations}
23350
23351 \end_inset 
23352
23353
23354 \layout Standard
23355
23356 SDCC performs a host of standard optimizations in addition to some MCU specific
23357  optimizations.
23358  
23359 \layout Subsection
23360
23361 Sub-expression Elimination
23362 \begin_inset LatexCommand \index{Subexpression elimination}
23363
23364 \end_inset 
23365
23366
23367 \layout Standard
23368
23369 The compiler does local and 
23370 \emph on 
23371 g
23372 \emph default 
23373 lobal 
23374 \emph on 
23375 c
23376 \emph default 
23377 ommon 
23378 \emph on 
23379 s
23380 \emph default 
23381 ubexpression 
23382 \emph on 
23383 e
23384 \emph default 
23385 limination, e.g.: 
23386 \layout Verse
23387
23388
23389 \family typewriter 
23390 i = x + y + 1; 
23391 \newline 
23392 j = x + y;
23393 \layout Standard
23394
23395 will be translated to
23396 \layout Verse
23397
23398
23399 \family typewriter 
23400 iTemp = x + y; 
23401 \newline 
23402 i = iTemp + 1; 
23403 \newline 
23404 j = iTemp;
23405 \layout Standard
23406
23407 Some subexpressions are not as obvious as the above example, e.g.:
23408 \layout Verse
23409
23410
23411 \family typewriter 
23412 a->b[i].c = 10; 
23413 \newline 
23414 a->b[i].d = 11;
23415 \layout Standard
23416
23417 In this case the address arithmetic a->b[i] will be computed only once;
23418  the equivalent code in C would be.
23419 \layout Verse
23420
23421
23422 \family typewriter 
23423 iTemp = a->b[i]; 
23424 \newline 
23425 iTemp.c = 10; 
23426 \newline 
23427 iTemp.d = 11;
23428 \layout Standard
23429
23430 The compiler will try to keep these temporary variables in registers.
23431 \layout Subsection
23432
23433 Dead-Code Elimination
23434 \begin_inset LatexCommand \index{Dead-code elimination}
23435
23436 \end_inset 
23437
23438
23439 \layout Verse
23440
23441
23442 \family typewriter 
23443 int global;
23444 \newline 
23445
23446 \newline 
23447 void f () { 
23448 \newline 
23449 \SpecialChar ~
23450 \SpecialChar ~
23451 int i; 
23452 \newline 
23453 \SpecialChar ~
23454 \SpecialChar ~
23455 i = 1; \SpecialChar ~
23456 \SpecialChar ~
23457 \SpecialChar ~
23458 \SpecialChar ~
23459 \SpecialChar ~
23460 /* dead store */ 
23461 \newline 
23462 \SpecialChar ~
23463 \SpecialChar ~
23464 global = 1;\SpecialChar ~
23465 /* dead store */ 
23466 \newline 
23467 \SpecialChar ~
23468 \SpecialChar ~
23469 global = 2; 
23470 \newline 
23471 \SpecialChar ~
23472 \SpecialChar ~
23473 return; 
23474 \newline 
23475 \SpecialChar ~
23476 \SpecialChar ~
23477 global = 3;\SpecialChar ~
23478 /* unreachable */ 
23479 \newline 
23480 }
23481 \layout Standard
23482
23483 will be changed to
23484 \layout Verse
23485
23486
23487 \family typewriter 
23488 int global;
23489 \newline 
23490
23491 \newline 
23492 void f () {
23493 \newline 
23494 \SpecialChar ~
23495 \SpecialChar ~
23496 global = 2; 
23497 \newline 
23498 }
23499 \layout Subsection
23500
23501 Copy-Propagation
23502 \begin_inset LatexCommand \index{Copy propagation}
23503
23504 \end_inset 
23505
23506
23507 \layout Verse
23508
23509
23510 \family typewriter 
23511 int f() { 
23512 \newline 
23513 \SpecialChar ~
23514 \SpecialChar ~
23515 int i, j; 
23516 \newline 
23517 \SpecialChar ~
23518 \SpecialChar ~
23519 i = 10; 
23520 \newline 
23521 \SpecialChar ~
23522 \SpecialChar ~
23523 j = i; 
23524 \newline 
23525 \SpecialChar ~
23526 \SpecialChar ~
23527 return j; 
23528 \newline 
23529 }
23530 \layout Standard
23531
23532 will be changed to 
23533 \layout Verse
23534
23535
23536 \family typewriter 
23537 int f() { 
23538 \newline 
23539 \SpecialChar ~
23540 \SpecialChar ~
23541 int i, j; 
23542 \newline 
23543 \SpecialChar ~
23544 \SpecialChar ~
23545 i = 10; 
23546 \newline 
23547 \SpecialChar ~
23548 \SpecialChar ~
23549 j = 10; 
23550 \newline 
23551 \SpecialChar ~
23552 \SpecialChar ~
23553 return 10; 
23554 \newline 
23555 }
23556 \layout Standard
23557
23558 Note: the dead stores created by this copy propagation will be eliminated
23559  by dead-code elimination.
23560 \layout Subsection
23561
23562 Loop Optimizations
23563 \begin_inset LatexCommand \index{Loop optimization}
23564
23565 \end_inset 
23566
23567
23568 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
23569
23570 \end_inset 
23571
23572
23573 \layout Standard
23574
23575 Two types of loop optimizations are done by SDCC 
23576 \emph on 
23577 loop invariant
23578 \emph default 
23579  lifting and
23580 \emph on 
23581  strength reduction
23582 \emph default 
23583  of loop induction variables.
23584  In addition to the strength reduction the optimizer marks the induction
23585  variables and the register allocator tries to keep the induction variables
23586  in registers for the duration of the loop.
23587  Because of this preference of the register allocator
23588 \begin_inset LatexCommand \index{Register allocation}
23589
23590 \end_inset 
23591
23592 , loop induction optimization causes an increase in register pressure, which
23593  may cause unwanted spilling of other temporary variables into the stack
23594 \begin_inset LatexCommand \index{stack}
23595
23596 \end_inset 
23597
23598  / data space.
23599  The compiler will generate a warning message when it is forced to allocate
23600  extra space either on the stack or data space.
23601  If this extra space allocation is undesirable then induction optimization
23602  can be eliminated either for the entire source file (with -
23603 \begin_inset ERT
23604 status Collapsed
23605
23606 \layout Standard
23607
23608 \backslash 
23609 /
23610 \end_inset 
23611
23612 -noinduction option) or for a given function only using #pragma\SpecialChar ~
23613 noinduction
23614 \begin_inset LatexCommand \index{\#pragma noinduction}
23615
23616 \end_inset 
23617
23618 .
23619 \newline 
23620
23621 \newline 
23622 Loop Invariant:
23623 \layout Verse
23624
23625
23626 \family typewriter 
23627 for (i = 0 ; i < 100 ; i ++) 
23628 \newline 
23629 \SpecialChar ~
23630 \SpecialChar ~
23631 \SpecialChar ~
23632 \SpecialChar ~
23633 f += k + l;
23634 \layout Standard
23635
23636 changed to
23637 \layout Verse
23638
23639
23640 \family typewriter 
23641 itemp = k + l; 
23642 \newline 
23643 for (i = 0; i < 100; i++) 
23644 \newline 
23645 \SpecialChar ~
23646 \SpecialChar ~
23647 \SpecialChar ~
23648 \SpecialChar ~
23649 f += itemp;
23650 \layout Standard
23651
23652 As mentioned previously some loop invariants are not as apparent, all static
23653  address computations are also moved out of the loop.
23654 \newline 
23655
23656 \newline 
23657 Strength Reduction
23658 \begin_inset LatexCommand \index{Strength reduction}
23659
23660 \end_inset 
23661
23662 , this optimization substitutes an expression by a cheaper expression:
23663 \layout Verse
23664
23665
23666 \family typewriter 
23667 for (i=0;i < 100; i++)
23668 \newline 
23669 \SpecialChar ~
23670 \SpecialChar ~
23671 \SpecialChar ~
23672 \SpecialChar ~
23673 ar[i*5] = i*3;
23674 \layout Standard
23675
23676 changed to
23677 \layout Verse
23678
23679
23680 \family typewriter 
23681 itemp1 = 0; 
23682 \newline 
23683 itemp2 = 0; 
23684 \newline 
23685 for (i=0;i< 100;i++) { 
23686 \newline 
23687 \SpecialChar ~
23688 \SpecialChar ~
23689 \SpecialChar ~
23690 \SpecialChar ~
23691 ar[itemp1] = itemp2; 
23692 \newline 
23693 \SpecialChar ~
23694 \SpecialChar ~
23695 \SpecialChar ~
23696 \SpecialChar ~
23697 itemp1 += 5; 
23698 \newline 
23699 \SpecialChar ~
23700 \SpecialChar ~
23701 \SpecialChar ~
23702 \SpecialChar ~
23703 itemp2 += 3; 
23704 \newline 
23705 }
23706 \layout Standard
23707
23708 The more expensive multiplication
23709 \begin_inset LatexCommand \index{Multiplication}
23710
23711 \end_inset 
23712
23713  is changed to a less expensive addition.
23714 \layout Subsection
23715
23716 Loop Reversing
23717 \begin_inset LatexCommand \index{Loop reversing}
23718
23719 \end_inset 
23720
23721
23722 \layout Standard
23723
23724 This optimization is done to reduce the overhead of checking loop boundaries
23725  for every iteration.
23726  Some simple loops can be reversed and implemented using a 
23727 \begin_inset Quotes eld
23728 \end_inset 
23729
23730 decrement and jump if not zero
23731 \begin_inset Quotes erd
23732 \end_inset 
23733
23734  instruction.
23735  SDCC checks for the following criterion to determine if a loop is reversible
23736  (note: more sophisticated compilers use data-dependency analysis to make
23737  this determination, SDCC uses a more simple minded analysis).
23738 \layout Itemize
23739
23740 The 'for' loop is of the form 
23741 \newline 
23742
23743 \newline 
23744
23745 \family typewriter 
23746 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
23747  += 1])
23748 \newline 
23749 \SpecialChar ~
23750 \SpecialChar ~
23751 \SpecialChar ~
23752 \SpecialChar ~
23753 <for body>
23754 \layout Itemize
23755
23756 The <for body> does not contain 
23757 \begin_inset Quotes eld
23758 \end_inset 
23759
23760 continue
23761 \begin_inset Quotes erd
23762 \end_inset 
23763
23764  or 'break
23765 \begin_inset Quotes erd
23766 \end_inset 
23767
23768 .
23769 \layout Itemize
23770
23771 All goto's are contained within the loop.
23772 \layout Itemize
23773
23774 No function calls within the loop.
23775 \layout Itemize
23776
23777 The loop control variable <sym> is not assigned any value within the loop
23778 \layout Itemize
23779
23780 The loop control variable does NOT participate in any arithmetic operation
23781  within the loop.
23782 \layout Itemize
23783
23784 There are NO switch statements in the loop.
23785 \layout Subsection
23786
23787 Algebraic Simplifications
23788 \layout Standard
23789
23790 SDCC does numerous algebraic simplifications, the following is a small sub-set
23791  of these optimizations.
23792 \layout Verse
23793
23794
23795 \family typewriter 
23796 i = j + 0;\SpecialChar ~
23797 \SpecialChar ~
23798 \SpecialChar ~
23799 \SpecialChar ~
23800  /* changed to: */\SpecialChar ~
23801 \SpecialChar ~
23802 \SpecialChar ~
23803 \SpecialChar ~
23804  i = j; 
23805 \newline 
23806 i /= 2;\SpecialChar ~
23807 \SpecialChar ~
23808 \SpecialChar ~
23809 \SpecialChar ~
23810 \SpecialChar ~
23811 \SpecialChar ~
23812 \SpecialChar ~
23813  /* changed to: */\SpecialChar ~
23814 \SpecialChar ~
23815 \SpecialChar ~
23816 \SpecialChar ~
23817  i >>= 1; 
23818 \newline 
23819 i = j - j;\SpecialChar ~
23820 \SpecialChar ~
23821 \SpecialChar ~
23822 \SpecialChar ~
23823  /* changed to: */\SpecialChar ~
23824 \SpecialChar ~
23825 \SpecialChar ~
23826 \SpecialChar ~
23827  i = 0; 
23828 \newline 
23829 i = j / 1;\SpecialChar ~
23830 \SpecialChar ~
23831 \SpecialChar ~
23832 \SpecialChar ~
23833  /* changed to: */\SpecialChar ~
23834 \SpecialChar ~
23835 \SpecialChar ~
23836 \SpecialChar ~
23837  i = j;
23838 \layout Standard
23839
23840 Note the subexpressions
23841 \begin_inset LatexCommand \index{Subexpression}
23842
23843 \end_inset 
23844
23845  given above are generally introduced by macro expansions or as a result
23846  of copy/constant propagation.
23847 \layout Subsection
23848
23849 'switch' Statements
23850 \begin_inset LatexCommand \label{sub:'switch'-Statements}
23851
23852 \end_inset 
23853
23854
23855 \begin_inset LatexCommand \index{switch statement}
23856
23857 \end_inset 
23858
23859
23860 \layout Standard
23861
23862 SDCC can optimize switch statements to jump tables
23863 \begin_inset LatexCommand \index{jump tables}
23864
23865 \end_inset 
23866
23867 .
23868  It makes the decision based on an estimate of the generated code size.
23869  SDCC is quite liberal in the requirements for jump table generation: 
23870 \layout Itemize
23871
23872 The labels need not be in order, and the starting number need not be one
23873  or zero, the case labels are in numerical sequence or not too many case
23874  labels are missing.
23875 \begin_deeper 
23876 \layout Verse
23877
23878
23879 \family typewriter 
23880 switch(i) {\SpecialChar ~
23881 \SpecialChar ~
23882 \SpecialChar ~
23883 \SpecialChar ~
23884 \SpecialChar ~
23885 \SpecialChar ~
23886 \SpecialChar ~
23887 \SpecialChar ~
23888 \SpecialChar ~
23889 \SpecialChar ~
23890 \SpecialChar ~
23891 \SpecialChar ~
23892 \SpecialChar ~
23893 \SpecialChar ~
23894 \SpecialChar ~
23895 \SpecialChar ~
23896 \SpecialChar ~
23897 \SpecialChar ~
23898 \SpecialChar ~
23899 \SpecialChar ~
23900 \SpecialChar ~
23901 \SpecialChar ~
23902 \SpecialChar ~
23903 \SpecialChar ~
23904 \SpecialChar ~
23905 \SpecialChar ~
23906 switch (i) { 
23907 \newline 
23908 \SpecialChar ~
23909 \SpecialChar ~
23910 \SpecialChar ~
23911 case 4: ...\SpecialChar ~
23912 \SpecialChar ~
23913 \SpecialChar ~
23914 \SpecialChar ~
23915 \SpecialChar ~
23916 \SpecialChar ~
23917 \SpecialChar ~
23918 \SpecialChar ~
23919 \SpecialChar ~
23920 \SpecialChar ~
23921 \SpecialChar ~
23922 \SpecialChar ~
23923 \SpecialChar ~
23924 \SpecialChar ~
23925 \SpecialChar ~
23926 \SpecialChar ~
23927 \SpecialChar ~
23928 \SpecialChar ~
23929 \SpecialChar ~
23930 \SpecialChar ~
23931 \SpecialChar ~
23932 \SpecialChar ~
23933 \SpecialChar ~
23934 \SpecialChar ~
23935 \SpecialChar ~
23936 \SpecialChar ~
23937 case 0: ...
23938  
23939 \newline 
23940 \SpecialChar ~
23941 \SpecialChar ~
23942 \SpecialChar ~
23943 case 5: ...\SpecialChar ~
23944 \SpecialChar ~
23945 \SpecialChar ~
23946 \SpecialChar ~
23947 \SpecialChar ~
23948 \SpecialChar ~
23949 \SpecialChar ~
23950 \SpecialChar ~
23951 \SpecialChar ~
23952 \SpecialChar ~
23953 \SpecialChar ~
23954 \SpecialChar ~
23955 \SpecialChar ~
23956 \SpecialChar ~
23957 \SpecialChar ~
23958 \SpecialChar ~
23959 \SpecialChar ~
23960 \SpecialChar ~
23961 \SpecialChar ~
23962 \SpecialChar ~
23963 \SpecialChar ~
23964 \SpecialChar ~
23965 \SpecialChar ~
23966 \SpecialChar ~
23967 \SpecialChar ~
23968 \SpecialChar ~
23969 case 1: ...
23970  
23971 \newline 
23972 \SpecialChar ~
23973 \SpecialChar ~
23974 \SpecialChar ~
23975 case 3: ...\SpecialChar ~
23976 \SpecialChar ~
23977 \SpecialChar ~
23978 \SpecialChar ~
23979 \SpecialChar ~
23980 \SpecialChar ~
23981 \SpecialChar ~
23982 \SpecialChar ~
23983 \SpecialChar ~
23984 \SpecialChar ~
23985 \SpecialChar ~
23986 \SpecialChar ~
23987 \SpecialChar ~
23988 \SpecialChar ~
23989 \SpecialChar ~
23990 \SpecialChar ~
23991 \SpecialChar ~
23992 \SpecialChar ~
23993 \SpecialChar ~
23994 \SpecialChar ~
23995 \SpecialChar ~
23996 \SpecialChar ~
23997 \SpecialChar ~
23998 \SpecialChar ~
23999 \SpecialChar ~
24000 \SpecialChar ~
24001
24002 \newline 
24003 \SpecialChar ~
24004 \SpecialChar ~
24005 \SpecialChar ~
24006 case 6: ...\SpecialChar ~
24007 \SpecialChar ~
24008 \SpecialChar ~
24009 \SpecialChar ~
24010 \SpecialChar ~
24011 \SpecialChar ~
24012 \SpecialChar ~
24013 \SpecialChar ~
24014 \SpecialChar ~
24015 \SpecialChar ~
24016 \SpecialChar ~
24017 \SpecialChar ~
24018 \SpecialChar ~
24019 \SpecialChar ~
24020 \SpecialChar ~
24021 \SpecialChar ~
24022 \SpecialChar ~
24023 \SpecialChar ~
24024 \SpecialChar ~
24025 \SpecialChar ~
24026 \SpecialChar ~
24027 \SpecialChar ~
24028 \SpecialChar ~
24029 \SpecialChar ~
24030 \SpecialChar ~
24031 \SpecialChar ~
24032 case 3: ...
24033  
24034 \newline 
24035 \SpecialChar ~
24036 \SpecialChar ~
24037 \SpecialChar ~
24038 case 7: ...\SpecialChar ~
24039 \SpecialChar ~
24040 \SpecialChar ~
24041 \SpecialChar ~
24042 \SpecialChar ~
24043 \SpecialChar ~
24044 \SpecialChar ~
24045 \SpecialChar ~
24046 \SpecialChar ~
24047 \SpecialChar ~
24048 \SpecialChar ~
24049 \SpecialChar ~
24050 \SpecialChar ~
24051 \SpecialChar ~
24052 \SpecialChar ~
24053 \SpecialChar ~
24054 \SpecialChar ~
24055 \SpecialChar ~
24056 \SpecialChar ~
24057 \SpecialChar ~
24058 \SpecialChar ~
24059 \SpecialChar ~
24060 \SpecialChar ~
24061 \SpecialChar ~
24062 \SpecialChar ~
24063 \SpecialChar ~
24064 case 4: ...
24065  
24066 \newline 
24067 \SpecialChar ~
24068 \SpecialChar ~
24069 \SpecialChar ~
24070 case 8: ...\SpecialChar ~
24071 \SpecialChar ~
24072 \SpecialChar ~
24073 \SpecialChar ~
24074 \SpecialChar ~
24075 \SpecialChar ~
24076 \SpecialChar ~
24077 \SpecialChar ~
24078 \SpecialChar ~
24079 \SpecialChar ~
24080 \SpecialChar ~
24081 \SpecialChar ~
24082 \SpecialChar ~
24083 \SpecialChar ~
24084 \SpecialChar ~
24085 \SpecialChar ~
24086 \SpecialChar ~
24087 \SpecialChar ~
24088 \SpecialChar ~
24089 \SpecialChar ~
24090 \SpecialChar ~
24091 \SpecialChar ~
24092 \SpecialChar ~
24093 \SpecialChar ~
24094 \SpecialChar ~
24095 \SpecialChar ~
24096 case 5: ...
24097  
24098 \newline 
24099 \SpecialChar ~
24100 \SpecialChar ~
24101 \SpecialChar ~
24102 case 9: ...\SpecialChar ~
24103 \SpecialChar ~
24104 \SpecialChar ~
24105 \SpecialChar ~
24106 \SpecialChar ~
24107 \SpecialChar ~
24108 \SpecialChar ~
24109 \SpecialChar ~
24110 \SpecialChar ~
24111 \SpecialChar ~
24112 \SpecialChar ~
24113 \SpecialChar ~
24114 \SpecialChar ~
24115 \SpecialChar ~
24116 \SpecialChar ~
24117 \SpecialChar ~
24118 \SpecialChar ~
24119 \SpecialChar ~
24120 \SpecialChar ~
24121 \SpecialChar ~
24122 \SpecialChar ~
24123 \SpecialChar ~
24124 \SpecialChar ~
24125 \SpecialChar ~
24126 \SpecialChar ~
24127 \SpecialChar ~
24128 case 6: ...
24129  
24130 \newline 
24131 \SpecialChar ~
24132 \SpecialChar ~
24133 \SpecialChar ~
24134 case 10: ...\SpecialChar ~
24135 \SpecialChar ~
24136 \SpecialChar ~
24137 \SpecialChar ~
24138 \SpecialChar ~
24139 \SpecialChar ~
24140 \SpecialChar ~
24141 \SpecialChar ~
24142 \SpecialChar ~
24143 \SpecialChar ~
24144 \SpecialChar ~
24145 \SpecialChar ~
24146 \SpecialChar ~
24147 \SpecialChar ~
24148 \SpecialChar ~
24149 \SpecialChar ~
24150 \SpecialChar ~
24151 \SpecialChar ~
24152 \SpecialChar ~
24153 \SpecialChar ~
24154 \SpecialChar ~
24155 \SpecialChar ~
24156 \SpecialChar ~
24157 \SpecialChar ~
24158 \SpecialChar ~
24159 case 7: ...
24160  
24161 \newline 
24162 \SpecialChar ~
24163 \SpecialChar ~
24164 \SpecialChar ~
24165 case 11: ...\SpecialChar ~
24166 \SpecialChar ~
24167 \SpecialChar ~
24168 \SpecialChar ~
24169 \SpecialChar ~
24170 \SpecialChar ~
24171 \SpecialChar ~
24172 \SpecialChar ~
24173 \SpecialChar ~
24174 \SpecialChar ~
24175 \SpecialChar ~
24176 \SpecialChar ~
24177 \SpecialChar ~
24178 \SpecialChar ~
24179 \SpecialChar ~
24180 \SpecialChar ~
24181 \SpecialChar ~
24182 \SpecialChar ~
24183 \SpecialChar ~
24184 \SpecialChar ~
24185 \SpecialChar ~
24186 \SpecialChar ~
24187 \SpecialChar ~
24188 \SpecialChar ~
24189 \SpecialChar ~
24190 case 8: ...
24191  
24192 \newline 
24193 }\SpecialChar ~
24194 \SpecialChar ~
24195 \SpecialChar ~
24196 \SpecialChar ~
24197 \SpecialChar ~
24198 \SpecialChar ~
24199 \SpecialChar ~
24200 \SpecialChar ~
24201 \SpecialChar ~
24202 \SpecialChar ~
24203 \SpecialChar ~
24204 \SpecialChar ~
24205 \SpecialChar ~
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 }
24230 \layout Standard
24231
24232 Both the above switch statements will be implemented using a jump-table.
24233  The example to the right side is slightly more efficient as the check for
24234  the lower boundary of the jump-table is not needed.
24235 \end_deeper 
24236 \layout Itemize
24237
24238 The number of case labels is not larger than supported by the target architectur
24239 e.
24240 \layout Itemize
24241
24242 If the case labels are not in numerical sequence ('gaps' between cases)
24243  SDCC checks whether a jump table with additionally inserted dummy cases
24244  is still attractive.
24245  
24246 \layout Itemize
24247
24248 If the starting number is not zero and a check for the lower boundary of
24249  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
24250  ...
24251  .
24252 \layout Standard
24253
24254 Switch statements which have large gaps in the numeric sequence or those
24255  that have too many case labels can be split into more than one switch statement
24256  for efficient code generation, e.g.:
24257 \layout Verse
24258
24259
24260 \family typewriter 
24261 switch (i) { 
24262 \newline 
24263 \SpecialChar ~
24264 \SpecialChar ~
24265 case 1: ...
24266  
24267 \newline 
24268 \SpecialChar ~
24269 \SpecialChar ~
24270 case 2: ...
24271  
24272 \newline 
24273 \SpecialChar ~
24274 \SpecialChar ~
24275 case 3: ...
24276  
24277 \newline 
24278 \SpecialChar ~
24279 \SpecialChar ~
24280 case 4: ...
24281  
24282 \newline 
24283 \SpecialChar ~
24284 \SpecialChar ~
24285 case 5: ...
24286  
24287 \newline 
24288 \SpecialChar ~
24289 \SpecialChar ~
24290 case 6: ...
24291  
24292 \newline 
24293 \SpecialChar ~
24294 \SpecialChar ~
24295 case 7: ...
24296  
24297 \newline 
24298 \SpecialChar ~
24299 \SpecialChar ~
24300 case 101: ...
24301  
24302 \newline 
24303 \SpecialChar ~
24304 \SpecialChar ~
24305 case 102: ...
24306  
24307 \newline 
24308 \SpecialChar ~
24309 \SpecialChar ~
24310 case 103: ...
24311  
24312 \newline 
24313 \SpecialChar ~
24314 \SpecialChar ~
24315 case 104: ...
24316  
24317 \newline 
24318 \SpecialChar ~
24319 \SpecialChar ~
24320 case 105: ...
24321  
24322 \newline 
24323 \SpecialChar ~
24324 \SpecialChar ~
24325 case 106: ...
24326  
24327 \newline 
24328 \SpecialChar ~
24329 \SpecialChar ~
24330 case 107: ...
24331  
24332 \newline 
24333 }
24334 \layout Standard
24335
24336 If the above switch statement is broken down into two switch statements
24337 \layout Verse
24338
24339
24340 \family typewriter 
24341 switch (i) { 
24342 \newline 
24343 \SpecialChar ~
24344 \SpecialChar ~
24345 case 1: ...
24346  
24347 \newline 
24348 \SpecialChar ~
24349 \SpecialChar ~
24350 case 2: ...
24351  
24352 \newline 
24353 \SpecialChar ~
24354 \SpecialChar ~
24355 case 3: ...
24356  
24357 \newline 
24358 \SpecialChar ~
24359 \SpecialChar ~
24360 case 4: ...
24361  
24362 \newline 
24363 \SpecialChar ~
24364 \SpecialChar ~
24365 case 5: ...
24366  
24367 \newline 
24368 \SpecialChar ~
24369 \SpecialChar ~
24370 case 6: ...
24371  
24372 \newline 
24373 \SpecialChar ~
24374 \SpecialChar ~
24375 case 7: ...
24376  
24377 \newline 
24378 }
24379 \layout Standard
24380
24381 and
24382 \layout Verse
24383
24384
24385 \family typewriter 
24386 switch (i) { 
24387 \newline 
24388 \SpecialChar ~
24389 \SpecialChar ~
24390 case 101: ...
24391  
24392 \newline 
24393 \SpecialChar ~
24394 \SpecialChar ~
24395 case 102: ...
24396  
24397 \newline 
24398 \SpecialChar ~
24399 \SpecialChar ~
24400 case 103: ...
24401  
24402 \newline 
24403 \SpecialChar ~
24404 \SpecialChar ~
24405 case 104: ...
24406  
24407 \newline 
24408 \SpecialChar ~
24409 \SpecialChar ~
24410 case 105: ...
24411  
24412 \newline 
24413 \SpecialChar ~
24414 \SpecialChar ~
24415 case 106: ...
24416  
24417 \newline 
24418 \SpecialChar ~
24419 \SpecialChar ~
24420 case 107: ...
24421  
24422 \newline 
24423 }
24424 \layout Standard
24425
24426 then both the switch statements will be implemented using jump-tables whereas
24427  the unmodified switch statement will not be.
24428 \layout Comment
24429
24430 There might be reasons which SDCC cannot know about to either favour or
24431  not favour jump tables.
24432  If the target system has to be as quick for the last switch case as for
24433  the first (pro jump table), or if the switch argument is known to be zero
24434  in the majority of the cases (contra jump table).
24435 \layout Standard
24436
24437 The pragma nojtbound
24438 \begin_inset LatexCommand \index{\#pragma nojtbound}
24439
24440 \end_inset 
24441
24442  can be used to turn off checking the 
24443 \emph on 
24444 j
24445 \emph default 
24446 ump 
24447 \emph on 
24448 t
24449 \emph default 
24450 able 
24451 \emph on 
24452 bound
24453 \emph default 
24454 aries.
24455  It has no effect if a default label is supplied.
24456  Use of this pragma is dangerous: if the switch
24457 \begin_inset LatexCommand \index{switch statement}
24458
24459 \end_inset 
24460
24461  argument is not matched by a case statement the processor will happily
24462  jump into Nirvana.
24463 \layout Subsection
24464
24465 Bit-shifting Operations
24466 \begin_inset LatexCommand \index{Bit shifting}
24467
24468 \end_inset 
24469
24470 .
24471 \layout Standard
24472
24473 Bit shifting is one of the most frequently used operation in embedded programmin
24474 g.
24475  SDCC tries to implement bit-shift operations in the most efficient way
24476  possible, e.g.:
24477 \layout Verse
24478
24479
24480 \family typewriter 
24481 unsigned char i;
24482 \newline 
24483 ...
24484  
24485 \newline 
24486 i >>= 4; 
24487 \newline 
24488 ...
24489 \layout Standard
24490
24491 generates the following code:
24492 \layout Verse
24493
24494
24495 \family typewriter 
24496 mov\SpecialChar ~
24497  a,_i 
24498 \newline 
24499 swap a 
24500 \newline 
24501 anl\SpecialChar ~
24502  a,#0x0f 
24503 \newline 
24504 mov\SpecialChar ~
24505  _i,a
24506 \layout Standard
24507
24508 In general SDCC will never setup a loop if the shift count is known.
24509  Another example:
24510 \layout Verse
24511
24512
24513 \family typewriter 
24514 unsigned int i; 
24515 \newline 
24516 ...
24517  
24518 \newline 
24519 i >>= 9; 
24520 \newline 
24521 ...
24522 \layout Standard
24523
24524 will generate:
24525 \layout Verse
24526
24527
24528 \family typewriter 
24529 mov\SpecialChar ~
24530 \SpecialChar ~
24531 a,(_i + 1) 
24532 \newline 
24533 mov\SpecialChar ~
24534 \SpecialChar ~
24535 (_i + 1),#0x00 
24536 \newline 
24537 clr\SpecialChar ~
24538 \SpecialChar ~
24539
24540 \newline 
24541 rrc\SpecialChar ~
24542 \SpecialChar ~
24543
24544 \newline 
24545 mov\SpecialChar ~
24546 \SpecialChar ~
24547 _i,a
24548 \layout Subsection
24549
24550 Bit-rotation
24551 \begin_inset LatexCommand \index{Bit rotation}
24552
24553 \end_inset 
24554
24555
24556 \layout Standard
24557
24558 A special case of the bit-shift operation is bit rotation
24559 \begin_inset LatexCommand \index{rotating bits}
24560
24561 \end_inset 
24562
24563 , SDCC recognizes the following expression to be a left bit-rotation:
24564 \layout Verse
24565
24566
24567 \family typewriter 
24568 \series bold 
24569 unsigned
24570 \series default 
24571 \SpecialChar ~
24572 \SpecialChar ~
24573 char i;\SpecialChar ~
24574 \SpecialChar ~
24575 \SpecialChar ~
24576 \SpecialChar ~
24577 \SpecialChar ~
24578 \SpecialChar ~
24579 \SpecialChar ~
24580 \SpecialChar ~
24581 \SpecialChar ~
24582 \SpecialChar ~
24583 \SpecialChar ~
24584 /* unsigned is needed for rotation */ 
24585 \newline 
24586 ...
24587  
24588 \newline 
24589 i = ((i << 1) | (i >> 7)); 
24590 \family default 
24591
24592 \newline 
24593
24594 \family typewriter 
24595 ...
24596 \layout Standard
24597
24598 will generate the following code:
24599 \layout Verse
24600
24601
24602 \family typewriter 
24603 mov\SpecialChar ~
24604 \SpecialChar ~
24605 a,_i 
24606 \newline 
24607 rl\SpecialChar ~
24608 \SpecialChar ~
24609 \SpecialChar ~
24610
24611 \newline 
24612 mov\SpecialChar ~
24613 \SpecialChar ~
24614 _i,a
24615 \layout Standard
24616
24617 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
24618 ns of this case will also be recognized as bit-rotation, i.e.: 
24619 \layout Verse
24620
24621
24622 \family typewriter 
24623 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
24624 \layout Subsection
24625
24626 Nibble and Byte Swapping
24627 \layout Standard
24628
24629 Other special cases of the bit-shift operations are nibble or byte swapping
24630 \begin_inset LatexCommand \index{swapping nibbles/bytes}
24631
24632 \end_inset 
24633
24634 , SDCC recognizes the following expressions:
24635 \layout Verse
24636
24637
24638 \family typewriter 
24639 \series bold 
24640 unsigned
24641 \series default 
24642 \SpecialChar ~
24643 \SpecialChar ~
24644 char i; 
24645 \newline 
24646
24647 \series bold 
24648 unsigned
24649 \series default 
24650 \SpecialChar ~
24651 \SpecialChar ~
24652 int j; 
24653 \newline 
24654 ...
24655  
24656 \newline 
24657 i = ((i << 4) | (i >> 4)); 
24658 \family default 
24659
24660 \newline 
24661
24662 \family typewriter 
24663 j = ((j << 8) | (j >> 8)); 
24664 \layout Standard
24665
24666 and generates a swap instruction for the nibble swapping
24667 \begin_inset LatexCommand \index{Nibble swapping}
24668
24669 \end_inset 
24670
24671  or move instructions for the byte swapping
24672 \begin_inset LatexCommand \index{Byte swapping}
24673
24674 \end_inset 
24675
24676 .
24677  The 
24678 \begin_inset Quotes sld
24679 \end_inset 
24680
24681 j
24682 \begin_inset Quotes srd
24683 \end_inset 
24684
24685  example can be used to convert from little to big-endian or vice versa.
24686  If you want to change the endianness of a 
24687 \emph on 
24688 signed
24689 \emph default 
24690  integer you have to cast to 
24691 \family typewriter 
24692 (unsigned int)
24693 \family default 
24694  first.
24695 \layout Standard
24696
24697 Note that SDCC stores numbers in little-endian
24698 \begin_inset Foot
24699 collapsed false
24700
24701 \layout Standard
24702
24703 Usually 8-bit processors don't care much about endianness.
24704  This is not the case for the standard 8051 which only has an instruction
24705  to increment its 
24706 \emph on 
24707 dptr
24708 \emph default 
24709
24710 \begin_inset LatexCommand \index{DPTR}
24711
24712 \end_inset 
24713
24714 -datapointer
24715 \emph on 
24716  
24717 \emph default 
24718 so little-endian is the more efficient byte order.
24719 \end_inset 
24720
24721
24722 \begin_inset LatexCommand \index{little-endian}
24723
24724 \end_inset 
24725
24726
24727 \begin_inset LatexCommand \index{Endianness}
24728
24729 \end_inset 
24730
24731  format (i.e.
24732  lowest order first).
24733 \layout Subsection
24734
24735 Highest Order Bit
24736 \begin_inset LatexCommand \index{Highest Order Bit}
24737
24738 \end_inset 
24739
24740  / Any Order Bit
24741 \begin_inset LatexCommand \index{Any Order Bit}
24742
24743 \end_inset 
24744
24745
24746 \layout Standard
24747
24748 It is frequently required to obtain the highest order bit of an integral
24749  type (long, int, short or char types).
24750  Also obtaining any other order bit is not uncommon.
24751  SDCC recognizes the following expressions to yield the highest order bit
24752  and generates optimized code for it, e.g.:
24753 \layout Verse
24754
24755
24756 \family typewriter 
24757 unsigned int gint; 
24758 \newline 
24759
24760 \newline 
24761 foo () { 
24762 \newline 
24763 \SpecialChar ~
24764 \SpecialChar ~
24765 unsigned char hob1, aob1; 
24766 \newline 
24767 \SpecialChar ~
24768 \SpecialChar ~
24769 bit hob2, hob3, aob2, aob3; 
24770 \newline 
24771 \SpecialChar ~
24772 \SpecialChar ~
24773 ...
24774  
24775 \newline 
24776 \SpecialChar ~
24777 \SpecialChar ~
24778 hob1 = (gint >> 15) & 1; 
24779 \newline 
24780 \SpecialChar ~
24781 \SpecialChar ~
24782 hob2 = (gint >> 15) & 1; 
24783 \newline 
24784 \SpecialChar ~
24785 \SpecialChar ~
24786 hob3 = gint & 0x8000; 
24787 \newline 
24788 \SpecialChar ~
24789 \SpecialChar ~
24790 aob1 = (gint >> 9) & 1; 
24791 \newline 
24792 \SpecialChar ~
24793 \SpecialChar ~
24794 aob2 = (gint >> 8) & 1; 
24795 \newline 
24796 \SpecialChar ~
24797 \SpecialChar ~
24798 aob3 = gint & 0x0800; 
24799 \newline 
24800 \SpecialChar ~
24801 \SpecialChar ~
24802 ..
24803  
24804 \newline 
24805 }
24806 \layout Standard
24807
24808 will generate the following code:
24809 \layout Verse
24810
24811
24812 \family typewriter 
24813 \SpecialChar ~
24814 \SpecialChar ~
24815 \SpecialChar ~
24816 \SpecialChar ~
24817 \SpecialChar ~
24818 \SpecialChar ~
24819 \SpecialChar ~
24820 \SpecialChar ~
24821 \SpecialChar ~
24822 \SpecialChar ~
24823 \SpecialChar ~
24824 \SpecialChar ~
24825 \SpecialChar ~
24826 \SpecialChar ~
24827 \SpecialChar ~
24828 \SpecialChar ~
24829 \SpecialChar ~
24830 \SpecialChar ~
24831 \SpecialChar ~
24832 \SpecialChar ~
24833 \SpecialChar ~
24834 \SpecialChar ~
24835 \SpecialChar ~
24836 \SpecialChar ~
24837 \SpecialChar ~
24838  61 ;\SpecialChar ~
24839  hob.c 7 
24840 \newline 
24841 000A E5*01\SpecialChar ~
24842 \SpecialChar ~
24843 \SpecialChar ~
24844 \SpecialChar ~
24845 \SpecialChar ~
24846 \SpecialChar ~
24847 \SpecialChar ~
24848 \SpecialChar ~
24849 \SpecialChar ~
24850 \SpecialChar ~
24851 \SpecialChar ~
24852 \SpecialChar ~
24853 \SpecialChar ~
24854 \SpecialChar ~
24855 \SpecialChar ~
24856  62\SpecialChar ~
24857 \SpecialChar ~
24858 \SpecialChar ~
24859 \SpecialChar ~
24860 \SpecialChar ~
24861 \SpecialChar ~
24862 \SpecialChar ~
24863 \SpecialChar ~
24864  mov\SpecialChar ~
24865 \SpecialChar ~
24866  a,(_gint + 1) 
24867 \newline 
24868 000C 23\SpecialChar ~
24869 \SpecialChar ~
24870 \SpecialChar ~
24871 \SpecialChar ~
24872 \SpecialChar ~
24873 \SpecialChar ~
24874 \SpecialChar ~
24875 \SpecialChar ~
24876 \SpecialChar ~
24877 \SpecialChar ~
24878 \SpecialChar ~
24879 \SpecialChar ~
24880 \SpecialChar ~
24881 \SpecialChar ~
24882 \SpecialChar ~
24883 \SpecialChar ~
24884 \SpecialChar ~
24885 \SpecialChar ~
24886  63\SpecialChar ~
24887 \SpecialChar ~
24888 \SpecialChar ~
24889 \SpecialChar ~
24890 \SpecialChar ~
24891 \SpecialChar ~
24892 \SpecialChar ~
24893 \SpecialChar ~
24894  rl\SpecialChar ~
24895 \SpecialChar ~
24896 \SpecialChar ~
24897  a 
24898 \newline 
24899 000D 54 01\SpecialChar ~
24900 \SpecialChar ~
24901 \SpecialChar ~
24902 \SpecialChar ~
24903 \SpecialChar ~
24904 \SpecialChar ~
24905 \SpecialChar ~
24906 \SpecialChar ~
24907 \SpecialChar ~
24908 \SpecialChar ~
24909 \SpecialChar ~
24910 \SpecialChar ~
24911 \SpecialChar ~
24912 \SpecialChar ~
24913 \SpecialChar ~
24914  64\SpecialChar ~
24915 \SpecialChar ~
24916 \SpecialChar ~
24917 \SpecialChar ~
24918 \SpecialChar ~
24919 \SpecialChar ~
24920 \SpecialChar ~
24921 \SpecialChar ~
24922  anl\SpecialChar ~
24923 \SpecialChar ~
24924  a,#0x01 
24925 \newline 
24926 000F F5*02\SpecialChar ~
24927 \SpecialChar ~
24928 \SpecialChar ~
24929 \SpecialChar ~
24930 \SpecialChar ~
24931 \SpecialChar ~
24932 \SpecialChar ~
24933 \SpecialChar ~
24934 \SpecialChar ~
24935 \SpecialChar ~
24936 \SpecialChar ~
24937 \SpecialChar ~
24938 \SpecialChar ~
24939 \SpecialChar ~
24940 \SpecialChar ~
24941  65\SpecialChar ~
24942 \SpecialChar ~
24943 \SpecialChar ~
24944 \SpecialChar ~
24945 \SpecialChar ~
24946 \SpecialChar ~
24947 \SpecialChar ~
24948 \SpecialChar ~
24949  mov\SpecialChar ~
24950 \SpecialChar ~
24951  _foo_hob1_1_1,a 
24952 \newline 
24953 \SpecialChar ~
24954 \SpecialChar ~
24955 \SpecialChar ~
24956 \SpecialChar ~
24957 \SpecialChar ~
24958 \SpecialChar ~
24959 \SpecialChar ~
24960 \SpecialChar ~
24961 \SpecialChar ~
24962 \SpecialChar ~
24963 \SpecialChar ~
24964 \SpecialChar ~
24965 \SpecialChar ~
24966 \SpecialChar ~
24967 \SpecialChar ~
24968 \SpecialChar ~
24969 \SpecialChar ~
24970 \SpecialChar ~
24971 \SpecialChar ~
24972 \SpecialChar ~
24973 \SpecialChar ~
24974 \SpecialChar ~
24975 \SpecialChar ~
24976 \SpecialChar ~
24977 \SpecialChar ~
24978  66 ;\SpecialChar ~
24979  hob.c 8 
24980 \newline 
24981 0011 E5*01\SpecialChar ~
24982 \SpecialChar ~
24983 \SpecialChar ~
24984 \SpecialChar ~
24985 \SpecialChar ~
24986 \SpecialChar ~
24987 \SpecialChar ~
24988 \SpecialChar ~
24989 \SpecialChar ~
24990 \SpecialChar ~
24991 \SpecialChar ~
24992 \SpecialChar ~
24993 \SpecialChar ~
24994 \SpecialChar ~
24995 \SpecialChar ~
24996  67\SpecialChar ~
24997 \SpecialChar ~
24998 \SpecialChar ~
24999 \SpecialChar ~
25000 \SpecialChar ~
25001 \SpecialChar ~
25002 \SpecialChar ~
25003 \SpecialChar ~
25004  mov\SpecialChar ~
25005 \SpecialChar ~
25006  a,(_gint + 1) 
25007 \newline 
25008 0013 33\SpecialChar ~
25009 \SpecialChar ~
25010 \SpecialChar ~
25011 \SpecialChar ~
25012 \SpecialChar ~
25013 \SpecialChar ~
25014 \SpecialChar ~
25015 \SpecialChar ~
25016 \SpecialChar ~
25017 \SpecialChar ~
25018 \SpecialChar ~
25019 \SpecialChar ~
25020 \SpecialChar ~
25021 \SpecialChar ~
25022 \SpecialChar ~
25023 \SpecialChar ~
25024 \SpecialChar ~
25025 \SpecialChar ~
25026  68\SpecialChar ~
25027 \SpecialChar ~
25028 \SpecialChar ~
25029 \SpecialChar ~
25030 \SpecialChar ~
25031 \SpecialChar ~
25032 \SpecialChar ~
25033 \SpecialChar ~
25034  rlc\SpecialChar ~
25035 \SpecialChar ~
25036  a 
25037 \newline 
25038 0014 92*00\SpecialChar ~
25039 \SpecialChar ~
25040 \SpecialChar ~
25041 \SpecialChar ~
25042 \SpecialChar ~
25043 \SpecialChar ~
25044 \SpecialChar ~
25045 \SpecialChar ~
25046 \SpecialChar ~
25047 \SpecialChar ~
25048 \SpecialChar ~
25049 \SpecialChar ~
25050 \SpecialChar ~
25051 \SpecialChar ~
25052 \SpecialChar ~
25053  69\SpecialChar ~
25054 \SpecialChar ~
25055 \SpecialChar ~
25056 \SpecialChar ~
25057 \SpecialChar ~
25058 \SpecialChar ~
25059 \SpecialChar ~
25060 \SpecialChar ~
25061  mov\SpecialChar ~
25062 \SpecialChar ~
25063  _foo_hob2_1_1,c 
25064 \newline 
25065 \SpecialChar ~
25066 \SpecialChar ~
25067 \SpecialChar ~
25068 \SpecialChar ~
25069 \SpecialChar ~
25070 \SpecialChar ~
25071 \SpecialChar ~
25072 \SpecialChar ~
25073 \SpecialChar ~
25074 \SpecialChar ~
25075 \SpecialChar ~
25076 \SpecialChar ~
25077 \SpecialChar ~
25078 \SpecialChar ~
25079 \SpecialChar ~
25080 \SpecialChar ~
25081 \SpecialChar ~
25082 \SpecialChar ~
25083 \SpecialChar ~
25084 \SpecialChar ~
25085 \SpecialChar ~
25086 \SpecialChar ~
25087 \SpecialChar ~
25088 \SpecialChar ~
25089 \SpecialChar ~
25090  66 ;\SpecialChar ~
25091  hob.c 9 
25092 \newline 
25093 0016 E5*01\SpecialChar ~
25094 \SpecialChar ~
25095 \SpecialChar ~
25096 \SpecialChar ~
25097 \SpecialChar ~
25098 \SpecialChar ~
25099 \SpecialChar ~
25100 \SpecialChar ~
25101 \SpecialChar ~
25102 \SpecialChar ~
25103 \SpecialChar ~
25104 \SpecialChar ~
25105 \SpecialChar ~
25106 \SpecialChar ~
25107 \SpecialChar ~
25108  67\SpecialChar ~
25109 \SpecialChar ~
25110 \SpecialChar ~
25111 \SpecialChar ~
25112 \SpecialChar ~
25113 \SpecialChar ~
25114 \SpecialChar ~
25115 \SpecialChar ~
25116  mov\SpecialChar ~
25117 \SpecialChar ~
25118  a,(_gint + 1) 
25119 \newline 
25120 0018 33\SpecialChar ~
25121 \SpecialChar ~
25122 \SpecialChar ~
25123 \SpecialChar ~
25124 \SpecialChar ~
25125 \SpecialChar ~
25126 \SpecialChar ~
25127 \SpecialChar ~
25128 \SpecialChar ~
25129 \SpecialChar ~
25130 \SpecialChar ~
25131 \SpecialChar ~
25132 \SpecialChar ~
25133 \SpecialChar ~
25134 \SpecialChar ~
25135 \SpecialChar ~
25136 \SpecialChar ~
25137 \SpecialChar ~
25138  68\SpecialChar ~
25139 \SpecialChar ~
25140 \SpecialChar ~
25141 \SpecialChar ~
25142 \SpecialChar ~
25143 \SpecialChar ~
25144 \SpecialChar ~
25145 \SpecialChar ~
25146  rlc\SpecialChar ~
25147 \SpecialChar ~
25148  a 
25149 \newline 
25150 0019 92*01\SpecialChar ~
25151 \SpecialChar ~
25152 \SpecialChar ~
25153 \SpecialChar ~
25154 \SpecialChar ~
25155 \SpecialChar ~
25156 \SpecialChar ~
25157 \SpecialChar ~
25158 \SpecialChar ~
25159 \SpecialChar ~
25160 \SpecialChar ~
25161 \SpecialChar ~
25162 \SpecialChar ~
25163 \SpecialChar ~
25164 \SpecialChar ~
25165  69\SpecialChar ~
25166 \SpecialChar ~
25167 \SpecialChar ~
25168 \SpecialChar ~
25169 \SpecialChar ~
25170 \SpecialChar ~
25171 \SpecialChar ~
25172 \SpecialChar ~
25173  mov\SpecialChar ~
25174 \SpecialChar ~
25175  _foo_hob3_1_1,c 
25176 \newline 
25177 \SpecialChar ~
25178 \SpecialChar ~
25179 \SpecialChar ~
25180 \SpecialChar ~
25181 \SpecialChar ~
25182 \SpecialChar ~
25183 \SpecialChar ~
25184 \SpecialChar ~
25185 \SpecialChar ~
25186 \SpecialChar ~
25187 \SpecialChar ~
25188 \SpecialChar ~
25189 \SpecialChar ~
25190 \SpecialChar ~
25191 \SpecialChar ~
25192 \SpecialChar ~
25193 \SpecialChar ~
25194 \SpecialChar ~
25195 \SpecialChar ~
25196 \SpecialChar ~
25197 \SpecialChar ~
25198 \SpecialChar ~
25199 \SpecialChar ~
25200 \SpecialChar ~
25201 \SpecialChar ~
25202  70 ;\SpecialChar ~
25203  hob.c 10 
25204 \newline 
25205 001B E5*01\SpecialChar ~
25206 \SpecialChar ~
25207 \SpecialChar ~
25208 \SpecialChar ~
25209 \SpecialChar ~
25210 \SpecialChar ~
25211 \SpecialChar ~
25212 \SpecialChar ~
25213 \SpecialChar ~
25214 \SpecialChar ~
25215 \SpecialChar ~
25216 \SpecialChar ~
25217 \SpecialChar ~
25218 \SpecialChar ~
25219 \SpecialChar ~
25220  71\SpecialChar ~
25221 \SpecialChar ~
25222 \SpecialChar ~
25223 \SpecialChar ~
25224 \SpecialChar ~
25225 \SpecialChar ~
25226 \SpecialChar ~
25227 \SpecialChar ~
25228  mov\SpecialChar ~
25229 \SpecialChar ~
25230  a,(_gint + 1) 
25231 \newline 
25232 001D 03\SpecialChar ~
25233 \SpecialChar ~
25234 \SpecialChar ~
25235 \SpecialChar ~
25236 \SpecialChar ~
25237 \SpecialChar ~
25238 \SpecialChar ~
25239 \SpecialChar ~
25240 \SpecialChar ~
25241 \SpecialChar ~
25242 \SpecialChar ~
25243 \SpecialChar ~
25244 \SpecialChar ~
25245 \SpecialChar ~
25246 \SpecialChar ~
25247 \SpecialChar ~
25248 \SpecialChar ~
25249 \SpecialChar ~
25250  72\SpecialChar ~
25251 \SpecialChar ~
25252 \SpecialChar ~
25253 \SpecialChar ~
25254 \SpecialChar ~
25255 \SpecialChar ~
25256 \SpecialChar ~
25257 \SpecialChar ~
25258  rr\SpecialChar ~
25259 \SpecialChar ~
25260 \SpecialChar ~
25261  a 
25262 \newline 
25263 001E 54 01\SpecialChar ~
25264 \SpecialChar ~
25265 \SpecialChar ~
25266 \SpecialChar ~
25267 \SpecialChar ~
25268 \SpecialChar ~
25269 \SpecialChar ~
25270 \SpecialChar ~
25271 \SpecialChar ~
25272 \SpecialChar ~
25273 \SpecialChar ~
25274 \SpecialChar ~
25275 \SpecialChar ~
25276 \SpecialChar ~
25277 \SpecialChar ~
25278  73\SpecialChar ~
25279 \SpecialChar ~
25280 \SpecialChar ~
25281 \SpecialChar ~
25282 \SpecialChar ~
25283 \SpecialChar ~
25284 \SpecialChar ~
25285 \SpecialChar ~
25286  anl\SpecialChar ~
25287 \SpecialChar ~
25288  a,#0x01 
25289 \newline 
25290 0020 F5*03\SpecialChar ~
25291 \SpecialChar ~
25292 \SpecialChar ~
25293 \SpecialChar ~
25294 \SpecialChar ~
25295 \SpecialChar ~
25296 \SpecialChar ~
25297 \SpecialChar ~
25298 \SpecialChar ~
25299 \SpecialChar ~
25300 \SpecialChar ~
25301 \SpecialChar ~
25302 \SpecialChar ~
25303 \SpecialChar ~
25304 \SpecialChar ~
25305  74\SpecialChar ~
25306 \SpecialChar ~
25307 \SpecialChar ~
25308 \SpecialChar ~
25309 \SpecialChar ~
25310 \SpecialChar ~
25311 \SpecialChar ~
25312 \SpecialChar ~
25313  mov\SpecialChar ~
25314 \SpecialChar ~
25315  _foo_aob1_1_1,a 
25316 \newline 
25317 \SpecialChar ~
25318 \SpecialChar ~
25319 \SpecialChar ~
25320 \SpecialChar ~
25321 \SpecialChar ~
25322 \SpecialChar ~
25323 \SpecialChar ~
25324 \SpecialChar ~
25325 \SpecialChar ~
25326 \SpecialChar ~
25327 \SpecialChar ~
25328 \SpecialChar ~
25329 \SpecialChar ~
25330 \SpecialChar ~
25331 \SpecialChar ~
25332 \SpecialChar ~
25333 \SpecialChar ~
25334 \SpecialChar ~
25335 \SpecialChar ~
25336 \SpecialChar ~
25337 \SpecialChar ~
25338 \SpecialChar ~
25339 \SpecialChar ~
25340 \SpecialChar ~
25341 \SpecialChar ~
25342  75 ;\SpecialChar ~
25343  hob.c 11 
25344 \newline 
25345 0022 E5*01\SpecialChar ~
25346 \SpecialChar ~
25347 \SpecialChar ~
25348 \SpecialChar ~
25349 \SpecialChar ~
25350 \SpecialChar ~
25351 \SpecialChar ~
25352 \SpecialChar ~
25353 \SpecialChar ~
25354 \SpecialChar ~
25355 \SpecialChar ~
25356 \SpecialChar ~
25357 \SpecialChar ~
25358 \SpecialChar ~
25359 \SpecialChar ~
25360  76\SpecialChar ~
25361 \SpecialChar ~
25362 \SpecialChar ~
25363 \SpecialChar ~
25364 \SpecialChar ~
25365 \SpecialChar ~
25366 \SpecialChar ~
25367 \SpecialChar ~
25368  mov\SpecialChar ~
25369 \SpecialChar ~
25370  a,(_gint + 1) 
25371 \newline 
25372 0024 13\SpecialChar ~
25373 \SpecialChar ~
25374 \SpecialChar ~
25375 \SpecialChar ~
25376 \SpecialChar ~
25377 \SpecialChar ~
25378 \SpecialChar ~
25379 \SpecialChar ~
25380 \SpecialChar ~
25381 \SpecialChar ~
25382 \SpecialChar ~
25383 \SpecialChar ~
25384 \SpecialChar ~
25385 \SpecialChar ~
25386 \SpecialChar ~
25387 \SpecialChar ~
25388 \SpecialChar ~
25389 \SpecialChar ~
25390  77\SpecialChar ~
25391 \SpecialChar ~
25392 \SpecialChar ~
25393 \SpecialChar ~
25394 \SpecialChar ~
25395 \SpecialChar ~
25396 \SpecialChar ~
25397 \SpecialChar ~
25398  rrc\SpecialChar ~
25399 \SpecialChar ~
25400  a 
25401 \newline 
25402 0025 92*02\SpecialChar ~
25403 \SpecialChar ~
25404 \SpecialChar ~
25405 \SpecialChar ~
25406 \SpecialChar ~
25407 \SpecialChar ~
25408 \SpecialChar ~
25409 \SpecialChar ~
25410 \SpecialChar ~
25411 \SpecialChar ~
25412 \SpecialChar ~
25413 \SpecialChar ~
25414 \SpecialChar ~
25415 \SpecialChar ~
25416 \SpecialChar ~
25417  78\SpecialChar ~
25418 \SpecialChar ~
25419 \SpecialChar ~
25420 \SpecialChar ~
25421 \SpecialChar ~
25422 \SpecialChar ~
25423 \SpecialChar ~
25424 \SpecialChar ~
25425  mov\SpecialChar ~
25426 \SpecialChar ~
25427  _foo_aob2_1_1,c 
25428 \newline 
25429 \SpecialChar ~
25430 \SpecialChar ~
25431 \SpecialChar ~
25432 \SpecialChar ~
25433 \SpecialChar ~
25434 \SpecialChar ~
25435 \SpecialChar ~
25436 \SpecialChar ~
25437 \SpecialChar ~
25438 \SpecialChar ~
25439 \SpecialChar ~
25440 \SpecialChar ~
25441 \SpecialChar ~
25442 \SpecialChar ~
25443 \SpecialChar ~
25444 \SpecialChar ~
25445 \SpecialChar ~
25446 \SpecialChar ~
25447 \SpecialChar ~
25448 \SpecialChar ~
25449 \SpecialChar ~
25450 \SpecialChar ~
25451 \SpecialChar ~
25452 \SpecialChar ~
25453 \SpecialChar ~
25454  79 ;\SpecialChar ~
25455  hob.c 12 
25456 \newline 
25457 0027 E5*01\SpecialChar ~
25458 \SpecialChar ~
25459 \SpecialChar ~
25460 \SpecialChar ~
25461 \SpecialChar ~
25462 \SpecialChar ~
25463 \SpecialChar ~
25464 \SpecialChar ~
25465 \SpecialChar ~
25466 \SpecialChar ~
25467 \SpecialChar ~
25468 \SpecialChar ~
25469 \SpecialChar ~
25470 \SpecialChar ~
25471 \SpecialChar ~
25472  80\SpecialChar ~
25473 \SpecialChar ~
25474 \SpecialChar ~
25475 \SpecialChar ~
25476 \SpecialChar ~
25477 \SpecialChar ~
25478 \SpecialChar ~
25479 \SpecialChar ~
25480  mov\SpecialChar ~
25481 \SpecialChar ~
25482  a,(_gint + 1) 
25483 \newline 
25484 0029 A2 E3\SpecialChar ~
25485 \SpecialChar ~
25486 \SpecialChar ~
25487 \SpecialChar ~
25488 \SpecialChar ~
25489 \SpecialChar ~
25490 \SpecialChar ~
25491 \SpecialChar ~
25492 \SpecialChar ~
25493 \SpecialChar ~
25494 \SpecialChar ~
25495 \SpecialChar ~
25496 \SpecialChar ~
25497 \SpecialChar ~
25498 \SpecialChar ~
25499  81\SpecialChar ~
25500 \SpecialChar ~
25501 \SpecialChar ~
25502 \SpecialChar ~
25503 \SpecialChar ~
25504 \SpecialChar ~
25505 \SpecialChar ~
25506 \SpecialChar ~
25507  mov\SpecialChar ~
25508 \SpecialChar ~
25509  c,acc[3] 
25510 \newline 
25511 002B 92*03\SpecialChar ~
25512 \SpecialChar ~
25513 \SpecialChar ~
25514 \SpecialChar ~
25515 \SpecialChar ~
25516 \SpecialChar ~
25517 \SpecialChar ~
25518 \SpecialChar ~
25519 \SpecialChar ~
25520 \SpecialChar ~
25521 \SpecialChar ~
25522 \SpecialChar ~
25523 \SpecialChar ~
25524 \SpecialChar ~
25525 \SpecialChar ~
25526  82\SpecialChar ~
25527 \SpecialChar ~
25528 \SpecialChar ~
25529 \SpecialChar ~
25530 \SpecialChar ~
25531 \SpecialChar ~
25532 \SpecialChar ~
25533 \SpecialChar ~
25534  mov\SpecialChar ~
25535 \SpecialChar ~
25536  _foo_aob3_1_1,c 
25537 \layout Standard
25538
25539 Other variations of these cases however will 
25540 \emph on 
25541 not
25542 \emph default 
25543  be recognized.
25544  They are standard C expressions, so I heartily recommend these be the only
25545  way to get the highest order bit, (it is portable).
25546  Of course it will be recognized even if it is embedded in other expressions,
25547  e.g.:
25548 \layout Verse
25549
25550
25551 \family typewriter 
25552 xyz = gint + ((gint >> 15) & 1);
25553 \layout Standard
25554
25555 will still be recognized.
25556 \layout Subsection
25557
25558 Higher Order Byte
25559 \begin_inset LatexCommand \index{Higher Order Byte}
25560
25561 \end_inset 
25562
25563  / Higher Order Word
25564 \begin_inset LatexCommand \index{Higher Order Word}
25565
25566 \end_inset 
25567
25568
25569 \layout Standard
25570
25571 It is also frequently required to obtain a higher order byte or word of
25572  a larger integral type (long, int or short types).
25573  SDCC recognizes the following expressions to yield the higher order byte
25574  or word and generates optimized code for it, e.g.:
25575 \layout Verse
25576
25577
25578 \family typewriter 
25579 unsigned int gint; 
25580 \newline 
25581 unsigned long int glong; 
25582 \newline 
25583
25584 \newline 
25585 foo () { 
25586 \newline 
25587 \SpecialChar ~
25588 \SpecialChar ~
25589 unsigned char hob1, hob2; 
25590 \newline 
25591 \SpecialChar ~
25592 \SpecialChar ~
25593 unsigned int how1, how2; 
25594 \newline 
25595 \SpecialChar ~
25596 \SpecialChar ~
25597 ...
25598  
25599 \newline 
25600 \SpecialChar ~
25601 \SpecialChar ~
25602 hob1 = (gint >> 8) & 0xFF; 
25603 \newline 
25604 \SpecialChar ~
25605 \SpecialChar ~
25606 hob2 = glong >> 24; 
25607 \newline 
25608 \SpecialChar ~
25609 \SpecialChar ~
25610 how1 = (glong >> 16) & 0xFFFF; 
25611 \newline 
25612 \SpecialChar ~
25613 \SpecialChar ~
25614 how2 = glong >> 8; 
25615 \newline 
25616 \SpecialChar ~
25617 \SpecialChar ~
25618 ..
25619  
25620 \newline 
25621 }
25622 \layout Standard
25623
25624 will generate the following code:
25625 \layout Verse
25626
25627
25628 \family typewriter 
25629 \SpecialChar ~
25630 \SpecialChar ~
25631 \SpecialChar ~
25632 \SpecialChar ~
25633 \SpecialChar ~
25634 \SpecialChar ~
25635 \SpecialChar ~
25636 \SpecialChar ~
25637 \SpecialChar ~
25638 \SpecialChar ~
25639 \SpecialChar ~
25640 \SpecialChar ~
25641 \SpecialChar ~
25642 \SpecialChar ~
25643 \SpecialChar ~
25644 \SpecialChar ~
25645 \SpecialChar ~
25646 \SpecialChar ~
25647 \SpecialChar ~
25648 \SpecialChar ~
25649 \SpecialChar ~
25650 \SpecialChar ~
25651 \SpecialChar ~
25652 \SpecialChar ~
25653 \SpecialChar ~
25654  91 ;\SpecialChar ~
25655  hob.c 15 
25656 \newline 
25657 0037 85*01*06\SpecialChar ~
25658 \SpecialChar ~
25659 \SpecialChar ~
25660 \SpecialChar ~
25661 \SpecialChar ~
25662 \SpecialChar ~
25663 \SpecialChar ~
25664 \SpecialChar ~
25665 \SpecialChar ~
25666 \SpecialChar ~
25667 \SpecialChar ~
25668 \SpecialChar ~
25669  92\SpecialChar ~
25670 \SpecialChar ~
25671 \SpecialChar ~
25672 \SpecialChar ~
25673 \SpecialChar ~
25674 \SpecialChar ~
25675 \SpecialChar ~
25676 \SpecialChar ~
25677  mov\SpecialChar ~
25678 \SpecialChar ~
25679  _foo_hob1_1_1,(_gint + 1) 
25680 \newline 
25681 \SpecialChar ~
25682 \SpecialChar ~
25683 \SpecialChar ~
25684 \SpecialChar ~
25685 \SpecialChar ~
25686 \SpecialChar ~
25687 \SpecialChar ~
25688 \SpecialChar ~
25689 \SpecialChar ~
25690 \SpecialChar ~
25691 \SpecialChar ~
25692 \SpecialChar ~
25693 \SpecialChar ~
25694 \SpecialChar ~
25695 \SpecialChar ~
25696 \SpecialChar ~
25697 \SpecialChar ~
25698 \SpecialChar ~
25699 \SpecialChar ~
25700 \SpecialChar ~
25701 \SpecialChar ~
25702 \SpecialChar ~
25703 \SpecialChar ~
25704 \SpecialChar ~
25705 \SpecialChar ~
25706  93 ;\SpecialChar ~
25707  hob.c 16 
25708 \newline 
25709 003A 85*05*07\SpecialChar ~
25710 \SpecialChar ~
25711 \SpecialChar ~
25712 \SpecialChar ~
25713 \SpecialChar ~
25714 \SpecialChar ~
25715 \SpecialChar ~
25716 \SpecialChar ~
25717 \SpecialChar ~
25718 \SpecialChar ~
25719 \SpecialChar ~
25720 \SpecialChar ~
25721  94\SpecialChar ~
25722 \SpecialChar ~
25723 \SpecialChar ~
25724 \SpecialChar ~
25725 \SpecialChar ~
25726 \SpecialChar ~
25727 \SpecialChar ~
25728 \SpecialChar ~
25729  mov\SpecialChar ~
25730 \SpecialChar ~
25731  _foo_hob2_1_1,(_glong + 3) 
25732 \newline 
25733 \SpecialChar ~
25734 \SpecialChar ~
25735 \SpecialChar ~
25736 \SpecialChar ~
25737 \SpecialChar ~
25738 \SpecialChar ~
25739 \SpecialChar ~
25740 \SpecialChar ~
25741 \SpecialChar ~
25742 \SpecialChar ~
25743 \SpecialChar ~
25744 \SpecialChar ~
25745 \SpecialChar ~
25746 \SpecialChar ~
25747 \SpecialChar ~
25748 \SpecialChar ~
25749 \SpecialChar ~
25750 \SpecialChar ~
25751 \SpecialChar ~
25752 \SpecialChar ~
25753 \SpecialChar ~
25754 \SpecialChar ~
25755 \SpecialChar ~
25756 \SpecialChar ~
25757 \SpecialChar ~
25758  95 ;\SpecialChar ~
25759  hob.c 17 
25760 \newline 
25761 003D 85*04*08\SpecialChar ~
25762 \SpecialChar ~
25763 \SpecialChar ~
25764 \SpecialChar ~
25765 \SpecialChar ~
25766 \SpecialChar ~
25767 \SpecialChar ~
25768 \SpecialChar ~
25769 \SpecialChar ~
25770 \SpecialChar ~
25771 \SpecialChar ~
25772 \SpecialChar ~
25773  96\SpecialChar ~
25774 \SpecialChar ~
25775 \SpecialChar ~
25776 \SpecialChar ~
25777 \SpecialChar ~
25778 \SpecialChar ~
25779 \SpecialChar ~
25780 \SpecialChar ~
25781  mov\SpecialChar ~
25782 \SpecialChar ~
25783  _foo_how1_1_1,(_glong + 2) 
25784 \newline 
25785 0040 85*05*09\SpecialChar ~
25786 \SpecialChar ~
25787 \SpecialChar ~
25788 \SpecialChar ~
25789 \SpecialChar ~
25790 \SpecialChar ~
25791 \SpecialChar ~
25792 \SpecialChar ~
25793 \SpecialChar ~
25794 \SpecialChar ~
25795 \SpecialChar ~
25796 \SpecialChar ~
25797  97\SpecialChar ~
25798 \SpecialChar ~
25799 \SpecialChar ~
25800 \SpecialChar ~
25801 \SpecialChar ~
25802 \SpecialChar ~
25803 \SpecialChar ~
25804 \SpecialChar ~
25805  mov\SpecialChar ~
25806 \SpecialChar ~
25807  (_foo_how1_1_1 + 1),(_glong + 3) 
25808 \newline 
25809 0043 85*03*0A\SpecialChar ~
25810 \SpecialChar ~
25811 \SpecialChar ~
25812 \SpecialChar ~
25813 \SpecialChar ~
25814 \SpecialChar ~
25815 \SpecialChar ~
25816 \SpecialChar ~
25817 \SpecialChar ~
25818 \SpecialChar ~
25819 \SpecialChar ~
25820 \SpecialChar ~
25821  98\SpecialChar ~
25822 \SpecialChar ~
25823 \SpecialChar ~
25824 \SpecialChar ~
25825 \SpecialChar ~
25826 \SpecialChar ~
25827 \SpecialChar ~
25828 \SpecialChar ~
25829  mov\SpecialChar ~
25830 \SpecialChar ~
25831  _foo_how2_1_1,(_glong + 1) 
25832 \newline 
25833 0046 85*04*0B\SpecialChar ~
25834 \SpecialChar ~
25835 \SpecialChar ~
25836 \SpecialChar ~
25837 \SpecialChar ~
25838 \SpecialChar ~
25839 \SpecialChar ~
25840 \SpecialChar ~
25841 \SpecialChar ~
25842 \SpecialChar ~
25843 \SpecialChar ~
25844 \SpecialChar ~
25845  99\SpecialChar ~
25846 \SpecialChar ~
25847 \SpecialChar ~
25848 \SpecialChar ~
25849 \SpecialChar ~
25850 \SpecialChar ~
25851 \SpecialChar ~
25852 \SpecialChar ~
25853  mov\SpecialChar ~
25854 \SpecialChar ~
25855  (_foo_how2_1_1 + 1),(_glong + 2) 
25856 \layout Standard
25857
25858 Again, variations of these cases may 
25859 \emph on 
25860 not
25861 \emph default 
25862  be recognized.
25863  They are standard C expressions, so I heartily recommend these be the only
25864  way to get the higher order byte/word, (it is portable).
25865  Of course it will be recognized even if it is embedded in other expressions,
25866  e.g.:
25867 \layout Verse
25868
25869
25870 \family typewriter 
25871 xyz = gint + ((gint >> 8) & 0xFF);
25872 \layout Standard
25873
25874 will still be recognized.
25875 \layout Subsection
25876
25877 Peephole Optimizer
25878 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
25879
25880 \end_inset 
25881
25882
25883 \begin_inset LatexCommand \index{Peephole optimizer}
25884
25885 \end_inset 
25886
25887
25888 \layout Standard
25889
25890 The compiler uses a rule based, pattern matching and re-writing mechanism
25891  for peep-hole optimization.
25892  It is inspired by 
25893 \emph on 
25894 copt
25895 \emph default 
25896  a peep-hole optimizer by Christopher W.
25897  Fraser (cwfraser\SpecialChar ~
25898 @\SpecialChar ~
25899 microsoft.com).
25900  A default set of rules are compiled into the compiler, additional rules
25901  may be added with the 
25902 \emph on 
25903 -
25904 \begin_inset ERT
25905 status Collapsed
25906
25907 \layout Standard
25908
25909 \backslash 
25910 /
25911 \end_inset 
25912
25913 -peep-file
25914 \begin_inset LatexCommand \index{-\/-peep-file}
25915
25916 \end_inset 
25917
25918  <filename>
25919 \emph default 
25920  option.
25921  The rule language is best illustrated with examples.
25922 \layout Verse
25923
25924
25925 \family typewriter 
25926 replace { 
25927 \newline 
25928 \SpecialChar ~
25929 \SpecialChar ~
25930 mov %1,a 
25931 \newline 
25932 \SpecialChar ~
25933 \SpecialChar ~
25934 mov a,%1
25935 \newline 
25936 } by {
25937 \newline 
25938 \SpecialChar ~
25939 \SpecialChar ~
25940 mov %1,a
25941 \newline 
25942 }
25943 \layout Standard
25944
25945 The above rule will change the following assembly
25946 \begin_inset LatexCommand \index{Assembler routines}
25947
25948 \end_inset 
25949
25950  sequence:
25951 \layout Verse
25952
25953
25954 \family typewriter 
25955 mov r1,a 
25956 \newline 
25957 mov a,r1
25958 \layout Standard
25959
25960 to
25961 \layout Verse
25962
25963
25964 \family typewriter 
25965 mov r1,a
25966 \layout Standard
25967
25968 Note: All occurrences of a 
25969 \emph on 
25970 %n
25971 \emph default 
25972  (pattern variable) must denote the same string.
25973  With the above rule, the assembly sequence:
25974 \layout Verse
25975
25976
25977 \family typewriter 
25978 mov r1,a 
25979 \newline 
25980 mov a,r2
25981 \layout Standard
25982
25983 will remain unmodified.
25984 \newline 
25985
25986 \newline 
25987 Other special case optimizations may be added by the user (via 
25988 \emph on 
25989 -
25990 \begin_inset ERT
25991 status Collapsed
25992
25993 \layout Standard
25994
25995 \backslash 
25996 /
25997 \end_inset 
25998
25999 -peep-file option
26000 \emph default 
26001 ).
26002  E.g.
26003  some variants of the 8051 MCU
26004 \begin_inset LatexCommand \index{MCS51 variants}
26005
26006 \end_inset 
26007
26008  allow only 
26009 \family typewriter 
26010 ajmp
26011 \family default 
26012  and 
26013 \family typewriter 
26014 acall
26015 \family default 
26016 .
26017  The following two rules will change all 
26018 \family typewriter 
26019 ljmp
26020 \family default 
26021  and 
26022 \family typewriter 
26023 lcall
26024 \family default 
26025  to 
26026 \family typewriter 
26027 ajmp
26028 \family default 
26029  and 
26030 \family typewriter 
26031 acall
26032 \layout Verse
26033
26034
26035 \family typewriter 
26036 replace { lcall %1 } by { acall %1 } 
26037 \newline 
26038 replace { ljmp %1 } by { ajmp %1 }
26039 \layout Standard
26040
26041 The 
26042 \emph on 
26043 inline-assembler code
26044 \emph default 
26045  is also passed through the peep hole optimizer, thus the peephole optimizer
26046  can also be used as an assembly level macro expander.
26047  The rules themselves are MCU dependent whereas the rule language infra-structur
26048 e is MCU independent.
26049  Peephole optimization rules for other MCU can be easily programmed using
26050  the rule language.
26051 \newline 
26052
26053 \newline 
26054 The syntax for a rule is as follows:
26055 \layout Verse
26056
26057
26058 \family typewriter 
26059 rule := replace [ restart ] '{' <assembly sequence> '
26060 \backslash 
26061 n' 
26062 \newline 
26063 \SpecialChar ~
26064  \SpecialChar ~
26065  \SpecialChar ~
26066  \SpecialChar ~
26067  \SpecialChar ~
26068  \SpecialChar ~
26069  \SpecialChar ~
26070  \SpecialChar ~
26071  \SpecialChar ~
26072  \SpecialChar ~
26073  \SpecialChar ~
26074  \SpecialChar ~
26075  \SpecialChar ~
26076  \SpecialChar ~
26077  '}' by '{' '
26078 \backslash 
26079 n' 
26080 \newline 
26081 \SpecialChar ~
26082  \SpecialChar ~
26083  \SpecialChar ~
26084  \SpecialChar ~
26085  \SpecialChar ~
26086  \SpecialChar ~
26087  \SpecialChar ~
26088  \SpecialChar ~
26089  \SpecialChar ~
26090  \SpecialChar ~
26091  \SpecialChar ~
26092  \SpecialChar ~
26093  \SpecialChar ~
26094  \SpecialChar ~
26095  \SpecialChar ~
26096  \SpecialChar ~
26097  <assembly sequence> '
26098 \backslash 
26099 n' 
26100 \newline 
26101 \SpecialChar ~
26102  \SpecialChar ~
26103  \SpecialChar ~
26104  \SpecialChar ~
26105  \SpecialChar ~
26106  \SpecialChar ~
26107  \SpecialChar ~
26108  \SpecialChar ~
26109  \SpecialChar ~
26110  \SpecialChar ~
26111  \SpecialChar ~
26112  \SpecialChar ~
26113  \SpecialChar ~
26114  \SpecialChar ~
26115  '}' [if <functionName> ] '
26116 \backslash 
26117 n' 
26118 \layout Standard
26119
26120 <assembly sequence> := assembly instruction (each instruction including
26121  labels must be on a separate line).
26122 \newline 
26123
26124 \newline 
26125 The optimizer will apply to the rules one by one from the top in the sequence
26126  of their appearance, it will terminate when all rules are exhausted.
26127  If the 'restart' option is specified, then the optimizer will start matching
26128  the rules again from the top, this option for a rule is expensive (performance)
26129 , it is intended to be used in situations where a transformation will trigger
26130  the same rule again.
26131  An example of this (not a good one, it has side effects) is the following
26132  rule:
26133 \layout Verse
26134
26135
26136 \family typewriter 
26137 replace restart { 
26138 \newline 
26139 \SpecialChar ~
26140 \SpecialChar ~
26141 pop %1 
26142 \newline 
26143 \SpecialChar ~
26144 \SpecialChar ~
26145 push %1 } by { 
26146 \newline 
26147 \SpecialChar ~
26148 \SpecialChar ~
26149 ; nop 
26150 \newline 
26151 }
26152 \layout Standard
26153
26154 Note that the replace pattern cannot be a blank, but can be a comment line.
26155  Without the 'restart' option only the innermost 'pop' 'push' pair would
26156  be eliminated, i.e.:
26157 \layout Verse
26158
26159
26160 \family typewriter 
26161 pop ar1 
26162 \newline 
26163 pop ar2 
26164 \newline 
26165 push ar2 
26166 \newline 
26167 push ar1
26168 \layout Standard
26169
26170 would result in:
26171 \layout Verse
26172
26173
26174 \family typewriter 
26175 pop ar1 
26176 \newline 
26177 ; nop 
26178 \newline 
26179 push ar1
26180 \layout Standard
26181
26182
26183 \emph on 
26184 with
26185 \emph default 
26186  the restart option the rule will be applied again to the resulting code
26187  and then all the pop-push pairs will be eliminated to yield:
26188 \layout Verse
26189
26190
26191 \family typewriter 
26192 ; nop 
26193 \newline 
26194 ; nop
26195 \layout Standard
26196
26197 A conditional function can be attached to a rule.
26198  Attaching rules are somewhat more involved, let me illustrate this with
26199  an example.
26200 \layout Verse
26201
26202
26203 \family typewriter 
26204 replace { 
26205 \newline 
26206 \SpecialChar ~
26207  \SpecialChar ~
26208  \SpecialChar ~
26209 ljmp %5 
26210 \newline 
26211 %2:
26212 \newline 
26213 } by { 
26214 \newline 
26215 \SpecialChar ~
26216  \SpecialChar ~
26217  \SpecialChar ~
26218 sjmp %5 
26219 \newline 
26220 %2:
26221 \newline 
26222 } if labelInRange
26223 \layout Standard
26224
26225 The optimizer does a look-up of a function name table defined in function
26226  
26227 \emph on 
26228 callFuncByName
26229 \emph default 
26230  in the source file SDCCpeeph.c, with the name 
26231 \emph on 
26232 labelInRange
26233 \emph default 
26234 .
26235  If it finds a corresponding entry the function is called.
26236  Note there can be no parameters specified for these functions, in this
26237  case the use of 
26238 \emph on 
26239 %5
26240 \emph default 
26241  is crucial, since the function 
26242 \emph on 
26243 labelInRange
26244 \emph default 
26245  expects to find the label in that particular variable (the hash table containin
26246 g the variable bindings is passed as a parameter).
26247  If you want to code more such functions, take a close look at the function
26248  labelInRange and the calling mechanism in source file SDCCpeeph.c.
26249  Currently implemented are 
26250 \emph on 
26251 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
26252  24bitMode, portIsDS390, 24bitModeAndPortDS390 
26253 \emph default 
26254 and
26255 \emph on 
26256  notVolatile
26257 \emph default 
26258 .
26259 \layout Standard
26260
26261 I know this whole thing is a little kludgey, but maybe some day we will
26262  have some better means.
26263  If you are looking at this file, you will see the default rules that are
26264  compiled into the compiler, you can add your own rules in the default set
26265  there if you get tired of specifying the -
26266 \begin_inset ERT
26267 status Collapsed
26268
26269 \layout Standard
26270
26271 \backslash 
26272 /
26273 \end_inset 
26274
26275 -peep-file option.
26276 \layout Section
26277
26278 ANSI-Compliance
26279 \begin_inset LatexCommand \index{ANSI-compliance}
26280
26281 \end_inset 
26282
26283
26284 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
26285
26286 \end_inset 
26287
26288
26289 \layout Standard
26290
26291 Deviations from the compliance:
26292 \layout Itemize
26293
26294 functions are not reentrant
26295 \begin_inset LatexCommand \index{reentrant}
26296
26297 \end_inset 
26298
26299  unless explicitly declared as such or the 
26300 \series bold 
26301 -
26302 \begin_inset ERT
26303 status Collapsed
26304
26305 \layout Standard
26306
26307 \backslash 
26308 /
26309 \end_inset 
26310
26311 -stack-auto
26312 \begin_inset LatexCommand \index{-\/-stack-auto}
26313
26314 \end_inset 
26315
26316
26317 \series default 
26318  command line option is specified.
26319 \layout Itemize
26320
26321 structures and unions cannot be assigned values directly, cannot be passed
26322  as function parameters or assigned to each other and cannot be a return
26323  value from a function, e.g.:
26324 \begin_deeper 
26325 \layout Verse
26326
26327
26328 \family typewriter 
26329 struct s { ...
26330  }; 
26331 \newline 
26332 struct s s1, s2; 
26333 \newline 
26334 foo() 
26335 \newline 
26336
26337 \newline 
26338 \SpecialChar ~
26339 \SpecialChar ~
26340 \SpecialChar ~
26341 \SpecialChar ~
26342 ...
26343  
26344 \newline 
26345 \SpecialChar ~
26346 \SpecialChar ~
26347 \SpecialChar ~
26348 \SpecialChar ~
26349 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
26350 \newline 
26351 \SpecialChar ~
26352 \SpecialChar ~
26353 \SpecialChar ~
26354 \SpecialChar ~
26355 ...
26356  
26357 \newline 
26358 }
26359 \newline 
26360 struct s foo1 (struct s parms) /* invalid in SDCC although allowed in ANSI
26361  */
26362 \newline 
26363
26364 \newline 
26365 \SpecialChar ~
26366 \SpecialChar ~
26367 \SpecialChar ~
26368 \SpecialChar ~
26369 struct s rets; 
26370 \newline 
26371 \SpecialChar ~
26372 \SpecialChar ~
26373 \SpecialChar ~
26374 \SpecialChar ~
26375 ...
26376  
26377 \newline 
26378 \SpecialChar ~
26379 \SpecialChar ~
26380 \SpecialChar ~
26381 \SpecialChar ~
26382 return rets;/* is invalid in SDCC although allowed in ANSI */ 
26383 \newline 
26384 }
26385 \end_deeper 
26386 \layout Itemize
26387
26388 initialization of structure arrays must be fully braced.
26389 \begin_deeper 
26390 \layout Verse
26391
26392
26393 \family typewriter 
26394 struct s { char x } a[] = {1, 2}; /* invalid in SDCC */
26395 \newline 
26396 struct s { char x } a[] = {{1}, {2}}; /* OK */
26397 \end_deeper 
26398 \layout Itemize
26399
26400 'long long
26401 \begin_inset LatexCommand \index{long long (not supported)}
26402
26403 \end_inset 
26404
26405 ' (64 bit integers
26406 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
26407
26408 \end_inset 
26409
26410 ) not supported.
26411 \layout Itemize
26412
26413 'double
26414 \begin_inset LatexCommand \index{double (not supported)}
26415
26416 \end_inset 
26417
26418 ' precision floating point 
26419 \begin_inset LatexCommand \index{Floating point support}
26420
26421 \end_inset 
26422
26423 not supported.
26424 \layout Itemize
26425
26426 Old K&R style
26427 \begin_inset LatexCommand \index{K\&R style}
26428
26429 \end_inset 
26430
26431  function declarations are NOT allowed.
26432 \begin_deeper 
26433 \layout Verse
26434
26435
26436 \family typewriter 
26437 foo(i,j) /* this old style of function declarations */ 
26438 \newline 
26439 int i,j; /* are valid in ANSI but not valid in SDCC */ 
26440 \newline 
26441
26442 \newline 
26443 \SpecialChar ~
26444 \SpecialChar ~
26445 \SpecialChar ~
26446 \SpecialChar ~
26447 ...
26448  
26449 \newline 
26450 }
26451 \end_deeper 
26452 \layout Itemize
26453
26454 Most enhancements in C99 are not supported, f.e.:
26455 \begin_deeper 
26456 \layout Verse
26457
26458
26459 \family typewriter 
26460 \series bold 
26461 inline
26462 \series default 
26463  int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
26464  in C99 */
26465 \newline 
26466 for (
26467 \series bold 
26468 int
26469 \series default 
26470  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
26471 \end_deeper 
26472 \layout Itemize
26473
26474 Certain words that are valid identifiers in the standard may be reserved
26475  words in SDCC unless the 
26476 \series bold 
26477 -
26478 \begin_inset ERT
26479 status Collapsed
26480
26481 \layout Standard
26482
26483 \backslash 
26484 /
26485 \end_inset 
26486
26487 -std-c89
26488 \begin_inset LatexCommand \index{-\/-std-c89}
26489
26490 \end_inset 
26491
26492  or -
26493 \begin_inset ERT
26494 status Collapsed
26495
26496 \layout Standard
26497
26498 \backslash 
26499 /
26500 \end_inset 
26501
26502 -std-c99
26503 \begin_inset LatexCommand \index{-\/-std-c99}
26504
26505 \end_inset 
26506
26507
26508 \series default 
26509  command line options are used.
26510  These may include (depending on the selected processor): 'at', 'banked',
26511  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
26512 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
26513  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
26514  '_naked'.
26515  Compliant equivalents of these keywords are always available in a form
26516  that begin with two underscores
26517 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
26518
26519 \end_inset 
26520
26521 , f.e.
26522  '__data' instead of 'data'.
26523 \layout Section
26524
26525 Cyclomatic Complexity
26526 \begin_inset LatexCommand \index{Cyclomatic complexity}
26527
26528 \end_inset 
26529
26530
26531 \layout Standard
26532
26533 Cyclomatic complexity of a function is defined as the number of independent
26534  paths the program can take during execution of the function.
26535  This is an important number since it defines the number test cases you
26536  have to generate to validate the function.
26537  The accepted industry standard for complexity number is 10, if the cyclomatic
26538  complexity reported by SDCC exceeds 10 you should think about simplification
26539  of the function logic.
26540  Note that the complexity level is not related to the number of lines of
26541  code in a function.
26542  Large functions can have low complexity, and small functions can have large
26543  complexity levels.
26544  
26545 \newline 
26546
26547 \newline 
26548 SDCC uses the following formula to compute the complexity:
26549 \newline 
26550
26551 \layout Standard
26552
26553 complexity = (number of edges in control flow graph) - (number of nodes
26554  in control flow graph) + 2;
26555 \newline 
26556
26557 \newline 
26558 Having said that the industry standard is 10, you should be aware that in
26559  some cases it be may unavoidable to have a complexity level of less than
26560  10.
26561  For example if you have switch statement with more than 10 case labels,
26562  each case label adds one to the complexity level.
26563  The complexity level is by no means an absolute measure of the algorithmic
26564  complexity of the function, it does however provide a good starting point
26565  for which functions you might look at for further optimization.
26566 \layout Section
26567
26568 Retargetting for other Processors
26569 \layout Standard
26570
26571 The issues for retargetting the compiler are far too numerous to be covered
26572  by this document.
26573  What follows is a brief description of each of the seven phases of the
26574  compiler and its MCU dependency.
26575 \layout Itemize
26576
26577 Parsing the source and building the annotated parse tree.
26578  This phase is largely MCU independent (except for the language extensions).
26579  Syntax & semantic checks are also done in this phase, along with some initial
26580  optimizations like back patching labels and the pattern matching optimizations
26581  like bit-rotation etc.
26582 \layout Itemize
26583
26584 The second phase involves generating an intermediate code which can be easy
26585  manipulated during the later phases.
26586  This phase is entirely MCU independent.
26587  The intermediate code generation assumes the target machine has unlimited
26588  number of registers, and designates them with the name iTemp.
26589  The compiler can be made to dump a human readable form of the code generated
26590  by using the -
26591 \begin_inset ERT
26592 status Collapsed
26593
26594 \layout Standard
26595
26596 \backslash 
26597 /
26598 \end_inset 
26599
26600 -dumpraw option.
26601 \layout Itemize
26602
26603 This phase does the bulk of the standard optimizations and is also MCU independe
26604 nt.
26605  This phase can be broken down into several sub-phases:
26606 \newline 
26607
26608 \newline 
26609 Break down intermediate code (iCode) into basic blocks.
26610 \newline 
26611 Do control flow & data flow analysis on the basic blocks.
26612 \newline 
26613 Do local common subexpression elimination, then global subexpression elimination
26614 \newline 
26615 Dead code elimination
26616 \newline 
26617 Loop optimizations
26618 \newline 
26619 If loop optimizations caused any changes then do 'global subexpression eliminati
26620 on' and 'dead code elimination' again.
26621 \layout Itemize
26622
26623 This phase determines the live-ranges; by live range I mean those iTemp
26624  variables defined by the compiler that still survive after all the optimization
26625 s.
26626  Live range analysis
26627 \begin_inset LatexCommand \index{Live range analysis}
26628
26629 \end_inset 
26630
26631  is essential for register allocation, since these computation determines
26632  which of these iTemps will be assigned to registers, and for how long.
26633 \layout Itemize
26634
26635 Phase five is register allocation.
26636  There are two parts to this process.
26637 \newline 
26638
26639 \newline 
26640 The first part I call 'register packing' (for lack of a better term).
26641  In this case several MCU specific expression folding is done to reduce
26642  register pressure.
26643 \newline 
26644
26645 \newline 
26646 The second part is more MCU independent and deals with allocating registers
26647  to the remaining live ranges.
26648  A lot of MCU specific code does creep into this phase because of the limited
26649  number of index registers available in the 8051.
26650 \layout Itemize
26651
26652 The Code generation phase is (unhappily), entirely MCU dependent and very
26653  little (if any at all) of this code can be reused for other MCU.
26654  However the scheme for allocating a homogenized assembler operand for each
26655  iCode operand may be reused.
26656 \layout Itemize
26657
26658 As mentioned in the optimization section the peep-hole optimizer is rule
26659  based system, which can reprogrammed for other MCUs.
26660 \layout Chapter
26661
26662 Compiler internals
26663 \begin_inset LatexCommand \index{Compiler internals}
26664
26665 \end_inset 
26666
26667
26668 \layout Section
26669
26670 The anatomy of the compiler
26671 \begin_inset LatexCommand \label{sub:The-anatomy-of}
26672
26673 \end_inset 
26674
26675
26676 \layout Standard
26677
26678
26679 \shape italic 
26680 This is an excerpt from an article published in Circuit Cellar Magazine
26681  in 
26682 \series bold 
26683 August 2000
26684 \series default 
26685 .
26686  It's a little outdated (the compiler is much more efficient now and user/develo
26687 per friendly), but pretty well exposes the guts of it all.
26688 \shape default 
26689
26690 \newline 
26691
26692 \newline 
26693 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
26694  It is fairly easy to retarget for other 8-bit MCU.
26695  Here we take a look at some of the internals of the compiler.
26696  
26697 \layout Paragraph*
26698
26699 Parsing
26700 \begin_inset LatexCommand \index{Parsing}
26701
26702 \end_inset 
26703
26704  
26705 \layout Standard
26706
26707 Parsing the input source file and creating an AST (Annotated Syntax Tree
26708 \begin_inset LatexCommand \index{Annotated syntax tree}
26709
26710 \end_inset 
26711
26712 ).
26713  This phase also involves propagating types (annotating each node of the
26714  parse tree with type information) and semantic analysis.
26715  There are some MCU specific parsing rules.
26716  For example the storage classes, the extended storage classes are MCU specific
26717  while there may be a xdata storage class for 8051 there is no such storage
26718  class for z80 or Atmel AVR.
26719  SDCC allows MCU specific storage class extensions, i.e.
26720  xdata will be treated as a storage class specifier when parsing 8051 C
26721  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
26722  C code.
26723 \layout Paragraph*
26724
26725 Generating iCode
26726 \begin_inset LatexCommand \index{iCode}
26727
26728 \end_inset 
26729
26730
26731 \layout Standard
26732
26733 Intermediate code generation.
26734  In this phase the AST is broken down into three-operand form (iCode).
26735  These three operand forms are represented as doubly linked lists.
26736  ICode is the term given to the intermediate form generated by the compiler.
26737  ICode example section shows some examples of iCode generated for some simple
26738  C source functions.
26739 \layout Paragraph*
26740
26741 Optimizations
26742 \begin_inset LatexCommand \index{Optimizations}
26743
26744 \end_inset 
26745
26746 .
26747 \layout Standard
26748
26749 Bulk of the target independent optimizations is performed in this phase.
26750  The optimizations include constant propagation, common sub-expression eliminati
26751 on, loop invariant code movement, strength reduction of loop induction variables
26752  and dead-code elimination.
26753 \layout Paragraph*
26754
26755 Live range analysis
26756 \begin_inset LatexCommand \index{Live range analysis}
26757
26758 \end_inset 
26759
26760
26761 \layout Standard
26762
26763 During intermediate code generation phase, the compiler assumes the target
26764  machine has infinite number of registers and generates a lot of temporary
26765  variables.
26766  The live range computation determines the lifetime of each of these compiler-ge
26767 nerated temporaries.
26768  A picture speaks a thousand words.
26769  ICode example sections show the live range annotations for each of the
26770  operand.
26771  It is important to note here, each iCode is assigned a number in the order
26772  of its execution in the function.
26773  The live ranges are computed in terms of these numbers.
26774  The from number is the number of the iCode which first defines the operand
26775  and the to number signifies the iCode which uses this operand last.
26776 \layout Paragraph*
26777
26778 Register Allocation
26779 \begin_inset LatexCommand \index{Register allocation}
26780
26781 \end_inset 
26782
26783
26784 \layout Standard
26785
26786 The register allocation determines the type and number of registers needed
26787  by each operand.
26788  In most MCUs only a few registers can be used for indirect addressing.
26789  In case of 8051 for example the registers R0 & R1 can be used to indirectly
26790  address the internal ram and DPTR to indirectly address the external ram.
26791  The compiler will try to allocate the appropriate register to pointer variables
26792  if it can.
26793  ICode example section shows the operands annotated with the registers assigned
26794  to them.
26795  The compiler will try to keep operands in registers as much as possible;
26796  there are several schemes the compiler uses to do achieve this.
26797  When the compiler runs out of registers the compiler will check to see
26798  if there are any live operands which is not used or defined in the current
26799  basic block being processed, if there are any found then it will push that
26800  operand and use the registers in this block, the operand will then be popped
26801  at the end of the basic block.
26802  
26803 \layout Standard
26804
26805 There are other MCU specific considerations in this phase.
26806  Some MCUs have an accumulator; very short-lived operands could be assigned
26807  to the accumulator instead of a general-purpose register.
26808 \layout Paragraph*
26809
26810 Code generation
26811 \layout Standard
26812
26813 Figure II gives a table of iCode operations supported by the compiler.
26814  The code generation involves translating these operations into corresponding
26815  assembly code for the processor.
26816  This sounds overly simple but that is the essence of code generation.
26817  Some of the iCode operations are generated on a MCU specific manner for
26818  example, the z80 port does not use registers to pass parameters so the
26819  SEND and RECV iCode operations will not be generated, and it also does
26820  not support JUMPTABLES.
26821  
26822 \newline 
26823
26824 \series bold 
26825 \shape italic 
26826 \color red
26827 <Where is Figure II?>
26828 \layout Comment
26829
26830 In the original article Figure II was announced to be downloadable on 
26831 \shape italic 
26832 Circuit Cellar
26833 \shape default 
26834 's web site.
26835  Unfortunately it never seemed to have shown up there, so: where is Figure
26836  II?
26837 \layout Paragraph*
26838
26839 ICode Example
26840 \begin_inset LatexCommand \index{iCode}
26841
26842 \end_inset 
26843
26844
26845 \layout Standard
26846
26847 This section shows some details of iCode.
26848  The example C code does not do anything useful; it is used as an example
26849  to illustrate the intermediate code generated by the compiler.
26850 \layout Verse
26851
26852
26853 \family typewriter 
26854 1.\SpecialChar ~
26855 xdata int * p;
26856 \newline 
26857 2.\SpecialChar ~
26858 int gint;
26859 \newline 
26860 3.\SpecialChar ~
26861 /* This function does nothing useful.
26862  It is used
26863 \newline 
26864 4.\SpecialChar ~
26865 \SpecialChar ~
26866 \SpecialChar ~
26867 \SpecialChar ~
26868 for the purpose of explaining iCode */
26869 \newline 
26870 5.\SpecialChar ~
26871 short function (data int *x)
26872 \newline 
26873 6.\SpecialChar ~
26874 {
26875 \newline 
26876 7.\SpecialChar ~
26877 \SpecialChar ~
26878 \SpecialChar ~
26879 short i=10; \SpecialChar ~
26880 \SpecialChar ~
26881 /* dead initialization eliminated */
26882 \newline 
26883 8.\SpecialChar ~
26884 \SpecialChar ~
26885 \SpecialChar ~
26886 short sum=10; /* dead initialization eliminated */
26887 \newline 
26888 9.\SpecialChar ~
26889 \SpecialChar ~
26890 \SpecialChar ~
26891 short mul;
26892 \newline 
26893 10.\SpecialChar ~
26894 \SpecialChar ~
26895 int j ;
26896 \newline 
26897 11.\SpecialChar ~
26898 \SpecialChar ~
26899 while (*x) *x++ = *p++; 
26900 \newline 
26901 12.\SpecialChar ~
26902 \SpecialChar ~
26903 \SpecialChar ~
26904 \SpecialChar ~
26905 sum = 0 ; 
26906 \newline 
26907 13.\SpecialChar ~
26908 \SpecialChar ~
26909 mul = 0;
26910 \newline 
26911 14.\SpecialChar ~
26912 \SpecialChar ~
26913 /* compiler detects i,j to be induction variables */
26914 \newline 
26915 15.\SpecialChar ~
26916 \SpecialChar ~
26917 for (i = 0, j = 10 ; i < 10 ; i++, j
26918 \family default 
26919 -
26920 \begin_inset ERT
26921 status Collapsed
26922
26923 \layout Standard
26924
26925 \backslash 
26926 /
26927 \end_inset 
26928
26929 -
26930 \family typewriter 
26931 ) {
26932 \newline 
26933 16.\SpecialChar ~
26934 \SpecialChar ~
26935 \SpecialChar ~
26936 \SpecialChar ~
26937 sum += i;
26938 \newline 
26939 17.\SpecialChar ~
26940 \SpecialChar ~
26941 \SpecialChar ~
26942 \SpecialChar ~
26943 mul += i * 3; \SpecialChar ~
26944 \SpecialChar ~
26945 /* this multiplication remains */
26946 \newline 
26947 18.\SpecialChar ~
26948 \SpecialChar ~
26949 \SpecialChar ~
26950 \SpecialChar ~
26951 gint += j * 3;\SpecialChar ~
26952 \SpecialChar ~
26953 /* this multiplication changed to addition */
26954 \newline 
26955 19.\SpecialChar ~
26956 \SpecialChar ~
26957 }
26958 \newline 
26959 20.\SpecialChar ~
26960 \SpecialChar ~
26961 return sum+mul;
26962 \newline 
26963 21.\SpecialChar ~
26964 }
26965 \layout Standard
26966
26967 In addition to the operands each iCode contains information about the filename
26968  and line it corresponds to in the source file.
26969  The first field in the listing should be interpreted as follows:
26970 \newline 
26971
26972 \shape italic 
26973 \size footnotesize 
26974 Filename(linenumber: iCode Execution sequence number : ICode hash table
26975  key : loop depth of the iCode).
26976 \shape default 
26977 \size default 
26978
26979 \newline 
26980 Then follows the human readable form of the ICode operation.
26981  Each operand of this triplet form can be of three basic types a) compiler
26982  generated temporary b) user defined variable c) a constant value.
26983  Note that local variables and parameters are replaced by compiler generated
26984  temporaries.
26985  Live ranges
26986 \begin_inset LatexCommand \index{Live range analysis}
26987
26988 \end_inset 
26989
26990  are computed only for temporaries (i.e.
26991  live ranges are not computed for global variables).
26992  Registers
26993 \begin_inset LatexCommand \index{Register allocation}
26994
26995 \end_inset 
26996
26997  are allocated for temporaries only.
26998  Operands are formatted in the following manner:
26999 \newline 
27000
27001 \shape italic 
27002 \size footnotesize 
27003 Operand Name [lr live-from : live-to ] { type information } [ registers
27004  allocated ].
27005 \shape default 
27006 \size default 
27007
27008 \newline 
27009 As mentioned earlier the live ranges are computed in terms of the execution
27010  sequence number of the iCodes, for example 
27011 \newline 
27012 the iTemp0 is live from (i.e.
27013  first defined in iCode with execution sequence number 3, and is last used
27014  in the iCode with sequence number 5).
27015  For induction variables such as iTemp21 the live range computation extends
27016  the lifetime from the start to the end of the loop.
27017 \newline 
27018 The register allocator used the live range information to allocate registers,
27019  the same registers may be used for different temporaries if their live
27020  ranges do not overlap, for example r0 is allocated to both iTemp6 and to
27021  iTemp17 since their live ranges do not overlap.
27022  In addition the allocator also takes into consideration the type and usage
27023  of a temporary, for example itemp6 is a pointer to near space and is used
27024  as to fetch data from (i.e.
27025  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
27026  Some short lived temporaries are allocated to special registers which have
27027  meaning to the code generator e.g.
27028  iTemp13 is allocated to a pseudo register CC which tells the back end that
27029  the temporary is used only for a conditional jump the code generation makes
27030  use of this information to optimize a compare and jump ICode.
27031 \newline 
27032 There are several loop optimizations
27033 \begin_inset LatexCommand \index{Loop optimization}
27034
27035 \end_inset 
27036
27037  performed by the compiler.
27038  It can detect induction variables iTemp21(i) and iTemp23(j).
27039  Also note the compiler does selective strength reduction
27040 \begin_inset LatexCommand \index{Strength reduction}
27041
27042 \end_inset 
27043
27044 , i.e.
27045  the multiplication of an induction variable in line 18 (gint = j * 3) is
27046  changed to addition, a new temporary iTemp17 is allocated and assigned
27047  a initial value, a constant 3 is then added for each iteration of the loop.
27048  The compiler does not change the multiplication
27049 \begin_inset LatexCommand \index{Multiplication}
27050
27051 \end_inset 
27052
27053  in line 17 however since the processor does support an 8 * 8 bit multiplication.
27054 \newline 
27055 Note the dead code elimination
27056 \begin_inset LatexCommand \index{Dead-code elimination}
27057
27058 \end_inset 
27059
27060  optimization eliminated the dead assignments in line 7 & 8 to I and sum
27061  respectively.
27062 \newline 
27063
27064 \layout Standard
27065
27066
27067 \size footnotesize 
27068 Sample.c (5:1:0:0) _entry($9) :
27069 \layout Standard
27070
27071
27072 \size footnotesize 
27073 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
27074 \layout Standard
27075
27076
27077 \size footnotesize 
27078 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
27079 \layout Standard
27080
27081
27082 \size footnotesize 
27083 Sample.c(11:4:53:0) preHeaderLbl0($11) :
27084 \layout Standard
27085
27086
27087 \size footnotesize 
27088 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
27089  * int}[r2]
27090 \layout Standard
27091
27092
27093 \size footnotesize 
27094 Sample.c(11:6:5:1) _whilecontinue_0($1) :
27095 \layout Standard
27096
27097
27098 \size footnotesize 
27099 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
27100  int}[r0]]
27101 \layout Standard
27102
27103
27104 \size footnotesize 
27105 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
27106 \layout Standard
27107
27108
27109 \size footnotesize 
27110 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
27111  * int}
27112 \layout Standard
27113
27114
27115 \size footnotesize 
27116 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
27117  {short}
27118 \layout Standard
27119
27120
27121 \size footnotesize 
27122 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
27123  * int}[DPTR]]
27124 \layout Standard
27125
27126
27127 \size footnotesize 
27128 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
27129 }[r2 r3]
27130 \layout Standard
27131
27132
27133 \size footnotesize 
27134 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
27135  * int}[r0] + 0x2 {short}
27136 \layout Standard
27137
27138
27139 \size footnotesize 
27140 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
27141 \layout Standard
27142
27143
27144 \size footnotesize 
27145 Sample.c(11:17:21:0)_whilebreak_0($3) :
27146 \layout Standard
27147
27148
27149 \size footnotesize 
27150 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
27151 \layout Standard
27152
27153
27154 \size footnotesize 
27155 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
27156 \layout Standard
27157
27158
27159 \size footnotesize 
27160 Sample.c(15:20:54:0)preHeaderLbl1($13) :
27161 \layout Standard
27162
27163
27164 \size footnotesize 
27165 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
27166 \layout Standard
27167
27168
27169 \size footnotesize 
27170 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
27171 \layout Standard
27172
27173
27174 \size footnotesize 
27175 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
27176 \layout Standard
27177
27178
27179 \size footnotesize 
27180 Sample.c(15:24:26:1)_forcond_0($4) :
27181 \layout Standard
27182
27183
27184 \size footnotesize 
27185 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
27186  < 0xa {short}
27187 \layout Standard
27188
27189
27190 \size footnotesize 
27191 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
27192 \layout Standard
27193
27194
27195 \size footnotesize 
27196 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
27197  + ITemp21 [lr21:38]{short}[r4]
27198 \layout Standard
27199
27200
27201 \size footnotesize 
27202 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
27203  * 0x3 {short}
27204 \layout Standard
27205
27206
27207 \size footnotesize 
27208 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
27209  + iTemp15 [lr29:30]{short}[r1]
27210 \layout Standard
27211
27212
27213 \size footnotesize 
27214 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
27215  r0]- 0x3 {short}
27216 \layout Standard
27217
27218
27219 \size footnotesize 
27220 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
27221 int}[r7 r0]
27222 \layout Standard
27223
27224
27225 \size footnotesize 
27226 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
27227  + 0x1 {short}
27228 \layout Standard
27229
27230
27231 \size footnotesize 
27232 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
27233  r6]- 0x1 {short}
27234 \layout Standard
27235
27236
27237 \size footnotesize 
27238 Sample.c(19:38:47:1) goto _forcond_0($4)
27239 \layout Standard
27240
27241
27242 \size footnotesize 
27243 Sample.c(19:39:48:0)_forbreak_0($7) :
27244 \layout Standard
27245
27246
27247 \size footnotesize 
27248 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
27249  + ITemp11 [lr19:40]{short}[r3]
27250 \layout Standard
27251
27252
27253 \size footnotesize 
27254 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
27255 \layout Standard
27256
27257
27258 \size footnotesize 
27259 Sample.c(20:42:51:0)_return($8) :
27260 \layout Standard
27261
27262
27263 \size footnotesize 
27264 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
27265 \size default 
27266
27267 \newline 
27268
27269 \newline 
27270 Finally the code generated for this function:
27271 \newline 
27272
27273 \layout Standard
27274
27275
27276 \size footnotesize 
27277 .area DSEG (DATA)
27278 \layout Standard
27279
27280
27281 \size footnotesize 
27282 _p::
27283 \layout Standard
27284
27285
27286 \size footnotesize 
27287 \SpecialChar ~
27288 \SpecialChar ~
27289 .ds 2
27290 \layout Standard
27291
27292
27293 \size footnotesize 
27294 _gint::
27295 \layout Standard
27296
27297
27298 \size footnotesize 
27299 \SpecialChar ~
27300 \SpecialChar ~
27301 .ds 2
27302 \layout Standard
27303
27304
27305 \size footnotesize 
27306 ; sample.c 5
27307 \layout Standard
27308
27309
27310 \size footnotesize 
27311 ; ----------------------------------------------
27312 \layout Standard
27313
27314
27315 \size footnotesize 
27316 ; function function
27317 \layout Standard
27318
27319
27320 \size footnotesize 
27321 ; ----------------------------------------------
27322 \layout Standard
27323
27324
27325 \size footnotesize 
27326 _function:
27327 \layout Standard
27328
27329
27330 \size footnotesize 
27331 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
27332 \layout Standard
27333
27334
27335 \size footnotesize 
27336 \SpecialChar ~
27337 \SpecialChar ~
27338 mov r2,dpl
27339 \layout Standard
27340
27341
27342 \size footnotesize 
27343 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
27344 \layout Standard
27345
27346
27347 \size footnotesize 
27348 \SpecialChar ~
27349 \SpecialChar ~
27350 mov ar0,r2
27351 \layout Standard
27352
27353
27354 \size footnotesize 
27355 ;_whilecontinue_0($1) :
27356 \layout Standard
27357
27358
27359 \size footnotesize 
27360 00101$:
27361 \layout Standard
27362
27363
27364 \size footnotesize 
27365 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
27366 \layout Standard
27367
27368
27369 \size footnotesize 
27370 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
27371 \layout Standard
27372
27373
27374 \size footnotesize 
27375 \SpecialChar ~
27376 \SpecialChar ~
27377 mov ar2,@r0
27378 \layout Standard
27379
27380
27381 \size footnotesize 
27382 \SpecialChar ~
27383 \SpecialChar ~
27384 inc r0
27385 \layout Standard
27386
27387
27388 \size footnotesize 
27389 \SpecialChar ~
27390 \SpecialChar ~
27391 mov ar3,@r0
27392 \layout Standard
27393
27394
27395 \size footnotesize 
27396 \SpecialChar ~
27397 \SpecialChar ~
27398 dec r0
27399 \layout Standard
27400
27401
27402 \size footnotesize 
27403 \SpecialChar ~
27404 \SpecialChar ~
27405 mov a,r2
27406 \layout Standard
27407
27408
27409 \size footnotesize 
27410 \SpecialChar ~
27411 \SpecialChar ~
27412 orl a,r3
27413 \layout Standard
27414
27415
27416 \size footnotesize 
27417 \SpecialChar ~
27418 \SpecialChar ~
27419 jz 00103$
27420 \layout Standard
27421
27422
27423 \size footnotesize 
27424 00114$:
27425 \layout Standard
27426
27427
27428 \size footnotesize 
27429 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
27430 \layout Standard
27431
27432
27433 \size footnotesize 
27434 \SpecialChar ~
27435 \SpecialChar ~
27436 mov dpl,_p
27437 \layout Standard
27438
27439
27440 \size footnotesize 
27441 \SpecialChar ~
27442 \SpecialChar ~
27443 mov dph,(_p + 1)
27444 \layout Standard
27445
27446
27447 \size footnotesize 
27448 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
27449 \layout Standard
27450
27451
27452 \size footnotesize 
27453 \SpecialChar ~
27454 \SpecialChar ~
27455 mov a,#0x02
27456 \layout Standard
27457
27458
27459 \size footnotesize 
27460 \SpecialChar ~
27461 \SpecialChar ~
27462 add a,_p
27463 \layout Standard
27464
27465
27466 \size footnotesize 
27467 \SpecialChar ~
27468 \SpecialChar ~
27469 mov _p,a
27470 \layout Standard
27471
27472
27473 \size footnotesize 
27474 \SpecialChar ~
27475 \SpecialChar ~
27476 clr a
27477 \layout Standard
27478
27479
27480 \size footnotesize 
27481 \SpecialChar ~
27482 \SpecialChar ~
27483 addc a,(_p + 1)
27484 \layout Standard
27485
27486
27487 \size footnotesize 
27488 \SpecialChar ~
27489 \SpecialChar ~
27490 mov (_p + 1),a
27491 \layout Standard
27492
27493
27494 \size footnotesize 
27495 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
27496 \layout Standard
27497
27498
27499 \size footnotesize 
27500 \SpecialChar ~
27501 \SpecialChar ~
27502 movx a,@dptr
27503 \layout Standard
27504
27505
27506 \size footnotesize 
27507 \SpecialChar ~
27508 \SpecialChar ~
27509 mov r2,a
27510 \layout Standard
27511
27512
27513 \size footnotesize 
27514 \SpecialChar ~
27515 \SpecialChar ~
27516 inc dptr
27517 \layout Standard
27518
27519
27520 \size footnotesize 
27521 \SpecialChar ~
27522 \SpecialChar ~
27523 movx a,@dptr
27524 \layout Standard
27525
27526
27527 \size footnotesize 
27528 \SpecialChar ~
27529 \SpecialChar ~
27530 mov r3,a
27531 \layout Standard
27532
27533
27534 \size footnotesize 
27535 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
27536 \layout Standard
27537
27538
27539 \size footnotesize 
27540 \SpecialChar ~
27541 \SpecialChar ~
27542 mov @r0,ar2
27543 \layout Standard
27544
27545
27546 \size footnotesize 
27547 \SpecialChar ~
27548 \SpecialChar ~
27549 inc r0
27550 \layout Standard
27551
27552
27553 \size footnotesize 
27554 \SpecialChar ~
27555 \SpecialChar ~
27556 mov @r0,ar3
27557 \layout Standard
27558
27559
27560 \size footnotesize 
27561 ; iTemp6 [lr5:16]{_near * int}[r0] = 
27562 \layout Standard
27563
27564
27565 \size footnotesize 
27566 ; iTemp6 [lr5:16]{_near * int}[r0] + 
27567 \layout Standard
27568
27569
27570 \size footnotesize 
27571 ; 0x2 {short}
27572 \layout Standard
27573
27574
27575 \size footnotesize 
27576 \SpecialChar ~
27577 \SpecialChar ~
27578 inc r0
27579 \layout Standard
27580
27581
27582 \size footnotesize 
27583 ; goto _whilecontinue_0($1)
27584 \layout Standard
27585
27586
27587 \size footnotesize 
27588 \SpecialChar ~
27589 \SpecialChar ~
27590 sjmp 00101$
27591 \layout Standard
27592
27593
27594 \size footnotesize 
27595 ; _whilebreak_0($3) :
27596 \layout Standard
27597
27598
27599 \size footnotesize 
27600 00103$:
27601 \layout Standard
27602
27603
27604 \size footnotesize 
27605 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
27606 \layout Standard
27607
27608
27609 \size footnotesize 
27610 \SpecialChar ~
27611 \SpecialChar ~
27612 mov r2,#0x00
27613 \layout Standard
27614
27615
27616 \size footnotesize 
27617 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
27618 \layout Standard
27619
27620
27621 \size footnotesize 
27622 \SpecialChar ~
27623 \SpecialChar ~
27624 mov r3,#0x00
27625 \layout Standard
27626
27627
27628 \size footnotesize 
27629 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
27630 \layout Standard
27631
27632
27633 \size footnotesize 
27634 \SpecialChar ~
27635 \SpecialChar ~
27636 mov r4,#0x00
27637 \layout Standard
27638
27639
27640 \size footnotesize 
27641 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
27642 \layout Standard
27643
27644
27645 \size footnotesize 
27646 \SpecialChar ~
27647 \SpecialChar ~
27648 mov r5,#0x0A
27649 \layout Standard
27650
27651
27652 \size footnotesize 
27653 \SpecialChar ~
27654 \SpecialChar ~
27655 mov r6,#0x00
27656 \layout Standard
27657
27658
27659 \size footnotesize 
27660 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
27661 \layout Standard
27662
27663
27664 \size footnotesize 
27665 \SpecialChar ~
27666 \SpecialChar ~
27667 mov r7,#0x1E
27668 \layout Standard
27669
27670
27671 \size footnotesize 
27672 \SpecialChar ~
27673 \SpecialChar ~
27674 mov r0,#0x00
27675 \layout Standard
27676
27677
27678 \size footnotesize 
27679 ; _forcond_0($4) :
27680 \layout Standard
27681
27682
27683 \size footnotesize 
27684 00104$:
27685 \layout Standard
27686
27687
27688 \size footnotesize 
27689 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
27690 \layout Standard
27691
27692
27693 \size footnotesize 
27694 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
27695 \layout Standard
27696
27697
27698 \size footnotesize 
27699 \SpecialChar ~
27700 \SpecialChar ~
27701 clr c
27702 \layout Standard
27703
27704
27705 \size footnotesize 
27706 \SpecialChar ~
27707 \SpecialChar ~
27708 mov a,r4
27709 \layout Standard
27710
27711
27712 \size footnotesize 
27713 \SpecialChar ~
27714 \SpecialChar ~
27715 xrl a,#0x80
27716 \layout Standard
27717
27718
27719 \size footnotesize 
27720 \SpecialChar ~
27721 \SpecialChar ~
27722 subb a,#0x8a
27723 \layout Standard
27724
27725
27726 \size footnotesize 
27727 \SpecialChar ~
27728 \SpecialChar ~
27729 jnc 00107$
27730 \layout Standard
27731
27732
27733 \size footnotesize 
27734 00115$:
27735 \layout Standard
27736
27737
27738 \size footnotesize 
27739 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
27740 \layout Standard
27741
27742
27743 \size footnotesize 
27744 ; iTemp21 [lr21:38]{short}[r4]
27745 \layout Standard
27746
27747
27748 \size footnotesize 
27749 \SpecialChar ~
27750 \SpecialChar ~
27751 mov a,r4
27752 \layout Standard
27753
27754
27755 \size footnotesize 
27756 \SpecialChar ~
27757 \SpecialChar ~
27758 add a,r2
27759 \layout Standard
27760
27761
27762 \size footnotesize 
27763 \SpecialChar ~
27764 \SpecialChar ~
27765 mov r2,a
27766 \layout Standard
27767
27768
27769 \size footnotesize 
27770 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
27771 \layout Standard
27772
27773
27774 \size footnotesize 
27775 \SpecialChar ~
27776 \SpecialChar ~
27777 mov b,#0x03
27778 \layout Standard
27779
27780
27781 \size footnotesize 
27782 \SpecialChar ~
27783 \SpecialChar ~
27784 mov a,r4
27785 \layout Standard
27786
27787
27788 \size footnotesize 
27789 \SpecialChar ~
27790 \SpecialChar ~
27791 mul ab
27792 \layout Standard
27793
27794
27795 \size footnotesize 
27796 \SpecialChar ~
27797 \SpecialChar ~
27798 mov r1,a
27799 \layout Standard
27800
27801
27802 \size footnotesize 
27803 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
27804 \layout Standard
27805
27806
27807 \size footnotesize 
27808 ; iTemp15 [lr29:30]{short}[r1]
27809 \layout Standard
27810
27811
27812 \size footnotesize 
27813 \SpecialChar ~
27814 \SpecialChar ~
27815 add a,r3
27816 \layout Standard
27817
27818
27819 \size footnotesize 
27820 \SpecialChar ~
27821 \SpecialChar ~
27822 mov r3,a
27823 \layout Standard
27824
27825
27826 \size footnotesize 
27827 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
27828 \layout Standard
27829
27830
27831 \size footnotesize 
27832 \SpecialChar ~
27833 \SpecialChar ~
27834 mov a,r7
27835 \layout Standard
27836
27837
27838 \size footnotesize 
27839 \SpecialChar ~
27840 \SpecialChar ~
27841 add a,#0xfd
27842 \layout Standard
27843
27844
27845 \size footnotesize 
27846 \SpecialChar ~
27847 \SpecialChar ~
27848 mov r7,a
27849 \layout Standard
27850
27851
27852 \size footnotesize 
27853 \SpecialChar ~
27854 \SpecialChar ~
27855 mov a,r0
27856 \layout Standard
27857
27858
27859 \size footnotesize 
27860 \SpecialChar ~
27861 \SpecialChar ~
27862 addc a,#0xff
27863 \layout Standard
27864
27865
27866 \size footnotesize 
27867 \SpecialChar ~
27868 \SpecialChar ~
27869 mov r0,a
27870 \layout Standard
27871
27872
27873 \size footnotesize 
27874 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
27875 \layout Standard
27876
27877
27878 \size footnotesize 
27879 \SpecialChar ~
27880 \SpecialChar ~
27881 mov a,r7
27882 \layout Standard
27883
27884
27885 \size footnotesize 
27886 \SpecialChar ~
27887 \SpecialChar ~
27888 add a,_gint
27889 \layout Standard
27890
27891
27892 \size footnotesize 
27893 \SpecialChar ~
27894 \SpecialChar ~
27895 mov _gint,a
27896 \layout Standard
27897
27898
27899 \size footnotesize 
27900 \SpecialChar ~
27901 \SpecialChar ~
27902 mov a,r0
27903 \layout Standard
27904
27905
27906 \size footnotesize 
27907 \SpecialChar ~
27908 \SpecialChar ~
27909 addc a,(_gint + 1)
27910 \layout Standard
27911
27912
27913 \size footnotesize 
27914 \SpecialChar ~
27915 \SpecialChar ~
27916 mov (_gint + 1),a
27917 \layout Standard
27918
27919
27920 \size footnotesize 
27921 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
27922 \layout Standard
27923
27924
27925 \size footnotesize 
27926 \SpecialChar ~
27927 \SpecialChar ~
27928 inc r4
27929 \layout Standard
27930
27931
27932 \size footnotesize 
27933 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
27934 \layout Standard
27935
27936
27937 \size footnotesize 
27938 \SpecialChar ~
27939 \SpecialChar ~
27940 dec r5
27941 \layout Standard
27942
27943
27944 \size footnotesize 
27945 \SpecialChar ~
27946 \SpecialChar ~
27947 cjne r5,#0xff,00104$
27948 \layout Standard
27949
27950
27951 \size footnotesize 
27952 \SpecialChar ~
27953 \SpecialChar ~
27954 dec r6
27955 \layout Standard
27956
27957
27958 \size footnotesize 
27959 ; goto _forcond_0($4)
27960 \layout Standard
27961
27962
27963 \size footnotesize 
27964 \SpecialChar ~
27965 \SpecialChar ~
27966 sjmp 00104$
27967 \layout Standard
27968
27969
27970 \size footnotesize 
27971 ; _forbreak_0($7) :
27972 \layout Standard
27973
27974
27975 \size footnotesize 
27976 00107$:
27977 \layout Standard
27978
27979
27980 \size footnotesize 
27981 ; ret iTemp24 [lr40:41]{short}
27982 \layout Standard
27983
27984
27985 \size footnotesize 
27986 \SpecialChar ~
27987 \SpecialChar ~
27988 mov a,r3
27989 \layout Standard
27990
27991
27992 \size footnotesize 
27993 \SpecialChar ~
27994 \SpecialChar ~
27995 add a,r2
27996 \layout Standard
27997
27998
27999 \size footnotesize 
28000 \SpecialChar ~
28001 \SpecialChar ~
28002 mov dpl,a
28003 \layout Standard
28004
28005
28006 \size footnotesize 
28007 ; _return($8) :
28008 \layout Standard
28009
28010
28011 \size footnotesize 
28012 00108$:
28013 \layout Standard
28014
28015
28016 \size footnotesize 
28017 \SpecialChar ~
28018 \SpecialChar ~
28019 ret
28020 \newline 
28021
28022 \layout Section
28023
28024 A few words about basic block successors, predecessors and dominators
28025 \layout Standard
28026
28027 Successors are basic blocks
28028 \begin_inset LatexCommand \index{Basic blocks}
28029
28030 \end_inset 
28031
28032  that might execute after this basic block.
28033 \newline 
28034 Predecessors are basic blocks that might execute before reaching this basic
28035  block.
28036 \newline 
28037 Dominators are basic blocks that WILL execute before reaching this basic
28038  block.
28039 \newline 
28040
28041 \layout Standard
28042
28043 [basic block 1]
28044 \layout Standard
28045
28046 if (something)
28047 \layout Standard
28048
28049 \SpecialChar ~
28050 \SpecialChar ~
28051 \SpecialChar ~
28052 \SpecialChar ~
28053 [basic block 2]
28054 \layout Standard
28055
28056 else
28057 \layout Standard
28058
28059 \SpecialChar ~
28060 \SpecialChar ~
28061 \SpecialChar ~
28062 \SpecialChar ~
28063 [basic block 3]
28064 \layout Standard
28065
28066 [basic block 4]
28067 \newline 
28068
28069 \layout Standard
28070
28071 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
28072 \layout Standard
28073
28074 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
28075 \layout Standard
28076
28077 c) domVect of [BB4] = BB1 ...
28078  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
28079  was executed.
28080 \layout Chapter
28081
28082 Acknowledgments
28083 \layout Standard
28084
28085
28086 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
28087
28088 \end_inset 
28089
28090
28091 \newline 
28092
28093 \newline 
28094
28095 \emph on 
28096 Thanks to all the other volunteer developers who have helped with coding,
28097  testing, web-page creation, distribution sets, etc.
28098  You know who you are :-)
28099 \emph default 
28100
28101 \newline 
28102
28103 \layout Standard
28104
28105 This document was initially written by Sandeep Dutta
28106 \layout Standard
28107
28108 All product names mentioned herein may be trademarks
28109 \begin_inset LatexCommand \index{Trademarks}
28110
28111 \end_inset 
28112
28113  of their respective companies.
28114  
28115 \layout Section*
28116
28117 Alphabetical index
28118 \layout Standard
28119
28120 To avoid confusion, the installation and building options for SDCC itself
28121  (chapter 2) are not part of the index.
28122 \layout Standard
28123
28124
28125 \begin_inset LatexCommand \printindex{}
28126
28127 \end_inset 
28128
28129
28130 \the_end