updated weblinks, index and smaller updates
[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 \usepackage[
6   pdftitle={SDCC Compiler User Guide},
7   pdfauthor={SDCC development team},
8   pdfsubject={installation, user manual},
9   pdfkeywords={8032 8051 ansi c compiler CPU DS390
10                embedded GPL HC08 manual mcs51 microcontroller PIC Z80},
11   colorlinks=true,
12   linkcolor=blue] {hyperref}
13 %
14 \sloppy
15 \tolerance=500          
16 \emergencystretch=30pt 
17 %
18 \date{}
19 \end_preamble
20 \language english
21 \inputencoding default
22 \fontscheme pslatex
23 \graphics default
24 \paperfontsize default
25 \spacing single 
26 \papersize letterpaper
27 \paperpackage a4
28 \use_geometry 1
29 \use_amsmath 0
30 \use_natbib 0
31 \use_numerical_citations 0
32 \paperorientation portrait
33 \leftmargin 30mm
34 \topmargin 20mm
35 \rightmargin 25mm
36 \bottommargin 20mm
37 \secnumdepth 3
38 \tocdepth 3
39 \paragraph_separation indent
40 \defskip medskip
41 \quotes_language swedish
42 \quotes_times 2
43 \papercolumns 1
44 \papersides 1
45 \paperpagestyle fancy
46
47 \layout Comment
48
49 Please note: double dashed longoptions (e.g.
50  --version) are written this way: -
51 \begin_inset ERT
52 status Collapsed
53
54 \layout Standard
55
56 \backslash 
57 /
58 \end_inset 
59
60 -
61 \layout Comment
62
63 Two resp.
64  three consecutive dashes simply result in a long resp.
65  extra long dash.
66 \layout Comment
67
68 Architecture specific stuff (like memory models, code examples) should maybe
69  later go
70 \layout Comment
71
72 into seperate sections/chapters/appendices (it is hard to document PIC or
73  Z80 in 
74 \layout Comment
75
76 a 8051 centered document) - for now simply add.
77 \layout Title
78
79 SDCC Compiler User Guide
80 \layout Date
81
82
83 \size normal 
84 SDCC 2.5.0
85 \size footnotesize 
86
87 \newline 
88 $Date$ 
89 \newline 
90 $Revision$
91 \layout Comment
92
93 The above strings enclosed in $ are automatically updated by cvs
94 \layout Standard
95
96
97 \begin_inset LatexCommand \tableofcontents{}
98
99 \end_inset 
100
101
102 \layout Chapter
103
104 Introduction
105 \layout Section
106
107 About SDCC
108 \layout Standard
109
110
111 \series bold 
112 SDCC
113 \series default 
114  (
115 \emph on 
116 S
117 \emph default 
118 mall 
119 \emph on 
120 D
121 \emph default 
122 evice 
123 \emph on 
124 C
125 \emph default 
126  
127 \emph on 
128 C
129 \emph default 
130 ompiler) is an open source, retargettable, optimizing ANSI-C compiler by
131  
132 \series bold 
133 Sandeep Dutta
134 \series default 
135  designed for 8 bit Microprocessors.
136  The current version targets Intel MCS51 based Microprocessors (8031, 8032,
137  8051, 8052
138 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
139
140 \end_inset 
141
142 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
143  Zilog Z80 based MCUs.
144  It can be retargetted for other microprocessors, support for Microchip
145  PIC, Atmel AVR is under development.
146  The entire source code for the compiler is distributed under GPL.
147  SDCC uses ASXXXX
148 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
149
150 \end_inset 
151
152  & ASLINK
153 \begin_inset LatexCommand \index{aslink}
154
155 \end_inset 
156
157 , an open source retargettable assembler & linker.
158  SDCC has extensive language extensions suitable for utilizing various microcont
159 rollers and underlying hardware effectively.
160  
161 \newline 
162
163 \newline 
164 In addition to the MCU specific optimizations SDCC also does a host of standard
165  optimizations like:
166 \layout Itemize
167
168 global sub expression elimination, 
169 \layout Itemize
170
171 loop optimizations (loop invariant, strength reduction of induction variables
172  and loop reversing), 
173 \layout Itemize
174
175 constant folding & propagation, 
176 \layout Itemize
177
178 copy propagation, 
179 \layout Itemize
180
181 dead code elimination 
182 \layout Itemize
183
184 jump tables for 
185 \emph on 
186 switch
187 \emph default 
188  statements.
189 \layout Standard
190
191 For the back-end SDCC uses a global register allocation scheme which should
192  be well suited for other 8 bit MCUs.
193  
194 \newline 
195
196 \newline 
197 The peep hole optimizer uses a rule based substitution mechanism which is
198  MCU independent.
199  
200 \newline 
201
202 \newline 
203 Supported data-types are:
204 \layout Itemize
205
206 char (8 bits, 1 byte), 
207 \layout Itemize
208
209 short and int (16 bits, 2 bytes), 
210 \layout Itemize
211
212 long (32 bit, 4 bytes)
213 \layout Itemize
214
215 float (4 byte IEEE).
216  
217 \layout Standard
218
219 The compiler also allows 
220 \emph on 
221 inline assembler code
222 \emph default 
223  to be embedded anywhere in a function.
224  In addition, routines developed in assembly can also be called.
225 \newline 
226
227 \newline 
228 SDCC also provides an option (-
229 \begin_inset ERT
230 status Collapsed
231
232 \layout Standard
233
234 \backslash 
235 /
236 \end_inset 
237
238 -cyclomatic) to report the relative complexity of a function.
239  These functions can then be further optimized, or hand coded in assembly
240  if needed.
241  
242 \newline 
243
244 \newline 
245 SDCC also comes with a companion source level debugger SDCDB, the debugger
246  currently uses ucSim a freeware simulator for 8051 and other micro-controllers.
247  
248 \newline 
249
250 \newline 
251 The latest version can be downloaded from 
252 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
253
254 \end_inset 
255
256 .
257
258 \series bold 
259  
260 \series default 
261 \emph on 
262 Please note: the compiler will probably always be some steps ahead of this
263  documentation
264 \series bold 
265 \emph default 
266
267 \begin_inset LatexCommand \index{Status of documentation}
268
269 \end_inset 
270
271
272 \begin_inset Foot
273 collapsed false
274
275 \layout Standard
276
277 Obviously this has pros and cons
278 \end_inset 
279
280 .
281 \layout Section
282
283 Open Source
284 \layout Standard
285
286 All packages used in this compiler system are 
287 \emph on 
288 open source
289 \emph default 
290  and 
291 \emph on 
292 freeware
293 \emph default 
294 ; source code for all the sub-packages (pre-processor, assemblers, linkers
295  etc) is distributed with the package.
296  This documentation is maintained using a freeware word processor (LyX).
297 \newline 
298 This program is free software; you can redistribute it and/or modify it
299  under the terms of the GNU General Public License
300 \begin_inset LatexCommand \index{GNU General Public License, GPL}
301
302 \end_inset 
303
304  as published by the Free Software Foundation; either version 2, or (at
305  your option) any later version.
306  This program is distributed in the hope that it will be useful, but WITHOUT
307  ANY WARRANTY; without even the implied warranty
308 \begin_inset LatexCommand \index{warranty}
309
310 \end_inset 
311
312  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
313  See the GNU General Public License for more details.
314  You should have received a copy of the GNU General Public License along
315  with this program; if not, write to the Free Software Foundation, 59 Temple
316  Place - Suite 330, Boston, MA 02111-1307, USA.
317  In other words, you are welcome to use, share and improve this program.
318  You are forbidden to forbid anyone else to use, share and improve what
319  you give them.
320  Help stamp out software-hoarding! 
321 \layout Section
322
323 Typographic conventions
324 \begin_inset LatexCommand \index{Typographic conventions}
325
326 \end_inset 
327
328
329 \layout Standard
330
331 Throughout this manual, we will use the following convention.
332  Commands you have to type in are printed in 
333 \family sans 
334 \series bold 
335 "sans serif"
336 \series default 
337 .
338
339 \family default 
340  Code samples are printed in 
341 \family typewriter 
342 typewriter font.
343
344 \family default 
345  Interesting items and new terms are printed in 
346 \emph on 
347 italic.
348 \layout Section
349
350 Compatibility with previous versions
351 \begin_inset LatexCommand \index{Compatibility with previous versions}
352
353 \end_inset 
354
355
356 \layout Standard
357
358 This version has numerous bug fixes compared with the previous version.
359  But we also introduced some incompatibilities with older versions.
360  Not just for the fun of it, but to make the compiler more stable, efficient
361  and ANSI compliant
362 \begin_inset LatexCommand \index{ANSI-compliance}
363
364 \end_inset 
365
366  (see section 
367 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
368
369 \end_inset 
370
371  for ANSI-Compliance).
372  
373 \newline 
374
375 \layout Itemize
376
377 short is now equivalent to int (16 bits), it used to be equivalent to char
378  (8 bits) which is not ANSI compliant.
379 \layout Itemize
380
381 the default directory for gcc-builds where include, library and documentation
382  files are stored is now in /usr/local/share.
383 \layout Itemize
384
385 char type parameters to vararg functions are casted to int unless explicitly
386  casted, e.g.: 
387 \newline 
388
389 \family typewriter 
390 \SpecialChar ~
391 \SpecialChar ~
392 char a=3;
393 \newline 
394 \SpecialChar ~
395 \SpecialChar ~
396 printf ("%d %c
397 \backslash 
398 n", a, (char)a);
399 \family default 
400
401 \newline 
402  will push a as an int and as a char resp.
403 \layout Itemize
404
405 option -
406 \begin_inset ERT
407 status Collapsed
408
409 \layout Standard
410
411 \backslash 
412 /
413 \end_inset 
414
415 -regextend has been removed.
416 \layout Itemize
417
418 option -
419 \begin_inset ERT
420 status Collapsed
421
422 \layout Standard
423
424 \backslash 
425 /
426 \end_inset 
427
428 -noregparms has been removed.
429 \layout Itemize
430
431 option -
432 \begin_inset ERT
433 status Collapsed
434
435 \layout Standard
436
437 \backslash 
438 /
439 \end_inset 
440
441 -stack-after-data has been removed.
442 \layout Itemize
443
444 bit
445 \begin_inset LatexCommand \index{bit}
446
447 \end_inset 
448
449  and sbit
450 \begin_inset LatexCommand \index{sbit}
451
452 \end_inset 
453
454
455 \begin_inset LatexCommand \index{\_\_sbit}
456
457 \end_inset 
458
459  types now consistently behave like the C99 _Bool type with respect to type
460  conversion
461 \begin_inset LatexCommand \index{type conversion}
462
463 \end_inset 
464
465
466 \begin_inset LatexCommand \index{type promotion}
467
468 \end_inset 
469
470 .
471  The most common incompatibility resulting from this change is related to
472  bit toggling
473 \begin_inset LatexCommand \index{Bit toggling}
474
475 \end_inset 
476
477  idioms, e.g.:
478 \newline 
479
480 \family typewriter 
481 \SpecialChar ~
482 \SpecialChar ~
483 bit b;
484 \newline 
485 \SpecialChar ~
486 \SpecialChar ~
487 b = ~b; /* equivalent to b=1 instead of toggling b */
488 \newline 
489 \SpecialChar ~
490 \SpecialChar ~
491 b = !b; /* toggles b */
492 \newline 
493
494 \family default 
495 In previous versions, both forms would have toggled the bit.
496 \layout Standard
497
498
499 \emph on 
500 <pending: more incompatibilities?>
501 \layout Section
502
503 System Requirements
504 \layout Standard
505
506 What do you need before you start installation of SDCC? A computer, and
507  a desire to compute.
508  The preferred method of installation is to compile SDCC from source using
509  GNU gcc and make.
510  For Windows some pre-compiled binary distributions are available for your
511  convenience.
512  You should have some experience with command line tools and compiler use.
513 \layout Section
514
515 Other Resources
516 \layout Standard
517
518 The SDCC home page at 
519 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
520
521 \end_inset 
522
523  is a great place to find distribution sets.
524  You can also find links to the user mailing lists that offer help or discuss
525  SDCC with other SDCC users.
526  Web links to other SDCC related sites can also be found here.
527  This document can be found in the DOC directory of the source package as
528  a text or HTML file.
529  A pdf version of this document is available at 
530 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
531
532 \end_inset 
533
534 .
535  Some of the other tools (simulator and assembler) included with SDCC contain
536  their own documentation and can be found in the source distribution.
537  If you want the latest unreleased software, the complete source package
538  is available directly by anonymous CVS on cvs.sdcc.sourceforge.net.
539 \layout Section
540
541 Wishes for the future
542 \layout Standard
543
544 There are (and always will be) some things that could be done.
545  Here are some I can think of:
546 \newline 
547
548 \layout Standard
549
550
551 \family typewriter 
552 char KernelFunction3(char p) at 0x340;
553 \newline 
554
555 \layout Standard
556
557
558 \family typewriter 
559 code banking
560 \begin_inset LatexCommand \index{code banking (not supported)}
561
562 \end_inset 
563
564  support for mcs51
565 \newline 
566
567 \newline 
568
569 \family default 
570 If you can think of some more, please see the section 
571 \begin_inset LatexCommand \ref{sub:Requesting-Features}
572
573 \end_inset 
574
575  about filing feature requests
576 \begin_inset LatexCommand \index{Requesting features}
577
578 \end_inset 
579
580
581 \begin_inset LatexCommand \index{Feature request}
582
583 \end_inset 
584
585 .
586 \newline 
587
588 \layout Chapter
589
590 Installing SDCC
591 \begin_inset LatexCommand \index{Installation}
592
593 \end_inset 
594
595
596 \layout Standard
597
598 For most users it is sufficient to skip to either section 
599 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
600
601 \end_inset 
602
603  or section 
604 \begin_inset LatexCommand \ref{sub:Windows-Install}
605
606 \end_inset 
607
608 .
609  More detailled instructions follow below.
610 \layout Section
611
612 Configure Options
613 \begin_inset LatexCommand \index{Options SDCC configuration}
614
615 \end_inset 
616
617
618 \layout Standard
619
620 The install paths, search paths and other options are defined when running
621  'configure'.
622  The defaults can be overridden by:
623 \layout List
624 \labelwidthstring 00.00.0000
625
626 -
627 \begin_inset ERT
628 status Collapsed
629
630 \layout Standard
631
632 \backslash 
633 /
634 \end_inset 
635
636 -prefix see table below
637 \layout List
638 \labelwidthstring 00.00.0000
639
640 -
641 \begin_inset ERT
642 status Collapsed
643
644 \layout Standard
645
646 \backslash 
647 /
648 \end_inset 
649
650 -exec_prefix see table below
651 \layout List
652 \labelwidthstring 00.00.0000
653
654 -
655 \begin_inset ERT
656 status Collapsed
657
658 \layout Standard
659
660 \backslash 
661 /
662 \end_inset 
663
664 -bindir see table below
665 \layout List
666 \labelwidthstring 00.00.0000
667
668 -
669 \begin_inset ERT
670 status Collapsed
671
672 \layout Standard
673
674 \backslash 
675 /
676 \end_inset 
677
678 -datadir see table below
679 \layout List
680 \labelwidthstring 00.00.0000
681
682 docdir environment variable, see table below
683 \layout List
684 \labelwidthstring 00.00.0000
685
686 include_dir_suffix environment variable, see table below
687 \layout List
688 \labelwidthstring 00.00.0000
689
690 lib_dir_suffix environment variable, see table below
691 \layout List
692 \labelwidthstring 00.00.0000
693
694 sdccconf_h_dir_separator environment variable, either / or 
695 \backslash 
696
697 \backslash 
698  makes sense here.
699  This character will only be used in sdccconf.h; don't forget it's a C-header,
700  therefore a double-backslash is needed there.
701 \layout List
702 \labelwidthstring 00.00.0000
703
704 -
705 \begin_inset ERT
706 status Collapsed
707
708 \layout Standard
709
710 \backslash 
711 /
712 \end_inset 
713
714 -disable-mcs51-port Excludes the Intel mcs51 port
715 \layout List
716 \labelwidthstring 00.00.0000
717
718 -
719 \begin_inset ERT
720 status Collapsed
721
722 \layout Standard
723
724 \backslash 
725 /
726 \end_inset 
727
728 -disable-gbz80-port Excludes the Gameboy gbz80 port
729 \layout List
730 \labelwidthstring 00.00.0000
731
732 -
733 \begin_inset ERT
734 status Collapsed
735
736 \layout Standard
737
738 \backslash 
739 /
740 \end_inset 
741
742 -disable-z80-port Excludes the z80 port
743 \layout List
744 \labelwidthstring 00.00.0000
745
746 -
747 \begin_inset ERT
748 status Collapsed
749
750 \layout Standard
751
752 \backslash 
753 /
754 \end_inset 
755
756 -disable-avr-port Excludes the AVR port
757 \layout List
758 \labelwidthstring 00.00.0000
759
760 -
761 \begin_inset ERT
762 status Collapsed
763
764 \layout Standard
765
766 \backslash 
767 /
768 \end_inset 
769
770 -disable-ds390-port Excludes the DS390 port
771 \layout List
772 \labelwidthstring 00.00.0000
773
774 -
775 \begin_inset ERT
776 status Collapsed
777
778 \layout Standard
779
780 \backslash 
781 /
782 \end_inset 
783
784 -disable-hc08-port Excludes the HC08 port
785 \layout List
786 \labelwidthstring 00.00.0000
787
788 -
789 \begin_inset ERT
790 status Collapsed
791
792 \layout Standard
793
794 \backslash 
795 /
796 \end_inset 
797
798 -disable-pic-port Excludes the PIC port
799 \layout List
800 \labelwidthstring 00.00.0000
801
802 -
803 \begin_inset ERT
804 status Collapsed
805
806 \layout Standard
807
808 \backslash 
809 /
810 \end_inset 
811
812 -disable-xa51-port Excludes the XA51 port
813 \layout List
814 \labelwidthstring 00.00.0000
815
816 -
817 \begin_inset ERT
818 status Collapsed
819
820 \layout Standard
821
822 \backslash 
823 /
824 \end_inset 
825
826 -disable-ucsim Disables configuring and building of ucsim
827 \layout List
828 \labelwidthstring 00.00.0000
829
830 -
831 \begin_inset ERT
832 status Collapsed
833
834 \layout Standard
835
836 \backslash 
837 /
838 \end_inset 
839
840 -disable-device-lib-build Disables automatically building device libraries
841 \layout List
842 \labelwidthstring 00.00.0000
843
844 -
845 \begin_inset ERT
846 status Collapsed
847
848 \layout Standard
849
850 \backslash 
851 /
852 \end_inset 
853
854 -disable-packihx Disables building packihx
855 \layout List
856 \labelwidthstring 00.00.0000
857
858 -
859 \begin_inset ERT
860 status Collapsed
861
862 \layout Standard
863
864 \backslash 
865 /
866 \end_inset 
867
868 -enable-libgc Use the Bohem memory allocator.
869  Lower runtime footprint.
870 \layout Standard
871
872 Furthermore the environment variables CC, CFLAGS, ...
873  the tools and their arguments can be influenced.
874  Please see `configure -
875 \begin_inset ERT
876 status Collapsed
877
878 \layout Standard
879
880 \backslash 
881 /
882 \end_inset 
883
884 -help` and the man/info pages of `configure` for details.
885 \newline 
886
887 \newline 
888 The names of the standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB,
889  STD_FP_LIB, STD_DS390_LIB, STD_XA51_LIB and the environment variables SDCC_DIR_
890 NAME, SDCC_INCLUDE_NAME, SDCC_LIB_NAME are defined by `configure` too.
891  At the moment it's not possible to change the default settings (it was
892  simply never required).
893 \newline 
894
895 \newline 
896 These configure options are compiled into the binaries, and can only be
897  changed by rerunning 'configure' and recompiling SDCC.
898  The configure options are written in 
899 \emph on 
900 italics
901 \emph default 
902  to distinguish them from run time environment variables (see section search
903  paths).
904 \newline 
905
906 \newline 
907 The settings for 
908 \begin_inset Quotes sld
909 \end_inset 
910
911 Win32 builds
912 \begin_inset Quotes srd
913 \end_inset 
914
915  are used by the SDCC team to build the official Win32 binaries.
916  The SDCC team uses Mingw32 to build the official Windows binaries, because
917  it's
918 \layout Enumerate
919
920 open source, 
921 \layout Enumerate
922
923 a gcc compiler and last but not least
924 \layout Enumerate
925
926 the binaries can be built by cross compiling on Sourceforge's compile farm.
927 \layout Standard
928
929 See the examples, how to pass the Win32 settings to 'configure'.
930  The other Win32 builds using Borland, VC or whatever don't use 'configure',
931  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
932  for Win32.
933 \newline 
934
935 \newline 
936 These defaults are:
937 \newline 
938
939 \layout Standard
940 \align center 
941
942 \begin_inset  Tabular
943 <lyxtabular version="3" rows="8" columns="3">
944 <features>
945 <column alignment="block" valignment="top" leftline="true" width="0in">
946 <column alignment="block" valignment="top" leftline="true" width="0in">
947 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
948 <row topline="true" bottomline="true">
949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
950 \begin_inset Text
951
952 \layout Standard
953
954 Variable
955 \end_inset 
956 </cell>
957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
958 \begin_inset Text
959
960 \layout Standard
961
962 default
963 \end_inset 
964 </cell>
965 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
966 \begin_inset Text
967
968 \layout Standard
969
970 Win32 builds
971 \end_inset 
972 </cell>
973 </row>
974 <row topline="true">
975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
976 \begin_inset Text
977
978 \layout Standard
979
980
981 \emph on 
982 PREFIX
983 \end_inset 
984 </cell>
985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
986 \begin_inset Text
987
988 \layout Standard
989
990 /usr/local
991 \end_inset 
992 </cell>
993 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
994 \begin_inset Text
995
996 \layout Standard
997
998
999 \backslash 
1000 sdcc
1001 \end_inset 
1002 </cell>
1003 </row>
1004 <row topline="true">
1005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1006 \begin_inset Text
1007
1008 \layout Standard
1009
1010
1011 \emph on 
1012 EXEC_PREFIX
1013 \end_inset 
1014 </cell>
1015 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1016 \begin_inset Text
1017
1018 \layout Standard
1019
1020
1021 \emph on 
1022 $PREFIX
1023 \end_inset 
1024 </cell>
1025 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1026 \begin_inset Text
1027
1028 \layout Standard
1029
1030
1031 \emph on 
1032 $PREFIX
1033 \end_inset 
1034 </cell>
1035 </row>
1036 <row topline="true">
1037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1038 \begin_inset Text
1039
1040 \layout Standard
1041
1042
1043 \emph on 
1044 BINDIR
1045 \end_inset 
1046 </cell>
1047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1048 \begin_inset Text
1049
1050 \layout Standard
1051
1052
1053 \emph on 
1054 $EXECPREFIX
1055 \emph default 
1056 /bin
1057 \end_inset 
1058 </cell>
1059 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1060 \begin_inset Text
1061
1062 \layout Standard
1063
1064
1065 \emph on 
1066 $EXECPREFIX
1067 \emph default 
1068
1069 \backslash 
1070 bin
1071 \end_inset 
1072 </cell>
1073 </row>
1074 <row topline="true">
1075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1076 \begin_inset Text
1077
1078 \layout Standard
1079
1080
1081 \emph on 
1082 DATADIR
1083 \end_inset 
1084 </cell>
1085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1086 \begin_inset Text
1087
1088 \layout Standard
1089
1090
1091 \emph on 
1092 $PREFIX
1093 \emph default 
1094 /share
1095 \end_inset 
1096 </cell>
1097 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1098 \begin_inset Text
1099
1100 \layout Standard
1101
1102
1103 \emph on 
1104 $PREFIX
1105 \end_inset 
1106 </cell>
1107 </row>
1108 <row topline="true">
1109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1110 \begin_inset Text
1111
1112 \layout Standard
1113
1114
1115 \emph on 
1116 DOCDIR
1117 \end_inset 
1118 </cell>
1119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1120 \begin_inset Text
1121
1122 \layout Standard
1123
1124
1125 \emph on 
1126 $DATADIR
1127 \emph default 
1128 /sdcc/doc
1129 \end_inset 
1130 </cell>
1131 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1132 \begin_inset Text
1133
1134 \layout Standard
1135
1136
1137 \emph on 
1138 $DATADIR
1139 \emph default 
1140
1141 \backslash 
1142 doc
1143 \end_inset 
1144 </cell>
1145 </row>
1146 <row topline="true">
1147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1148 \begin_inset Text
1149
1150 \layout Standard
1151
1152
1153 \emph on 
1154 INCLUDE_DIR_SUFFIX
1155 \end_inset 
1156 </cell>
1157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1158 \begin_inset Text
1159
1160 \layout Standard
1161
1162 sdcc/include
1163 \end_inset 
1164 </cell>
1165 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1166 \begin_inset Text
1167
1168 \layout Standard
1169
1170 include
1171 \end_inset 
1172 </cell>
1173 </row>
1174 <row topline="true" bottomline="true">
1175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1176 \begin_inset Text
1177
1178 \layout Standard
1179
1180
1181 \emph on 
1182 LIB_DIR_SUFFIX
1183 \end_inset 
1184 </cell>
1185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1186 \begin_inset Text
1187
1188 \layout Standard
1189
1190 sdcc/lib
1191 \end_inset 
1192 </cell>
1193 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1194 \begin_inset Text
1195
1196 \layout Standard
1197
1198 lib
1199 \end_inset 
1200 </cell>
1201 </row>
1202 </lyxtabular>
1203
1204 \end_inset 
1205
1206
1207 \newline 
1208
1209 \layout Standard
1210 \noindent 
1211 'configure' also computes relative paths.
1212  This is needed for full relocatability of a binary package and to complete
1213  search paths (see section search paths below):
1214 \newline 
1215  
1216 \layout Standard
1217 \align center 
1218
1219 \begin_inset  Tabular
1220 <lyxtabular version="3" rows="4" columns="3">
1221 <features>
1222 <column alignment="block" valignment="top" leftline="true" width="0in">
1223 <column alignment="block" valignment="top" leftline="true" width="0in">
1224 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1225 <row topline="true" bottomline="true">
1226 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1227 \begin_inset Text
1228
1229 \layout Standard
1230
1231 Variable (computed)
1232 \end_inset 
1233 </cell>
1234 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1235 \begin_inset Text
1236
1237 \layout Standard
1238
1239 default
1240 \end_inset 
1241 </cell>
1242 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1243 \begin_inset Text
1244
1245 \layout Standard
1246
1247 Win32 builds
1248 \end_inset 
1249 </cell>
1250 </row>
1251 <row topline="true" bottomline="true">
1252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1253 \begin_inset Text
1254
1255 \layout Standard
1256
1257
1258 \emph on 
1259 BIN2DATA_DIR
1260 \end_inset 
1261 </cell>
1262 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1263 \begin_inset Text
1264
1265 \layout Standard
1266
1267 ../share
1268 \end_inset 
1269 </cell>
1270 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1271 \begin_inset Text
1272
1273 \layout Standard
1274
1275 ..
1276 \end_inset 
1277 </cell>
1278 </row>
1279 <row bottomline="true">
1280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1281 \begin_inset Text
1282
1283 \layout Standard
1284
1285
1286 \emph on 
1287 PREFIX2BIN_DIR
1288 \end_inset 
1289 </cell>
1290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1291 \begin_inset Text
1292
1293 \layout Standard
1294
1295 bin
1296 \end_inset 
1297 </cell>
1298 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1299 \begin_inset Text
1300
1301 \layout Standard
1302
1303 bin
1304 \end_inset 
1305 </cell>
1306 </row>
1307 <row bottomline="true">
1308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1309 \begin_inset Text
1310
1311 \layout Standard
1312
1313
1314 \emph on 
1315 PREFIX2DATA_DIR
1316 \end_inset 
1317 </cell>
1318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1319 \begin_inset Text
1320
1321 \layout Standard
1322
1323 share/sdcc
1324 \end_inset 
1325 </cell>
1326 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1327 \begin_inset Text
1328
1329 \layout Standard
1330
1331 \end_inset 
1332 </cell>
1333 </row>
1334 </lyxtabular>
1335
1336 \end_inset 
1337
1338
1339 \newline 
1340
1341 \layout Standard
1342 \noindent 
1343 Examples:
1344 \layout LyX-Code
1345
1346 ./configure
1347 \newline 
1348 ./configure -
1349 \begin_inset ERT
1350 status Collapsed
1351
1352 \layout Standard
1353
1354 \backslash 
1355 /
1356 \end_inset 
1357
1358 -prefix=
1359 \begin_inset Quotes srd
1360 \end_inset 
1361
1362 /usr/bin
1363 \begin_inset Quotes srd
1364 \end_inset 
1365
1366  -
1367 \begin_inset ERT
1368 status Collapsed
1369
1370 \layout Standard
1371
1372 \backslash 
1373 /
1374 \end_inset 
1375
1376 -datadir=
1377 \begin_inset Quotes srd
1378 \end_inset 
1379
1380 /usr/share
1381 \begin_inset Quotes srd
1382 \end_inset 
1383
1384
1385 \newline 
1386 ./configure -
1387 \begin_inset ERT
1388 status Collapsed
1389
1390 \layout Standard
1391
1392 \backslash 
1393 /
1394 \end_inset 
1395
1396 -disable-avr-port -
1397 \begin_inset ERT
1398 status Collapsed
1399
1400 \layout Standard
1401
1402 \backslash 
1403 /
1404 \end_inset 
1405
1406 -disable-xa51-port
1407 \layout Standard
1408
1409 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1410 32'):
1411 \layout LyX-Code
1412
1413 ./configure 
1414 \backslash 
1415
1416 \newline 
1417 CC=
1418 \begin_inset Quotes srd
1419 \end_inset 
1420
1421 i586-mingw32msvc-gcc
1422 \begin_inset Quotes srd
1423 \end_inset 
1424
1425  CXX=
1426 \begin_inset Quotes srd
1427 \end_inset 
1428
1429 i586-mingw32msvc-g++
1430 \begin_inset Quotes srd
1431 \end_inset 
1432
1433  
1434 \backslash 
1435  
1436 \newline 
1437 RANLIB=
1438 \begin_inset Quotes srd
1439 \end_inset 
1440
1441 i586-mingw32msvc-ranlib
1442 \begin_inset Quotes srd
1443 \end_inset 
1444
1445  
1446 \backslash 
1447
1448 \newline 
1449 STRIP=
1450 \begin_inset Quotes srd
1451 \end_inset 
1452
1453 i586-mingw32msvc-strip
1454 \begin_inset Quotes srd
1455 \end_inset 
1456
1457  
1458 \backslash 
1459
1460 \newline 
1461 -
1462 \begin_inset ERT
1463 status Collapsed
1464
1465 \layout Standard
1466
1467 \backslash 
1468 /
1469 \end_inset 
1470
1471 -prefix=
1472 \begin_inset Quotes srd
1473 \end_inset 
1474
1475 /sdcc
1476 \begin_inset Quotes srd
1477 \end_inset 
1478
1479  
1480 \backslash 
1481
1482 \newline 
1483 -
1484 \begin_inset ERT
1485 status Collapsed
1486
1487 \layout Standard
1488
1489 \backslash 
1490 /
1491 \end_inset 
1492
1493 -datadir=
1494 \begin_inset Quotes srd
1495 \end_inset 
1496
1497 /sdcc
1498 \begin_inset Quotes srd
1499 \end_inset 
1500
1501  
1502 \backslash 
1503
1504 \newline 
1505 docdir=
1506 \begin_inset Quotes srd
1507 \end_inset 
1508
1509 /sdcc/doc
1510 \begin_inset Quotes srd
1511 \end_inset 
1512
1513  
1514 \backslash 
1515
1516 \newline 
1517 include_dir_suffix=
1518 \begin_inset Quotes srd
1519 \end_inset 
1520
1521 include
1522 \begin_inset Quotes srd
1523 \end_inset 
1524
1525  
1526 \backslash 
1527
1528 \newline 
1529 lib_dir_suffix=
1530 \begin_inset Quotes srd
1531 \end_inset 
1532
1533 lib
1534 \begin_inset Quotes srd
1535 \end_inset 
1536
1537  
1538 \backslash 
1539
1540 \newline 
1541 sdccconf_h_dir_separator=
1542 \begin_inset Quotes srd
1543 \end_inset 
1544
1545
1546 \backslash 
1547
1548 \backslash 
1549
1550 \backslash 
1551
1552 \backslash 
1553
1554 \begin_inset Quotes srd
1555 \end_inset 
1556
1557  
1558 \backslash 
1559
1560 \newline 
1561 -
1562 \begin_inset ERT
1563 status Collapsed
1564
1565 \layout Standard
1566
1567 \backslash 
1568 /
1569 \end_inset 
1570
1571 -disable-device-lib-build
1572 \backslash 
1573
1574 \newline 
1575 -
1576 \begin_inset ERT
1577 status Collapsed
1578
1579 \layout Standard
1580
1581 \backslash 
1582 /
1583 \end_inset 
1584
1585 -disable-ucsim
1586 \backslash 
1587
1588 \newline 
1589 -
1590 \begin_inset ERT
1591 status Collapsed
1592
1593 \layout Standard
1594
1595 \backslash 
1596 /
1597 \end_inset 
1598
1599 -host=i586-mingw32msvc -
1600 \begin_inset ERT
1601 status Collapsed
1602
1603 \layout Standard
1604
1605 \backslash 
1606 /
1607 \end_inset 
1608
1609 -build=unknown-unknown-linux-gnu
1610 \layout Standard
1611
1612 To 
1613 \begin_inset Quotes sld
1614 \end_inset 
1615
1616 cross
1617 \begin_inset Quotes srd
1618 \end_inset 
1619
1620 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
1621 ):
1622 \layout LyX-Code
1623
1624 ./configure -C 
1625 \backslash 
1626
1627 \newline 
1628 CFLAGS=
1629 \begin_inset Quotes srd
1630 \end_inset 
1631
1632 -mno-cygwin -O2
1633 \begin_inset Quotes srd
1634 \end_inset 
1635
1636  
1637 \backslash 
1638
1639 \newline 
1640 LDFLAGS=
1641 \begin_inset Quotes srd
1642 \end_inset 
1643
1644 -mno-cygwin
1645 \begin_inset Quotes srd
1646 \end_inset 
1647
1648  
1649 \backslash 
1650
1651 \newline 
1652 -
1653 \begin_inset ERT
1654 status Collapsed
1655
1656 \layout Standard
1657
1658 \backslash 
1659 /
1660 \end_inset 
1661
1662 -prefix=
1663 \begin_inset Quotes srd
1664 \end_inset 
1665
1666 /sdcc
1667 \begin_inset Quotes srd
1668 \end_inset 
1669
1670  
1671 \backslash 
1672
1673 \newline 
1674 -
1675 \begin_inset ERT
1676 status Collapsed
1677
1678 \layout Standard
1679
1680 \backslash 
1681 /
1682 \end_inset 
1683
1684 -datadir=
1685 \begin_inset Quotes srd
1686 \end_inset 
1687
1688 /sdcc
1689 \begin_inset Quotes srd
1690 \end_inset 
1691
1692  
1693 \backslash 
1694
1695 \newline 
1696 docdir=
1697 \begin_inset Quotes srd
1698 \end_inset 
1699
1700 /sdcc/doc
1701 \begin_inset Quotes srd
1702 \end_inset 
1703
1704  
1705 \backslash 
1706  
1707 \newline 
1708 include_dir_suffix=
1709 \begin_inset Quotes srd
1710 \end_inset 
1711
1712 include
1713 \begin_inset Quotes srd
1714 \end_inset 
1715
1716  
1717 \backslash 
1718
1719 \newline 
1720 lib_dir_suffix=
1721 \begin_inset Quotes srd
1722 \end_inset 
1723
1724 lib
1725 \begin_inset Quotes srd
1726 \end_inset 
1727
1728  
1729 \backslash 
1730
1731 \newline 
1732 sdccconf_h_dir_separator=
1733 \begin_inset Quotes srd
1734 \end_inset 
1735
1736
1737 \backslash 
1738
1739 \backslash 
1740
1741 \backslash 
1742
1743 \backslash 
1744
1745 \begin_inset Quotes srd
1746 \end_inset 
1747
1748  
1749 \backslash 
1750
1751 \newline 
1752 -
1753 \begin_inset ERT
1754 status Collapsed
1755
1756 \layout Standard
1757
1758 \backslash 
1759 /
1760 \end_inset 
1761
1762 -disable-ucsim
1763 \layout Standard
1764
1765 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
1766  The option '-
1767 \begin_inset ERT
1768 status Collapsed
1769
1770 \layout Standard
1771
1772 \backslash 
1773 /
1774 \end_inset 
1775
1776 -C' turns on caching, which gives a little bit extra speed.
1777  However if options are changed, it can be necessary to delete the config.cache
1778  file.
1779 \layout Section
1780
1781 Install paths
1782 \begin_inset LatexCommand \label{sub:Install-paths}
1783
1784 \end_inset 
1785
1786
1787 \begin_inset LatexCommand \index{Install paths}
1788
1789 \end_inset 
1790
1791
1792 \layout Standard
1793 \added_space_top medskip \align center 
1794
1795 \begin_inset  Tabular
1796 <lyxtabular version="3" rows="5" columns="4">
1797 <features>
1798 <column alignment="center" valignment="top" leftline="true" width="0">
1799 <column alignment="center" valignment="top" leftline="true" width="0">
1800 <column alignment="center" valignment="top" leftline="true" width="0">
1801 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
1802 <row topline="true" bottomline="true">
1803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1804 \begin_inset Text
1805
1806 \layout Standard
1807
1808
1809 \series bold 
1810 Description
1811 \end_inset 
1812 </cell>
1813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1814 \begin_inset Text
1815
1816 \layout Standard
1817
1818
1819 \series bold 
1820 Path
1821 \end_inset 
1822 </cell>
1823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1824 \begin_inset Text
1825
1826 \layout Standard
1827
1828
1829 \series bold 
1830 Default
1831 \end_inset 
1832 </cell>
1833 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1834 \begin_inset Text
1835
1836 \layout Standard
1837
1838
1839 \series bold 
1840 Win32 builds
1841 \end_inset 
1842 </cell>
1843 </row>
1844 <row topline="true">
1845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1846 \begin_inset Text
1847
1848 \layout Standard
1849
1850 Binary files*
1851 \end_inset 
1852 </cell>
1853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1854 \begin_inset Text
1855
1856 \layout Standard
1857
1858
1859 \emph on 
1860 $EXEC_PREFIX
1861 \end_inset 
1862 </cell>
1863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1864 \begin_inset Text
1865
1866 \layout Standard
1867
1868 /usr/local/bin
1869 \end_inset 
1870 </cell>
1871 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1872 \begin_inset Text
1873
1874 \layout Standard
1875
1876
1877 \backslash 
1878 sdcc
1879 \backslash 
1880 bin
1881 \end_inset 
1882 </cell>
1883 </row>
1884 <row topline="true">
1885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1886 \begin_inset Text
1887
1888 \layout Standard
1889
1890 Include files
1891 \end_inset 
1892 </cell>
1893 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1894 \begin_inset Text
1895
1896 \layout Standard
1897
1898
1899 \emph on 
1900 $DATADIR/ $INCLUDE_DIR_SUFFIX
1901 \end_inset 
1902 </cell>
1903 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1904 \begin_inset Text
1905
1906 \layout Standard
1907
1908 /usr/local/share/sdcc/include
1909 \end_inset 
1910 </cell>
1911 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1912 \begin_inset Text
1913
1914 \layout Standard
1915
1916
1917 \backslash 
1918 sdcc
1919 \backslash 
1920 include
1921 \end_inset 
1922 </cell>
1923 </row>
1924 <row topline="true">
1925 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1926 \begin_inset Text
1927
1928 \layout Standard
1929
1930 Library file**
1931 \end_inset 
1932 </cell>
1933 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1934 \begin_inset Text
1935
1936 \layout Standard
1937
1938
1939 \emph on 
1940 $DATADIR/$LIB_DIR_SUFFIX
1941 \end_inset 
1942 </cell>
1943 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1944 \begin_inset Text
1945
1946 \layout Standard
1947
1948 /usr/local/share/sdcc/lib
1949 \end_inset 
1950 </cell>
1951 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1952 \begin_inset Text
1953
1954 \layout Standard
1955
1956
1957 \backslash 
1958 sdcc
1959 \backslash 
1960 lib
1961 \end_inset 
1962 </cell>
1963 </row>
1964 <row topline="true" bottomline="true">
1965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1966 \begin_inset Text
1967
1968 \layout Standard
1969
1970 Documentation
1971 \end_inset 
1972 </cell>
1973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1974 \begin_inset Text
1975
1976 \layout Standard
1977
1978
1979 \emph on 
1980 $DOCDIR
1981 \end_inset 
1982 </cell>
1983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1984 \begin_inset Text
1985
1986 \layout Standard
1987
1988 /usr/local/share/sdcc/doc
1989 \end_inset 
1990 </cell>
1991 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1992 \begin_inset Text
1993
1994 \layout Standard
1995
1996
1997 \backslash 
1998 sdcc
1999 \backslash 
2000 doc
2001 \end_inset 
2002 </cell>
2003 </row>
2004 </lyxtabular>
2005
2006 \end_inset 
2007
2008
2009 \layout Verse
2010
2011
2012 \size footnotesize 
2013 *compiler, preprocessor, assembler, and linker
2014 \newline 
2015 **the 
2016 \shape italic 
2017 model
2018 \shape default 
2019  is auto-appended by the compiler, e.g.
2020  small, large, z80, ds390 etc
2021 \layout Standard
2022 \noindent 
2023 The install paths can still be changed during `make install` with e.g.:
2024 \layout LyX-Code
2025
2026 make install prefix=$(HOME)/local/sdcc
2027 \layout Standard
2028
2029 Of course this doesn't change the search paths compiled into the binaries.
2030 \newline 
2031
2032 \newline 
2033 Moreover the install path can be changed by defining DESTDIR
2034 \begin_inset LatexCommand \index{DESTDIR}
2035
2036 \end_inset 
2037
2038 :
2039 \layout LyX-Code
2040
2041 make install DESTDIR=$(HOME)/sdcc.rpm/
2042 \layout Standard
2043
2044 Please note that DESTDIR must have a trailing slash!
2045 \layout Section
2046
2047 Search Paths
2048 \begin_inset LatexCommand \label{sub:Search-Paths}
2049
2050 \end_inset 
2051
2052
2053 \begin_inset LatexCommand \index{Search path}
2054
2055 \end_inset 
2056
2057
2058 \layout Standard
2059
2060 Some search paths or parts of them are determined by configure variables
2061  (in 
2062 \emph on 
2063 italics
2064 \emph default 
2065 , see section above).
2066  Further search paths are determined by environment variables during runtime.
2067  
2068 \newline 
2069 The paths searched when running the compiler are as follows (the first catch
2070  wins):
2071 \newline 
2072
2073 \newline 
2074 1.
2075  Binary files (preprocessor, assembler and linker)
2076 \newline 
2077
2078 \layout Standard
2079 \align center 
2080
2081 \begin_inset  Tabular
2082 <lyxtabular version="3" rows="4" columns="3">
2083 <features>
2084 <column alignment="block" valignment="top" leftline="true" width="0in">
2085 <column alignment="block" valignment="top" leftline="true" width="0in">
2086 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2087 <row topline="true" bottomline="true">
2088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2089 \begin_inset Text
2090
2091 \layout Standard
2092
2093 Search path
2094 \end_inset 
2095 </cell>
2096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2097 \begin_inset Text
2098
2099 \layout Standard
2100
2101 default
2102 \end_inset 
2103 </cell>
2104 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2105 \begin_inset Text
2106
2107 \layout Standard
2108
2109 Win32 builds
2110 \end_inset 
2111 </cell>
2112 </row>
2113 <row topline="true">
2114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2115 \begin_inset Text
2116
2117 \layout Standard
2118
2119 $SDCC_HOME/
2120 \emph on 
2121 $PPREFIX2BIN_DIR
2122 \end_inset 
2123 </cell>
2124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2125 \begin_inset Text
2126
2127 \layout Standard
2128
2129 $SDCC_HOME/bin
2130 \end_inset 
2131 </cell>
2132 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2133 \begin_inset Text
2134
2135 \layout Standard
2136
2137 $SDCC_HOME
2138 \backslash 
2139 bin
2140 \end_inset 
2141 </cell>
2142 </row>
2143 <row topline="true">
2144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2145 \begin_inset Text
2146
2147 \layout Standard
2148
2149 Path of argv[0] (if available)
2150 \end_inset 
2151 </cell>
2152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2153 \begin_inset Text
2154
2155 \layout Standard
2156
2157 Path of argv[0]
2158 \end_inset 
2159 </cell>
2160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2161 \begin_inset Text
2162
2163 \layout Standard
2164
2165 Path of argv[0]
2166 \end_inset 
2167 </cell>
2168 </row>
2169 <row topline="true" bottomline="true">
2170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2171 \begin_inset Text
2172
2173 \layout Standard
2174
2175 $PATH
2176 \end_inset 
2177 </cell>
2178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2179 \begin_inset Text
2180
2181 \layout Standard
2182
2183 $PATH
2184 \end_inset 
2185 </cell>
2186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2187 \begin_inset Text
2188
2189 \layout Standard
2190
2191 $PATH
2192 \end_inset 
2193 </cell>
2194 </row>
2195 </lyxtabular>
2196
2197 \end_inset 
2198
2199  
2200 \newline 
2201
2202 \layout Standard
2203 \noindent 
2204 2.
2205  Include files
2206 \newline 
2207
2208 \layout Standard
2209 \align center 
2210
2211 \begin_inset  Tabular
2212 <lyxtabular version="3" rows="6" columns="3">
2213 <features>
2214 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2215 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2216 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2217 <row topline="true" bottomline="true">
2218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2219 \begin_inset Text
2220
2221 \layout Standard
2222
2223 Search path
2224 \end_inset 
2225 </cell>
2226 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2227 \begin_inset Text
2228
2229 \layout Standard
2230
2231 default
2232 \end_inset 
2233 </cell>
2234 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2235 \begin_inset Text
2236
2237 \layout Standard
2238
2239 Win32 builds
2240 \end_inset 
2241 </cell>
2242 </row>
2243 <row topline="true">
2244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2245 \begin_inset Text
2246
2247 \layout Standard
2248
2249 -
2250 \begin_inset ERT
2251 status Collapsed
2252
2253 \layout Standard
2254
2255 \backslash 
2256 /
2257 \end_inset 
2258
2259 -I dir
2260 \end_inset 
2261 </cell>
2262 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2263 \begin_inset Text
2264
2265 \layout Standard
2266
2267 -
2268 \begin_inset ERT
2269 status Collapsed
2270
2271 \layout Standard
2272
2273 \backslash 
2274 /
2275 \end_inset 
2276
2277 -I dir
2278 \end_inset 
2279 </cell>
2280 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2281 \begin_inset Text
2282
2283 \layout Standard
2284
2285 -
2286 \begin_inset ERT
2287 status Collapsed
2288
2289 \layout Standard
2290
2291 \backslash 
2292 /
2293 \end_inset 
2294
2295 -I dir
2296 \end_inset 
2297 </cell>
2298 </row>
2299 <row topline="true">
2300 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2301 \begin_inset Text
2302
2303 \layout Standard
2304
2305 $SDCC_INCLUDE
2306 \end_inset 
2307 </cell>
2308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2309 \begin_inset Text
2310
2311 \layout Standard
2312
2313 $SDCC_INCLUDE
2314 \end_inset 
2315 </cell>
2316 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2317 \begin_inset Text
2318
2319 \layout Standard
2320
2321 $SDCC_INCLUDE
2322 \end_inset 
2323 </cell>
2324 </row>
2325 <row topline="true">
2326 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2327 \begin_inset Text
2328
2329 \layout Standard
2330
2331 $SDCC_HOME/
2332 \newline 
2333
2334 \emph on 
2335 $PREFIX2DATA_DIR/
2336 \newline 
2337 $INCLUDE_DIR_SUFFIX
2338 \end_inset 
2339 </cell>
2340 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2341 \begin_inset Text
2342
2343 \layout Standard
2344
2345 $SDCC_ HOME/
2346 \newline 
2347 share/sdcc/
2348 \newline 
2349 include
2350 \end_inset 
2351 </cell>
2352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2353 \begin_inset Text
2354
2355 \layout Standard
2356
2357 $SDCC_HOME
2358 \backslash 
2359 include
2360 \end_inset 
2361 </cell>
2362 </row>
2363 <row topline="true">
2364 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2365 \begin_inset Text
2366
2367 \layout Standard
2368
2369 path(argv[0])/
2370 \newline 
2371
2372 \emph on 
2373 $BIN2DATADIR/
2374 \emph default 
2375
2376 \newline 
2377
2378 \emph on 
2379 $INCLUDE_DIR_SUFFIX
2380 \end_inset 
2381 </cell>
2382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2383 \begin_inset Text
2384
2385 \layout Standard
2386
2387 path(argv[0])/
2388 \newline 
2389 ../sdcc/include
2390 \newline 
2391 \SpecialChar ~
2392 \SpecialChar ~
2393 \SpecialChar ~
2394 \SpecialChar ~
2395 \SpecialChar ~
2396 \SpecialChar ~
2397 \SpecialChar ~
2398 \SpecialChar ~
2399 \SpecialChar ~
2400 \SpecialChar ~
2401 \SpecialChar ~
2402 \SpecialChar ~
2403 \SpecialChar ~
2404 \SpecialChar ~
2405 \SpecialChar ~
2406 \SpecialChar ~
2407 \SpecialChar ~
2408 \SpecialChar ~
2409 \SpecialChar ~
2410 \SpecialChar ~
2411 \SpecialChar ~
2412 \SpecialChar ~
2413 \SpecialChar ~
2414 \SpecialChar ~
2415 \SpecialChar ~
2416 \SpecialChar ~
2417 \SpecialChar ~
2418 \SpecialChar ~
2419 \SpecialChar ~
2420 \SpecialChar ~
2421 \SpecialChar ~
2422 \SpecialChar ~
2423 \SpecialChar ~
2424 \SpecialChar ~
2425 \SpecialChar ~
2426 \SpecialChar ~
2427 \SpecialChar ~
2428 \SpecialChar ~
2429
2430 \end_inset 
2431 </cell>
2432 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2433 \begin_inset Text
2434
2435 \layout Standard
2436
2437 path(argv[0])
2438 \backslash 
2439 ..
2440 \backslash 
2441 include
2442 \end_inset 
2443 </cell>
2444 </row>
2445 <row topline="true" bottomline="true">
2446 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2447 \begin_inset Text
2448
2449 \layout Standard
2450
2451
2452 \emph on 
2453 $DATADIR/
2454 \emph default 
2455
2456 \newline 
2457
2458 \emph on 
2459 $INCLUDE_DIR_SUFFIX
2460 \end_inset 
2461 </cell>
2462 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2463 \begin_inset Text
2464
2465 \layout Standard
2466
2467 /usr/local/share/sdcc/
2468 \newline 
2469 include
2470 \end_inset 
2471 </cell>
2472 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2473 \begin_inset Text
2474
2475 \layout Standard
2476
2477 (not on Win32)
2478 \end_inset 
2479 </cell>
2480 </row>
2481 </lyxtabular>
2482
2483 \end_inset 
2484
2485  
2486 \newline 
2487
2488 \layout Standard
2489 \noindent 
2490 The option -
2491 \begin_inset ERT
2492 status Collapsed
2493
2494 \layout Standard
2495
2496 \backslash 
2497 /
2498 \end_inset 
2499
2500 -nostdinc disables the last two search paths.
2501 \newline 
2502
2503 \newline 
2504 3.
2505  Library files 
2506 \newline 
2507
2508 \layout Standard
2509
2510 With the exception of 
2511 \begin_inset Quotes sld
2512 \end_inset 
2513
2514 -
2515 \begin_inset ERT
2516 status Collapsed
2517
2518 \layout Standard
2519
2520 \backslash 
2521 /
2522 \end_inset 
2523
2524 -L dir
2525 \begin_inset Quotes srd
2526 \end_inset 
2527
2528  the 
2529 \shape italic 
2530 model
2531 \shape default 
2532  is auto-appended by the compiler (e.g.
2533  small, large, z80, ds390 etc.).
2534  
2535 \newline 
2536
2537 \layout Standard
2538 \align center 
2539
2540 \begin_inset  Tabular
2541 <lyxtabular version="3" rows="6" columns="3">
2542 <features>
2543 <column alignment="block" valignment="top" leftline="true" width="1.7in">
2544 <column alignment="block" valignment="top" leftline="true" width="1.2in">
2545 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
2546 <row topline="true" bottomline="true">
2547 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2548 \begin_inset Text
2549
2550 \layout Standard
2551
2552 Search path
2553 \end_inset 
2554 </cell>
2555 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2556 \begin_inset Text
2557
2558 \layout Standard
2559
2560 default
2561 \end_inset 
2562 </cell>
2563 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2564 \begin_inset Text
2565
2566 \layout Standard
2567
2568 Win32 builds
2569 \end_inset 
2570 </cell>
2571 </row>
2572 <row topline="true">
2573 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2574 \begin_inset Text
2575
2576 \layout Standard
2577
2578 -
2579 \begin_inset ERT
2580 status Collapsed
2581
2582 \layout Standard
2583
2584 \backslash 
2585 /
2586 \end_inset 
2587
2588 -L dir
2589 \end_inset 
2590 </cell>
2591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2592 \begin_inset Text
2593
2594 \layout Standard
2595
2596 -
2597 \begin_inset ERT
2598 status Collapsed
2599
2600 \layout Standard
2601
2602 \backslash 
2603 /
2604 \end_inset 
2605
2606 -L dir
2607 \end_inset 
2608 </cell>
2609 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2610 \begin_inset Text
2611
2612 \layout Standard
2613
2614 -
2615 \begin_inset ERT
2616 status Collapsed
2617
2618 \layout Standard
2619
2620 \backslash 
2621 /
2622 \end_inset 
2623
2624 -L dir
2625 \end_inset 
2626 </cell>
2627 </row>
2628 <row topline="true">
2629 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2630 \begin_inset Text
2631
2632 \layout Standard
2633
2634 $SDCC_LIB/
2635 \newline 
2636
2637 \emph on 
2638 <model>
2639 \end_inset 
2640 </cell>
2641 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2642 \begin_inset Text
2643
2644 \layout Standard
2645
2646 $SDCC_LIB/
2647 \newline 
2648
2649 \emph on 
2650 <model>
2651 \end_inset 
2652 </cell>
2653 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2654 \begin_inset Text
2655
2656 \layout Standard
2657
2658 $SDCC_LIB
2659 \backslash 
2660
2661 \newline 
2662
2663 \emph on 
2664 <model>
2665 \end_inset 
2666 </cell>
2667 </row>
2668 <row topline="true">
2669 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2670 \begin_inset Text
2671
2672 \layout Standard
2673
2674 $SDCC_HOME/
2675 \newline 
2676
2677 \emph on 
2678 $PREFIX2DATA_DIR/
2679 \newline 
2680 $LIB_DIR_SUFFIX/<model>
2681 \end_inset 
2682 </cell>
2683 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2684 \begin_inset Text
2685
2686 \layout Standard
2687
2688 $SDCC_HOME/
2689 \newline 
2690 share/sdcc/
2691 \newline 
2692 lib/
2693 \emph on 
2694 <model>
2695 \end_inset 
2696 </cell>
2697 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2698 \begin_inset Text
2699
2700 \layout Standard
2701
2702 $SDCC_HOME
2703 \backslash 
2704 lib
2705 \backslash 
2706
2707 \emph on 
2708
2709 \newline 
2710 <model>
2711 \end_inset 
2712 </cell>
2713 </row>
2714 <row topline="true">
2715 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2716 \begin_inset Text
2717
2718 \layout Standard
2719
2720 path(argv[0])/
2721 \newline 
2722
2723 \emph on 
2724 $BIN2DATADIR/
2725 \emph default 
2726
2727 \newline 
2728
2729 \emph on 
2730 $LIB_DIR_SUFFIX/<model>
2731 \end_inset 
2732 </cell>
2733 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2734 \begin_inset Text
2735
2736 \layout Standard
2737
2738 path(argv[0])/
2739 \newline 
2740 ../sdcc/lib/
2741 \emph on 
2742 <model>
2743 \newline 
2744 \SpecialChar ~
2745 \SpecialChar ~
2746 \SpecialChar ~
2747 \SpecialChar ~
2748 \SpecialChar ~
2749 \SpecialChar ~
2750 \SpecialChar ~
2751 \SpecialChar ~
2752 \SpecialChar ~
2753 \SpecialChar ~
2754 \SpecialChar ~
2755 \SpecialChar ~
2756 \SpecialChar ~
2757 \SpecialChar ~
2758 \SpecialChar ~
2759 \SpecialChar ~
2760 \SpecialChar ~
2761 \SpecialChar ~
2762 \SpecialChar ~
2763 \SpecialChar ~
2764 \SpecialChar ~
2765 \SpecialChar ~
2766 \SpecialChar ~
2767 \SpecialChar ~
2768 \SpecialChar ~
2769 \SpecialChar ~
2770 \SpecialChar ~
2771 \SpecialChar ~
2772 \SpecialChar ~
2773 \SpecialChar ~
2774 \SpecialChar ~
2775 \SpecialChar ~
2776 \SpecialChar ~
2777 \SpecialChar ~
2778 \SpecialChar ~
2779 \SpecialChar ~
2780 \SpecialChar ~
2781 \SpecialChar ~
2782 \SpecialChar ~
2783
2784 \end_inset 
2785 </cell>
2786 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2787 \begin_inset Text
2788
2789 \layout Standard
2790
2791 path(argv[0])
2792 \backslash 
2793
2794 \newline 
2795 ..
2796 \backslash 
2797 lib
2798 \backslash 
2799
2800 \emph on 
2801 <model>
2802 \newline 
2803 \SpecialChar ~
2804 \SpecialChar ~
2805 \SpecialChar ~
2806 \SpecialChar ~
2807 \SpecialChar ~
2808 \SpecialChar ~
2809 \SpecialChar ~
2810 \SpecialChar ~
2811 \SpecialChar ~
2812 \SpecialChar ~
2813 \SpecialChar ~
2814 \SpecialChar ~
2815 \SpecialChar ~
2816 \SpecialChar ~
2817 \SpecialChar ~
2818 \SpecialChar ~
2819 \SpecialChar ~
2820 \SpecialChar ~
2821 \SpecialChar ~
2822 \SpecialChar ~
2823 \SpecialChar ~
2824 \SpecialChar ~
2825 \SpecialChar ~
2826 \SpecialChar ~
2827 \SpecialChar ~
2828 \SpecialChar ~
2829 \SpecialChar ~
2830 \SpecialChar ~
2831 \SpecialChar ~
2832 \SpecialChar ~
2833 \SpecialChar ~
2834 \SpecialChar ~
2835 \SpecialChar ~
2836 \SpecialChar ~
2837 \SpecialChar ~
2838
2839 \end_inset 
2840 </cell>
2841 </row>
2842 <row topline="true" bottomline="true">
2843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2844 \begin_inset Text
2845
2846 \layout Standard
2847
2848
2849 \emph on 
2850 $DATADIR/
2851 \newline 
2852 $LIB_DIR_SUFFIX/<model>
2853 \end_inset 
2854 </cell>
2855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2856 \begin_inset Text
2857
2858 \layout Standard
2859
2860 /usr/local/share/sdcc/
2861 \newline 
2862 lib/
2863 \emph on 
2864 <model>
2865 \end_inset 
2866 </cell>
2867 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2868 \begin_inset Text
2869
2870 \layout Standard
2871
2872 (not on Win32)
2873 \end_inset 
2874 </cell>
2875 </row>
2876 </lyxtabular>
2877
2878 \end_inset 
2879
2880
2881 \newline 
2882
2883 \layout Comment
2884
2885 Don't delete any of the stray spaces in the table above without checking
2886  the HTML output (last line)!
2887 \layout Standard
2888
2889 \SpecialChar ~
2890
2891 \newline 
2892 The option -
2893 \begin_inset ERT
2894 status Collapsed
2895
2896 \layout Standard
2897
2898 \backslash 
2899 /
2900 \end_inset 
2901
2902 -nostdlib disables the last two search paths.
2903 \layout Section
2904
2905 Building SDCC
2906 \begin_inset LatexCommand \index{Building SDCC}
2907
2908 \end_inset 
2909
2910
2911 \layout Subsection
2912
2913 Building SDCC on Linux
2914 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
2915
2916 \end_inset 
2917
2918
2919 \layout Enumerate
2920
2921
2922 \series medium 
2923 Download the source package
2924 \series default 
2925  either from the SDCC CVS repository or from the nightly snapshots
2926 \series medium 
2927 , it will be named something like sdcc
2928 \series default 
2929 .src
2930 \series medium 
2931 .t
2932 \series default 
2933 ar.
2934 \series medium 
2935 gz
2936 \series default 
2937  
2938 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
2939
2940 \end_inset 
2941
2942 .
2943 \layout Enumerate
2944
2945
2946 \series medium 
2947 Bring up a command line terminal, such as xterm.
2948 \layout Enumerate
2949
2950
2951 \series medium 
2952 Unpack the file using a command like: 
2953 \family sans 
2954 \series bold 
2955 "tar -xvzf sdcc.src.tar.gz
2956 \family default 
2957 \series default 
2958 "
2959 \series medium 
2960 , this will create a sub-directory called sdcc with all of the sources.
2961 \layout Enumerate
2962
2963 Change directory into the main SDCC directory, for example type: 
2964 \family sans 
2965 \series bold 
2966 "cd sdcc
2967 \series default 
2968 ".
2969 \layout Enumerate
2970
2971
2972 \series medium 
2973 Type 
2974 \family sans 
2975 \series bold 
2976 "./configure
2977 \family default 
2978 \series default 
2979 ".
2980  This configures the package for compilation on your system.
2981 \layout Enumerate
2982
2983
2984 \series medium 
2985 Type 
2986 \family sans 
2987 \series bold 
2988 "make
2989 \family default 
2990 \series default 
2991 "
2992 \series medium 
2993 .
2994
2995 \series default 
2996  All of the source packages will compile, this can take a while.
2997 \layout Enumerate
2998
2999
3000 \series medium 
3001 Type 
3002 \family sans 
3003 \series bold 
3004 "make install"
3005 \family default 
3006 \series default 
3007  as root
3008 \series medium 
3009 .
3010
3011 \series default 
3012  This copies the binary executables, the include files, the libraries and
3013  the documentation to the install directories.
3014  Proceed with section 
3015 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3016
3017 \end_inset 
3018
3019 .
3020 \layout Subsection
3021
3022 Building SDCC on OSX 2.x
3023 \layout Standard
3024
3025 Follow the instruction for Linux.
3026 \newline 
3027
3028 \newline 
3029 On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease
3030 )) fails to compile SDCC.
3031  Fortunately there's also gcc 2.9.x installed, which works fine.
3032  This compiler can be selected by running 'configure' with:
3033 \layout LyX-Code
3034
3035 ./configure CC=gcc2 CXX=g++2
3036 \layout Subsection
3037
3038 Cross compiling SDCC on Linux for Windows
3039 \layout Standard
3040
3041 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3042  See section 'Configure Options'.
3043 \layout Subsection
3044
3045 Building SDCC on Windows 
3046 \layout Standard
3047
3048 With the exception of Cygwin the SDCC binaries uCsim and sdcdb can't be
3049  built on Windows.
3050  They use Unix-sockets, which are not available on Win32.
3051 \layout Subsection
3052
3053 Building SDCC using Cygwin and Mingw32
3054 \layout Standard
3055
3056 For building and installing a Cygwin executable follow the instructions
3057  for Linux.
3058 \newline 
3059
3060 \newline 
3061 On Cygwin a 
3062 \begin_inset Quotes sld
3063 \end_inset 
3064
3065 native
3066 \begin_inset Quotes srd
3067 \end_inset 
3068
3069  Win32-binary can be built, which will not need the Cygwin-DLL.
3070  For the necessary 'configure' options see section 'configure options' or
3071  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
3072 \newline 
3073
3074 \newline 
3075 In order to install Cygwin on Windows download setup.exe from 
3076 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
3077
3078 \end_inset 
3079
3080 .
3081  Run it, set the 
3082 \begin_inset Quotes sld
3083 \end_inset 
3084
3085 default text file type
3086 \begin_inset Quotes srd
3087 \end_inset 
3088
3089  to 
3090 \begin_inset Quotes sld
3091 \end_inset 
3092
3093 unix
3094 \begin_inset Quotes srd
3095 \end_inset 
3096
3097  and download/install at least the following packages.
3098  Some packages are selected by default, others will be automatically selected
3099  because of dependencies with the manually selected packages.
3100  Never deselect these packages!
3101 \layout Itemize
3102
3103 flex
3104 \layout Itemize
3105
3106 bison
3107 \layout Itemize
3108
3109 gcc ; version 3.x is fine, no need to use the old 2.9x
3110 \layout Itemize
3111
3112 binutils ; selected with gcc
3113 \layout Itemize
3114
3115 make
3116 \layout Itemize
3117
3118 rxvt ; a nice console, which makes life much easier under windoze (see below)
3119 \layout Itemize
3120
3121 man ; not really needed for building SDCC, but you'll miss it sooner or
3122  later
3123 \layout Itemize
3124
3125 less ; not really needed for building SDCC, but you'll miss it sooner or
3126  later
3127 \layout Itemize
3128
3129 cvs ; only if you use CVS access
3130 \layout Standard
3131
3132 If you want to develop something you'll need:
3133 \layout Itemize
3134
3135 python ; for the regression tests
3136 \layout Itemize
3137
3138 gdb ; the gnu debugger, together with the nice GUI 
3139 \begin_inset Quotes sld
3140 \end_inset 
3141
3142 insight
3143 \begin_inset Quotes srd
3144 \end_inset 
3145
3146
3147 \layout Itemize
3148
3149 openssh ; to access the CF or commit changes
3150 \layout Itemize
3151
3152 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3153  use autoconf-stable!
3154 \layout Standard
3155
3156 rxvt is a nice console with history.
3157  Replace in your cygwin.bat the line
3158 \layout LyX-Code
3159
3160 bash -
3161 \begin_inset ERT
3162 status Collapsed
3163
3164 \layout Standard
3165
3166 \backslash 
3167 /
3168 \end_inset 
3169
3170 -login -i 
3171 \layout Standard
3172
3173 with (one line):
3174 \layout LyX-Code
3175
3176 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3177 \layout LyX-Code
3178
3179      -bg black -fg white -geometry 100x65 -e bash -
3180 \begin_inset ERT
3181 status Collapsed
3182
3183 \layout Standard
3184
3185 \backslash 
3186 /
3187 \end_inset 
3188
3189 -login
3190 \layout Standard
3191
3192 Text selected with the mouse is automatically copied to the clipboard, pasting
3193  works with shift-insert.
3194 \newline 
3195
3196 \newline 
3197 The other good tip is to make sure you have no //c/-style paths anywhere,
3198  use /cygdrive/c/ instead.
3199  Using // invokes a network lookup which is very slow.
3200  If you think 
3201 \begin_inset Quotes sld
3202 \end_inset 
3203
3204 cygdrive
3205 \begin_inset Quotes srd
3206 \end_inset 
3207
3208  is too long, you can change it with e.g.
3209 \layout LyX-Code
3210
3211 mount -s -u -c /mnt
3212 \layout Standard
3213
3214 SDCC sources use the unix line ending LF.
3215  Life is much easier, if you store the source tree on a drive which is mounted
3216  in binary mode.
3217  And use an editor which can handle LF-only line endings.
3218  Make sure not to commit files with windows line endings.
3219  The tabulator spacing
3220 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
3221
3222 \end_inset 
3223
3224  used in the project is 8.
3225  Although a tabulator spacing of 8 is a sensible choice for programmers
3226  (it's a power of 2 and allows to display 8/16 bit signed variables without
3227  loosing columns) the plan is to move towards using only spaces in the source.
3228 \layout Subsection
3229
3230 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3231 \layout Standard
3232
3233
3234 \series medium 
3235 Download the source package
3236 \series default 
3237  either from the SDCC CVS repository or from the 
3238 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3239
3240 \end_inset 
3241
3242
3243 \series medium 
3244 , it will be named something like sdcc
3245 \series default 
3246 .src
3247 \series medium 
3248 .tgz.
3249
3250 \series default 
3251  SDCC is distributed with all the projects, workspaces, and files you need
3252  to build it using Visual C++ 6.0/NET (except for sdcdb.exe which currently
3253  doesn't build under MSVC).
3254  The workspace name is 'sdcc.dsw'.
3255  Please note that as it is now, all the executables are created in a folder
3256  called sdcc
3257 \backslash 
3258 bin_vc.
3259  Once built you need to copy the executables from sdcc
3260 \backslash 
3261 bin_vc to sdcc
3262 \backslash 
3263 bin before running SDCC.
3264  
3265 \newline 
3266
3267 \newline 
3268 WARNING: Visual studio is very picky with line terminations; it expects
3269  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
3270  If you are getting a message such as "This makefile was not generated by
3271  Developer Studio etc.
3272  etc.
3273 \begin_inset Quotes srd
3274 \end_inset 
3275
3276  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
3277  need to convert the Unix style line endings to DOS style line endings.
3278  To do so you can use the 
3279 \begin_inset Quotes sld
3280 \end_inset 
3281
3282 unix2dos
3283 \begin_inset Quotes srd
3284 \end_inset 
3285
3286  utility freely available on the internet.
3287  Doug Hawkins reported in the sdcc-user list that this works:
3288 \newline 
3289
3290 \newline 
3291 C:
3292 \backslash 
3293 Programming
3294 \backslash 
3295 SDCC> unix2dos sdcc.dsw
3296 \newline 
3297 C:
3298 \backslash 
3299 Programming
3300 \backslash 
3301 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
3302 \newline 
3303
3304 \newline 
3305 In order to build SDCC with MSVC you need win32 executables of bison.exe,
3306  flex.exe, and gawk.exe.
3307  One good place to get them is 
3308 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3309
3310 \end_inset 
3311
3312
3313 \newline 
3314
3315 \newline 
3316 Download the file UnxUtils
3317 \begin_inset LatexCommand \index{UnxUtils}
3318
3319 \end_inset 
3320
3321 .zip.
3322  Now you have to install the utilities and setup MSVC so it can locate the
3323  required programs.
3324  Here there are two alternatives (choose one!):
3325 \layout Enumerate
3326
3327 The easy way:
3328 \newline 
3329
3330 \newline 
3331 a) Extract UnxUtils.zip to your C:
3332 \backslash 
3333  hard disk PRESERVING the original paths, otherwise bison won't work.
3334  (If you are using WinZip make certain that 'Use folder names' is selected)
3335 \newline 
3336
3337 \newline 
3338 b) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3339  in 'Show directories for:' select 'Executable files', and in the directories
3340  window add a new path: 'C:
3341 \backslash 
3342 user
3343 \backslash 
3344 local
3345 \backslash 
3346 wbin', click ok.
3347 \newline 
3348
3349 \newline 
3350 (As a side effect, you get a bunch of Unix utilities that could be useful,
3351  such as diff and patch.)
3352 \layout Enumerate
3353
3354 A more compact way:
3355 \newline 
3356
3357 \newline 
3358 This one avoids extracting a bunch of files you may not use, but requires
3359  some extra work:
3360 \newline 
3361
3362 \newline 
3363 a) Create a directory were to put the tools needed, or use a directory already
3364  present.
3365  Say for example 'C:
3366 \backslash 
3367 util'.
3368 \newline 
3369
3370 \newline 
3371 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and gawk.exe
3372  to such directory WITHOUT preserving the original paths.
3373  (If you are using WinZip make certain that 'Use folder names' is not selected)
3374 \newline 
3375
3376 \newline 
3377 c) Rename bison.exe to '_bison.exe'.
3378 \newline 
3379
3380 \newline 
3381 d) Create a batch file 'bison.bat' in 'C:
3382 \backslash 
3383 util
3384 \backslash 
3385 ' and add these lines: 
3386 \newline 
3387 \SpecialChar ~
3388 \SpecialChar ~
3389 set BISON_SIMPLE=C:
3390 \backslash 
3391 util
3392 \backslash 
3393 bison.simple 
3394 \newline 
3395 \SpecialChar ~
3396 \SpecialChar ~
3397 set BISON_HAIRY=C:
3398 \backslash 
3399 util
3400 \backslash 
3401 bison.hairy
3402 \newline 
3403 \SpecialChar ~
3404 \SpecialChar ~
3405 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3406 \newline 
3407
3408 \newline 
3409 Steps 'c' and 'd' are needed because bison requires by default that the
3410  files 'bison.simple' and 'bison.hairy' reside in some weird Unix directory,
3411  '/usr/local/share/' I think.
3412  So it is necessary to tell bison where those files are located if they
3413  are not in such directory.
3414  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3415 \newline 
3416
3417 \newline 
3418 e) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3419  in 'Show directories for:' select 'Executable files', and in the directories
3420  window add a new path: 'c:
3421 \backslash 
3422 util', click ok.
3423  Note that you can use any other path instead of 'c:
3424 \backslash 
3425 util', even the path where the Visual C++ tools are, probably: 'C:
3426 \backslash 
3427 Program Files
3428 \backslash 
3429 Microsoft Visual Studio
3430 \backslash 
3431 Common
3432 \backslash 
3433 Tools'.
3434  So you don't have to execute step 'e' :)
3435 \layout Standard
3436
3437 That is it.
3438  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
3439  the executables from sdcc
3440 \backslash 
3441 bin_vc to sdcc
3442 \backslash 
3443 bin, and you can compile using SDCC.
3444 \layout Subsection
3445
3446 Building SDCC Using Borland
3447 \layout Enumerate
3448
3449 From the sdcc directory, run the command "make -f Makefile.bcc".
3450  This should regenerate all the .exe files in the bin directory except for
3451  sdcdb.exe (which currently doesn't build under Borland C++).
3452 \layout Enumerate
3453
3454 If you modify any source files and need to rebuild, be aware that the dependenci
3455 es may not be correctly calculated.
3456  The safest option is to delete all .obj files and run the build again.
3457  From a Cygwin BASH prompt, this can easily be done with the command (be
3458  sure you are in the sdcc directory):
3459 \newline 
3460
3461 \newline 
3462
3463 \family sans 
3464 \series bold 
3465 find .
3466  
3467 \backslash 
3468 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
3469 \backslash 
3470 ) -print -exec rm {} 
3471 \backslash 
3472 ;
3473 \family default 
3474 \series default 
3475
3476 \newline 
3477
3478 \newline 
3479 or on Windows NT/2000/XP from the command prompt with the command:
3480 \newline 
3481
3482 \family sans 
3483 \series bold 
3484
3485 \newline 
3486 del /s *.obj *.lib *.rul
3487 \family default 
3488 \series default 
3489  from the sdcc directory.
3490 \layout Subsection
3491
3492 Windows Install Using a ZIP Package
3493 \layout Enumerate
3494
3495 Download the binary zip package from 
3496 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
3497
3498 \end_inset 
3499
3500  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
3501  This should unpack to a group of sub-directories.
3502  An example directory structure after unpacking the mingw32 package is:
3503  c:
3504 \backslash 
3505 sdcc
3506 \backslash 
3507 bin for the executables, c:
3508 \backslash 
3509 sdcc
3510 \backslash 
3511 include and c:
3512 \backslash 
3513 sdcc
3514 \backslash 
3515 lib for the include and libraries.
3516 \layout Enumerate
3517
3518 Adjust your environment variable PATH to include the location of the bin
3519  directory or start sdcc using the full path.
3520 \layout Subsection
3521
3522 Windows Install Using the Setup Program
3523 \begin_inset LatexCommand \label{sub:Windows-Install}
3524
3525 \end_inset 
3526
3527
3528 \layout Standard
3529
3530 Download the setup program 
3531 \emph on 
3532 sdcc-x.y.z-setup.exe
3533 \emph default 
3534  for an official release from 
3535 \newline 
3536
3537 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
3538
3539 \end_inset 
3540
3541  or a setup program for one of the snapshots 
3542 \emph on 
3543 sdcc_yyyymmdd_setup.exe
3544 \emph default 
3545  from 
3546 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
3547
3548 \end_inset 
3549
3550  and execute it.
3551  A windows typical installer will guide you through the installation process.
3552 \layout Section
3553
3554 Building the Documentation
3555 \layout Standard
3556
3557 If the necessary tools (LyX, LaTeX, LaTeX2HTML) are installed it is as easy
3558  as changing into the doc directory and typing 
3559 \family sans 
3560 \series bold 
3561
3562 \begin_inset Quotes srd
3563 \end_inset 
3564
3565 make
3566 \begin_inset Quotes srd
3567 \end_inset 
3568
3569
3570 \family default 
3571 \series default 
3572  there.
3573  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
3574 x).
3575  Using LyX 
3576 \begin_inset LatexCommand \url{http://www.lyx.org}
3577
3578 \end_inset 
3579
3580  as editor this is straightforward.
3581  Prebuilt documentation in html and pdf format is available from 
3582 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
3583
3584 \end_inset 
3585
3586 .
3587 \layout Section
3588
3589 Reading the Documentation
3590 \layout Standard
3591
3592 Currently reading the document in pdf format is recommended, as for unknown
3593  reason the hyperlinks are working there whereas in the html version they
3594  are not
3595 \begin_inset Foot
3596 collapsed false
3597
3598 \layout Standard
3599
3600 If you should know why please drop us a note
3601 \end_inset 
3602
3603 .
3604  
3605 \newline 
3606 You'll find the pdf version
3607 \begin_inset LatexCommand \index{PDF version of this document}
3608
3609 \end_inset 
3610
3611  at 
3612 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
3613
3614 \end_inset 
3615
3616 .
3617  
3618 \newline 
3619 A html version
3620 \begin_inset LatexCommand \index{HTML version of this document}
3621
3622 \end_inset 
3623
3624  should be online at 
3625 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
3626
3627 \end_inset 
3628
3629 .
3630 \newline 
3631 This documentation is in some aspects different from a commercial documentation:
3632  
3633 \layout Itemize
3634
3635 It tries to document SDCC for several processor architectures in one document
3636  (commercially these probably would be separate documents/products).
3637  This document
3638 \begin_inset LatexCommand \index{Status of documentation}
3639
3640 \end_inset 
3641
3642  currently matches SDCC for mcs51 and DS390 best and does give too few informati
3643 on about f.e.
3644  Z80, PIC14, PIC16 and HC08.
3645 \layout Itemize
3646
3647 There are many references pointing away from this documentation.
3648  Don't let this distract you.
3649  If there f.e.
3650  was a reference like 
3651 \begin_inset LatexCommand \url{http://www.opencores.org}
3652
3653 \end_inset 
3654
3655  together with a statement 
3656 \begin_inset Quotes sld
3657 \end_inset 
3658
3659 some processors which are targetted by SDCC can be implemented in a 
3660 \emph on 
3661 f
3662 \emph default 
3663 ield 
3664 \emph on 
3665 p
3666 \emph default 
3667 rogrammable 
3668 \emph on 
3669 g
3670 \emph default 
3671 ate 
3672 \emph on 
3673 a
3674 \emph default 
3675 rray
3676 \begin_inset LatexCommand \index{fpga (field programmable gate array)}
3677
3678 \end_inset 
3679
3680
3681 \begin_inset Quotes srd
3682 \end_inset 
3683
3684  we expect you to have a quick look there and come back.
3685  If you read this you are on the right track.
3686 \layout Itemize
3687
3688 Some sections attribute more space to problems, restrictions and warnings
3689  than to the solution.
3690 \layout Itemize
3691
3692 The installation section and the section about the debugger is intimidating.
3693 \layout Itemize
3694
3695 There are still lots of typos and there are more different writing styles
3696  than pictures.
3697 \layout Section
3698
3699 Testing the SDCC Compiler
3700 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
3701
3702 \end_inset 
3703
3704
3705 \layout Standard
3706
3707 The first thing you should do after installing your SDCC compiler is to
3708  see if it runs.
3709  Type 
3710 \family sans 
3711 \series bold 
3712 "sdcc -
3713 \begin_inset ERT
3714 status Collapsed
3715
3716 \layout Standard
3717
3718 \backslash 
3719 /
3720 \end_inset 
3721
3722 -version"
3723 \begin_inset LatexCommand \index{version}
3724
3725 \end_inset 
3726
3727
3728 \family default 
3729 \series default 
3730  at the prompt, and the program should run and tell you the version.
3731  If it doesn't run, or gives a message about not finding sdcc program, then
3732  you need to check over your installation.
3733  Make sure that the sdcc bin directory is in your executable search path
3734  defined by the PATH environment setting (
3735 \series medium 
3736 see 
3737 \series default 
3738 section 
3739 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3740
3741 \end_inset 
3742
3743 \SpecialChar ~
3744
3745 \series medium 
3746 Install trouble-shooting for suggestions
3747 \series default 
3748 ).
3749  Make sure that the sdcc program is in the bin folder, if not perhaps something
3750  did not install correctly.
3751 \newline 
3752
3753 \newline 
3754
3755 \series medium 
3756 SDCC 
3757 \series default 
3758 is commonly installed as described in section 
3759 \begin_inset Quotes sld
3760 \end_inset 
3761
3762 Install and search paths
3763 \begin_inset Quotes srd
3764 \end_inset 
3765
3766 .
3767 \newline 
3768
3769 \newline 
3770
3771 \series medium 
3772 Make sure the compiler works on a very simple example.
3773  Type in the following test.c program using your favorite 
3774 \series default 
3775 ASCII 
3776 \series medium 
3777 editor:
3778 \layout Verse
3779
3780
3781 \family typewriter 
3782 char test;
3783 \newline 
3784
3785 \newline 
3786 void main(void) {
3787 \newline 
3788 \SpecialChar ~
3789 \SpecialChar ~
3790 \SpecialChar ~
3791 \SpecialChar ~
3792 test=0;
3793 \newline 
3794 }
3795 \layout Standard
3796
3797
3798 \series medium 
3799 Compile this using the following command: 
3800 \family sans 
3801 \series bold 
3802 "sdcc -c test.c".
3803
3804 \family default 
3805 \series default 
3806  
3807 \series medium 
3808 If all goes well, the compiler will generate a test.asm and test.rel file.
3809  Congratulations, you've just compiled your first program with SDCC.
3810  We used the -c option to tell SDCC not to link the generated code, just
3811  to keep things simple for this step.
3812 \series default 
3813
3814 \newline 
3815
3816 \newline 
3817
3818 \series medium 
3819 The next step is to try it with the linker.
3820  Type in 
3821 \family sans 
3822 \series bold 
3823 "sdcc test.c
3824 \family default 
3825 \series default 
3826 "
3827 \series medium 
3828 .
3829  If all goes well the compiler will link with the libraries and produce
3830  a test.ihx output file.
3831  If this step fails
3832 \series default 
3833  
3834 \series medium 
3835 (no test.ihx, and the linker generates warnings), then the problem is most
3836  likely that 
3837 \series default 
3838 SDCC
3839 \series medium 
3840  cannot find the 
3841 \series default 
3842 /
3843 \series medium 
3844 usr/local/share/sdcc/lib directory
3845 \series default 
3846  
3847 \series medium 
3848 (see 
3849 \series default 
3850 section 
3851 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3852
3853 \end_inset 
3854
3855 \SpecialChar ~
3856
3857 \series medium 
3858 Install trouble-shooting for suggestions).
3859 \series default 
3860
3861 \newline 
3862
3863 \newline 
3864
3865 \series medium 
3866 The final test is to ensure 
3867 \series default 
3868 SDCC
3869 \series medium 
3870  can use the 
3871 \series default 
3872 standard
3873 \series medium 
3874  header files and libraries.
3875  Edit test.c and change it to the following:
3876 \layout Verse
3877
3878
3879 \family typewriter 
3880 #include <string.h>
3881 \newline 
3882
3883 \newline 
3884 char str1[10];
3885 \newline 
3886
3887 \newline 
3888 void main(void) {
3889 \newline 
3890 \SpecialChar ~
3891 \SpecialChar ~
3892 strcpy(str1, "testing");
3893 \newline 
3894 }
3895 \layout Standard
3896
3897
3898 \series medium 
3899 Compile this by typing 
3900 \family sans 
3901 \series bold 
3902 "sdcc test.c"
3903 \family default 
3904 \series medium 
3905 .
3906  This should generate a test.ihx output file, and it should give no warnings
3907  such as not finding the string.h file.
3908  If it cannot find the string.h file, then the problem is that 
3909 \series default 
3910 SDCC
3911 \series medium 
3912  cannot find the /usr/local/share/sdcc/include directory
3913 \series default 
3914  
3915 \series medium 
3916 (see the 
3917 \series default 
3918 section 
3919 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3920
3921 \end_inset 
3922
3923 \SpecialChar ~
3924
3925 \series medium 
3926 Install trouble-shooting section for suggestions).
3927
3928 \series default 
3929  Use option 
3930 \series bold 
3931 -
3932 \begin_inset ERT
3933 status Collapsed
3934
3935 \layout Standard
3936
3937 \backslash 
3938 /
3939 \end_inset 
3940
3941 -print-search-dirs
3942 \series default 
3943
3944 \begin_inset LatexCommand \index{-\/-print-search-dirs}
3945
3946 \end_inset 
3947
3948  to find exactly where SDCC is looking for the include and lib files.
3949 \layout Section
3950
3951 Install Trouble-shooting
3952 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
3953
3954 \end_inset 
3955
3956
3957 \begin_inset LatexCommand \index{Install trouble-shooting}
3958
3959 \end_inset 
3960
3961
3962 \layout Subsection
3963
3964 If SDCC does not build correctly
3965 \layout Standard
3966
3967 A thing to try is starting from scratch by unpacking the .tgz source package
3968  again in an empty directory.
3969  Configure it like:
3970 \newline 
3971
3972 \newline 
3973
3974 \family sans 
3975 \series bold 
3976 ./configure 2>&1 | tee configure.log
3977 \family default 
3978 \series default 
3979
3980 \newline 
3981
3982 \newline 
3983 and build it like:
3984 \newline 
3985
3986 \newline 
3987
3988 \family sans 
3989 \series bold 
3990 make 2>&1 | tee make.log
3991 \family default 
3992 \series default 
3993
3994 \newline 
3995
3996 \newline 
3997 If anything goes wrong, you can review the log files to locate the problem.
3998  Or a relevant part of this can be attached to an email that could be helpful
3999  when requesting help from the mailing list.
4000 \layout Subsection
4001
4002 What the 
4003 \begin_inset Quotes sld
4004 \end_inset 
4005
4006 ./configure
4007 \begin_inset Quotes srd
4008 \end_inset 
4009
4010  does
4011 \layout Standard
4012
4013 The 
4014 \begin_inset Quotes sld
4015 \end_inset 
4016
4017 ./configure
4018 \begin_inset Quotes srd
4019 \end_inset 
4020
4021  command is a script that analyzes your system and performs some configuration
4022  to ensure the source package compiles on your system.
4023  It will take a few minutes to run, and will compile a few tests to determine
4024  what compiler features are installed.
4025 \layout Subsection
4026
4027 What the 
4028 \begin_inset Quotes sld
4029 \end_inset 
4030
4031 make
4032 \begin_inset Quotes srd
4033 \end_inset 
4034
4035  does
4036 \layout Standard
4037
4038 This runs the GNU make tool, which automatically compiles all the source
4039  packages into the final installed binary executables.
4040 \layout Subsection
4041
4042 What the 
4043 \begin_inset Quotes sld
4044 \end_inset 
4045
4046 make install
4047 \begin_inset Quotes erd
4048 \end_inset 
4049
4050  command does.
4051 \layout Standard
4052
4053 This will install the compiler, other executables libraries and include
4054  files into the appropriate directories.
4055  See sections 
4056 \begin_inset LatexCommand \ref{sub:Install-paths}
4057
4058 \end_inset 
4059
4060 ,\SpecialChar ~
4061
4062 \begin_inset LatexCommand \ref{sub:Search-Paths}
4063
4064 \end_inset 
4065
4066 \SpecialChar ~
4067 about install and search paths.
4068 \newline 
4069 On most systems you will need super-user privileges to do this.
4070 \layout Section
4071
4072 Components of SDCC
4073 \layout Standard
4074
4075 SDCC is not just a compiler, but a collection of tools by various developers.
4076  These include linkers, assemblers, simulators and other components.
4077  Here is a summary of some of the components.
4078  Note that the included simulator and assembler have separate documentation
4079  which you can find in the source package in their respective directories.
4080  As SDCC grows to include support for other processors, other packages from
4081  various developers are included and may have their own sets of documentation.
4082 \newline 
4083
4084 \newline 
4085 You might want to look at the files which are installed in <installdir>.
4086  At the time of this writing, we find the following programs for gcc-builds:
4087 \newline 
4088  
4089 \newline 
4090 In <installdir>/bin:
4091 \layout Itemize
4092
4093 sdcc - The compiler.
4094 \layout Itemize
4095
4096 sdcpp - The C preprocessor.
4097 \layout Itemize
4098
4099 asx8051 - The assembler for 8051 type processors.
4100 \layout Itemize
4101
4102 as-z80
4103 \series bold 
4104
4105 \series default 
4106 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
4107 \layout Itemize
4108
4109 aslink -The linker for 8051 type processors.
4110 \layout Itemize
4111
4112 link-z80
4113 \series bold 
4114
4115 \series default 
4116 link-gbz80 - The Z80 and GameBoy Z80 linkers.
4117 \layout Itemize
4118
4119 s51 - The ucSim 8051 simulator.
4120 \layout Itemize
4121
4122 sdcdb - The source debugger.
4123 \layout Itemize
4124
4125 packihx - A tool to pack (compress) Intel hex files.
4126 \layout Standard
4127
4128 In <installdir>/share/sdcc/include
4129 \layout Itemize
4130
4131 the include files
4132 \layout Standard
4133
4134 In <installdir>/share/sdcc/lib
4135 \layout Itemize
4136
4137 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
4138  relocatables.
4139 \layout Standard
4140
4141 In <installdir>/share/sdcc/doc
4142 \layout Itemize
4143
4144 the documentation
4145 \layout Standard
4146
4147 As development for other processors proceeds, this list will expand to include
4148  executables to support processors like AVR, PIC, etc.
4149 \layout Subsection
4150
4151 sdcc - The Compiler
4152 \layout Standard
4153
4154 This is the actual compiler, it in turn uses the c-preprocessor and invokes
4155  the assembler and linkage editor.
4156 \layout Subsection
4157
4158 sdcpp - The C-Preprocessor
4159 \layout Standard
4160
4161 The preprocessor
4162 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
4163
4164 \end_inset 
4165
4166  is a modified version of the GNU preprocessor.
4167  The C preprocessor is used to pull in #include sources, process #ifdef
4168  statements, #defines and so on.
4169 \layout Subsection
4170
4171 as
4172 \emph on 
4173 xxxx
4174 \emph default 
4175 , aslink, link-
4176 \emph on 
4177 xxx
4178 \emph default 
4179  - The Assemblers and Linkage Editors
4180 \layout Standard
4181
4182 This is retargettable assembler & linkage editor, it was developed by Alan
4183  Baldwin.
4184  John Hartman created the version for 8051, and I (Sandeep) have made some
4185  enhancements and bug fixes for it to work properly with SDCC.
4186 \layout Subsection
4187
4188 s51 - The Simulator
4189 \layout Standard
4190
4191 S51
4192 \begin_inset LatexCommand \index{s51}
4193
4194 \end_inset 
4195
4196  is a freeware, opensource simulator developed by Daniel Drotos.
4197  The simulator is built as part of the build process.
4198  For more information visit Daniel's web site at: 
4199 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
4200
4201 \end_inset 
4202
4203 .
4204  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
4205  XA51 family.
4206 \layout Subsection
4207
4208 sdcdb - Source Level Debugger
4209 \layout Standard
4210
4211 Sdcdb
4212 \begin_inset LatexCommand \index{sdcdb (debugger)}
4213
4214 \end_inset 
4215
4216  is the companion source level debugger.
4217  More about sdcdb in section 
4218 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
4219
4220 \end_inset 
4221
4222 .
4223  The current version of the debugger uses Daniel's Simulator S51
4224 \begin_inset LatexCommand \index{s51}
4225
4226 \end_inset 
4227
4228 , but can be easily changed to use other simulators.
4229  
4230 \layout Chapter
4231
4232 Using SDCC
4233 \layout Section
4234
4235 Compiling
4236 \layout Subsection
4237
4238 Single Source File Projects
4239 \layout Standard
4240
4241 For single source file 8051 projects the process is very simple.
4242  Compile your programs with the following command 
4243 \family sans 
4244 \series bold 
4245 "sdcc sourcefile.c".
4246
4247 \family default 
4248 \series default 
4249  This will compile, assemble and link your source file.
4250  Output files are as follows:
4251 \layout Itemize
4252
4253 sourcefile.asm
4254 \begin_inset LatexCommand \index{<file>.asm}
4255
4256 \end_inset 
4257
4258  - Assembler source
4259 \begin_inset LatexCommand \index{Assembler source}
4260
4261 \end_inset 
4262
4263  file created by the compiler
4264 \layout Itemize
4265
4266 sourcefile.lst
4267 \begin_inset LatexCommand \index{<file>.lst}
4268
4269 \end_inset 
4270
4271  - Assembler listing
4272 \begin_inset LatexCommand \index{Assembler listing}
4273
4274 \end_inset 
4275
4276  file created by the Assembler
4277 \layout Itemize
4278
4279 sourcefile.rst
4280 \begin_inset LatexCommand \index{<file>.rst}
4281
4282 \end_inset 
4283
4284  - Assembler listing
4285 \begin_inset LatexCommand \index{Assembler listing}
4286
4287 \end_inset 
4288
4289  file updated with linkedit information, created by linkage editor
4290 \layout Itemize
4291
4292 sourcefile.sym
4293 \begin_inset LatexCommand \index{<file>.sym}
4294
4295 \end_inset 
4296
4297  - symbol listing
4298 \begin_inset LatexCommand \index{Symbol listing}
4299
4300 \end_inset 
4301
4302  for the sourcefile, created by the assembler
4303 \layout Itemize
4304
4305 sourcefile.rel
4306 \begin_inset LatexCommand \index{<file>.rel}
4307
4308 \end_inset 
4309
4310  or sourcefile.o
4311 \begin_inset LatexCommand \index{<file>.o}
4312
4313 \end_inset 
4314
4315  - Object file
4316 \begin_inset LatexCommand \index{Object file}
4317
4318 \end_inset 
4319
4320  created by the assembler, input to Linkage editor
4321 \layout Itemize
4322
4323 sourcefile.map
4324 \begin_inset LatexCommand \index{<file>.map}
4325
4326 \end_inset 
4327
4328  - The memory map
4329 \begin_inset LatexCommand \index{Memory map}
4330
4331 \end_inset 
4332
4333  for the load module, created by the Linker
4334 \layout Itemize
4335
4336 sourcefile.mem
4337 \begin_inset LatexCommand \index{<file>.mem}
4338
4339 \end_inset 
4340
4341  - A file with a summary of the memory usage
4342 \layout Itemize
4343
4344 sourcefile.ihx
4345 \begin_inset LatexCommand \index{<file>.ihx}
4346
4347 \end_inset 
4348
4349  - The load module in Intel hex format
4350 \begin_inset LatexCommand \index{Intel hex format}
4351
4352 \end_inset 
4353
4354  (you can select the Motorola S19 format
4355 \begin_inset LatexCommand \index{Motorola S19 format}
4356
4357 \end_inset 
4358
4359  with -
4360 \begin_inset ERT
4361 status Collapsed
4362
4363 \layout Standard
4364
4365 \backslash 
4366 /
4367 \end_inset 
4368
4369 -out-fmt-s19
4370 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
4371
4372 \end_inset 
4373
4374 .
4375  If you need another format you might want to use 
4376 \family sans 
4377 \shape italic 
4378 objdump
4379 \family default 
4380 \shape default 
4381
4382 \begin_inset LatexCommand \index{objdump (tool)}
4383
4384 \end_inset 
4385
4386  or
4387 \family sans 
4388 \shape italic 
4389  srecord
4390 \family default 
4391 \shape default 
4392
4393 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
4394
4395 \end_inset 
4396
4397 ).
4398  Both formats are documented in the documentation of srecord
4399 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
4400
4401 \end_inset 
4402
4403
4404 \layout Itemize
4405
4406 sourcefile.adb
4407 \begin_inset LatexCommand \index{<file>.adb}
4408
4409 \end_inset 
4410
4411  - An intermediate file containing debug information needed to create the
4412  .cdb file (with -
4413 \begin_inset ERT
4414 status Open
4415
4416 \layout Standard
4417
4418 \backslash 
4419 /
4420 \end_inset 
4421
4422 -debug
4423 \begin_inset LatexCommand \index{-\/-debug}
4424
4425 \end_inset 
4426
4427
4428 \layout Itemize
4429
4430 sourcefile.cdb
4431 \begin_inset LatexCommand \index{<file>.cdb}
4432
4433 \end_inset 
4434
4435  - An optional file (with -
4436 \begin_inset ERT
4437 status Collapsed
4438
4439 \layout Standard
4440
4441 \backslash 
4442 /
4443 \end_inset 
4444
4445 -debug) containing debug information.
4446  The format is documented in cdbfileformat.pdf
4447 \layout Itemize
4448
4449 sourcefile.
4450  - (no extension)
4451 \begin_inset LatexCommand \index{<file> (no extension)}
4452
4453 \end_inset 
4454
4455  An optional AOMF or AOMF51
4456 \begin_inset LatexCommand \index{AOMF, AOMF51}
4457
4458 \end_inset 
4459
4460  file containing debug information (generated with option -
4461 \begin_inset ERT
4462 status Collapsed
4463
4464 \layout Standard
4465
4466 \backslash 
4467 /
4468 \end_inset 
4469
4470 -debug).
4471  The (Intel)
4472 \emph on 
4473  a
4474 \emph default 
4475 bsolute 
4476 \emph on 
4477 o
4478 \emph default 
4479 bject 
4480 \emph on 
4481 m
4482 \emph default 
4483 odule 
4484 \emph on 
4485 f
4486 \emph default 
4487 ormat is commonly used by third party tools (debuggers
4488 \begin_inset LatexCommand \index{Debugger}
4489
4490 \end_inset 
4491
4492 , simulators, emulators)
4493 \layout Itemize
4494
4495 sourcefile.dump*
4496 \begin_inset LatexCommand \index{<file>.dump*}
4497
4498 \end_inset 
4499
4500  - Dump file to debug the compiler it self (generated with option -
4501 \begin_inset ERT
4502 status Collapsed
4503
4504 \layout Standard
4505
4506 \backslash 
4507 /
4508 \end_inset 
4509
4510 -dumpall) (see section 
4511 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
4512
4513 \end_inset 
4514
4515 \SpecialChar ~
4516  and section 
4517 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
4518
4519 \end_inset 
4520
4521 \SpecialChar ~
4522
4523 \begin_inset Quotes sld
4524 \end_inset 
4525
4526 Anatomy of the compiler
4527 \begin_inset Quotes srd
4528 \end_inset 
4529
4530 ).
4531 \layout Subsection
4532
4533 Projects with Multiple Source Files
4534 \layout Standard
4535
4536 SDCC can compile only ONE file at a time.
4537  Let us for example assume that you have a project containing the following
4538  files:
4539 \newline 
4540
4541 \newline 
4542 foo1.c (contains some functions)
4543 \newline 
4544 foo2.c (contains some more functions)
4545 \newline 
4546 foomain.c (contains more functions and the function main)
4547 \newline 
4548
4549 \size footnotesize 
4550
4551 \newline 
4552
4553 \size default 
4554 The first two files will need to be compiled separately with the commands:
4555 \size footnotesize 
4556  
4557 \size default 
4558
4559 \newline 
4560
4561 \newline 
4562
4563 \family sans 
4564 \series bold 
4565 sdcc\SpecialChar ~
4566 -c\SpecialChar ~
4567 foo1.c
4568 \family default 
4569 \series default 
4570 \size footnotesize 
4571
4572 \newline 
4573
4574 \family sans 
4575 \series bold 
4576 \size default 
4577 sdcc\SpecialChar ~
4578 -c\SpecialChar ~
4579 foo2.c
4580 \family default 
4581 \series default 
4582
4583 \newline 
4584
4585 \newline 
4586 Then compile the source file containing the 
4587 \emph on 
4588 main()
4589 \emph default 
4590  function and link
4591 \begin_inset LatexCommand \index{Linker}
4592
4593 \end_inset 
4594
4595  the files together with the following command: 
4596 \newline 
4597
4598 \newline 
4599
4600 \family sans 
4601 \series bold 
4602 sdcc\SpecialChar ~
4603 foomain.c\SpecialChar ~
4604 foo1.rel\SpecialChar ~
4605 foo2.rel
4606 \family default 
4607 \series default 
4608
4609 \begin_inset LatexCommand \index{<file>.rel}
4610
4611 \end_inset 
4612
4613
4614 \newline 
4615
4616 \newline 
4617 Alternatively, 
4618 \emph on 
4619 foomain.c 
4620 \emph default 
4621 can be separately compiled as well: 
4622 \family sans 
4623 \series bold 
4624
4625 \newline 
4626
4627 \newline 
4628 sdcc\SpecialChar ~
4629 -c\SpecialChar ~
4630 foomain.c
4631 \newline 
4632 sdcc foomain.rel foo1.rel foo2.rel
4633 \newline 
4634
4635 \newline 
4636
4637 \family default 
4638 \series default 
4639 The file containing the 
4640 \emph on 
4641 main()
4642 \emph default 
4643  function
4644 \emph on 
4645  
4646 \emph default 
4647 \noun on 
4648 must
4649 \noun default 
4650  be the 
4651 \noun on 
4652 first
4653 \noun default 
4654  file specified in the command line, since the linkage editor processes
4655  file in the order they are presented to it.
4656  The linker is invoked from SDCC using a script file with extension .lnk
4657 \begin_inset LatexCommand \index{<file>.lnk}
4658
4659 \end_inset 
4660
4661 .
4662  You can view this file to troubleshoot linking problems such as those arising
4663  from missing libraries.
4664 \layout Subsection
4665
4666 Projects with Additional Libraries
4667 \begin_inset LatexCommand \index{Libraries}
4668
4669 \end_inset 
4670
4671
4672 \layout Standard
4673
4674 Some reusable routines may be compiled into a library, see the documentation
4675  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
4676  for how to create a 
4677 \emph on 
4678 .lib
4679 \begin_inset LatexCommand \index{<file>.lib}
4680
4681 \end_inset 
4682
4683
4684 \emph default 
4685  library file.
4686  Libraries created in this manner can be included in the command line.
4687  Make sure you include the -L <library-path> option to tell the linker where
4688  to look for these files if they are not in the current directory.
4689  Here is an example, assuming you have the source file 
4690 \emph on 
4691 foomain.c
4692 \emph default 
4693  and a library
4694 \emph on 
4695  foolib.lib
4696 \emph default 
4697  in the directory 
4698 \emph on 
4699 mylib
4700 \emph default 
4701  (if that is not the same as your current project):
4702 \newline 
4703
4704 \newline 
4705
4706 \family sans 
4707 \series bold 
4708 sdcc foomain.c foolib.lib -L mylib
4709 \newline 
4710
4711 \newline 
4712
4713 \family default 
4714 \series default 
4715 Note here that
4716 \emph on 
4717  mylib
4718 \emph default 
4719  must be an absolute path name.
4720 \newline 
4721
4722 \newline 
4723 The most efficient way to use libraries is to keep separate modules in separate
4724  source files.
4725  The lib file now should name all the modules.rel
4726 \begin_inset LatexCommand \index{<file>.rel}
4727
4728 \end_inset 
4729
4730  files.
4731  For an example see the standard library file 
4732 \emph on 
4733 libsdcc.lib
4734 \emph default 
4735  in the directory <installdir>/share/lib/small.
4736 \layout Subsection
4737
4738 Using sdcclib to Create and Manage Libraries
4739 \begin_inset LatexCommand \index{sdcclib}
4740
4741 \end_inset 
4742
4743
4744 \layout Standard
4745
4746 Alternatively, instead of having a .rel file for each entry on the library
4747  file as described in the preceding section, sdcclib can be used to embed
4748  all the modules belonging to such library in the library file itself.
4749  This results in a larger library file, but it greatly reduces the number
4750  of disk files accessed by the linker.
4751   Additionally, the packed library file contains an index of all include
4752  modules and symbols that significantly speeds up the linking process.
4753  To display a list of options supported by sdcclib type:
4754 \newline 
4755
4756 \layout Standard
4757
4758
4759 \family sans 
4760 \series bold 
4761 sdcclib -?
4762 \begin_inset LatexCommand \index{sdcclib}
4763
4764 \end_inset 
4765
4766
4767 \newline 
4768
4769 \newline 
4770
4771 \family default 
4772 \series default 
4773 To create a new library file, start by compiling all the required modules.
4774  For example:
4775 \newline 
4776
4777 \layout Standard
4778
4779
4780 \family sans 
4781 \series bold 
4782 sdcc -c _divsint.c
4783 \layout Standard
4784
4785
4786 \family sans 
4787 \series bold 
4788 sdcc -c _divuint.c
4789 \layout Standard
4790
4791
4792 \family sans 
4793 \series bold 
4794 sdcc -c _modsint.c
4795 \layout Standard
4796
4797
4798 \family sans 
4799 \series bold 
4800 sdcc -c _moduint.c
4801 \layout Standard
4802
4803
4804 \family sans 
4805 \series bold 
4806 sdcc -c _mulint.c
4807 \newline 
4808
4809 \layout Standard
4810
4811 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
4812  and _mulint.rel.
4813  The next step is to add the .rel files to the library file:
4814 \newline 
4815
4816 \layout Standard
4817
4818
4819 \family sans 
4820 \series bold 
4821 sdcclib libint.lib _divsint.rel
4822 \family default 
4823
4824 \begin_inset LatexCommand \index{sdcclib}
4825
4826 \end_inset 
4827
4828
4829 \layout Standard
4830
4831
4832 \family sans 
4833 \series bold 
4834 sdcclib libint.lib _divuint.rel
4835 \layout Standard
4836
4837
4838 \family sans 
4839 \series bold 
4840 sdcclib libint.lib _modsint.rel
4841 \layout Standard
4842
4843
4844 \family sans 
4845 \series bold 
4846 sdcclib libint.lib _moduint.rel
4847 \layout Standard
4848
4849
4850 \family sans 
4851 \series bold 
4852 sdcclib libint.lib _mulint.rel
4853 \series default 
4854
4855 \newline 
4856
4857 \layout Standard
4858
4859 If the file already exists in the library, it will be replaced.
4860  To see what modules and symbols are included in the library, options -s
4861  and -m are available.
4862  For example:
4863 \newline 
4864
4865 \newline 
4866
4867 \family sans 
4868 \series bold 
4869 sdcclib -s libint.lib
4870 \family default 
4871
4872 \begin_inset LatexCommand \index{sdcclib}
4873
4874 \end_inset 
4875
4876
4877 \newline 
4878
4879 \family typewriter 
4880 \series default 
4881 _divsint.rel:
4882 \layout Standard
4883
4884
4885 \family typewriter 
4886 __divsint_a_1_1
4887 \layout Standard
4888
4889
4890 \family typewriter 
4891 __divsint_PARM_2
4892 \layout Standard
4893
4894
4895 \family typewriter 
4896 __divsint
4897 \newline 
4898 _divuint.rel:
4899 \layout Standard
4900
4901
4902 \family typewriter 
4903 __divuint_a_1_1
4904 \layout Standard
4905
4906
4907 \family typewriter 
4908 __divuint_PARM_2
4909 \layout Standard
4910
4911
4912 \family typewriter 
4913 __divuint_reste_1_1
4914 \layout Standard
4915
4916
4917 \family typewriter 
4918 __divuint_count_1_1
4919 \layout Standard
4920
4921
4922 \family typewriter 
4923 __divuint
4924 \newline 
4925 _modsint.rel:
4926 \layout Standard
4927
4928
4929 \family typewriter 
4930 __modsint_a_1_1
4931 \layout Standard
4932
4933
4934 \family typewriter 
4935 __modsint_PARM_2
4936 \layout Standard
4937
4938
4939 \family typewriter 
4940 __modsint
4941 \newline 
4942 _moduint.rel:
4943 \layout Standard
4944
4945
4946 \family typewriter 
4947 __moduint_a_1_1
4948 \layout Standard
4949
4950
4951 \family typewriter 
4952 __moduint_PARM_2
4953 \layout Standard
4954
4955
4956 \family typewriter 
4957 __moduint_count_1_1
4958 \layout Standard
4959
4960
4961 \family typewriter 
4962 __moduint
4963 \newline 
4964 _mulint.rel:
4965 \layout Standard
4966
4967
4968 \family typewriter 
4969 __mulint_PARM_2
4970 \layout Standard
4971
4972
4973 \family typewriter 
4974 __mulint
4975 \family default 
4976 \series bold 
4977
4978 \newline 
4979
4980 \layout Standard
4981
4982 If the source files are compiled using -
4983 \begin_inset ERT
4984 status Open
4985
4986 \layout Standard
4987
4988 \backslash 
4989 /
4990 \end_inset 
4991
4992 -debug
4993 \begin_inset LatexCommand \index{-\/-debug}
4994
4995 \end_inset 
4996
4997 , the corresponding debug information file .adb will be include in the library
4998  file as well.
4999  The library files created with sdcclib are plain text files, so they can
5000  be viewed with a text editor.
5001  It is not recomended to modify a library file created with sdcclib using
5002  a text editor, as there are file indexes numbers located accross the file
5003  used by the linker to quickly locate the required module to link.
5004  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
5005  it can be safely deleted, since all the information required for linking
5006  is embedded in the library file itself.
5007  Library files created using sdcclib are used as described in the preceding
5008  sections.
5009 \layout Section
5010
5011 Command Line Options
5012 \begin_inset LatexCommand \index{Command Line Options}
5013
5014 \end_inset 
5015
5016
5017 \layout Subsection
5018
5019 Processor Selection Options
5020 \begin_inset LatexCommand \index{Options processor selection}
5021
5022 \end_inset 
5023
5024
5025 \begin_inset LatexCommand \index{Processor selection options}
5026
5027 \end_inset 
5028
5029
5030 \layout List
5031 \labelwidthstring 00.00.0000
5032
5033
5034 \series bold 
5035 -mmcs51
5036 \begin_inset LatexCommand \index{-mmcs51}
5037
5038 \end_inset 
5039
5040
5041 \series default 
5042  Generate code for the Intel MCS51
5043 \begin_inset LatexCommand \index{MCS51}
5044
5045 \end_inset 
5046
5047  family of processors.
5048  This is the default processor target.
5049 \layout List
5050 \labelwidthstring 00.00.0000
5051
5052
5053 \series bold 
5054 -mds390
5055 \begin_inset LatexCommand \index{-mds390}
5056
5057 \end_inset 
5058
5059
5060 \series default 
5061  Generate code for the Dallas DS80C390
5062 \begin_inset LatexCommand \index{DS80C390}
5063
5064 \end_inset 
5065
5066  processor.
5067 \layout List
5068 \labelwidthstring 00.00.0000
5069
5070
5071 \series bold 
5072 -mds400
5073 \begin_inset LatexCommand \index{-mds400}
5074
5075 \end_inset 
5076
5077
5078 \series default 
5079  Generate code for the Dallas DS80C400
5080 \begin_inset LatexCommand \index{DS80C400}
5081
5082 \end_inset 
5083
5084  processor.
5085 \layout List
5086 \labelwidthstring 00.00.0000
5087
5088
5089 \series bold 
5090 -mhc08
5091 \begin_inset LatexCommand \index{-mhc08}
5092
5093 \end_inset 
5094
5095
5096 \series default 
5097  Generate code for the Freescale/Motorola HC08
5098 \begin_inset LatexCommand \index{HC08}
5099
5100 \end_inset 
5101
5102  family of processors.
5103 \layout List
5104 \labelwidthstring 00.00.0000
5105
5106
5107 \series bold 
5108 -mz80
5109 \begin_inset LatexCommand \index{-mz80}
5110
5111 \end_inset 
5112
5113
5114 \series default 
5115  Generate code for the Zilog Z80
5116 \begin_inset LatexCommand \index{Z80}
5117
5118 \end_inset 
5119
5120  family of processors.
5121 \layout List
5122 \labelwidthstring 00.00.0000
5123
5124
5125 \series bold 
5126 -mgbz80
5127 \begin_inset LatexCommand \index{-mgbz80}
5128
5129 \end_inset 
5130
5131
5132 \series default 
5133  Generate code for the GameBoy Z80
5134 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
5135
5136 \end_inset 
5137
5138  processor (Not actively maintained).
5139 \layout List
5140 \labelwidthstring 00.00.0000
5141
5142
5143 \series bold 
5144 -mavr
5145 \begin_inset LatexCommand \index{-mavr}
5146
5147 \end_inset 
5148
5149
5150 \series default 
5151  Generate code for the Atmel AVR
5152 \begin_inset LatexCommand \index{AVR}
5153
5154 \end_inset 
5155
5156  processor (In development, not complete).
5157  AVR users should probably have a look at winavr 
5158 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
5159
5160 \end_inset 
5161
5162  or 
5163 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
5164
5165 \end_inset 
5166
5167 .
5168 \layout Comment
5169
5170 I think it is fair to direct users there for now.
5171  Open source is also about avoiding unnecessary work .
5172  But I didn't find the 'official' link.
5173 \layout List
5174 \labelwidthstring 00.00.0000
5175
5176
5177 \series bold 
5178 -mpic14
5179 \begin_inset LatexCommand \index{-mpic14}
5180
5181 \end_inset 
5182
5183
5184 \series default 
5185  Generate code for the Microchip PIC 14
5186 \begin_inset LatexCommand \index{PIC14}
5187
5188 \end_inset 
5189
5190 -bit processors (p16f84 and variants.
5191  In development, not complete).
5192 \layout Comment
5193
5194 p16f627 p16f628 p16f84 p16f873 p16f877?
5195 \layout List
5196 \labelwidthstring 00.00.0000
5197
5198
5199 \series bold 
5200 -mpic16
5201 \begin_inset LatexCommand \index{-mpic16}
5202
5203 \end_inset 
5204
5205
5206 \series default 
5207  Generate code for the Microchip PIC 16
5208 \begin_inset LatexCommand \index{PIC16}
5209
5210 \end_inset 
5211
5212 -bit processors (p18f452 and variants.
5213  In development, not complete).
5214 \layout List
5215 \labelwidthstring 00.00.0000
5216
5217
5218 \series bold 
5219 -mtlcs900h
5220 \series default 
5221  Generate code for the Toshiba TLCS-900H
5222 \begin_inset LatexCommand \index{TLCS-900H}
5223
5224 \end_inset 
5225
5226  processor (Not maintained, not complete).
5227 \layout List
5228 \labelwidthstring 00.00.0000
5229
5230
5231 \series bold 
5232 -mxa51
5233 \begin_inset LatexCommand \index{-mxa51}
5234
5235 \end_inset 
5236
5237
5238 \series default 
5239  Generate code for the Phillips XA51
5240 \begin_inset LatexCommand \index{XA51}
5241
5242 \end_inset 
5243
5244  processor (Not maintained, not complete).
5245 \layout Subsection
5246
5247 Preprocessor Options
5248 \begin_inset LatexCommand \index{Options preprocessor}
5249
5250 \end_inset 
5251
5252
5253 \begin_inset LatexCommand \index{Preprocessor options}
5254
5255 \end_inset 
5256
5257
5258 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5259
5260 \end_inset 
5261
5262
5263 \layout List
5264 \labelwidthstring 00.00.0000
5265
5266
5267 \series bold 
5268 -I<path>
5269 \begin_inset LatexCommand \index{-I<path>}
5270
5271 \end_inset 
5272
5273
5274 \series default 
5275  The additional location where the pre processor will look for <..h> or 
5276 \begin_inset Quotes eld
5277 \end_inset 
5278
5279 ..h
5280 \begin_inset Quotes erd
5281 \end_inset 
5282
5283  files.
5284 \layout List
5285 \labelwidthstring 00.00.0000
5286
5287
5288 \series bold 
5289 -D<macro[=value]>
5290 \begin_inset LatexCommand \index{-D<macro[=value]>}
5291
5292 \end_inset 
5293
5294
5295 \series default 
5296  Command line definition of macros.
5297  Passed to the preprocessor.
5298 \layout List
5299 \labelwidthstring 00.00.0000
5300
5301
5302 \series bold 
5303 -M
5304 \begin_inset LatexCommand \index{-M}
5305
5306 \end_inset 
5307
5308
5309 \series default 
5310  Tell the preprocessor to output a rule suitable for make describing the
5311  dependencies of each object file.
5312  For each source file, the preprocessor outputs one make-rule whose target
5313  is the object file name for that source file and whose dependencies are
5314  all the files `#include'd in it.
5315  This rule may be a single line or may be continued with `
5316 \backslash 
5317 '-newline if it is long.
5318  The list of rules is printed on standard output instead of the preprocessed
5319  C program.
5320  `-M' implies `-E
5321 \begin_inset LatexCommand \index{-E}
5322
5323 \end_inset 
5324
5325 '.
5326 \layout List
5327 \labelwidthstring 00.00.0000
5328
5329
5330 \series bold 
5331 -C
5332 \begin_inset LatexCommand \index{-C}
5333
5334 \end_inset 
5335
5336
5337 \series default 
5338  Tell the preprocessor not to discard comments.
5339  Used with the `-E' option.
5340 \layout List
5341 \labelwidthstring 00.00.0000
5342
5343
5344 \series bold 
5345 -MM
5346 \begin_inset LatexCommand \index{-MM}
5347
5348 \end_inset 
5349
5350
5351 \size large 
5352 \bar under 
5353  
5354 \series default 
5355 \size default 
5356 \bar default 
5357 Like `-M' but the output mentions only the user header files included with
5358  `#include 
5359 \begin_inset Quotes eld
5360 \end_inset 
5361
5362 file"'.
5363  System header files included with `#include <file>' are omitted.
5364 \layout List
5365 \labelwidthstring 00.00.0000
5366
5367
5368 \series bold 
5369 -Aquestion(answer)
5370 \begin_inset LatexCommand \index{-Aquestion(answer)}
5371
5372 \end_inset 
5373
5374
5375 \series default 
5376  Assert the answer answer for question, in case it is tested with a preprocessor
5377  conditional such as `#if #question(answer)'.
5378  `-A-' disables the standard assertions that normally describe the target
5379  machine.
5380 \layout List
5381 \labelwidthstring 00.00.0000
5382
5383
5384 \series bold 
5385 -Umacro
5386 \begin_inset LatexCommand \index{-Umacro}
5387
5388 \end_inset 
5389
5390
5391 \series default 
5392  Undefine macro macro.
5393  `-U' options are evaluated after all `-D' options, but before any `-include'
5394  and `-imacros' options.
5395 \layout List
5396 \labelwidthstring 00.00.0000
5397
5398
5399 \series bold 
5400 -dM
5401 \begin_inset LatexCommand \index{-dM}
5402
5403 \end_inset 
5404
5405
5406 \series default 
5407  Tell the preprocessor to output only a list of the macro definitions that
5408  are in effect at the end of preprocessing.
5409  Used with the `-E' option.
5410 \layout List
5411 \labelwidthstring 00.00.0000
5412
5413
5414 \series bold 
5415 -dD
5416 \begin_inset LatexCommand \index{-dD}
5417
5418 \end_inset 
5419
5420
5421 \series default 
5422  Tell the preprocessor to pass all macro definitions into the output, in
5423  their proper sequence in the rest of the output.
5424 \layout List
5425 \labelwidthstring 00.00.0000
5426
5427
5428 \series bold 
5429 -dN
5430 \begin_inset LatexCommand \index{-dN}
5431
5432 \end_inset 
5433
5434
5435 \size large 
5436 \bar under 
5437  
5438 \series default 
5439 \size default 
5440 \bar default 
5441 Like `-dD' except that the macro arguments and contents are omitted.
5442  Only `#define name' is included in the output.
5443 \layout List
5444 \labelwidthstring 00.00.0000
5445
5446
5447 \series bold 
5448 -Wp\SpecialChar ~
5449 preprocessorOption[,preprocessorOption]
5450 \series default 
5451
5452 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
5453
5454 \end_inset 
5455
5456 ...
5457  Pass the preprocessorOption to the preprocessor 
5458 \family typewriter 
5459 sdcpp
5460 \family default 
5461
5462 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5463
5464 \end_inset 
5465
5466 .
5467  SDCC uses an adapted version of the preprocessor cpp of the GNU Compiler
5468  Collection (gcc), if you need more dedicated options please refer to the
5469  documentation at 
5470 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
5471
5472 \end_inset 
5473
5474 .
5475 \layout Subsection
5476
5477 Linker Options
5478 \begin_inset LatexCommand \index{Options linker}
5479
5480 \end_inset 
5481
5482
5483 \begin_inset LatexCommand \index{Linker options}
5484
5485 \end_inset 
5486
5487
5488 \layout List
5489 \labelwidthstring 00.00.0000
5490
5491
5492 \series bold 
5493 -L\SpecialChar ~
5494 -
5495 \series default 
5496
5497 \begin_inset ERT
5498 status Collapsed
5499
5500 \layout Standard
5501
5502 \backslash 
5503 /
5504 \end_inset 
5505
5506
5507 \series bold 
5508 -lib-path
5509 \begin_inset LatexCommand \index{-\/-lib-path <path>}
5510
5511 \end_inset 
5512
5513
5514 \begin_inset LatexCommand \index{-L -\/-lib-path}
5515
5516 \end_inset 
5517
5518
5519 \series default 
5520 \SpecialChar ~
5521 <absolute path to additional libraries> This option is passed to the linkage
5522  editor's additional libraries
5523 \begin_inset LatexCommand \index{Libraries}
5524
5525 \end_inset 
5526
5527  search path.
5528  The path name must be absolute.
5529  Additional library files may be specified in the command line.
5530  See section Compiling programs for more details.
5531 \layout List
5532 \labelwidthstring 00.00.0000
5533
5534
5535 \series bold 
5536 -
5537 \begin_inset ERT
5538 status Collapsed
5539
5540 \layout Standard
5541
5542 \backslash 
5543 /
5544 \end_inset 
5545
5546 -xram-loc
5547 \series default 
5548
5549 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
5550
5551 \end_inset 
5552
5553 \SpecialChar ~
5554 <Value> The start location of the external ram
5555 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
5556
5557 \end_inset 
5558
5559 , default value is 0.
5560  The value entered can be in Hexadecimal or Decimal format, e.g.: -
5561 \begin_inset ERT
5562 status Collapsed
5563
5564 \layout Standard
5565
5566 \backslash 
5567 /
5568 \end_inset 
5569
5570 -xram-loc 0x8000 or -
5571 \begin_inset ERT
5572 status Collapsed
5573
5574 \layout Standard
5575
5576 \backslash 
5577 /
5578 \end_inset 
5579
5580 -xram-loc 32768.
5581 \layout List
5582 \labelwidthstring 00.00.0000
5583
5584
5585 \series bold 
5586 -
5587 \begin_inset ERT
5588 status Collapsed
5589
5590 \layout Standard
5591
5592 \backslash 
5593 /
5594 \end_inset 
5595
5596 -code-loc
5597 \series default 
5598
5599 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
5600
5601 \end_inset 
5602
5603 \SpecialChar ~
5604 <Value> The start location of the code
5605 \begin_inset LatexCommand \index{code}
5606
5607 \end_inset 
5608
5609  segment, default value 0.
5610  Note when this option is used the interrupt vector table is also relocated
5611  to the given address.
5612  The value entered can be in Hexadecimal or Decimal format, e.g.: -
5613 \begin_inset ERT
5614 status Collapsed
5615
5616 \layout Standard
5617
5618 \backslash 
5619 /
5620 \end_inset 
5621
5622 -code-loc 0x8000 or -
5623 \begin_inset ERT
5624 status Collapsed
5625
5626 \layout Standard
5627
5628 \backslash 
5629 /
5630 \end_inset 
5631
5632 -code-loc 32768.
5633 \layout List
5634 \labelwidthstring 00.00.0000
5635
5636
5637 \series bold 
5638 -
5639 \begin_inset ERT
5640 status Collapsed
5641
5642 \layout Standard
5643
5644 \backslash 
5645 /
5646 \end_inset 
5647
5648 -stack-loc
5649 \series default 
5650
5651 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
5652
5653 \end_inset 
5654
5655 \SpecialChar ~
5656 <Value> By default the stack
5657 \begin_inset LatexCommand \index{stack}
5658
5659 \end_inset 
5660
5661  is placed after the data segment.
5662  Using this option the stack can be placed anywhere in the internal memory
5663  space of the 8051.
5664  The value entered can be in Hexadecimal or Decimal format, e.g.
5665  -
5666 \begin_inset ERT
5667 status Collapsed
5668
5669 \layout Standard
5670
5671 \backslash 
5672 /
5673 \end_inset 
5674
5675 -stack-loc 0x20 or -
5676 \begin_inset ERT
5677 status Collapsed
5678
5679 \layout Standard
5680
5681 \backslash 
5682 /
5683 \end_inset 
5684
5685 -stack-loc 32.
5686  Since the sp register is incremented before a push or call, the initial
5687  sp will be set to one byte prior the provided value.
5688  The provided value should not overlap any other memory areas such as used
5689  register banks or the data segment and with enough space for the current
5690  application.
5691  The 
5692 \series bold 
5693 -
5694 \begin_inset ERT
5695 status Collapsed
5696
5697 \layout Standard
5698
5699 \backslash 
5700 /
5701 \end_inset 
5702
5703 -pack-iram
5704 \series default 
5705 \SpecialChar ~
5706
5707 \begin_inset LatexCommand \index{-\/-pack-iram}
5708
5709 \end_inset 
5710
5711  option (which is now a default setting) will override this setting, so
5712  you should also specify the 
5713 \series bold 
5714 -
5715 \begin_inset ERT
5716 status Collapsed
5717
5718 \layout Standard
5719
5720 \backslash 
5721 /
5722 \end_inset 
5723
5724 -no-pack-iram
5725 \series default 
5726 \SpecialChar ~
5727
5728 \begin_inset LatexCommand \index{-\/-no-pack-iram}
5729
5730 \end_inset 
5731
5732  option if you need to manually place the stack.
5733 \layout List
5734 \labelwidthstring 00.00.0000
5735
5736
5737 \series bold 
5738 -
5739 \begin_inset ERT
5740 status Collapsed
5741
5742 \layout Standard
5743
5744 \backslash 
5745 /
5746 \end_inset 
5747
5748 -data-loc
5749 \series default 
5750
5751 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
5752
5753 \end_inset 
5754
5755 \SpecialChar ~
5756 <Value> The start location of the internal ram data
5757 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
5758
5759 \end_inset 
5760
5761  segment.
5762  The value entered can be in Hexadecimal or Decimal format, eg.
5763  -
5764 \begin_inset ERT
5765 status Collapsed
5766
5767 \layout Standard
5768
5769 \backslash 
5770 /
5771 \end_inset 
5772
5773 -data-loc 0x20 or -
5774 \begin_inset ERT
5775 status Collapsed
5776
5777 \layout Standard
5778
5779 \backslash 
5780 /
5781 \end_inset 
5782
5783 -data-loc 32.
5784  (By default, the start location of the internal ram data segment  is set
5785  as low as possible in memory, taking into account the used register banks
5786  and the bit segment at address 0x20.
5787  For example if register banks 0 and 1 are used without bit variables, the
5788  data segment will be set, if -
5789 \begin_inset ERT
5790 status Collapsed
5791
5792 \layout Standard
5793
5794 \backslash 
5795 /
5796 \end_inset 
5797
5798 -data-loc is not used, to location 0x10.)
5799 \layout List
5800 \labelwidthstring 00.00.0000
5801
5802
5803 \series bold 
5804 -
5805 \begin_inset ERT
5806 status Collapsed
5807
5808 \layout Standard
5809
5810 \backslash 
5811 /
5812 \end_inset 
5813
5814 -idata-loc
5815 \series default 
5816
5817 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
5818
5819 \end_inset 
5820
5821 \SpecialChar ~
5822 <Value> The start location of the indirectly addressable internal ram
5823 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
5824
5825 \end_inset 
5826
5827  of the 8051, default value is 0x80.
5828  The value entered can be in Hexadecimal or Decimal format, eg.
5829  -
5830 \begin_inset ERT
5831 status Collapsed
5832
5833 \layout Standard
5834
5835 \backslash 
5836 /
5837 \end_inset 
5838
5839 -idata-loc 0x88 or -
5840 \begin_inset ERT
5841 status Collapsed
5842
5843 \layout Standard
5844
5845 \backslash 
5846 /
5847 \end_inset 
5848
5849 -idata-loc 136.
5850 \layout List
5851 \labelwidthstring 00.00.0000
5852
5853
5854 \series bold 
5855 -
5856 \begin_inset ERT
5857 status Collapsed
5858
5859 \layout Standard
5860
5861 \backslash 
5862 /
5863 \end_inset 
5864
5865 -bit-loc
5866 \series default 
5867 \SpecialChar ~
5868 <Value> The start location of the bit
5869 \begin_inset LatexCommand \index{bit}
5870
5871 \end_inset 
5872
5873  addressable internal ram of the 8051.
5874  This is 
5875 \emph on 
5876 not
5877 \emph default 
5878  implemented yet.
5879  Instead an option can be passed directly to the linker: -Wl\SpecialChar ~
5880 -bBSEG=<Value>.
5881 \layout List
5882 \labelwidthstring 00.00.0000
5883
5884
5885 \series bold 
5886 -
5887 \begin_inset ERT
5888 status Collapsed
5889
5890 \layout Standard
5891
5892 \backslash 
5893 /
5894 \end_inset 
5895
5896 -out-fmt-ihx
5897 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
5898
5899 \end_inset 
5900
5901
5902 \bar under 
5903  
5904 \series default 
5905 \bar default 
5906 The linker output (final object code) is in Intel Hex format.
5907 \begin_inset LatexCommand \index{Intel hex format}
5908
5909 \end_inset 
5910
5911  This is the default option.
5912  The format itself is documented in the documentation of srecord
5913 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5914
5915 \end_inset 
5916
5917 .
5918 \layout List
5919 \labelwidthstring 00.00.0000
5920
5921
5922 \series bold 
5923 -
5924 \begin_inset ERT
5925 status Collapsed
5926
5927 \layout Standard
5928
5929 \backslash 
5930 /
5931 \end_inset 
5932
5933 -out-fmt-s19
5934 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5935
5936 \end_inset 
5937
5938
5939 \bar under 
5940  
5941 \series default 
5942 \bar default 
5943 The linker output (final object code) is in Motorola S19 format
5944 \begin_inset LatexCommand \index{Motorola S19 format}
5945
5946 \end_inset 
5947
5948 .
5949  The format itself is documented in the documentation of srecord.
5950 \layout List
5951 \labelwidthstring 00.00.0000
5952
5953
5954 \series bold 
5955 -
5956 \begin_inset ERT
5957 status Collapsed
5958
5959 \layout Standard
5960
5961 \backslash 
5962 /
5963 \end_inset 
5964
5965 -out-fmt-elf
5966 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5967
5968 \end_inset 
5969
5970
5971 \bar under 
5972  
5973 \series default 
5974 \bar default 
5975 The linker output (final object code) is in ELF format
5976 \begin_inset LatexCommand \index{ELF format}
5977
5978 \end_inset 
5979
5980 .
5981  (Currently only supported for the HC08 processors)
5982 \layout List
5983 \labelwidthstring 00.00.0000
5984
5985
5986 \series bold 
5987 -Wl\SpecialChar ~
5988 linkOption[,linkOption]
5989 \series default 
5990
5991 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
5992
5993 \end_inset 
5994
5995 ...
5996  Pass the linkOption to the linker.
5997  See file sdcc/as/doc/asxhtm.html for more on linker options.
5998 \layout Subsection
5999
6000 MCS51 Options
6001 \begin_inset LatexCommand \index{Options MCS51}
6002
6003 \end_inset 
6004
6005
6006 \begin_inset LatexCommand \index{MCS51 options}
6007
6008 \end_inset 
6009
6010
6011 \layout List
6012 \labelwidthstring 00.00.0000
6013
6014
6015 \series bold 
6016 -
6017 \begin_inset ERT
6018 status Collapsed
6019
6020 \layout Standard
6021
6022 \backslash 
6023 /
6024 \end_inset 
6025
6026 -model-small
6027 \begin_inset LatexCommand \index{-\/-model-small}
6028
6029 \end_inset 
6030
6031
6032 \series default 
6033 \size large 
6034 \emph on 
6035  
6036 \size default 
6037 \emph default 
6038 Generate code for Small Model programs, see section Memory Models for more
6039  details.
6040  This is the default model.
6041 \layout List
6042 \labelwidthstring 00.00.0000
6043
6044
6045 \series bold 
6046 -
6047 \begin_inset ERT
6048 status Collapsed
6049
6050 \layout Standard
6051
6052 \backslash 
6053 /
6054 \end_inset 
6055
6056 -model-large
6057 \begin_inset LatexCommand \index{-\/-model-large}
6058
6059 \end_inset 
6060
6061
6062 \series default 
6063  Generate code for Large model programs, see section Memory Models for more
6064  details.
6065  If this option is used all source files in the project have to be compiled
6066  with this option.
6067 \layout List
6068 \labelwidthstring 00.00.0000
6069
6070
6071 \series bold 
6072 -
6073 \begin_inset ERT
6074 status Collapsed
6075
6076 \layout Standard
6077
6078 \backslash 
6079 /
6080 \end_inset 
6081
6082 -xstack
6083 \begin_inset LatexCommand \index{-\/-xstack}
6084
6085 \end_inset 
6086
6087
6088 \series default 
6089  Uses a pseudo stack in the first 256 bytes in the external ram for allocating
6090  variables and passing parameters.
6091  See section 
6092 \begin_inset LatexCommand \ref{sub:External-Stack}
6093
6094 \end_inset 
6095
6096 \SpecialChar ~
6097  External Stack for more details.
6098 \layout List
6099 \labelwidthstring 00.00.0000
6100
6101
6102 \series bold 
6103 -
6104 \begin_inset ERT
6105 status Collapsed
6106
6107 \layout Standard
6108
6109 \backslash 
6110 /
6111 \end_inset 
6112
6113 -iram-size
6114 \series default 
6115 \SpecialChar ~
6116 <Value>
6117 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
6118
6119 \end_inset 
6120
6121  Causes the linker to check if the internal ram usage is within limits of
6122  the given value.
6123 \layout List
6124 \labelwidthstring 00.00.0000
6125
6126
6127 \series bold 
6128 -
6129 \begin_inset ERT
6130 status Collapsed
6131
6132 \layout Standard
6133
6134 \backslash 
6135 /
6136 \end_inset 
6137
6138 -xram-size
6139 \series default 
6140 \SpecialChar ~
6141 <Value>
6142 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
6143
6144 \end_inset 
6145
6146  Causes the linker to check if the external ram usage is within limits of
6147  the given value.
6148 \layout List
6149 \labelwidthstring 00.00.0000
6150
6151
6152 \series bold 
6153 -
6154 \begin_inset ERT
6155 status Collapsed
6156
6157 \layout Standard
6158
6159 \backslash 
6160 /
6161 \end_inset 
6162
6163 -code-size
6164 \series default 
6165 \SpecialChar ~
6166 <Value>
6167 \begin_inset LatexCommand \index{-\/-code-size <Value>}
6168
6169 \end_inset 
6170
6171  Causes the linker to check if the code memory usage is within limits of
6172  the given value.
6173 \layout List
6174 \labelwidthstring 00.00.0000
6175
6176
6177 \series bold 
6178 -
6179 \begin_inset ERT
6180 status Collapsed
6181
6182 \layout Standard
6183
6184 \backslash 
6185 /
6186 \end_inset 
6187
6188 -stack-size
6189 \series default 
6190 \SpecialChar ~
6191 <Value>
6192 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
6193
6194 \end_inset 
6195
6196  Causes the linker to check if there is at minimum <Value> bytes for stack.
6197 \layout List
6198 \labelwidthstring 00.00.0000
6199
6200
6201 \series bold 
6202 -
6203 \begin_inset ERT
6204 status Collapsed
6205
6206 \layout Standard
6207
6208 \backslash 
6209 /
6210 \end_inset 
6211
6212 -pack-iram
6213 \series default 
6214 \SpecialChar ~
6215
6216 \begin_inset LatexCommand \index{-\/-pack-iram}
6217
6218 \end_inset 
6219
6220  Causes the linker to use unused register banks for data variables and pack
6221  data, idata and stack together.
6222  This is the default now.
6223 \layout List
6224 \labelwidthstring 00.00.0000
6225
6226
6227 \series bold 
6228 -
6229 \begin_inset ERT
6230 status Collapsed
6231
6232 \layout Standard
6233
6234 \backslash 
6235 /
6236 \end_inset 
6237
6238 -no-pack-iram
6239 \series default 
6240 \SpecialChar ~
6241
6242 \begin_inset LatexCommand \index{-\/-no-pack-iram}
6243
6244 \end_inset 
6245
6246  Causes the linker to use old style for allocating memory areas.
6247 \layout Subsection
6248
6249 DS390 / DS400 Options
6250 \begin_inset LatexCommand \index{Options DS390}
6251
6252 \end_inset 
6253
6254
6255 \begin_inset LatexCommand \index{DS390 options}
6256
6257 \end_inset 
6258
6259
6260 \layout List
6261 \labelwidthstring 00.00.0000
6262
6263
6264 \series bold 
6265 -
6266 \begin_inset ERT
6267 status Collapsed
6268
6269 \layout Standard
6270
6271 \backslash 
6272 /
6273 \end_inset 
6274
6275 -model-flat24
6276 \series default 
6277
6278 \begin_inset LatexCommand \index{-\/-model-flat24}
6279
6280 \end_inset 
6281
6282
6283 \size large 
6284 \emph on 
6285  
6286 \size default 
6287 \emph default 
6288 Generate 24-bit flat mode code.
6289  This is the one and only that the ds390 code generator supports right now
6290  and is default when using 
6291 \emph on 
6292 -mds390
6293 \emph default 
6294 .
6295  See section Memory Models for more details.
6296 \layout List
6297 \labelwidthstring 00.00.0000
6298
6299
6300 \series bold 
6301 -
6302 \begin_inset ERT
6303 status Collapsed
6304
6305 \layout Standard
6306
6307 \backslash 
6308 /
6309 \end_inset 
6310
6311 -protect-sp-update
6312 \begin_inset LatexCommand \index{-\/-protect-sp-update}
6313
6314 \end_inset 
6315
6316
6317 \series default 
6318  disable interrupts during ESP:SP updates.
6319 \layout List
6320 \labelwidthstring 00.00.0000
6321
6322
6323 \series bold 
6324 -
6325 \begin_inset ERT
6326 status Collapsed
6327
6328 \layout Standard
6329
6330 \backslash 
6331 /
6332 \end_inset 
6333
6334 -stack-10bit
6335 \series default 
6336
6337 \begin_inset LatexCommand \index{-\/-stack-10bit}
6338
6339 \end_inset 
6340
6341  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
6342  This is the one and only that the ds390 code generator supports right now
6343  and is default when using 
6344 \emph on 
6345 -mds390
6346 \emph default 
6347 .
6348  In this mode, the stack is located in the lower 1K of the internal RAM,
6349  which is mapped to 0x400000.
6350  Note that the support is incomplete, since it still uses a single byte
6351  as the stack pointer.
6352  This means that only the lower 256 bytes of the potential 1K stack space
6353  will actually be used.
6354  However, this does allow you to reclaim the precious 256 bytes of low RAM
6355  for use for the DATA and IDATA segments.
6356  The compiler will not generate any code to put the processor into 10 bit
6357  stack mode.
6358  It is important to ensure that the processor is in this mode before calling
6359  any re-entrant functions compiled with this option.
6360  In principle, this should work with the 
6361 \emph on 
6362 -
6363 \begin_inset ERT
6364 status Collapsed
6365
6366 \layout Standard
6367
6368 \backslash 
6369 /
6370 \end_inset 
6371
6372 -stack-auto
6373 \begin_inset LatexCommand \index{-\/-stack-auto}
6374
6375 \end_inset 
6376
6377
6378 \emph default 
6379  option, but that has not been tested.
6380  It is incompatible with the 
6381 \emph on 
6382 -
6383 \begin_inset ERT
6384 status Collapsed
6385
6386 \layout Standard
6387
6388 \backslash 
6389 /
6390 \end_inset 
6391
6392 -xstack
6393 \begin_inset LatexCommand \index{-\/-xstack}
6394
6395 \end_inset 
6396
6397
6398 \emph default 
6399  option.
6400  It also only makes sense if the processor is in 24 bit contiguous addressing
6401  mode (see the 
6402 \emph on 
6403 -
6404 \begin_inset ERT
6405 status Collapsed
6406
6407 \layout Standard
6408
6409 \backslash 
6410 /
6411 \end_inset 
6412
6413 -model-flat24 option
6414 \emph default 
6415 ).
6416 \layout List
6417 \labelwidthstring 00.00.0000
6418
6419
6420 \series bold 
6421 -
6422 \begin_inset ERT
6423 status Collapsed
6424
6425 \layout Standard
6426
6427 \backslash 
6428 /
6429 \end_inset 
6430
6431 -stack-probe
6432 \begin_inset LatexCommand \index{-\/-stack-probe}
6433
6434 \end_inset 
6435
6436
6437 \series default 
6438  insert call to function __stack_probe at each function prologue.
6439 \layout List
6440 \labelwidthstring 00.00.0000
6441
6442
6443 \series bold 
6444 -
6445 \begin_inset ERT
6446 status Collapsed
6447
6448 \layout Standard
6449
6450 \backslash 
6451 /
6452 \end_inset 
6453
6454 -tini-libid
6455 \begin_inset LatexCommand \index{-\/-tini-libid}
6456
6457 \end_inset 
6458
6459
6460 \series default 
6461  <nnnn> LibraryID used in -mTININative.
6462  
6463 \layout List
6464 \labelwidthstring 00.00.0000
6465
6466
6467 \series bold 
6468 -
6469 \begin_inset ERT
6470 status Collapsed
6471
6472 \layout Standard
6473
6474 \backslash 
6475 /
6476 \end_inset 
6477
6478 -use-accelerator
6479 \begin_inset LatexCommand \index{-\/-use-accelerator}
6480
6481 \end_inset 
6482
6483
6484 \series default 
6485  generate code for DS390 Arithmetic Accelerator.
6486  
6487 \layout Subsection
6488
6489 Z80 Options
6490 \begin_inset LatexCommand \index{Options Z80}
6491
6492 \end_inset 
6493
6494
6495 \begin_inset LatexCommand \index{Z80 options}
6496
6497 \end_inset 
6498
6499
6500 \layout List
6501 \labelwidthstring 00.00.0000
6502
6503
6504 \series bold 
6505 -
6506 \begin_inset ERT
6507 status Collapsed
6508
6509 \layout Standard
6510
6511 \backslash 
6512 /
6513 \end_inset 
6514
6515 -callee-saves-bc
6516 \series default 
6517
6518 \begin_inset LatexCommand \index{-\/-callee-saves-bc}
6519
6520 \end_inset 
6521
6522
6523 \size large 
6524 \emph on 
6525  
6526 \size default 
6527 \emph default 
6528 Force a called function to always save BC.
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 -no-std-crt0
6545 \series default 
6546
6547 \begin_inset LatexCommand \index{-\/-no-std-crt0}
6548
6549 \end_inset 
6550
6551  When linking, skip the standard crt0.o object file.
6552  You must provide your own crt0.o for your system when linking.
6553  
6554 \layout Subsection
6555
6556 Optimization Options
6557 \begin_inset LatexCommand \index{Options optimization}
6558
6559 \end_inset 
6560
6561
6562 \begin_inset LatexCommand \index{Optimization options}
6563
6564 \end_inset 
6565
6566
6567 \layout List
6568 \labelwidthstring 00.00.0000
6569
6570
6571 \series bold 
6572 -
6573 \begin_inset ERT
6574 status Collapsed
6575
6576 \layout Standard
6577
6578 \backslash 
6579 /
6580 \end_inset 
6581
6582 -nogcse
6583 \begin_inset LatexCommand \index{-\/-nogcse}
6584
6585 \end_inset 
6586
6587
6588 \series default 
6589  Will not do global subexpression elimination, this option may be used when
6590  the compiler creates undesirably large stack/data spaces to store compiler
6591  temporaries (
6592 \emph on 
6593 s
6594 \emph default 
6595 pill 
6596 \emph on 
6597 loc
6598 \emph default 
6599 ations, sloc
6600 \begin_inset LatexCommand \index{sloc (spill location)}
6601
6602 \end_inset 
6603
6604 ).
6605  A warning message will be generated when this happens and the compiler
6606  will indicate the number of extra bytes it allocated.
6607  It is recommended that this option NOT be used, #pragma\SpecialChar ~
6608 nogcse
6609 \begin_inset LatexCommand \index{\#pragma nogcse}
6610
6611 \end_inset 
6612
6613  can be used to turn off global subexpression elimination
6614 \begin_inset LatexCommand \index{Subexpression elimination}
6615
6616 \end_inset 
6617
6618  for a given function only.
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 -noinvariant
6635 \begin_inset LatexCommand \index{-\/-noinvariant}
6636
6637 \end_inset 
6638
6639
6640 \series default 
6641  Will not do loop invariant optimizations, this may be turned off for reasons
6642  explained for the previous option.
6643  For more details of loop optimizations performed see Loop Invariants in
6644  section 
6645 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
6646
6647 \end_inset 
6648
6649 .
6650  It is recommended that this option NOT be used, #pragma\SpecialChar ~
6651 noinvariant
6652 \begin_inset LatexCommand \index{\#pragma noinvariant}
6653
6654 \end_inset 
6655
6656  can be used to turn off invariant optimizations for a given function only.
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 -noinduction
6673 \begin_inset LatexCommand \index{-\/-noinduction}
6674
6675 \end_inset 
6676
6677
6678 \series default 
6679  Will not do loop induction optimizations, see section strength reduction
6680  for more details.
6681  It is recommended that this option is NOT used, #pragma\SpecialChar ~
6682 noinduction
6683 \begin_inset LatexCommand \index{\#pragma noinduction}
6684
6685 \end_inset 
6686
6687  can be used to turn off induction optimizations for a given function only.
6688 \layout List
6689 \labelwidthstring 00.00.0000
6690
6691
6692 \series bold 
6693 -
6694 \begin_inset ERT
6695 status Collapsed
6696
6697 \layout Standard
6698
6699 \backslash 
6700 /
6701 \end_inset 
6702
6703 -nojtbound
6704 \begin_inset LatexCommand \index{-\/-nojtbound}
6705
6706 \end_inset 
6707
6708
6709 \size large 
6710 \bar under 
6711  
6712 \series default 
6713 \size default 
6714 \bar default 
6715  Will not generate boundary condition check when switch statements
6716 \begin_inset LatexCommand \index{switch statement}
6717
6718 \end_inset 
6719
6720  are implemented using jump-tables.
6721  See section 
6722 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
6723
6724 \end_inset 
6725
6726 \SpecialChar ~
6727 Switch Statements for more details.
6728  It is recommended that this option is NOT used, #pragma\SpecialChar ~
6729 nojtbound
6730 \begin_inset LatexCommand \index{\#pragma nojtbound}
6731
6732 \end_inset 
6733
6734  can be used to turn off boundary checking for jump tables for a given function
6735  only.
6736 \layout List
6737 \labelwidthstring 00.00.0000
6738
6739
6740 \series bold 
6741 -
6742 \begin_inset ERT
6743 status Collapsed
6744
6745 \layout Standard
6746
6747 \backslash 
6748 /
6749 \end_inset 
6750
6751 -noloopreverse
6752 \begin_inset LatexCommand \index{-\/-noloopreverse}
6753
6754 \end_inset 
6755
6756
6757 \series default 
6758 \size large 
6759  
6760 \size default 
6761 Will not do loop reversal 
6762 \begin_inset LatexCommand \index{Loop reversing}
6763
6764 \end_inset 
6765
6766 optimization.
6767 \layout List
6768 \labelwidthstring 00.00.0000
6769
6770 -
6771 \begin_inset ERT
6772 status Collapsed
6773
6774 \layout Standard
6775
6776 \backslash 
6777 /
6778 \end_inset 
6779
6780 -
6781 \series bold 
6782 nolabelopt
6783 \series default 
6784  
6785 \begin_inset LatexCommand \index{-\/-nolabelopt }
6786
6787 \end_inset 
6788
6789 Will not optimize labels (makes the dumpfiles more readable).
6790 \layout List
6791 \labelwidthstring 00.00.0000
6792
6793
6794 \series bold 
6795 -
6796 \begin_inset ERT
6797 status Collapsed
6798
6799 \layout Standard
6800
6801 \backslash 
6802 /
6803 \end_inset 
6804
6805 -no-xinit-opt
6806 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
6807
6808 \end_inset 
6809
6810
6811 \series default 
6812  Will not memcpy initialized data from code space into xdata space.
6813  This saves a few bytes in code space if you don't have initialized data
6814 \begin_inset LatexCommand \index{Variable initialization}
6815
6816 \end_inset 
6817
6818 .
6819 \layout List
6820 \labelwidthstring 00.00.0000
6821
6822
6823 \series bold 
6824 -
6825 \begin_inset ERT
6826 status Collapsed
6827
6828 \layout Standard
6829
6830 \backslash 
6831 /
6832 \end_inset 
6833
6834 -nooverlay
6835 \begin_inset LatexCommand \index{-\/-nooverlay}
6836
6837 \end_inset 
6838
6839
6840 \series default 
6841   The compiler will not overlay parameters and local variables of any function,
6842  see section Parameters and local variables for more details.
6843 \layout List
6844 \labelwidthstring 00.00.0000
6845
6846
6847 \series bold 
6848 -
6849 \begin_inset ERT
6850 status Collapsed
6851
6852 \layout Standard
6853
6854 \backslash 
6855 /
6856 \end_inset 
6857
6858 -no-peep
6859 \begin_inset LatexCommand \index{-\/-no-peep}
6860
6861 \end_inset 
6862
6863
6864 \series default 
6865  Disable peep-hole optimization.
6866 \layout List
6867 \labelwidthstring 00.00.0000
6868
6869
6870 \series bold 
6871 -
6872 \begin_inset ERT
6873 status Collapsed
6874
6875 \layout Standard
6876
6877 \backslash 
6878 /
6879 \end_inset 
6880
6881 -peep-file
6882 \series default 
6883
6884 \begin_inset LatexCommand \index{-\/-peep-file}
6885
6886 \end_inset 
6887
6888 \SpecialChar ~
6889 <filename> This option can be used to use additional rules to be used by
6890  the peep hole optimizer.
6891  See section 
6892 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
6893
6894 \end_inset 
6895
6896 \SpecialChar ~
6897 Peep Hole optimizations for details on how to write these rules.
6898 \layout List
6899 \labelwidthstring 00.00.0000
6900
6901
6902 \series bold 
6903 -
6904 \begin_inset ERT
6905 status Collapsed
6906
6907 \layout Standard
6908
6909 \backslash 
6910 /
6911 \end_inset 
6912
6913 -peep-asm
6914 \begin_inset LatexCommand \index{-\/-peep-asm}
6915
6916 \end_inset 
6917
6918
6919 \series default 
6920  Pass the inline assembler code through the peep hole optimizer.
6921  This can cause unexpected changes to inline assembler code, please go through
6922  the peephole optimizer
6923 \begin_inset LatexCommand \index{Peephole optimizer}
6924
6925 \end_inset 
6926
6927  rules defined in the source file tree '<target>/peeph.def' before using
6928  this option.
6929 \layout List
6930 \labelwidthstring 00.00.0000
6931
6932
6933 \series bold 
6934 -
6935 \begin_inset ERT
6936 status Collapsed
6937
6938 \layout Standard
6939
6940 \backslash 
6941 /
6942 \end_inset 
6943
6944 -opt-code-speed
6945 \begin_inset LatexCommand \index{-\/-opt-code-speed}
6946
6947 \end_inset 
6948
6949
6950 \series default 
6951  The compiler will optimize code generation towards fast code, possibly
6952  at the expense of code size.
6953 \layout List
6954 \labelwidthstring 00.00.0000
6955
6956
6957 \series bold 
6958 -
6959 \begin_inset ERT
6960 status Collapsed
6961
6962 \layout Standard
6963
6964 \backslash 
6965 /
6966 \end_inset 
6967
6968 -opt-code-size
6969 \begin_inset LatexCommand \index{-\/-opt-code-size}
6970
6971 \end_inset 
6972
6973
6974 \series default 
6975  The compiler will optimize code generation towards compact code, possibly
6976  at the expense of code speed.
6977 \layout Subsection
6978
6979 Other Options
6980 \begin_inset LatexCommand \index{Options other}
6981
6982 \end_inset 
6983
6984
6985 \layout List
6986 \labelwidthstring 00.00.0000
6987
6988
6989 \series bold 
6990 -c\SpecialChar ~
6991 -
6992 \begin_inset ERT
6993 status Collapsed
6994
6995 \layout Standard
6996
6997 \backslash 
6998 /
6999 \end_inset 
7000
7001 -compile-only
7002 \begin_inset LatexCommand \index{-\/-compile-only}
7003
7004 \end_inset 
7005
7006
7007 \begin_inset LatexCommand \index{-c -\/-compile-only}
7008
7009 \end_inset 
7010
7011
7012 \series default 
7013  will compile and assemble the source, but will not call the linkage editor.
7014 \layout List
7015 \labelwidthstring 00.00.0000
7016
7017
7018 \series bold 
7019 -
7020 \series default 
7021
7022 \begin_inset ERT
7023 status Collapsed
7024
7025 \layout Standard
7026
7027 \backslash 
7028 /
7029 \end_inset 
7030
7031
7032 \series bold 
7033 -c1mode
7034 \begin_inset LatexCommand \index{-\/-c1mode}
7035
7036 \end_inset 
7037
7038
7039 \series default 
7040  reads the preprocessed source from standard input and compiles it.
7041  The file name for the assembler output must be specified using the -o option.
7042 \layout List
7043 \labelwidthstring 00.00.0000
7044
7045
7046 \series bold 
7047 -E
7048 \begin_inset LatexCommand \index{-E}
7049
7050 \end_inset 
7051
7052
7053 \series default 
7054  Run only the C preprocessor.
7055  Preprocess all the C source files specified and output the results to standard
7056  output.
7057 \layout List
7058 \labelwidthstring 00.00.0000
7059
7060
7061 \series bold 
7062 -o\SpecialChar ~
7063 <path/file>
7064 \begin_inset LatexCommand \index{-o <path/file>}
7065
7066 \end_inset 
7067
7068  
7069 \series default 
7070 The output path resp.
7071  file where everything will be placed.
7072  If the parameter is a path, it must have a trailing slash (or backslash
7073  for the Windows binaries) to be recognized as a path.
7074  
7075 \layout List
7076 \labelwidthstring 00.00.0000
7077
7078
7079 \series bold 
7080 -
7081 \begin_inset ERT
7082 status Collapsed
7083
7084 \layout Standard
7085
7086 \backslash 
7087 /
7088 \end_inset 
7089
7090 -stack-auto
7091 \begin_inset LatexCommand \index{-\/-stack-auto}
7092
7093 \end_inset 
7094
7095
7096 \series default 
7097 \size large 
7098 \emph on 
7099  
7100 \size default 
7101 \emph default 
7102 All functions in the source file will be compiled as 
7103 \emph on 
7104 reentrant
7105 \emph default 
7106
7107 \begin_inset LatexCommand \index{reentrant}
7108
7109 \end_inset 
7110
7111 , i.e.
7112  the parameters and local variables will be allocated on the stack
7113 \begin_inset LatexCommand \index{stack}
7114
7115 \end_inset 
7116
7117 .
7118  See section 
7119 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
7120
7121 \end_inset 
7122
7123  Parameters and Local Variables for more details.
7124  If this option is used all source files in the project should be compiled
7125  with this option.
7126  It automatically implies --int-long-reent and --float-reent.
7127  
7128 \layout List
7129 \labelwidthstring 00.00.0000
7130
7131
7132 \series bold 
7133 -
7134 \begin_inset ERT
7135 status Collapsed
7136
7137 \layout Standard
7138
7139 \backslash 
7140 /
7141 \end_inset 
7142
7143 -callee-saves
7144 \begin_inset LatexCommand \index{-\/-callee-saves}
7145
7146 \end_inset 
7147
7148  function1[,function2][,function3]....
7149
7150 \series default 
7151  The compiler by default uses a caller saves convention for register saving
7152  across function calls, however this can cause unnecessary register pushing
7153  & popping when calling small functions from larger functions.
7154  This option can be used to switch the register saving convention for the
7155  function names specified.
7156  The compiler will not save registers when calling these functions, no extra
7157  code will be generated at the entry & exit (function prologue
7158 \series bold 
7159
7160 \begin_inset LatexCommand \index{function prologue}
7161
7162 \end_inset 
7163
7164
7165 \series default 
7166  & epilogue
7167 \series bold 
7168
7169 \begin_inset LatexCommand \index{function epilogue}
7170
7171 \end_inset 
7172
7173
7174 \series default 
7175 ) for these functions to save & restore the registers used by these functions,
7176  this can SUBSTANTIALLY reduce code & improve run time performance of the
7177  generated code.
7178  In the future the compiler (with inter procedural analysis) will be able
7179  to determine the appropriate scheme to use for each function call.
7180  DO NOT use this option for built-in functions such as _mulint..., if this
7181  option is used for a library function the appropriate library function
7182  needs to be recompiled with the same option.
7183  If the project consists of multiple source files then all the source file
7184  should be compiled with the same -
7185 \begin_inset ERT
7186 status Collapsed
7187
7188 \layout Standard
7189
7190 \backslash 
7191 /
7192 \end_inset 
7193
7194 -callee-saves option string.
7195  Also see #pragma\SpecialChar ~
7196 callee_saves
7197 \begin_inset LatexCommand \index{\#pragma callee\_saves}
7198
7199 \end_inset 
7200
7201 .
7202 \layout List
7203 \labelwidthstring 00.00.0000
7204
7205
7206 \series bold 
7207 -
7208 \begin_inset ERT
7209 status Collapsed
7210
7211 \layout Standard
7212
7213 \backslash 
7214 /
7215 \end_inset 
7216
7217 -debug
7218 \begin_inset LatexCommand \index{-\/-debug}
7219
7220 \end_inset 
7221
7222
7223 \bar under 
7224  
7225 \series default 
7226 \bar default 
7227 When this option is used the compiler will generate debug information.
7228  The debug information collected in a file with .cdb extension can be used
7229  with the SDCDB.
7230  For more information see documentation for SDCDB.
7231  Another file with no extension contains debug information in AOMF or AOMF51
7232 \begin_inset LatexCommand \index{AOMF, AOMF51}
7233
7234 \end_inset 
7235
7236  format which is commonly used by third party tools.
7237 \layout List
7238 \labelwidthstring 00.00.0000
7239
7240
7241 \series bold 
7242 -S
7243 \begin_inset LatexCommand \index{-S}
7244
7245 \end_inset 
7246
7247
7248 \size large 
7249 \bar under 
7250  
7251 \series default 
7252 \size default 
7253 \bar default 
7254 Stop after the stage of compilation proper; do not assemble.
7255  The output is an assembler code file for the input file specified.
7256 \layout List
7257 \labelwidthstring 00.00.0000
7258
7259
7260 \series bold 
7261 -
7262 \begin_inset ERT
7263 status Collapsed
7264
7265 \layout Standard
7266
7267 \backslash 
7268 /
7269 \end_inset 
7270
7271 -int-long-reent
7272 \begin_inset LatexCommand \index{-\/-int-long-reent}
7273
7274 \end_inset 
7275
7276
7277 \series default 
7278  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
7279  Note by default these libraries are compiled as non-reentrant.
7280  See section Installation for more details.
7281 \layout List
7282 \labelwidthstring 00.00.0000
7283
7284
7285 \series bold 
7286 -
7287 \begin_inset ERT
7288 status Collapsed
7289
7290 \layout Standard
7291
7292 \backslash 
7293 /
7294 \end_inset 
7295
7296 -cyclomatic
7297 \begin_inset LatexCommand \index{-\/-cyclomatic}
7298
7299 \end_inset 
7300
7301
7302 \bar under 
7303  
7304 \series default 
7305 \bar default 
7306 This option will cause the compiler to generate an information message for
7307  each function in the source file.
7308  The message contains some 
7309 \emph on 
7310 important
7311 \emph default 
7312  information about the function.
7313  The number of edges and nodes the compiler detected in the control flow
7314  graph of the function, and most importantly the 
7315 \emph on 
7316 cyclomatic complexity
7317 \begin_inset LatexCommand \index{Cyclomatic complexity}
7318
7319 \end_inset 
7320
7321
7322 \emph default 
7323  see section on Cyclomatic Complexity for more details.
7324 \layout List
7325 \labelwidthstring 00.00.0000
7326
7327
7328 \series bold 
7329 -
7330 \begin_inset ERT
7331 status Collapsed
7332
7333 \layout Standard
7334
7335 \backslash 
7336 /
7337 \end_inset 
7338
7339 -float-reent
7340 \begin_inset LatexCommand \index{-\/-float-reent}
7341
7342 \end_inset 
7343
7344
7345 \series default 
7346  Floating point library is compiled as reentrant
7347 \begin_inset LatexCommand \index{reentrant}
7348
7349 \end_inset 
7350
7351 .
7352  See section Installation for more details.
7353 \layout List
7354 \labelwidthstring 00.00.0000
7355
7356
7357 \series bold 
7358 -
7359 \begin_inset ERT
7360 status Collapsed
7361
7362 \layout Standard
7363
7364 \backslash 
7365 /
7366 \end_inset 
7367
7368 -main-return
7369 \begin_inset LatexCommand \index{-\/-main-return}
7370
7371 \end_inset 
7372
7373
7374 \series default 
7375  This option can be used if the code generated is called by a monitor program
7376  or if the main routine includes an endless loop.
7377  This option might result in slightly smaller code and save two bytes of
7378  stack space.
7379  The return from the 'main'
7380 \begin_inset LatexCommand \index{main return}
7381
7382 \end_inset 
7383
7384  function will return to the function calling main.
7385  The default setting is to lock up i.e.
7386  generate a '
7387 \family typewriter 
7388 sjmp .
7389 \family default 
7390 '.
7391 \layout List
7392 \labelwidthstring 00.00.0000
7393
7394
7395 \series bold 
7396 -
7397 \begin_inset ERT
7398 status Collapsed
7399
7400 \layout Standard
7401
7402 \backslash 
7403 /
7404 \end_inset 
7405
7406 -nostdinc
7407 \begin_inset LatexCommand \index{-\/-nostdinc}
7408
7409 \end_inset 
7410
7411
7412 \series default 
7413  This will prevent the compiler from passing on the default include path
7414  to the preprocessor.
7415 \layout List
7416 \labelwidthstring 00.00.0000
7417
7418
7419 \series bold 
7420 -
7421 \begin_inset ERT
7422 status Collapsed
7423
7424 \layout Standard
7425
7426 \backslash 
7427 /
7428 \end_inset 
7429
7430 -nostdlib
7431 \begin_inset LatexCommand \index{-\/-nostdlib}
7432
7433 \end_inset 
7434
7435
7436 \series default 
7437  This will prevent the compiler from passing on the default library
7438 \begin_inset LatexCommand \index{Libraries}
7439
7440 \end_inset 
7441
7442  path to the linker.
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 -verbose
7459 \begin_inset LatexCommand \index{-\/-verbose}
7460
7461 \end_inset 
7462
7463
7464 \series default 
7465  Shows the various actions the compiler is performing.
7466 \layout List
7467 \labelwidthstring 00.00.0000
7468
7469
7470 \series bold 
7471 -V
7472 \begin_inset LatexCommand \index{-V}
7473
7474 \end_inset 
7475
7476
7477 \series default 
7478  Shows the actual commands the compiler is executing.
7479 \layout List
7480 \labelwidthstring 00.00.0000
7481
7482
7483 \series bold 
7484 -
7485 \begin_inset ERT
7486 status Collapsed
7487
7488 \layout Standard
7489
7490 \backslash 
7491 /
7492 \end_inset 
7493
7494 -no-c-code-in-asm
7495 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
7496
7497 \end_inset 
7498
7499
7500 \series default 
7501  Hides your ugly and inefficient c-code from the asm file, so you can always
7502  blame the compiler :)
7503 \layout List
7504 \labelwidthstring 00.00.0000
7505
7506
7507 \series bold 
7508 -
7509 \begin_inset ERT
7510 status Collapsed
7511
7512 \layout Standard
7513
7514 \backslash 
7515 /
7516 \end_inset 
7517
7518 -no-peep-comments
7519 \begin_inset LatexCommand \index{-\/-no-peep-comments}
7520
7521 \end_inset 
7522
7523
7524 \series default 
7525  Will not include peep-hole comments in the generated files.
7526 \layout List
7527 \labelwidthstring 00.00.0000
7528
7529
7530 \series bold 
7531 -
7532 \begin_inset ERT
7533 status Collapsed
7534
7535 \layout Standard
7536
7537 \backslash 
7538 /
7539 \end_inset 
7540
7541 -i-code-in-asm
7542 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
7543
7544 \end_inset 
7545
7546
7547 \series default 
7548  Include i-codes in the asm file.
7549  Sounds like noise but is most helpful for debugging the compiler itself.
7550 \layout List
7551 \labelwidthstring 00.00.0000
7552
7553
7554 \series bold 
7555 -
7556 \begin_inset ERT
7557 status Collapsed
7558
7559 \layout Standard
7560
7561 \backslash 
7562 /
7563 \end_inset 
7564
7565 -less-pedantic
7566 \begin_inset LatexCommand \index{-\/-less-pedantic}
7567
7568 \end_inset 
7569
7570
7571 \series default 
7572  Disable some of the more pedantic warnings
7573 \begin_inset LatexCommand \index{Warnings}
7574
7575 \end_inset 
7576
7577  (jwk burps: please be more specific here, please!).
7578  If you want rather more than less warnings you should consider using a
7579  separate tool dedicated to syntax checking like splint 
7580 \begin_inset LatexCommand \url{http://www.splint.org}
7581
7582 \end_inset 
7583
7584 .
7585 \layout List
7586 \labelwidthstring 00.00.0000
7587
7588
7589 \series bold 
7590 -
7591 \begin_inset ERT
7592 status Collapsed
7593
7594 \layout Standard
7595
7596 \backslash 
7597 /
7598 \end_inset 
7599
7600 -disable-warning\SpecialChar ~
7601 <nnnn>
7602 \begin_inset LatexCommand \index{-\/-disable-warning}
7603
7604 \end_inset 
7605
7606
7607 \series default 
7608  Disable specific warning with number <nnnn>.
7609 \layout List
7610 \labelwidthstring 00.00.0000
7611
7612
7613 \series bold 
7614 -
7615 \begin_inset ERT
7616 status Collapsed
7617
7618 \layout Standard
7619
7620 \backslash 
7621 /
7622 \end_inset 
7623
7624 -print-search-dirs
7625 \begin_inset LatexCommand \index{-\/-print-search-dirs}
7626
7627 \end_inset 
7628
7629
7630 \series default 
7631  Display the directories in the compiler's search path
7632 \layout List
7633 \labelwidthstring 00.00.0000
7634
7635
7636 \series bold 
7637 -
7638 \begin_inset ERT
7639 status Collapsed
7640
7641 \layout Standard
7642
7643 \backslash 
7644 /
7645 \end_inset 
7646
7647 -vc
7648 \begin_inset LatexCommand \index{-\/-vc}
7649
7650 \end_inset 
7651
7652
7653 \series default 
7654  Display errors and warnings using MSVC style, so you can use SDCC with
7655  visual studio.
7656 \layout List
7657 \labelwidthstring 00.00.0000
7658
7659
7660 \series bold 
7661 -
7662 \begin_inset ERT
7663 status Collapsed
7664
7665 \layout Standard
7666
7667 \backslash 
7668 /
7669 \end_inset 
7670
7671 -use-stdout
7672 \begin_inset LatexCommand \index{-\/-use-stdout}
7673
7674 \end_inset 
7675
7676
7677 \series default 
7678  Send errors and warnings to stdout instead of stderr.
7679 \layout List
7680 \labelwidthstring 00.00.0000
7681
7682
7683 \series bold 
7684 -Wa\SpecialChar ~
7685 asmOption[,asmOption]
7686 \series default 
7687
7688 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
7689
7690 \end_inset 
7691
7692 ...
7693  Pass the asmOption to the assembler
7694 \begin_inset LatexCommand \index{Options assembler}
7695
7696 \end_inset 
7697
7698
7699 \begin_inset LatexCommand \index{Assembler options}
7700
7701 \end_inset 
7702
7703 .
7704  See file sdcc/as/doc/asxhtm.html for assembler options.
7705 \layout List
7706 \labelwidthstring 00.00.0000
7707
7708
7709 \series bold 
7710 -
7711 \begin_inset ERT
7712 status Collapsed
7713
7714 \layout Standard
7715
7716 \backslash 
7717 /
7718 \end_inset 
7719
7720 -std-sdcc89
7721 \begin_inset LatexCommand \index{-\/-std-sdcc89}
7722
7723 \end_inset 
7724
7725
7726 \series default 
7727  Generally follow the C89 standard, but allow SDCC features that conflict
7728  with the standard (default).
7729 \layout List
7730 \labelwidthstring 00.00.0000
7731
7732
7733 \series bold 
7734 -
7735 \begin_inset ERT
7736 status Collapsed
7737
7738 \layout Standard
7739
7740 \backslash 
7741 /
7742 \end_inset 
7743
7744 -std-c89
7745 \begin_inset LatexCommand \index{-\/-std-c89}
7746
7747 \end_inset 
7748
7749
7750 \series default 
7751  Follow the C89 standard and disable SDCC features that conflict with the
7752  standard.
7753 \layout List
7754 \labelwidthstring 00.00.0000
7755
7756
7757 \series bold 
7758 -
7759 \begin_inset ERT
7760 status Collapsed
7761
7762 \layout Standard
7763
7764 \backslash 
7765 /
7766 \end_inset 
7767
7768 -std-sdcc99
7769 \begin_inset LatexCommand \index{-\/-std-sdcc99}
7770
7771 \end_inset 
7772
7773
7774 \series default 
7775  Generally follow the C99 standard, but allow SDCC features that conflict
7776  with the standard (incomplete support).
7777 \layout List
7778 \labelwidthstring 00.00.0000
7779
7780
7781 \series bold 
7782 -
7783 \begin_inset ERT
7784 status Collapsed
7785
7786 \layout Standard
7787
7788 \backslash 
7789 /
7790 \end_inset 
7791
7792 -std-c99
7793 \begin_inset LatexCommand \index{-\/-std-sdcc99}
7794
7795 \end_inset 
7796
7797
7798 \series default 
7799  Follow the C99 standard and disable SDCC features that conflict with the
7800  standard (incomplete support).
7801 \layout Subsection
7802
7803 Intermediate Dump Options
7804 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
7805
7806 \end_inset 
7807
7808
7809 \begin_inset LatexCommand \index{Options intermediate dump}
7810
7811 \end_inset 
7812
7813
7814 \begin_inset LatexCommand \index{Intermediate dump options}
7815
7816 \end_inset 
7817
7818
7819 \layout Standard
7820
7821 The following options are provided for the purpose of retargetting and debugging
7822  the compiler.
7823  They provide a means to dump the intermediate code (iCode
7824 \begin_inset LatexCommand \index{iCode}
7825
7826 \end_inset 
7827
7828 ) generated by the compiler in human readable form at various stages of
7829  the compilation process.
7830  More on iCodes see chapter 
7831 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
7832
7833 \end_inset 
7834
7835  
7836 \begin_inset Quotes srd
7837 \end_inset 
7838
7839 The anatomy of the compiler
7840 \begin_inset Quotes srd
7841 \end_inset 
7842
7843 .
7844 \layout List
7845 \labelwidthstring 00.00.0000
7846
7847
7848 \series bold 
7849 -
7850 \begin_inset ERT
7851 status Collapsed
7852
7853 \layout Standard
7854
7855 \backslash 
7856 /
7857 \end_inset 
7858
7859 -dumpraw
7860 \begin_inset LatexCommand \index{-\/-dumpraw}
7861
7862 \end_inset 
7863
7864
7865 \series default 
7866  This option will cause the compiler to dump the intermediate code into
7867  a file of named 
7868 \emph on 
7869 <source filename>.dumpraw
7870 \emph default 
7871  just after the intermediate code has been generated for a function, i.e.
7872  before any optimizations are done.
7873  The basic blocks
7874 \begin_inset LatexCommand \index{Basic blocks}
7875
7876 \end_inset 
7877
7878  at this stage ordered in the depth first number, so they may not be in
7879  sequence of execution.
7880 \layout List
7881 \labelwidthstring 00.00.0000
7882
7883
7884 \series bold 
7885 -
7886 \begin_inset ERT
7887 status Collapsed
7888
7889 \layout Standard
7890
7891 \backslash 
7892 /
7893 \end_inset 
7894
7895 -dumpgcse
7896 \begin_inset LatexCommand \index{-\/-dumpgcse}
7897
7898 \end_inset 
7899
7900
7901 \series default 
7902  Will create a dump of iCode's, after global subexpression elimination
7903 \begin_inset LatexCommand \index{Global subexpression elimination}
7904
7905 \end_inset 
7906
7907 , into a file named 
7908 \emph on 
7909 <source filename>.dumpgcse.
7910 \layout List
7911 \labelwidthstring 00.00.0000
7912
7913
7914 \series bold 
7915 -
7916 \begin_inset ERT
7917 status Collapsed
7918
7919 \layout Standard
7920
7921 \backslash 
7922 /
7923 \end_inset 
7924
7925 -dumpdeadcode
7926 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
7927
7928 \end_inset 
7929
7930
7931 \series default 
7932  Will create a dump of iCode's, after deadcode elimination
7933 \begin_inset LatexCommand \index{Dead-code elimination}
7934
7935 \end_inset 
7936
7937 , into a file named 
7938 \emph on 
7939 <source filename>.dumpdeadcode.
7940 \layout List
7941 \labelwidthstring 00.00.0000
7942
7943
7944 \series bold 
7945 -
7946 \begin_inset ERT
7947 status Collapsed
7948
7949 \layout Standard
7950
7951 \backslash 
7952 /
7953 \end_inset 
7954
7955 -dumploop
7956 \begin_inset LatexCommand \index{-\/-dumploop}
7957
7958 \end_inset 
7959
7960
7961 \series default 
7962 \size large 
7963  
7964 \size default 
7965 Will create a dump of iCode's, after loop optimizations
7966 \begin_inset LatexCommand \index{Loop optimization}
7967
7968 \end_inset 
7969
7970 , into a file named 
7971 \emph on 
7972 <source filename>.dumploop.
7973 \layout List
7974 \labelwidthstring 00.00.0000
7975
7976
7977 \series bold 
7978 -
7979 \begin_inset ERT
7980 status Collapsed
7981
7982 \layout Standard
7983
7984 \backslash 
7985 /
7986 \end_inset 
7987
7988 -dumprange
7989 \begin_inset LatexCommand \index{-\/-dumprange}
7990
7991 \end_inset 
7992
7993
7994 \series default 
7995 \size large 
7996  
7997 \size default 
7998 Will create a dump of iCode's, after live range analysis
7999 \begin_inset LatexCommand \index{Live range analysis}
8000
8001 \end_inset 
8002
8003 , into a file named 
8004 \emph on 
8005 <source filename>.dumprange.
8006 \layout List
8007 \labelwidthstring 00.00.0000
8008
8009
8010 \series bold 
8011 -
8012 \begin_inset ERT
8013 status Collapsed
8014
8015 \layout Standard
8016
8017 \backslash 
8018 /
8019 \end_inset 
8020
8021 -dumlrange
8022 \begin_inset LatexCommand \index{-\/-dumlrange}
8023
8024 \end_inset 
8025
8026
8027 \series default 
8028  Will dump the life ranges
8029 \begin_inset LatexCommand \index{Live range analysis}
8030
8031 \end_inset 
8032
8033  for all symbols.
8034 \layout List
8035 \labelwidthstring 00.00.0000
8036
8037
8038 \series bold 
8039 -
8040 \begin_inset ERT
8041 status Collapsed
8042
8043 \layout Standard
8044
8045 \backslash 
8046 /
8047 \end_inset 
8048
8049 -dumpregassign
8050 \begin_inset LatexCommand \index{-\/-dumpregassign}
8051
8052 \end_inset 
8053
8054
8055 \bar under 
8056  
8057 \series default 
8058 \bar default 
8059 Will create a dump of iCode's, after register assignment
8060 \begin_inset LatexCommand \index{Register assignment}
8061
8062 \end_inset 
8063
8064 , into a file named 
8065 \emph on 
8066 <source filename>.dumprassgn.
8067 \layout List
8068 \labelwidthstring 00.00.0000
8069
8070
8071 \series bold 
8072 -
8073 \begin_inset ERT
8074 status Collapsed
8075
8076 \layout Standard
8077
8078 \backslash 
8079 /
8080 \end_inset 
8081
8082 -dumplrange
8083 \begin_inset LatexCommand \index{-\/-dumplrange}
8084
8085 \end_inset 
8086
8087
8088 \series default 
8089  Will create a dump of the live ranges of iTemp's
8090 \layout List
8091 \labelwidthstring 00.00.0000
8092
8093
8094 \series bold 
8095 -
8096 \begin_inset ERT
8097 status Collapsed
8098
8099 \layout Standard
8100
8101 \backslash 
8102 /
8103 \end_inset 
8104
8105 -dumpall
8106 \begin_inset LatexCommand \index{-\/-dumpall}
8107
8108 \end_inset 
8109
8110
8111 \size large 
8112 \bar under 
8113  
8114 \series default 
8115 \size default 
8116 \bar default 
8117 Will cause all the above mentioned dumps to be created.
8118 \layout Subsection
8119
8120 Redirecting output on Windows Shells
8121 \layout Standard
8122
8123 By default SDCC writes it's error messages to 
8124 \begin_inset Quotes sld
8125 \end_inset 
8126
8127 standard error
8128 \begin_inset Quotes srd
8129 \end_inset 
8130
8131 .
8132  To force all messages to 
8133 \begin_inset Quotes sld
8134 \end_inset 
8135
8136 standard output
8137 \begin_inset Quotes srd
8138 \end_inset 
8139
8140  use 
8141 \series bold 
8142 -
8143 \series default 
8144 \emph on 
8145
8146 \begin_inset ERT
8147 status Collapsed
8148
8149 \layout Standard
8150
8151 \backslash 
8152 /
8153 \end_inset 
8154
8155
8156 \series bold 
8157 \emph default 
8158 -
8159 \series default 
8160 use-stdout
8161 \begin_inset LatexCommand \index{-\/-use-stdout}
8162
8163 \end_inset 
8164
8165 .
8166  Additionally, if you happen to have visual studio installed in your windows
8167  machine, you can use it to compile your sources using a custom build and
8168  the SDCC -
8169 \emph on 
8170
8171 \begin_inset ERT
8172 status Collapsed
8173
8174 \layout Standard
8175
8176 \backslash 
8177 /
8178 \end_inset 
8179
8180
8181 \emph default 
8182 -vc
8183 \begin_inset LatexCommand \index{-\/-vc}
8184
8185 \end_inset 
8186
8187  option.
8188  Something like this should work:
8189 \newline 
8190
8191 \newline 
8192
8193 \series bold 
8194 c:
8195 \backslash 
8196 sdcc
8197 \backslash 
8198 bin
8199 \backslash 
8200 sdcc.exe -
8201 \series default 
8202 \emph on 
8203
8204 \begin_inset ERT
8205 status Collapsed
8206
8207 \layout Standard
8208
8209 \backslash 
8210 /
8211 \end_inset 
8212
8213
8214 \series bold 
8215 \emph default 
8216 -vc -
8217 \series default 
8218 \emph on 
8219
8220 \begin_inset ERT
8221 status Collapsed
8222
8223 \layout Standard
8224
8225 \backslash 
8226 /
8227 \end_inset 
8228
8229
8230 \series bold 
8231 \emph default 
8232 -model-large -c $(InputPath)
8233 \layout Section
8234
8235 Environment variables
8236 \begin_inset LatexCommand \index{Environment variables}
8237
8238 \end_inset 
8239
8240
8241 \layout Standard
8242
8243 SDCC recognizes the following environment variables:
8244 \layout List
8245 \labelwidthstring 00.00.0000
8246
8247
8248 \series bold 
8249 SDCC_LEAVE_SIGNALS
8250 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
8251
8252 \end_inset 
8253
8254
8255 \series default 
8256  SDCC installs a signal handler
8257 \begin_inset LatexCommand \index{signal handler}
8258
8259 \end_inset 
8260
8261  to be able to delete temporary files after an user break (^C) or an exception.
8262  If this environment variable is set, SDCC won't install the signal handler
8263  in order to be able to debug SDCC.
8264 \layout List
8265 \labelwidthstring 00.00.0000
8266
8267
8268 \series bold 
8269 TMP,\SpecialChar ~
8270 TEMP,\SpecialChar ~
8271 TMPDIR
8272 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
8273
8274 \end_inset 
8275
8276
8277 \series default 
8278  Path, where temporary files will be created.
8279  The order of the variables is the search order.
8280  In a standard *nix environment these variables are not set, and there's
8281  no need to set them.
8282  On Windows it's recommended to set one of them.
8283 \layout List
8284 \labelwidthstring 00.00.0000
8285
8286
8287 \series bold 
8288 SDCC_HOME
8289 \begin_inset LatexCommand \index{SDCC\_HOME}
8290
8291 \end_inset 
8292
8293
8294 \series default 
8295  Path, see section 
8296 \begin_inset LatexCommand \ref{sub:Install-paths}
8297
8298 \end_inset 
8299
8300 \SpecialChar ~
8301
8302 \begin_inset Quotes sld
8303 \end_inset 
8304
8305  Install Paths
8306 \begin_inset Quotes srd
8307 \end_inset 
8308
8309 .
8310 \layout List
8311 \labelwidthstring 00.00.0000
8312
8313
8314 \series bold 
8315 SDCC_INCLUDE
8316 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
8317
8318 \end_inset 
8319
8320
8321 \series default 
8322  Path, see section 
8323 \begin_inset LatexCommand \ref{sub:Search-Paths}
8324
8325 \end_inset 
8326
8327 \SpecialChar ~
8328
8329 \begin_inset Quotes sld
8330 \end_inset 
8331
8332 Search Paths
8333 \begin_inset Quotes srd
8334 \end_inset 
8335
8336 .
8337 \layout List
8338 \labelwidthstring 00.00.0000
8339
8340
8341 \series bold 
8342 SDCC_LIB
8343 \begin_inset LatexCommand \index{SDCC\_LIB}
8344
8345 \end_inset 
8346
8347
8348 \series default 
8349  Path, see section 
8350 \begin_inset LatexCommand \ref{sub:Search-Paths}
8351
8352 \end_inset 
8353
8354 \SpecialChar ~
8355
8356 \begin_inset Quotes sld
8357 \end_inset 
8358
8359 Search Paths
8360 \begin_inset Quotes srd
8361 \end_inset 
8362
8363 ..
8364 \layout Standard
8365
8366 There are some more environment variables recognized by SDCC, but these
8367  are solely used for debugging purposes.
8368  They can change or disappear very quickly, and will never be documented.
8369 \layout Section
8370
8371 Storage Class Language Extensions
8372 \layout Subsection
8373
8374 MCS51/DS390 Storage Class
8375 \begin_inset LatexCommand \index{Storage class}
8376
8377 \end_inset 
8378
8379  Language Extensions
8380 \layout Standard
8381
8382 In addition to the ANSI storage classes SDCC allows the following MCS51
8383  specific storage classes:
8384 \layout Subsubsection
8385
8386 data
8387 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
8388
8389 \end_inset 
8390
8391
8392 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
8393
8394 \end_inset 
8395
8396  / near
8397 \begin_inset LatexCommand \index{near (storage class)}
8398
8399 \end_inset 
8400
8401
8402 \begin_inset LatexCommand \index{\_\_near (storage class)}
8403
8404 \end_inset 
8405
8406
8407 \layout Standard
8408
8409 This is the 
8410 \series bold 
8411 default
8412 \series default 
8413  storage class for the Small Memory model (
8414 \emph on 
8415 data
8416 \emph default 
8417  and 
8418 \emph on 
8419 near
8420 \emph default 
8421  can be used synonymously).
8422  Variables declared with this storage class will be allocated in the directly
8423  addressable portion of the internal RAM of a 8051, e.g.:
8424 \layout Verse
8425
8426
8427 \family typewriter 
8428 data unsigned char test_data;
8429 \layout Standard
8430
8431 Writing 0x01 to this variable generates the assembly code:
8432 \layout Verse
8433
8434
8435 \family typewriter 
8436 75*00 01\SpecialChar ~
8437 \SpecialChar ~
8438 \SpecialChar ~
8439 mov\SpecialChar ~
8440 \SpecialChar ~
8441 _test_data,#0x01 
8442 \layout Subsubsection
8443
8444 xdata
8445 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
8446
8447 \end_inset 
8448
8449
8450 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
8451
8452 \end_inset 
8453
8454  / far
8455 \begin_inset LatexCommand \index{far (storage class)}
8456
8457 \end_inset 
8458
8459
8460 \begin_inset LatexCommand \index{\_\_far (storage class)}
8461
8462 \end_inset 
8463
8464
8465 \layout Standard
8466
8467 Variables declared with this storage class will be placed in the external
8468  RAM.
8469  This is the 
8470 \series bold 
8471 default
8472 \series default 
8473  storage class for the Large Memory model, e.g.:
8474 \layout Verse
8475
8476
8477 \family typewriter 
8478 xdata unsigned char test_xdata;
8479 \layout Standard
8480
8481 Writing 0x01 to this variable generates the assembly code:
8482 \layout Verse
8483
8484
8485 \family typewriter 
8486 90s00r00\SpecialChar ~
8487 \SpecialChar ~
8488 \SpecialChar ~
8489 mov\SpecialChar ~
8490 \SpecialChar ~
8491 dptr,#_test_xdata 
8492 \newline 
8493 74\SpecialChar ~
8494 01\SpecialChar ~
8495 \SpecialChar ~
8496 \SpecialChar ~
8497 \SpecialChar ~
8498 \SpecialChar ~
8499 \SpecialChar ~
8500 mov\SpecialChar ~
8501 \SpecialChar ~
8502 a,#0x01 
8503 \newline 
8504 F0\SpecialChar ~
8505 \SpecialChar ~
8506 \SpecialChar ~
8507 \SpecialChar ~
8508 \SpecialChar ~
8509 \SpecialChar ~
8510 \SpecialChar ~
8511 \SpecialChar ~
8512 \SpecialChar ~
8513 movx\SpecialChar ~
8514 @dptr,a 
8515 \layout Subsubsection
8516
8517 idata
8518 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
8519
8520 \end_inset 
8521
8522
8523 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
8524
8525 \end_inset 
8526
8527
8528 \layout Standard
8529
8530 Variables declared with this storage class will be allocated into the indirectly
8531  addressable portion of the internal ram of a 8051, e.g.:
8532 \layout Verse
8533
8534
8535 \family typewriter 
8536 idata unsigned char test_idata;
8537 \layout Standard
8538
8539 Writing 0x01 to this variable generates the assembly code:
8540 \layout Verse
8541
8542
8543 \family typewriter 
8544 78r00\SpecialChar ~
8545 \SpecialChar ~
8546 \SpecialChar ~
8547 \SpecialChar ~
8548 \SpecialChar ~
8549 \SpecialChar ~
8550 \SpecialChar ~
8551 mov\SpecialChar ~
8552 \SpecialChar ~
8553 r0,#_test_idata
8554 \newline 
8555 76\SpecialChar ~
8556 01\SpecialChar ~
8557 \SpecialChar ~
8558 \SpecialChar ~
8559 \SpecialChar ~
8560 \SpecialChar ~
8561 \SpecialChar ~
8562 \SpecialChar ~
8563 mov\SpecialChar ~
8564 \SpecialChar ~
8565 @r0,#0x01
8566 \layout Standard
8567
8568 Please note, the first 128 byte of idata physically access the same RAM
8569  as the data memory.
8570  The original 8051 had 128 byte idata memory, nowadays most devices have
8571  256 byte idata memory.
8572  The stack
8573 \begin_inset LatexCommand \index{stack}
8574
8575 \end_inset 
8576
8577  is located in idata memory.
8578 \layout Subsubsection
8579
8580 pdata
8581 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
8582
8583 \end_inset 
8584
8585
8586 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
8587
8588 \end_inset 
8589
8590
8591 \layout Standard
8592
8593 Paged xdata access is just as straightforward as using the other addressing
8594  modes of a 8051.
8595  It is typically located at the start of xdata and has a maximum size of
8596  256 bytes.
8597  The following example writes 0x01 to the address pointed to.
8598  Please note, pdata access physically accesses xdata memory.
8599  The high byte of the address is determined by port P2 
8600 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
8601
8602 \end_inset 
8603
8604 (or in case of some 8051 variants by a separate Special Function Register,
8605  see section 
8606 \begin_inset LatexCommand \ref{sub:MCS51-variants}
8607
8608 \end_inset 
8609
8610 ).
8611 \layout Verse
8612
8613
8614 \family typewriter 
8615 pdata unsigned char *test_pdata_ptr;
8616 \newline 
8617
8618 \newline 
8619 void main() 
8620 \newline 
8621
8622 \newline 
8623 \SpecialChar ~
8624 \SpecialChar ~
8625 \SpecialChar ~
8626 \SpecialChar ~
8627 test_pdata_ptr = (pdata *)0xfe; 
8628 \newline 
8629 \SpecialChar ~
8630 \SpecialChar ~
8631 \SpecialChar ~
8632 \SpecialChar ~
8633 *test_pdata_ptr = 1; 
8634 \newline 
8635
8636 \layout Standard
8637
8638 Generates the assembly code:
8639 \layout Verse
8640
8641
8642 \family typewriter 
8643 75*01 FE\SpecialChar ~
8644 \SpecialChar ~
8645 \SpecialChar ~
8646 mov\SpecialChar ~
8647  _test_pdata_ptr,#0xFE
8648 \newline 
8649 78 FE\SpecialChar ~
8650 \SpecialChar ~
8651 \SpecialChar ~
8652 \SpecialChar ~
8653 \SpecialChar ~
8654 \SpecialChar ~
8655 mov\SpecialChar ~
8656  r0,#0xFE 
8657 \newline 
8658 74 01\SpecialChar ~
8659 \SpecialChar ~
8660 \SpecialChar ~
8661 \SpecialChar ~
8662 \SpecialChar ~
8663 \SpecialChar ~
8664 mov\SpecialChar ~
8665  a,#0x01
8666 \newline 
8667 F2\SpecialChar ~
8668 \SpecialChar ~
8669 \SpecialChar ~
8670 \SpecialChar ~
8671 \SpecialChar ~
8672 \SpecialChar ~
8673 \SpecialChar ~
8674 \SpecialChar ~
8675 \SpecialChar ~
8676 movx @r0,a 
8677 \layout Standard
8678
8679 If the -
8680 \begin_inset ERT
8681 status Collapsed
8682
8683 \layout Standard
8684
8685 \backslash 
8686 /
8687 \end_inset 
8688
8689 -xstack
8690 \begin_inset LatexCommand \index{-\/-xstack}
8691
8692 \end_inset 
8693
8694  option is used the pdata memory area is followed by the xstack memory area
8695  and the sum of their sizes is limited to 256 bytes.
8696 \layout Subsubsection
8697
8698 code
8699 \begin_inset LatexCommand \index{code}
8700
8701 \end_inset 
8702
8703
8704 \begin_inset LatexCommand \index{\_\_code}
8705
8706 \end_inset 
8707
8708
8709 \layout Standard
8710
8711 'Variables' declared with this storage class will be placed in the code
8712  memory:
8713 \layout Verse
8714
8715
8716 \family typewriter 
8717 code unsigned char test_code;
8718 \layout Standard
8719
8720 Read access to this variable generates the assembly code:
8721 \layout Verse
8722
8723
8724 \family typewriter 
8725 90s00r6F\SpecialChar ~
8726 \SpecialChar ~
8727 \SpecialChar ~
8728 mov dptr,#_test_code
8729 \newline 
8730 E4\SpecialChar ~
8731 \SpecialChar ~
8732 \SpecialChar ~
8733 \SpecialChar ~
8734 \SpecialChar ~
8735 \SpecialChar ~
8736 \SpecialChar ~
8737 \SpecialChar ~
8738 \SpecialChar ~
8739 clr a
8740 \newline 
8741 93\SpecialChar ~
8742 \SpecialChar ~
8743 \SpecialChar ~
8744 \SpecialChar ~
8745 \SpecialChar ~
8746 \SpecialChar ~
8747 \SpecialChar ~
8748 \SpecialChar ~
8749 \SpecialChar ~
8750 movc a,@a+dptr 
8751 \layout Standard
8752
8753
8754 \family typewriter 
8755 char
8756 \family default 
8757  indexed arrays of characters in code memory can be accessed efficiently:
8758 \layout Verse
8759
8760
8761 \family typewriter 
8762 code char test_array[] = {'c','h','e','a','p'}; 
8763 \layout Standard
8764
8765 Read access to this array using an 8-bit unsigned index generates the assembly
8766  code:
8767 \layout Verse
8768
8769
8770 \family typewriter 
8771 E5*00\SpecialChar ~
8772 \SpecialChar ~
8773 \SpecialChar ~
8774 \SpecialChar ~
8775 \SpecialChar ~
8776 \SpecialChar ~
8777 mov a,_index 
8778 \layout Verse
8779
8780
8781 \family typewriter 
8782 90s00r41\SpecialChar ~
8783 \SpecialChar ~
8784 \SpecialChar ~
8785 mov dptr,#_test_array
8786 \layout Verse
8787
8788
8789 \family typewriter 
8790 93\SpecialChar ~
8791 \SpecialChar ~
8792 \SpecialChar ~
8793 \SpecialChar ~
8794 \SpecialChar ~
8795 \SpecialChar ~
8796 \SpecialChar ~
8797 \SpecialChar ~
8798 \SpecialChar ~
8799 movc a,@a+dptr 
8800 \layout Subsubsection
8801
8802 bit
8803 \begin_inset LatexCommand \index{bit}
8804
8805 \end_inset 
8806
8807
8808 \begin_inset LatexCommand \index{\_\_bit}
8809
8810 \end_inset 
8811
8812
8813 \layout Standard
8814
8815 This is a data-type and a storage class specifier.
8816  When a variable is declared as a bit, it is allocated into the bit addressable
8817  memory of 8051, e.g.:
8818 \layout Verse
8819
8820
8821 \family typewriter 
8822 bit test_bit;
8823 \layout Standard
8824
8825 Writing 1 to this variable generates the assembly code:
8826 \layout Verse
8827
8828
8829 \family typewriter 
8830 D2*00\SpecialChar ~
8831 \SpecialChar ~
8832 \SpecialChar ~
8833 \SpecialChar ~
8834 \SpecialChar ~
8835 \SpecialChar ~
8836 \SpecialChar ~
8837 setb\SpecialChar ~
8838 _test_bit
8839 \layout Standard
8840
8841 The bit addressable memory consists of 128 bits which are located from 0x20
8842  to 0x2f in data memory.
8843  
8844 \newline 
8845 Apart from this 8051 specific storage class most architectures support ANSI-C
8846  bitfields
8847 \begin_inset LatexCommand \index{bitfields}
8848
8849 \end_inset 
8850
8851
8852 \begin_inset Foot
8853 collapsed false
8854
8855 \layout Standard
8856
8857 Not really meant as examples, but nevertheless showing what bitfields are
8858  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
8859 \end_inset 
8860
8861 .
8862  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
8863  signed modifier are implemented as unsigned.
8864 \layout Subsubsection
8865
8866 sfr
8867 \begin_inset LatexCommand \index{sfr}
8868
8869 \end_inset 
8870
8871
8872 \begin_inset LatexCommand \index{\_\_sfr}
8873
8874 \end_inset 
8875
8876  / sbit
8877 \begin_inset LatexCommand \index{\_\_sbit}
8878
8879 \end_inset 
8880
8881
8882 \layout Standard
8883
8884 Like the bit keyword, 
8885 \emph on 
8886 sfr / sbit 
8887 \emph default 
8888 signifies both a data-type and storage class, they are used to describe
8889  the 
8890 \emph on 
8891 s
8892 \emph default 
8893 pecial 
8894 \emph on 
8895 f
8896 \emph default 
8897 unction 
8898 \emph on 
8899 r
8900 \emph default 
8901 egisters and 
8902 \emph on 
8903 s
8904 \emph default 
8905 pecial 
8906 \emph on 
8907 bit
8908 \emph default 
8909  variables of a 8051, eg:
8910 \layout Verse
8911
8912
8913 \family typewriter 
8914 sfr at
8915 \begin_inset LatexCommand \index{at}
8916
8917 \end_inset 
8918
8919
8920 \begin_inset LatexCommand \index{\_\_at}
8921
8922 \end_inset 
8923
8924  0x80 P0;\SpecialChar ~
8925  /* special function register P0 at location 0x80 */
8926 \newline 
8927 sbit at 0xd7 CY; /* CY (Carry Flag
8928 \begin_inset LatexCommand \index{Flags}
8929
8930 \end_inset 
8931
8932
8933 \begin_inset LatexCommand \index{Carry flag}
8934
8935 \end_inset 
8936
8937 ) */
8938 \layout Standard
8939
8940 Special function registers which are located on an address dividable by
8941  8 are bit-addressable, an
8942 \emph on 
8943  sbit
8944 \emph default 
8945  addresses a specific bit within these sfr.
8946 \layout Subsubsection
8947
8948 Pointers
8949 \begin_inset LatexCommand \index{Pointer}
8950
8951 \end_inset 
8952
8953  to MCS51/DS390 specific memory spaces
8954 \layout Standard
8955
8956 SDCC allows (via language extensions) pointers to explicitly point to any
8957  of the memory spaces
8958 \begin_inset LatexCommand \index{Memory model}
8959
8960 \end_inset 
8961
8962  of the 8051.
8963  In addition to the explicit pointers, the compiler uses (by default) generic
8964  pointers which can be used to point to any of the memory spaces.
8965 \newline 
8966
8967 \newline 
8968 Pointer declaration examples:
8969 \layout Verse
8970
8971
8972 \family typewriter 
8973 /* pointer physically in internal ram pointing to object in external ram
8974  */ 
8975 \newline 
8976 xdata unsigned char * data p;
8977 \newline 
8978
8979 \newline 
8980 /* pointer physically in external ram pointing to object in internal ram
8981  */ 
8982 \newline 
8983 data unsigned char * xdata p;
8984 \newline 
8985
8986 \newline 
8987 /* pointer physically in code rom pointing to data in xdata space */ 
8988 \newline 
8989 xdata unsigned char * code p;
8990 \newline 
8991
8992 \newline 
8993 /* pointer physically in code space pointing to data in code space */ 
8994 \newline 
8995 code unsigned char * code p;
8996 \newline 
8997
8998 \newline 
8999 /* the following is a generic pointer physically located in xdata space
9000  */
9001 \newline 
9002 char * xdata p;
9003 \layout Standard
9004
9005 Well you get the idea.
9006  
9007 \newline 
9008
9009 \newline 
9010 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
9011 \emph on 
9012 generic
9013 \emph default 
9014  pointers.
9015  
9016 \size small 
9017
9018 \newline 
9019
9020 \newline 
9021
9022 \size default 
9023 The highest order byte of the 
9024 \emph on 
9025 generic
9026 \emph default 
9027  pointers contains the data space information.
9028  Assembler support routines are called whenever data is stored or retrieved
9029  using 
9030 \emph on 
9031 generic
9032 \emph default 
9033  pointers.
9034  These are useful for developing reusable library
9035 \begin_inset LatexCommand \index{Libraries}
9036
9037 \end_inset 
9038
9039  routines.
9040  Explicitly specifying the pointer type will generate the most efficient
9041  code.
9042 \layout Subsubsection
9043
9044 Notes on MCS51 memory
9045 \begin_inset LatexCommand \index{MCS51 memory}
9046
9047 \end_inset 
9048
9049  layout
9050 \layout Standard
9051
9052 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
9053  RAM memory which is structured as follows:
9054 \newline 
9055
9056 \newline 
9057 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
9058  
9059 \newline 
9060 - Bytes 20-2F - 16 bytes to hold 128 bit
9061 \begin_inset LatexCommand \index{bit}
9062
9063 \end_inset 
9064
9065  variables and, 
9066 \newline 
9067 - Bytes 30-7F - 80 bytes for general purpose use.
9068 \newline 
9069
9070 \layout Standard
9071
9072 Additionally some members of the MCS51 family may have up to 128 bytes of
9073  additional, indirectly addressable, internal RAM memory (
9074 \emph on 
9075 idata
9076 \emph default 
9077
9078 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
9079
9080 \end_inset 
9081
9082
9083 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
9084
9085 \end_inset 
9086
9087 ).
9088  Furthermore, some chips may have some built in external memory (
9089 \emph on 
9090 xdata
9091 \emph default 
9092
9093 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9094
9095 \end_inset 
9096
9097
9098 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
9099
9100 \end_inset 
9101
9102 ) which should not be confused with the internal, directly addressable RAM
9103  memory (
9104 \emph on 
9105 data
9106 \emph default 
9107
9108 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
9109
9110 \end_inset 
9111
9112
9113 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
9114
9115 \end_inset 
9116
9117 ).
9118  Sometimes this built in 
9119 \emph on 
9120 xdata
9121 \emph default 
9122  memory has to be activated before using it (you can probably find this
9123  information on the datasheet of the microcontroller your are using, see
9124  also section 
9125 \begin_inset LatexCommand \ref{sub:Startup-Code}
9126
9127 \end_inset 
9128
9129 \SpecialChar ~
9130 Startup-Code).
9131 \layout Standard
9132
9133 Normally SDCC will only use the first bank
9134 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
9135
9136 \end_inset 
9137
9138  of registers (register bank 0), but it is possible to specify that other
9139  banks of registers (keyword 
9140 \emph on 
9141 using
9142 \emph default 
9143  
9144 \emph on 
9145
9146 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
9147
9148 \end_inset 
9149
9150
9151 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
9152
9153 \end_inset 
9154
9155
9156 \emph default 
9157 ) should be used in interrupt
9158 \begin_inset LatexCommand \index{interrupt}
9159
9160 \end_inset 
9161
9162
9163 \begin_inset LatexCommand \index{\_\_interrupt}
9164
9165 \end_inset 
9166
9167  routines.
9168  By default, the compiler will place the stack after the last byte of allocated
9169  memory for variables.
9170  For example, if the first 2 banks of registers are used, and only four
9171  bytes are used for 
9172 \emph on 
9173 data
9174 \emph default 
9175  variables, it will position the base of the internal stack at address 20
9176  (0x14).
9177  This implies that as the stack
9178 \begin_inset LatexCommand \index{stack}
9179
9180 \end_inset 
9181
9182  grows, it will use up the remaining register banks, and the 16 bytes used
9183  by the 128 bit variables, and 80 bytes for general purpose use.
9184  If any bit variables are used, the data variables will be placed in unused
9185  register banks and after the byte holding the last bit variable.
9186  For example, if register banks 0 and 1 are used, and there are 9 bit variables
9187  (two bytes used), 
9188 \emph on 
9189 data
9190 \emph default 
9191  variables will be placed starting from address 0x10 to 0x20 and continue
9192  at address 0x22.
9193  You can also use -
9194 \begin_inset ERT
9195 status Collapsed
9196
9197 \layout Standard
9198
9199 \backslash 
9200 /
9201 \end_inset 
9202
9203 -data-loc
9204 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
9205
9206 \end_inset 
9207
9208  to specify the start address of the 
9209 \emph on 
9210 data
9211 \emph default 
9212  and -
9213 \begin_inset ERT
9214 status Collapsed
9215
9216 \layout Standard
9217
9218 \backslash 
9219 /
9220 \end_inset 
9221
9222 -iram-size
9223 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
9224
9225 \end_inset 
9226
9227  to specify the size of the total internal RAM (
9228 \emph on 
9229 data
9230 \emph default 
9231 +
9232 \emph on 
9233 idata
9234 \emph default 
9235 ).
9236  
9237 \layout Standard
9238
9239 By default the 8051 linker will place the stack after the last byte of (i)data
9240  variables.
9241  Option -
9242 \begin_inset ERT
9243 status Collapsed
9244
9245 \layout Standard
9246
9247 \backslash 
9248 /
9249 \end_inset 
9250
9251 -stack-loc
9252 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
9253
9254 \end_inset 
9255
9256  allows you to specify the start of the stack, i.e.
9257  you could start it after any data in the general purpose area.
9258  If your microcontroller has additional indirectly addressable internal
9259  RAM (
9260 \emph on 
9261 idata
9262 \emph default 
9263 ) you can place the stack on it.
9264  You may also need to use -
9265 \begin_inset ERT
9266 status Collapsed
9267
9268 \layout Standard
9269
9270 \backslash 
9271 /
9272 \end_inset 
9273
9274 -xdata-loc
9275 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
9276
9277 \end_inset 
9278
9279  to set the start address of the external RAM (
9280 \emph on 
9281 xdata
9282 \emph default 
9283 ) and -
9284 \begin_inset ERT
9285 status Collapsed
9286
9287 \layout Standard
9288
9289 \backslash 
9290 /
9291 \end_inset 
9292
9293 -xram-size
9294 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
9295
9296 \end_inset 
9297
9298  to specify its size.
9299  Same goes for the code memory, using -
9300 \begin_inset ERT
9301 status Collapsed
9302
9303 \layout Standard
9304
9305 \backslash 
9306 /
9307 \end_inset 
9308
9309 -code-loc
9310 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
9311
9312 \end_inset 
9313
9314  and -
9315 \begin_inset ERT
9316 status Collapsed
9317
9318 \layout Standard
9319
9320 \backslash 
9321 /
9322 \end_inset 
9323
9324 -code-size
9325 \begin_inset LatexCommand \index{-\/-code-size <Value>}
9326
9327 \end_inset 
9328
9329 .
9330  If in doubt, don't specify any options and see if the resulting memory
9331  layout is appropriate, then you can adjust it.
9332 \layout Standard
9333
9334 The linker generates two files with memory allocation information.
9335  The first, with extension .map
9336 \begin_inset LatexCommand \index{<file>.map}
9337
9338 \end_inset 
9339
9340  shows all the variables and segments.
9341  The second with extension .mem
9342 \begin_inset LatexCommand \index{<file>.mem}
9343
9344 \end_inset 
9345
9346  shows the final memory layout.
9347  The linker will complain either if memory segments overlap, there is not
9348  enough memory, or there is not enough space for stack.
9349  If you get any linking warnings and/or errors related to stack or segments
9350  allocation, take a look at either the .map or .mem files to find out what
9351  the problem is.
9352  The .mem file may even suggest a solution to the problem.
9353 \layout Subsection
9354
9355 Z80/Z180 Storage Class
9356 \begin_inset LatexCommand \index{Storage class}
9357
9358 \end_inset 
9359
9360  Language Extensions
9361 \layout Subsubsection
9362
9363 sfr
9364 \begin_inset LatexCommand \index{sfr}
9365
9366 \end_inset 
9367
9368
9369 \begin_inset LatexCommand \index{\_\_sfr}
9370
9371 \end_inset 
9372
9373  (in/out to 8-bit addresses)
9374 \layout Standard
9375
9376 The Z80
9377 \begin_inset LatexCommand \index{Z80}
9378
9379 \end_inset 
9380
9381  family has separate address spaces for memory and 
9382 \emph on 
9383 i
9384 \emph default 
9385 nput/
9386 \emph on 
9387 o
9388 \emph default 
9389 utput memory.
9390  I/O memory
9391 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
9392
9393 \end_inset 
9394
9395  is accessed with special instructions, e.g.:
9396 \layout Verse
9397
9398
9399 \family typewriter 
9400 sfr at 0x78 IoPort;\SpecialChar ~
9401 \SpecialChar ~
9402 /* define a var in I/O space at 78h called IoPort */
9403  
9404 \layout Standard
9405
9406 Writing 0x01 to this variable generates the assembly code:
9407 \layout Verse
9408
9409
9410 \family typewriter 
9411 3E 01\SpecialChar ~
9412 \SpecialChar ~
9413 \SpecialChar ~
9414 \SpecialChar ~
9415 \SpecialChar ~
9416 \SpecialChar ~
9417 ld a,#0x01
9418 \newline 
9419 D3 78\SpecialChar ~
9420 \SpecialChar ~
9421 \SpecialChar ~
9422 \SpecialChar ~
9423 \SpecialChar ~
9424 \SpecialChar ~
9425 out (_IoPort),a 
9426 \layout Subsubsection
9427
9428 banked sfr
9429 \begin_inset LatexCommand \index{sfr}
9430
9431 \end_inset 
9432
9433
9434 \begin_inset LatexCommand \index{\_\_sfr}
9435
9436 \end_inset 
9437
9438  (in/out to 16-bit addresses)
9439 \layout Standard
9440
9441 The keyword 
9442 \emph on 
9443 banked
9444 \emph default 
9445  is used to support 16 bit addresses in I/O memory e.g.:
9446 \layout Verse
9447
9448
9449 \family typewriter 
9450 sfr banked at
9451 \begin_inset LatexCommand \index{at}
9452
9453 \end_inset 
9454
9455
9456 \begin_inset LatexCommand \index{\_\_at}
9457
9458 \end_inset 
9459
9460  0x123 IoPort; 
9461 \layout Standard
9462
9463 Writing 0x01 to this variable generates the assembly code:
9464 \layout Verse
9465
9466
9467 \family typewriter 
9468 01 23 01\SpecialChar ~
9469 \SpecialChar ~
9470 \SpecialChar ~
9471 ld bc,#_IoPort
9472 \newline 
9473 3E 01\SpecialChar ~
9474 \SpecialChar ~
9475 \SpecialChar ~
9476 \SpecialChar ~
9477 \SpecialChar ~
9478 \SpecialChar ~
9479 ld a,#0x01 
9480 \newline 
9481 ED 79\SpecialChar ~
9482 \SpecialChar ~
9483 \SpecialChar ~
9484 \SpecialChar ~
9485 \SpecialChar ~
9486 \SpecialChar ~
9487 out (c),a 
9488 \layout Subsubsection
9489
9490 sfr
9491 \begin_inset LatexCommand \index{sfr}
9492
9493 \end_inset 
9494
9495
9496 \begin_inset LatexCommand \index{\_\_sfr}
9497
9498 \end_inset 
9499
9500  (in0/out0 to 8 bit addresses on Z180
9501 \begin_inset LatexCommand \index{Z180}
9502
9503 \end_inset 
9504
9505 /HD64180
9506 \begin_inset LatexCommand \index{HD64180}
9507
9508 \end_inset 
9509
9510 )
9511 \layout Standard
9512
9513 The compiler option -
9514 \begin_inset ERT
9515 status Collapsed
9516
9517 \layout Standard
9518
9519 \backslash 
9520 /
9521 \end_inset 
9522
9523 -portmode=180 (80) and a compiler #pragma\SpecialChar ~
9524 portmode
9525 \begin_inset LatexCommand \index{\#pragma portmode}
9526
9527 \end_inset 
9528
9529 =z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
9530 ns 
9531 \family typewriter 
9532 in0/out0
9533 \family default 
9534  instead of 
9535 \family typewriter 
9536 in/out
9537 \family default 
9538 .
9539  If you include the file z180.h this will be set automatically.
9540 \layout Subsection
9541
9542 HC08 Storage Class
9543 \begin_inset LatexCommand \index{Storage class}
9544
9545 \end_inset 
9546
9547  Language Extensions
9548 \layout Subsubsection
9549
9550 data
9551 \begin_inset LatexCommand \index{data (hc08 storage class)}
9552
9553 \end_inset 
9554
9555
9556 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
9557
9558 \end_inset 
9559
9560  
9561 \layout Standard
9562
9563 The data storage class declares a variable that resides in the first 256
9564  bytes of memory (the direct page).
9565  The HC08 is most efficient at accessing variables (especially pointers)
9566  stored here.
9567 \layout Subsubsection
9568
9569 xdata
9570 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
9571
9572 \end_inset 
9573
9574
9575 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
9576
9577 \end_inset 
9578
9579  
9580 \layout Standard
9581
9582 The xdata storage class declares a variable that can reside anywhere in
9583  memory.
9584  This is the default if no storage class is specified.
9585  
9586 \layout Section
9587
9588 Absolute Addressing
9589 \begin_inset LatexCommand \index{Absolute addressing}
9590
9591 \end_inset 
9592
9593
9594 \layout Standard
9595
9596 Data items can be assigned an absolute address with the 
9597 \emph on 
9598 at
9599 \begin_inset LatexCommand \index{at}
9600
9601 \end_inset 
9602
9603
9604 \begin_inset LatexCommand \index{\_\_at}
9605
9606 \end_inset 
9607
9608  <address>
9609 \emph default 
9610  keyword, in addition to a storage class, e.g.:
9611 \layout Verse
9612
9613
9614 \family typewriter 
9615 xdata
9616 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9617
9618 \end_inset 
9619
9620
9621 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
9622
9623 \end_inset 
9624
9625  at
9626 \begin_inset LatexCommand \index{at}
9627
9628 \end_inset 
9629
9630
9631 \begin_inset LatexCommand \index{\_\_at}
9632
9633 \end_inset 
9634
9635  0x7ffe unsigned int chksum;
9636 \layout Standard
9637
9638 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
9639  of the external ram.
9640  The compiler does 
9641 \emph on 
9642 not
9643 \emph default 
9644  reserve any space for variables declared in this way (they are implemented
9645  with an equate in the assembler).
9646  Thus it is left to the programmer to make sure there are no overlaps with
9647  other variables that are declared without the absolute address.
9648  The assembler listing file (.lst
9649 \begin_inset LatexCommand \index{<file>.lst}
9650
9651 \end_inset 
9652
9653 ) and the linker output files (.rst
9654 \begin_inset LatexCommand \index{<file>.rst}
9655
9656 \end_inset 
9657
9658 ) and (.map
9659 \begin_inset LatexCommand \index{<file>.map}
9660
9661 \end_inset 
9662
9663 ) are good places to look for such overlaps.
9664  Variables with an absolute address are 
9665 \emph on 
9666 not
9667 \emph default 
9668  initialized
9669 \begin_inset LatexCommand \index{Variable initialization}
9670
9671 \end_inset 
9672
9673 .
9674 \layout Standard
9675
9676 In case of memory mapped I/O devices the keyword 
9677 \emph on 
9678 volatile
9679 \emph default 
9680  has to be used to tell the compiler that accesses might not be removed:
9681 \layout Verse
9682
9683
9684 \family typewriter 
9685 volatile
9686 \begin_inset LatexCommand \index{volatile}
9687
9688 \end_inset 
9689
9690  xdata
9691 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9692
9693 \end_inset 
9694
9695  at
9696 \begin_inset LatexCommand \index{at}
9697
9698 \end_inset 
9699
9700  0x8000 unsigned char PORTA_8255;
9701 \layout Standard
9702
9703 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
9704 r) array
9705 \family typewriter 
9706 \size footnotesize 
9707
9708 \begin_inset LatexCommand \index{Aligned array}
9709
9710 \end_inset 
9711
9712
9713 \family default 
9714 \size default 
9715  starts at a block (256 byte) boundary
9716 \begin_inset LatexCommand \index{block boundary}
9717
9718 \end_inset 
9719
9720  (section 
9721 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
9722
9723 \end_inset 
9724
9725  has an example).
9726 \newline 
9727 Absolute addresses can be specified for variables in all storage classes,
9728  e.g.:
9729 \layout Verse
9730
9731
9732 \family typewriter 
9733 bit
9734 \begin_inset LatexCommand \index{bit}
9735
9736 \end_inset 
9737
9738  at
9739 \begin_inset LatexCommand \index{at}
9740
9741 \end_inset 
9742
9743  0x02 bvar;
9744 \layout Standard
9745
9746 The above example will allocate the variable at offset 0x02 in the bit-addressab
9747 le space.
9748  There is no real advantage to assigning absolute addresses to variables
9749  in this manner, unless you want strict control over all the variables allocated.
9750  One possible use would be to write hardware portable code.
9751  For example, if you have a routine that uses one or more of the microcontroller
9752  I/O pins, and such pins are different for two different hardwares, you
9753  can declare the I/O pins in your routine using:
9754 \layout Verse
9755
9756
9757 \family typewriter 
9758 extern volatile
9759 \begin_inset LatexCommand \index{volatile}
9760
9761 \end_inset 
9762
9763  bit MOSI;\SpecialChar ~
9764 \SpecialChar ~
9765 \SpecialChar ~
9766 \SpecialChar ~
9767 /* master out, slave in */
9768 \newline 
9769 extern volatile bit MISO;\SpecialChar ~
9770 \SpecialChar ~
9771 \SpecialChar ~
9772 \SpecialChar ~
9773 /* master in, slave out */
9774 \newline 
9775 extern volatile bit MCLK;\SpecialChar ~
9776 \SpecialChar ~
9777 \SpecialChar ~
9778 \SpecialChar ~
9779 /* master clock */
9780 \newline 
9781
9782 \newline 
9783 /* Input and Output of a byte on a 3-wire serial bus.
9784 \newline 
9785 \SpecialChar ~
9786 \SpecialChar ~
9787 \SpecialChar ~
9788 If needed adapt polarity of clock, polarity of data and bit order
9789 \newline 
9790 \SpecialChar ~
9791 */
9792 \newline 
9793 unsigned char spi_io(unsigned char out_byte) 
9794 \newline 
9795
9796 \newline 
9797 \SpecialChar ~
9798 \SpecialChar ~
9799 \SpecialChar ~
9800 \SpecialChar ~
9801 unsigned char i=8;
9802 \newline 
9803 \SpecialChar ~
9804 \SpecialChar ~
9805 \SpecialChar ~
9806 \SpecialChar ~
9807 do { 
9808 \newline 
9809 \SpecialChar ~
9810 \SpecialChar ~
9811 \SpecialChar ~
9812 \SpecialChar ~
9813 \SpecialChar ~
9814 \SpecialChar ~
9815 \SpecialChar ~
9816 \SpecialChar ~
9817 MOSI = out_byte & 0x80; 
9818 \newline 
9819 \SpecialChar ~
9820 \SpecialChar ~
9821 \SpecialChar ~
9822 \SpecialChar ~
9823 \SpecialChar ~
9824 \SpecialChar ~
9825 \SpecialChar ~
9826 \SpecialChar ~
9827 out_byte <<= 1;
9828 \newline 
9829 \SpecialChar ~
9830 \SpecialChar ~
9831 \SpecialChar ~
9832 \SpecialChar ~
9833 \SpecialChar ~
9834 \SpecialChar ~
9835 \SpecialChar ~
9836 \SpecialChar ~
9837 MCLK = 1; 
9838 \newline 
9839 \SpecialChar ~
9840 \SpecialChar ~
9841 \SpecialChar ~
9842 \SpecialChar ~
9843 \SpecialChar ~
9844 \SpecialChar ~
9845 \SpecialChar ~
9846 \SpecialChar ~
9847 /* _asm nop _endasm; */\SpecialChar ~
9848 \SpecialChar ~
9849 \SpecialChar ~
9850 \SpecialChar ~
9851 \SpecialChar ~
9852 \SpecialChar ~
9853 \SpecialChar ~
9854 \SpecialChar ~
9855 /* for slow peripherals */
9856 \newline 
9857 \SpecialChar ~
9858 \SpecialChar ~
9859 \SpecialChar ~
9860 \SpecialChar ~
9861 \SpecialChar ~
9862 \SpecialChar ~
9863 \SpecialChar ~
9864 \SpecialChar ~
9865 if(MISO) 
9866 \newline 
9867 \SpecialChar ~
9868 \SpecialChar ~
9869 \SpecialChar ~
9870 \SpecialChar ~
9871 \SpecialChar ~
9872 \SpecialChar ~
9873 \SpecialChar ~
9874 \SpecialChar ~
9875 \SpecialChar ~
9876 \SpecialChar ~
9877 \SpecialChar ~
9878 \SpecialChar ~
9879 out_byte += 1; 
9880 \newline 
9881 \SpecialChar ~
9882 \SpecialChar ~
9883 \SpecialChar ~
9884 \SpecialChar ~
9885 \SpecialChar ~
9886 \SpecialChar ~
9887 \SpecialChar ~
9888 \SpecialChar ~
9889 MCLK = 0; 
9890 \newline 
9891 \SpecialChar ~
9892 \SpecialChar ~
9893 \SpecialChar ~
9894 \SpecialChar ~
9895 } while(--i);
9896 \newline 
9897 \SpecialChar ~
9898 \SpecialChar ~
9899 \SpecialChar ~
9900 \SpecialChar ~
9901 return out_byte; 
9902 \newline 
9903 }
9904 \layout Standard
9905
9906 Then, someplace in the code for the first hardware you would use
9907 \layout Verse
9908
9909
9910 \family typewriter 
9911 bit at
9912 \begin_inset LatexCommand \index{at}
9913
9914 \end_inset 
9915
9916
9917 \begin_inset LatexCommand \index{\_\_at}
9918
9919 \end_inset 
9920
9921  0x80 MOSI;\SpecialChar ~
9922 \SpecialChar ~
9923 \SpecialChar ~
9924 \SpecialChar ~
9925 /* I/O port 0, bit 0 */
9926 \newline 
9927 bit at 0x81 MISO;\SpecialChar ~
9928 \SpecialChar ~
9929 \SpecialChar ~
9930 \SpecialChar ~
9931 /* I/O port 0, bit 1 */
9932 \newline 
9933 bit at 0x82 MCLK;\SpecialChar ~
9934 \SpecialChar ~
9935 \SpecialChar ~
9936 \SpecialChar ~
9937 /* I/O port 0, bit 2 */
9938 \layout Standard
9939
9940 Similarly, for the second hardware you would use
9941 \layout Verse
9942
9943
9944 \family typewriter 
9945 bit at 0x83 MOSI;\SpecialChar ~
9946 \SpecialChar ~
9947 \SpecialChar ~
9948 \SpecialChar ~
9949 /* I/O port 0, bit 3 */
9950 \newline 
9951 bit at 0x91 MISO;\SpecialChar ~
9952 \SpecialChar ~
9953 \SpecialChar ~
9954 \SpecialChar ~
9955 /* I/O port 1, bit 1 */
9956 \newline 
9957 bit
9958 \begin_inset LatexCommand \index{bit}
9959
9960 \end_inset 
9961
9962  at 0x92 MCLK;\SpecialChar ~
9963 \SpecialChar ~
9964 \SpecialChar ~
9965 \SpecialChar ~
9966 /* I/O port 1, bit 2 */
9967 \layout Standard
9968
9969 and you can use the same hardware dependent routine without changes, as
9970  for example in a library.
9971  This is somehow similar to sbit, but only one absolute address has to be
9972  specified in the whole project.
9973 \layout Section
9974
9975 Parameters
9976 \begin_inset LatexCommand \index{Parameters}
9977
9978 \end_inset 
9979
9980
9981 \begin_inset LatexCommand \index{function parameter}
9982
9983 \end_inset 
9984
9985  & Local Variables
9986 \begin_inset LatexCommand \index{local variables}
9987
9988 \end_inset 
9989
9990
9991 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
9992
9993 \end_inset 
9994
9995
9996 \layout Standard
9997
9998 Automatic (local) variables and parameters to functions can either be placed
9999  on the stack or in data-space.
10000  The default action of the compiler is to place these variables in the internal
10001  RAM (for small model) or external RAM (for large model).
10002  This in fact makes them similar to 
10003 \emph on 
10004 static
10005 \begin_inset LatexCommand \index{static}
10006
10007 \end_inset 
10008
10009
10010 \emph default 
10011  so by default functions are non-reentrant
10012 \begin_inset LatexCommand \index{reentrant}
10013
10014 \end_inset 
10015
10016 .
10017  
10018 \newline 
10019
10020 \newline 
10021 They can be placed on the stack
10022 \begin_inset LatexCommand \index{stack}
10023
10024 \end_inset 
10025
10026  by using the
10027 \emph on 
10028  -
10029 \begin_inset ERT
10030 status Collapsed
10031
10032 \layout Standard
10033
10034 \backslash 
10035 /
10036 \end_inset 
10037
10038 -stack-auto
10039 \begin_inset LatexCommand \index{-\/-stack-auto}
10040
10041 \end_inset 
10042
10043
10044 \emph default 
10045  option, by using 
10046 \emph on 
10047 #pragma\SpecialChar ~
10048 stackauto
10049 \emph default 
10050
10051 \begin_inset LatexCommand \index{\#pragma stackauto}
10052
10053 \end_inset 
10054
10055  or by using the 
10056 \emph on 
10057 reentrant
10058 \begin_inset LatexCommand \index{reentrant}
10059
10060 \end_inset 
10061
10062
10063 \emph default 
10064  keyword in the function declaration, e.g.:
10065 \layout Verse
10066
10067
10068 \family typewriter 
10069 unsigned char foo(char i) reentrant 
10070 \newline 
10071
10072 \newline 
10073 \SpecialChar ~
10074 \SpecialChar ~
10075 \SpecialChar ~
10076 \SpecialChar ~
10077 ...
10078  
10079 \newline 
10080 }
10081 \layout Standard
10082
10083 Since stack space on 8051 is limited, the 
10084 \emph on 
10085 reentrant 
10086 \emph default 
10087 keyword or the
10088 \emph on 
10089  -
10090 \begin_inset ERT
10091 status Collapsed
10092
10093 \layout Standard
10094
10095 \backslash 
10096 /
10097 \end_inset 
10098
10099 -stack-auto
10100 \emph default 
10101  option should be used sparingly.
10102  Note that the reentrant keyword just means that the parameters & local
10103  variables will be allocated to the stack, it 
10104 \emph on 
10105 does not
10106 \emph default 
10107  mean that the function is register bank
10108 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
10109
10110 \end_inset 
10111
10112  independent.
10113 \newline 
10114
10115 \newline 
10116 Local variables
10117 \begin_inset LatexCommand \index{local variables}
10118
10119 \end_inset 
10120
10121  can be assigned storage classes and absolute
10122 \begin_inset LatexCommand \index{Absolute addressing}
10123
10124 \end_inset 
10125
10126  addresses, e.g.: 
10127 \layout Verse
10128
10129
10130 \family typewriter 
10131 unsigned char foo() 
10132 \newline 
10133 {
10134 \newline 
10135 \SpecialChar ~
10136 \SpecialChar ~
10137 \SpecialChar ~
10138 \SpecialChar ~
10139 xdata unsigned char i;
10140 \newline 
10141 \SpecialChar ~
10142 \SpecialChar ~
10143 \SpecialChar ~
10144 \SpecialChar ~
10145 bit bvar;
10146 \newline 
10147 \SpecialChar ~
10148 \SpecialChar ~
10149 \SpecialChar ~
10150 \SpecialChar ~
10151 data at
10152 \begin_inset LatexCommand \index{at}
10153
10154 \end_inset 
10155
10156  0x31 unsigned char j;
10157 \newline 
10158 \SpecialChar ~
10159 \SpecialChar ~
10160 \SpecialChar ~
10161 \SpecialChar ~
10162 ...
10163  
10164 \newline 
10165 }
10166 \layout Standard
10167
10168 In the above example the variable 
10169 \emph on 
10170 i
10171 \emph default 
10172  will be allocated in the external ram, 
10173 \emph on 
10174 bvar
10175 \emph default 
10176  in bit addressable space and
10177 \emph on 
10178  j
10179 \emph default 
10180  in internal ram.
10181  When compiled with 
10182 \emph on 
10183 -
10184 \begin_inset ERT
10185 status Collapsed
10186
10187 \layout Standard
10188
10189 \backslash 
10190 /
10191 \end_inset 
10192
10193 -stack-auto
10194 \emph default 
10195  or when a function is declared as 
10196 \emph on 
10197 reentrant
10198 \emph default 
10199  this should only be done for static variables.
10200 \layout Standard
10201
10202 Parameters
10203 \begin_inset LatexCommand \index{function parameter}
10204
10205 \end_inset 
10206
10207  however are not allowed any storage class
10208 \begin_inset LatexCommand \index{Storage class}
10209
10210 \end_inset 
10211
10212 , (storage classes for parameters will be ignored), their allocation is
10213  governed by the memory model in use, and the reentrancy options.
10214 \layout Section
10215
10216 Overlaying
10217 \begin_inset LatexCommand \label{sub:Overlaying}
10218
10219 \end_inset 
10220
10221
10222 \begin_inset LatexCommand \index{Overlaying}
10223
10224 \end_inset 
10225
10226
10227 \layout Standard
10228
10229 For non-reentrant
10230 \begin_inset LatexCommand \index{reentrant}
10231
10232 \end_inset 
10233
10234  functions SDCC will try to reduce internal ram space usage by overlaying
10235  parameters and local variables of a function (if possible).
10236  Parameters and local variables
10237 \begin_inset LatexCommand \index{local variables}
10238
10239 \end_inset 
10240
10241  of a function will be allocated to an overlayable segment if the function
10242  has 
10243 \emph on 
10244 no other function calls and the function is non-reentrant and the memory
10245  model
10246 \begin_inset LatexCommand \index{Memory model}
10247
10248 \end_inset 
10249
10250  is small.
10251
10252 \emph default 
10253  If an explicit storage class
10254 \begin_inset LatexCommand \index{Storage class}
10255
10256 \end_inset 
10257
10258  is specified for a local variable, it will NOT be overlayed.
10259 \layout Standard
10260
10261 Note that the compiler (not the linkage editor) makes the decision for overlayin
10262 g the data items.
10263  Functions that are called from an interrupt service routine should be preceded
10264  by a #pragma\SpecialChar ~
10265 nooverlay
10266 \begin_inset LatexCommand \index{\#pragma nooverlay}
10267
10268 \end_inset 
10269
10270  if they are not reentrant.
10271 \layout Standard
10272
10273 Also note that the compiler does not do any processing of inline assembler
10274  code, so the compiler might incorrectly assign local variables and parameters
10275  of a function into the overlay segment if the inline assembler code calls
10276  other c-functions that might use the overlay.
10277  In that case the #pragma\SpecialChar ~
10278 nooverlay should be used.
10279 \layout Standard
10280
10281 Parameters and local variables of functions that contain 16 or 32 bit multiplica
10282 tion
10283 \begin_inset LatexCommand \index{Multiplication}
10284
10285 \end_inset 
10286
10287  or division
10288 \begin_inset LatexCommand \index{Division}
10289
10290 \end_inset 
10291
10292  will NOT be overlayed since these are implemented using external functions,
10293  e.g.:
10294 \layout Verse
10295
10296
10297 \family typewriter 
10298 #pragma save 
10299 \newline 
10300 #pragma nooverlay
10301 \begin_inset LatexCommand \index{\#pragma nooverlay}
10302
10303 \end_inset 
10304
10305  
10306 \newline 
10307 void set_error(unsigned char errcd) 
10308 \newline 
10309 {
10310 \newline 
10311 \SpecialChar ~
10312 \SpecialChar ~
10313 \SpecialChar ~
10314 \SpecialChar ~
10315 P3 = errcd;
10316 \newline 
10317
10318 \newline 
10319 #pragma restore 
10320 \newline 
10321
10322 \newline 
10323 void some_isr () interrupt
10324 \begin_inset LatexCommand \index{interrupt}
10325
10326 \end_inset 
10327
10328  2
10329 \newline 
10330 {
10331 \newline 
10332 \SpecialChar ~
10333 \SpecialChar ~
10334 \SpecialChar ~
10335 \SpecialChar ~
10336 ...
10337 \newline 
10338 \SpecialChar ~
10339 \SpecialChar ~
10340 \SpecialChar ~
10341 \SpecialChar ~
10342 set_error(10);
10343 \newline 
10344 \SpecialChar ~
10345 \SpecialChar ~
10346 \SpecialChar ~
10347 \SpecialChar ~
10348 ...
10349  
10350 \newline 
10351 }
10352 \layout Standard
10353
10354 In the above example the parameter 
10355 \emph on 
10356 errcd
10357 \emph default 
10358  for the function 
10359 \emph on 
10360 set_error
10361 \emph default 
10362  would be assigned to the overlayable segment if the #pragma\SpecialChar ~
10363 nooverlay was
10364  not present, this could cause unpredictable runtime behavior when called
10365  from an interrupt service routine.
10366  The #pragma\SpecialChar ~
10367 nooverlay ensures that the parameters and local variables for
10368  the function are NOT overlayed.
10369 \layout Section
10370
10371 Interrupt Service Routines
10372 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
10373
10374 \end_inset 
10375
10376
10377 \layout Subsection
10378
10379 General Information
10380 \layout Standard
10381
10382 SDCC allows 
10383 \emph on 
10384 i
10385 \emph default 
10386 nterrupt 
10387 \emph on 
10388 s
10389 \emph default 
10390 ervice 
10391 \emph on 
10392 r
10393 \emph default 
10394 outines to be coded in C, with some extended keywords.
10395 \layout Verse
10396
10397
10398 \family typewriter 
10399 void timer_isr (void) interrupt 1 using 1 
10400 \newline 
10401
10402 \newline 
10403 \SpecialChar ~
10404 \SpecialChar ~
10405 \SpecialChar ~
10406 \SpecialChar ~
10407 ...
10408  
10409 \newline 
10410 }
10411 \layout Standard
10412
10413 The optional number following the 
10414 \emph on 
10415 interrupt
10416 \begin_inset LatexCommand \index{interrupt}
10417
10418 \end_inset 
10419
10420
10421 \begin_inset LatexCommand \index{\_\_interrupt}
10422
10423 \end_inset 
10424
10425
10426 \emph default 
10427  keyword is the interrupt number this routine will service.
10428  When present, the compiler will insert a call to this routine in the interrupt
10429  vector table for the interrupt number specified.
10430  If you have multiple source files in your project, interrupt service routines
10431  can be present in any of them, but a prototype of the isr MUST be present
10432  or included in the file that contains the function 
10433 \emph on 
10434 main
10435 \emph default 
10436 .
10437  The optional 
10438 \emph on 
10439 using
10440 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10441
10442 \end_inset 
10443
10444
10445 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
10446
10447 \end_inset 
10448
10449
10450 \emph default 
10451  keyword can be used to tell the compiler to use the specified register
10452  bank (8051 specific) when generating code for this function.
10453  
10454 \newline 
10455
10456 \layout Standard
10457
10458 Interrupt service routines open the door for some very interesting bugs:
10459 \newline 
10460 If an interrupt service routine changes variables which are accessed by
10461  other functions these variables have to be declared 
10462 \emph on 
10463 volatile
10464 \emph default 
10465
10466 \begin_inset LatexCommand \index{volatile}
10467
10468 \end_inset 
10469
10470 .
10471  
10472 \layout Standard
10473
10474 If the access to these variables is not 
10475 \emph on 
10476 atomic
10477 \begin_inset LatexCommand \index{atomic}
10478
10479 \end_inset 
10480
10481
10482 \emph default 
10483  (i.e.
10484  the processor needs more than one instruction for the access and could
10485  be interrupted while accessing the variable) the interrupt must be disabled
10486  during the access to avoid inconsistent data.
10487  Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
10488  and should be protected by disabling interrupts.
10489  You're not automatically on the safe side if you use 8 bit variables though.
10490  We need an example here: f.e.
10491  on the 8051 the harmless looking 
10492 \begin_inset Quotes srd
10493 \end_inset 
10494
10495
10496 \family typewriter 
10497 flags\SpecialChar ~
10498 |=\SpecialChar ~
10499 0x80;
10500 \family default 
10501
10502 \begin_inset Quotes sld
10503 \end_inset 
10504
10505  is not atomic if 
10506 \family typewriter 
10507 flags
10508 \family default 
10509  resides in xdata.
10510  Setting 
10511 \begin_inset Quotes srd
10512 \end_inset 
10513
10514
10515 \family typewriter 
10516 flags\SpecialChar ~
10517 |=\SpecialChar ~
10518 0x40;
10519 \family default 
10520
10521 \begin_inset Quotes sld
10522 \end_inset 
10523
10524  from within an interrupt routine might get lost if the interrupt occurs
10525  at the wrong time.
10526  
10527 \begin_inset Quotes sld
10528 \end_inset 
10529
10530
10531 \family typewriter 
10532 counter\SpecialChar ~
10533 +=\SpecialChar ~
10534 8;
10535 \family default 
10536
10537 \begin_inset Quotes srd
10538 \end_inset 
10539
10540  is not atomic on the 8051 even if 
10541 \family typewriter 
10542 counter
10543 \family default 
10544  is located in data memory.
10545  Bugs like these are hard to reproduce and can cause a lot of trouble.
10546  
10547 \layout Standard
10548
10549 The return address and the registers used in the interrupt service routine
10550  are saved on the stack
10551 \begin_inset LatexCommand \index{stack}
10552
10553 \end_inset 
10554
10555  so there must be sufficient stack space.
10556  If there isn't variables or registers (or even the return address itself)
10557  will be corrupted.
10558  This 
10559 \emph on 
10560 stack overflow
10561 \emph default 
10562
10563 \begin_inset LatexCommand \index{stack overflow}
10564
10565 \end_inset 
10566
10567  is most likely to happen if the interrupt occurs during the 
10568 \begin_inset Quotes sld
10569 \end_inset 
10570
10571 deepest
10572 \begin_inset Quotes srd
10573 \end_inset 
10574
10575  subroutine when the stack is already in use for f.e.
10576  many return addresses.
10577 \layout Standard
10578
10579 A special note here, int (16 bit) and long (32 bit) integer division
10580 \begin_inset LatexCommand \index{Division}
10581
10582 \end_inset 
10583
10584 , multiplication
10585 \begin_inset LatexCommand \index{Multiplication}
10586
10587 \end_inset 
10588
10589  & modulus
10590 \begin_inset LatexCommand \index{Modulus}
10591
10592 \end_inset 
10593
10594  and floating-point
10595 \begin_inset LatexCommand \index{Floating point support}
10596
10597 \end_inset 
10598
10599  operations are implemented using external support routines developed in
10600  ANSI-C.
10601  If an interrupt service routine needs to do any of these operations then
10602  the support routines (as mentioned in a following section) will have to
10603  be recompiled using the
10604 \emph on 
10605  -
10606 \begin_inset ERT
10607 status Collapsed
10608
10609 \layout Standard
10610
10611 \backslash 
10612 /
10613 \end_inset 
10614
10615 -stack-auto
10616 \begin_inset LatexCommand \index{-\/-stack-auto}
10617
10618 \end_inset 
10619
10620
10621 \emph default 
10622  option and the source file will need to be compiled using the 
10623 \emph on 
10624 -
10625 \begin_inset ERT
10626 status Collapsed
10627
10628 \layout Standard
10629
10630 \backslash 
10631 /
10632 \end_inset 
10633
10634 -int-long-reent
10635 \emph default 
10636
10637 \begin_inset LatexCommand \index{-\/-int-long-reent}
10638
10639 \end_inset 
10640
10641  compiler option.
10642 \layout Standard
10643
10644 Calling other functions from an interrupt service routine is not recommended,
10645  avoid it if possible.
10646  Note that when some function is called from an interrupt service routine
10647  it should be preceded by a #pragma\SpecialChar ~
10648 nooverlay
10649 \begin_inset LatexCommand \index{\#pragma nooverlay}
10650
10651 \end_inset 
10652
10653  if it is not reentrant.
10654  Furthermore nonreentrant functions should not be called from the main program
10655  while the interrupt service routine might be active.
10656  
10657 \newline 
10658
10659 \newline 
10660 Also see section 
10661 \begin_inset LatexCommand \ref{sub:Overlaying}
10662
10663 \end_inset 
10664
10665 \SpecialChar ~
10666 about Overlaying and section 
10667 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
10668
10669 \end_inset 
10670
10671 \SpecialChar ~
10672 about Functions using private register banks.
10673 \layout Subsection
10674
10675 MCS51/DS390 Interrupt Service Routines
10676 \layout Standard
10677
10678 Interrupt numbers and the corresponding address & descriptions for the Standard
10679  8051/8052 are listed below.
10680  SDCC will automatically adjust the interrupt vector table to the maximum
10681  interrupt number specified.
10682 \newline 
10683
10684 \layout Standard
10685 \align center 
10686
10687 \begin_inset  Tabular
10688 <lyxtabular version="3" rows="7" columns="3">
10689 <features>
10690 <column alignment="center" valignment="top" leftline="true" width="0in">
10691 <column alignment="center" valignment="top" leftline="true" width="0in">
10692 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0in">
10693 <row topline="true" bottomline="true">
10694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10695 \begin_inset Text
10696
10697 \layout Standard
10698
10699 Interrupt #
10700 \end_inset 
10701 </cell>
10702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10703 \begin_inset Text
10704
10705 \layout Standard
10706
10707 Description
10708 \end_inset 
10709 </cell>
10710 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10711 \begin_inset Text
10712
10713 \layout Standard
10714
10715 Vector Address
10716 \end_inset 
10717 </cell>
10718 </row>
10719 <row topline="true">
10720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10721 \begin_inset Text
10722
10723 \layout Standard
10724
10725 0
10726 \end_inset 
10727 </cell>
10728 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10729 \begin_inset Text
10730
10731 \layout Standard
10732
10733 External 0
10734 \end_inset 
10735 </cell>
10736 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10737 \begin_inset Text
10738
10739 \layout Standard
10740
10741 0x0003
10742 \end_inset 
10743 </cell>
10744 </row>
10745 <row topline="true">
10746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10747 \begin_inset Text
10748
10749 \layout Standard
10750
10751 1
10752 \end_inset 
10753 </cell>
10754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10755 \begin_inset Text
10756
10757 \layout Standard
10758
10759 Timer 0
10760 \end_inset 
10761 </cell>
10762 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10763 \begin_inset Text
10764
10765 \layout Standard
10766
10767 0x000B
10768 \end_inset 
10769 </cell>
10770 </row>
10771 <row topline="true">
10772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10773 \begin_inset Text
10774
10775 \layout Standard
10776
10777 2
10778 \end_inset 
10779 </cell>
10780 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10781 \begin_inset Text
10782
10783 \layout Standard
10784
10785 External 1
10786 \end_inset 
10787 </cell>
10788 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10789 \begin_inset Text
10790
10791 \layout Standard
10792
10793 0x0013
10794 \end_inset 
10795 </cell>
10796 </row>
10797 <row topline="true">
10798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10799 \begin_inset Text
10800
10801 \layout Standard
10802
10803 3
10804 \end_inset 
10805 </cell>
10806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10807 \begin_inset Text
10808
10809 \layout Standard
10810
10811 Timer 1
10812 \end_inset 
10813 </cell>
10814 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10815 \begin_inset Text
10816
10817 \layout Standard
10818
10819 0x001B
10820 \end_inset 
10821 </cell>
10822 </row>
10823 <row topline="true">
10824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10825 \begin_inset Text
10826
10827 \layout Standard
10828
10829 4
10830 \end_inset 
10831 </cell>
10832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10833 \begin_inset Text
10834
10835 \layout Standard
10836
10837 Serial
10838 \end_inset 
10839 </cell>
10840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10841 \begin_inset Text
10842
10843 \layout Standard
10844
10845 0x0023
10846 \end_inset 
10847 </cell>
10848 </row>
10849 <row topline="true" bottomline="true">
10850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10851 \begin_inset Text
10852
10853 \layout Standard
10854
10855 5
10856 \end_inset 
10857 </cell>
10858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10859 \begin_inset Text
10860
10861 \layout Standard
10862
10863 Timer 2 (8052)
10864 \end_inset 
10865 </cell>
10866 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10867 \begin_inset Text
10868
10869 \layout Standard
10870
10871 0x002B
10872 \end_inset 
10873 </cell>
10874 </row>
10875 </lyxtabular>
10876
10877 \end_inset 
10878
10879
10880 \newline 
10881
10882 \layout Standard
10883
10884 If the interrupt service routine is defined without 
10885 \emph on 
10886 using
10887 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10888
10889 \end_inset 
10890
10891
10892 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
10893
10894 \end_inset 
10895
10896
10897 \emph default 
10898  a register bank or with register bank 0 (
10899 \emph on 
10900 using
10901 \emph default 
10902  0), the compiler will save the registers used by itself on the stack upon
10903  entry and restore them at exit, however if such an interrupt service routine
10904  calls another function then the entire register bank will be saved on the
10905  stack.
10906  This scheme may be advantageous for small interrupt service routines which
10907  have low register usage.
10908 \layout Standard
10909
10910 If the interrupt service routine is defined to be using a specific register
10911  bank then only 
10912 \emph on 
10913 a, b, dptr
10914 \emph default 
10915  & psw are saved and restored, if such an interrupt service routine calls
10916  another function (using another register bank) then the entire register
10917  bank of the called function will be saved on the stack.
10918  This scheme is recommended for larger interrupt service routines.
10919 \layout Subsection
10920
10921 HC08 Interrupt Service Routines
10922 \layout Standard
10923
10924 Since the number of interrupts available is chip specific and the interrupt
10925  vector table always ends at the last byte of memory, the interrupt numbers
10926  corresponds to the interrupt vectors in reverse order of address.
10927  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
10928  2 will use the interrupt vector at 0xfffa, and so on.
10929  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
10930  this way; instead see section 
10931 \begin_inset LatexCommand \ref{sub:Startup-Code}
10932
10933 \end_inset 
10934
10935  for details on customizing startup.
10936 \layout Subsection
10937
10938 Z80 Interrupt Service Routines
10939 \layout Standard
10940
10941 The Z80 uses several different methods for determining the correct interrupt
10942  vector depending on the hardware implementation.
10943  Therefore, SDCC ignores the optional interrupt number and does not attempt
10944  to generate an interrupt vector table.
10945 \layout Standard
10946
10947 By default, SDCC generates code for a maskable interrupt, which uses an
10948  RETI instruction to return from the interrupt.
10949  To write an interrupt handler for the non-maskable interrupt, which needs
10950  an RETN instruction instead, add the 
10951 \emph on 
10952 critical
10953 \emph default 
10954  keyword:
10955 \layout Verse
10956
10957
10958 \family typewriter 
10959 void nmi_isr (void) critical interrupt
10960 \newline 
10961
10962 \newline 
10963 \SpecialChar ~
10964 \SpecialChar ~
10965 \SpecialChar ~
10966 \SpecialChar ~
10967 ...
10968  
10969 \newline 
10970 }
10971 \layout Section
10972
10973 Enabling and Disabling Interrupts
10974 \layout Subsection
10975
10976 Critical Functions and Critical Statements
10977 \layout Standard
10978
10979 A special keyword may be associated with a block or a function declaring
10980  it as 
10981 \emph on 
10982 critical
10983 \emph default 
10984 .
10985  SDCC will generate code to disable all interrupts
10986 \begin_inset LatexCommand \index{interrupt}
10987
10988 \end_inset 
10989
10990  upon entry to a critical function and restore the interrupt enable to the
10991  previous state before returning.
10992  Nesting critical functions will need one additional byte on the stack
10993 \begin_inset LatexCommand \index{stack}
10994
10995 \end_inset 
10996
10997  for each call.
10998 \layout Verse
10999
11000
11001 \family typewriter 
11002 int foo () critical
11003 \begin_inset LatexCommand \index{critical}
11004
11005 \end_inset 
11006
11007
11008 \begin_inset LatexCommand \index{\_\_critical}
11009
11010 \end_inset 
11011
11012  
11013 \newline 
11014
11015 \newline 
11016 \SpecialChar ~
11017 \SpecialChar ~
11018 \SpecialChar ~
11019 \SpecialChar ~
11020 ...
11021  
11022 \newline 
11023 \SpecialChar ~
11024 \SpecialChar ~
11025 \SpecialChar ~
11026 \SpecialChar ~
11027 ...
11028  
11029 \newline 
11030 }
11031 \layout Standard
11032
11033 The critical attribute maybe used with other attributes like 
11034 \emph on 
11035 reentrant.
11036 \emph default 
11037
11038 \newline 
11039 The keyword 
11040 \emph on 
11041 critical
11042 \emph default 
11043  may also be used to disable interrupts more locally:
11044 \layout Verse
11045
11046
11047 \family typewriter 
11048 critical{ i++; }
11049 \layout Standard
11050
11051 More than one statement could have been included in the block.
11052 \layout Subsection
11053
11054 Enabling and Disabling Interrupts directly
11055 \layout Standard
11056
11057 Interrupts
11058 \begin_inset LatexCommand \index{interrupt}
11059
11060 \end_inset 
11061
11062  can also be disabled and enabled directly (8051):
11063 \layout Verse
11064
11065
11066 \family typewriter 
11067 EA = 0;\SpecialChar ~
11068 \SpecialChar ~
11069 \SpecialChar ~
11070 \SpecialChar ~
11071 \SpecialChar ~
11072 \SpecialChar ~
11073 \SpecialChar ~
11074 \SpecialChar ~
11075 \SpecialChar ~
11076 \SpecialChar ~
11077 \SpecialChar ~
11078 \SpecialChar ~
11079 or:\SpecialChar ~
11080 \SpecialChar ~
11081 \SpecialChar ~
11082 \SpecialChar ~
11083 \SpecialChar ~
11084 \SpecialChar ~
11085 \SpecialChar ~
11086 \SpecialChar ~
11087 \SpecialChar ~
11088 \SpecialChar ~
11089 \SpecialChar ~
11090 EA_SAVE = EA;
11091 \layout Verse
11092
11093
11094 \family typewriter 
11095 ...\SpecialChar ~
11096 \SpecialChar ~
11097 \SpecialChar ~
11098 \SpecialChar ~
11099 \SpecialChar ~
11100 \SpecialChar ~
11101 \SpecialChar ~
11102 \SpecialChar ~
11103 \SpecialChar ~
11104 \SpecialChar ~
11105 \SpecialChar ~
11106 \SpecialChar ~
11107 \SpecialChar ~
11108 \SpecialChar ~
11109 \SpecialChar ~
11110 \SpecialChar ~
11111 \SpecialChar ~
11112 \SpecialChar ~
11113 \SpecialChar ~
11114 \SpecialChar ~
11115 \SpecialChar ~
11116 \SpecialChar ~
11117 \SpecialChar ~
11118 \SpecialChar ~
11119 \SpecialChar ~
11120 \SpecialChar ~
11121 \SpecialChar ~
11122 \SpecialChar ~
11123 \SpecialChar ~
11124 \SpecialChar ~
11125 EA = 0;
11126 \layout Verse
11127
11128
11129 \family typewriter 
11130 EA = 1;\SpecialChar ~
11131 \SpecialChar ~
11132 \SpecialChar ~
11133 \SpecialChar ~
11134 \SpecialChar ~
11135 \SpecialChar ~
11136 \SpecialChar ~
11137 \SpecialChar ~
11138 \SpecialChar ~
11139 \SpecialChar ~
11140 \SpecialChar ~
11141 \SpecialChar ~
11142 \SpecialChar ~
11143 \SpecialChar ~
11144 \SpecialChar ~
11145 \SpecialChar ~
11146 \SpecialChar ~
11147 \SpecialChar ~
11148 \SpecialChar ~
11149 \SpecialChar ~
11150 \SpecialChar ~
11151 \SpecialChar ~
11152 \SpecialChar ~
11153 \SpecialChar ~
11154 \SpecialChar ~
11155 \SpecialChar ~
11156 ...
11157 \layout Verse
11158
11159
11160 \family typewriter 
11161 \SpecialChar ~
11162 \SpecialChar ~
11163 \SpecialChar ~
11164 \SpecialChar ~
11165 \SpecialChar ~
11166 \SpecialChar ~
11167 \SpecialChar ~
11168 \SpecialChar ~
11169 \SpecialChar ~
11170 \SpecialChar ~
11171 \SpecialChar ~
11172 \SpecialChar ~
11173 \SpecialChar ~
11174 \SpecialChar ~
11175 \SpecialChar ~
11176 \SpecialChar ~
11177 \SpecialChar ~
11178 \SpecialChar ~
11179 \SpecialChar ~
11180 \SpecialChar ~
11181 \SpecialChar ~
11182 \SpecialChar ~
11183 \SpecialChar ~
11184 \SpecialChar ~
11185 \SpecialChar ~
11186 \SpecialChar ~
11187 \SpecialChar ~
11188 \SpecialChar ~
11189 \SpecialChar ~
11190 \SpecialChar ~
11191 \SpecialChar ~
11192 \SpecialChar ~
11193 \SpecialChar ~
11194 EA = EA_SAVE;
11195 \layout Standard
11196
11197 On other architectures which have seperate opcodes for enabling and disabling
11198  interrupts you might want to make use of defines with inline assembly
11199 \begin_inset LatexCommand \index{Assembler routines}
11200
11201 \end_inset 
11202
11203  (HC08):
11204 \layout Verse
11205
11206
11207 \family typewriter 
11208 #define CLI _asm
11209 \begin_inset LatexCommand \index{\_asm}
11210
11211 \end_inset 
11212
11213 \SpecialChar ~
11214 \SpecialChar ~
11215 cli\SpecialChar ~
11216 \SpecialChar ~
11217 _endasm
11218 \begin_inset LatexCommand \index{\_endasm}
11219
11220 \end_inset 
11221
11222
11223 \layout Verse
11224
11225
11226 \family typewriter 
11227 #define SEI _asm\SpecialChar ~
11228 \SpecialChar ~
11229 sei\SpecialChar ~
11230 \SpecialChar ~
11231 _endasm; 
11232 \layout Verse
11233
11234
11235 \family typewriter 
11236 ...
11237 \layout Standard
11238
11239 Note: it is sometimes sufficient to disable only a specific interrupt source
11240  like f.e.
11241  a timer or serial interrupt by manipulating an 
11242 \emph on 
11243 interrupt mask
11244 \begin_inset LatexCommand \index{interrupt mask}
11245
11246 \end_inset 
11247
11248
11249 \emph default 
11250  register.
11251  
11252 \layout Standard
11253
11254 Usually the time during which interrupts are disabled should be kept as
11255  short as possible.
11256  This minimizes both 
11257 \emph on 
11258 interrupt latency
11259 \emph default 
11260
11261 \begin_inset LatexCommand \index{interrupt latency}
11262
11263 \end_inset 
11264
11265  (the time between the occurrence of the interrupt and the execution of
11266  the first code in the interrupt routine) and 
11267 \emph on 
11268 interrupt jitter
11269 \emph default 
11270
11271 \begin_inset LatexCommand \index{interrupt jitter}
11272
11273 \end_inset 
11274
11275  (the difference between the shortest and the longest interrupt latency).
11276  These really are something different, f.e.
11277  a serial interrupt has to be served before its buffer overruns so it cares
11278  for the maximum interrupt latency, whereas it does not care about jitter.
11279  On a loudspeaker driven via a digital to analog converter which is fed
11280  by an interrupt a latency of a few milliseconds might be tolerable, whereas
11281  a much smaller jitter will be very audible.
11282 \layout Standard
11283
11284 You can reenable interrupts within an interrupt routine and on some architecture
11285 s you can make use of two (or more) levels of 
11286 \emph on 
11287 interrupt priorities
11288 \emph default 
11289
11290 \begin_inset LatexCommand \index{interrupt priority}
11291
11292 \end_inset 
11293
11294 .
11295  On some architectures which don't support interrupt priorities these can
11296  be implemented by manipulating the interrupt mask and reenabling interrupts
11297  within the interrupt routine.
11298  Check there is sufficient space on the stack
11299 \begin_inset LatexCommand \index{stack}
11300
11301 \end_inset 
11302
11303  and don't add complexity unless you have to.
11304  
11305 \layout Subsection
11306
11307 Semaphore
11308 \begin_inset LatexCommand \index{semaphore}
11309
11310 \end_inset 
11311
11312  locking (mcs51/ds390)
11313 \layout Standard
11314
11315 Some architectures (mcs51/ds390) have an atomic
11316 \begin_inset LatexCommand \index{atomic}
11317
11318 \end_inset 
11319
11320  bit test and
11321 \emph on 
11322  
11323 \emph default 
11324 clear
11325 \emph on 
11326  
11327 \emph default 
11328 instruction.
11329  These type of instructions are typically used in preemptive multitasking
11330  systems, where a routine f.e.
11331  claims the use of a data structure ('acquires a lock
11332 \begin_inset LatexCommand \index{lock}
11333
11334 \end_inset 
11335
11336  on it'), makes some modifications and then releases the lock when the data
11337  structure is consistent again.
11338  The instruction may also be used if interrupt and non-interrupt code have
11339  to compete for a resource.
11340  With the atomic bit test and clear instruction interrupts
11341 \begin_inset LatexCommand \index{interrupt}
11342
11343 \end_inset 
11344
11345  don't have to be disabled for the locking operation.
11346  
11347 \layout Standard
11348
11349 SDCC generates this instruction if the source follows this pattern:
11350 \layout Verse
11351
11352
11353 \family typewriter 
11354 volatile
11355 \begin_inset LatexCommand \index{volatile}
11356
11357 \end_inset 
11358
11359  bit resource_is_free; 
11360 \newline 
11361
11362 \newline 
11363 if (resource_is_free) 
11364 \newline 
11365 \SpecialChar ~
11366 \SpecialChar ~
11367
11368 \newline 
11369 \SpecialChar ~
11370 \SpecialChar ~
11371 \SpecialChar ~
11372 \SpecialChar ~
11373 resource_is_free=0; 
11374 \newline 
11375 \SpecialChar ~
11376 \SpecialChar ~
11377 \SpecialChar ~
11378 \SpecialChar ~
11379 ...
11380  
11381 \newline 
11382 \SpecialChar ~
11383 \SpecialChar ~
11384 \SpecialChar ~
11385 \SpecialChar ~
11386 resource_is_free=1;
11387 \newline 
11388 \SpecialChar ~
11389 \SpecialChar ~
11390
11391 \layout Standard
11392
11393 Note, mcs51 and ds390 support only an atomic
11394 \begin_inset LatexCommand \index{atomic}
11395
11396 \end_inset 
11397
11398  bit test and 
11399 \emph on 
11400 clear
11401 \emph default 
11402  instruction (as opposed to atomic bit test and 
11403 \emph on 
11404 set).
11405 \layout Section
11406
11407 Functions using private register banks
11408 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
11409
11410 \end_inset 
11411
11412  (mcs51/ds390)
11413 \layout Standard
11414
11415 Some architectures have support for quickly changing register sets.
11416  SDCC supports this feature with the 
11417 \emph on 
11418 using
11419 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11420
11421 \end_inset 
11422
11423
11424 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11425
11426 \end_inset 
11427
11428
11429 \emph default 
11430  attribute (which tells the compiler to use a register bank
11431 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
11432
11433 \end_inset 
11434
11435  other than the default bank zero).
11436  It should only be applied to 
11437 \emph on 
11438 interrupt
11439 \begin_inset LatexCommand \index{interrupt}
11440
11441 \end_inset 
11442
11443
11444 \emph default 
11445  functions (see footnote below).
11446  This will in most circumstances make the generated ISR code more efficient
11447  since it will not have to save registers on the stack.
11448 \layout Standard
11449
11450 The 
11451 \emph on 
11452 using
11453 \emph default 
11454  attribute will have no effect on the generated code for a 
11455 \emph on 
11456 non-interrupt
11457 \emph default 
11458  function (but may occasionally be useful anyway
11459 \begin_inset Foot
11460 collapsed false
11461
11462 \layout Standard
11463
11464 possible exception: if a function is called ONLY from 'interrupt' functions
11465  using a particular bank, it can be declared with the same 'using' attribute
11466  as the calling 'interrupt' functions.
11467  For instance, if you have several ISRs using bank one, and all of them
11468  call memcpy(), it might make sense to create a specialized version of memcpy()
11469  'using 1', since this would prevent the ISR from having to save bank zero
11470  to the stack on entry and switch to bank zero before calling the function
11471 \end_inset 
11472
11473 ).
11474 \newline 
11475
11476 \emph on 
11477 (pending: I don't think this has been done yet)
11478 \layout Standard
11479
11480 An 
11481 \emph on 
11482 interrupt
11483 \emph default 
11484  function using a non-zero bank will assume that it can trash that register
11485  bank, and will not save it.
11486  Since high-priority interrupts
11487 \begin_inset LatexCommand \index{interrupts}
11488
11489 \end_inset 
11490
11491
11492 \begin_inset LatexCommand \index{interrupt priority}
11493
11494 \end_inset 
11495
11496  can interrupt low-priority ones on the 8051 and friends, this means that
11497  if a high-priority ISR 
11498 \emph on 
11499 using
11500 \emph default 
11501  a particular bank occurs while processing a low-priority ISR 
11502 \emph on 
11503 using
11504 \emph default 
11505  the same bank, terrible and bad things can happen.
11506  To prevent this, no single register bank should be 
11507 \emph on 
11508 used
11509 \emph default 
11510  by both a high priority and a low priority ISR.
11511  This is probably most easily done by having all high priority ISRs use
11512  one bank and all low priority ISRs use another.
11513  If you have an ISR which can change priority at runtime, you're on your
11514  own: I suggest using the default bank zero and taking the small performance
11515  hit.
11516 \layout Standard
11517
11518 It is most efficient if your ISR calls no other functions.
11519  If your ISR must call other functions, it is most efficient if those functions
11520  use the same bank as the ISR (see note 1 below); the next best is if the
11521  called functions use bank zero.
11522  It is very inefficient to call a function using a different, non-zero bank
11523  from an ISR.
11524  
11525 \layout Section
11526
11527 Startup Code
11528 \begin_inset LatexCommand \label{sub:Startup-Code}
11529
11530 \end_inset 
11531
11532
11533 \begin_inset LatexCommand \index{Startup code}
11534
11535 \end_inset 
11536
11537
11538 \layout Subsection
11539
11540 MCS51/DS390 Startup Code
11541 \layout Standard
11542
11543 The compiler inserts a call to the C routine 
11544 \emph on 
11545 _sdcc_external_startup()
11546 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
11547
11548 \end_inset 
11549
11550
11551 \series bold 
11552 \emph default 
11553  
11554 \series default 
11555 at the start of the CODE area.
11556  This routine is in the runtime library
11557 \begin_inset LatexCommand \index{Runtime library}
11558
11559 \end_inset 
11560
11561 .
11562  By default this routine returns 0, if this routine returns a non-zero value,
11563  the static & global variable initialization will be skipped and the function
11564  main will be invoked.
11565  Otherwise static & global variables will be initialized before the function
11566  main is invoked.
11567  You could add a 
11568 \emph on 
11569 _sdcc_external_startup()
11570 \emph default 
11571  routine to your program to override the default if you need to setup hardware
11572  or perform some other critical operation prior to static & global variable
11573  initialization
11574 \begin_inset LatexCommand \index{Variable initialization}
11575
11576 \end_inset 
11577
11578 .
11579  On some mcs51 variants xdata
11580 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11581
11582 \end_inset 
11583
11584  memory has to be explicitly enabled before it can be accessed or if the
11585  watchdog needs to be disabled, this is the place to do it.
11586  The startup code clears all internal data memory, 256 bytes by default,
11587  but from 0 to n-1 if 
11588 \emph on 
11589 -
11590 \begin_inset ERT
11591 status Collapsed
11592
11593 \layout Standard
11594
11595 \backslash 
11596 /
11597 \end_inset 
11598
11599 -iram-size
11600 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
11601
11602 \end_inset 
11603
11604 n
11605 \emph default 
11606  is used.
11607  (recommended for Chipcon CC1010).
11608 \layout Standard
11609
11610 See also the compiler option 
11611 \emph on 
11612 -
11613 \begin_inset ERT
11614 status Collapsed
11615
11616 \layout Standard
11617
11618 \backslash 
11619 /
11620 \end_inset 
11621
11622 -no-xinit
11623 \emph default 
11624 -
11625 \emph on 
11626 opt
11627 \emph default 
11628
11629 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
11630
11631 \end_inset 
11632
11633  and section 
11634 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11635
11636 \end_inset 
11637
11638 \SpecialChar ~
11639 about MCS51-variants.
11640 \layout Subsection
11641
11642 HC08 Startup Code
11643 \layout Standard
11644
11645 The HC08 startup code follows the same scheme as the MCS51 startup code.
11646 \layout Subsection
11647
11648 Z80 Startup Code
11649 \layout Standard
11650
11651 On the Z80 the startup code is inserted by linking with crt0.o which is generated
11652  from sdcc/device/lib/z80/crt0.s.
11653  If you need a different startup code you can use the compiler option 
11654 \emph on 
11655 -
11656 \series bold 
11657 \emph default 
11658
11659 \begin_inset ERT
11660 status Collapsed
11661
11662 \layout Standard
11663
11664 \backslash 
11665 /
11666 \end_inset 
11667
11668
11669 \series default 
11670 \emph on 
11671 -no-std-crt0
11672 \emph default 
11673
11674 \begin_inset LatexCommand \index{-\/-no-std-crt0}
11675
11676 \end_inset 
11677
11678  and provide your own crt0.o.
11679  
11680 \layout Section
11681
11682 Inline Assembler Code
11683 \begin_inset LatexCommand \index{Assembler routines}
11684
11685 \end_inset 
11686
11687
11688 \layout Subsection
11689
11690 A Step by Step Introduction
11691 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
11692
11693 \end_inset 
11694
11695
11696 \layout Standard
11697
11698 Starting from a small snippet of c-code this example shows for the MCS51
11699  how to use inline assembly, access variables, a function parameter and
11700  an array in xdata memory.
11701  The example uses an MCS51 here but is easily adapted for other architectures.
11702  This is a buffer routine which should be optimized:
11703 \layout Verse
11704
11705
11706 \family typewriter 
11707 \size footnotesize 
11708 unsigned char far
11709 \begin_inset LatexCommand \index{far (storage class)}
11710
11711 \end_inset 
11712
11713
11714 \begin_inset LatexCommand \index{\_\_far (storage class)}
11715
11716 \end_inset 
11717
11718  at
11719 \begin_inset LatexCommand \index{at}
11720
11721 \end_inset 
11722
11723
11724 \begin_inset LatexCommand \index{\_\_at}
11725
11726 \end_inset 
11727
11728  0x7f00 buf[0x100];
11729 \begin_inset LatexCommand \index{Aligned array}
11730
11731 \end_inset 
11732
11733
11734 \newline 
11735 unsigned char head,tail;
11736 \newline 
11737
11738 \newline 
11739 void to_buffer( unsigned char c ) 
11740 \newline 
11741 {
11742 \newline 
11743 \SpecialChar ~
11744 \SpecialChar ~
11745 \SpecialChar ~
11746 \SpecialChar ~
11747 if( head != tail-1 ) 
11748 \newline 
11749 \SpecialChar ~
11750 \SpecialChar ~
11751 \SpecialChar ~
11752 \SpecialChar ~
11753 \SpecialChar ~
11754 \SpecialChar ~
11755 \SpecialChar ~
11756 \SpecialChar ~
11757 buf[ head++ ] = c;\SpecialChar ~
11758 \SpecialChar ~
11759 \SpecialChar ~
11760 \SpecialChar ~
11761 /* access to a 256 byte aligned array */
11762 \newline 
11763
11764 \layout Standard
11765
11766 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
11767  then a corresponding buffer.asm file is generated.
11768  We define a new function 
11769 \family typewriter 
11770 to_buffer_asm()
11771 \family default 
11772  in file buffer.c in which we cut and paste the generated code, removing
11773  unwanted comments and some ':'.
11774  Then add 
11775 \begin_inset Quotes sld
11776 \end_inset 
11777
11778 _asm
11779 \begin_inset Quotes srd
11780 \end_inset 
11781
11782  and 
11783 \begin_inset Quotes sld
11784 \end_inset 
11785
11786 _endasm;
11787 \begin_inset Quotes srd
11788 \end_inset 
11789
11790  to the beginning and the end of the function body:
11791 \layout Verse
11792
11793
11794 \family typewriter 
11795 \size footnotesize 
11796 /* With a cut and paste from the .asm file, we have something to start with.
11797 \newline 
11798 \SpecialChar ~
11799 \SpecialChar ~
11800 \SpecialChar ~
11801 The function is not yet OK! (registers aren't saved) */ 
11802 \newline 
11803 void to_buffer_asm( unsigned char c ) 
11804 \newline 
11805
11806 \newline 
11807 \SpecialChar ~
11808 \SpecialChar ~
11809 \SpecialChar ~
11810 \SpecialChar ~
11811 _asm
11812 \begin_inset LatexCommand \index{\_asm}
11813
11814 \end_inset 
11815
11816
11817 \begin_inset LatexCommand \index{\_\_asm}
11818
11819 \end_inset 
11820
11821
11822 \newline 
11823 \SpecialChar ~
11824 \SpecialChar ~
11825 \SpecialChar ~
11826 \SpecialChar ~
11827 mov\SpecialChar ~
11828 \SpecialChar ~
11829 r2,dpl 
11830 \newline 
11831 ;buffer.c if( head != tail-1 ) 
11832 \newline 
11833 \SpecialChar ~
11834 \SpecialChar ~
11835 \SpecialChar ~
11836 \SpecialChar ~
11837 mov\SpecialChar ~
11838 \SpecialChar ~
11839 a,_tail 
11840 \newline 
11841 \SpecialChar ~
11842 \SpecialChar ~
11843 \SpecialChar ~
11844 \SpecialChar ~
11845 dec\SpecialChar ~
11846 \SpecialChar ~
11847
11848 \newline 
11849 \SpecialChar ~
11850 \SpecialChar ~
11851 \SpecialChar ~
11852 \SpecialChar ~
11853 mov\SpecialChar ~
11854 \SpecialChar ~
11855 r3,a 
11856 \newline 
11857 \SpecialChar ~
11858 \SpecialChar ~
11859 \SpecialChar ~
11860 \SpecialChar ~
11861 mov\SpecialChar ~
11862 \SpecialChar ~
11863 a,_head 
11864 \newline 
11865 \SpecialChar ~
11866 \SpecialChar ~
11867 \SpecialChar ~
11868 \SpecialChar ~
11869 cjne a,ar3,00106$ 
11870 \newline 
11871 \SpecialChar ~
11872 \SpecialChar ~
11873 \SpecialChar ~
11874 \SpecialChar ~
11875 ret
11876 \newline 
11877 00106$: 
11878 \newline 
11879 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
11880 \begin_inset LatexCommand \index{Aligned array}
11881
11882 \end_inset 
11883
11884
11885 \newline 
11886 \SpecialChar ~
11887 \SpecialChar ~
11888 \SpecialChar ~
11889 \SpecialChar ~
11890 mov\SpecialChar ~
11891 \SpecialChar ~
11892 r3,_head 
11893 \newline 
11894 \SpecialChar ~
11895 \SpecialChar ~
11896 \SpecialChar ~
11897 \SpecialChar ~
11898 inc\SpecialChar ~
11899 \SpecialChar ~
11900 _head 
11901 \newline 
11902 \SpecialChar ~
11903 \SpecialChar ~
11904 \SpecialChar ~
11905 \SpecialChar ~
11906 mov\SpecialChar ~
11907 \SpecialChar ~
11908 dpl,r3 
11909 \newline 
11910 \SpecialChar ~
11911 \SpecialChar ~
11912 \SpecialChar ~
11913 \SpecialChar ~
11914 mov\SpecialChar ~
11915 \SpecialChar ~
11916 dph,#(_buf >> 8) 
11917 \newline 
11918 \SpecialChar ~
11919 \SpecialChar ~
11920 \SpecialChar ~
11921 \SpecialChar ~
11922 mov\SpecialChar ~
11923 \SpecialChar ~
11924 a,r2 
11925 \newline 
11926 \SpecialChar ~
11927 \SpecialChar ~
11928 \SpecialChar ~
11929 \SpecialChar ~
11930 movx @dptr,a 
11931 \newline 
11932 00103$: 
11933 \newline 
11934 \SpecialChar ~
11935 \SpecialChar ~
11936 \SpecialChar ~
11937 \SpecialChar ~
11938 ret
11939 \newline 
11940 \SpecialChar ~
11941 \SpecialChar ~
11942 \SpecialChar ~
11943 \SpecialChar ~
11944 _endasm
11945 \begin_inset LatexCommand \index{\_endasm}
11946
11947 \end_inset 
11948
11949
11950 \begin_inset LatexCommand \index{\_\_endasm}
11951
11952 \end_inset 
11953
11954 ;
11955 \newline 
11956
11957 \layout Standard
11958
11959 The new file buffer.c should compile with only one warning about the unreferenced
11960  function argument 'c'.
11961  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
11962  (1) and finally have:
11963 \layout Verse
11964
11965
11966 \family typewriter 
11967 \size footnotesize 
11968 unsigned char far at 0x7f00 buf[0x100];
11969 \newline 
11970 unsigned char head,tail;
11971 \newline 
11972 #define USE_ASSEMBLY (1)
11973 \newline 
11974
11975 \newline 
11976 #if !USE_ASSEMBLY
11977 \newline 
11978
11979 \newline 
11980 void to_buffer( unsigned char c )
11981 \newline 
11982 {
11983 \newline 
11984 \SpecialChar ~
11985 \SpecialChar ~
11986 \SpecialChar ~
11987 \SpecialChar ~
11988 if( head != tail-1 )
11989 \newline 
11990 \SpecialChar ~
11991 \SpecialChar ~
11992 \SpecialChar ~
11993 \SpecialChar ~
11994 \SpecialChar ~
11995 \SpecialChar ~
11996 \SpecialChar ~
11997 \SpecialChar ~
11998 buf[ head++ ] = c;
11999 \newline 
12000 }
12001 \newline 
12002
12003 \newline 
12004 #else
12005 \newline 
12006
12007 \newline 
12008 void to_buffer( unsigned char c )
12009 \newline 
12010 {
12011 \newline 
12012 \SpecialChar ~
12013 \SpecialChar ~
12014 \SpecialChar ~
12015 \SpecialChar ~
12016 c; // to avoid warning: unreferenced function argument
12017 \newline 
12018 \SpecialChar ~
12019 \SpecialChar ~
12020 \SpecialChar ~
12021 \SpecialChar ~
12022 _asm
12023 \begin_inset LatexCommand \index{\_asm}
12024
12025 \end_inset 
12026
12027
12028 \begin_inset LatexCommand \index{\_\_asm}
12029
12030 \end_inset 
12031
12032
12033 \newline 
12034 \SpecialChar ~
12035 \SpecialChar ~
12036 \SpecialChar ~
12037 \SpecialChar ~
12038 \SpecialChar ~
12039 \SpecialChar ~
12040 \SpecialChar ~
12041 \SpecialChar ~
12042 ; save used registers here.
12043  
12044 \newline 
12045 \SpecialChar ~
12046 \SpecialChar ~
12047 \SpecialChar ~
12048 \SpecialChar ~
12049 \SpecialChar ~
12050 \SpecialChar ~
12051 \SpecialChar ~
12052 \SpecialChar ~
12053 ; If we were still using r2,r3 we would have to push them here.
12054  
12055 \newline 
12056 ; if( head != tail-1 )
12057 \newline 
12058 \SpecialChar ~
12059 \SpecialChar ~
12060 \SpecialChar ~
12061 \SpecialChar ~
12062 \SpecialChar ~
12063 \SpecialChar ~
12064 \SpecialChar ~
12065 \SpecialChar ~
12066 mov\SpecialChar ~
12067  a,_tail
12068 \newline 
12069 \SpecialChar ~
12070 \SpecialChar ~
12071 \SpecialChar ~
12072 \SpecialChar ~
12073 \SpecialChar ~
12074 \SpecialChar ~
12075 \SpecialChar ~
12076 \SpecialChar ~
12077 dec\SpecialChar ~
12078  a
12079 \newline 
12080 \SpecialChar ~
12081 \SpecialChar ~
12082 \SpecialChar ~
12083 \SpecialChar ~
12084 \SpecialChar ~
12085 \SpecialChar ~
12086 \SpecialChar ~
12087 \SpecialChar ~
12088 xrl\SpecialChar ~
12089  a,_head
12090 \newline 
12091 \SpecialChar ~
12092 \SpecialChar ~
12093 \SpecialChar ~
12094 \SpecialChar ~
12095 \SpecialChar ~
12096 \SpecialChar ~
12097 \SpecialChar ~
12098 \SpecialChar ~
12099 ; we could do an ANL a,#0x0f here to use a smaller buffer (see below)
12100 \newline 
12101 \SpecialChar ~
12102 \SpecialChar ~
12103 \SpecialChar ~
12104 \SpecialChar ~
12105 \SpecialChar ~
12106 \SpecialChar ~
12107 \SpecialChar ~
12108 \SpecialChar ~
12109 jz\SpecialChar ~
12110 \SpecialChar ~
12111  t_b_end$
12112 \newline 
12113 \SpecialChar ~
12114 \SpecialChar ~
12115 \SpecialChar ~
12116 \SpecialChar ~
12117 \SpecialChar ~
12118 \SpecialChar ~
12119 \SpecialChar ~
12120 \SpecialChar ~
12121 ;
12122 \newline 
12123 ; buf[ head++ ] = c;
12124 \newline 
12125 \SpecialChar ~
12126 \SpecialChar ~
12127 \SpecialChar ~
12128 \SpecialChar ~
12129 \SpecialChar ~
12130 \SpecialChar ~
12131 \SpecialChar ~
12132 \SpecialChar ~
12133 mov\SpecialChar ~
12134  a,dpl \SpecialChar ~
12135 \SpecialChar ~
12136 \SpecialChar ~
12137 \SpecialChar ~
12138 \SpecialChar ~
12139 \SpecialChar ~
12140 \SpecialChar ~
12141 ; dpl holds lower byte of function argument
12142 \newline 
12143 \SpecialChar ~
12144 \SpecialChar ~
12145 \SpecialChar ~
12146 \SpecialChar ~
12147 \SpecialChar ~
12148 \SpecialChar ~
12149 \SpecialChar ~
12150 \SpecialChar ~
12151 mov\SpecialChar ~
12152  dpl,_head \SpecialChar ~
12153 \SpecialChar ~
12154 \SpecialChar ~
12155 ; buf is 0x100 byte aligned so head can be used directly
12156 \newline 
12157 \SpecialChar ~
12158 \SpecialChar ~
12159 \SpecialChar ~
12160 \SpecialChar ~
12161 \SpecialChar ~
12162 \SpecialChar ~
12163 \SpecialChar ~
12164 \SpecialChar ~
12165 mov\SpecialChar ~
12166  dph,#(_buf>>8)
12167 \newline 
12168 \SpecialChar ~
12169 \SpecialChar ~
12170 \SpecialChar ~
12171 \SpecialChar ~
12172 \SpecialChar ~
12173 \SpecialChar ~
12174 \SpecialChar ~
12175 \SpecialChar ~
12176 movx @dptr,a
12177 \newline 
12178 \SpecialChar ~
12179 \SpecialChar ~
12180 \SpecialChar ~
12181 \SpecialChar ~
12182 \SpecialChar ~
12183 \SpecialChar ~
12184 \SpecialChar ~
12185 \SpecialChar ~
12186 inc \SpecialChar ~
12187 _head
12188 \newline 
12189 \SpecialChar ~
12190 \SpecialChar ~
12191 \SpecialChar ~
12192 \SpecialChar ~
12193 \SpecialChar ~
12194 \SpecialChar ~
12195 \SpecialChar ~
12196 \SpecialChar ~
12197 ; we could do an ANL _head,#0x0f here to use a smaller buffer (see above)
12198 \newline 
12199 t_b_end$:
12200 \newline 
12201 \SpecialChar ~
12202 \SpecialChar ~
12203 \SpecialChar ~
12204 \SpecialChar ~
12205 \SpecialChar ~
12206 \SpecialChar ~
12207 \SpecialChar ~
12208 \SpecialChar ~
12209 ; restore used registers here 
12210 \newline 
12211 \SpecialChar ~
12212 \SpecialChar ~
12213 \SpecialChar ~
12214 \SpecialChar ~
12215 _endasm
12216 \begin_inset LatexCommand \index{\_endasm}
12217
12218 \end_inset 
12219
12220
12221 \begin_inset LatexCommand \index{\_\_endasm}
12222
12223 \end_inset 
12224
12225 ;
12226 \newline 
12227 }
12228 \newline 
12229 #endif
12230 \layout Standard
12231
12232 The inline assembler code can contain any valid code understood by the assembler
12233 , this includes any assembler directives and comment lines
12234 \begin_inset Foot
12235 collapsed false
12236
12237 \layout Standard
12238
12239 The assembler does not like some characters like ':' or ''' in comments.
12240  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
12241 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
12242
12243 \end_inset 
12244
12245
12246 \begin_inset LatexCommand \index{Assembler documentation}
12247
12248 \end_inset 
12249
12250
12251 \end_inset 
12252
12253 .
12254  The compiler does not do any validation of the code within the 
12255 \family typewriter 
12256 _asm
12257 \begin_inset LatexCommand \index{\_asm}
12258
12259 \end_inset 
12260
12261
12262 \begin_inset LatexCommand \index{\_\_asm}
12263
12264 \end_inset 
12265
12266  ...
12267  _endasm
12268 \size footnotesize 
12269
12270 \begin_inset LatexCommand \index{\_endasm}
12271
12272 \end_inset 
12273
12274
12275 \begin_inset LatexCommand \index{\_\_endasm}
12276
12277 \end_inset 
12278
12279
12280 \size default 
12281 ;
12282 \family default 
12283  keyword pair.
12284  Specifically it will not know which registers are used and thus register
12285  pushing/popping
12286 \begin_inset LatexCommand \index{push/pop}
12287
12288 \end_inset 
12289
12290  has to be done manually.
12291  
12292 \layout Standard
12293
12294 It is recommended that each assembly instruction (including labels) be placed
12295  in a separate line (as the example shows).
12296  When the -
12297 \begin_inset ERT
12298 status Collapsed
12299
12300 \layout Standard
12301
12302 \backslash 
12303 /
12304 \end_inset 
12305
12306 -
12307 \emph on 
12308 peep-asm
12309 \begin_inset LatexCommand \index{-\/-peep-asm}
12310
12311 \end_inset 
12312
12313
12314 \emph default 
12315  command line option is used, the inline assembler code will be passed through
12316  the peephole optimizer
12317 \begin_inset LatexCommand \index{Peephole optimizer}
12318
12319 \end_inset 
12320
12321 .
12322  There are only a few (if any) cases where this option makes sense, it might
12323  cause some unexpected changes in the inline assembler code.
12324  Please go through the peephole optimizer rules defined in file 
12325 \emph on 
12326 SDCCpeeph.def
12327 \emph default 
12328  before using this option.
12329 \layout Subsection
12330
12331 Naked Functions
12332 \begin_inset LatexCommand \label{sub:Naked-Functions}
12333
12334 \end_inset 
12335
12336
12337 \begin_inset LatexCommand \index{Naked functions}
12338
12339 \end_inset 
12340
12341
12342 \layout Standard
12343
12344 A special keyword may be associated with a function declaring it as 
12345 \emph on 
12346 _naked
12347 \begin_inset LatexCommand \index{\_naked}
12348
12349 \end_inset 
12350
12351
12352 \begin_inset LatexCommand \index{\_\_naked}
12353
12354 \end_inset 
12355
12356 .
12357  
12358 \emph default 
12359 The 
12360 \emph on 
12361 _naked
12362 \emph default 
12363  function modifier attribute prevents the compiler from generating prologue
12364 \begin_inset LatexCommand \index{function prologue}
12365
12366 \end_inset 
12367
12368  and epilogue
12369 \begin_inset LatexCommand \index{function epilogue}
12370
12371 \end_inset 
12372
12373  code for that function.
12374  This means that the user is entirely responsible for such things as saving
12375  any registers that may need to be preserved, selecting the proper register
12376  bank, generating the 
12377 \emph on 
12378 return
12379 \emph default 
12380  instruction at the end, etc.
12381  Practically, this means that the contents of the function must be written
12382  in inline assembler.
12383  This is particularly useful for interrupt functions, which can have a large
12384  (and often unnecessary) prologue/epilogue.
12385  For example, compare the code generated by these two functions:
12386 \layout Verse
12387
12388
12389 \family typewriter 
12390 volatile
12391 \begin_inset LatexCommand \index{volatile}
12392
12393 \end_inset 
12394
12395  data unsigned char counter;
12396 \newline 
12397
12398 \newline 
12399 void simpleInterrupt(void) interrupt
12400 \begin_inset LatexCommand \index{interrupt}
12401
12402 \end_inset 
12403
12404
12405 \begin_inset LatexCommand \index{\_\_interrupt}
12406
12407 \end_inset 
12408
12409  1
12410 \newline 
12411 {
12412 \newline 
12413 \SpecialChar ~
12414 \SpecialChar ~
12415 \SpecialChar ~
12416 \SpecialChar ~
12417 counter++;
12418 \newline 
12419 }
12420 \newline 
12421
12422 \newline 
12423 void nakedInterrupt(void) interrupt 2 _naked
12424 \newline 
12425 {
12426 \newline 
12427 \SpecialChar ~
12428 \SpecialChar ~
12429 \SpecialChar ~
12430 \SpecialChar ~
12431 _asm
12432 \begin_inset LatexCommand \index{\_asm}
12433
12434 \end_inset 
12435
12436
12437 \begin_inset LatexCommand \index{\_\_asm}
12438
12439 \end_inset 
12440
12441
12442 \newline 
12443 \SpecialChar ~
12444 \SpecialChar ~
12445 \SpecialChar ~
12446 \SpecialChar ~
12447 \SpecialChar ~
12448 \SpecialChar ~
12449 inc\SpecialChar ~
12450 \SpecialChar ~
12451 \SpecialChar ~
12452 \SpecialChar ~
12453 \SpecialChar ~
12454 _counter ; does not change flags, no need to save psw
12455 \newline 
12456 \SpecialChar ~
12457 \SpecialChar ~
12458 \SpecialChar ~
12459 \SpecialChar ~
12460 \SpecialChar ~
12461 \SpecialChar ~
12462 reti\SpecialChar ~
12463 \SpecialChar ~
12464 \SpecialChar ~
12465 \SpecialChar ~
12466 ; MUST explicitly include ret or reti in _naked function.
12467 \newline 
12468 \SpecialChar ~
12469 \SpecialChar ~
12470 \SpecialChar ~
12471 \SpecialChar ~
12472 _endasm
12473 \begin_inset LatexCommand \index{\_endasm}
12474
12475 \end_inset 
12476
12477
12478 \begin_inset LatexCommand \index{\_\_endasm}
12479
12480 \end_inset 
12481
12482 ;
12483 \newline 
12484 }
12485 \layout Standard
12486
12487 For an 8051 target, the generated simpleInterrupt looks like:
12488 \layout Verse
12489
12490
12491 \family typewriter 
12492 _simpleInterrupt:
12493 \newline 
12494 \SpecialChar ~
12495 \SpecialChar ~
12496 \SpecialChar ~
12497 \SpecialChar ~
12498 push\SpecialChar ~
12499 \SpecialChar ~
12500 \SpecialChar ~
12501 \SpecialChar ~
12502 acc
12503 \newline 
12504 \SpecialChar ~
12505 \SpecialChar ~
12506 \SpecialChar ~
12507 \SpecialChar ~
12508 push\SpecialChar ~
12509 \SpecialChar ~
12510 \SpecialChar ~
12511 \SpecialChar ~
12512 b
12513 \newline 
12514 \SpecialChar ~
12515 \SpecialChar ~
12516 \SpecialChar ~
12517 \SpecialChar ~
12518 push\SpecialChar ~
12519 \SpecialChar ~
12520 \SpecialChar ~
12521 \SpecialChar ~
12522 dpl
12523 \newline 
12524 \SpecialChar ~
12525 \SpecialChar ~
12526 \SpecialChar ~
12527 \SpecialChar ~
12528 push\SpecialChar ~
12529 \SpecialChar ~
12530 \SpecialChar ~
12531 \SpecialChar ~
12532 dph
12533 \newline 
12534 \SpecialChar ~
12535 \SpecialChar ~
12536 \SpecialChar ~
12537 \SpecialChar ~
12538 push\SpecialChar ~
12539 \SpecialChar ~
12540 \SpecialChar ~
12541 \SpecialChar ~
12542 psw
12543 \newline 
12544 \SpecialChar ~
12545 \SpecialChar ~
12546 \SpecialChar ~
12547 \SpecialChar ~
12548 mov\SpecialChar ~
12549 \SpecialChar ~
12550 \SpecialChar ~
12551 \SpecialChar ~
12552 \SpecialChar ~
12553 psw,#0x00
12554 \newline 
12555 \SpecialChar ~
12556 \SpecialChar ~
12557 \SpecialChar ~
12558 \SpecialChar ~
12559 inc\SpecialChar ~
12560 \SpecialChar ~
12561 \SpecialChar ~
12562 \SpecialChar ~
12563 \SpecialChar ~
12564 _counter
12565 \newline 
12566 \SpecialChar ~
12567 \SpecialChar ~
12568 \SpecialChar ~
12569 \SpecialChar ~
12570 pop\SpecialChar ~
12571 \SpecialChar ~
12572 \SpecialChar ~
12573 \SpecialChar ~
12574 \SpecialChar ~
12575 psw
12576 \newline 
12577 \SpecialChar ~
12578 \SpecialChar ~
12579 \SpecialChar ~
12580 \SpecialChar ~
12581 pop\SpecialChar ~
12582 \SpecialChar ~
12583 \SpecialChar ~
12584 \SpecialChar ~
12585 \SpecialChar ~
12586 dph
12587 \newline 
12588 \SpecialChar ~
12589 \SpecialChar ~
12590 \SpecialChar ~
12591 \SpecialChar ~
12592 pop\SpecialChar ~
12593 \SpecialChar ~
12594 \SpecialChar ~
12595 \SpecialChar ~
12596 \SpecialChar ~
12597 dpl
12598 \newline 
12599 \SpecialChar ~
12600 \SpecialChar ~
12601 \SpecialChar ~
12602 \SpecialChar ~
12603 pop\SpecialChar ~
12604 \SpecialChar ~
12605 \SpecialChar ~
12606 \SpecialChar ~
12607 \SpecialChar ~
12608 b
12609 \newline 
12610 \SpecialChar ~
12611 \SpecialChar ~
12612 \SpecialChar ~
12613 \SpecialChar ~
12614 pop\SpecialChar ~
12615 \SpecialChar ~
12616 \SpecialChar ~
12617 \SpecialChar ~
12618 \SpecialChar ~
12619 acc
12620 \newline 
12621 \SpecialChar ~
12622 \SpecialChar ~
12623 \SpecialChar ~
12624 \SpecialChar ~
12625 reti
12626 \layout Standard
12627
12628 whereas nakedInterrupt looks like:
12629 \layout Verse
12630
12631
12632 \family typewriter 
12633 _nakedInterrupt:
12634 \newline 
12635 \SpecialChar ~
12636 \SpecialChar ~
12637 \SpecialChar ~
12638 \SpecialChar ~
12639 inc\SpecialChar ~
12640 \SpecialChar ~
12641 \SpecialChar ~
12642 \SpecialChar ~
12643 _counter ; does not change flags, no need to save psw
12644 \newline 
12645 \SpecialChar ~
12646 \SpecialChar ~
12647 \SpecialChar ~
12648 \SpecialChar ~
12649 reti\SpecialChar ~
12650 \SpecialChar ~
12651 \SpecialChar ~
12652 \SpecialChar ~
12653 \SpecialChar ~
12654 \SpecialChar ~
12655 \SpecialChar ~
12656 \SpecialChar ~
12657 \SpecialChar ~
12658 \SpecialChar ~
12659 \SpecialChar ~
12660 \SpecialChar ~
12661 ; MUST explicitly include ret or reti in _naked function
12662 \layout Standard
12663
12664 The related directive #pragma exclude
12665 \begin_inset LatexCommand \index{\#pragma exclude}
12666
12667 \end_inset 
12668
12669  allows a more fine grained control over pushing & popping
12670 \begin_inset LatexCommand \index{push/pop}
12671
12672 \end_inset 
12673
12674  the registers.
12675 \layout Standard
12676
12677 While there is nothing preventing you from writing C code inside a 
12678 \family typewriter 
12679 _naked
12680 \family default 
12681  function, there are many ways to shoot yourself in the foot doing this,
12682  and it is recommended that you stick to inline assembler.
12683 \layout Subsection
12684
12685 Use of Labels within Inline Assembler
12686 \layout Standard
12687
12688 SDCC allows the use of in-line assembler with a few restrictions regarding
12689  labels.
12690  In older versions of the compiler all labels defined within inline assembler
12691  code 
12692 \emph on 
12693 had to be
12694 \emph default 
12695  of the form 
12696 \emph on 
12697 nnnnn$
12698 \emph default 
12699  where nnnn is a number less than 100 (which implies a limit of utmost 100
12700  inline assembler labels 
12701 \emph on 
12702 per function
12703 \emph default 
12704 \noun on 
12705 )
12706 \noun default 
12707 .
12708  
12709 \layout Verse
12710
12711
12712 \family typewriter 
12713 _asm
12714 \begin_inset LatexCommand \index{\_asm}
12715
12716 \end_inset 
12717
12718
12719 \begin_inset LatexCommand \index{\_\_asm}
12720
12721 \end_inset 
12722
12723  
12724 \newline 
12725 \SpecialChar ~
12726 \SpecialChar ~
12727 \SpecialChar ~
12728 \SpecialChar ~
12729 mov\SpecialChar ~
12730 \SpecialChar ~
12731 \SpecialChar ~
12732 \SpecialChar ~
12733 \SpecialChar ~
12734 b,#10 
12735 \newline 
12736 00001$: 
12737 \newline 
12738 \SpecialChar ~
12739 \SpecialChar ~
12740 \SpecialChar ~
12741 \SpecialChar ~
12742 djnz\SpecialChar ~
12743 \SpecialChar ~
12744 \SpecialChar ~
12745 \SpecialChar ~
12746 b,00001$ 
12747 \newline 
12748 _endasm
12749 \begin_inset LatexCommand \index{\_endasm}
12750
12751 \end_inset 
12752
12753
12754 \begin_inset LatexCommand \index{\_\_endasm}
12755
12756 \end_inset 
12757
12758  ;
12759 \layout Standard
12760
12761 Inline assembler code cannot reference any C-Labels, however it can reference
12762  labels
12763 \begin_inset LatexCommand \index{Labels}
12764
12765 \end_inset 
12766
12767  defined by the inline assembler, e.g.:
12768 \layout Verse
12769
12770
12771 \family typewriter 
12772 foo() { 
12773 \newline 
12774 \SpecialChar ~
12775 \SpecialChar ~
12776 \SpecialChar ~
12777 \SpecialChar ~
12778 /* some c code */ 
12779 \newline 
12780 \SpecialChar ~
12781 \SpecialChar ~
12782 \SpecialChar ~
12783 \SpecialChar ~
12784 _asm 
12785 \newline 
12786 \SpecialChar ~
12787 \SpecialChar ~
12788 \SpecialChar ~
12789 \SpecialChar ~
12790 \SpecialChar ~
12791 \SpecialChar ~
12792 ; some assembler code 
12793 \newline 
12794 \SpecialChar ~
12795 \SpecialChar ~
12796 \SpecialChar ~
12797 \SpecialChar ~
12798 \SpecialChar ~
12799 \SpecialChar ~
12800 ljmp $0003 
12801 \newline 
12802 \SpecialChar ~
12803 \SpecialChar ~
12804 \SpecialChar ~
12805 \SpecialChar ~
12806 _endasm; 
12807 \newline 
12808 \SpecialChar ~
12809 \SpecialChar ~
12810 \SpecialChar ~
12811 \SpecialChar ~
12812 /* some more c code */ 
12813 \newline 
12814 clabel:\SpecialChar ~
12815 \SpecialChar ~
12816 /* inline assembler cannot reference this label */ 
12817 \newline 
12818 \SpecialChar ~
12819 \SpecialChar ~
12820 \SpecialChar ~
12821 \SpecialChar ~
12822 _asm
12823 \newline 
12824 \SpecialChar ~
12825 \SpecialChar ~
12826 \SpecialChar ~
12827 \SpecialChar ~
12828 $0003: ;label (can be referenced by inline assembler only) 
12829 \newline 
12830 \SpecialChar ~
12831 \SpecialChar ~
12832 \SpecialChar ~
12833 \SpecialChar ~
12834 _endasm
12835 \begin_inset LatexCommand \index{\_endasm}
12836
12837 \end_inset 
12838
12839
12840 \begin_inset LatexCommand \index{\_\_endasm}
12841
12842 \end_inset 
12843
12844  ; 
12845 \newline 
12846 \SpecialChar ~
12847 \SpecialChar ~
12848 \SpecialChar ~
12849 \SpecialChar ~
12850 /* some more c code */
12851 \newline 
12852 }
12853 \layout Standard
12854
12855 In other words inline assembly code can access labels defined in inline
12856  assembly within the scope of the function.
12857  The same goes the other way, i.e.
12858  labels defines in inline assembly can not be accessed by C statements.
12859 \layout Section
12860
12861 Interfacing with Assembler Code
12862 \begin_inset LatexCommand \index{Assembler routines}
12863
12864 \end_inset 
12865
12866
12867 \layout Subsection
12868
12869 Global Registers used for Parameter Passing
12870 \begin_inset LatexCommand \index{Parameter passing}
12871
12872 \end_inset 
12873
12874
12875 \layout Standard
12876
12877 The compiler always uses the global registers 
12878 \emph on 
12879 DPL, DPH
12880 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
12881
12882 \end_inset 
12883
12884
12885 \begin_inset LatexCommand \index{DPTR}
12886
12887 \end_inset 
12888
12889 , B
12890 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
12891
12892 \end_inset 
12893
12894  
12895 \emph default 
12896 and
12897 \emph on 
12898  ACC
12899 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
12900
12901 \end_inset 
12902
12903
12904 \emph default 
12905  to pass the first parameter to a routine.
12906  The second parameter onwards is either allocated on the stack (for reentrant
12907  routines or if -
12908 \begin_inset ERT
12909 status Collapsed
12910
12911 \layout Standard
12912
12913 \backslash 
12914 /
12915 \end_inset 
12916
12917 -stack-auto is used) or in data / xdata memory (depending on the memory
12918  model).
12919  
12920 \layout Subsection
12921
12922 Assembler Routine (non-reentrant)
12923 \layout Standard
12924
12925 In the following example
12926 \begin_inset LatexCommand \index{reentrant}
12927
12928 \end_inset 
12929
12930
12931 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
12932
12933 \end_inset 
12934
12935  the function c_func calls an assembler routine asm_func, which takes two
12936  parameters
12937 \begin_inset LatexCommand \index{function parameter}
12938
12939 \end_inset 
12940
12941 .
12942 \layout Verse
12943
12944
12945 \family typewriter 
12946 extern int asm_func(unsigned char, unsigned char);
12947 \newline 
12948
12949 \newline 
12950 int c_func (unsigned char i, unsigned char j)
12951 \newline 
12952 {
12953 \newline 
12954 \SpecialChar ~
12955 \SpecialChar ~
12956 \SpecialChar ~
12957 \SpecialChar ~
12958 return asm_func(i,j);
12959 \newline 
12960 }
12961 \newline 
12962
12963 \newline 
12964 int main()
12965 \newline 
12966 {
12967 \newline 
12968 \SpecialChar ~
12969 \SpecialChar ~
12970 \SpecialChar ~
12971 \SpecialChar ~
12972 return c_func(10,9);
12973 \newline 
12974 }
12975 \layout Standard
12976
12977 The corresponding assembler function is:
12978 \layout Verse
12979
12980
12981 \family typewriter 
12982 .globl _asm_func_PARM_2 
12983 \newline 
12984 \SpecialChar ~
12985 \SpecialChar ~
12986 \SpecialChar ~
12987 \SpecialChar ~
12988 \SpecialChar ~
12989 \SpecialChar ~
12990 \SpecialChar ~
12991 \SpecialChar ~
12992 .globl _asm_func 
12993 \newline 
12994 \SpecialChar ~
12995 \SpecialChar ~
12996 \SpecialChar ~
12997 \SpecialChar ~
12998 \SpecialChar ~
12999 \SpecialChar ~
13000 \SpecialChar ~
13001 \SpecialChar ~
13002 .area OSEG 
13003 \newline 
13004 _asm_func_PARM_2:
13005 \newline 
13006 \SpecialChar ~
13007 \SpecialChar ~
13008 \SpecialChar ~
13009 \SpecialChar ~
13010 \SpecialChar ~
13011 \SpecialChar ~
13012 \SpecialChar ~
13013 \SpecialChar ~
13014 .ds    1 
13015 \newline 
13016 \SpecialChar ~
13017 \SpecialChar ~
13018 \SpecialChar ~
13019 \SpecialChar ~
13020 \SpecialChar ~
13021 \SpecialChar ~
13022 \SpecialChar ~
13023 \SpecialChar ~
13024 .area CSEG 
13025 \newline 
13026 _asm_func: 
13027 \newline 
13028 \SpecialChar ~
13029 \SpecialChar ~
13030 \SpecialChar ~
13031 \SpecialChar ~
13032 \SpecialChar ~
13033 \SpecialChar ~
13034 \SpecialChar ~
13035 \SpecialChar ~
13036 mov\SpecialChar ~
13037 \SpecialChar ~
13038 \SpecialChar ~
13039 \SpecialChar ~
13040 a,dpl 
13041 \newline 
13042 \SpecialChar ~
13043 \SpecialChar ~
13044 \SpecialChar ~
13045 \SpecialChar ~
13046 \SpecialChar ~
13047 \SpecialChar ~
13048 \SpecialChar ~
13049 \SpecialChar ~
13050 add\SpecialChar ~
13051 \SpecialChar ~
13052 \SpecialChar ~
13053 \SpecialChar ~
13054 a,_asm_func_PARM_2 
13055 \newline 
13056 \SpecialChar ~
13057 \SpecialChar ~
13058 \SpecialChar ~
13059 \SpecialChar ~
13060 \SpecialChar ~
13061 \SpecialChar ~
13062 \SpecialChar ~
13063 \SpecialChar ~
13064 mov\SpecialChar ~
13065 \SpecialChar ~
13066 \SpecialChar ~
13067 \SpecialChar ~
13068 dpl,a 
13069 \newline 
13070 \SpecialChar ~
13071 \SpecialChar ~
13072 \SpecialChar ~
13073 \SpecialChar ~
13074 \SpecialChar ~
13075 \SpecialChar ~
13076 \SpecialChar ~
13077 \SpecialChar ~
13078 mov\SpecialChar ~
13079 \SpecialChar ~
13080 \SpecialChar ~
13081 \SpecialChar ~
13082 dph
13083 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
13084
13085 \end_inset 
13086
13087 ,#0x00 
13088 \newline 
13089 \SpecialChar ~
13090 \SpecialChar ~
13091 \SpecialChar ~
13092 \SpecialChar ~
13093 \SpecialChar ~
13094 \SpecialChar ~
13095 \SpecialChar ~
13096 \SpecialChar ~
13097 ret
13098 \layout Standard
13099
13100 Note here that the return values
13101 \begin_inset LatexCommand \index{return value}
13102
13103 \end_inset 
13104
13105  are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
13106  two byte values.
13107  'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
13108 b' & 'acc' for four byte values.
13109 \layout Standard
13110
13111 The parameter naming convention is _<function_name>_PARM_<n>, where n is
13112  the parameter number starting from 1, and counting from the left.
13113  The first parameter is passed in 
13114 \begin_inset Quotes eld
13115 \end_inset 
13116
13117 dpl
13118 \begin_inset Quotes erd
13119 \end_inset 
13120
13121  for a one byte parameter, 
13122 \begin_inset Quotes eld
13123 \end_inset 
13124
13125 dptr
13126 \begin_inset Quotes erd
13127 \end_inset 
13128
13129  for two bytes, 
13130 \begin_inset Quotes eld
13131 \end_inset 
13132
13133 b,dptr
13134 \begin_inset Quotes erd
13135 \end_inset 
13136
13137  for three bytes and 
13138 \begin_inset Quotes eld
13139 \end_inset 
13140
13141 acc,b,dptr
13142 \begin_inset Quotes erd
13143 \end_inset 
13144
13145  for a four bytes parameter.
13146  The variable name for the second parameter will be _<function_name>_PARM_2.
13147 \newline 
13148
13149 \newline 
13150 Assemble the assembler routine with the following command:
13151 \newline 
13152
13153 \newline 
13154
13155 \family sans 
13156 \series bold 
13157 asx8051 -losg asmfunc.asm
13158 \newline 
13159
13160 \newline 
13161
13162 \family default 
13163 \series default 
13164 Then compile and link the assembler routine to the C source file with the
13165  following command:
13166 \newline 
13167
13168 \newline 
13169
13170 \family sans 
13171 \series bold 
13172 sdcc cfunc.c asmfunc.rel
13173 \layout Subsection
13174
13175 Assembler Routine (reentrant)
13176 \layout Standard
13177
13178 In this case
13179 \begin_inset LatexCommand \index{reentrant}
13180
13181 \end_inset 
13182
13183
13184 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
13185
13186 \end_inset 
13187
13188  the second parameter
13189 \begin_inset LatexCommand \index{function parameter}
13190
13191 \end_inset 
13192
13193  onwards will be passed on the stack, the parameters are pushed from right
13194  to left i.e.
13195  after the call the leftmost parameter will be on the top of the stack.
13196  Here is an example:
13197 \layout Verse
13198
13199
13200 \family typewriter 
13201 extern int asm_func(unsigned char, unsigned char);
13202 \newline 
13203
13204 \newline 
13205 int c_func (unsigned char i, unsigned char j) reentrant 
13206 \newline 
13207
13208 \newline 
13209 \SpecialChar ~
13210 \SpecialChar ~
13211 \SpecialChar ~
13212 \SpecialChar ~
13213 return asm_func(i,j); 
13214 \newline 
13215
13216 \newline 
13217
13218 \newline 
13219 int main() 
13220 \newline 
13221
13222 \newline 
13223 \SpecialChar ~
13224 \SpecialChar ~
13225 \SpecialChar ~
13226 \SpecialChar ~
13227 return c_func(10,9); 
13228 \newline 
13229 }
13230 \layout Standard
13231
13232 The corresponding assembler routine is:
13233 \layout Verse
13234
13235
13236 \family typewriter 
13237 .globl _asm_func 
13238 \newline 
13239 _asm_func: 
13240 \newline 
13241 \SpecialChar ~
13242 \SpecialChar ~
13243 \SpecialChar ~
13244 \SpecialChar ~
13245 push  _bp 
13246 \newline 
13247 \SpecialChar ~
13248 \SpecialChar ~
13249 \SpecialChar ~
13250 \SpecialChar ~
13251 mov _bp,sp 
13252 \newline 
13253 \SpecialChar ~
13254 \SpecialChar ~
13255 \SpecialChar ~
13256 \SpecialChar ~
13257 mov r2,dpl
13258 \newline 
13259 \SpecialChar ~
13260 \SpecialChar ~
13261 \SpecialChar ~
13262 \SpecialChar ~
13263 mov a,_bp 
13264 \newline 
13265 \SpecialChar ~
13266 \SpecialChar ~
13267 \SpecialChar ~
13268 \SpecialChar ~
13269 add a,#0xfd 
13270 \newline 
13271 \SpecialChar ~
13272 \SpecialChar ~
13273 \SpecialChar ~
13274 \SpecialChar ~
13275 mov r0,a 
13276 \newline 
13277 \SpecialChar ~
13278 \SpecialChar ~
13279 \SpecialChar ~
13280 \SpecialChar ~
13281 add  a,#0xfc ;?
13282 \newline 
13283 \SpecialChar ~
13284 \SpecialChar ~
13285 \SpecialChar ~
13286 \SpecialChar ~
13287 mov  r1,a 
13288 \newline 
13289 \SpecialChar ~
13290 \SpecialChar ~
13291 \SpecialChar ~
13292 \SpecialChar ~
13293 mov  a,@r0 
13294 \newline 
13295 \SpecialChar ~
13296 \SpecialChar ~
13297 \SpecialChar ~
13298 \SpecialChar ~
13299 add  a,r2 ;?
13300 \newline 
13301 \SpecialChar ~
13302 \SpecialChar ~
13303 \SpecialChar ~
13304 \SpecialChar ~
13305 mov  dpl,a 
13306 \newline 
13307 \SpecialChar ~
13308 \SpecialChar ~
13309 \SpecialChar ~
13310 \SpecialChar ~
13311 mov  dph,#0x00 
13312 \newline 
13313 \SpecialChar ~
13314 \SpecialChar ~
13315 \SpecialChar ~
13316 \SpecialChar ~
13317 mov  sp,_bp 
13318 \newline 
13319 \SpecialChar ~
13320 \SpecialChar ~
13321 \SpecialChar ~
13322 \SpecialChar ~
13323 pop  _bp 
13324 \newline 
13325 \SpecialChar ~
13326 \SpecialChar ~
13327 \SpecialChar ~
13328 \SpecialChar ~
13329 ret
13330 \layout Standard
13331
13332 The compiling and linking procedure remains the same, however note the extra
13333  entry & exit linkage required for the assembler code, _bp is the stack
13334  frame pointer and is used to compute the offset into the stack for parameters
13335  and local variables.
13336 \layout Section
13337
13338 int (16 bit)
13339 \begin_inset LatexCommand \index{int (16 bit)}
13340
13341 \end_inset 
13342
13343  and long (32 bit)
13344 \begin_inset LatexCommand \index{long (32 bit)}
13345
13346 \end_inset 
13347
13348  Support
13349 \layout Standard
13350
13351 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
13352  multiplication and modulus operations are implemented by support routines.
13353  These support routines are all developed in ANSI-C to facilitate porting
13354  to other MCUs, although some model specific assembler optimizations are
13355  used.
13356  The following files contain the described routines, all of them can be
13357  found in <installdir>/share/sdcc/lib.
13358 \newline 
13359
13360 \layout Standard
13361 \align center 
13362
13363 \begin_inset  Tabular
13364 <lyxtabular version="3" rows="11" columns="2">
13365 <features>
13366 <column alignment="center" valignment="top" leftline="true" width="0">
13367 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
13368 <row topline="true" bottomline="true">
13369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13370 \begin_inset Text
13371
13372 \layout Standard
13373
13374
13375 \series bold 
13376 Function
13377 \end_inset 
13378 </cell>
13379 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13380 \begin_inset Text
13381
13382 \layout Standard
13383
13384
13385 \series bold 
13386 Description
13387 \end_inset 
13388 </cell>
13389 </row>
13390 <row topline="true">
13391 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13392 \begin_inset Text
13393
13394 \layout Standard
13395
13396 _mulint.c 
13397 \end_inset 
13398 </cell>
13399 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13400 \begin_inset Text
13401
13402 \layout Standard
13403
13404 16 bit multiplication
13405 \end_inset 
13406 </cell>
13407 </row>
13408 <row topline="true">
13409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13410 \begin_inset Text
13411
13412 \layout Standard
13413
13414 _divsint.c 
13415 \end_inset 
13416 </cell>
13417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13418 \begin_inset Text
13419
13420 \layout Standard
13421
13422  signed 16 bit division (calls _divuint)
13423 \end_inset 
13424 </cell>
13425 </row>
13426 <row topline="true">
13427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13428 \begin_inset Text
13429
13430 \layout Standard
13431
13432 _divuint.c 
13433 \end_inset 
13434 </cell>
13435 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13436 \begin_inset Text
13437
13438 \layout Standard
13439
13440  unsigned 16 bit division
13441 \end_inset 
13442 </cell>
13443 </row>
13444 <row topline="true">
13445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13446 \begin_inset Text
13447
13448 \layout Standard
13449
13450 _modsint.c
13451 \end_inset 
13452 </cell>
13453 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13454 \begin_inset Text
13455
13456 \layout Standard
13457
13458 signed 16 bit modulus (calls _moduint)
13459 \end_inset 
13460 </cell>
13461 </row>
13462 <row topline="true">
13463 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13464 \begin_inset Text
13465
13466 \layout Standard
13467
13468 _moduint.c
13469 \end_inset 
13470 </cell>
13471 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13472 \begin_inset Text
13473
13474 \layout Standard
13475
13476 unsigned 16 bit modulus
13477 \end_inset 
13478 </cell>
13479 </row>
13480 <row topline="true">
13481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13482 \begin_inset Text
13483
13484 \layout Standard
13485
13486 _mullong.c
13487 \end_inset 
13488 </cell>
13489 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13490 \begin_inset Text
13491
13492 \layout Standard
13493
13494 32 bit multiplication
13495 \end_inset 
13496 </cell>
13497 </row>
13498 <row topline="true">
13499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13500 \begin_inset Text
13501
13502 \layout Standard
13503
13504 _divslong.c 
13505 \end_inset 
13506 </cell>
13507 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13508 \begin_inset Text
13509
13510 \layout Standard
13511
13512  signed 32 division (calls _divulong)
13513 \end_inset 
13514 </cell>
13515 </row>
13516 <row topline="true">
13517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13518 \begin_inset Text
13519
13520 \layout Standard
13521
13522 _divulong.c 
13523 \end_inset 
13524 </cell>
13525 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13526 \begin_inset Text
13527
13528 \layout Standard
13529
13530 unsigned 32 division
13531 \end_inset 
13532 </cell>
13533 </row>
13534 <row topline="true">
13535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13536 \begin_inset Text
13537
13538 \layout Standard
13539
13540 _modslong.c
13541 \end_inset 
13542 </cell>
13543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13544 \begin_inset Text
13545
13546 \layout Standard
13547
13548  signed 32 bit modulus (calls _modulong)
13549 \end_inset 
13550 </cell>
13551 </row>
13552 <row topline="true" bottomline="true">
13553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13554 \begin_inset Text
13555
13556 \layout Standard
13557
13558 _modulong.c
13559 \end_inset 
13560 </cell>
13561 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13562 \begin_inset Text
13563
13564 \layout Standard
13565
13566 unsigned 32 bit modulus
13567 \end_inset 
13568 </cell>
13569 </row>
13570 </lyxtabular>
13571
13572 \end_inset 
13573
13574
13575 \newline 
13576
13577 \layout Standard
13578
13579 Since they are compiled as 
13580 \emph on 
13581 non-reentrant
13582 \emph default 
13583
13584 \begin_inset LatexCommand \index{reentrant}
13585
13586 \end_inset 
13587
13588 , interrupt
13589 \begin_inset LatexCommand \index{interrupt}
13590
13591 \end_inset 
13592
13593  service routines should not do any of the above operations.
13594  If this is unavoidable then the above routines will need to be compiled
13595  with the 
13596 \emph on 
13597 -
13598 \begin_inset ERT
13599 status Collapsed
13600
13601 \layout Standard
13602
13603 \backslash 
13604 /
13605 \end_inset 
13606
13607 -stack-auto
13608 \begin_inset LatexCommand \index{-\/-stack-auto}
13609
13610 \end_inset 
13611
13612
13613 \emph default 
13614  option, after which the source program will have to be compiled with 
13615 \emph on 
13616 -
13617 \begin_inset ERT
13618 status Collapsed
13619
13620 \layout Standard
13621
13622 \backslash 
13623 /
13624 \end_inset 
13625
13626 -int-long-reent
13627 \begin_inset LatexCommand \index{-\/-int-long-reent}
13628
13629 \end_inset 
13630
13631
13632 \emph default 
13633  option.
13634  Notice that you don't have to call these routines directly.
13635  The compiler will use them automatically every time an integer operation
13636  is required.
13637 \layout Section
13638
13639 Floating Point Support
13640 \begin_inset LatexCommand \index{Floating point support}
13641
13642 \end_inset 
13643
13644
13645 \layout Standard
13646
13647 SDCC supports IEEE (single precision 4 bytes) floating point numbers.The
13648  floating point support routines are derived from gcc's floatlib.c and consist
13649  of the following routines:
13650 \newline 
13651
13652 \layout Standard
13653 \align center 
13654
13655 \size footnotesize 
13656
13657 \begin_inset  Tabular
13658 <lyxtabular version="3" rows="17" columns="2">
13659 <features>
13660 <column alignment="center" valignment="top" leftline="true" width="0">
13661 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
13662 <row topline="true" bottomline="true">
13663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13664 \begin_inset Text
13665
13666 \layout Standard
13667
13668
13669 \family roman 
13670 \series medium 
13671 \shape up 
13672 \size normal 
13673 \emph off 
13674 \bar no 
13675 \noun off 
13676 \color none
13677 Function 
13678 \end_inset 
13679 </cell>
13680 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13681 \begin_inset Text
13682
13683 \layout Standard
13684
13685 Description
13686 \end_inset 
13687 </cell>
13688 </row>
13689 <row topline="true">
13690 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13691 \begin_inset Text
13692
13693 \layout Standard
13694
13695
13696 \family roman 
13697 \series medium 
13698 \shape up 
13699 \size normal 
13700 \emph off 
13701 \bar no 
13702 \noun off 
13703 \color none
13704 _fsadd.c
13705 \end_inset 
13706 </cell>
13707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13708 \begin_inset Text
13709
13710 \layout Standard
13711
13712
13713 \family roman 
13714 \series medium 
13715 \shape up 
13716 \size normal 
13717 \emph off 
13718 \bar no 
13719 \noun off 
13720 \color none
13721 add floating point numbers
13722 \end_inset 
13723 </cell>
13724 </row>
13725 <row topline="true">
13726 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13727 \begin_inset Text
13728
13729 \layout Standard
13730
13731
13732 \family roman 
13733 \series medium 
13734 \shape up 
13735 \size normal 
13736 \emph off 
13737 \bar no 
13738 \noun off 
13739 \color none
13740 _fssub.c 
13741 \end_inset 
13742 </cell>
13743 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13744 \begin_inset Text
13745
13746 \layout Standard
13747
13748
13749 \family roman 
13750 \series medium 
13751 \shape up 
13752 \size normal 
13753 \emph off 
13754 \bar no 
13755 \noun off 
13756 \color none
13757 subtract floating point numbers 
13758 \end_inset 
13759 </cell>
13760 </row>
13761 <row topline="true">
13762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13763 \begin_inset Text
13764
13765 \layout Standard
13766
13767
13768 \family roman 
13769 \series medium 
13770 \shape up 
13771 \size normal 
13772 \emph off 
13773 \bar no 
13774 \noun off 
13775 \color none
13776 _fsdiv.c 
13777 \end_inset 
13778 </cell>
13779 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13780 \begin_inset Text
13781
13782 \layout Standard
13783
13784
13785 \family roman 
13786 \series medium 
13787 \shape up 
13788 \size normal 
13789 \emph off 
13790 \bar no 
13791 \noun off 
13792 \color none
13793 divide floating point numbers 
13794 \end_inset 
13795 </cell>
13796 </row>
13797 <row topline="true">
13798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13799 \begin_inset Text
13800
13801 \layout Standard
13802
13803
13804 \family roman 
13805 \series medium 
13806 \shape up 
13807 \size normal 
13808 \emph off 
13809 \bar no 
13810 \noun off 
13811 \color none
13812 _fsmul.c 
13813 \end_inset 
13814 </cell>
13815 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13816 \begin_inset Text
13817
13818 \layout Standard
13819
13820
13821 \family roman 
13822 \series medium 
13823 \shape up 
13824 \size normal 
13825 \emph off 
13826 \bar no 
13827 \noun off 
13828 \color none
13829 multiply floating point numbers 
13830 \end_inset 
13831 </cell>
13832 </row>
13833 <row topline="true">
13834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13835 \begin_inset Text
13836
13837 \layout Standard
13838
13839
13840 \family roman 
13841 \series medium 
13842 \shape up 
13843 \size normal 
13844 \emph off 
13845 \bar no 
13846 \noun off 
13847 \color none
13848 _fs2uchar.c
13849 \end_inset 
13850 </cell>
13851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13852 \begin_inset Text
13853
13854 \layout Standard
13855
13856
13857 \family roman 
13858 \series medium 
13859 \shape up 
13860 \size normal 
13861 \emph off 
13862 \bar no 
13863 \noun off 
13864 \color none
13865 convert floating point to unsigned char
13866 \end_inset 
13867 </cell>
13868 </row>
13869 <row topline="true">
13870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13871 \begin_inset Text
13872
13873 \layout Standard
13874
13875
13876 \family roman 
13877 \series medium 
13878 \shape up 
13879 \size normal 
13880 \emph off 
13881 \bar no 
13882 \noun off 
13883 \color none
13884 _fs2char.c
13885 \end_inset 
13886 </cell>
13887 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13888 \begin_inset Text
13889
13890 \layout Standard
13891
13892
13893 \family roman 
13894 \series medium 
13895 \shape up 
13896 \size normal 
13897 \emph off 
13898 \bar no 
13899 \noun off 
13900 \color none
13901 convert floating point to signed char
13902 \end_inset 
13903 </cell>
13904 </row>
13905 <row topline="true">
13906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13907 \begin_inset Text
13908
13909 \layout Standard
13910
13911
13912 \family roman 
13913 \series medium 
13914 \shape up 
13915 \size normal 
13916 \emph off 
13917 \bar no 
13918 \noun off 
13919 \color none
13920 _fs2uint.c
13921 \end_inset 
13922 </cell>
13923 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13924 \begin_inset Text
13925
13926 \layout Standard
13927
13928
13929 \family roman 
13930 \series medium 
13931 \shape up 
13932 \size normal 
13933 \emph off 
13934 \bar no 
13935 \noun off 
13936 \color none
13937 convert floating point to unsigned int
13938 \end_inset 
13939 </cell>
13940 </row>
13941 <row topline="true">
13942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13943 \begin_inset Text
13944
13945 \layout Standard
13946
13947
13948 \family roman 
13949 \series medium 
13950 \shape up 
13951 \size normal 
13952 \emph off 
13953 \bar no 
13954 \noun off 
13955 \color none
13956 _fs2int.c
13957 \end_inset 
13958 </cell>
13959 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13960 \begin_inset Text
13961
13962 \layout Standard
13963
13964
13965 \family roman 
13966 \series medium 
13967 \shape up 
13968 \size normal 
13969 \emph off 
13970 \bar no 
13971 \noun off 
13972 \color none
13973 convert floating point to signed int
13974 \end_inset 
13975 </cell>
13976 </row>
13977 <row topline="true">
13978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13979 \begin_inset Text
13980
13981 \layout Standard
13982
13983
13984 \family roman 
13985 \series medium 
13986 \shape up 
13987 \size normal 
13988 \emph off 
13989 \bar no 
13990 \noun off 
13991 \color none
13992 _fs2ulong.
13993 \family default 
13994 \series default 
13995 \shape default 
13996 \size default 
13997 \emph default 
13998 \bar default 
13999 \noun default 
14000 \color default
14001 c
14002 \end_inset 
14003 </cell>
14004 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14005 \begin_inset Text
14006
14007 \layout Standard
14008
14009
14010 \family roman 
14011 \series medium 
14012 \shape up 
14013 \size normal 
14014 \emph off 
14015 \bar no 
14016 \noun off 
14017 \color none
14018 convert floating point to unsigned long
14019 \end_inset 
14020 </cell>
14021 </row>
14022 <row topline="true">
14023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14024 \begin_inset Text
14025
14026 \layout Standard
14027
14028
14029 \family roman 
14030 \series medium 
14031 \shape up 
14032 \size normal 
14033 \emph off 
14034 \bar no 
14035 \noun off 
14036 \color none
14037 _fs2long.c
14038 \end_inset 
14039 </cell>
14040 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14041 \begin_inset Text
14042
14043 \layout Standard
14044
14045
14046 \family roman 
14047 \series medium 
14048 \shape up 
14049 \size normal 
14050 \emph off 
14051 \bar no 
14052 \noun off 
14053 \color none
14054 convert floating point to signed long
14055 \end_inset 
14056 </cell>
14057 </row>
14058 <row topline="true">
14059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14060 \begin_inset Text
14061
14062 \layout Standard
14063
14064
14065 \family roman 
14066 \series medium 
14067 \shape up 
14068 \size normal 
14069 \emph off 
14070 \bar no 
14071 \noun off 
14072 \color none
14073 _uchar2fs.c
14074 \end_inset 
14075 </cell>
14076 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14077 \begin_inset Text
14078
14079 \layout Standard
14080
14081
14082 \family roman 
14083 \series medium 
14084 \shape up 
14085 \size normal 
14086 \emph off 
14087 \bar no 
14088 \noun off 
14089 \color none
14090 convert unsigned char to floating point
14091 \end_inset 
14092 </cell>
14093 </row>
14094 <row topline="true">
14095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14096 \begin_inset Text
14097
14098 \layout Standard
14099
14100
14101 \family roman 
14102 \series medium 
14103 \shape up 
14104 \size normal 
14105 \emph off 
14106 \bar no 
14107 \noun off 
14108 \color none
14109 _char2fs.c
14110 \end_inset 
14111 </cell>
14112 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14113 \begin_inset Text
14114
14115 \layout Standard
14116
14117
14118 \family roman 
14119 \series medium 
14120 \shape up 
14121 \size normal 
14122 \emph off 
14123 \bar no 
14124 \noun off 
14125 \color none
14126 convert char to floating point number
14127 \end_inset 
14128 </cell>
14129 </row>
14130 <row topline="true">
14131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14132 \begin_inset Text
14133
14134 \layout Standard
14135
14136
14137 \family roman 
14138 \series medium 
14139 \shape up 
14140 \size normal 
14141 \emph off 
14142 \bar no 
14143 \noun off 
14144 \color none
14145 _uint2fs.c
14146 \end_inset 
14147 </cell>
14148 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14149 \begin_inset Text
14150
14151 \layout Standard
14152
14153
14154 \family roman 
14155 \series medium 
14156 \shape up 
14157 \size normal 
14158 \emph off 
14159 \bar no 
14160 \noun off 
14161 \color none
14162 convert unsigned int to floating point
14163 \end_inset 
14164 </cell>
14165 </row>
14166 <row topline="true">
14167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14168 \begin_inset Text
14169
14170 \layout Standard
14171
14172
14173 \family roman 
14174 \series medium 
14175 \shape up 
14176 \size normal 
14177 \emph off 
14178 \bar no 
14179 \noun off 
14180 \color none
14181 _int2fs.c
14182 \end_inset 
14183 </cell>
14184 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14185 \begin_inset Text
14186
14187 \layout Standard
14188
14189
14190 \family roman 
14191 \series medium 
14192 \shape up 
14193 \size normal 
14194 \emph off 
14195 \bar no 
14196 \noun off 
14197 \color none
14198 convert int to floating point numbers
14199 \end_inset 
14200 </cell>
14201 </row>
14202 <row topline="true">
14203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14204 \begin_inset Text
14205
14206 \layout Standard
14207
14208
14209 \family roman 
14210 \series medium 
14211 \shape up 
14212 \size normal 
14213 \emph off 
14214 \bar no 
14215 \noun off 
14216 \color none
14217 _ulong2fs.c
14218 \end_inset 
14219 </cell>
14220 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14221 \begin_inset Text
14222
14223 \layout Standard
14224
14225
14226 \family roman 
14227 \series medium 
14228 \shape up 
14229 \size normal 
14230 \emph off 
14231 \bar no 
14232 \noun off 
14233 \color none
14234 convert unsigned long to floating point number
14235 \end_inset 
14236 </cell>
14237 </row>
14238 <row topline="true" bottomline="true">
14239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14240 \begin_inset Text
14241
14242 \layout Standard
14243
14244
14245 \family roman 
14246 \series medium 
14247 \shape up 
14248 \size normal 
14249 \emph off 
14250 \bar no 
14251 \noun off 
14252 \color none
14253 _long2fs.c
14254 \end_inset 
14255 </cell>
14256 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14257 \begin_inset Text
14258
14259 \layout Standard
14260
14261
14262 \family roman 
14263 \series medium 
14264 \shape up 
14265 \size normal 
14266 \emph off 
14267 \bar no 
14268 \noun off 
14269 \color none
14270 convert long to floating point number
14271 \end_inset 
14272 </cell>
14273 </row>
14274 </lyxtabular>
14275
14276 \end_inset 
14277
14278
14279 \newline 
14280
14281 \layout Standard
14282
14283 These support routines are developed in ANSI-C so there is room for space
14284  and speed improvement
14285 \begin_inset Foot
14286 collapsed false
14287
14288 \layout Standard
14289
14290 The floating point routines for the mcs51 are implemented in assembler
14291 \end_inset 
14292
14293 .
14294  Note if all these routines are used simultaneously the data space might
14295  overflow.
14296  For serious floating point usage the large model might be needed.
14297  Also notice that you don't have to call this routines directly.
14298  The compiler will use them automatically every time a floating point operation
14299  is required.
14300 \layout Section
14301
14302 Library Routines
14303 \begin_inset LatexCommand \index{Libraries}
14304
14305 \end_inset 
14306
14307
14308 \layout Standard
14309
14310
14311 \emph on 
14312 <pending: this is messy and incomplete - a little more information is in
14313  sdcc/doc/libdoc.txt
14314 \emph default 
14315  >
14316 \layout Subsection
14317
14318 Compiler support routines (_gptrget, _mulint etc.)
14319 \layout Subsection
14320
14321 Stdclib functions (puts, printf, strcat etc.)
14322 \layout Subsubsection
14323
14324 <stdio.h>
14325 \layout Standard
14326
14327
14328 \begin_inset LatexCommand \index{<stdio.h>}
14329
14330 \end_inset 
14331
14332 As usual on embedded systems you have to provide your own 
14333 \family typewriter 
14334 getchar()
14335 \begin_inset LatexCommand \index{getchar()}
14336
14337 \end_inset 
14338
14339  
14340 \family default 
14341 and 
14342 \family typewriter 
14343 putchar()
14344 \begin_inset LatexCommand \index{putchar()}
14345
14346 \end_inset 
14347
14348
14349 \family default 
14350  routines.
14351  SDCC does not know whether the system connects to a serial line with or
14352  without handshake, LCD, keyboard or other device.
14353  You'll find examples for serial routines f.e.
14354  in sdcc/device/lib.
14355 \layout Standard
14356
14357 The default
14358 \family typewriter 
14359  printf()
14360 \begin_inset LatexCommand \index{printf()}
14361
14362 \end_inset 
14363
14364
14365 \family default 
14366 implementation in
14367 \family typewriter 
14368  printf_large.c
14369 \family default 
14370  does not support float (except on ds390).
14371  To enable this recompile it with the option 
14372 \emph on 
14373 -
14374 \begin_inset ERT
14375 status Collapsed
14376
14377 \layout Standard
14378
14379 \backslash 
14380 /
14381 \end_inset 
14382
14383 DUSE_FLOATS=1
14384 \begin_inset LatexCommand \index{USE\_FLOATS}
14385
14386 \end_inset 
14387
14388
14389 \emph default 
14390  on the command line.
14391  Use
14392 \emph on 
14393 -
14394 \begin_inset ERT
14395 status Collapsed
14396
14397 \layout Standard
14398
14399 \backslash 
14400 /
14401 \end_inset 
14402
14403 -model-large
14404 \begin_inset LatexCommand \index{-\/-model-large}
14405
14406 \end_inset 
14407
14408
14409 \emph default 
14410  for the mcs51 port, since this uses a lot of memory.
14411 \layout Standard
14412
14413 If you're short on memory you might want to use 
14414 \family typewriter 
14415 printf_small()
14416 \begin_inset LatexCommand \index{printf\_small()}
14417
14418 \end_inset 
14419
14420
14421 \family default 
14422  
14423 \emph on 
14424 instead
14425 \emph default 
14426  of
14427 \family typewriter 
14428  printf().
14429
14430 \family default 
14431  For the mcs51 there additionally are assembly versions 
14432 \family typewriter 
14433 printf_tiny()
14434 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
14435
14436 \end_inset 
14437
14438
14439 \family default 
14440  and 
14441 \family typewriter 
14442 printf_fast()
14443 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
14444
14445 \end_inset 
14446
14447  
14448 \family default 
14449 and
14450 \family typewriter 
14451  printf_fast_f()
14452 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
14453
14454 \end_inset 
14455
14456
14457 \family default 
14458  which should fit the requirements of many embedded systems (printf_fast()
14459  can be customized by unsetting #defines to 
14460 \emph on 
14461 not
14462 \emph default 
14463  support long variables and field widths).
14464 \layout Subsection
14465
14466 Math functions (sin, pow, sqrt etc.)
14467 \layout Subsection
14468
14469 Other libraries
14470 \layout Standard
14471
14472 Libraries
14473 \begin_inset LatexCommand \index{Libraries}
14474
14475 \end_inset 
14476
14477  included in SDCC should have a license at least as liberal as the GNU Lesser
14478  General Public License
14479 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
14480
14481 \end_inset 
14482
14483  
14484 \emph on 
14485 LGPL
14486 \emph default 
14487 .
14488 \layout Comment
14489
14490 license statements for the libraries are missing.
14491  sdcc/device/lib/ser_ir.c
14492 \layout Comment
14493
14494 or _decdptr f.e.
14495  come with a GPL (as opposed to LGPL) License - this will not be liberal
14496  enough for many embedded programmers.
14497 \layout Standard
14498
14499 If you have ported some library or want to share experience about some code
14500  which f.e.
14501  falls into any of these categories Busses (I
14502 \begin_inset Formula $^{\textrm{2}}$
14503 \end_inset 
14504
14505 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
14506  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
14507  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
14508 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
14509
14510 \end_inset 
14511
14512 \SpecialChar ~
14513 would certainly like to hear about it.
14514  Programmers coding for embedded systems are not especially famous for being
14515  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
14516 e these references are very valuable.
14517  Let's help to create a climate where information is shared.
14518 \layout Section
14519
14520 Memory Models
14521 \layout Subsection
14522
14523 MCS51 Memory Models
14524 \begin_inset LatexCommand \index{Memory model}
14525
14526 \end_inset 
14527
14528
14529 \begin_inset LatexCommand \index{MCS51 memory model}
14530
14531 \end_inset 
14532
14533
14534 \layout Subsubsection
14535
14536 Small and Large
14537 \layout Standard
14538
14539 SDCC allows two memory models for MCS51 code, 
14540 \shape slanted 
14541 small
14542 \shape default 
14543  and 
14544 \shape slanted 
14545 large
14546 \shape default 
14547 .
14548  Modules compiled with different memory models should 
14549 \emph on 
14550 never
14551 \emph default 
14552  be combined together or the results would be unpredictable.
14553  The library routines supplied with the compiler are compiled as both small
14554  and large.
14555  The compiled library modules are contained in separate directories as small
14556  and large so that you can link to either set.
14557  
14558 \layout Standard
14559
14560 When the large model is used all variables declared without a storage class
14561  will be allocated into the external ram, this includes all parameters and
14562  local variables (for non-reentrant
14563 \begin_inset LatexCommand \index{reentrant}
14564
14565 \end_inset 
14566
14567  functions).
14568  When the small model is used variables without storage class are allocated
14569  in the internal ram.
14570 \layout Standard
14571
14572 Judicious usage of the processor specific storage classes
14573 \begin_inset LatexCommand \index{Storage class}
14574
14575 \end_inset 
14576
14577  and the 'reentrant' function type will yield much more efficient code,
14578  than using the large model.
14579  Several optimizations are disabled when the program is compiled using the
14580  large model, it is therefore recommended that the small model be used unless
14581  absolutely required.
14582 \layout Subsubsection
14583
14584 External Stack
14585 \begin_inset LatexCommand \label{sub:External-Stack}
14586
14587 \end_inset 
14588
14589
14590 \begin_inset LatexCommand \index{stack}
14591
14592 \end_inset 
14593
14594
14595 \begin_inset LatexCommand \index{External stack (mcs51)}
14596
14597 \end_inset 
14598
14599
14600 \layout Standard
14601
14602 The external stack (-
14603 \begin_inset ERT
14604 status Collapsed
14605
14606 \layout Standard
14607
14608 \backslash 
14609 /
14610 \end_inset 
14611
14612 -xstack option
14613 \begin_inset LatexCommand \index{-\/-xstack}
14614
14615 \end_inset 
14616
14617 ) is located in pdata
14618 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
14619
14620 \end_inset 
14621
14622  memory (usually at the start of the external ram segment) and uses all
14623  unused space in pdata (max.
14624  256 bytes).
14625  When -
14626 \begin_inset ERT
14627 status Collapsed
14628
14629 \layout Standard
14630
14631 \backslash 
14632 /
14633 \end_inset 
14634
14635 -xstack option is used to compile the program, the parameters and local
14636  variables
14637 \begin_inset LatexCommand \index{local variables}
14638
14639 \end_inset 
14640
14641  of all reentrant functions are allocated in this area.
14642  This option is provided for programs with large stack space requirements.
14643  When used with the -
14644 \begin_inset ERT
14645 status Collapsed
14646
14647 \layout Standard
14648
14649 \backslash 
14650 /
14651 \end_inset 
14652
14653 -stack-auto
14654 \begin_inset LatexCommand \index{-\/-stack-auto}
14655
14656 \end_inset 
14657
14658  option, all parameters and local variables are allocated on the external
14659  stack (note: support libraries will need to be recompiled with the same
14660  options.
14661  There is a predefined target in the library makefile).
14662 \layout Standard
14663
14664 The compiler outputs the higher order address byte of the external ram segment
14665  into port P2
14666 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
14667
14668 \end_inset 
14669
14670  (see also section 
14671 \begin_inset LatexCommand \ref{sub:MCS51-variants}
14672
14673 \end_inset 
14674
14675 ), therefore when using the External Stack option, this port 
14676 \emph on 
14677 may not
14678 \emph default 
14679  be used by the application program.
14680 \layout Subsection
14681
14682 DS390 Memory Model
14683 \begin_inset LatexCommand \index{Memory model}
14684
14685 \end_inset 
14686
14687
14688 \begin_inset LatexCommand \index{DS390 memory model}
14689
14690 \end_inset 
14691
14692
14693 \layout Standard
14694
14695 The only model supported is Flat 24
14696 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
14697
14698 \end_inset 
14699
14700 .
14701  This generates code for the 24 bit contiguous addressing mode of the Dallas
14702  DS80C390 part.
14703  In this mode, up to four meg of external RAM or code space can be directly
14704  addressed.
14705  See the data sheets at www.dalsemi.com for further information on this part.
14706 \newline 
14707
14708 \newline 
14709 Note that the compiler does not generate any code to place the processor
14710  into 24 bitmode (although 
14711 \emph on 
14712 tinibios
14713 \emph default 
14714  in the ds390 libraries will do that for you).
14715  If you don't use 
14716 \emph on 
14717 tinibios
14718 \emph default 
14719
14720 \begin_inset LatexCommand \index{Tinibios (DS390)}
14721
14722 \end_inset 
14723
14724 , the boot loader or similar code must ensure that the processor is in 24
14725  bit contiguous addressing mode before calling the SDCC startup code.
14726 \newline 
14727
14728 \newline 
14729 Like the 
14730 \emph on 
14731 -
14732 \begin_inset ERT
14733 status Collapsed
14734
14735 \layout Standard
14736
14737 \backslash 
14738 /
14739 \end_inset 
14740
14741 -model-large
14742 \emph default 
14743  option, variables will by default be placed into the XDATA segment.
14744  
14745 \newline 
14746
14747 \newline 
14748 Segments may be placed anywhere in the 4 meg address space using the usual
14749  -
14750 \begin_inset ERT
14751 status Collapsed
14752
14753 \layout Standard
14754
14755 \backslash 
14756 /
14757 \end_inset 
14758
14759 -*-loc options.
14760  Note that if any segments are located above 64K, the -r flag must be passed
14761  to the linker to generate the proper segment relocations, and the Intel
14762  HEX output format must be used.
14763  The -r flag can be passed to the linker by using the option 
14764 \emph on 
14765 -Wl-r
14766 \emph default 
14767  on the SDCC command line.
14768  However, currently the linker can not handle code segments > 64k.
14769 \layout Section
14770
14771 Pragmas
14772 \begin_inset LatexCommand \index{Pragmas}
14773
14774 \end_inset 
14775
14776
14777 \layout Standard
14778
14779 SDCC supports the following #pragma directives:
14780 \layout Itemize
14781
14782 save
14783 \begin_inset LatexCommand \index{\#pragma save}
14784
14785 \end_inset 
14786
14787  - this will save all current options to the save/restore stack.
14788  See #pragma\SpecialChar ~
14789 restore.
14790 \layout Itemize
14791
14792 restore
14793 \begin_inset LatexCommand \index{\#pragma restore}
14794
14795 \end_inset 
14796
14797  - will restore saved options from the last save.
14798  saves & restores can be nested.
14799  SDCC uses a save/restore stack: save pushes current options to the stack,
14800  restore pulls current options from the stack.
14801  See #pragma\SpecialChar ~
14802 save.
14803 \newline 
14804
14805 \layout Itemize
14806
14807 callee_saves
14808 \begin_inset LatexCommand \index{\#pragma callee\_saves}
14809
14810 \end_inset 
14811
14812
14813 \begin_inset LatexCommand \index{function prologue}
14814
14815 \end_inset 
14816
14817  function1[,function2[,function3...]] - The compiler by default uses a caller
14818  saves convention for register saving across function calls, however this
14819  can cause unnecessary register pushing & popping
14820 \begin_inset LatexCommand \index{push/pop}
14821
14822 \end_inset 
14823
14824  when calling small functions from larger functions.
14825  This option can be used to switch off the register saving convention for
14826  the function names specified.
14827  The compiler will not save registers when calling these functions, extra
14828  code need to be manually inserted at the entry & exit for these functions
14829  to save & restore the registers used by these functions, this can SUBSTANTIALLY
14830  reduce code & improve run time performance of the generated code.
14831  In the future the compiler (with inter procedural analysis) may be able
14832  to determine the appropriate scheme to use for each function call.
14833  If -
14834 \begin_inset ERT
14835 status Collapsed
14836
14837 \layout Standard
14838
14839 \backslash 
14840 /
14841 \end_inset 
14842
14843 -callee-saves command line option is used, the function names specified
14844  in #pragma\SpecialChar ~
14845 callee_saves
14846 \begin_inset LatexCommand \index{\#pragma callee\_saves}
14847
14848 \end_inset 
14849
14850  is appended to the list of functions specified in the command line.
14851 \layout Itemize
14852
14853 exclude
14854 \begin_inset LatexCommand \index{\#pragma exclude}
14855
14856 \end_inset 
14857
14858  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
14859  of pairs of push/pop
14860 \begin_inset LatexCommand \index{push/pop}
14861
14862 \end_inset 
14863
14864  instructions in 
14865 \emph on 
14866 I
14867 \emph default 
14868 nterrupt
14869 \begin_inset LatexCommand \index{interrupt}
14870
14871 \end_inset 
14872
14873  
14874 \emph on 
14875 S
14876 \emph default 
14877 ervice 
14878 \emph on 
14879 R
14880 \emph default 
14881 outines.
14882  The directive should be placed immediately before the ISR function definition
14883  and it affects ALL ISR functions following it.
14884  To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
14885 exclude\SpecialChar ~
14886 none
14887 \begin_inset LatexCommand \index{\#pragma exclude}
14888
14889 \end_inset 
14890
14891 .
14892  See also the related keyword _naked
14893 \begin_inset LatexCommand \index{\_naked}
14894
14895 \end_inset 
14896
14897
14898 \begin_inset LatexCommand \index{\_\_naked}
14899
14900 \end_inset 
14901
14902 .
14903 \layout Itemize
14904
14905 less_pedantic
14906 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
14907
14908 \end_inset 
14909
14910  - the compiler will not warn you anymore for obvious mistakes, you'r on
14911  your own now ;-(
14912 \layout Itemize
14913
14914 disable_warning <nnnn>
14915 \begin_inset LatexCommand \index{\#pragma disable\_warning}
14916
14917 \end_inset 
14918
14919  - the compiler will not warn you anymore about warning number <nnnn>.
14920 \layout Itemize
14921
14922 nogcse
14923 \begin_inset LatexCommand \index{\#pragma nogcse}
14924
14925 \end_inset 
14926
14927  - will stop global common subexpression elimination.
14928 \layout Itemize
14929
14930 noinduction
14931 \begin_inset LatexCommand \index{\#pragma noinduction}
14932
14933 \end_inset 
14934
14935  - will stop loop induction optimizations.
14936 \layout Itemize
14937
14938 noinvariant
14939 \begin_inset LatexCommand \index{\#pragma noinvariant}
14940
14941 \end_inset 
14942
14943  - will not do loop invariant optimizations.
14944  For more details see Loop Invariants in section
14945 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
14946
14947 \end_inset 
14948
14949 .
14950 \layout Itemize
14951
14952 noiv
14953 \begin_inset LatexCommand \index{\#pragma noiv}
14954
14955 \end_inset 
14956
14957  - Do not generate interrupt
14958 \begin_inset LatexCommand \index{interrupt}
14959
14960 \end_inset 
14961
14962  vector table entries for all ISR functions defined after the pragma.
14963  This is useful in cases where the interrupt vector table must be defined
14964  manually, or when there is a secondary, manually defined interrupt vector
14965  table (e.g.
14966  for the autovector feature of the Cypress EZ-USB FX2).
14967  More elegantly this can be achieved by obmitting the optional interrupt
14968  number after the interrupt keyword, see section 
14969 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
14970
14971 \end_inset 
14972
14973 \SpecialChar ~
14974 about interrupts.
14975 \layout Itemize
14976
14977 nojtbound
14978 \begin_inset LatexCommand \index{\#pragma nojtbound}
14979
14980 \end_inset 
14981
14982  - will not generate code for boundary value checking, when switch statements
14983  are turned into jump-tables (dangerous).
14984  For more details see section 
14985 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
14986
14987 \end_inset 
14988
14989 .
14990 \layout Itemize
14991
14992 noloopreverse
14993 \begin_inset LatexCommand \index{\#pragma noloopreverse}
14994
14995 \end_inset 
14996
14997  - Will not do loop reversal optimization
14998 \layout Itemize
14999
15000 nooverlay
15001 \begin_inset LatexCommand \index{\#pragma nooverlay}
15002
15003 \end_inset 
15004
15005  - the compiler will not overlay the parameters and local variables of a
15006  function.
15007 \layout Itemize
15008
15009 stackauto
15010 \begin_inset LatexCommand \index{\#pragma stackauto}
15011
15012 \end_inset 
15013
15014 - See option -
15015 \begin_inset ERT
15016 status Collapsed
15017
15018 \layout Standard
15019
15020 \backslash 
15021 /
15022 \end_inset 
15023
15024 -stack-auto
15025 \begin_inset LatexCommand \index{-\/-stack-auto}
15026
15027 \end_inset 
15028
15029  and section 
15030 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
15031
15032 \end_inset 
15033
15034  Parameters and Local Variables.
15035 \layout Itemize
15036
15037 opt_code_speed 
15038 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
15039
15040 \end_inset 
15041
15042 - The compiler will optimize code generation towards fast code, possibly
15043  at the expense of code size.
15044 \layout Itemize
15045
15046 opt_code_size 
15047 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
15048
15049 \end_inset 
15050
15051 - The compiler will optimize code generation towards compact code, possibly
15052  at the expense of code speed.
15053 \layout Itemize
15054
15055 opt_code_balanced 
15056 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
15057
15058 \end_inset 
15059
15060 - The compiler will attempt to generate code that is both compact and fast,
15061  as long as meeting one goal is not a detriment to the other (this is the
15062  default).
15063  
15064 \layout Itemize
15065
15066 std_sdcc89 
15067 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
15068
15069 \end_inset 
15070
15071 - Generally follow the C89 standard, but allow SDCC features that conflict
15072  with the standard (default).
15073 \layout Itemize
15074
15075 std_c89 
15076 \begin_inset LatexCommand \index{\#pragma std\_c89}
15077
15078 \end_inset 
15079
15080 - Follow the C89 standard and disable SDCC features that conflict with the
15081  standard.
15082 \layout Itemize
15083
15084 std_sdcc99 
15085 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
15086
15087 \end_inset 
15088
15089 - Generally follow the C99 standard, but allow SDCC features that conflict
15090  with the standard (incomplete support).
15091 \layout Itemize
15092
15093 std_c99 
15094 \begin_inset LatexCommand \index{\#pragma std\_c99}
15095
15096 \end_inset 
15097
15098 - Follow the C99 standard and disable SDCC features that conflict with the
15099  standard (incomplete support).
15100 \layout Standard
15101
15102 SDCPP supports the following #pragma directives:
15103 \layout Itemize
15104
15105 preproc_asm
15106 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
15107
15108 \end_inset 
15109
15110  (+ | -) - switch _asm _endasm block preprocessing on / off.
15111  Default is on.
15112 \layout Standard
15113
15114 The pragma's are intended to be used to turn-on or off certain optimizations
15115  which might cause the compiler to generate extra stack / data space to
15116  store compiler generated temporary variables.
15117  This usually happens in large functions.
15118  Pragma directives should be used as shown in the following example, they
15119  are used to control options & optimizations for a given function; pragmas
15120  should be placed before and/or after a function, placing pragma's inside
15121  a function body could have unpredictable results.
15122 \layout Verse
15123
15124
15125 \family typewriter 
15126 #pragma save
15127 \begin_inset LatexCommand \index{\#pragma save}
15128
15129 \end_inset 
15130
15131  \SpecialChar ~
15132 \SpecialChar ~
15133 \SpecialChar ~
15134 \SpecialChar ~
15135 \SpecialChar ~
15136 \SpecialChar ~
15137 \SpecialChar ~
15138 /* save the current settings */ 
15139 \newline 
15140 #pragma nogcse
15141 \begin_inset LatexCommand \index{\#pragma nogcse}
15142
15143 \end_inset 
15144
15145  \SpecialChar ~
15146 \SpecialChar ~
15147 \SpecialChar ~
15148 \SpecialChar ~
15149 \SpecialChar ~
15150 /* turnoff global subexpression elimination */ 
15151 \newline 
15152 #pragma noinduction
15153 \begin_inset LatexCommand \index{\#pragma noinduction}
15154
15155 \end_inset 
15156
15157  /* turn off induction optimizations */ 
15158 \newline 
15159 int foo () 
15160 \newline 
15161
15162 \newline 
15163 \SpecialChar ~
15164  \SpecialChar ~
15165  ...
15166  
15167 \newline 
15168 \SpecialChar ~
15169  \SpecialChar ~
15170  /* large code */ 
15171 \newline 
15172 \SpecialChar ~
15173  \SpecialChar ~
15174  ...
15175  
15176 \newline 
15177
15178 \newline 
15179 #pragma restore
15180 \begin_inset LatexCommand \index{\#pragma restore}
15181
15182 \end_inset 
15183
15184  /* turn the optimizations back on */
15185 \layout Standard
15186
15187 The compiler will generate a warning message when extra space is allocated.
15188  It is strongly recommended that the save and restore pragma's be used when
15189  changing options for a function.
15190 \layout Section
15191
15192 Defines Created by the Compiler
15193 \layout Standard
15194
15195 The compiler creates the following #defines
15196 \begin_inset LatexCommand \index{\#defines}
15197
15198 \end_inset 
15199
15200
15201 \begin_inset LatexCommand \index{Defines created by the compiler}
15202
15203 \end_inset 
15204
15205 :
15206 \newline 
15207
15208 \layout Standard
15209
15210
15211 \begin_inset  Tabular
15212 <lyxtabular version="3" rows="10" columns="2">
15213 <features>
15214 <column alignment="center" valignment="top" leftline="true" width="0">
15215 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15216 <row topline="true" bottomline="true">
15217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15218 \begin_inset Text
15219
15220 \layout Standard
15221
15222
15223 \series bold 
15224 #define
15225 \end_inset 
15226 </cell>
15227 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15228 \begin_inset Text
15229
15230 \layout Standard
15231
15232
15233 \series bold 
15234 Description
15235 \end_inset 
15236 </cell>
15237 </row>
15238 <row topline="true">
15239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15240 \begin_inset Text
15241
15242 \layout Standard
15243
15244 SDCC
15245 \begin_inset LatexCommand \index{SDCC}
15246
15247 \end_inset 
15248
15249  
15250 \end_inset 
15251 </cell>
15252 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15253 \begin_inset Text
15254
15255 \layout Standard
15256
15257 this Symbol is always defined
15258 \end_inset 
15259 </cell>
15260 </row>
15261 <row topline="true">
15262 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15263 \begin_inset Text
15264
15265 \layout Standard
15266
15267 SDCC_mcs51
15268 \begin_inset LatexCommand \index{SDCC\_mcs51}
15269
15270 \end_inset 
15271
15272  or SDCC_ds390
15273 \begin_inset LatexCommand \index{SDCC\_ds390}
15274
15275 \end_inset 
15276
15277  or SDCC_z80
15278 \begin_inset LatexCommand \index{SDCC\_z80}
15279
15280 \end_inset 
15281
15282 , etc
15283 \end_inset 
15284 </cell>
15285 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15286 \begin_inset Text
15287
15288 \layout Standard
15289
15290 depending on the model used (e.g.: -mds390
15291 \end_inset 
15292 </cell>
15293 </row>
15294 <row topline="true">
15295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15296 \begin_inset Text
15297
15298 \layout Standard
15299
15300 __mcs51
15301 \begin_inset LatexCommand \index{\_\_mcs51}
15302
15303 \end_inset 
15304
15305 , __ds390
15306 \begin_inset LatexCommand \index{\_\_ds390}
15307
15308 \end_inset 
15309
15310 , __hc08
15311 \begin_inset LatexCommand \index{\_\_hc08}
15312
15313 \end_inset 
15314
15315 , __z80
15316 \begin_inset LatexCommand \index{\_\_z80}
15317
15318 \end_inset 
15319
15320 , etc
15321 \end_inset 
15322 </cell>
15323 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15324 \begin_inset Text
15325
15326 \layout Standard
15327
15328 depending on the model used (e.g.
15329  -mz80)
15330 \end_inset 
15331 </cell>
15332 </row>
15333 <row topline="true">
15334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15335 \begin_inset Text
15336
15337 \layout Standard
15338
15339 SDCC_STACK_AUTO
15340 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
15341
15342 \end_inset 
15343
15344
15345 \end_inset 
15346 </cell>
15347 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15348 \begin_inset Text
15349
15350 \layout Standard
15351
15352 when 
15353 \emph on 
15354 -
15355 \begin_inset ERT
15356 status Collapsed
15357
15358 \layout Standard
15359
15360 \backslash 
15361 /
15362 \end_inset 
15363
15364 -stack-auto
15365 \emph default 
15366  option is used
15367 \end_inset 
15368 </cell>
15369 </row>
15370 <row topline="true">
15371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15372 \begin_inset Text
15373
15374 \layout Standard
15375
15376 SDCC_MODEL_SMALL
15377 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
15378
15379 \end_inset 
15380
15381
15382 \end_inset 
15383 </cell>
15384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15385 \begin_inset Text
15386
15387 \layout Standard
15388
15389 when 
15390 \emph on 
15391 -
15392 \begin_inset ERT
15393 status Collapsed
15394
15395 \layout Standard
15396
15397 \backslash 
15398 /
15399 \end_inset 
15400
15401 -model-small
15402 \emph default 
15403  is used
15404 \end_inset 
15405 </cell>
15406 </row>
15407 <row topline="true">
15408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15409 \begin_inset Text
15410
15411 \layout Standard
15412
15413 SDCC_MODEL_LARGE
15414 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
15415
15416 \end_inset 
15417
15418
15419 \end_inset 
15420 </cell>
15421 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15422 \begin_inset Text
15423
15424 \layout Standard
15425
15426 when 
15427 \emph on 
15428 -
15429 \begin_inset ERT
15430 status Collapsed
15431
15432 \layout Standard
15433
15434 \backslash 
15435 /
15436 \end_inset 
15437
15438 -model-large
15439 \emph default 
15440  is used
15441 \end_inset 
15442 </cell>
15443 </row>
15444 <row topline="true">
15445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15446 \begin_inset Text
15447
15448 \layout Standard
15449
15450 SDCC_USE_XSTACK
15451 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
15452
15453 \end_inset 
15454
15455
15456 \end_inset 
15457 </cell>
15458 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15459 \begin_inset Text
15460
15461 \layout Standard
15462
15463 when 
15464 \emph on 
15465 -
15466 \begin_inset ERT
15467 status Collapsed
15468
15469 \layout Standard
15470
15471 \backslash 
15472 /
15473 \end_inset 
15474
15475 -xstack
15476 \emph default 
15477  option is used
15478 \end_inset 
15479 </cell>
15480 </row>
15481 <row topline="true">
15482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15483 \begin_inset Text
15484
15485 \layout Standard
15486
15487 SDCC_STACK_TENBIT
15488 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
15489
15490 \end_inset 
15491
15492  
15493 \end_inset 
15494 </cell>
15495 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15496 \begin_inset Text
15497
15498 \layout Standard
15499
15500 when 
15501 \emph on 
15502 -mds390
15503 \emph default 
15504  is used
15505 \end_inset 
15506 </cell>
15507 </row>
15508 <row topline="true" bottomline="true">
15509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15510 \begin_inset Text
15511
15512 \layout Standard
15513
15514 SDCC_MODEL_FLAT24
15515 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
15516
15517 \end_inset 
15518
15519
15520 \end_inset 
15521 </cell>
15522 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15523 \begin_inset Text
15524
15525 \layout Standard
15526
15527 when 
15528 \emph on 
15529 -mds390
15530 \emph default 
15531  is used
15532 \end_inset 
15533 </cell>
15534 </row>
15535 </lyxtabular>
15536
15537 \end_inset 
15538
15539
15540 \layout Chapter
15541
15542 Notes on supported Processors
15543 \layout Section
15544
15545 MCS51 variants
15546 \begin_inset LatexCommand \label{sub:MCS51-variants}
15547
15548 \end_inset 
15549
15550
15551 \begin_inset LatexCommand \index{MCS51 variants}
15552
15553 \end_inset 
15554
15555
15556 \layout Standard
15557
15558 MCS51 processors are available from many vendors and come in many different
15559  flavours.
15560  While they might differ considerably in respect to Special Function Registers
15561  the core MCS51 is usually not modified or is kept compatible.
15562  
15563 \layout Subsection
15564
15565 pdata access by SFR 
15566 \layout Standard
15567
15568 With the upcome of devices with internal xdata and flash memory devices
15569  using port P2
15570 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
15571
15572 \end_inset 
15573
15574  as dedicated I/O port is becoming more popular.
15575  Switching the high byte for pdata
15576 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
15577
15578 \end_inset 
15579
15580  access which was formerly done by port P2 is then achieved by a Special
15581  Function Register
15582 \begin_inset LatexCommand \index{sfr}
15583
15584 \end_inset 
15585
15586 .
15587  In well-established MCS51 tradition the address of this 
15588 \emph on 
15589 sfr
15590 \emph default 
15591  is where the chip designers decided to put it.
15592  Needless to say that they didn't agree on a common name either.
15593  So that the startup code can correctly initialize xdata variables, you
15594  should define an sfr with the name _XPAGE
15595 \family typewriter 
15596
15597 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
15598
15599 \end_inset 
15600
15601
15602 \family default 
15603  at the appropriate location if the default, port P2, is not used for this.
15604  Some examples are:
15605 \layout Verse
15606
15607
15608 \family typewriter 
15609 sfr at 0x92 _XPAGE; /* Cypress EZ-USB family */
15610 \layout Verse
15611
15612
15613 \family typewriter 
15614 sfr at 0xaf _XPAGE; /* some Silicon Labs (Cygnal) chips */
15615 \layout Verse
15616
15617
15618 \family typewriter 
15619 sfr at 0xaa _XPAGE; /* some Silicon Labs (Cygnal) chips */
15620 \layout Standard
15621
15622 For more exotic implementations further customizations may be needed.
15623  See section 
15624 \begin_inset LatexCommand \ref{sub:Startup-Code}
15625
15626 \end_inset 
15627
15628  for other possibilities.
15629 \layout Subsection
15630
15631 Other Features available by SFR
15632 \layout Standard
15633
15634 Some MCS51 variants offer features like Double DPTR
15635 \begin_inset LatexCommand \index{DPTR}
15636
15637 \end_inset 
15638
15639 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
15640  These are currently not used for the MCS51 port.
15641  If you absolutely need them you can fall back to inline assembly or submit
15642  a patch to SDCC.
15643 \layout Section
15644
15645 DS400 port
15646 \layout Standard
15647
15648 The DS80C400 microcontroller has a rich set of peripherals.
15649  In its built-in ROM library it includes functions to access some of the
15650  features, among them is a TCP stack with IP4 and IP6 support.
15651  Library headers (currently in beta status) and other files are provided
15652  at 
15653 \size footnotesize 
15654
15655 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
15656
15657 \end_inset 
15658
15659 .
15660  
15661 \layout Section
15662
15663 The Z80 and gbz80 port
15664 \layout Standard
15665
15666 SDCC can target both the Zilog 
15667 \begin_inset LatexCommand \index{Z80}
15668
15669 \end_inset 
15670
15671  and the Nintendo Gameboy's Z80-like gbz80
15672 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
15673
15674 \end_inset 
15675
15676 .
15677  The Z80 port is passed through the same 
15678 \emph on 
15679 regressions tests
15680 \begin_inset LatexCommand \index{Regression test}
15681
15682 \end_inset 
15683
15684
15685 \emph default 
15686  as the MCS51 and DS390 ports, so floating point support, support for long
15687  variables and bitfield support is fine.
15688  See mailing lists and forums about interrupt routines.
15689 \layout Standard
15690
15691 As always, the code is the authoritative reference - see z80/ralloc.c and
15692  z80/gen.c.
15693  The stack
15694 \begin_inset LatexCommand \index{stack}
15695
15696 \end_inset 
15697
15698  frame is similar to that generated by the IAR Z80 compiler.
15699  IX is used as the base pointer, HL and IY are used as a temporary registers,
15700  and BC and DE are available for holding variables.
15701  Return values
15702 \begin_inset LatexCommand \index{return value}
15703
15704 \end_inset 
15705
15706  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
15707  bytes).
15708  The gbz80 port use the same set of registers for the return values, but
15709  in a different order of significance: E (one byte), DE (two bytes), or
15710  HLDE (four bytes).
15711 \layout Section
15712
15713 The HC08 port
15714 \layout Standard
15715
15716 The port to the Motorola HC08
15717 \begin_inset LatexCommand \index{HC08}
15718
15719 \end_inset 
15720
15721  family has been added in October 2003, and is still undergoing some basic
15722  development.
15723  The code generator is complete, but the register allocation is still quite
15724  unoptimized.
15725  Some of the SDCC's standard C library functions have embedded non-HC08
15726  inline assembly and so are not yet usable.
15727 \newline 
15728
15729 \newline 
15730
15731 \layout Section
15732
15733 The PIC14 port
15734 \layout Standard
15735
15736 The 14bit PIC
15737 \begin_inset LatexCommand \index{PIC14}
15738
15739 \end_inset 
15740
15741  port still requires a major effort from the development community.
15742  However it can work for very simple code.
15743 \layout Subsection
15744
15745 C code and 14bit PIC code page
15746 \begin_inset LatexCommand \index{code page (pic14)}
15747
15748 \end_inset 
15749
15750  and RAM banks
15751 \begin_inset LatexCommand \index{RAM bank (pic14)}
15752
15753 \end_inset 
15754
15755
15756 \layout Standard
15757
15758 The linker organizes allocation for the code page and RAM banks.
15759  It does not have intimate knowledge of the code flow.
15760  It will put all the code section of a single asm file into a single code
15761  page.
15762  In order to make use of multiple code pages, separate asm files must be
15763  used.
15764  The compiler treats all functions of a single C file as being in the same
15765  code page unless it is non static.
15766  The compiler treats all local variables of a single C file as being in
15767  the same RAM bank unless it is an extern.
15768 \newline 
15769
15770 \newline 
15771 To get the best follow these guide lines:
15772 \layout Enumerate
15773
15774 make local functions static, as non static functions require code page selection
15775  overhead.
15776 \layout Enumerate
15777
15778 Make local variables static as extern variables require RAM bank selection
15779  overhead.
15780 \layout Enumerate
15781
15782 For devices that have multiple code pages it is more efficient to use the
15783  same number of files as pages, i.e.
15784  for the 16F877 use 4 separate files and i.e.
15785  for the 16F874 use 2 separate files.
15786  This way the linker can put the code for each file into different code
15787  pages and the compiler can allocate reusable variables more efficiently
15788  and there's less page selection overhead.
15789  And as for any 8 bit micro (especially for PIC 14 as they have a very simple
15790  instruction set) use 'unsigned char' whereever possible instead of 'int'.
15791 \layout Subsection
15792
15793 Creating a device include file 
15794 \layout Standard
15795
15796 For generating a device include file use the support perl script inc2h.pl
15797  kept in directory support/script.
15798 \layout Subsection
15799
15800 Interrupt code
15801 \layout Standard
15802
15803 For the interrupt function, use the keyword 'interrupt'
15804 \begin_inset LatexCommand \index{interrupt}
15805
15806 \end_inset 
15807
15808  with level number of 0 (PIC14 only has 1 interrupt so this number is only
15809  there to avoid a syntax error - it ought to be fixed).
15810  E.g.:
15811 \layout Verse
15812
15813
15814 \family typewriter 
15815 void Intr(void) interrupt 0
15816 \newline 
15817 {
15818 \newline 
15819 \SpecialChar ~
15820 \SpecialChar ~
15821 T0IF = 0; /* Clear timer interrupt */
15822 \newline 
15823 }
15824 \layout Subsection
15825
15826 Linking and assembling
15827 \layout Standard
15828
15829 For assembling you can use either GPUTILS'
15830 \begin_inset LatexCommand \index{gputils (pic tools)}
15831
15832 \end_inset 
15833
15834  gpasm.exe or MPLAB's mpasmwin.exe.
15835  GPUTILS is available from 
15836 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
15837
15838 \end_inset 
15839
15840 .
15841  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
15842  If you use MPLAB and an interrupt function then the linker script file
15843  vectors section will need to be enlarged to link with mplink.
15844 \newline 
15845
15846 \newline 
15847 Here is a 
15848 \family typewriter 
15849 Makefile
15850 \family default 
15851  using GPUTILS:
15852 \layout Verse
15853
15854
15855 \family typewriter 
15856 .c.o:
15857 \newline 
15858 \SpecialChar ~
15859 \SpecialChar ~
15860 \SpecialChar ~
15861 \SpecialChar ~
15862 \SpecialChar ~
15863 \SpecialChar ~
15864 \SpecialChar ~
15865 \SpecialChar ~
15866 sdcc -S -V -mpic14 -p16F877 $< 
15867 \newline 
15868 \SpecialChar ~
15869 \SpecialChar ~
15870 \SpecialChar ~
15871 \SpecialChar ~
15872 \SpecialChar ~
15873 \SpecialChar ~
15874 \SpecialChar ~
15875 \SpecialChar ~
15876 gpasm -c $*.asm
15877 \newline 
15878
15879 \newline 
15880 $(PRJ).hex: $(OBJS) 
15881 \newline 
15882 \SpecialChar ~
15883 \SpecialChar ~
15884 \SpecialChar ~
15885 \SpecialChar ~
15886 \SpecialChar ~
15887 \SpecialChar ~
15888 \SpecialChar ~
15889 \SpecialChar ~
15890 gplink -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS)
15891 \layout Standard
15892
15893 Here is a 
15894 \family typewriter 
15895 Makefile
15896 \family default 
15897  using MPLAB:
15898 \layout Verse
15899
15900
15901 \family typewriter 
15902 .c.o: 
15903 \newline 
15904 \SpecialChar ~
15905 \SpecialChar ~
15906 \SpecialChar ~
15907 \SpecialChar ~
15908 \SpecialChar ~
15909 \SpecialChar ~
15910 \SpecialChar ~
15911 \SpecialChar ~
15912 sdcc -S -V -mpic14 -p16F877 $< 
15913 \newline 
15914 \SpecialChar ~
15915 \SpecialChar ~
15916 \SpecialChar ~
15917 \SpecialChar ~
15918 \SpecialChar ~
15919 \SpecialChar ~
15920 \SpecialChar ~
15921 \SpecialChar ~
15922 mpasmwin /q /o $*.asm
15923 \newline 
15924
15925 \newline 
15926 $(PRJ).hex: $(OBJS) 
15927 \newline 
15928 \SpecialChar ~
15929 \SpecialChar ~
15930 \SpecialChar ~
15931 \SpecialChar ~
15932 \SpecialChar ~
15933 \SpecialChar ~
15934 \SpecialChar ~
15935 \SpecialChar ~
15936 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS)
15937 \layout Standard
15938
15939 Please note that indentations within a
15940 \family typewriter 
15941  Makefile
15942 \family default 
15943  have to be done with a tabulator character.
15944 \layout Section
15945
15946 The PIC16
15947 \begin_inset LatexCommand \index{PIC16}
15948
15949 \end_inset 
15950
15951  port
15952 \layout Standard
15953
15954 The PIC16
15955 \begin_inset LatexCommand \index{PIC16}
15956
15957 \end_inset 
15958
15959  port is the portion of SDCC that is responsible to produce code for the
15960  Microchip
15961 \begin_inset LatexCommand \index{Microchip}
15962
15963 \end_inset 
15964
15965 (TM) microcontrollers with 16 bit core.
15966  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
15967  Currently supported devices are:
15968 \layout Standard
15969 \align center 
15970
15971 \begin_inset  Tabular
15972 <lyxtabular version="3" rows="4" columns="6">
15973 <features>
15974 <column alignment="center" valignment="top" leftline="true" width="0">
15975 <column alignment="center" valignment="top" leftline="true" width="0">
15976 <column alignment="center" valignment="top" leftline="true" width="0">
15977 <column alignment="center" valignment="top" leftline="true" width="0">
15978 <column alignment="center" valignment="top" leftline="true" width="0">
15979 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15980 <row topline="true">
15981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15982 \begin_inset Text
15983
15984 \layout Standard
15985
15986 18F242
15987 \end_inset 
15988 </cell>
15989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15990 \begin_inset Text
15991
15992 \layout Standard
15993
15994 18F248
15995 \end_inset 
15996 </cell>
15997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15998 \begin_inset Text
15999
16000 \layout Standard
16001
16002 18F252
16003 \end_inset 
16004 </cell>
16005 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16006 \begin_inset Text
16007
16008 \layout Standard
16009
16010 18F258
16011 \end_inset 
16012 </cell>
16013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16014 \begin_inset Text
16015
16016 \layout Standard
16017
16018 18F442
16019 \end_inset 
16020 </cell>
16021 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16022 \begin_inset Text
16023
16024 \layout Standard
16025
16026 18F448
16027 \end_inset 
16028 </cell>
16029 </row>
16030 <row topline="true">
16031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16032 \begin_inset Text
16033
16034 \layout Standard
16035
16036 18F452
16037 \end_inset 
16038 </cell>
16039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16040 \begin_inset Text
16041
16042 \layout Standard
16043
16044 18F458
16045 \end_inset 
16046 </cell>
16047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16048 \begin_inset Text
16049
16050 \layout Standard
16051
16052 18F1220
16053 \end_inset 
16054 </cell>
16055 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16056 \begin_inset Text
16057
16058 \layout Standard
16059
16060 18F2220
16061 \end_inset 
16062 </cell>
16063 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16064 \begin_inset Text
16065
16066 \layout Standard
16067
16068 18F2550
16069 \end_inset 
16070 </cell>
16071 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16072 \begin_inset Text
16073
16074 \layout Standard
16075
16076 18F4331
16077 \end_inset 
16078 </cell>
16079 </row>
16080 <row topline="true">
16081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16082 \begin_inset Text
16083
16084 \layout Standard
16085
16086 18F4455
16087 \end_inset 
16088 </cell>
16089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16090 \begin_inset Text
16091
16092 \layout Standard
16093
16094 18F6520
16095 \end_inset 
16096 </cell>
16097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16098 \begin_inset Text
16099
16100 \layout Standard
16101
16102 18F6620
16103 \end_inset 
16104 </cell>
16105 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16106 \begin_inset Text
16107
16108 \layout Standard
16109
16110 18F6680
16111 \end_inset 
16112 </cell>
16113 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16114 \begin_inset Text
16115
16116 \layout Standard
16117
16118 18F6720
16119 \end_inset 
16120 </cell>
16121 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16122 \begin_inset Text
16123
16124 \layout Standard
16125
16126 18F8520
16127 \end_inset 
16128 </cell>
16129 </row>
16130 <row topline="true" bottomline="true">
16131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16132 \begin_inset Text
16133
16134 \layout Standard
16135
16136 18F8620
16137 \end_inset 
16138 </cell>
16139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16140 \begin_inset Text
16141
16142 \layout Standard
16143
16144 18F8680
16145 \end_inset 
16146 </cell>
16147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16148 \begin_inset Text
16149
16150 \layout Standard
16151
16152 18F8720
16153 \end_inset 
16154 </cell>
16155 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16156 \begin_inset Text
16157
16158 \layout Standard
16159
16160 \end_inset 
16161 </cell>
16162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16163 \begin_inset Text
16164
16165 \layout Standard
16166
16167 \end_inset 
16168 </cell>
16169 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16170 \begin_inset Text
16171
16172 \layout Standard
16173
16174 \end_inset 
16175 </cell>
16176 </row>
16177 </lyxtabular>
16178
16179 \end_inset 
16180
16181
16182 \layout Subsection
16183
16184 Global Options
16185 \layout Standard
16186
16187 PIC16 port supports the standard command line arguments as supposed, with
16188  the exception of certain cases that will be mentioned in the following
16189  list:
16190 \layout List
16191 \labelwidthstring 00.00.0000
16192
16193 -
16194 \begin_inset ERT
16195 status Collapsed
16196
16197 \layout Standard
16198
16199 \backslash 
16200 /
16201 \end_inset 
16202
16203 -callee-saves See -
16204 \begin_inset ERT
16205 status Collapsed
16206
16207 \layout Standard
16208
16209 \backslash 
16210 /
16211 \end_inset 
16212
16213 -all-callee-saves
16214 \layout List
16215 \labelwidthstring 00.00.0000
16216
16217 -
16218 \begin_inset ERT
16219 status Collapsed
16220
16221 \layout Standard
16222
16223 \backslash 
16224 /
16225 \end_inset 
16226
16227 -all-callee-saves All function arguments are passed on stack by default.
16228  
16229 \emph on 
16230 There is no need to specify this in the command line.
16231 \layout List
16232 \labelwidthstring 00.00.0000
16233
16234 -
16235 \begin_inset ERT
16236 status Collapsed
16237
16238 \layout Standard
16239
16240 \backslash 
16241 /
16242 \end_inset 
16243
16244 -fommit-frame-pointer Frame pointer will be omitted when the function uses
16245  no local variables.
16246 \layout Subsection
16247
16248 Port Specific Options
16249 \begin_inset LatexCommand \index{Options PIC16}
16250
16251 \end_inset 
16252
16253
16254 \layout Standard
16255
16256 The port specific options appear after the global options in the sdcc --help
16257  output.
16258 \layout Subsubsection
16259
16260 General Options
16261 \layout Standard
16262
16263 General options enable certain port features and optimizations.
16264 \layout List
16265 \labelwidthstring 00.00.0000
16266
16267 -
16268 \begin_inset ERT
16269 status Collapsed
16270
16271 \layout Standard
16272
16273 \backslash 
16274 /
16275 \end_inset 
16276
16277 -stack-model=[model] Used in conjuction with the command above.
16278  Defines the stack model to be used, valid stack models are : 
16279 \begin_deeper 
16280 \layout List
16281 \labelwidthstring 00.00.0000
16282
16283
16284 \emph on 
16285 small
16286 \emph default 
16287  Selects small stack model.
16288  8 bit stack and frame pointers.
16289  Supports 256 bytes stack size.
16290 \layout List
16291 \labelwidthstring 00.00.0000
16292
16293
16294 \emph on 
16295 large
16296 \emph default 
16297  Selects large stack model.
16298  16 bit stack and frame pointers.
16299  Supports 65536 bytes stack size.
16300 \end_deeper 
16301 \layout List
16302 \labelwidthstring 00.00.0000
16303
16304 -
16305 \begin_inset ERT
16306 status Collapsed
16307
16308 \layout Standard
16309
16310 \backslash 
16311 /
16312 \end_inset 
16313
16314 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
16315  unitialized data variables with [kword].
16316  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
16317 \layout List
16318 \labelwidthstring 00.00.0000
16319
16320 -
16321 \begin_inset ERT
16322 status Collapsed
16323
16324 \layout Standard
16325
16326 \backslash 
16327 /
16328 \end_inset 
16329
16330 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
16331  Useful for bootloaders.
16332 \layout List
16333 \labelwidthstring 00.00.0000
16334
16335 -
16336 \begin_inset ERT
16337 status Collapsed
16338
16339 \layout Standard
16340
16341 \backslash 
16342 /
16343 \end_inset 
16344
16345 -asm= sets the full path and name of an external assembler to call.
16346 \layout List
16347 \labelwidthstring 00.00.0000
16348
16349 -
16350 \begin_inset ERT
16351 status Collapsed
16352
16353 \layout Standard
16354
16355 \backslash 
16356 /
16357 \end_inset 
16358
16359 -link= sets the full path and name of an external linker to call.
16360 \layout List
16361 \labelwidthstring 00.00.0000
16362
16363 -
16364 \begin_inset ERT
16365 status Collapsed
16366
16367 \layout Standard
16368
16369 \backslash 
16370 /
16371 \end_inset 
16372
16373 -mplab-comp MPLAB compatibility option.
16374  Currently only suppresses special gpasm directives.
16375 \layout Subsubsection
16376
16377 Optimization Options
16378 \layout List
16379 \labelwidthstring 00.00.0000
16380
16381 -
16382 \begin_inset ERT
16383 status Collapsed
16384
16385 \layout Standard
16386
16387 \backslash 
16388 /
16389 \end_inset 
16390
16391 -optimize-goto Try to use (conditional) BRA instead of GOTO
16392 \layout List
16393 \labelwidthstring 00.00.0000
16394
16395 -
16396 \begin_inset ERT
16397 status Collapsed
16398
16399 \layout Standard
16400
16401 \backslash 
16402 /
16403 \end_inset 
16404
16405 -optimize-cmp Try to optimize some compares.
16406 \layout List
16407 \labelwidthstring 00.00.0000
16408
16409 -
16410 \begin_inset ERT
16411 status Collapsed
16412
16413 \layout Standard
16414
16415 \backslash 
16416 /
16417 \end_inset 
16418
16419 -obanksel=nn Set optimization level for inserting BANKSELs.
16420 \newline 
16421
16422 \begin_deeper 
16423 \layout List
16424 \labelwidthstring 00.00.0000
16425
16426 0 no optimization
16427 \layout List
16428 \labelwidthstring 00.00.0000
16429
16430 1 checks previous used register and if it is the same then does not emit
16431  BANKSEL, accounts only for labels.
16432 \layout List
16433 \labelwidthstring 00.00.0000
16434
16435 2 tries to check the location of (even different) symbols and removes BANKSELs
16436  if they are in the same bank.
16437  
16438 \newline 
16439
16440 \emph on 
16441 Important: There might be problems if the linker script has data sections
16442  across bank borders!
16443 \end_deeper 
16444 \layout Subsubsection
16445
16446 Linking Options
16447 \layout List
16448 \labelwidthstring 00.00.0000
16449
16450 -
16451 \begin_inset ERT
16452 status Collapsed
16453
16454 \layout Standard
16455
16456 \backslash 
16457 /
16458 \end_inset 
16459
16460 -nodefaultlibs do not link default libraries when linking
16461 \layout List
16462 \labelwidthstring 00.00.0000
16463
16464 -
16465 \begin_inset ERT
16466 status Collapsed
16467
16468 \layout Standard
16469
16470 \backslash 
16471 /
16472 \end_inset 
16473
16474 -no-crt Don't link the default run-time modules
16475 \layout List
16476 \labelwidthstring 00.00.0000
16477
16478 -
16479 \begin_inset ERT
16480 status Collapsed
16481
16482 \layout Standard
16483
16484 \backslash 
16485 /
16486 \end_inset 
16487
16488 -use-crt= Use a custom run-time module instead of the defaults.
16489 \layout Subsubsection
16490
16491 Debugging Options
16492 \layout Standard
16493
16494 Debugging options enable extra debugging information in the output files.
16495 \layout List
16496 \labelwidthstring 00.00.0000
16497
16498 -
16499 \begin_inset ERT
16500 status Collapsed
16501
16502 \layout Standard
16503
16504 \backslash 
16505 /
16506 \end_inset 
16507
16508 -debug-xtra Similar to -
16509 \begin_inset ERT
16510 status Collapsed
16511
16512 \layout Standard
16513
16514 \backslash 
16515 /
16516 \end_inset 
16517
16518 -debug
16519 \begin_inset LatexCommand \index{-\/-debug}
16520
16521 \end_inset 
16522
16523 , but dumps more information.
16524 \layout List
16525 \labelwidthstring 00.00.0000
16526
16527 -
16528 \begin_inset ERT
16529 status Collapsed
16530
16531 \layout Standard
16532
16533 \backslash 
16534 /
16535 \end_inset 
16536
16537 -debug-ralloc Force register allocator to dump <source>.d file with debugging
16538  information.
16539  <source> is the name of the file compiled.
16540 \layout List
16541 \labelwidthstring 00.00.0000
16542
16543 -
16544 \begin_inset ERT
16545 status Collapsed
16546
16547 \layout Standard
16548
16549 \backslash 
16550 /
16551 \end_inset 
16552
16553 -pcode-verbose Enable pcode debugging information in translation.
16554 \layout List
16555 \labelwidthstring 00.00.0000
16556
16557 -
16558 \begin_inset ERT
16559 status Collapsed
16560
16561 \layout Standard
16562
16563 \backslash 
16564 /
16565 \end_inset 
16566
16567 -denable-peeps Force the usage of peepholes.
16568  Use with care.
16569 \layout List
16570 \labelwidthstring 00.00.0000
16571
16572 -
16573 \begin_inset ERT
16574 status Collapsed
16575
16576 \layout Standard
16577
16578 \backslash 
16579 /
16580 \end_inset 
16581
16582 -gstack Trace push/pops for stack pointer overflow
16583 \layout List
16584 \labelwidthstring 00.00.0000
16585
16586 -
16587 \begin_inset ERT
16588 status Collapsed
16589
16590 \layout Standard
16591
16592 \backslash 
16593 /
16594 \end_inset 
16595
16596 -call-tree dump call tree in .calltree file
16597 \layout Subsection
16598
16599 Enviromental Variables
16600 \layout Standard
16601
16602 There is a number of enviromental variables that can be used when running
16603  SDCC to enable certain optimizations or force a specific program behaviour.
16604  these variables are primarily for debugging purposes so they can be enabled/dis
16605 abled at will.
16606 \layout Standard
16607
16608 Currently there is only two such variables available:
16609 \layout List
16610 \labelwidthstring 00.00.0000
16611
16612 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
16613  bitfields is optimized by directly loading FSR0 with the address of the
16614  bitfield structure.
16615  Normally SDCC will cast the bitfield structure to a bitfield pointer and
16616  then load FSR0.
16617  This step saves data ram and code space for functions that perform heavy
16618  use of bitfields.
16619  (ie.
16620  80 bytes of code space are saved when compiling malloc.c with this option).
16621  
16622 \layout List
16623 \labelwidthstring 00.00.0000
16624
16625 NO_REG_OPT do not perform pCode registers optimization.
16626  This should be used for debugging purposes.
16627  In some where bugs in the pcode optimizer are found, users can benefit
16628  from temporarily disabling the optimizer until the bug is fixed.
16629 \layout Subsection
16630
16631 Preprocessor Macros
16632 \layout Standard
16633
16634 PIC16 port defines the following preprocessor macros while translating a
16635  source.
16636 \layout Standard
16637 \align center 
16638
16639 \begin_inset  Tabular
16640 <lyxtabular version="3" rows="6" columns="2">
16641 <features>
16642 <column alignment="center" valignment="top" leftline="true" width="0">
16643 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
16644 <row topline="true" bottomline="true">
16645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16646 \begin_inset Text
16647
16648 \layout Standard
16649
16650 Macro
16651 \end_inset 
16652 </cell>
16653 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16654 \begin_inset Text
16655
16656 \layout Standard
16657
16658 Description
16659 \end_inset 
16660 </cell>
16661 </row>
16662 <row topline="true">
16663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16664 \begin_inset Text
16665
16666 \layout Standard
16667
16668 SDCC_pic16
16669 \end_inset 
16670 </cell>
16671 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16672 \begin_inset Text
16673
16674 \layout Standard
16675
16676 Port identification
16677 \end_inset 
16678 </cell>
16679 </row>
16680 <row topline="true">
16681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16682 \begin_inset Text
16683
16684 \layout Standard
16685
16686 _
16687 \begin_inset ERT
16688 status Collapsed
16689
16690 \layout Standard
16691
16692 \backslash 
16693 /
16694 \end_inset 
16695
16696 _pic16
16697 \end_inset 
16698 </cell>
16699 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16700 \begin_inset Text
16701
16702 \layout Standard
16703
16704 Port identification (same as above)
16705 \end_inset 
16706 </cell>
16707 </row>
16708 <row topline="true">
16709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16710 \begin_inset Text
16711
16712 \layout Standard
16713
16714 pic18fxxxx
16715 \end_inset 
16716 </cell>
16717 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16718 \begin_inset Text
16719
16720 \layout Standard
16721
16722 MCU Identification.
16723  
16724 \emph on 
16725 xxxx
16726 \emph default 
16727  is the microcontrol identification number, i.e.
16728  452, 6620, etc
16729 \end_inset 
16730 </cell>
16731 </row>
16732 <row topline="true">
16733 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16734 \begin_inset Text
16735
16736 \layout Standard
16737
16738 _
16739 \begin_inset ERT
16740 status Collapsed
16741
16742 \layout Standard
16743
16744 \backslash 
16745 /
16746 \end_inset 
16747
16748 _18Fxxxx
16749 \end_inset 
16750 </cell>
16751 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16752 \begin_inset Text
16753
16754 \layout Standard
16755
16756 MCU Identification (same as above)
16757 \end_inset 
16758 </cell>
16759 </row>
16760 <row topline="true" bottomline="true">
16761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16762 \begin_inset Text
16763
16764 \layout Standard
16765
16766 STACK_MODEL_nnn
16767 \end_inset 
16768 </cell>
16769 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16770 \begin_inset Text
16771
16772 \layout Standard
16773
16774 nnn = SMALL or LARGE respectively according to the stack model used
16775 \end_inset 
16776 </cell>
16777 </row>
16778 </lyxtabular>
16779
16780 \end_inset 
16781
16782
16783 \layout Standard
16784
16785 In addition the following macros are defined when calling assembler:
16786 \layout Standard
16787 \align center 
16788
16789 \begin_inset  Tabular
16790 <lyxtabular version="3" rows="4" columns="2">
16791 <features>
16792 <column alignment="center" valignment="top" leftline="true" width="0">
16793 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
16794 <row topline="true" bottomline="true">
16795 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16796 \begin_inset Text
16797
16798 \layout Standard
16799
16800 Macro
16801 \end_inset 
16802 </cell>
16803 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16804 \begin_inset Text
16805
16806 \layout Standard
16807
16808 Description
16809 \end_inset 
16810 </cell>
16811 </row>
16812 <row topline="true">
16813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16814 \begin_inset Text
16815
16816 \layout Standard
16817
16818 __18Fxxxx
16819 \end_inset 
16820 </cell>
16821 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16822 \begin_inset Text
16823
16824 \layout Standard
16825
16826 MCU Identification.
16827  
16828 \emph on 
16829 xxxx
16830 \emph default 
16831  is the microcontrol identification number, i.e.
16832  452, 6620, etc
16833 \end_inset 
16834 </cell>
16835 </row>
16836 <row topline="true">
16837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16838 \begin_inset Text
16839
16840 \layout Standard
16841
16842 SDCC_MODEL_nnn
16843 \end_inset 
16844 </cell>
16845 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16846 \begin_inset Text
16847
16848 \layout Standard
16849
16850 nnn = SMALL or LARGE respectively according to the memory model used for
16851  SDCC
16852 \end_inset 
16853 </cell>
16854 </row>
16855 <row topline="true" bottomline="true">
16856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16857 \begin_inset Text
16858
16859 \layout Standard
16860
16861 STACK_MODEL_nnn
16862 \end_inset 
16863 </cell>
16864 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16865 \begin_inset Text
16866
16867 \layout Standard
16868
16869 nnn = SMALL or LARGE respectively according to the stack model used
16870 \end_inset 
16871 </cell>
16872 </row>
16873 </lyxtabular>
16874
16875 \end_inset 
16876
16877
16878 \layout Subsection
16879
16880 Directories
16881 \layout Standard
16882
16883 PIC16
16884 \begin_inset LatexCommand \index{PIC16}
16885
16886 \end_inset 
16887
16888  port uses the following directories for searching header files and libraries.
16889 \layout Standard
16890 \align center 
16891
16892 \begin_inset  Tabular
16893 <lyxtabular version="3" rows="3" columns="4">
16894 <features>
16895 <column alignment="center" valignment="top" leftline="true" width="0">
16896 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
16897 <column alignment="center" valignment="top" width="0">
16898 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
16899 <row topline="true" bottomline="true">
16900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16901 \begin_inset Text
16902
16903 \layout Standard
16904
16905 Directory
16906 \end_inset 
16907 </cell>
16908 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16909 \begin_inset Text
16910
16911 \layout Standard
16912
16913 Description
16914 \end_inset 
16915 </cell>
16916 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16917 \begin_inset Text
16918
16919 \layout Standard
16920
16921 Target
16922 \end_inset 
16923 </cell>
16924 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16925 \begin_inset Text
16926
16927 \layout Standard
16928
16929 Command prefix
16930 \end_inset 
16931 </cell>
16932 </row>
16933 <row topline="true">
16934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16935 \begin_inset Text
16936
16937 \layout Standard
16938
16939 PREFIX/sdcc/include/pic16
16940 \end_inset 
16941 </cell>
16942 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16943 \begin_inset Text
16944
16945 \layout Standard
16946
16947 PIC16 specific headers
16948 \end_inset 
16949 </cell>
16950 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16951 \begin_inset Text
16952
16953 \layout Standard
16954
16955 Compiler
16956 \end_inset 
16957 </cell>
16958 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16959 \begin_inset Text
16960
16961 \layout Standard
16962
16963 -I
16964 \end_inset 
16965 </cell>
16966 </row>
16967 <row topline="true" bottomline="true">
16968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16969 \begin_inset Text
16970
16971 \layout Standard
16972
16973 PREFIX/sdcc/lib/pic16
16974 \end_inset 
16975 </cell>
16976 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16977 \begin_inset Text
16978
16979 \layout Standard
16980
16981 PIC16 specific libraries
16982 \end_inset 
16983 </cell>
16984 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16985 \begin_inset Text
16986
16987 \layout Standard
16988
16989 Linker
16990 \end_inset 
16991 </cell>
16992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16993 \begin_inset Text
16994
16995 \layout Standard
16996
16997 -L
16998 \end_inset 
16999 </cell>
17000 </row>
17001 </lyxtabular>
17002
17003 \end_inset 
17004
17005
17006 \layout Subsection
17007
17008 Pragmas
17009 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
17010
17011 \end_inset 
17012
17013
17014 \layout Standard
17015
17016 PIC16 port currently supports the following pragmas:
17017 \layout List
17018 \labelwidthstring 00.00.0000
17019
17020 stack pragma stack forces the code generator to initialize the stack & frame
17021  pointers at a specific address.
17022  This is an adhoc solution for cases where no STACK directive is available
17023  in the linker script or gplink is not instructed to create a stack section.
17024 \newline 
17025 The stack pragma should be used only once in a project.
17026  Multiple pragmas may result in indeterminate behaviour of the program.
17027 \begin_inset Foot
17028 collapsed false
17029
17030 \layout Standard
17031
17032 The old format (ie.
17033  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
17034  cross page boundaries (or even exceed the available data RAM) and crash
17035  the program.
17036  Make sure that stack does not cross page boundaries when using the SMALL
17037  stack model.
17038 \end_inset 
17039
17040
17041 \newline 
17042 The format is as follows:
17043 \layout LyX-Code
17044
17045 #pragma stack bottom_address [stack_size]
17046 \layout Standard
17047
17048
17049 \emph on 
17050 bottom_address
17051 \emph default 
17052  is the lower bound of the stack section.
17053  The stack pointer initially will point at address (bottom_address+stack_size-1).
17054 \layout LyX-Code
17055
17056 Example:
17057 \layout LyX-Code
17058
17059 \layout LyX-Code
17060
17061 /* initializes stack of 100 bytes at RAM address 0x200 */
17062 \layout LyX-Code
17063
17064 #pragma stack 0x200 100
17065 \layout Standard
17066
17067 If the stack_size field is omitted then a stack is created with the default
17068  size of 64.
17069  This size might be enough for most programs, but its not enough for operations
17070  with deep function nesting or excessive stack usage.
17071 \layout List
17072 \labelwidthstring 00.00.0000
17073
17074 wparam 
17075 \emph on 
17076 This pragma is deprecated.
17077  Its use will cause a warning message to be issued.
17078 \emph default 
17079
17080 \newline 
17081
17082 \layout List
17083 \labelwidthstring 00.00.0000
17084
17085 code place a function symbol at static FLASH address
17086 \layout LyX-Code
17087
17088 Example:
17089 \layout LyX-Code
17090
17091 \layout LyX-Code
17092
17093 /* place function test_func at 0x4000 */
17094 \layout LyX-Code
17095
17096 #pragma code test_func 0x4000
17097 \layout LyX-Code
17098
17099 \layout List
17100 \labelwidthstring 00.00.0000
17101
17102 library instructs the linker to use a library module.
17103 \newline 
17104 Usage:
17105 \layout LyX-Code
17106
17107 #pragma library module_name
17108 \layout Standard
17109
17110
17111 \emph on 
17112 module_name
17113 \emph default 
17114  can be any library or object file (including its path).
17115  Note that there are four reserved keywords which have special meaning.
17116  These are:
17117 \layout Standard
17118 \align center 
17119
17120 \begin_inset  Tabular
17121 <lyxtabular version="3" rows="6" columns="3">
17122 <features>
17123 <column alignment="center" valignment="top" leftline="true" width="0">
17124 <column alignment="block" valignment="top" leftline="true" width="20page%">
17125 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
17126 <row topline="true" bottomline="true">
17127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17128 \begin_inset Text
17129
17130 \layout Standard
17131
17132 Keyword
17133 \end_inset 
17134 </cell>
17135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17136 \begin_inset Text
17137
17138 \layout Standard
17139
17140 Description
17141 \end_inset 
17142 </cell>
17143 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17144 \begin_inset Text
17145
17146 \layout Standard
17147
17148 Module to link
17149 \end_inset 
17150 </cell>
17151 </row>
17152 <row topline="true">
17153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17154 \begin_inset Text
17155
17156 \layout Standard
17157
17158
17159 \series bold 
17160 ignore
17161 \end_inset 
17162 </cell>
17163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17164 \begin_inset Text
17165
17166 \layout Standard
17167
17168 ignore all library pragmas
17169 \end_inset 
17170 </cell>
17171 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17172 \begin_inset Text
17173
17174 \layout Standard
17175
17176
17177 \emph on 
17178 (none)
17179 \end_inset 
17180 </cell>
17181 </row>
17182 <row topline="true">
17183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17184 \begin_inset Text
17185
17186 \layout Standard
17187
17188
17189 \series bold 
17190 c
17191 \end_inset 
17192 </cell>
17193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17194 \begin_inset Text
17195
17196 \layout Standard
17197
17198 link the C library
17199 \end_inset 
17200 </cell>
17201 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17202 \begin_inset Text
17203
17204 \layout Standard
17205
17206
17207 \emph on 
17208 libc18f
17209 \emph default 
17210 .lib
17211 \end_inset 
17212 </cell>
17213 </row>
17214 <row topline="true">
17215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17216 \begin_inset Text
17217
17218 \layout Standard
17219
17220
17221 \series bold 
17222 math
17223 \end_inset 
17224 </cell>
17225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17226 \begin_inset Text
17227
17228 \layout Standard
17229
17230 link the Math libarary
17231 \end_inset 
17232 </cell>
17233 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17234 \begin_inset Text
17235
17236 \layout Standard
17237
17238
17239 \emph on 
17240 libm18f
17241 \emph default 
17242 .lib
17243 \end_inset 
17244 </cell>
17245 </row>
17246 <row topline="true">
17247 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17248 \begin_inset Text
17249
17250 \layout Standard
17251
17252
17253 \series bold 
17254 io
17255 \end_inset 
17256 </cell>
17257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17258 \begin_inset Text
17259
17260 \layout Standard
17261
17262 link the I/O library
17263 \end_inset 
17264 </cell>
17265 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17266 \begin_inset Text
17267
17268 \layout Standard
17269
17270
17271 \emph on 
17272 libio18f*
17273 \emph default 
17274 .lib
17275 \end_inset 
17276 </cell>
17277 </row>
17278 <row topline="true" bottomline="true">
17279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17280 \begin_inset Text
17281
17282 \layout Standard
17283
17284
17285 \series bold 
17286 debug
17287 \end_inset 
17288 </cell>
17289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17290 \begin_inset Text
17291
17292 \layout Standard
17293
17294 link the debug library
17295 \end_inset 
17296 </cell>
17297 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17298 \begin_inset Text
17299
17300 \layout Standard
17301
17302
17303 \emph on 
17304 libdebug
17305 \emph default 
17306 .lib
17307 \end_inset 
17308 </cell>
17309 </row>
17310 </lyxtabular>
17311
17312 \end_inset 
17313
17314
17315 \newline 
17316 * is the device number, i.e.
17317  452 for PIC18F452 MCU.
17318 \layout Standard
17319
17320 This feature allows for linking with specific libraries withoug having to
17321  explicit name them in the command line.
17322  Note that the 
17323 \noun on 
17324 ignore
17325 \noun default 
17326  keyword will reject all modules specified by the library pragma.
17327 \layout List
17328 \labelwidthstring 00.00.0000
17329
17330 udata pragma udata instructs the compiler to emit code so that linker will
17331  place a variable at a specific memory bank
17332 \layout LyX-Code
17333
17334 Example:
17335 \layout LyX-Code
17336
17337 \layout LyX-Code
17338
17339 /* places variable foo at bank2 */
17340 \layout LyX-Code
17341
17342 #pragma udata bank2 foo
17343 \layout LyX-Code
17344
17345 char foo;
17346 \layout Standard
17347
17348 In order for this pragma to work extra SECTION directives should be added
17349  in the .lkr script.
17350  In the following example a sample .lkr file is shown:
17351 \layout LyX-Code
17352
17353 \layout LyX-Code
17354
17355 // Sample linker script for the PIC18F452 processor
17356 \layout LyX-Code
17357
17358 LIBPATH .
17359 \layout LyX-Code
17360
17361 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
17362 \layout LyX-Code
17363
17364 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
17365 \layout LyX-Code
17366
17367 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
17368 \layout LyX-Code
17369
17370 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
17371 \layout LyX-Code
17372
17373 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
17374 \layout LyX-Code
17375
17376 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
17377 \layout LyX-Code
17378
17379 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
17380 \layout LyX-Code
17381
17382 \layout LyX-Code
17383
17384 DATABANK   NAME=gpr0       START=0x80           END=0xFF
17385 \layout LyX-Code
17386
17387 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
17388 \layout LyX-Code
17389
17390 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
17391 \layout LyX-Code
17392
17393 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
17394 \layout LyX-Code
17395
17396 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
17397 \layout LyX-Code
17398
17399 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
17400 \layout LyX-Code
17401
17402 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
17403 \layout LyX-Code
17404
17405 \layout LyX-Code
17406
17407 SECTION    NAME=CONFIG     ROM=config
17408 \layout LyX-Code
17409
17410 \layout LyX-Code
17411
17412 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
17413 \layout LyX-Code
17414
17415 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
17416 \layout LyX-Code
17417
17418 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
17419 \layout LyX-Code
17420
17421 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
17422 \layout LyX-Code
17423
17424 SECTION    NAME=bank4      RAM=gpr4
17425 \layout LyX-Code
17426
17427 SECTION    NAME=bank5      RAM=gpr5
17428 \layout Standard
17429
17430 The linker will recognise the section name set in the pragma statement and
17431  will position the variable at the memory bank set with the RAM field at
17432  the SECTION line in the linker script file.
17433 \layout Subsection
17434
17435 Header Files
17436 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
17437
17438 \end_inset 
17439
17440
17441 \layout Standard
17442
17443 There is one main header file that can be included to the source files using
17444  the pic16 port.
17445  That file is the 
17446 \series bold 
17447 pic18fregs.h
17448 \series default 
17449 .
17450  This header file contains the definitions for the processor special registers,
17451  so it is necessary if the source accesses them.
17452  It can be included by adding the following line in the beginning of the
17453  file:
17454 \layout LyX-Code
17455
17456 #include <pic18fregs.h>
17457 \layout Standard
17458
17459 The specific microcontroller is selected within the pic18fregs.h automatically,
17460  so the same source can be used with a variety of devices.
17461 \layout Subsection
17462
17463 Libraries
17464 \layout Standard
17465
17466 The libraries that PIC16
17467 \begin_inset LatexCommand \index{PIC16}
17468
17469 \end_inset 
17470
17471  port depends on are the microcontroller device libraries which contain
17472  the symbol definitions for the microcontroller special function registers.
17473  These libraries have the format pic18fxxxx.lib, where 
17474 \emph on 
17475 xxxx
17476 \emph default 
17477  is the microcontroller identification number.
17478  The specific library is selected automatically by the compiler at link
17479  stage according to the selected device.
17480 \layout Standard
17481
17482 Libraries are created with gplib which is part of the gputils package 
17483 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
17484
17485 \end_inset 
17486
17487 .
17488 \layout Subsubsection*
17489
17490 Building the libraries
17491 \layout Standard
17492
17493 Before using SDCC/pic16 there are some libraries that need to be compiled.
17494  This process is not done automatically by SDCC since not all users use
17495  SDCC for pic16 projects.
17496  So each user should compile the libraries separately.
17497 \layout Standard
17498
17499 The steps to compile the pic16 libraries under Linux are:
17500 \layout LyX-Code
17501
17502 cd device/lib/pic16
17503 \layout LyX-Code
17504
17505 ./configure
17506 \layout LyX-Code
17507
17508 make
17509 \layout LyX-Code
17510
17511 cd ..
17512 \layout LyX-Code
17513
17514 make model-pic16
17515 \layout LyX-Code
17516
17517 su -c 'make install'     # install the libraries, you need the root password
17518 \layout Standard
17519
17520 If you need to install the headers too, do:
17521 \layout LyX-Code
17522
17523 cd device/include
17524 \layout LyX-Code
17525
17526 su -c 'make install'     # install the headers, you need the root password
17527 \layout Standard
17528
17529 There exist a special target to build the I/O libraries.
17530  This target is not automatically build because it will build the I/O library
17531  for 
17532 \emph on 
17533 every
17534 \emph default 
17535  supported device.
17536  This way building will take quite a lot of time.
17537  Users are advised to edit the 
17538 \series bold 
17539 device/lib/pic16/pics.build
17540 \series default 
17541  file and then execute:
17542 \layout LyX-Code
17543
17544 make lib-io
17545 \layout Subsection
17546
17547 Memory Models
17548 \layout Standard
17549
17550 The following memory models are supported by the PIC16 port:
17551 \layout Itemize
17552
17553 small model
17554 \layout Itemize
17555
17556 large model
17557 \layout Standard
17558
17559 Memory model affects the default size of pointers within the source.
17560  The sizes are shown in the next table:
17561 \layout Standard
17562 \align center 
17563
17564 \begin_inset  Tabular
17565 <lyxtabular version="3" rows="3" columns="3">
17566 <features>
17567 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
17568 <column alignment="center" valignment="top" leftline="true" width="0">
17569 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
17570 <row topline="true" bottomline="true">
17571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17572 \begin_inset Text
17573
17574 \layout Standard
17575
17576 Pointer sizes according to memory model
17577 \end_inset 
17578 </cell>
17579 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17580 \begin_inset Text
17581
17582 \layout Standard
17583
17584 small model
17585 \end_inset 
17586 </cell>
17587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17588 \begin_inset Text
17589
17590 \layout Standard
17591
17592 large model
17593 \end_inset 
17594 </cell>
17595 </row>
17596 <row topline="true" bottomline="true">
17597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17598 \begin_inset Text
17599
17600 \layout Standard
17601
17602 code pointers
17603 \end_inset 
17604 </cell>
17605 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17606 \begin_inset Text
17607
17608 \layout Standard
17609
17610 16-bits
17611 \end_inset 
17612 </cell>
17613 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17614 \begin_inset Text
17615
17616 \layout Standard
17617
17618 24-bits
17619 \end_inset 
17620 </cell>
17621 </row>
17622 <row topline="true" bottomline="true">
17623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17624 \begin_inset Text
17625
17626 \layout Standard
17627
17628 data pointers
17629 \end_inset 
17630 </cell>
17631 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
17632 \begin_inset Text
17633
17634 \layout Standard
17635
17636 16-bits
17637 \end_inset 
17638 </cell>
17639 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17640 \begin_inset Text
17641
17642 \layout Standard
17643
17644 16-bits
17645 \end_inset 
17646 </cell>
17647 </row>
17648 </lyxtabular>
17649
17650 \end_inset 
17651
17652
17653 \layout Standard
17654
17655 It is advisable that all sources within a project are compiled with the
17656  same memory model.
17657  If one wants to override the default memory model, this can be done by
17658  declaring a pointer as 
17659 \series bold 
17660 far
17661 \series default 
17662  or 
17663 \series bold 
17664 near
17665 \series default 
17666 .
17667  Far selects large memory model's pointers, while near selects small memory
17668  model's pointers.
17669 \layout Standard
17670
17671 The standard device libraries (see 
17672 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
17673
17674 \end_inset 
17675
17676 ) contain no reference to pointers, so they can be used with both memory
17677  models.
17678 \layout Subsection
17679
17680 Stack
17681 \layout Standard
17682
17683 The stack implementation for the PIC16 port uses two indirect registers,
17684  FSR1 and FSR2.
17685 \layout List
17686 \labelwidthstring 00.00.0000
17687
17688 FSR1 is assigned as stack pointer
17689 \layout List
17690 \labelwidthstring 00.00.0000
17691
17692 FSR2 is assigned as frame pointer
17693 \layout Standard
17694
17695 The following stack models are supported by the PIC16 port
17696 \layout Itemize
17697
17698
17699 \noun on 
17700 small
17701 \noun default 
17702  model
17703 \layout Itemize
17704
17705
17706 \noun on 
17707 large
17708 \noun default 
17709  model
17710 \layout Standard
17711
17712
17713 \noun on 
17714 Small
17715 \noun default 
17716  model means that only the FSRxL byte is used to access stack and frame,
17717  while 
17718 \emph on 
17719 \noun on 
17720 large
17721 \emph default 
17722 \noun default 
17723  uses both FSRxL and FSRxH registers.
17724  The following table shows the stack/frame pointers sizes according to stack
17725  model and the maximum space they can address:
17726 \layout Standard
17727 \align center 
17728
17729 \begin_inset  Tabular
17730 <lyxtabular version="3" rows="3" columns="3">
17731 <features>
17732 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
17733 <column alignment="center" valignment="top" leftline="true" width="0">
17734 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
17735 <row topline="true" bottomline="true">
17736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17737 \begin_inset Text
17738
17739 \layout Standard
17740
17741 Stack & Frame pointer sizes according to stack model
17742 \end_inset 
17743 </cell>
17744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17745 \begin_inset Text
17746
17747 \layout Standard
17748
17749 small
17750 \end_inset 
17751 </cell>
17752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17753 \begin_inset Text
17754
17755 \layout Standard
17756
17757 large
17758 \end_inset 
17759 </cell>
17760 </row>
17761 <row topline="true">
17762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17763 \begin_inset Text
17764
17765 \layout Standard
17766
17767 Stack pointer FSR1
17768 \end_inset 
17769 </cell>
17770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17771 \begin_inset Text
17772
17773 \layout Standard
17774
17775 8-bits
17776 \end_inset 
17777 </cell>
17778 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17779 \begin_inset Text
17780
17781 \layout Standard
17782
17783 16-bits
17784 \end_inset 
17785 </cell>
17786 </row>
17787 <row topline="true" bottomline="true">
17788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17789 \begin_inset Text
17790
17791 \layout Standard
17792
17793 Frame pointer FSR2
17794 \end_inset 
17795 </cell>
17796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17797 \begin_inset Text
17798
17799 \layout Standard
17800
17801 8-bits
17802 \end_inset 
17803 </cell>
17804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17805 \begin_inset Text
17806
17807 \layout Standard
17808
17809 16-bits
17810 \end_inset 
17811 </cell>
17812 </row>
17813 </lyxtabular>
17814
17815 \end_inset 
17816
17817
17818 \layout Standard
17819
17820
17821 \noun on 
17822 Large 
17823 \noun default 
17824 stack model is currently not working properly throughout the code generator.
17825  So its use is not advised.
17826  Also there are some other points that need special care:
17827 \newline 
17828
17829 \layout Enumerate
17830
17831 Do not create stack sections with size more than one physical bank (that
17832  is 256 bytes)
17833 \layout Enumerate
17834
17835 Stack sections should no cross physical bank limits (i.e.
17836  #pragma stack 0x50 0x100)
17837 \layout Standard
17838
17839 These limitations are caused by the fact that only FSRxL is modified when
17840  using SMALL stack model, so no more than 256 bytes of stack can be used.
17841  This problem will disappear after LARGE model is fully implemented.
17842 \layout Subsection
17843
17844 Functions
17845 \layout Standard
17846
17847 In addition to the standard SDCC function keywords, PIC16 port makes available
17848  two more:
17849 \layout List
17850 \labelwidthstring 00.00.0000
17851
17852 wparam Use the WREG to pass one byte of the first function argument.
17853  This improves speed but you may not use this for functions with arguments
17854  that are called via function pointers, otherwise the first byte of the
17855  first parameter will get lost.
17856  Usage:
17857 \layout LyX-Code
17858
17859 void func_wparam(int a) wparam
17860 \layout LyX-Code
17861
17862 {
17863 \layout LyX-Code
17864
17865     /* WREG hold the lower part of a */
17866 \layout LyX-Code
17867
17868     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
17869  */
17870 \layout LyX-Code
17871
17872 ...
17873 \layout LyX-Code
17874
17875 }
17876 \layout Standard
17877
17878 This keyword replaces the deprecated wparam pragma.
17879 \layout List
17880 \labelwidthstring 00.00.0000
17881
17882 shadowregs When entering/exiting an ISR, it is possible to take advantage
17883  of the PIC18F hardware shadow registers which hold the values of WREG,
17884  STATUS and BSR registers.
17885  This can be done by adding the keyword 
17886 \emph on 
17887 shadowregs
17888 \emph default 
17889  before the 
17890 \emph on 
17891 interrupt
17892 \emph default 
17893  keyword in the function's header.
17894 \layout LyX-Code
17895
17896 void isr_shadow(void) shadowregs interrupt 1
17897 \layout LyX-Code
17898
17899 {
17900 \layout LyX-Code
17901
17902 ...
17903 \layout LyX-Code
17904
17905 }
17906 \layout Standard
17907
17908
17909 \emph on 
17910 shadowregs
17911 \emph default 
17912  instructs the code generator not to store/restore WREG, STATUS, BSR when
17913  entering/exiting the ISR.
17914 \layout Subsection
17915
17916 Function return values
17917 \layout Standard
17918
17919 Return values from functions are placed to the appropriate registers following
17920  a modified Microchip policy optimized for SDCC.
17921  The following table shows these registers:
17922 \layout Standard
17923 \align center 
17924
17925 \begin_inset  Tabular
17926 <lyxtabular version="3" rows="6" columns="2">
17927 <features>
17928 <column alignment="center" valignment="top" leftline="true" width="0">
17929 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
17930 <row topline="true" bottomline="true">
17931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17932 \begin_inset Text
17933
17934 \layout Standard
17935
17936 size
17937 \end_inset 
17938 </cell>
17939 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17940 \begin_inset Text
17941
17942 \layout Standard
17943
17944 destination register
17945 \end_inset 
17946 </cell>
17947 </row>
17948 <row topline="true">
17949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17950 \begin_inset Text
17951
17952 \layout Standard
17953
17954 8 bits
17955 \end_inset 
17956 </cell>
17957 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17958 \begin_inset Text
17959
17960 \layout Standard
17961
17962 WREG
17963 \end_inset 
17964 </cell>
17965 </row>
17966 <row topline="true">
17967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17968 \begin_inset Text
17969
17970 \layout Standard
17971
17972 16 bits
17973 \end_inset 
17974 </cell>
17975 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17976 \begin_inset Text
17977
17978 \layout Standard
17979
17980 PRODL:WREG
17981 \end_inset 
17982 </cell>
17983 </row>
17984 <row topline="true">
17985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17986 \begin_inset Text
17987
17988 \layout Standard
17989
17990 24 bits
17991 \end_inset 
17992 </cell>
17993 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17994 \begin_inset Text
17995
17996 \layout Standard
17997
17998 PRODH:PRODL:WREG
17999 \end_inset 
18000 </cell>
18001 </row>
18002 <row topline="true">
18003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18004 \begin_inset Text
18005
18006 \layout Standard
18007
18008 32 bits
18009 \end_inset 
18010 </cell>
18011 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18012 \begin_inset Text
18013
18014 \layout Standard
18015
18016 FSR0L:PRODH:PRODL:WREG
18017 \end_inset 
18018 </cell>
18019 </row>
18020 <row topline="true" bottomline="true">
18021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18022 \begin_inset Text
18023
18024 \layout Standard
18025
18026 >32 bits
18027 \end_inset 
18028 </cell>
18029 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18030 \begin_inset Text
18031
18032 \layout Standard
18033
18034 on stack, FSR0 points to the beginning
18035 \end_inset 
18036 </cell>
18037 </row>
18038 </lyxtabular>
18039
18040 \end_inset 
18041
18042
18043 \layout Subsection
18044
18045 Interrupts
18046 \layout Standard
18047
18048 An interrupt servive routine (ISR) is declared using the 
18049 \emph on 
18050 interrupt
18051 \emph default 
18052  keyword.
18053 \layout LyX-Code
18054
18055 void isr(void) interrupt 
18056 \emph on 
18057 n
18058 \layout LyX-Code
18059
18060 {
18061 \layout LyX-Code
18062
18063 ...
18064 \layout LyX-Code
18065
18066 }
18067 \layout Standard
18068
18069
18070 \emph on 
18071 n
18072 \emph default 
18073  is the interrupt number, which for PIC18F devices can be:
18074 \layout Standard
18075 \align center 
18076
18077 \begin_inset  Tabular
18078 <lyxtabular version="3" rows="4" columns="3">
18079 <features>
18080 <column alignment="center" valignment="top" leftline="true" width="0">
18081 <column alignment="center" valignment="top" leftline="true" width="0">
18082 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18083 <row topline="true" bottomline="true">
18084 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18085 \begin_inset Text
18086
18087 \layout Standard
18088
18089
18090 \emph on 
18091 n
18092 \end_inset 
18093 </cell>
18094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18095 \begin_inset Text
18096
18097 \layout Standard
18098
18099 Interrupt Vector
18100 \end_inset 
18101 </cell>
18102 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18103 \begin_inset Text
18104
18105 \layout Standard
18106
18107 Interrupt Vector Address
18108 \end_inset 
18109 </cell>
18110 </row>
18111 <row topline="true">
18112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18113 \begin_inset Text
18114
18115 \layout Standard
18116
18117 0
18118 \end_inset 
18119 </cell>
18120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18121 \begin_inset Text
18122
18123 \layout Standard
18124
18125 RESET vector
18126 \end_inset 
18127 </cell>
18128 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18129 \begin_inset Text
18130
18131 \layout Standard
18132
18133 0x000000
18134 \end_inset 
18135 </cell>
18136 </row>
18137 <row topline="true">
18138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18139 \begin_inset Text
18140
18141 \layout Standard
18142
18143
18144 \family roman 
18145 \series medium 
18146 \shape up 
18147 \size normal 
18148 \emph off 
18149 \bar no 
18150 \noun off 
18151 \color none
18152 1
18153 \end_inset 
18154 </cell>
18155 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18156 \begin_inset Text
18157
18158 \layout Standard
18159
18160
18161 \family roman 
18162 \series medium 
18163 \shape up 
18164 \size normal 
18165 \emph off 
18166 \bar no 
18167 \noun off 
18168 \color none
18169 HIGH priority interrupts
18170 \end_inset 
18171 </cell>
18172 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18173 \begin_inset Text
18174
18175 \layout Standard
18176
18177 0x000008
18178 \end_inset 
18179 </cell>
18180 </row>
18181 <row topline="true" bottomline="true">
18182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18183 \begin_inset Text
18184
18185 \layout Standard
18186
18187 2
18188 \end_inset 
18189 </cell>
18190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18191 \begin_inset Text
18192
18193 \layout Standard
18194
18195 LOW priority interrupts
18196 \end_inset 
18197 </cell>
18198 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18199 \begin_inset Text
18200
18201 \layout Standard
18202
18203 0x000018
18204 \end_inset 
18205 </cell>
18206 </row>
18207 </lyxtabular>
18208
18209 \end_inset 
18210
18211
18212 \layout Standard
18213
18214 When generating assembly code for ISR the code generator places a 
18215 \noun on 
18216 goto 
18217 \noun default 
18218 instruction at the 
18219 \emph on 
18220 Interrupt Vector Address
18221 \emph default 
18222  which points at the genetated ISR.
18223  This single GOTO instruction is part of an automatically generated 
18224 \emph on 
18225 interrupt entry point
18226 \emph default 
18227  function.
18228  The actuall ISR code is placed as normally would in the code space.
18229  Upon interrupt request, the GOTO instruction is executed which jumps to
18230  the ISR code.
18231  When declaring interrupt functions as _naked this GOTO instruction is 
18232 \series bold 
18233 not
18234 \series default 
18235  generated.
18236  The whole interrupt functions is therefore placed at the Interrupt Vector
18237  Address of the specific interrupt.
18238  This is not a problem for the LOW priority interrupts, but it is a problem
18239  for the RESET and the HIGH priority interrupts because code may be written
18240  at the next interrupt´s vector address and cause undeterminate program
18241  behaviour if that interrupt is raised.
18242 \begin_inset Foot
18243 collapsed false
18244
18245 \layout Standard
18246
18247 This is not a problem when
18248 \layout Enumerate
18249
18250 this is a HIGH interrupt ISR and LOW interrupts are 
18251 \emph on 
18252 disabled
18253 \emph default 
18254  or not used.
18255 \layout Enumerate
18256
18257 when the ISR is small enough not to reach the next interrupt´s vector address.
18258 \end_inset 
18259
18260
18261 \layout Standard
18262
18263
18264 \emph on 
18265 n
18266 \emph default 
18267  is possible to be omitted.
18268  This way a function is generated similar to an ISR, but it is not assigned
18269  to any interrupt.
18270 \layout Standard
18271
18272 When entering an interrupt, currently the PIC16
18273 \begin_inset LatexCommand \index{PIC16}
18274
18275 \end_inset 
18276
18277  port automatically saves the following registers:
18278 \layout Itemize
18279
18280 WREG
18281 \layout Itemize
18282
18283 STATUS
18284 \layout Itemize
18285
18286 BSR
18287 \layout Itemize
18288
18289 PROD (PRODL and PRODH)
18290 \layout Itemize
18291
18292 FSR0 (FSR0L and FSR0H)
18293 \layout Standard
18294
18295 These registers are restored upon return from the interrupt routine.
18296 \begin_inset Foot
18297 collapsed false
18298
18299 \layout Standard
18300
18301 NOTE that when the _naked attribute is specified for an interrupt routine,
18302  then NO registers are stored or restored.
18303 \end_inset 
18304
18305
18306 \layout Subsection
18307
18308 Generic Pointers
18309 \layout Standard
18310
18311 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
18312  There are 3 types of generic pointers currently implemented data, code
18313  and eeprom pointers.
18314  They are differentiated by the value of the 7th and 6th bits of the upper
18315  byte:
18316 \layout Standard
18317 \align center 
18318
18319 \begin_inset  Tabular
18320 <lyxtabular version="3" rows="5" columns="5">
18321 <features>
18322 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18323 <column alignment="center" valignment="top" width="0">
18324 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18325 <column alignment="center" valignment="top" width="0">
18326 <column alignment="left" valignment="top" rightline="true" width="0">
18327 <row topline="true" bottomline="true">
18328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18329 \begin_inset Text
18330
18331 \layout Standard
18332
18333 pointer type
18334 \end_inset 
18335 </cell>
18336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18337 \begin_inset Text
18338
18339 \layout Standard
18340
18341 7th bit
18342 \end_inset 
18343 </cell>
18344 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18345 \begin_inset Text
18346
18347 \layout Standard
18348
18349 6th bit
18350 \end_inset 
18351 </cell>
18352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18353 \begin_inset Text
18354
18355 \layout Standard
18356
18357 rest of the pointer
18358 \end_inset 
18359 </cell>
18360 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18361 \begin_inset Text
18362
18363 \layout Standard
18364
18365 descrption
18366 \end_inset 
18367 </cell>
18368 </row>
18369 <row topline="true" bottomline="true">
18370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18371 \begin_inset Text
18372
18373 \layout Standard
18374
18375 data 
18376 \end_inset 
18377 </cell>
18378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18379 \begin_inset Text
18380
18381 \layout Standard
18382
18383 1
18384 \end_inset 
18385 </cell>
18386 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18387 \begin_inset Text
18388
18389 \layout Standard
18390
18391 0
18392 \end_inset 
18393 </cell>
18394 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18395 \begin_inset Text
18396
18397 \layout Standard
18398
18399
18400 \family typewriter 
18401 \shape slanted 
18402 \emph on 
18403 uuuuuu uuuuxxxx xxxxxxxx
18404 \end_inset 
18405 </cell>
18406 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18407 \begin_inset Text
18408
18409 \layout Standard
18410
18411 a 12-bit data pointer in data RAM memory
18412 \end_inset 
18413 </cell>
18414 </row>
18415 <row bottomline="true">
18416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18417 \begin_inset Text
18418
18419 \layout Standard
18420
18421 code
18422 \end_inset 
18423 </cell>
18424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18425 \begin_inset Text
18426
18427 \layout Standard
18428
18429 0
18430 \end_inset 
18431 </cell>
18432 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18433 \begin_inset Text
18434
18435 \layout Standard
18436
18437 0
18438 \end_inset 
18439 </cell>
18440 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18441 \begin_inset Text
18442
18443 \layout Standard
18444
18445
18446 \family typewriter 
18447 \shape slanted 
18448 \emph on 
18449 uxxxxx xxxxxxxx xxxxxxxx
18450 \end_inset 
18451 </cell>
18452 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18453 \begin_inset Text
18454
18455 \layout Standard
18456
18457 a 21-bit code pointer in FLASH memory
18458 \end_inset 
18459 </cell>
18460 </row>
18461 <row bottomline="true">
18462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18463 \begin_inset Text
18464
18465 \layout Standard
18466
18467 eeprom
18468 \end_inset 
18469 </cell>
18470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18471 \begin_inset Text
18472
18473 \layout Standard
18474
18475 0
18476 \end_inset 
18477 </cell>
18478 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18479 \begin_inset Text
18480
18481 \layout Standard
18482
18483 1
18484 \end_inset 
18485 </cell>
18486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18487 \begin_inset Text
18488
18489 \layout Standard
18490
18491
18492 \family typewriter 
18493 \shape slanted 
18494 \emph on 
18495 uuuuuu uuuuuuxx xxxxxxxx
18496 \end_inset 
18497 </cell>
18498 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18499 \begin_inset Text
18500
18501 \layout Standard
18502
18503 a 10-bit eeprom pointer in EEPROM memory
18504 \end_inset 
18505 </cell>
18506 </row>
18507 <row bottomline="true">
18508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18509 \begin_inset Text
18510
18511 \layout Standard
18512
18513 (unimplemented)
18514 \end_inset 
18515 </cell>
18516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18517 \begin_inset Text
18518
18519 \layout Standard
18520
18521 1
18522 \end_inset 
18523 </cell>
18524 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18525 \begin_inset Text
18526
18527 \layout Standard
18528
18529 1
18530 \end_inset 
18531 </cell>
18532 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18533 \begin_inset Text
18534
18535 \layout Standard
18536
18537
18538 \family typewriter 
18539 \shape slanted 
18540 \emph on 
18541 xxxxxx xxxxxxxx xxxxxxxx
18542 \end_inset 
18543 </cell>
18544 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18545 \begin_inset Text
18546
18547 \layout Standard
18548
18549 unimplemented pointer type
18550 \end_inset 
18551 </cell>
18552 </row>
18553 </lyxtabular>
18554
18555 \end_inset 
18556
18557
18558 \layout Standard
18559
18560 Generic pointer are read and written with a set of library functions which
18561  read/write 1, 2, 3, 4 bytes.
18562 \layout Subsection
18563
18564 PIC16 C Libraries
18565 \layout Subsubsection
18566
18567 Standard I/O Streams
18568 \layout Standard
18569
18570 In the 
18571 \emph on 
18572 stdio.h
18573 \emph default 
18574  the type FILE is defined as:
18575 \layout LyX-Code
18576
18577 typedef char * FILE;
18578 \layout Standard
18579
18580 This type is the stream type implemented I/O in the PIC18F devices.
18581  Also the standard input and output streams are declared in stdio.h:
18582 \layout LyX-Code
18583
18584 extern FILE * stdin;
18585 \layout LyX-Code
18586
18587 extern FILE * stdout;
18588 \layout Standard
18589
18590 The FILE type is actually a generic pointer which defines one more type
18591  of generic pointers, the 
18592 \emph on 
18593 stream 
18594 \emph default 
18595 pointer.
18596  This new type has the format:
18597 \layout Standard
18598 \align center 
18599
18600 \begin_inset  Tabular
18601 <lyxtabular version="3" rows="2" columns="7">
18602 <features>
18603 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18604 <column alignment="center" valignment="top" width="0">
18605 <column alignment="center" valignment="top" leftline="true" width="0">
18606 <column alignment="center" valignment="top" leftline="true" width="0">
18607 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18608 <column alignment="center" valignment="top" width="0">
18609 <column alignment="left" valignment="top" rightline="true" width="0">
18610 <row topline="true" bottomline="true">
18611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18612 \begin_inset Text
18613
18614 \layout Standard
18615
18616 pointer type
18617 \end_inset 
18618 </cell>
18619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18620 \begin_inset Text
18621
18622 \layout Standard
18623
18624 <7:6>
18625 \end_inset 
18626 </cell>
18627 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18628 \begin_inset Text
18629
18630 \layout Standard
18631
18632 <5>
18633 \end_inset 
18634 </cell>
18635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18636 \begin_inset Text
18637
18638 \layout Standard
18639
18640 <4>
18641 \end_inset 
18642 </cell>
18643 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18644 \begin_inset Text
18645
18646 \layout Standard
18647
18648 <3:0>
18649 \end_inset 
18650 </cell>
18651 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18652 \begin_inset Text
18653
18654 \layout Standard
18655
18656 rest of the pointer
18657 \end_inset 
18658 </cell>
18659 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18660 \begin_inset Text
18661
18662 \layout Standard
18663
18664 descrption
18665 \end_inset 
18666 </cell>
18667 </row>
18668 <row topline="true" bottomline="true">
18669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18670 \begin_inset Text
18671
18672 \layout Standard
18673
18674 stream
18675 \end_inset 
18676 </cell>
18677 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18678 \begin_inset Text
18679
18680 \layout Standard
18681
18682 00
18683 \end_inset 
18684 </cell>
18685 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18686 \begin_inset Text
18687
18688 \layout Standard
18689
18690 1
18691 \end_inset 
18692 </cell>
18693 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18694 \begin_inset Text
18695
18696 \layout Standard
18697
18698 0
18699 \end_inset 
18700 </cell>
18701 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18702 \begin_inset Text
18703
18704 \layout Standard
18705
18706 nnnn
18707 \end_inset 
18708 </cell>
18709 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18710 \begin_inset Text
18711
18712 \layout Standard
18713
18714
18715 \family typewriter 
18716 \shape slanted 
18717 \emph on 
18718 uuuuuuuu uuuuuuuu
18719 \end_inset 
18720 </cell>
18721 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18722 \begin_inset Text
18723
18724 \layout Standard
18725
18726 upper byte high nubble is 0x2n, the rest are zeroes
18727 \end_inset 
18728 </cell>
18729 </row>
18730 </lyxtabular>
18731
18732 \end_inset 
18733
18734
18735 \layout Standard
18736
18737 Currently implemented there are 3 types of streams defined:
18738 \layout Standard
18739 \align center 
18740
18741 \begin_inset  Tabular
18742 <lyxtabular version="3" rows="4" columns="4">
18743 <features>
18744 <column alignment="center" valignment="top" leftline="true" width="0">
18745 <column alignment="center" valignment="top" leftline="true" width="0">
18746 <column alignment="center" valignment="top" leftline="true" width="0">
18747 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
18748 <row topline="true" bottomline="true">
18749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18750 \begin_inset Text
18751
18752 \layout Standard
18753
18754 stream type
18755 \end_inset 
18756 </cell>
18757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18758 \begin_inset Text
18759
18760 \layout Standard
18761
18762 value
18763 \end_inset 
18764 </cell>
18765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18766 \begin_inset Text
18767
18768 \layout Standard
18769
18770 module
18771 \end_inset 
18772 </cell>
18773 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18774 \begin_inset Text
18775
18776 \layout Standard
18777
18778 description
18779 \end_inset 
18780 </cell>
18781 </row>
18782 <row topline="true">
18783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18784 \begin_inset Text
18785
18786 \layout Standard
18787
18788 STREAM_USART
18789 \end_inset 
18790 </cell>
18791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18792 \begin_inset Text
18793
18794 \layout Standard
18795
18796
18797 \family typewriter 
18798 0x200000UL
18799 \end_inset 
18800 </cell>
18801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18802 \begin_inset Text
18803
18804 \layout Standard
18805
18806 USART
18807 \end_inset 
18808 </cell>
18809 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18810 \begin_inset Text
18811
18812 \layout Standard
18813
18814 Writes/Reads characters via the USART peripheral
18815 \end_inset 
18816 </cell>
18817 </row>
18818 <row topline="true">
18819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18820 \begin_inset Text
18821
18822 \layout Standard
18823
18824 STREAM_MSSP
18825 \end_inset 
18826 </cell>
18827 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18828 \begin_inset Text
18829
18830 \layout Standard
18831
18832
18833 \family typewriter 
18834 0x210000UL
18835 \end_inset 
18836 </cell>
18837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18838 \begin_inset Text
18839
18840 \layout Standard
18841
18842 MSSP
18843 \end_inset 
18844 </cell>
18845 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18846 \begin_inset Text
18847
18848 \layout Standard
18849
18850 Writes/Reads characters via the MSSP peripheral
18851 \end_inset 
18852 </cell>
18853 </row>
18854 <row topline="true" bottomline="true">
18855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18856 \begin_inset Text
18857
18858 \layout Standard
18859
18860 STREAM_USER
18861 \end_inset 
18862 </cell>
18863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18864 \begin_inset Text
18865
18866 \layout Standard
18867
18868
18869 \family typewriter 
18870 0x2f0000UL
18871 \end_inset 
18872 </cell>
18873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18874 \begin_inset Text
18875
18876 \layout Standard
18877
18878 (none)
18879 \end_inset 
18880 </cell>
18881 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18882 \begin_inset Text
18883
18884 \layout Standard
18885
18886 Writes/Reads characters via used defined functions
18887 \end_inset 
18888 </cell>
18889 </row>
18890 </lyxtabular>
18891
18892 \end_inset 
18893
18894
18895 \layout Standard
18896
18897 The stream identifiers are declared as macros in the stdio.h header.
18898 \layout Standard
18899
18900 In the libc library there exist the functions that are used to write to
18901  each of the above streams.
18902  These are
18903 \layout List
18904 \labelwidthstring 00.00.0000
18905
18906 _
18907 \begin_inset ERT
18908 status Collapsed
18909
18910 \layout Standard
18911
18912 \backslash 
18913 /
18914 \end_inset 
18915
18916 _stream_usart_putchar writes a character at the USART stream
18917 \layout List
18918 \labelwidthstring 00.00.0000
18919
18920 _
18921 \begin_inset ERT
18922 status Collapsed
18923
18924 \layout Standard
18925
18926 \backslash 
18927 /
18928 \end_inset 
18929
18930 _stream_mssp_putchar writes a character at the MSSP stream
18931 \layout List
18932 \labelwidthstring 00.00.0000
18933
18934 putchar dummy function.
18935  This writes a character to a user specified manner.
18936 \layout Standard
18937
18938 In order to increase performance 
18939 \emph on 
18940 putchar 
18941 \emph default 
18942 is declared in stdio.h as having its parameter in WREG (it has the wparam
18943  keyword).
18944  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
18945  in a user-friendly way.
18946  
18947 \emph on 
18948 arg
18949 \emph default 
18950  is the name of the variable that holds the character to print.
18951  An example follows:
18952 \layout LyX-Code
18953
18954 #include <pic18fregs.h>
18955 \newline 
18956 #include <stdio.h>
18957 \newline 
18958
18959 \newline 
18960 PUTCHAR( c )
18961 \layout LyX-Code
18962
18963 {
18964 \layout LyX-Code
18965
18966     PORTA = c;    /* dump character c to PORTA */
18967 \layout LyX-Code
18968
18969
18970 \newline 
18971
18972 \newline 
18973 void main(void)
18974 \layout LyX-Code
18975
18976 {
18977 \layout LyX-Code
18978
18979     stdout = STREAM_USER;    /* this is not necessery, since stdout points
18980 \layout LyX-Code
18981
18982                               * by default to STREAM_USER */
18983 \layout LyX-Code
18984
18985     printf (¨This is a printf test
18986 \backslash 
18987 n¨);
18988 \layout LyX-Code
18989
18990 }
18991 \layout LyX-Code
18992
18993 \layout Subsubsection
18994
18995 Printing functions
18996 \layout Standard
18997
18998 PIC16 contains an implementation of the printf-family of functions.
18999  There exist the following functions:
19000 \layout LyX-Code
19001
19002 extern unsigned int sprintf(char *buf, char *fmt, ...);
19003 \layout LyX-Code
19004
19005 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
19006 \layout LyX-Code
19007
19008 \layout LyX-Code
19009
19010 extern unsigned int printf(char *fmt, ...);
19011 \layout LyX-Code
19012
19013 extern unsigned int vprintf(char *fmt, va_lista ap);
19014 \layout LyX-Code
19015
19016 \layout LyX-Code
19017
19018 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
19019 \layout LyX-Code
19020
19021 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
19022 \layout Standard
19023
19024 For sprintf and vsprintf 
19025 \emph on 
19026 buf 
19027 \emph default 
19028 should normally be a data pointer where the resulting string will be placed.
19029  No range checking is done so the user should allocate the necessery buffer.
19030  For fprintf and vfprintf 
19031 \emph on 
19032 fp
19033 \emph default 
19034  should be a stream pointer (i.e.
19035  stdout, STREAM_MSSP, etc...).
19036 \layout Subsubsection
19037
19038 Signals
19039 \layout Standard
19040
19041 The PIC18F family of microcontrollers supports a number of interrupt sources.
19042  A list of these interrupts is shown in the following table:
19043 \layout Standard
19044 \align center 
19045
19046 \begin_inset  Tabular
19047 <lyxtabular version="3" rows="11" columns="4">
19048 <features>
19049 <column alignment="left" valignment="top" leftline="true" width="0">
19050 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19051 <column alignment="left" valignment="top" leftline="true" width="0">
19052 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
19053 <row topline="true" bottomline="true">
19054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19055 \begin_inset Text
19056
19057 \layout Standard
19058
19059 signal name
19060 \end_inset 
19061 </cell>
19062 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19063 \begin_inset Text
19064
19065 \layout Standard
19066
19067 description
19068 \end_inset 
19069 </cell>
19070 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19071 \begin_inset Text
19072
19073 \layout Standard
19074
19075 signal name
19076 \end_inset 
19077 </cell>
19078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19079 \begin_inset Text
19080
19081 \layout Standard
19082
19083 descritpion
19084 \end_inset 
19085 </cell>
19086 </row>
19087 <row topline="true">
19088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19089 \begin_inset Text
19090
19091 \layout Standard
19092
19093 SIG_RB
19094 \end_inset 
19095 </cell>
19096 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19097 \begin_inset Text
19098
19099 \layout Standard
19100
19101 PORTB change interrupt
19102 \end_inset 
19103 </cell>
19104 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19105 \begin_inset Text
19106
19107 \layout Standard
19108
19109 SIG_EE
19110 \end_inset 
19111 </cell>
19112 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19113 \begin_inset Text
19114
19115 \layout Standard
19116
19117 EEPROM/FLASH write complete interrupt
19118 \end_inset 
19119 </cell>
19120 </row>
19121 <row topline="true">
19122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19123 \begin_inset Text
19124
19125 \layout Standard
19126
19127 SIG_INT0
19128 \end_inset 
19129 </cell>
19130 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19131 \begin_inset Text
19132
19133 \layout Standard
19134
19135 INT0 external interrupt
19136 \end_inset 
19137 </cell>
19138 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19139 \begin_inset Text
19140
19141 \layout Standard
19142
19143 SIG_BCOL
19144 \end_inset 
19145 </cell>
19146 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19147 \begin_inset Text
19148
19149 \layout Standard
19150
19151 Bus collision interrupt
19152 \end_inset 
19153 </cell>
19154 </row>
19155 <row topline="true">
19156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19157 \begin_inset Text
19158
19159 \layout Standard
19160
19161 SIG_INT1
19162 \end_inset 
19163 </cell>
19164 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19165 \begin_inset Text
19166
19167 \layout Standard
19168
19169 INT1 external interrupt
19170 \end_inset 
19171 </cell>
19172 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19173 \begin_inset Text
19174
19175 \layout Standard
19176
19177 SIG_LVD
19178 \end_inset 
19179 </cell>
19180 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19181 \begin_inset Text
19182
19183 \layout Standard
19184
19185 Low voltage detect interrupt
19186 \end_inset 
19187 </cell>
19188 </row>
19189 <row topline="true">
19190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19191 \begin_inset Text
19192
19193 \layout Standard
19194
19195 SIG_INT2
19196 \end_inset 
19197 </cell>
19198 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19199 \begin_inset Text
19200
19201 \layout Standard
19202
19203 INT2 external interrupt
19204 \end_inset 
19205 </cell>
19206 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19207 \begin_inset Text
19208
19209 \layout Standard
19210
19211 SIG_PSP
19212 \end_inset 
19213 </cell>
19214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19215 \begin_inset Text
19216
19217 \layout Standard
19218
19219 Parallel slave port interrupt
19220 \end_inset 
19221 </cell>
19222 </row>
19223 <row topline="true">
19224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19225 \begin_inset Text
19226
19227 \layout Standard
19228
19229 SIG_CCP1
19230 \end_inset 
19231 </cell>
19232 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19233 \begin_inset Text
19234
19235 \layout Standard
19236
19237 CCP1 module interrupt
19238 \end_inset 
19239 </cell>
19240 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19241 \begin_inset Text
19242
19243 \layout Standard
19244
19245 SIG_AD
19246 \end_inset 
19247 </cell>
19248 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19249 \begin_inset Text
19250
19251 \layout Standard
19252
19253 AD convertion complete interrupt
19254 \end_inset 
19255 </cell>
19256 </row>
19257 <row topline="true">
19258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19259 \begin_inset Text
19260
19261 \layout Standard
19262
19263 SIG_CCP2
19264 \end_inset 
19265 </cell>
19266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19267 \begin_inset Text
19268
19269 \layout Standard
19270
19271 CCP2 module interrupt
19272 \end_inset 
19273 </cell>
19274 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19275 \begin_inset Text
19276
19277 \layout Standard
19278
19279 SIG_RC
19280 \end_inset 
19281 </cell>
19282 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19283 \begin_inset Text
19284
19285 \layout Standard
19286
19287 USART receive interrupt
19288 \end_inset 
19289 </cell>
19290 </row>
19291 <row topline="true">
19292 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19293 \begin_inset Text
19294
19295 \layout Standard
19296
19297 SIG_TMR0
19298 \end_inset 
19299 </cell>
19300 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19301 \begin_inset Text
19302
19303 \layout Standard
19304
19305 TMR0 overflow interrupt
19306 \end_inset 
19307 </cell>
19308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19309 \begin_inset Text
19310
19311 \layout Standard
19312
19313 SIG_TX
19314 \end_inset 
19315 </cell>
19316 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19317 \begin_inset Text
19318
19319 \layout Standard
19320
19321 USART transmit interrupt
19322 \end_inset 
19323 </cell>
19324 </row>
19325 <row topline="true">
19326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19327 \begin_inset Text
19328
19329 \layout Standard
19330
19331 SIG_TMR1
19332 \end_inset 
19333 </cell>
19334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19335 \begin_inset Text
19336
19337 \layout Standard
19338
19339 TMR1 overflow interrupt
19340 \end_inset 
19341 </cell>
19342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19343 \begin_inset Text
19344
19345 \layout Standard
19346
19347 SIG_MSSP
19348 \end_inset 
19349 </cell>
19350 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19351 \begin_inset Text
19352
19353 \layout Standard
19354
19355 SSP receive/transmit interrupt
19356 \end_inset 
19357 </cell>
19358 </row>
19359 <row topline="true">
19360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19361 \begin_inset Text
19362
19363 \layout Standard
19364
19365 SIG_TMR2
19366 \end_inset 
19367 </cell>
19368 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19369 \begin_inset Text
19370
19371 \layout Standard
19372
19373 TMR2 matches PR2 interrupt
19374 \end_inset 
19375 </cell>
19376 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19377 \begin_inset Text
19378
19379 \layout Standard
19380
19381 \end_inset 
19382 </cell>
19383 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19384 \begin_inset Text
19385
19386 \layout Standard
19387
19388 \end_inset 
19389 </cell>
19390 </row>
19391 <row topline="true" bottomline="true">
19392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19393 \begin_inset Text
19394
19395 \layout Standard
19396
19397 SIG_TMR3
19398 \end_inset 
19399 </cell>
19400 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19401 \begin_inset Text
19402
19403 \layout Standard
19404
19405 TMR3 overflow interrupt
19406 \end_inset 
19407 </cell>
19408 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19409 \begin_inset Text
19410
19411 \layout Standard
19412
19413 \end_inset 
19414 </cell>
19415 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19416 \begin_inset Text
19417
19418 \layout Standard
19419
19420 \end_inset 
19421 </cell>
19422 </row>
19423 </lyxtabular>
19424
19425 \end_inset 
19426
19427
19428 \layout Standard
19429
19430 The prototypes for these names are defined in the header file 
19431 \emph on 
19432 signal.h
19433 \emph default 
19434  .
19435 \layout Standard
19436
19437 In order to simplify signal handling, a number of macros is provided:
19438 \layout List
19439 \labelwidthstring 00.00.0000
19440
19441 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
19442  high priority interrupts.
19443  
19444 \emph on 
19445 name
19446 \emph default 
19447  is the function name to use.
19448 \layout List
19449 \labelwidthstring 00.00.0000
19450
19451 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
19452  low priority interrupt.
19453  
19454 \emph on 
19455 name
19456 \emph default 
19457  is the function name to use.
19458 \layout List
19459 \labelwidthstring 00.00.0000
19460
19461 DEF_HANDLER(sig,handler) define a handler for signal 
19462 \emph on 
19463 sig.
19464 \layout List
19465 \labelwidthstring 00.00.0000
19466
19467 END_DEF end the declaration of the dispatch table.
19468 \layout Standard
19469
19470 Additionally there are two more macros to simplify the declaration of the
19471  signal handler:
19472 \layout List
19473 \labelwidthstring 00.00.0000
19474
19475
19476 \series medium 
19477 SIGHANDLER(handler) 
19478 \series default 
19479 this declares the function prototype for the 
19480 \emph on 
19481 handler
19482 \emph default 
19483  function.
19484 \layout List
19485 \labelwidthstring 00.00.0000
19486
19487 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
19488 \layout Standard
19489
19490 An example of using the macros above is shown below:
19491 \layout LyX-Code
19492
19493 #include <pic18fregs.h>
19494 \layout LyX-Code
19495
19496 #include <signal.h>
19497 \newline 
19498
19499 \newline 
19500 DEF_INTHIGH(high_int)
19501 \layout LyX-Code
19502
19503 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
19504 \layout LyX-Code
19505
19506 DEF_HANDLER(SIG_BCOL, _bcol_handler)
19507 \layout LyX-Code
19508
19509 END_DEF
19510 \newline 
19511
19512 \newline 
19513 SIGHANDLER(_tmr0_handler)
19514 \layout LyX-Code
19515
19516 {
19517 \layout LyX-Code
19518
19519   /* action to be taken when timer 0 overflows */
19520 \layout LyX-Code
19521
19522 }
19523 \newline 
19524
19525 \newline 
19526 SIGHANDLERNAKED(_bcol_handler)
19527 \layout LyX-Code
19528
19529 {
19530 \layout LyX-Code
19531
19532   _asm
19533 \layout LyX-Code
19534
19535     /* action to be taken when bus collision occurs */
19536 \layout LyX-Code
19537
19538     retfie
19539 \layout LyX-Code
19540
19541  _endasm;
19542 \layout LyX-Code
19543
19544 }
19545 \layout Standard
19546
19547
19548 \series bold 
19549 NOTES:
19550 \series default 
19551  Special care should be taken when using the above scheme:
19552 \layout Itemize
19553
19554 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
19555 \layout Itemize
19556
19557 when declaring SIGHANDLERNAKED handler never forget to use 
19558 \emph on 
19559 retfie
19560 \emph default 
19561  for proper returning.
19562 \layout Subsection
19563
19564 PIC16 Port -- Tips
19565 \layout Standard
19566
19567 Here you can find some general tips for compiling programs with SDCC/pic16.
19568 \layout Subsubsection
19569
19570 Stack size
19571 \layout Standard
19572
19573 The default stack size (that is 64 bytes) probably is enough for many programs.
19574  One must take care that when there are many levels of function nesting,
19575  or there is excessive usage of stack, its size should be extended.
19576  An example of such a case is the printf/sprintf family of functions.
19577  If you encounter problems like not being able to print integers, then you
19578  need to set the stack size around the maximum (256 for small stack model).
19579  The following diagram shows what happens when calling printf to print an
19580  integer:
19581 \layout LyX-Code
19582
19583 printf () --> ltoa () --> ultoa () --> divschar ()
19584 \layout Standard
19585
19586 It is should be understood that stack is easily consumed when calling complicate
19587 d functions.
19588  Using command line arguments like -
19589 \begin_inset ERT
19590 status Collapsed
19591
19592 \layout Standard
19593
19594 \backslash 
19595 /
19596 \end_inset 
19597
19598 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
19599  stack frames.
19600  Other ways to reduce stack usage may exist.
19601 \layout Chapter
19602
19603 Debugging with SDCDB
19604 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
19605
19606 \end_inset 
19607
19608
19609 \begin_inset LatexCommand \index{sdcdb (debugger)}
19610
19611 \end_inset 
19612
19613  
19614 \layout Standard
19615
19616 SDCC is distributed with a source level debugger
19617 \begin_inset LatexCommand \index{Debugger}
19618
19619 \end_inset 
19620
19621 .
19622  The debugger uses a command line interface, the command repertoire of the
19623  debugger has been kept as close to gdb
19624 \begin_inset LatexCommand \index{gdb}
19625
19626 \end_inset 
19627
19628  (the GNU debugger) as possible.
19629  The configuration and build process is part of the standard compiler installati
19630 on, which also builds and installs the debugger in the target directory
19631  specified during configuration.
19632  The debugger allows you debug BOTH at the C source and at the ASM source
19633  level.
19634  Sdcdb is available on Unix platforms only.
19635 \layout Section
19636
19637 Compiling for Debugging
19638 \layout Standard
19639
19640 The -
19641 \begin_inset ERT
19642 status Collapsed
19643
19644 \layout Standard
19645
19646 \backslash 
19647 /
19648 \end_inset 
19649
19650 -debug
19651 \begin_inset LatexCommand \index{-\/-debug}
19652
19653 \end_inset 
19654
19655  option must be specified for all files for which debug information is to
19656  be generated.
19657  The complier generates a .adb file for each of these files.
19658  The linker creates the .cdb
19659 \begin_inset LatexCommand \index{<file>.cdb}
19660
19661 \end_inset 
19662
19663  file from the .adb
19664 \begin_inset LatexCommand \index{<file>.adb}
19665
19666 \end_inset 
19667
19668  files and the address information.
19669  This .cdb is used by the debugger.
19670 \layout Section
19671
19672 How the Debugger Works
19673 \layout Standard
19674
19675 When the -
19676 \begin_inset ERT
19677 status Collapsed
19678
19679 \layout Standard
19680
19681 \backslash 
19682 /
19683 \end_inset 
19684
19685 -debug option is specified the compiler generates extra symbol information
19686  some of which are put into the assembler source and some are put into the
19687  .adb file.
19688   Then the linker creates the .cdb file from the individual .adb files with
19689  the address information for the symbols.
19690  The debugger reads the symbolic information generated by the compiler &
19691  the address information generated by the linker.
19692  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
19693  execution is controlled by the debugger.
19694  When a command is issued for the debugger, it translates it into appropriate
19695  commands for the simulator.
19696 \layout Section
19697
19698 Starting the Debugger
19699 \layout Standard
19700
19701 The debugger can be started using the following command line.
19702  (Assume the file you are debugging has the file name foo).
19703 \newline 
19704
19705 \newline 
19706
19707 \family sans 
19708 \series bold 
19709 sdcdb foo
19710 \newline 
19711
19712 \family default 
19713 \series default 
19714
19715 \newline 
19716 The debugger will look for the following files.
19717 \layout Itemize
19718
19719 foo.c - the source file.
19720 \layout Itemize
19721
19722 foo.cdb - the debugger symbol information file.
19723 \layout Itemize
19724
19725 foo.ihx - the Intel hex format
19726 \begin_inset LatexCommand \index{Intel hex format}
19727
19728 \end_inset 
19729
19730  object file.
19731 \layout Section
19732
19733 Command Line Options.
19734 \layout Itemize
19735
19736 -
19737 \begin_inset ERT
19738 status Collapsed
19739
19740 \layout Standard
19741
19742 \backslash 
19743 /
19744 \end_inset 
19745
19746 -directory=<source file directory> this option can used to specify the directory
19747  search list.
19748  The debugger will look into the directory list specified for source, cdb
19749  & ihx files.
19750  The items in the directory list must be separated by ':', e.g.
19751  if the source files can be in the directories /home/src1 and /home/src2,
19752  the -
19753 \begin_inset ERT
19754 status Collapsed
19755
19756 \layout Standard
19757
19758 \backslash 
19759 /
19760 \end_inset 
19761
19762 -directory option should be -
19763 \begin_inset ERT
19764 status Collapsed
19765
19766 \layout Standard
19767
19768 \backslash 
19769 /
19770 \end_inset 
19771
19772 -directory=/home/src1:/home/src2.
19773  Note there can be no spaces in the option.
19774  
19775 \layout Itemize
19776
19777 -cd <directory> - change to the <directory>.
19778 \layout Itemize
19779
19780 -fullname - used by GUI front ends.
19781 \layout Itemize
19782
19783 -cpu <cpu-type> - this argument is passed to the simulator please see the
19784  simulator docs for details.
19785 \layout Itemize
19786
19787 -X <Clock frequency > this options is passed to the simulator please see
19788  the simulator docs for details.
19789 \layout Itemize
19790
19791 -s <serial port file> passed to simulator see the simulator docs for details.
19792 \layout Itemize
19793
19794 -S <serial in,out> passed to simulator see the simulator docs for details.
19795 \layout Itemize
19796
19797 -k <port number> passed to simulator see the simulator docs for details.
19798 \layout Section
19799
19800 Debugger Commands.
19801 \layout Standard
19802
19803 As mentioned earlier the command interface for the debugger has been deliberatel
19804 y kept as close the GNU debugger gdb, as possible.
19805  This will help the integration with existing graphical user interfaces
19806  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
19807  If you use a graphical user interface for the debugger you can skip the
19808  next sections.
19809 \layout Subsubsection*
19810
19811 break [line | file:line | function | file:function]
19812 \layout Standard
19813
19814 Set breakpoint at specified line or function:
19815 \newline 
19816
19817 \newline 
19818
19819 \family sans 
19820 \series bold 
19821 sdcdb>break 100 
19822 \newline 
19823 sdcdb>break foo.c:100
19824 \newline 
19825 sdcdb>break funcfoo
19826 \newline 
19827 sdcdb>break foo.c:funcfoo
19828 \layout Subsubsection*
19829
19830 clear [line | file:line | function | file:function ]
19831 \layout Standard
19832
19833 Clear breakpoint at specified line or function:
19834 \newline 
19835
19836 \newline 
19837
19838 \family sans 
19839 \series bold 
19840 sdcdb>clear 100
19841 \newline 
19842 sdcdb>clear foo.c:100
19843 \newline 
19844 sdcdb>clear funcfoo
19845 \newline 
19846 sdcdb>clear foo.c:funcfoo
19847 \layout Subsubsection*
19848
19849 continue
19850 \layout Standard
19851
19852 Continue program being debugged, after breakpoint.
19853 \layout Subsubsection*
19854
19855 finish
19856 \layout Standard
19857
19858 Execute till the end of the current function.
19859 \layout Subsubsection*
19860
19861 delete [n]
19862 \layout Standard
19863
19864 Delete breakpoint number 'n'.
19865  If used without any option clear ALL user defined break points.
19866 \layout Subsubsection*
19867
19868 info [break | stack | frame | registers ]
19869 \layout Itemize
19870
19871 info break - list all breakpoints
19872 \layout Itemize
19873
19874 info stack - show the function call stack.
19875 \layout Itemize
19876
19877 info frame - show information about the current execution frame.
19878 \layout Itemize
19879
19880 info registers - show content of all registers.
19881 \layout Subsubsection*
19882
19883 step
19884 \layout Standard
19885
19886 Step program until it reaches a different source line.
19887  Note: pressing <return> repeats the last command.
19888 \layout Subsubsection*
19889
19890 next
19891 \layout Standard
19892
19893 Step program, proceeding through subroutine calls.
19894 \layout Subsubsection*
19895
19896 run
19897 \layout Standard
19898
19899 Start debugged program.
19900 \layout Subsubsection*
19901
19902 ptype variable 
19903 \layout Standard
19904
19905 Print type information of the variable.
19906 \layout Subsubsection*
19907
19908 print variable
19909 \layout Standard
19910
19911 print value of variable.
19912 \layout Subsubsection*
19913
19914 file filename
19915 \layout Standard
19916
19917 load the given file name.
19918  Note this is an alternate method of loading file for debugging.
19919 \layout Subsubsection*
19920
19921 frame
19922 \layout Standard
19923
19924 print information about current frame.
19925 \layout Subsubsection*
19926
19927 set srcmode
19928 \layout Standard
19929
19930 Toggle between C source & assembly source.
19931 \layout Subsubsection*
19932
19933 ! simulator command
19934 \layout Standard
19935
19936 Send the string following '!' to the simulator, the simulator response is
19937  displayed.
19938  Note the debugger does not interpret the command being sent to the simulator,
19939  so if a command like 'go' is sent the debugger can loose its execution
19940  context and may display incorrect values.
19941 \layout Subsubsection*
19942
19943 quit
19944 \layout Standard
19945
19946 "Watch me now.
19947  Iam going Down.
19948  My name is Bobby Brown"
19949 \layout Section
19950
19951 Interfacing with XEmacs
19952 \begin_inset LatexCommand \index{XEmacs}
19953
19954 \end_inset 
19955
19956
19957 \begin_inset LatexCommand \index{Emacs}
19958
19959 \end_inset 
19960
19961 .
19962 \layout Standard
19963
19964 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
19965  sdcdb.el and sdcdbsrc.el.
19966  These two files can be found in the $(prefix)/bin directory after the installat
19967 ion is complete.
19968  These files need to be loaded into XEmacs for the interface to work.
19969  This can be done at XEmacs startup time by inserting the following into
19970  your '.xemacs' file (which can be found in your HOME directory): 
19971 \newline 
19972
19973 \newline 
19974
19975 \family typewriter 
19976 (load-file sdcdbsrc.el) 
19977 \family default 
19978
19979 \newline 
19980
19981 \newline 
19982 .xemacs is a lisp file so the () around the command is REQUIRED.
19983  The files can also be loaded dynamically while XEmacs is running, set the
19984  environment variable 'EMACSLOADPATH' to the installation bin directory
19985  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
19986  To start the interface enter the following command: 
19987 \newline 
19988
19989 \newline 
19990
19991 \family sans 
19992 \series bold 
19993 ESC-x sdcdbsrc
19994 \family default 
19995 \series default 
19996
19997 \newline 
19998
19999 \newline 
20000 You will prompted to enter the file name to be debugged.
20001  
20002 \newline 
20003
20004 \newline 
20005 The command line options that are passed to the simulator directly are bound
20006  to default values in the file sdcdbsrc.el.
20007  The variables are listed below, these values maybe changed as required.
20008 \layout Itemize
20009
20010 sdcdbsrc-cpu-type '51
20011 \layout Itemize
20012
20013 sdcdbsrc-frequency '11059200
20014 \layout Itemize
20015
20016 sdcdbsrc-serial nil
20017 \layout Standard
20018
20019 The following is a list of key mapping for the debugger interface.
20020 \layout Standard
20021
20022 \SpecialChar ~
20023
20024 \family typewriter 
20025
20026 \newline 
20027 ;;\SpecialChar ~
20028 Current Listing :: 
20029 \newline 
20030 ;;key\SpecialChar ~
20031 \SpecialChar ~
20032 \SpecialChar ~
20033 \SpecialChar ~
20034 \SpecialChar ~
20035 \SpecialChar ~
20036 \SpecialChar ~
20037 \SpecialChar ~
20038 \SpecialChar ~
20039 \SpecialChar ~
20040 \SpecialChar ~
20041 \SpecialChar ~
20042 \SpecialChar ~
20043 \SpecialChar ~
20044 binding\SpecialChar ~
20045 \SpecialChar ~
20046 \SpecialChar ~
20047 \SpecialChar ~
20048 \SpecialChar ~
20049 \SpecialChar ~
20050 \SpecialChar ~
20051 \SpecialChar ~
20052 \SpecialChar ~
20053 \SpecialChar ~
20054 \SpecialChar ~
20055 \SpecialChar ~
20056 \SpecialChar ~
20057 \SpecialChar ~
20058 \SpecialChar ~
20059 \SpecialChar ~
20060 \SpecialChar ~
20061 \SpecialChar ~
20062 \SpecialChar ~
20063 \SpecialChar ~
20064 \SpecialChar ~
20065 \SpecialChar ~
20066 Comment 
20067 \newline 
20068 ;;---\SpecialChar ~
20069 \SpecialChar ~
20070 \SpecialChar ~
20071 \SpecialChar ~
20072 \SpecialChar ~
20073 \SpecialChar ~
20074 \SpecialChar ~
20075 \SpecialChar ~
20076 \SpecialChar ~
20077 \SpecialChar ~
20078 \SpecialChar ~
20079 \SpecialChar ~
20080 \SpecialChar ~
20081 \SpecialChar ~
20082 -------\SpecialChar ~
20083 \SpecialChar ~
20084 \SpecialChar ~
20085 \SpecialChar ~
20086 \SpecialChar ~
20087 \SpecialChar ~
20088 \SpecialChar ~
20089 \SpecialChar ~
20090 \SpecialChar ~
20091 \SpecialChar ~
20092 \SpecialChar ~
20093 \SpecialChar ~
20094 \SpecialChar ~
20095 \SpecialChar ~
20096 \SpecialChar ~
20097 \SpecialChar ~
20098 \SpecialChar ~
20099 \SpecialChar ~
20100 \SpecialChar ~
20101 \SpecialChar ~
20102 \SpecialChar ~
20103 \SpecialChar ~
20104 -------
20105 \newline 
20106 ;; 
20107 \newline 
20108 ;;\SpecialChar ~
20109 n\SpecialChar ~
20110 \SpecialChar ~
20111 \SpecialChar ~
20112 \SpecialChar ~
20113 \SpecialChar ~
20114 \SpecialChar ~
20115 \SpecialChar ~
20116 \SpecialChar ~
20117 \SpecialChar ~
20118 \SpecialChar ~
20119 \SpecialChar ~
20120 \SpecialChar ~
20121 \SpecialChar ~
20122 \SpecialChar ~
20123 \SpecialChar ~
20124 sdcdb-next-from-src\SpecialChar ~
20125 \SpecialChar ~
20126 \SpecialChar ~
20127 \SpecialChar ~
20128 \SpecialChar ~
20129 \SpecialChar ~
20130 \SpecialChar ~
20131 \SpecialChar ~
20132 \SpecialChar ~
20133 \SpecialChar ~
20134 SDCDB next command 
20135 \newline 
20136 ;;\SpecialChar ~
20137 b\SpecialChar ~
20138 \SpecialChar ~
20139 \SpecialChar ~
20140 \SpecialChar ~
20141 \SpecialChar ~
20142 \SpecialChar ~
20143 \SpecialChar ~
20144 \SpecialChar ~
20145 \SpecialChar ~
20146 \SpecialChar ~
20147 \SpecialChar ~
20148 \SpecialChar ~
20149 \SpecialChar ~
20150 \SpecialChar ~
20151 \SpecialChar ~
20152 sdcdb-back-from-src\SpecialChar ~
20153 \SpecialChar ~
20154 \SpecialChar ~
20155 \SpecialChar ~
20156 \SpecialChar ~
20157 \SpecialChar ~
20158 \SpecialChar ~
20159 \SpecialChar ~
20160 \SpecialChar ~
20161 \SpecialChar ~
20162 SDCDB back command 
20163 \newline 
20164 ;;\SpecialChar ~
20165 c\SpecialChar ~
20166 \SpecialChar ~
20167 \SpecialChar ~
20168 \SpecialChar ~
20169 \SpecialChar ~
20170 \SpecialChar ~
20171 \SpecialChar ~
20172 \SpecialChar ~
20173 \SpecialChar ~
20174 \SpecialChar ~
20175 \SpecialChar ~
20176 \SpecialChar ~
20177 \SpecialChar ~
20178 \SpecialChar ~
20179 \SpecialChar ~
20180 sdcdb-cont-from-src\SpecialChar ~
20181 \SpecialChar ~
20182 \SpecialChar ~
20183 \SpecialChar ~
20184 \SpecialChar ~
20185 \SpecialChar ~
20186 \SpecialChar ~
20187 \SpecialChar ~
20188 \SpecialChar ~
20189 \SpecialChar ~
20190 SDCDB continue command
20191 \newline 
20192 ;;\SpecialChar ~
20193 s\SpecialChar ~
20194 \SpecialChar ~
20195 \SpecialChar ~
20196 \SpecialChar ~
20197 \SpecialChar ~
20198 \SpecialChar ~
20199 \SpecialChar ~
20200 \SpecialChar ~
20201 \SpecialChar ~
20202 \SpecialChar ~
20203 \SpecialChar ~
20204 \SpecialChar ~
20205 \SpecialChar ~
20206 \SpecialChar ~
20207 \SpecialChar ~
20208 sdcdb-step-from-src\SpecialChar ~
20209 \SpecialChar ~
20210 \SpecialChar ~
20211 \SpecialChar ~
20212 \SpecialChar ~
20213 \SpecialChar ~
20214 \SpecialChar ~
20215 \SpecialChar ~
20216 \SpecialChar ~
20217 \SpecialChar ~
20218 SDCDB step command 
20219 \newline 
20220 ;;\SpecialChar ~
20221 ?\SpecialChar ~
20222 \SpecialChar ~
20223 \SpecialChar ~
20224 \SpecialChar ~
20225 \SpecialChar ~
20226 \SpecialChar ~
20227 \SpecialChar ~
20228 \SpecialChar ~
20229 \SpecialChar ~
20230 \SpecialChar ~
20231 \SpecialChar ~
20232 \SpecialChar ~
20233 \SpecialChar ~
20234 \SpecialChar ~
20235 \SpecialChar ~
20236 sdcdb-whatis-c-sexp\SpecialChar ~
20237 \SpecialChar ~
20238 \SpecialChar ~
20239 \SpecialChar ~
20240 \SpecialChar ~
20241 \SpecialChar ~
20242 \SpecialChar ~
20243 \SpecialChar ~
20244 \SpecialChar ~
20245 \SpecialChar ~
20246 SDCDB ptypecommand for data at 
20247 \newline 
20248 ;;\SpecialChar ~
20249 \SpecialChar ~
20250 \SpecialChar ~
20251 \SpecialChar ~
20252 \SpecialChar ~
20253 \SpecialChar ~
20254 \SpecialChar ~
20255 \SpecialChar ~
20256 \SpecialChar ~
20257 \SpecialChar ~
20258 \SpecialChar ~
20259 \SpecialChar ~
20260 \SpecialChar ~
20261 \SpecialChar ~
20262 \SpecialChar ~
20263 \SpecialChar ~
20264 \SpecialChar ~
20265 \SpecialChar ~
20266 \SpecialChar ~
20267 \SpecialChar ~
20268 \SpecialChar ~
20269 \SpecialChar ~
20270 \SpecialChar ~
20271 \SpecialChar ~
20272 \SpecialChar ~
20273 \SpecialChar ~
20274 \SpecialChar ~
20275 \SpecialChar ~
20276 \SpecialChar ~
20277 \SpecialChar ~
20278 \SpecialChar ~
20279 \SpecialChar ~
20280 \SpecialChar ~
20281 \SpecialChar ~
20282 \SpecialChar ~
20283 \SpecialChar ~
20284 \SpecialChar ~
20285 \SpecialChar ~
20286 \SpecialChar ~
20287 \SpecialChar ~
20288 \SpecialChar ~
20289 \SpecialChar ~
20290 \SpecialChar ~
20291 \SpecialChar ~
20292 \SpecialChar ~
20293 \SpecialChar ~
20294 \SpecialChar ~
20295 buffer point 
20296 \newline 
20297 ;;\SpecialChar ~
20298 x\SpecialChar ~
20299 \SpecialChar ~
20300 \SpecialChar ~
20301 \SpecialChar ~
20302 \SpecialChar ~
20303 \SpecialChar ~
20304 \SpecialChar ~
20305 \SpecialChar ~
20306 \SpecialChar ~
20307 \SpecialChar ~
20308 \SpecialChar ~
20309 \SpecialChar ~
20310 \SpecialChar ~
20311 \SpecialChar ~
20312 \SpecialChar ~
20313 sdcdbsrc-delete\SpecialChar ~
20314 \SpecialChar ~
20315 \SpecialChar ~
20316 \SpecialChar ~
20317 \SpecialChar ~
20318 \SpecialChar ~
20319 \SpecialChar ~
20320 \SpecialChar ~
20321 \SpecialChar ~
20322 \SpecialChar ~
20323 \SpecialChar ~
20324 \SpecialChar ~
20325 \SpecialChar ~
20326 \SpecialChar ~
20327 SDCDB Delete all breakpoints if no arg 
20328 \newline 
20329 ;;\SpecialChar ~
20330 \SpecialChar ~
20331 \SpecialChar ~
20332 \SpecialChar ~
20333 \SpecialChar ~
20334 \SpecialChar ~
20335 \SpecialChar ~
20336 \SpecialChar ~
20337 \SpecialChar ~
20338 \SpecialChar ~
20339 \SpecialChar ~
20340 \SpecialChar ~
20341 \SpecialChar ~
20342 \SpecialChar ~
20343 \SpecialChar ~
20344 \SpecialChar ~
20345 \SpecialChar ~
20346 \SpecialChar ~
20347 \SpecialChar ~
20348 \SpecialChar ~
20349 \SpecialChar ~
20350 \SpecialChar ~
20351 \SpecialChar ~
20352 \SpecialChar ~
20353 \SpecialChar ~
20354 \SpecialChar ~
20355 \SpecialChar ~
20356 \SpecialChar ~
20357 \SpecialChar ~
20358 \SpecialChar ~
20359 \SpecialChar ~
20360 \SpecialChar ~
20361 \SpecialChar ~
20362 \SpecialChar ~
20363 \SpecialChar ~
20364 \SpecialChar ~
20365 \SpecialChar ~
20366 \SpecialChar ~
20367 \SpecialChar ~
20368 \SpecialChar ~
20369 \SpecialChar ~
20370 \SpecialChar ~
20371 \SpecialChar ~
20372 \SpecialChar ~
20373 \SpecialChar ~
20374 \SpecialChar ~
20375 \SpecialChar ~
20376 given or delete arg (C-u arg x) 
20377 \newline 
20378 ;;\SpecialChar ~
20379 m\SpecialChar ~
20380 \SpecialChar ~
20381 \SpecialChar ~
20382 \SpecialChar ~
20383 \SpecialChar ~
20384 \SpecialChar ~
20385 \SpecialChar ~
20386 \SpecialChar ~
20387 \SpecialChar ~
20388 \SpecialChar ~
20389 \SpecialChar ~
20390 \SpecialChar ~
20391 \SpecialChar ~
20392 \SpecialChar ~
20393 \SpecialChar ~
20394 sdcdbsrc-frame\SpecialChar ~
20395 \SpecialChar ~
20396 \SpecialChar ~
20397 \SpecialChar ~
20398 \SpecialChar ~
20399 \SpecialChar ~
20400 \SpecialChar ~
20401 \SpecialChar ~
20402 \SpecialChar ~
20403 \SpecialChar ~
20404 \SpecialChar ~
20405 \SpecialChar ~
20406 \SpecialChar ~
20407 \SpecialChar ~
20408 \SpecialChar ~
20409 SDCDB Display current frame if no arg, 
20410 \newline 
20411 ;;\SpecialChar ~
20412 \SpecialChar ~
20413 \SpecialChar ~
20414 \SpecialChar ~
20415 \SpecialChar ~
20416 \SpecialChar ~
20417 \SpecialChar ~
20418 \SpecialChar ~
20419 \SpecialChar ~
20420 \SpecialChar ~
20421 \SpecialChar ~
20422 \SpecialChar ~
20423 \SpecialChar ~
20424 \SpecialChar ~
20425 \SpecialChar ~
20426 \SpecialChar ~
20427 \SpecialChar ~
20428 \SpecialChar ~
20429 \SpecialChar ~
20430 \SpecialChar ~
20431 \SpecialChar ~
20432 \SpecialChar ~
20433 \SpecialChar ~
20434 \SpecialChar ~
20435 \SpecialChar ~
20436 \SpecialChar ~
20437 \SpecialChar ~
20438 \SpecialChar ~
20439 \SpecialChar ~
20440 \SpecialChar ~
20441 \SpecialChar ~
20442 \SpecialChar ~
20443 \SpecialChar ~
20444 \SpecialChar ~
20445 \SpecialChar ~
20446 \SpecialChar ~
20447 \SpecialChar ~
20448 \SpecialChar ~
20449 \SpecialChar ~
20450 \SpecialChar ~
20451 \SpecialChar ~
20452 \SpecialChar ~
20453 \SpecialChar ~
20454 \SpecialChar ~
20455 \SpecialChar ~
20456 \SpecialChar ~
20457 \SpecialChar ~
20458 given or display frame arg 
20459 \newline 
20460 ;;\SpecialChar ~
20461 \SpecialChar ~
20462 \SpecialChar ~
20463 \SpecialChar ~
20464 \SpecialChar ~
20465 \SpecialChar ~
20466 \SpecialChar ~
20467 \SpecialChar ~
20468 \SpecialChar ~
20469 \SpecialChar ~
20470 \SpecialChar ~
20471 \SpecialChar ~
20472 \SpecialChar ~
20473 \SpecialChar ~
20474 \SpecialChar ~
20475 \SpecialChar ~
20476 \SpecialChar ~
20477 \SpecialChar ~
20478 \SpecialChar ~
20479 \SpecialChar ~
20480 \SpecialChar ~
20481 \SpecialChar ~
20482 \SpecialChar ~
20483 \SpecialChar ~
20484 \SpecialChar ~
20485 \SpecialChar ~
20486 \SpecialChar ~
20487 \SpecialChar ~
20488 \SpecialChar ~
20489 \SpecialChar ~
20490 \SpecialChar ~
20491 \SpecialChar ~
20492 \SpecialChar ~
20493 \SpecialChar ~
20494 \SpecialChar ~
20495 \SpecialChar ~
20496 \SpecialChar ~
20497 \SpecialChar ~
20498 \SpecialChar ~
20499 \SpecialChar ~
20500 \SpecialChar ~
20501 \SpecialChar ~
20502 \SpecialChar ~
20503 \SpecialChar ~
20504 \SpecialChar ~
20505 \SpecialChar ~
20506 \SpecialChar ~
20507 buffer point 
20508 \newline 
20509 ;;\SpecialChar ~
20510 !\SpecialChar ~
20511 \SpecialChar ~
20512 \SpecialChar ~
20513 \SpecialChar ~
20514 \SpecialChar ~
20515 \SpecialChar ~
20516 \SpecialChar ~
20517 \SpecialChar ~
20518 \SpecialChar ~
20519 \SpecialChar ~
20520 \SpecialChar ~
20521 \SpecialChar ~
20522 \SpecialChar ~
20523 \SpecialChar ~
20524 \SpecialChar ~
20525 sdcdbsrc-goto-sdcdb\SpecialChar ~
20526 \SpecialChar ~
20527 \SpecialChar ~
20528 \SpecialChar ~
20529 \SpecialChar ~
20530 \SpecialChar ~
20531 \SpecialChar ~
20532 \SpecialChar ~
20533 \SpecialChar ~
20534 \SpecialChar ~
20535 Goto the SDCDB output buffer 
20536 \newline 
20537 ;;\SpecialChar ~
20538 p\SpecialChar ~
20539 \SpecialChar ~
20540 \SpecialChar ~
20541 \SpecialChar ~
20542 \SpecialChar ~
20543 \SpecialChar ~
20544 \SpecialChar ~
20545 \SpecialChar ~
20546 \SpecialChar ~
20547 \SpecialChar ~
20548 \SpecialChar ~
20549 \SpecialChar ~
20550 \SpecialChar ~
20551 \SpecialChar ~
20552 \SpecialChar ~
20553 sdcdb-print-c-sexp\SpecialChar ~
20554 \SpecialChar ~
20555 \SpecialChar ~
20556 \SpecialChar ~
20557 \SpecialChar ~
20558 \SpecialChar ~
20559 \SpecialChar ~
20560 \SpecialChar ~
20561 \SpecialChar ~
20562 \SpecialChar ~
20563 \SpecialChar ~
20564 SDCDB print command for data at 
20565 \newline 
20566 ;;\SpecialChar ~
20567 \SpecialChar ~
20568 \SpecialChar ~
20569 \SpecialChar ~
20570 \SpecialChar ~
20571 \SpecialChar ~
20572 \SpecialChar ~
20573 \SpecialChar ~
20574 \SpecialChar ~
20575 \SpecialChar ~
20576 \SpecialChar ~
20577 \SpecialChar ~
20578 \SpecialChar ~
20579 \SpecialChar ~
20580 \SpecialChar ~
20581 \SpecialChar ~
20582 \SpecialChar ~
20583 \SpecialChar ~
20584 \SpecialChar ~
20585 \SpecialChar ~
20586 \SpecialChar ~
20587 \SpecialChar ~
20588 \SpecialChar ~
20589 \SpecialChar ~
20590 \SpecialChar ~
20591 \SpecialChar ~
20592 \SpecialChar ~
20593 \SpecialChar ~
20594 \SpecialChar ~
20595 \SpecialChar ~
20596 \SpecialChar ~
20597 \SpecialChar ~
20598 \SpecialChar ~
20599 \SpecialChar ~
20600 \SpecialChar ~
20601 \SpecialChar ~
20602 \SpecialChar ~
20603 \SpecialChar ~
20604 \SpecialChar ~
20605 \SpecialChar ~
20606 \SpecialChar ~
20607 \SpecialChar ~
20608 \SpecialChar ~
20609 \SpecialChar ~
20610 \SpecialChar ~
20611 \SpecialChar ~
20612 \SpecialChar ~
20613 buffer point 
20614 \newline 
20615 ;;\SpecialChar ~
20616 g\SpecialChar ~
20617 \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 sdcdbsrc-goto-sdcdb\SpecialChar ~
20632 \SpecialChar ~
20633 \SpecialChar ~
20634 \SpecialChar ~
20635 \SpecialChar ~
20636 \SpecialChar ~
20637 \SpecialChar ~
20638 \SpecialChar ~
20639 \SpecialChar ~
20640 \SpecialChar ~
20641 Goto the SDCDB output buffer 
20642 \newline 
20643 ;;\SpecialChar ~
20644 t\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 sdcdbsrc-mode\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 Toggles Sdcdbsrc mode (turns it off) 
20676 \newline 
20677 ;; 
20678 \newline 
20679 ;;\SpecialChar ~
20680 C-c\SpecialChar ~
20681 C-f\SpecialChar ~
20682 \SpecialChar ~
20683 \SpecialChar ~
20684 \SpecialChar ~
20685 \SpecialChar ~
20686 \SpecialChar ~
20687 \SpecialChar ~
20688 \SpecialChar ~
20689 \SpecialChar ~
20690 sdcdb-finish-from-src\SpecialChar ~
20691 \SpecialChar ~
20692 \SpecialChar ~
20693 \SpecialChar ~
20694 \SpecialChar ~
20695 \SpecialChar ~
20696 \SpecialChar ~
20697 \SpecialChar ~
20698 SDCDB finish command 
20699 \newline 
20700 ;; 
20701 \newline 
20702 ;;\SpecialChar ~
20703 C-x\SpecialChar ~
20704 SPC\SpecialChar ~
20705 \SpecialChar ~
20706 \SpecialChar ~
20707 \SpecialChar ~
20708 \SpecialChar ~
20709 \SpecialChar ~
20710 \SpecialChar ~
20711 \SpecialChar ~
20712 \SpecialChar ~
20713 sdcdb-break\SpecialChar ~
20714 \SpecialChar ~
20715 \SpecialChar ~
20716 \SpecialChar ~
20717 \SpecialChar ~
20718 \SpecialChar ~
20719 \SpecialChar ~
20720 \SpecialChar ~
20721 \SpecialChar ~
20722 \SpecialChar ~
20723 \SpecialChar ~
20724 \SpecialChar ~
20725 \SpecialChar ~
20726 \SpecialChar ~
20727 \SpecialChar ~
20728 \SpecialChar ~
20729 \SpecialChar ~
20730 \SpecialChar ~
20731 Set break for line with point 
20732 \newline 
20733 ;;\SpecialChar ~
20734 ESC\SpecialChar ~
20735 t\SpecialChar ~
20736 \SpecialChar ~
20737 \SpecialChar ~
20738 \SpecialChar ~
20739 \SpecialChar ~
20740 \SpecialChar ~
20741 \SpecialChar ~
20742 \SpecialChar ~
20743 \SpecialChar ~
20744 \SpecialChar ~
20745 \SpecialChar ~
20746 sdcdbsrc-mode\SpecialChar ~
20747 \SpecialChar ~
20748 \SpecialChar ~
20749 \SpecialChar ~
20750 \SpecialChar ~
20751 \SpecialChar ~
20752 \SpecialChar ~
20753 \SpecialChar ~
20754 \SpecialChar ~
20755 \SpecialChar ~
20756 \SpecialChar ~
20757 \SpecialChar ~
20758 \SpecialChar ~
20759 \SpecialChar ~
20760 \SpecialChar ~
20761 \SpecialChar ~
20762 Toggle Sdcdbsrc mode 
20763 \newline 
20764 ;;\SpecialChar ~
20765 ESC\SpecialChar ~
20766 m\SpecialChar ~
20767 \SpecialChar ~
20768 \SpecialChar ~
20769 \SpecialChar ~
20770 \SpecialChar ~
20771 \SpecialChar ~
20772 \SpecialChar ~
20773 \SpecialChar ~
20774 \SpecialChar ~
20775 \SpecialChar ~
20776 \SpecialChar ~
20777 sdcdbsrc-srcmode\SpecialChar ~
20778 \SpecialChar ~
20779 \SpecialChar ~
20780 \SpecialChar ~
20781 \SpecialChar ~
20782 \SpecialChar ~
20783 \SpecialChar ~
20784 \SpecialChar ~
20785 \SpecialChar ~
20786 \SpecialChar ~
20787 \SpecialChar ~
20788 \SpecialChar ~
20789 \SpecialChar ~
20790 Toggle list mode 
20791 \newline 
20792 ;; 
20793 \newline 
20794
20795 \layout Chapter
20796 \pagebreak_top 
20797 TIPS
20798 \layout Standard
20799
20800 Here are a few guidelines that will help the compiler generate more efficient
20801  code, some of the tips are specific to this compiler others are generally
20802  good programming practice.
20803 \layout Itemize
20804
20805 Use the smallest data type to represent your data-value.
20806  If it is known in advance that the value is going to be less than 256 then
20807  use an 'unsigned char' instead of a 'short' or 'int'.
20808  Please note, that ANSI C requires both signed and unsigned chars to be
20809  promoted to 'signed int' before doing any operation.
20810  This promotion
20811 \begin_inset LatexCommand \index{type promotion}
20812
20813 \end_inset 
20814
20815  can be omitted, if the result is the same.
20816  The effect of the promotion rules together with the sign-extension is often
20817  surprising:
20818 \begin_deeper 
20819 \layout Verse
20820
20821
20822 \family typewriter 
20823 unsigned char uc = 0xfe;
20824 \newline 
20825 if (uc * uc < 0) /* this is true! */
20826 \newline 
20827 {
20828 \newline 
20829 \SpecialChar ~
20830 \SpecialChar ~
20831 \SpecialChar ~
20832 \SpecialChar ~
20833 ....
20834 \newline 
20835 }
20836 \layout Standard
20837
20838
20839 \family typewriter 
20840 uc * uc
20841 \family default 
20842  is evaluated as 
20843 \family typewriter 
20844 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
20845 \family default 
20846 .
20847  
20848 \newline 
20849 Another one:
20850 \layout Verse
20851
20852
20853 \family typewriter 
20854 (unsigned char) -12 / (signed char) -3 = ...
20855 \layout Standard
20856
20857 No, the result is not 4:
20858 \layout Verse
20859
20860
20861 \family typewriter 
20862 (int) (unsigned char) -12 / (int) (signed char) -3 =
20863 \newline 
20864 (int) (unsigned char) 0xf4 / (int) (signed char) 0xfd =
20865 \newline 
20866 (int) 0x00f4 / (int) 0xfffd =
20867 \newline 
20868 (int) 0x00f4 / (int) 0xfffd =
20869 \newline 
20870 (int) 244 / (int) -3 =
20871 \newline 
20872 (int) -81 = (int) 0xffaf;
20873 \layout Standard
20874
20875 Don't complain, that gcc gives you a different result.
20876  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
20877  Therefore the results are different.
20878 \newline 
20879 From 
20880 \begin_inset Quotes sld
20881 \end_inset 
20882
20883 comp.lang.c FAQ
20884 \begin_inset Quotes srd
20885 \end_inset 
20886
20887 :
20888 \layout Quote
20889
20890 If well-defined overflow characteristics are important and negative values
20891  are not, or if you want to steer clear of sign-extension problems when
20892  manipulating bits or bytes, use one of the corresponding unsigned types.
20893  (Beware when mixing signed and unsigned values in expressions, though.)
20894 \newline 
20895 Although character types (especially unsigned char) can be used as "tiny"
20896  integers, doing so is sometimes more trouble than it's worth, due to unpredicta
20897 ble sign extension and increased code size.
20898 \end_deeper 
20899 \layout Itemize
20900
20901 Use unsigned when it is known in advance that the value is not going to
20902  be negative.
20903  This helps especially if you are doing division or multiplication, bit-shifting
20904  or are using an array index.
20905 \layout Itemize
20906
20907 NEVER jump into a LOOP.
20908 \layout Itemize
20909
20910 Declare the variables to be local
20911 \begin_inset LatexCommand \index{local variables}
20912
20913 \end_inset 
20914
20915  whenever possible, especially loop control variables (induction).
20916 \layout Itemize
20917
20918 Since the compiler does not always do implicit integral promotion, the programme
20919 r should do an explicit cast when integral promotion is required.
20920 \layout Itemize
20921
20922 Reducing the size of division, multiplication & modulus operations can reduce
20923  code size substantially.
20924  Take the following code for example.
20925 \begin_deeper 
20926 \layout Verse
20927
20928
20929 \family typewriter 
20930 foobar(unsigned int p1, unsigned char ch)
20931 \newline 
20932 {
20933 \newline 
20934 \SpecialChar ~
20935 \SpecialChar ~
20936 \SpecialChar ~
20937 \SpecialChar ~
20938 unsigned char ch1 = p1 % ch ;
20939 \newline 
20940 \SpecialChar ~
20941 \SpecialChar ~
20942 \SpecialChar ~
20943 \SpecialChar ~
20944 ....
20945 \newline 
20946 }
20947 \layout Standard
20948
20949 For the modulus operation the variable ch will be promoted to unsigned int
20950  first then the modulus operation will be performed (this will lead to a
20951  call to support routine _moduint()), and the result will be casted to a
20952  char.
20953  If the code is changed to 
20954 \layout Verse
20955
20956
20957 \family typewriter 
20958 foobar(unsigned int p1, unsigned char ch)
20959 \newline 
20960 {
20961 \newline 
20962 \SpecialChar ~
20963 \SpecialChar ~
20964 \SpecialChar ~
20965 \SpecialChar ~
20966 unsigned char ch1 = (unsigned char)p1 % ch ;
20967 \newline 
20968 \SpecialChar ~
20969 \SpecialChar ~
20970 \SpecialChar ~
20971 \SpecialChar ~
20972 ....
20973 \newline 
20974 }
20975 \layout Standard
20976
20977 It would substantially reduce the code generated (future versions of the
20978  compiler will be smart enough to detect such optimization opportunities).
20979 \end_deeper 
20980 \layout Itemize
20981
20982 Have a look at the assembly listing to get a 
20983 \begin_inset Quotes sld
20984 \end_inset 
20985
20986 feeling
20987 \begin_inset Quotes srd
20988 \end_inset 
20989
20990  for the code generation.
20991 \layout Section
20992
20993 Tools
20994 \begin_inset LatexCommand \index{Tools}
20995
20996 \end_inset 
20997
20998  included in the distribution
20999 \layout Standard
21000 \align center 
21001
21002 \begin_inset  Tabular
21003 <lyxtabular version="3" rows="12" columns="3">
21004 <features>
21005 <column alignment="center" valignment="top" leftline="true" width="0pt">
21006 <column alignment="center" valignment="top" leftline="true" width="0pt">
21007 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
21008 <row topline="true" bottomline="true">
21009 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21010 \begin_inset Text
21011
21012 \layout Standard
21013
21014 Name
21015 \end_inset 
21016 </cell>
21017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21018 \begin_inset Text
21019
21020 \layout Standard
21021
21022 Purpose
21023 \end_inset 
21024 </cell>
21025 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21026 \begin_inset Text
21027
21028 \layout Standard
21029
21030 Directory
21031 \end_inset 
21032 </cell>
21033 </row>
21034 <row topline="true">
21035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21036 \begin_inset Text
21037
21038 \layout Standard
21039
21040 uCsim
21041 \end_inset 
21042 </cell>
21043 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21044 \begin_inset Text
21045
21046 \layout Standard
21047
21048 Simulator for various architectures
21049 \end_inset 
21050 </cell>
21051 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21052 \begin_inset Text
21053
21054 \layout Standard
21055
21056 sdcc/sim/ucsim
21057 \end_inset 
21058 </cell>
21059 </row>
21060 <row topline="true">
21061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21062 \begin_inset Text
21063
21064 \layout Standard
21065
21066 keil2sdcc.pl
21067 \end_inset 
21068 </cell>
21069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21070 \begin_inset Text
21071
21072 \layout Standard
21073
21074 header file conversion
21075 \end_inset 
21076 </cell>
21077 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21078 \begin_inset Text
21079
21080 \layout Standard
21081
21082 sdcc/support/scripts
21083 \end_inset 
21084 </cell>
21085 </row>
21086 <row topline="true">
21087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21088 \begin_inset Text
21089
21090 \layout Standard
21091
21092 mh2h.c
21093 \end_inset 
21094 </cell>
21095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21096 \begin_inset Text
21097
21098 \layout Standard
21099
21100 header file conversion
21101 \end_inset 
21102 </cell>
21103 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21104 \begin_inset Text
21105
21106 \layout Standard
21107
21108 sdcc/support/scripts
21109 \end_inset 
21110 </cell>
21111 </row>
21112 <row topline="true">
21113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21114 \begin_inset Text
21115
21116 \layout Standard
21117
21118 as-gbz80
21119 \end_inset 
21120 </cell>
21121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21122 \begin_inset Text
21123
21124 \layout Standard
21125
21126 Assembler
21127 \end_inset 
21128 </cell>
21129 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21130 \begin_inset Text
21131
21132 \layout Standard
21133
21134
21135 \family roman 
21136 \series medium 
21137 \shape up 
21138 \size normal 
21139 \emph off 
21140 \bar no 
21141 \noun off 
21142 \color none
21143 sdcc/bin
21144 \end_inset 
21145 </cell>
21146 </row>
21147 <row topline="true">
21148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21149 \begin_inset Text
21150
21151 \layout Standard
21152
21153 as-z80
21154 \end_inset 
21155 </cell>
21156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21157 \begin_inset Text
21158
21159 \layout Standard
21160
21161 Assembler
21162 \end_inset 
21163 </cell>
21164 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21165 \begin_inset Text
21166
21167 \layout Standard
21168
21169
21170 \family roman 
21171 \series medium 
21172 \shape up 
21173 \size normal 
21174 \emph off 
21175 \bar no 
21176 \noun off 
21177 \color none
21178 sdcc/bin
21179 \end_inset 
21180 </cell>
21181 </row>
21182 <row topline="true">
21183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21184 \begin_inset Text
21185
21186 \layout Standard
21187
21188 asx8051
21189 \end_inset 
21190 </cell>
21191 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21192 \begin_inset Text
21193
21194 \layout Standard
21195
21196 Assembler
21197 \end_inset 
21198 </cell>
21199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21200 \begin_inset Text
21201
21202 \layout Standard
21203
21204
21205 \family roman 
21206 \series medium 
21207 \shape up 
21208 \size normal 
21209 \emph off 
21210 \bar no 
21211 \noun off 
21212 \color none
21213 sdcc/bin
21214 \end_inset 
21215 </cell>
21216 </row>
21217 <row topline="true">
21218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21219 \begin_inset Text
21220
21221 \layout Standard
21222
21223 sdcdb
21224 \end_inset 
21225 </cell>
21226 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21227 \begin_inset Text
21228
21229 \layout Standard
21230
21231 Simulator
21232 \end_inset 
21233 </cell>
21234 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21235 \begin_inset Text
21236
21237 \layout Standard
21238
21239
21240 \family roman 
21241 \series medium 
21242 \shape up 
21243 \size normal 
21244 \emph off 
21245 \bar no 
21246 \noun off 
21247 \color none
21248 sdcc/bin
21249 \end_inset 
21250 </cell>
21251 </row>
21252 <row topline="true">
21253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21254 \begin_inset Text
21255
21256 \layout Standard
21257
21258 aslink
21259 \end_inset 
21260 </cell>
21261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21262 \begin_inset Text
21263
21264 \layout Standard
21265
21266 Linker
21267 \end_inset 
21268 </cell>
21269 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21270 \begin_inset Text
21271
21272 \layout Standard
21273
21274
21275 \family roman 
21276 \series medium 
21277 \shape up 
21278 \size normal 
21279 \emph off 
21280 \bar no 
21281 \noun off 
21282 \color none
21283 sdcc/bin
21284 \end_inset 
21285 </cell>
21286 </row>
21287 <row topline="true">
21288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21289 \begin_inset Text
21290
21291 \layout Standard
21292
21293 link-z80
21294 \end_inset 
21295 </cell>
21296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21297 \begin_inset Text
21298
21299 \layout Standard
21300
21301 Linker
21302 \end_inset 
21303 </cell>
21304 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21305 \begin_inset Text
21306
21307 \layout Standard
21308
21309
21310 \family roman 
21311 \series medium 
21312 \shape up 
21313 \size normal 
21314 \emph off 
21315 \bar no 
21316 \noun off 
21317 \color none
21318 sdcc/bin
21319 \end_inset 
21320 </cell>
21321 </row>
21322 <row topline="true">
21323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21324 \begin_inset Text
21325
21326 \layout Standard
21327
21328 link-gbz80
21329 \end_inset 
21330 </cell>
21331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21332 \begin_inset Text
21333
21334 \layout Standard
21335
21336 Linker
21337 \end_inset 
21338 </cell>
21339 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21340 \begin_inset Text
21341
21342 \layout Standard
21343
21344
21345 \family roman 
21346 \series medium 
21347 \shape up 
21348 \size normal 
21349 \emph off 
21350 \bar no 
21351 \noun off 
21352 \color none
21353 sdcc/bin
21354 \end_inset 
21355 </cell>
21356 </row>
21357 <row topline="true" bottomline="true">
21358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21359 \begin_inset Text
21360
21361 \layout Standard
21362
21363 packihx
21364 \end_inset 
21365 </cell>
21366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21367 \begin_inset Text
21368
21369 \layout Standard
21370
21371 ihx packer
21372 \end_inset 
21373 </cell>
21374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21375 \begin_inset Text
21376
21377 \layout Standard
21378
21379
21380 \family roman 
21381 \series medium 
21382 \shape up 
21383 \size normal 
21384 \emph off 
21385 \bar no 
21386 \noun off 
21387 \color none
21388 sdcc/bin
21389 \end_inset 
21390 </cell>
21391 </row>
21392 </lyxtabular>
21393
21394 \end_inset 
21395
21396
21397 \newline 
21398
21399 \layout Section
21400
21401 Documentation
21402 \begin_inset LatexCommand \index{Documentation}
21403
21404 \end_inset 
21405
21406  included in the distribution
21407 \layout Standard
21408 \align center 
21409
21410 \begin_inset  Tabular
21411 <lyxtabular version="3" rows="10" columns="2">
21412 <features>
21413 <column alignment="left" valignment="top" leftline="true" width="0">
21414 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
21415 <row topline="true" bottomline="true">
21416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21417 \begin_inset Text
21418
21419 \layout Standard
21420
21421 Subject / Title
21422 \end_inset 
21423 </cell>
21424 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21425 \begin_inset Text
21426
21427 \layout Standard
21428
21429 Where to get / filename
21430 \end_inset 
21431 </cell>
21432 </row>
21433 <row topline="true">
21434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21435 \begin_inset Text
21436
21437 \layout Standard
21438
21439 SDCC Compiler User Guide
21440 \end_inset 
21441 </cell>
21442 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21443 \begin_inset Text
21444
21445 \layout Standard
21446
21447 You're reading it right now
21448 \end_inset 
21449 </cell>
21450 </row>
21451 <row topline="true">
21452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21453 \begin_inset Text
21454
21455 \layout Standard
21456
21457 Changelog of SDCC
21458 \end_inset 
21459 </cell>
21460 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21461 \begin_inset Text
21462
21463 \layout Standard
21464
21465 sdcc/Changelog
21466 \end_inset 
21467 </cell>
21468 </row>
21469 <row topline="true">
21470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21471 \begin_inset Text
21472
21473 \layout Standard
21474
21475 ASXXXX
21476 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
21477
21478 \end_inset 
21479
21480
21481 \begin_inset LatexCommand \index{Assembler documentation}
21482
21483 \end_inset 
21484
21485  Assemblers and ASLINK
21486 \begin_inset LatexCommand \index{aslink}
21487
21488 \end_inset 
21489
21490
21491 \begin_inset LatexCommand \index{Linker documentation}
21492
21493 \end_inset 
21494
21495  Relocating Linker
21496 \end_inset 
21497 </cell>
21498 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21499 \begin_inset Text
21500
21501 \layout Standard
21502
21503 sdcc/as/doc/asxhtm.html
21504 \end_inset 
21505 </cell>
21506 </row>
21507 <row topline="true">
21508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21509 \begin_inset Text
21510
21511 \layout Standard
21512
21513 SDCC regression test
21514 \begin_inset LatexCommand \index{Regression test}
21515
21516 \end_inset 
21517
21518
21519 \end_inset 
21520 </cell>
21521 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21522 \begin_inset Text
21523
21524 \layout Standard
21525
21526 sdcc/doc/test_suite_spec.pdf
21527 \end_inset 
21528 </cell>
21529 </row>
21530 <row topline="true">
21531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21532 \begin_inset Text
21533
21534 \layout Standard
21535
21536 Various notes
21537 \end_inset 
21538 </cell>
21539 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21540 \begin_inset Text
21541
21542 \layout Standard
21543
21544 sdcc/doc/*
21545 \end_inset 
21546 </cell>
21547 </row>
21548 <row topline="true">
21549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21550 \begin_inset Text
21551
21552 \layout Standard
21553
21554 Notes on debugging with sdcdb
21555 \begin_inset LatexCommand \index{sdcdb (debugger)}
21556
21557 \end_inset 
21558
21559
21560 \end_inset 
21561 </cell>
21562 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21563 \begin_inset Text
21564
21565 \layout Standard
21566
21567 sdcc/debugger/README
21568 \end_inset 
21569 </cell>
21570 </row>
21571 <row topline="true">
21572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21573 \begin_inset Text
21574
21575 \layout Standard
21576
21577 Software simulator for microcontrollers
21578 \end_inset 
21579 </cell>
21580 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21581 \begin_inset Text
21582
21583 \layout Standard
21584
21585
21586 \family roman 
21587 \series medium 
21588 \shape up 
21589 \size normal 
21590 \emph off 
21591 \bar no 
21592 \noun off 
21593 \color none
21594 sdcc/sim/ucsim/doc
21595 \family default 
21596 \series default 
21597 \shape default 
21598 \size default 
21599 \emph default 
21600 \bar default 
21601 \noun default 
21602 \color default
21603 /index.html
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 Temporary notes on the pic16
21614 \begin_inset LatexCommand \index{PIC16}
21615
21616 \end_inset 
21617
21618  port
21619 \end_inset 
21620 </cell>
21621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21622 \begin_inset Text
21623
21624 \layout Standard
21625
21626 sdcc/src/pic16/NOTES
21627 \end_inset 
21628 </cell>
21629 </row>
21630 <row topline="true" bottomline="true">
21631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21632 \begin_inset Text
21633
21634 \layout Standard
21635
21636 SDCC internal documentation (debugging file format)
21637 \end_inset 
21638 </cell>
21639 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21640 \begin_inset Text
21641
21642 \layout Standard
21643
21644 sdcc/doc/
21645 \family roman 
21646 \series medium 
21647 \shape up 
21648 \size normal 
21649 \emph off 
21650 \bar no 
21651 \noun off 
21652 \color none
21653 cdbfileformat.pd
21654 \family default 
21655 \series default 
21656 \shape default 
21657 \size default 
21658 \emph default 
21659 \bar default 
21660 \noun default 
21661 \color default
21662 f
21663 \end_inset 
21664 </cell>
21665 </row>
21666 </lyxtabular>
21667
21668 \end_inset 
21669
21670
21671 \newline 
21672
21673 \layout Section
21674
21675 Related open source tools
21676 \begin_inset LatexCommand \index{Related tools}
21677
21678 \end_inset 
21679
21680
21681 \layout Standard
21682 \align center 
21683
21684 \begin_inset  Tabular
21685 <lyxtabular version="3" rows="11" columns="3">
21686 <features>
21687 <column alignment="center" valignment="top" leftline="true" width="0pt">
21688 <column alignment="block" valignment="top" leftline="true" width="30line%">
21689 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
21690 <row topline="true" bottomline="true">
21691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21692 \begin_inset Text
21693
21694 \layout Standard
21695
21696 Name
21697 \end_inset 
21698 </cell>
21699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21700 \begin_inset Text
21701
21702 \layout Standard
21703
21704 Purpose
21705 \end_inset 
21706 </cell>
21707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21708 \begin_inset Text
21709
21710 \layout Standard
21711
21712 Where to get
21713 \end_inset 
21714 </cell>
21715 </row>
21716 <row topline="true">
21717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21718 \begin_inset Text
21719
21720 \layout Standard
21721
21722 gpsim
21723 \begin_inset LatexCommand \index{gpsim (pic simulator)}
21724
21725 \end_inset 
21726
21727
21728 \end_inset 
21729 </cell>
21730 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21731 \begin_inset Text
21732
21733 \layout Standard
21734
21735 PIC simulator
21736 \end_inset 
21737 </cell>
21738 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21739 \begin_inset Text
21740
21741 \layout Standard
21742
21743
21744 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
21745
21746 \end_inset 
21747
21748
21749 \end_inset 
21750 </cell>
21751 </row>
21752 <row topline="true">
21753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21754 \begin_inset Text
21755
21756 \layout Standard
21757
21758 gputils
21759 \begin_inset LatexCommand \index{gputils (pic tools)}
21760
21761 \end_inset 
21762
21763
21764 \end_inset 
21765 </cell>
21766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21767 \begin_inset Text
21768
21769 \layout Standard
21770
21771 GNU PIC utilities
21772 \end_inset 
21773 </cell>
21774 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21775 \begin_inset Text
21776
21777 \layout Standard
21778
21779
21780 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
21781
21782 \end_inset 
21783
21784
21785 \end_inset 
21786 </cell>
21787 </row>
21788 <row topline="true">
21789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21790 \begin_inset Text
21791
21792 \layout Standard
21793
21794 flP5
21795 \end_inset 
21796 </cell>
21797 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21798 \begin_inset Text
21799
21800 \layout Standard
21801
21802 PIC programmer
21803 \end_inset 
21804 </cell>
21805 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21806 \begin_inset Text
21807
21808 \layout Standard
21809
21810
21811 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
21812
21813 \end_inset 
21814
21815
21816 \end_inset 
21817 </cell>
21818 </row>
21819 <row topline="true">
21820 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21821 \begin_inset Text
21822
21823 \layout Standard
21824
21825 indent
21826 \begin_inset LatexCommand \index{indent (source formatting tool)}
21827
21828 \end_inset 
21829
21830
21831 \end_inset 
21832 </cell>
21833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21834 \begin_inset Text
21835
21836 \layout Standard
21837
21838 Formats C source - Master of the white spaces
21839 \end_inset 
21840 </cell>
21841 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21842 \begin_inset Text
21843
21844 \layout Standard
21845
21846
21847 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
21848
21849 \end_inset 
21850
21851
21852 \end_inset 
21853 </cell>
21854 </row>
21855 <row topline="true">
21856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21857 \begin_inset Text
21858
21859 \layout Standard
21860
21861 srecord
21862 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
21863
21864 \end_inset 
21865
21866
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 Object file conversion, checksumming, ...
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 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
21884
21885 \end_inset 
21886
21887
21888 \end_inset 
21889 </cell>
21890 </row>
21891 <row topline="true">
21892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21893 \begin_inset Text
21894
21895 \layout Standard
21896
21897 objdump
21898 \begin_inset LatexCommand \index{objdump (tool)}
21899
21900 \end_inset 
21901
21902
21903 \end_inset 
21904 </cell>
21905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21906 \begin_inset Text
21907
21908 \layout Standard
21909
21910 Object file conversion, ...
21911 \end_inset 
21912 </cell>
21913 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21914 \begin_inset Text
21915
21916 \layout Standard
21917
21918 Part of binutils (should be there anyway)
21919 \end_inset 
21920 </cell>
21921 </row>
21922 <row topline="true">
21923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21924 \begin_inset Text
21925
21926 \layout Standard
21927
21928 doxygen
21929 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
21930
21931 \end_inset 
21932
21933
21934 \end_inset 
21935 </cell>
21936 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21937 \begin_inset Text
21938
21939 \layout Standard
21940
21941 Source code documentation system
21942 \end_inset 
21943 </cell>
21944 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21945 \begin_inset Text
21946
21947 \layout Standard
21948
21949
21950 \begin_inset LatexCommand \url{http://www.doxygen.org}
21951
21952 \end_inset 
21953
21954
21955 \end_inset 
21956 </cell>
21957 </row>
21958 <row topline="true">
21959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21960 \begin_inset Text
21961
21962 \layout Standard
21963
21964 kdevelop
21965 \end_inset 
21966 </cell>
21967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21968 \begin_inset Text
21969
21970 \layout Standard
21971
21972 IDE (has anyone tried integrating SDCC & sdcdb? Unix only)
21973 \end_inset 
21974 </cell>
21975 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21976 \begin_inset Text
21977
21978 \layout Standard
21979
21980
21981 \begin_inset LatexCommand \url{http://www.kdevelop.org}
21982
21983 \end_inset 
21984
21985
21986 \end_inset 
21987 </cell>
21988 </row>
21989 <row topline="true">
21990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21991 \begin_inset Text
21992
21993 \layout Standard
21994
21995 splint
21996 \begin_inset LatexCommand \index{splint (syntax checking tool)}
21997
21998 \end_inset 
21999
22000
22001 \end_inset 
22002 </cell>
22003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22004 \begin_inset Text
22005
22006 \layout Standard
22007
22008 Statically checks c sources (has anyone adapted splint for SDCC?)
22009 \end_inset 
22010 </cell>
22011 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22012 \begin_inset Text
22013
22014 \layout Standard
22015
22016
22017 \begin_inset LatexCommand \url{http://www.splint.org}
22018
22019 \end_inset 
22020
22021
22022 \end_inset 
22023 </cell>
22024 </row>
22025 <row topline="true" bottomline="true">
22026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22027 \begin_inset Text
22028
22029 \layout Standard
22030
22031 ddd
22032 \begin_inset LatexCommand \index{ddd (debugger)}
22033
22034 \end_inset 
22035
22036
22037 \end_inset 
22038 </cell>
22039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22040 \begin_inset Text
22041
22042 \layout Standard
22043
22044 Debugger, serves nicely as GUI to sdcdb
22045 \begin_inset LatexCommand \index{sdcdb (debugger)}
22046
22047 \end_inset 
22048
22049  (Unix only)
22050 \end_inset 
22051 </cell>
22052 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22053 \begin_inset Text
22054
22055 \layout Standard
22056
22057
22058 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
22059
22060 \end_inset 
22061
22062
22063 \end_inset 
22064 </cell>
22065 </row>
22066 </lyxtabular>
22067
22068 \end_inset 
22069
22070
22071 \newline 
22072
22073 \layout Section
22074
22075 Related documentation / recommended reading
22076 \layout Standard
22077 \align center 
22078
22079 \begin_inset  Tabular
22080 <lyxtabular version="3" rows="6" columns="3">
22081 <features>
22082 <column alignment="center" valignment="top" leftline="true" width="0pt">
22083 <column alignment="block" valignment="top" leftline="true" width="30line%">
22084 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
22085 <row topline="true" bottomline="true">
22086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22087 \begin_inset Text
22088
22089 \layout Standard
22090
22091 Name
22092 \end_inset 
22093 </cell>
22094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22095 \begin_inset Text
22096
22097 \layout Standard
22098
22099 Subject / Title
22100 \end_inset 
22101 </cell>
22102 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22103 \begin_inset Text
22104
22105 \layout Standard
22106
22107 Where to get
22108 \end_inset 
22109 </cell>
22110 </row>
22111 <row topline="true">
22112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22113 \begin_inset Text
22114
22115 \layout Standard
22116
22117
22118 \family roman 
22119 \series medium 
22120 \shape up 
22121 \size normal 
22122 \emph off 
22123 \bar no 
22124 \noun off 
22125 \color none
22126 c-refcard.pdf
22127 \end_inset 
22128 </cell>
22129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22130 \begin_inset Text
22131
22132 \layout Standard
22133
22134 C Reference Card
22135 \begin_inset LatexCommand \index{C Reference card}
22136
22137 \end_inset 
22138
22139 , 2 pages
22140 \end_inset 
22141 </cell>
22142 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22143 \begin_inset Text
22144
22145 \layout Standard
22146
22147
22148 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
22149
22150 \end_inset 
22151
22152
22153 \end_inset 
22154 </cell>
22155 </row>
22156 <row topline="true">
22157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22158 \begin_inset Text
22159
22160 \layout Standard
22161
22162 c-faq
22163 \end_inset 
22164 </cell>
22165 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22166 \begin_inset Text
22167
22168 \layout Standard
22169
22170 C-FAQ-list
22171 \end_inset 
22172 </cell>
22173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22174 \begin_inset Text
22175
22176 \layout Standard
22177
22178
22179 \begin_inset LatexCommand \url{http://www.eskimo.com/~scs/C-faq/top.html}
22180
22181 \end_inset 
22182
22183
22184 \end_inset 
22185 </cell>
22186 </row>
22187 <row topline="true">
22188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22189 \begin_inset Text
22190
22191 \layout Standard
22192
22193 \end_inset 
22194 </cell>
22195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22196 \begin_inset Text
22197
22198 \layout Standard
22199
22200 Latest datasheet of the target CPU
22201 \end_inset 
22202 </cell>
22203 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22204 \begin_inset Text
22205
22206 \layout Standard
22207
22208 vendor
22209 \end_inset 
22210 </cell>
22211 </row>
22212 <row topline="true">
22213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22214 \begin_inset Text
22215
22216 \layout Standard
22217
22218 \end_inset 
22219 </cell>
22220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22221 \begin_inset Text
22222
22223 \layout Standard
22224
22225 Revision history of datasheet
22226 \end_inset 
22227 </cell>
22228 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22229 \begin_inset Text
22230
22231 \layout Standard
22232
22233 vendor
22234 \end_inset 
22235 </cell>
22236 </row>
22237 <row topline="true" bottomline="true">
22238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22239 \begin_inset Text
22240
22241 \layout Standard
22242
22243 S.
22244  S.
22245  Muchnick
22246 \end_inset 
22247 </cell>
22248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22249 \begin_inset Text
22250
22251 \layout Standard
22252
22253 Advanced Compiler Design and Implementation
22254 \end_inset 
22255 </cell>
22256 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22257 \begin_inset Text
22258
22259 \layout Standard
22260
22261 bookstore (very dedicated, probably read other books first)
22262 \end_inset 
22263 </cell>
22264 </row>
22265 </lyxtabular>
22266
22267 \end_inset 
22268
22269
22270 \newline 
22271
22272 \layout Section
22273
22274 Some Questions
22275 \layout Standard
22276
22277 Some questions answered, some pointers given - it might be time to in turn
22278  ask 
22279 \emph on 
22280 you
22281 \emph default 
22282  some questions: 
22283 \layout Itemize
22284
22285 can you solve your project with the selected microcontroller? Would you
22286  find out early or rather late that your target is too small/slow/whatever?
22287  Can you switch to a slightly better device if it doesn't fit?
22288 \layout Itemize
22289
22290 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
22291  and/or another programming language be more adequate? Would an operating
22292  system on the target device help?
22293 \layout Itemize
22294
22295 if you solved the problem, will the marketing department be happy?
22296 \layout Itemize
22297
22298 if the marketing department is happy, will customers be happy?
22299 \layout Itemize
22300
22301 if you're the project manager, marketing department and maybe even the customer
22302  in one person, have you tried to see the project from the outside?
22303 \layout Itemize
22304
22305 is the project done if you think it is done? Or is just that other interface/pro
22306 tocol/feature/configuration/option missing? How about website, manual(s),
22307  internationali(z|s)ation, packaging, labels, 2nd source for components,
22308  electromagnetic compatability/interference, documentation for production,
22309  production test software, update mechanism, patent issues?
22310 \layout Itemize
22311
22312 is your project adequately positioned in that magic triangle: fame, fortune,
22313  fun?
22314 \layout Standard
22315
22316 Maybe not all answers to these questions are known and some answers may
22317  even be 
22318 \emph on 
22319 no
22320 \emph default 
22321 , nevertheless knowing these questions may help you to avoid burnout
22322 \begin_inset Foot
22323 collapsed false
22324
22325 \layout Standard
22326
22327 burnout is bad for electronic devices, programmers and motorcycle tyres
22328 \end_inset 
22329
22330 .
22331  Chances are you didn't want to hear some of them...
22332 \layout Chapter
22333
22334 Support
22335 \begin_inset LatexCommand \index{Support}
22336
22337 \end_inset 
22338
22339
22340 \layout Standard
22341
22342 SDCC has grown to be a large project.
22343  The compiler alone (without the preprocessor, assembler and linker) is
22344  well over 100,000 lines of code (blank stripped).
22345  The open source nature of this project is a key to its continued growth
22346  and support.
22347  You gain the benefit and support of many active software developers and
22348  end users.
22349  Is SDCC perfect? No, that's why we need your help.
22350  The developers take pride in fixing reported bugs.
22351  You can help by reporting the bugs and helping other SDCC users.
22352  There are lots of ways to contribute, and we encourage you to take part
22353  in making SDCC a great software package.
22354  
22355 \layout Standard
22356
22357 The SDCC project is hosted on the SDCC sourceforge site at 
22358 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
22359
22360 \end_inset 
22361
22362 .
22363  You'll find the complete set of mailing lists
22364 \begin_inset LatexCommand \index{Mailing list(s)}
22365
22366 \end_inset 
22367
22368 , forums, bug reporting system, patch submission
22369 \begin_inset LatexCommand \index{Patch submission}
22370
22371 \end_inset 
22372
22373  system, download
22374 \begin_inset LatexCommand \index{download}
22375
22376 \end_inset 
22377
22378  area and cvs code repository
22379 \begin_inset LatexCommand \index{cvs code repository}
22380
22381 \end_inset 
22382
22383  there.
22384 \layout Section
22385
22386 Reporting Bugs
22387 \begin_inset LatexCommand \index{Bug reporting}
22388
22389 \end_inset 
22390
22391
22392 \begin_inset LatexCommand \index{Reporting bugs}
22393
22394 \end_inset 
22395
22396
22397 \layout Standard
22398
22399 The recommended way of reporting bugs is using the infrastructure of the
22400  sourceforge site.
22401  You can follow the status of bug reports there and have an overview about
22402  the known bugs.
22403 \layout Standard
22404
22405 Bug reports are automatically forwarded to the developer mailing list and
22406  will be fixed ASAP.
22407  When reporting a bug, it is very useful to include a small test program
22408  (the smaller the better) which reproduces the problem.
22409  If you can isolate the problem by looking at the generated assembly code,
22410  this can be very helpful.
22411  Compiling your program with the -
22412 \begin_inset ERT
22413 status Collapsed
22414
22415 \layout Standard
22416
22417 \backslash 
22418 /
22419 \end_inset 
22420
22421 -dumpall
22422 \begin_inset LatexCommand \index{-\/-dumpall}
22423
22424 \end_inset 
22425
22426  option can sometimes be useful in locating optimization problems.
22427  When reporting a bug please maker sure you:
22428 \layout Enumerate
22429
22430 Attach the code you are compiling with SDCC.
22431  
22432 \layout Enumerate
22433
22434 Specify the exact command you use to run SDCC, or attach your Makefile.
22435  
22436 \layout Enumerate
22437
22438 Specify the SDCC version (type "
22439 \family sans 
22440 \series bold 
22441 sdcc -v
22442 \family default 
22443 \series default 
22444 "), your platform, and operating system.
22445  
22446 \layout Enumerate
22447
22448 Provide an exact copy of any error message or incorrect output.
22449  
22450 \layout Enumerate
22451
22452 Put something meaningful in the subject of your message.
22453 \layout Standard
22454
22455 Please attempt to include these 5 important parts, as applicable, in all
22456  requests for support or when reporting any problems or bugs with SDCC.
22457  Though this will make your message lengthy, it will greatly improve your
22458  chance that SDCC users and developers will be able to help you.
22459  Some SDCC developers are frustrated by bug reports without code provided
22460  that they can use to reproduce and ultimately fix the problem, so please
22461  be sure to provide sample code if you are reporting a bug! 
22462 \layout Standard
22463
22464 Please have a short check that you are using a recent version of SDCC and
22465  the bug is not yet known.
22466  This is the link for reporting bugs: 
22467 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
22468
22469 \end_inset 
22470
22471 .
22472 \layout Section
22473
22474 Requesting Features
22475 \begin_inset LatexCommand \label{sub:Requesting-Features}
22476
22477 \end_inset 
22478
22479
22480 \begin_inset LatexCommand \index{Feature request}
22481
22482 \end_inset 
22483
22484
22485 \begin_inset LatexCommand \index{Requesting features}
22486
22487 \end_inset 
22488
22489
22490 \layout Standard
22491
22492 Like bug reports feature requests are forwarded to the developer mailing
22493  list.
22494  This is the link for requesting features: 
22495 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
22496
22497 \end_inset 
22498
22499 .
22500 \layout Section
22501
22502 Submitting patches
22503 \layout Standard
22504
22505 Like bug reports contributed patches are forwarded to the developer mailing
22506  list.
22507  This is the link for submitting patches
22508 \begin_inset LatexCommand \index{Patch submission}
22509
22510 \end_inset 
22511
22512
22513 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
22514
22515 \end_inset 
22516
22517 .
22518 \layout Standard
22519
22520 You need to specify some parameters to the 
22521 \family typewriter 
22522 diff
22523 \family default 
22524  command for the patches to be useful.
22525  If you modified more than one file a patch created f.e.
22526  with 
22527 \family sans 
22528 \series bold 
22529
22530 \begin_inset Quotes sld
22531 \end_inset 
22532
22533 diff -Naur unmodified_directory modified_directory >my_changes.patch
22534 \begin_inset Quotes srd
22535 \end_inset 
22536
22537
22538 \family default 
22539 \series default 
22540  will be fine, otherwise 
22541 \family sans 
22542 \series bold 
22543
22544 \begin_inset Quotes sld
22545 \end_inset 
22546
22547 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
22548 \begin_inset Quotes srd
22549 \end_inset 
22550
22551
22552 \series default 
22553  
22554 \family default 
22555 will do.
22556 \layout Section
22557
22558 Getting Help
22559 \layout Standard
22560
22561 These links should take you directly to the 
22562 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
22563
22564 \end_inset 
22565
22566
22567 \begin_inset Foot
22568 collapsed false
22569
22570 \layout Standard
22571
22572 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
22573  automated messages (mid 2003)
22574 \end_inset 
22575
22576  and the 
22577 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
22578
22579 \end_inset 
22580
22581 , lists
22582 \begin_inset LatexCommand \index{Mailing list(s)}
22583
22584 \end_inset 
22585
22586  and forums are archived and searchable so if you are lucky someone already
22587  had a similar problem.
22588  While mails to the lists themselves are delivered promptly their web front
22589  end on sourceforge sometimes shows a severe time lag (up to several weeks),
22590  if you're seriously using SDCC please consider subscribing to the lists.
22591 \layout Section
22592
22593 ChangeLog
22594 \layout Standard
22595
22596 You can follow the status of the cvs version
22597 \begin_inset LatexCommand \index{version}
22598
22599 \end_inset 
22600
22601  of SDCC by watching the Changelog
22602 \begin_inset LatexCommand \index{Changelog}
22603
22604 \end_inset 
22605
22606  in the cvs-repository
22607 \newline 
22608
22609 \size footnotesize 
22610
22611 \begin_inset LatexCommand \htmlurl{http://cvs.sf.net/cgi-bin/viewcvs.cgi/*checkout*/sdcc/sdcc/ChangeLog?rev=HEAD&content-type=text/plain}
22612
22613 \end_inset 
22614
22615 .
22616 \layout Section
22617
22618 Release policy
22619 \begin_inset LatexCommand \index{Release policy}
22620
22621 \end_inset 
22622
22623
22624 \layout Standard
22625
22626 Historically there often were long delays between official releases and
22627  the sourceforge download area tends to get not updated at all.
22628  Excuses in the past might have referred to problems with live range analysis,
22629  but as this was fixed a while ago, the current problem is that another
22630  excuse has to be found.
22631  Kidding aside, we have to get better there! On the other hand there are
22632  daily snapshots available at 
22633 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
22634
22635 \end_inset 
22636
22637 , and you can always build the very last version (hopefully with many bugs
22638  fixed, and features added) from the source code available at 
22639 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
22640
22641 \end_inset 
22642
22643 .
22644 \layout Section
22645
22646 Examples
22647 \begin_inset LatexCommand \index{Examples}
22648
22649 \end_inset 
22650
22651
22652 \layout Standard
22653
22654 You'll find some small examples in the directory 
22655 \emph on 
22656 sdcc/device/examples/.
22657  
22658 \emph default 
22659 More examples and libraries are available at
22660 \emph on 
22661  The SDCC Open Knowledge Resource 
22662 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
22663
22664 \end_inset 
22665
22666  
22667 \emph default 
22668 web site or at 
22669 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
22670
22671 \end_inset 
22672
22673 .
22674 \layout Comment
22675
22676 I did insert a reference to Paul's web site here although it seems rather
22677  dedicated to a specific 8032 board (I think it's okay because it f.e.
22678  shows LCD/Harddisc interface and has a free 8051 monitor.
22679  Independent 8032 board vendors face hard competition of heavily subsidized
22680  development boards anyway).
22681 \layout Comment
22682
22683 Maybe we should include some links to real world applications.
22684  Preferably pointer to pointers (one for each architecture) so this stays
22685  manageable here?
22686 \layout Section
22687
22688 Quality control
22689 \begin_inset LatexCommand \index{Quality control}
22690
22691 \end_inset 
22692
22693
22694 \layout Standard
22695
22696 The compiler is passed through nightly compile and build checks.
22697  The so called 
22698 \shape italic 
22699 regression tests
22700 \shape default 
22701
22702 \begin_inset LatexCommand \index{Regression test}
22703
22704 \end_inset 
22705
22706  check that SDCC itself compiles flawlessly on several platforms and checks
22707  the quality of the code generated by SDCC by running the code through simulator
22708 s.
22709  There is a separate document 
22710 \shape italic 
22711 test_suite.pdf
22712 \begin_inset LatexCommand \index{Test suite}
22713
22714 \end_inset 
22715
22716
22717 \shape default 
22718  about this.
22719 \layout Standard
22720
22721 You'll find the test code in the directory 
22722 \shape italic 
22723 sdcc/support/regression
22724 \shape default 
22725 .
22726  You can run these tests manually by running 
22727 \family sans 
22728 make
22729 \family default 
22730  in this directory (or f.e.
22731  
22732 \family sans 
22733 \series bold 
22734
22735 \begin_inset Quotes sld
22736 \end_inset 
22737
22738 make test-mcs51
22739 \begin_inset Quotes srd
22740 \end_inset 
22741
22742
22743 \family default 
22744 \series default 
22745  if you don't want to run the complete tests).
22746  The test code might also be interesting if you want to look for examples
22747 \begin_inset LatexCommand \index{Examples}
22748
22749 \end_inset 
22750
22751  checking corner cases of SDCC or if you plan to submit patches
22752 \begin_inset LatexCommand \index{Patch submission}
22753
22754 \end_inset 
22755
22756 .
22757 \layout Standard
22758
22759 The pic port uses a different set of regression tests, you'll find them
22760  in the directory 
22761 \shape italic 
22762 sdcc/src/regression
22763 \shape default 
22764 .
22765 \layout Chapter
22766 \pagebreak_top 
22767 SDCC Technical Data
22768 \layout Section
22769
22770 Optimizations
22771 \begin_inset LatexCommand \index{Optimizations}
22772
22773 \end_inset 
22774
22775
22776 \layout Standard
22777
22778 SDCC performs a host of standard optimizations in addition to some MCU specific
22779  optimizations.
22780  
22781 \layout Subsection
22782
22783 Sub-expression Elimination
22784 \begin_inset LatexCommand \index{Subexpression elimination}
22785
22786 \end_inset 
22787
22788
22789 \layout Standard
22790
22791 The compiler does local and 
22792 \emph on 
22793 g
22794 \emph default 
22795 lobal 
22796 \emph on 
22797 c
22798 \emph default 
22799 ommon 
22800 \emph on 
22801 s
22802 \emph default 
22803 ubexpression 
22804 \emph on 
22805 e
22806 \emph default 
22807 limination, e.g.: 
22808 \layout Verse
22809
22810
22811 \family typewriter 
22812 i = x + y + 1; 
22813 \newline 
22814 j = x + y;
22815 \layout Standard
22816
22817 will be translated to
22818 \layout Verse
22819
22820
22821 \family typewriter 
22822 iTemp = x + y; 
22823 \newline 
22824 i = iTemp + 1; 
22825 \newline 
22826 j = iTemp;
22827 \layout Standard
22828
22829 Some subexpressions are not as obvious as the above example, e.g.:
22830 \layout Verse
22831
22832
22833 \family typewriter 
22834 a->b[i].c = 10; 
22835 \newline 
22836 a->b[i].d = 11;
22837 \layout Standard
22838
22839 In this case the address arithmetic a->b[i] will be computed only once;
22840  the equivalent code in C would be.
22841 \layout Verse
22842
22843
22844 \family typewriter 
22845 iTemp = a->b[i]; 
22846 \newline 
22847 iTemp.c = 10; 
22848 \newline 
22849 iTemp.d = 11;
22850 \layout Standard
22851
22852 The compiler will try to keep these temporary variables in registers.
22853 \layout Subsection
22854
22855 Dead-Code Elimination
22856 \begin_inset LatexCommand \index{Dead-code elimination}
22857
22858 \end_inset 
22859
22860
22861 \layout Verse
22862
22863
22864 \family typewriter 
22865 int global;
22866 \newline 
22867
22868 \newline 
22869 void f () { 
22870 \newline 
22871 \SpecialChar ~
22872 \SpecialChar ~
22873 int i; 
22874 \newline 
22875 \SpecialChar ~
22876 \SpecialChar ~
22877 i = 1; \SpecialChar ~
22878 \SpecialChar ~
22879 \SpecialChar ~
22880 \SpecialChar ~
22881 \SpecialChar ~
22882 /* dead store */ 
22883 \newline 
22884 \SpecialChar ~
22885 \SpecialChar ~
22886 global = 1;\SpecialChar ~
22887 /* dead store */ 
22888 \newline 
22889 \SpecialChar ~
22890 \SpecialChar ~
22891 global = 2; 
22892 \newline 
22893 \SpecialChar ~
22894 \SpecialChar ~
22895 return; 
22896 \newline 
22897 \SpecialChar ~
22898 \SpecialChar ~
22899 global = 3;\SpecialChar ~
22900 /* unreachable */ 
22901 \newline 
22902 }
22903 \layout Standard
22904
22905 will be changed to
22906 \layout Verse
22907
22908
22909 \family typewriter 
22910 int global;
22911 \newline 
22912
22913 \newline 
22914 void f () {
22915 \newline 
22916 \SpecialChar ~
22917 \SpecialChar ~
22918 global = 2; 
22919 \newline 
22920 }
22921 \layout Subsection
22922
22923 Copy-Propagation
22924 \begin_inset LatexCommand \index{Copy propagation}
22925
22926 \end_inset 
22927
22928
22929 \layout Verse
22930
22931
22932 \family typewriter 
22933 int f() { 
22934 \newline 
22935 \SpecialChar ~
22936 \SpecialChar ~
22937 int i, j; 
22938 \newline 
22939 \SpecialChar ~
22940 \SpecialChar ~
22941 i = 10; 
22942 \newline 
22943 \SpecialChar ~
22944 \SpecialChar ~
22945 j = i; 
22946 \newline 
22947 \SpecialChar ~
22948 \SpecialChar ~
22949 return j; 
22950 \newline 
22951 }
22952 \layout Standard
22953
22954 will be changed to 
22955 \layout Verse
22956
22957
22958 \family typewriter 
22959 int f() { 
22960 \newline 
22961 \SpecialChar ~
22962 \SpecialChar ~
22963 int i, j; 
22964 \newline 
22965 \SpecialChar ~
22966 \SpecialChar ~
22967 i = 10; 
22968 \newline 
22969 \SpecialChar ~
22970 \SpecialChar ~
22971 j = 10; 
22972 \newline 
22973 \SpecialChar ~
22974 \SpecialChar ~
22975 return 10; 
22976 \newline 
22977 }
22978 \layout Standard
22979
22980 Note: the dead stores created by this copy propagation will be eliminated
22981  by dead-code elimination.
22982 \layout Subsection
22983
22984 Loop Optimizations
22985 \begin_inset LatexCommand \index{Loop optimization}
22986
22987 \end_inset 
22988
22989
22990 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
22991
22992 \end_inset 
22993
22994
22995 \layout Standard
22996
22997 Two types of loop optimizations are done by SDCC 
22998 \emph on 
22999 loop invariant
23000 \emph default 
23001  lifting and
23002 \emph on 
23003  strength reduction
23004 \emph default 
23005  of loop induction variables.
23006  In addition to the strength reduction the optimizer marks the induction
23007  variables and the register allocator tries to keep the induction variables
23008  in registers for the duration of the loop.
23009  Because of this preference of the register allocator
23010 \begin_inset LatexCommand \index{Register allocation}
23011
23012 \end_inset 
23013
23014 , loop induction optimization causes an increase in register pressure, which
23015  may cause unwanted spilling of other temporary variables into the stack
23016 \begin_inset LatexCommand \index{stack}
23017
23018 \end_inset 
23019
23020  / data space.
23021  The compiler will generate a warning message when it is forced to allocate
23022  extra space either on the stack or data space.
23023  If this extra space allocation is undesirable then induction optimization
23024  can be eliminated either for the entire source file (with -
23025 \begin_inset ERT
23026 status Collapsed
23027
23028 \layout Standard
23029
23030 \backslash 
23031 /
23032 \end_inset 
23033
23034 -noinduction option) or for a given function only using #pragma\SpecialChar ~
23035 noinduction
23036 \begin_inset LatexCommand \index{\#pragma noinduction}
23037
23038 \end_inset 
23039
23040 .
23041 \newline 
23042
23043 \newline 
23044 Loop Invariant:
23045 \layout Verse
23046
23047
23048 \family typewriter 
23049 for (i = 0 ; i < 100 ; i ++) 
23050 \newline 
23051 \SpecialChar ~
23052 \SpecialChar ~
23053 \SpecialChar ~
23054 \SpecialChar ~
23055 f += k + l;
23056 \layout Standard
23057
23058 changed to
23059 \layout Verse
23060
23061
23062 \family typewriter 
23063 itemp = k + l; 
23064 \newline 
23065 for (i = 0; i < 100; i++) 
23066 \newline 
23067 \SpecialChar ~
23068 \SpecialChar ~
23069 \SpecialChar ~
23070 \SpecialChar ~
23071 f += itemp;
23072 \layout Standard
23073
23074 As mentioned previously some loop invariants are not as apparent, all static
23075  address computations are also moved out of the loop.
23076 \newline 
23077
23078 \newline 
23079 Strength Reduction
23080 \begin_inset LatexCommand \index{Strength reduction}
23081
23082 \end_inset 
23083
23084 , this optimization substitutes an expression by a cheaper expression:
23085 \layout Verse
23086
23087
23088 \family typewriter 
23089 for (i=0;i < 100; i++)
23090 \newline 
23091 \SpecialChar ~
23092 \SpecialChar ~
23093 \SpecialChar ~
23094 \SpecialChar ~
23095 ar[i*5] = i*3;
23096 \layout Standard
23097
23098 changed to
23099 \layout Verse
23100
23101
23102 \family typewriter 
23103 itemp1 = 0; 
23104 \newline 
23105 itemp2 = 0; 
23106 \newline 
23107 for (i=0;i< 100;i++) { 
23108 \newline 
23109 \SpecialChar ~
23110 \SpecialChar ~
23111 \SpecialChar ~
23112 \SpecialChar ~
23113 ar[itemp1] = itemp2; 
23114 \newline 
23115 \SpecialChar ~
23116 \SpecialChar ~
23117 \SpecialChar ~
23118 \SpecialChar ~
23119 itemp1 += 5; 
23120 \newline 
23121 \SpecialChar ~
23122 \SpecialChar ~
23123 \SpecialChar ~
23124 \SpecialChar ~
23125 itemp2 += 3; 
23126 \newline 
23127 }
23128 \layout Standard
23129
23130 The more expensive multiplication
23131 \begin_inset LatexCommand \index{Multiplication}
23132
23133 \end_inset 
23134
23135  is changed to a less expensive addition.
23136 \layout Subsection
23137
23138 Loop Reversing
23139 \begin_inset LatexCommand \index{Loop reversing}
23140
23141 \end_inset 
23142
23143
23144 \layout Standard
23145
23146 This optimization is done to reduce the overhead of checking loop boundaries
23147  for every iteration.
23148  Some simple loops can be reversed and implemented using a 
23149 \begin_inset Quotes eld
23150 \end_inset 
23151
23152 decrement and jump if not zero
23153 \begin_inset Quotes erd
23154 \end_inset 
23155
23156  instruction.
23157  SDCC checks for the following criterion to determine if a loop is reversible
23158  (note: more sophisticated compilers use data-dependency analysis to make
23159  this determination, SDCC uses a more simple minded analysis).
23160 \layout Itemize
23161
23162 The 'for' loop is of the form 
23163 \newline 
23164
23165 \newline 
23166
23167 \family typewriter 
23168 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
23169  += 1])
23170 \newline 
23171 \SpecialChar ~
23172 \SpecialChar ~
23173 \SpecialChar ~
23174 \SpecialChar ~
23175 <for body>
23176 \layout Itemize
23177
23178 The <for body> does not contain 
23179 \begin_inset Quotes eld
23180 \end_inset 
23181
23182 continue
23183 \begin_inset Quotes erd
23184 \end_inset 
23185
23186  or 'break
23187 \begin_inset Quotes erd
23188 \end_inset 
23189
23190 .
23191 \layout Itemize
23192
23193 All goto's are contained within the loop.
23194 \layout Itemize
23195
23196 No function calls within the loop.
23197 \layout Itemize
23198
23199 The loop control variable <sym> is not assigned any value within the loop
23200 \layout Itemize
23201
23202 The loop control variable does NOT participate in any arithmetic operation
23203  within the loop.
23204 \layout Itemize
23205
23206 There are NO switch statements in the loop.
23207 \layout Subsection
23208
23209 Algebraic Simplifications
23210 \layout Standard
23211
23212 SDCC does numerous algebraic simplifications, the following is a small sub-set
23213  of these optimizations.
23214 \layout Verse
23215
23216
23217 \family typewriter 
23218 i = j + 0;\SpecialChar ~
23219 \SpecialChar ~
23220 \SpecialChar ~
23221 \SpecialChar ~
23222  /* changed to: */\SpecialChar ~
23223 \SpecialChar ~
23224 \SpecialChar ~
23225 \SpecialChar ~
23226  i = j; 
23227 \newline 
23228 i /= 2;\SpecialChar ~
23229 \SpecialChar ~
23230 \SpecialChar ~
23231 \SpecialChar ~
23232 \SpecialChar ~
23233 \SpecialChar ~
23234 \SpecialChar ~
23235  /* changed to: */\SpecialChar ~
23236 \SpecialChar ~
23237 \SpecialChar ~
23238 \SpecialChar ~
23239  i >>= 1; 
23240 \newline 
23241 i = j - j;\SpecialChar ~
23242 \SpecialChar ~
23243 \SpecialChar ~
23244 \SpecialChar ~
23245  /* changed to: */\SpecialChar ~
23246 \SpecialChar ~
23247 \SpecialChar ~
23248 \SpecialChar ~
23249  i = 0; 
23250 \newline 
23251 i = j / 1;\SpecialChar ~
23252 \SpecialChar ~
23253 \SpecialChar ~
23254 \SpecialChar ~
23255  /* changed to: */\SpecialChar ~
23256 \SpecialChar ~
23257 \SpecialChar ~
23258 \SpecialChar ~
23259  i = j;
23260 \layout Standard
23261
23262 Note the subexpressions
23263 \begin_inset LatexCommand \index{Subexpression}
23264
23265 \end_inset 
23266
23267  given above are generally introduced by macro expansions or as a result
23268  of copy/constant propagation.
23269 \layout Subsection
23270
23271 'switch' Statements
23272 \begin_inset LatexCommand \label{sub:'switch'-Statements}
23273
23274 \end_inset 
23275
23276
23277 \begin_inset LatexCommand \index{switch statement}
23278
23279 \end_inset 
23280
23281
23282 \layout Standard
23283
23284 SDCC can optimize switch statements to jump tables
23285 \begin_inset LatexCommand \index{jump tables}
23286
23287 \end_inset 
23288
23289 .
23290  It makes the decision based on an estimate of the generated code size.
23291  SDCC is quite liberal in the requirements for jump table generation: 
23292 \layout Itemize
23293
23294 The labels need not be in order, and the starting number need not be one
23295  or zero, the case labels are in numerical sequence or not too many case
23296  labels are missing.
23297 \begin_deeper 
23298 \layout Verse
23299
23300
23301 \family typewriter 
23302 switch(i) {\SpecialChar ~
23303 \SpecialChar ~
23304 \SpecialChar ~
23305 \SpecialChar ~
23306 \SpecialChar ~
23307 \SpecialChar ~
23308 \SpecialChar ~
23309 \SpecialChar ~
23310 \SpecialChar ~
23311 \SpecialChar ~
23312 \SpecialChar ~
23313 \SpecialChar ~
23314 \SpecialChar ~
23315 \SpecialChar ~
23316 \SpecialChar ~
23317 \SpecialChar ~
23318 \SpecialChar ~
23319 \SpecialChar ~
23320 \SpecialChar ~
23321 \SpecialChar ~
23322 \SpecialChar ~
23323 \SpecialChar ~
23324 \SpecialChar ~
23325 \SpecialChar ~
23326 \SpecialChar ~
23327 \SpecialChar ~
23328 switch (i) { 
23329 \newline 
23330 \SpecialChar ~
23331 \SpecialChar ~
23332 \SpecialChar ~
23333 case 4: ...\SpecialChar ~
23334 \SpecialChar ~
23335 \SpecialChar ~
23336 \SpecialChar ~
23337 \SpecialChar ~
23338 \SpecialChar ~
23339 \SpecialChar ~
23340 \SpecialChar ~
23341 \SpecialChar ~
23342 \SpecialChar ~
23343 \SpecialChar ~
23344 \SpecialChar ~
23345 \SpecialChar ~
23346 \SpecialChar ~
23347 \SpecialChar ~
23348 \SpecialChar ~
23349 \SpecialChar ~
23350 \SpecialChar ~
23351 \SpecialChar ~
23352 \SpecialChar ~
23353 \SpecialChar ~
23354 \SpecialChar ~
23355 \SpecialChar ~
23356 \SpecialChar ~
23357 \SpecialChar ~
23358 \SpecialChar ~
23359 case 0: ...
23360  
23361 \newline 
23362 \SpecialChar ~
23363 \SpecialChar ~
23364 \SpecialChar ~
23365 case 5: ...\SpecialChar ~
23366 \SpecialChar ~
23367 \SpecialChar ~
23368 \SpecialChar ~
23369 \SpecialChar ~
23370 \SpecialChar ~
23371 \SpecialChar ~
23372 \SpecialChar ~
23373 \SpecialChar ~
23374 \SpecialChar ~
23375 \SpecialChar ~
23376 \SpecialChar ~
23377 \SpecialChar ~
23378 \SpecialChar ~
23379 \SpecialChar ~
23380 \SpecialChar ~
23381 \SpecialChar ~
23382 \SpecialChar ~
23383 \SpecialChar ~
23384 \SpecialChar ~
23385 \SpecialChar ~
23386 \SpecialChar ~
23387 \SpecialChar ~
23388 \SpecialChar ~
23389 \SpecialChar ~
23390 \SpecialChar ~
23391 case 1: ...
23392  
23393 \newline 
23394 \SpecialChar ~
23395 \SpecialChar ~
23396 \SpecialChar ~
23397 case 3: ...\SpecialChar ~
23398 \SpecialChar ~
23399 \SpecialChar ~
23400 \SpecialChar ~
23401 \SpecialChar ~
23402 \SpecialChar ~
23403 \SpecialChar ~
23404 \SpecialChar ~
23405 \SpecialChar ~
23406 \SpecialChar ~
23407 \SpecialChar ~
23408 \SpecialChar ~
23409 \SpecialChar ~
23410 \SpecialChar ~
23411 \SpecialChar ~
23412 \SpecialChar ~
23413 \SpecialChar ~
23414 \SpecialChar ~
23415 \SpecialChar ~
23416 \SpecialChar ~
23417 \SpecialChar ~
23418 \SpecialChar ~
23419 \SpecialChar ~
23420 \SpecialChar ~
23421 \SpecialChar ~
23422 \SpecialChar ~
23423
23424 \newline 
23425 \SpecialChar ~
23426 \SpecialChar ~
23427 \SpecialChar ~
23428 case 6: ...\SpecialChar ~
23429 \SpecialChar ~
23430 \SpecialChar ~
23431 \SpecialChar ~
23432 \SpecialChar ~
23433 \SpecialChar ~
23434 \SpecialChar ~
23435 \SpecialChar ~
23436 \SpecialChar ~
23437 \SpecialChar ~
23438 \SpecialChar ~
23439 \SpecialChar ~
23440 \SpecialChar ~
23441 \SpecialChar ~
23442 \SpecialChar ~
23443 \SpecialChar ~
23444 \SpecialChar ~
23445 \SpecialChar ~
23446 \SpecialChar ~
23447 \SpecialChar ~
23448 \SpecialChar ~
23449 \SpecialChar ~
23450 \SpecialChar ~
23451 \SpecialChar ~
23452 \SpecialChar ~
23453 \SpecialChar ~
23454 case 3: ...
23455  
23456 \newline 
23457 \SpecialChar ~
23458 \SpecialChar ~
23459 \SpecialChar ~
23460 case 7: ...\SpecialChar ~
23461 \SpecialChar ~
23462 \SpecialChar ~
23463 \SpecialChar ~
23464 \SpecialChar ~
23465 \SpecialChar ~
23466 \SpecialChar ~
23467 \SpecialChar ~
23468 \SpecialChar ~
23469 \SpecialChar ~
23470 \SpecialChar ~
23471 \SpecialChar ~
23472 \SpecialChar ~
23473 \SpecialChar ~
23474 \SpecialChar ~
23475 \SpecialChar ~
23476 \SpecialChar ~
23477 \SpecialChar ~
23478 \SpecialChar ~
23479 \SpecialChar ~
23480 \SpecialChar ~
23481 \SpecialChar ~
23482 \SpecialChar ~
23483 \SpecialChar ~
23484 \SpecialChar ~
23485 \SpecialChar ~
23486 case 4: ...
23487  
23488 \newline 
23489 \SpecialChar ~
23490 \SpecialChar ~
23491 \SpecialChar ~
23492 case 8: ...\SpecialChar ~
23493 \SpecialChar ~
23494 \SpecialChar ~
23495 \SpecialChar ~
23496 \SpecialChar ~
23497 \SpecialChar ~
23498 \SpecialChar ~
23499 \SpecialChar ~
23500 \SpecialChar ~
23501 \SpecialChar ~
23502 \SpecialChar ~
23503 \SpecialChar ~
23504 \SpecialChar ~
23505 \SpecialChar ~
23506 \SpecialChar ~
23507 \SpecialChar ~
23508 \SpecialChar ~
23509 \SpecialChar ~
23510 \SpecialChar ~
23511 \SpecialChar ~
23512 \SpecialChar ~
23513 \SpecialChar ~
23514 \SpecialChar ~
23515 \SpecialChar ~
23516 \SpecialChar ~
23517 \SpecialChar ~
23518 case 5: ...
23519  
23520 \newline 
23521 \SpecialChar ~
23522 \SpecialChar ~
23523 \SpecialChar ~
23524 case 9: ...\SpecialChar ~
23525 \SpecialChar ~
23526 \SpecialChar ~
23527 \SpecialChar ~
23528 \SpecialChar ~
23529 \SpecialChar ~
23530 \SpecialChar ~
23531 \SpecialChar ~
23532 \SpecialChar ~
23533 \SpecialChar ~
23534 \SpecialChar ~
23535 \SpecialChar ~
23536 \SpecialChar ~
23537 \SpecialChar ~
23538 \SpecialChar ~
23539 \SpecialChar ~
23540 \SpecialChar ~
23541 \SpecialChar ~
23542 \SpecialChar ~
23543 \SpecialChar ~
23544 \SpecialChar ~
23545 \SpecialChar ~
23546 \SpecialChar ~
23547 \SpecialChar ~
23548 \SpecialChar ~
23549 \SpecialChar ~
23550 case 6: ...
23551  
23552 \newline 
23553 \SpecialChar ~
23554 \SpecialChar ~
23555 \SpecialChar ~
23556 case 10: ...\SpecialChar ~
23557 \SpecialChar ~
23558 \SpecialChar ~
23559 \SpecialChar ~
23560 \SpecialChar ~
23561 \SpecialChar ~
23562 \SpecialChar ~
23563 \SpecialChar ~
23564 \SpecialChar ~
23565 \SpecialChar ~
23566 \SpecialChar ~
23567 \SpecialChar ~
23568 \SpecialChar ~
23569 \SpecialChar ~
23570 \SpecialChar ~
23571 \SpecialChar ~
23572 \SpecialChar ~
23573 \SpecialChar ~
23574 \SpecialChar ~
23575 \SpecialChar ~
23576 \SpecialChar ~
23577 \SpecialChar ~
23578 \SpecialChar ~
23579 \SpecialChar ~
23580 \SpecialChar ~
23581 case 7: ...
23582  
23583 \newline 
23584 \SpecialChar ~
23585 \SpecialChar ~
23586 \SpecialChar ~
23587 case 11: ...\SpecialChar ~
23588 \SpecialChar ~
23589 \SpecialChar ~
23590 \SpecialChar ~
23591 \SpecialChar ~
23592 \SpecialChar ~
23593 \SpecialChar ~
23594 \SpecialChar ~
23595 \SpecialChar ~
23596 \SpecialChar ~
23597 \SpecialChar ~
23598 \SpecialChar ~
23599 \SpecialChar ~
23600 \SpecialChar ~
23601 \SpecialChar ~
23602 \SpecialChar ~
23603 \SpecialChar ~
23604 \SpecialChar ~
23605 \SpecialChar ~
23606 \SpecialChar ~
23607 \SpecialChar ~
23608 \SpecialChar ~
23609 \SpecialChar ~
23610 \SpecialChar ~
23611 \SpecialChar ~
23612 case 8: ...
23613  
23614 \newline 
23615 }\SpecialChar ~
23616 \SpecialChar ~
23617 \SpecialChar ~
23618 \SpecialChar ~
23619 \SpecialChar ~
23620 \SpecialChar ~
23621 \SpecialChar ~
23622 \SpecialChar ~
23623 \SpecialChar ~
23624 \SpecialChar ~
23625 \SpecialChar ~
23626 \SpecialChar ~
23627 \SpecialChar ~
23628 \SpecialChar ~
23629 \SpecialChar ~
23630 \SpecialChar ~
23631 \SpecialChar ~
23632 \SpecialChar ~
23633 \SpecialChar ~
23634 \SpecialChar ~
23635 \SpecialChar ~
23636 \SpecialChar ~
23637 \SpecialChar ~
23638 \SpecialChar ~
23639 \SpecialChar ~
23640 \SpecialChar ~
23641 \SpecialChar ~
23642 \SpecialChar ~
23643 \SpecialChar ~
23644 \SpecialChar ~
23645 \SpecialChar ~
23646 \SpecialChar ~
23647 \SpecialChar ~
23648 \SpecialChar ~
23649 \SpecialChar ~
23650 \SpecialChar ~
23651 }
23652 \layout Standard
23653
23654 Both the above switch statements will be implemented using a jump-table.
23655  The example to the right side is slightly more efficient as the check for
23656  the lower boundary of the jump-table is not needed.
23657 \end_deeper 
23658 \layout Itemize
23659
23660 The number of case labels is not larger than supported by the target architectur
23661 e.
23662 \layout Itemize
23663
23664 If the case labels are not in numerical sequence ('gaps' between cases)
23665  SDCC checks whether a jump table with additionally inserted dummy cases
23666  is still attractive.
23667  
23668 \layout Itemize
23669
23670 If the starting number is not zero and a check for the lower boundary of
23671  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
23672  ...
23673  .
23674 \layout Standard
23675
23676 Switch statements which have large gaps in the numeric sequence or those
23677  that have too many case labels can be split into more than one switch statement
23678  for efficient code generation, e.g.:
23679 \layout Verse
23680
23681
23682 \family typewriter 
23683 switch (i) { 
23684 \newline 
23685 \SpecialChar ~
23686 \SpecialChar ~
23687 case 1: ...
23688  
23689 \newline 
23690 \SpecialChar ~
23691 \SpecialChar ~
23692 case 2: ...
23693  
23694 \newline 
23695 \SpecialChar ~
23696 \SpecialChar ~
23697 case 3: ...
23698  
23699 \newline 
23700 \SpecialChar ~
23701 \SpecialChar ~
23702 case 4: ...
23703  
23704 \newline 
23705 \SpecialChar ~
23706 \SpecialChar ~
23707 case 5: ...
23708  
23709 \newline 
23710 \SpecialChar ~
23711 \SpecialChar ~
23712 case 6: ...
23713  
23714 \newline 
23715 \SpecialChar ~
23716 \SpecialChar ~
23717 case 7: ...
23718  
23719 \newline 
23720 \SpecialChar ~
23721 \SpecialChar ~
23722 case 101: ...
23723  
23724 \newline 
23725 \SpecialChar ~
23726 \SpecialChar ~
23727 case 102: ...
23728  
23729 \newline 
23730 \SpecialChar ~
23731 \SpecialChar ~
23732 case 103: ...
23733  
23734 \newline 
23735 \SpecialChar ~
23736 \SpecialChar ~
23737 case 104: ...
23738  
23739 \newline 
23740 \SpecialChar ~
23741 \SpecialChar ~
23742 case 105: ...
23743  
23744 \newline 
23745 \SpecialChar ~
23746 \SpecialChar ~
23747 case 106: ...
23748  
23749 \newline 
23750 \SpecialChar ~
23751 \SpecialChar ~
23752 case 107: ...
23753  
23754 \newline 
23755 }
23756 \layout Standard
23757
23758 If the above switch statement is broken down into two switch statements
23759 \layout Verse
23760
23761
23762 \family typewriter 
23763 switch (i) { 
23764 \newline 
23765 \SpecialChar ~
23766 \SpecialChar ~
23767 case 1: ...
23768  
23769 \newline 
23770 \SpecialChar ~
23771 \SpecialChar ~
23772 case 2: ...
23773  
23774 \newline 
23775 \SpecialChar ~
23776 \SpecialChar ~
23777 case 3: ...
23778  
23779 \newline 
23780 \SpecialChar ~
23781 \SpecialChar ~
23782 case 4: ...
23783  
23784 \newline 
23785 \SpecialChar ~
23786 \SpecialChar ~
23787 case 5: ...
23788  
23789 \newline 
23790 \SpecialChar ~
23791 \SpecialChar ~
23792 case 6: ...
23793  
23794 \newline 
23795 \SpecialChar ~
23796 \SpecialChar ~
23797 case 7: ...
23798  
23799 \newline 
23800 }
23801 \layout Standard
23802
23803 and
23804 \layout Verse
23805
23806
23807 \family typewriter 
23808 switch (i) { 
23809 \newline 
23810 \SpecialChar ~
23811 \SpecialChar ~
23812 case 101: ...
23813  
23814 \newline 
23815 \SpecialChar ~
23816 \SpecialChar ~
23817 case 102: ...
23818  
23819 \newline 
23820 \SpecialChar ~
23821 \SpecialChar ~
23822 case 103: ...
23823  
23824 \newline 
23825 \SpecialChar ~
23826 \SpecialChar ~
23827 case 104: ...
23828  
23829 \newline 
23830 \SpecialChar ~
23831 \SpecialChar ~
23832 case 105: ...
23833  
23834 \newline 
23835 \SpecialChar ~
23836 \SpecialChar ~
23837 case 106: ...
23838  
23839 \newline 
23840 \SpecialChar ~
23841 \SpecialChar ~
23842 case 107: ...
23843  
23844 \newline 
23845 }
23846 \layout Standard
23847
23848 then both the switch statements will be implemented using jump-tables whereas
23849  the unmodified switch statement will not be.
23850 \layout Comment
23851
23852 There might be reasons which SDCC cannot know about to either favour or
23853  not favour jump tables.
23854  If the target system has to be as quick for the last switch case as for
23855  the first (pro jump table), or if the switch argument is known to be zero
23856  in the majority of the cases (contra jump table).
23857 \layout Standard
23858
23859 The pragma nojtbound
23860 \begin_inset LatexCommand \index{\#pragma nojtbound}
23861
23862 \end_inset 
23863
23864  can be used to turn off checking the 
23865 \emph on 
23866 j
23867 \emph default 
23868 ump 
23869 \emph on 
23870 t
23871 \emph default 
23872 able 
23873 \emph on 
23874 bound
23875 \emph default 
23876 aries.
23877  It has no effect if a default label is supplied.
23878  Use of this pragma is dangerous: if the switch
23879 \begin_inset LatexCommand \index{switch statement}
23880
23881 \end_inset 
23882
23883  argument is not matched by a case statement the processor will happily
23884  jump into Nirvana.
23885 \layout Subsection
23886
23887 Bit-shifting Operations
23888 \begin_inset LatexCommand \index{Bit shifting}
23889
23890 \end_inset 
23891
23892 .
23893 \layout Standard
23894
23895 Bit shifting is one of the most frequently used operation in embedded programmin
23896 g.
23897  SDCC tries to implement bit-shift operations in the most efficient way
23898  possible, e.g.:
23899 \layout Verse
23900
23901
23902 \family typewriter 
23903 unsigned char i;
23904 \newline 
23905 ...
23906  
23907 \newline 
23908 i >>= 4; 
23909 \newline 
23910 ...
23911 \layout Standard
23912
23913 generates the following code:
23914 \layout Verse
23915
23916
23917 \family typewriter 
23918 mov\SpecialChar ~
23919  a,_i 
23920 \newline 
23921 swap a 
23922 \newline 
23923 anl\SpecialChar ~
23924  a,#0x0f 
23925 \newline 
23926 mov\SpecialChar ~
23927  _i,a
23928 \layout Standard
23929
23930 In general SDCC will never setup a loop if the shift count is known.
23931  Another example:
23932 \layout Verse
23933
23934
23935 \family typewriter 
23936 unsigned int i; 
23937 \newline 
23938 ...
23939  
23940 \newline 
23941 i >>= 9; 
23942 \newline 
23943 ...
23944 \layout Standard
23945
23946 will generate:
23947 \layout Verse
23948
23949
23950 \family typewriter 
23951 mov\SpecialChar ~
23952 \SpecialChar ~
23953 a,(_i + 1) 
23954 \newline 
23955 mov\SpecialChar ~
23956 \SpecialChar ~
23957 (_i + 1),#0x00 
23958 \newline 
23959 clr\SpecialChar ~
23960 \SpecialChar ~
23961
23962 \newline 
23963 rrc\SpecialChar ~
23964 \SpecialChar ~
23965
23966 \newline 
23967 mov\SpecialChar ~
23968 \SpecialChar ~
23969 _i,a
23970 \layout Subsection
23971
23972 Bit-rotation
23973 \begin_inset LatexCommand \index{Bit rotation}
23974
23975 \end_inset 
23976
23977
23978 \layout Standard
23979
23980 A special case of the bit-shift operation is bit rotation
23981 \begin_inset LatexCommand \index{rotating bits}
23982
23983 \end_inset 
23984
23985 , SDCC recognizes the following expression to be a left bit-rotation:
23986 \layout Verse
23987
23988
23989 \family typewriter 
23990 \series bold 
23991 unsigned
23992 \series default 
23993 \SpecialChar ~
23994 \SpecialChar ~
23995 char i;\SpecialChar ~
23996 \SpecialChar ~
23997 \SpecialChar ~
23998 \SpecialChar ~
23999 \SpecialChar ~
24000 \SpecialChar ~
24001 \SpecialChar ~
24002 \SpecialChar ~
24003 \SpecialChar ~
24004 \SpecialChar ~
24005 \SpecialChar ~
24006 /* unsigned is needed for rotation */ 
24007 \newline 
24008 ...
24009  
24010 \newline 
24011 i = ((i << 1) | (i >> 7)); 
24012 \family default 
24013
24014 \newline 
24015
24016 \family typewriter 
24017 ...
24018 \layout Standard
24019
24020 will generate the following code:
24021 \layout Verse
24022
24023
24024 \family typewriter 
24025 mov\SpecialChar ~
24026 \SpecialChar ~
24027 a,_i 
24028 \newline 
24029 rl\SpecialChar ~
24030 \SpecialChar ~
24031 \SpecialChar ~
24032
24033 \newline 
24034 mov\SpecialChar ~
24035 \SpecialChar ~
24036 _i,a
24037 \layout Standard
24038
24039 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
24040 ns of this case will also be recognized as bit-rotation, i.e.: 
24041 \layout Verse
24042
24043
24044 \family typewriter 
24045 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
24046 \layout Subsection
24047
24048 Nibble and Byte Swapping
24049 \layout Standard
24050
24051 Other special cases of the bit-shift operations are nibble or byte swapping
24052 \begin_inset LatexCommand \index{swapping nibbles/bytes}
24053
24054 \end_inset 
24055
24056 , SDCC recognizes the following expressions:
24057 \layout Verse
24058
24059
24060 \family typewriter 
24061 \series bold 
24062 unsigned
24063 \series default 
24064 \SpecialChar ~
24065 \SpecialChar ~
24066 char i; 
24067 \newline 
24068
24069 \series bold 
24070 unsigned
24071 \series default 
24072 \SpecialChar ~
24073 \SpecialChar ~
24074 int j; 
24075 \newline 
24076 ...
24077  
24078 \newline 
24079 i = ((i << 4) | (i >> 4)); 
24080 \family default 
24081
24082 \newline 
24083
24084 \family typewriter 
24085 j = ((j << 8) | (j >> 8)); 
24086 \layout Standard
24087
24088 and generates a swap instruction for the nibble swapping
24089 \begin_inset LatexCommand \index{Nibble swapping}
24090
24091 \end_inset 
24092
24093  or move instructions for the byte swapping
24094 \begin_inset LatexCommand \index{Byte swapping}
24095
24096 \end_inset 
24097
24098 .
24099  The 
24100 \begin_inset Quotes sld
24101 \end_inset 
24102
24103 j
24104 \begin_inset Quotes srd
24105 \end_inset 
24106
24107  example can be used to convert from little to big-endian or vice versa.
24108  If you want to change the endianness of a 
24109 \emph on 
24110 signed
24111 \emph default 
24112  integer you have to cast to 
24113 \family typewriter 
24114 (unsigned int)
24115 \family default 
24116  first.
24117 \layout Standard
24118
24119 Note that SDCC stores numbers in little-endian
24120 \begin_inset Foot
24121 collapsed false
24122
24123 \layout Standard
24124
24125 Usually 8-bit processors don't care much about endianness.
24126  This is not the case for the standard 8051 which only has an instruction
24127  to increment its 
24128 \emph on 
24129 dptr
24130 \emph default 
24131
24132 \begin_inset LatexCommand \index{DPTR}
24133
24134 \end_inset 
24135
24136 -datapointer
24137 \emph on 
24138  
24139 \emph default 
24140 so little-endian is the more efficient byte order.
24141 \end_inset 
24142
24143
24144 \begin_inset LatexCommand \index{little-endian}
24145
24146 \end_inset 
24147
24148
24149 \begin_inset LatexCommand \index{Endianness}
24150
24151 \end_inset 
24152
24153  format (i.e.
24154  lowest order first).
24155 \layout Subsection
24156
24157 Highest Order Bit
24158 \begin_inset LatexCommand \index{Highest Order Bit}
24159
24160 \end_inset 
24161
24162
24163 \layout Standard
24164
24165 It is frequently required to obtain the highest order bit of an integral
24166  type (long, int, short or char types).
24167  SDCC recognizes the following expression to yield the highest order bit
24168  and generates optimized code for it, e.g.:
24169 \layout Verse
24170
24171
24172 \family typewriter 
24173 unsigned int gint; 
24174 \newline 
24175
24176 \newline 
24177 foo () { 
24178 \newline 
24179 \SpecialChar ~
24180 \SpecialChar ~
24181 unsigned char hob; 
24182 \newline 
24183 \SpecialChar ~
24184 \SpecialChar ~
24185 ...
24186  
24187 \newline 
24188 \SpecialChar ~
24189 \SpecialChar ~
24190 hob = (gint >> 15) & 1; 
24191 \newline 
24192 \SpecialChar ~
24193 \SpecialChar ~
24194 ..
24195  
24196 \newline 
24197 }
24198 \layout Standard
24199
24200 will generate the following code:
24201 \layout Verse
24202
24203
24204 \family typewriter 
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 \SpecialChar ~
24230  61 ;\SpecialChar ~
24231  hob.c 7 
24232 \newline 
24233 000A E5*01\SpecialChar ~
24234 \SpecialChar ~
24235 \SpecialChar ~
24236 \SpecialChar ~
24237 \SpecialChar ~
24238 \SpecialChar ~
24239 \SpecialChar ~
24240 \SpecialChar ~
24241 \SpecialChar ~
24242 \SpecialChar ~
24243 \SpecialChar ~
24244 \SpecialChar ~
24245 \SpecialChar ~
24246 \SpecialChar ~
24247 \SpecialChar ~
24248  62\SpecialChar ~
24249 \SpecialChar ~
24250 \SpecialChar ~
24251 \SpecialChar ~
24252 \SpecialChar ~
24253 \SpecialChar ~
24254 \SpecialChar ~
24255 \SpecialChar ~
24256  mov\SpecialChar ~
24257 \SpecialChar ~
24258  a,(_gint + 1) 
24259 \newline 
24260 000C 23\SpecialChar ~
24261 \SpecialChar ~
24262 \SpecialChar ~
24263 \SpecialChar ~
24264 \SpecialChar ~
24265 \SpecialChar ~
24266 \SpecialChar ~
24267 \SpecialChar ~
24268 \SpecialChar ~
24269 \SpecialChar ~
24270 \SpecialChar ~
24271 \SpecialChar ~
24272 \SpecialChar ~
24273 \SpecialChar ~
24274 \SpecialChar ~
24275 \SpecialChar ~
24276 \SpecialChar ~
24277 \SpecialChar ~
24278  63\SpecialChar ~
24279 \SpecialChar ~
24280 \SpecialChar ~
24281 \SpecialChar ~
24282 \SpecialChar ~
24283 \SpecialChar ~
24284 \SpecialChar ~
24285 \SpecialChar ~
24286  rl\SpecialChar ~
24287 \SpecialChar ~
24288 \SpecialChar ~
24289  a 
24290 \newline 
24291 000D 54 01\SpecialChar ~
24292 \SpecialChar ~
24293 \SpecialChar ~
24294 \SpecialChar ~
24295 \SpecialChar ~
24296 \SpecialChar ~
24297 \SpecialChar ~
24298 \SpecialChar ~
24299 \SpecialChar ~
24300 \SpecialChar ~
24301 \SpecialChar ~
24302 \SpecialChar ~
24303 \SpecialChar ~
24304 \SpecialChar ~
24305 \SpecialChar ~
24306  64\SpecialChar ~
24307 \SpecialChar ~
24308 \SpecialChar ~
24309 \SpecialChar ~
24310 \SpecialChar ~
24311 \SpecialChar ~
24312 \SpecialChar ~
24313 \SpecialChar ~
24314  anl\SpecialChar ~
24315 \SpecialChar ~
24316  a,#0x01 
24317 \newline 
24318 000F F5*02\SpecialChar ~
24319 \SpecialChar ~
24320 \SpecialChar ~
24321 \SpecialChar ~
24322 \SpecialChar ~
24323 \SpecialChar ~
24324 \SpecialChar ~
24325 \SpecialChar ~
24326 \SpecialChar ~
24327 \SpecialChar ~
24328 \SpecialChar ~
24329 \SpecialChar ~
24330 \SpecialChar ~
24331 \SpecialChar ~
24332 \SpecialChar ~
24333  65\SpecialChar ~
24334 \SpecialChar ~
24335 \SpecialChar ~
24336 \SpecialChar ~
24337 \SpecialChar ~
24338 \SpecialChar ~
24339 \SpecialChar ~
24340 \SpecialChar ~
24341  mov\SpecialChar ~
24342 \SpecialChar ~
24343  _foo_hob_1_1,a
24344 \layout Standard
24345
24346 Variations of this case however will 
24347 \emph on 
24348 not
24349 \emph default 
24350  be recognized.
24351  It is a standard C expression, so I heartily recommend this be the only
24352  way to get the highest order bit, (it is portable).
24353  Of course it will be recognized even if it is embedded in other expressions,
24354  e.g.:
24355 \layout Verse
24356
24357
24358 \family typewriter 
24359 xyz = gint + ((gint >> 15) & 1);
24360 \layout Standard
24361
24362 will still be recognized.
24363 \layout Subsection
24364
24365 Peephole Optimizer
24366 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
24367
24368 \end_inset 
24369
24370
24371 \begin_inset LatexCommand \index{Peephole optimizer}
24372
24373 \end_inset 
24374
24375
24376 \layout Standard
24377
24378 The compiler uses a rule based, pattern matching and re-writing mechanism
24379  for peep-hole optimization.
24380  It is inspired by 
24381 \emph on 
24382 copt
24383 \emph default 
24384  a peep-hole optimizer by Christopher W.
24385  Fraser (cwfraser\SpecialChar ~
24386 @\SpecialChar ~
24387 microsoft.com).
24388  A default set of rules are compiled into the compiler, additional rules
24389  may be added with the 
24390 \emph on 
24391 -
24392 \begin_inset ERT
24393 status Collapsed
24394
24395 \layout Standard
24396
24397 \backslash 
24398 /
24399 \end_inset 
24400
24401 -peep-file
24402 \begin_inset LatexCommand \index{-\/-peep-file}
24403
24404 \end_inset 
24405
24406  <filename>
24407 \emph default 
24408  option.
24409  The rule language is best illustrated with examples.
24410 \layout Verse
24411
24412
24413 \family typewriter 
24414 replace { 
24415 \newline 
24416 \SpecialChar ~
24417 \SpecialChar ~
24418 mov %1,a 
24419 \newline 
24420 \SpecialChar ~
24421 \SpecialChar ~
24422 mov a,%1
24423 \newline 
24424 } by {
24425 \newline 
24426 \SpecialChar ~
24427 \SpecialChar ~
24428 mov %1,a
24429 \newline 
24430 }
24431 \layout Standard
24432
24433 The above rule will change the following assembly
24434 \begin_inset LatexCommand \index{Assembler routines}
24435
24436 \end_inset 
24437
24438  sequence:
24439 \layout Verse
24440
24441
24442 \family typewriter 
24443 mov r1,a 
24444 \newline 
24445 mov a,r1
24446 \layout Standard
24447
24448 to
24449 \layout Verse
24450
24451
24452 \family typewriter 
24453 mov r1,a
24454 \layout Standard
24455
24456 Note: All occurrences of a 
24457 \emph on 
24458 %n
24459 \emph default 
24460  (pattern variable) must denote the same string.
24461  With the above rule, the assembly sequence:
24462 \layout Verse
24463
24464
24465 \family typewriter 
24466 mov r1,a 
24467 \newline 
24468 mov a,r2
24469 \layout Standard
24470
24471 will remain unmodified.
24472 \newline 
24473
24474 \newline 
24475 Other special case optimizations may be added by the user (via 
24476 \emph on 
24477 -
24478 \begin_inset ERT
24479 status Collapsed
24480
24481 \layout Standard
24482
24483 \backslash 
24484 /
24485 \end_inset 
24486
24487 -peep-file option
24488 \emph default 
24489 ).
24490  E.g.
24491  some variants of the 8051 MCU
24492 \begin_inset LatexCommand \index{MCS51 variants}
24493
24494 \end_inset 
24495
24496  allow only 
24497 \family typewriter 
24498 ajmp
24499 \family default 
24500  and 
24501 \family typewriter 
24502 acall
24503 \family default 
24504 .
24505  The following two rules will change all 
24506 \family typewriter 
24507 ljmp
24508 \family default 
24509  and 
24510 \family typewriter 
24511 lcall
24512 \family default 
24513  to 
24514 \family typewriter 
24515 ajmp
24516 \family default 
24517  and 
24518 \family typewriter 
24519 acall
24520 \layout Verse
24521
24522
24523 \family typewriter 
24524 replace { lcall %1 } by { acall %1 } 
24525 \newline 
24526 replace { ljmp %1 } by { ajmp %1 }
24527 \layout Standard
24528
24529 The 
24530 \emph on 
24531 inline-assembler code
24532 \emph default 
24533  is also passed through the peep hole optimizer, thus the peephole optimizer
24534  can also be used as an assembly level macro expander.
24535  The rules themselves are MCU dependent whereas the rule language infra-structur
24536 e is MCU independent.
24537  Peephole optimization rules for other MCU can be easily programmed using
24538  the rule language.
24539 \newline 
24540
24541 \newline 
24542 The syntax for a rule is as follows:
24543 \layout Verse
24544
24545
24546 \family typewriter 
24547 rule := replace [ restart ] '{' <assembly sequence> '
24548 \backslash 
24549 n' 
24550 \newline 
24551 \SpecialChar ~
24552  \SpecialChar ~
24553  \SpecialChar ~
24554  \SpecialChar ~
24555  \SpecialChar ~
24556  \SpecialChar ~
24557  \SpecialChar ~
24558  \SpecialChar ~
24559  \SpecialChar ~
24560  \SpecialChar ~
24561  \SpecialChar ~
24562  \SpecialChar ~
24563  \SpecialChar ~
24564  \SpecialChar ~
24565  '}' by '{' '
24566 \backslash 
24567 n' 
24568 \newline 
24569 \SpecialChar ~
24570  \SpecialChar ~
24571  \SpecialChar ~
24572  \SpecialChar ~
24573  \SpecialChar ~
24574  \SpecialChar ~
24575  \SpecialChar ~
24576  \SpecialChar ~
24577  \SpecialChar ~
24578  \SpecialChar ~
24579  \SpecialChar ~
24580  \SpecialChar ~
24581  \SpecialChar ~
24582  \SpecialChar ~
24583  \SpecialChar ~
24584  \SpecialChar ~
24585  <assembly sequence> '
24586 \backslash 
24587 n' 
24588 \newline 
24589 \SpecialChar ~
24590  \SpecialChar ~
24591  \SpecialChar ~
24592  \SpecialChar ~
24593  \SpecialChar ~
24594  \SpecialChar ~
24595  \SpecialChar ~
24596  \SpecialChar ~
24597  \SpecialChar ~
24598  \SpecialChar ~
24599  \SpecialChar ~
24600  \SpecialChar ~
24601  \SpecialChar ~
24602  \SpecialChar ~
24603  '}' [if <functionName> ] '
24604 \backslash 
24605 n' 
24606 \layout Standard
24607
24608 <assembly sequence> := assembly instruction (each instruction including
24609  labels must be on a separate line).
24610 \newline 
24611
24612 \newline 
24613 The optimizer will apply to the rules one by one from the top in the sequence
24614  of their appearance, it will terminate when all rules are exhausted.
24615  If the 'restart' option is specified, then the optimizer will start matching
24616  the rules again from the top, this option for a rule is expensive (performance)
24617 , it is intended to be used in situations where a transformation will trigger
24618  the same rule again.
24619  An example of this (not a good one, it has side effects) is the following
24620  rule:
24621 \layout Verse
24622
24623
24624 \family typewriter 
24625 replace restart { 
24626 \newline 
24627 \SpecialChar ~
24628 \SpecialChar ~
24629 pop %1 
24630 \newline 
24631 \SpecialChar ~
24632 \SpecialChar ~
24633 push %1 } by { 
24634 \newline 
24635 \SpecialChar ~
24636 \SpecialChar ~
24637 ; nop 
24638 \newline 
24639 }
24640 \layout Standard
24641
24642 Note that the replace pattern cannot be a blank, but can be a comment line.
24643  Without the 'restart' option only the innermost 'pop' 'push' pair would
24644  be eliminated, i.e.:
24645 \layout Verse
24646
24647
24648 \family typewriter 
24649 pop ar1 
24650 \newline 
24651 pop ar2 
24652 \newline 
24653 push ar2 
24654 \newline 
24655 push ar1
24656 \layout Standard
24657
24658 would result in:
24659 \layout Verse
24660
24661
24662 \family typewriter 
24663 pop ar1 
24664 \newline 
24665 ; nop 
24666 \newline 
24667 push ar1
24668 \layout Standard
24669
24670
24671 \emph on 
24672 with
24673 \emph default 
24674  the restart option the rule will be applied again to the resulting code
24675  and then all the pop-push pairs will be eliminated to yield:
24676 \layout Verse
24677
24678
24679 \family typewriter 
24680 ; nop 
24681 \newline 
24682 ; nop
24683 \layout Standard
24684
24685 A conditional function can be attached to a rule.
24686  Attaching rules are somewhat more involved, let me illustrate this with
24687  an example.
24688 \layout Verse
24689
24690
24691 \family typewriter 
24692 replace { 
24693 \newline 
24694 \SpecialChar ~
24695  \SpecialChar ~
24696  \SpecialChar ~
24697 ljmp %5 
24698 \newline 
24699 %2:
24700 \newline 
24701 } by { 
24702 \newline 
24703 \SpecialChar ~
24704  \SpecialChar ~
24705  \SpecialChar ~
24706 sjmp %5 
24707 \newline 
24708 %2:
24709 \newline 
24710 } if labelInRange
24711 \layout Standard
24712
24713 The optimizer does a look-up of a function name table defined in function
24714  
24715 \emph on 
24716 callFuncByName
24717 \emph default 
24718  in the source file SDCCpeeph.c, with the name 
24719 \emph on 
24720 labelInRange
24721 \emph default 
24722 .
24723  If it finds a corresponding entry the function is called.
24724  Note there can be no parameters specified for these functions, in this
24725  case the use of 
24726 \emph on 
24727 %5
24728 \emph default 
24729  is crucial, since the function 
24730 \emph on 
24731 labelInRange
24732 \emph default 
24733  expects to find the label in that particular variable (the hash table containin
24734 g the variable bindings is passed as a parameter).
24735  If you want to code more such functions, take a close look at the function
24736  labelInRange and the calling mechanism in source file SDCCpeeph.c.
24737  Currently implemented are 
24738 \emph on 
24739 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
24740  24bitMode, portIsDS390, 24bitModeAndPortDS390 
24741 \emph default 
24742 and
24743 \emph on 
24744  notVolatile
24745 \emph default 
24746 .
24747 \layout Standard
24748
24749 I know this whole thing is a little kludgey, but maybe some day we will
24750  have some better means.
24751  If you are looking at this file, you will see the default rules that are
24752  compiled into the compiler, you can add your own rules in the default set
24753  there if you get tired of specifying the -
24754 \begin_inset ERT
24755 status Collapsed
24756
24757 \layout Standard
24758
24759 \backslash 
24760 /
24761 \end_inset 
24762
24763 -peep-file option.
24764 \layout Section
24765
24766 ANSI-Compliance
24767 \begin_inset LatexCommand \index{ANSI-compliance}
24768
24769 \end_inset 
24770
24771
24772 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
24773
24774 \end_inset 
24775
24776
24777 \layout Standard
24778
24779 Deviations from the compliance:
24780 \layout Itemize
24781
24782 functions are not reentrant
24783 \begin_inset LatexCommand \index{reentrant}
24784
24785 \end_inset 
24786
24787  unless explicitly declared as such or the 
24788 \series bold 
24789 -
24790 \begin_inset ERT
24791 status Collapsed
24792
24793 \layout Standard
24794
24795 \backslash 
24796 /
24797 \end_inset 
24798
24799 -stack-auto
24800 \begin_inset LatexCommand \index{-\/-stack-auto}
24801
24802 \end_inset 
24803
24804
24805 \series default 
24806  command line option is specified.
24807 \layout Itemize
24808
24809 structures and unions cannot be assigned values directly, cannot be passed
24810  as function parameters or assigned to each other and cannot be a return
24811  value from a function, e.g.:
24812 \begin_deeper 
24813 \layout Verse
24814
24815
24816 \family typewriter 
24817 struct s { ...
24818  }; 
24819 \newline 
24820 struct s s1, s2; 
24821 \newline 
24822 foo() 
24823 \newline 
24824
24825 \newline 
24826 \SpecialChar ~
24827 \SpecialChar ~
24828 \SpecialChar ~
24829 \SpecialChar ~
24830 ...
24831  
24832 \newline 
24833 \SpecialChar ~
24834 \SpecialChar ~
24835 \SpecialChar ~
24836 \SpecialChar ~
24837 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
24838 \newline 
24839 \SpecialChar ~
24840 \SpecialChar ~
24841 \SpecialChar ~
24842 \SpecialChar ~
24843 ...
24844  
24845 \newline 
24846 }
24847 \newline 
24848 struct s foo1 (struct s parms) /* invalid in SDCC although allowed in ANSI
24849  */
24850 \newline 
24851
24852 \newline 
24853 \SpecialChar ~
24854 \SpecialChar ~
24855 \SpecialChar ~
24856 \SpecialChar ~
24857 struct s rets; 
24858 \newline 
24859 \SpecialChar ~
24860 \SpecialChar ~
24861 \SpecialChar ~
24862 \SpecialChar ~
24863 ...
24864  
24865 \newline 
24866 \SpecialChar ~
24867 \SpecialChar ~
24868 \SpecialChar ~
24869 \SpecialChar ~
24870 return rets;/* is invalid in SDCC although allowed in ANSI */ 
24871 \newline 
24872 }
24873 \end_deeper 
24874 \layout Itemize
24875
24876 'long long
24877 \begin_inset LatexCommand \index{long long (not supported)}
24878
24879 \end_inset 
24880
24881 ' (64 bit integers
24882 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
24883
24884 \end_inset 
24885
24886 ) not supported.
24887 \layout Itemize
24888
24889 'double
24890 \begin_inset LatexCommand \index{double (not supported)}
24891
24892 \end_inset 
24893
24894 ' precision floating point 
24895 \begin_inset LatexCommand \index{Floating point support}
24896
24897 \end_inset 
24898
24899 not supported.
24900 \layout Itemize
24901
24902 No support for setjmp
24903 \begin_inset LatexCommand \index{setjmp (not supported)}
24904
24905 \end_inset 
24906
24907  and longjmp
24908 \begin_inset LatexCommand \index{longjmp (not supported)}
24909
24910 \end_inset 
24911
24912  (for now).
24913 \layout Itemize
24914
24915 Old K&R style
24916 \begin_inset LatexCommand \index{K\&R style}
24917
24918 \end_inset 
24919
24920  function declarations are NOT allowed.
24921 \begin_deeper 
24922 \layout Verse
24923
24924
24925 \family typewriter 
24926 foo(i,j) /* this old style of function declarations */ 
24927 \newline 
24928 int i,j; /* are valid in ANSI but not valid in SDCC */ 
24929 \newline 
24930
24931 \newline 
24932 \SpecialChar ~
24933 \SpecialChar ~
24934 \SpecialChar ~
24935 \SpecialChar ~
24936 ...
24937  
24938 \newline 
24939 }
24940 \end_deeper 
24941 \layout Itemize
24942
24943 Certain words that are valid identifiers in the standard may be reserved
24944  words in SDCC unless the 
24945 \series bold 
24946 -
24947 \begin_inset ERT
24948 status Collapsed
24949
24950 \layout Standard
24951
24952 \backslash 
24953 /
24954 \end_inset 
24955
24956 -std-c89
24957 \begin_inset LatexCommand \index{-\/-std-c89}
24958
24959 \end_inset 
24960
24961  or -
24962 \begin_inset ERT
24963 status Collapsed
24964
24965 \layout Standard
24966
24967 \backslash 
24968 /
24969 \end_inset 
24970
24971 -std-c99
24972 \begin_inset LatexCommand \index{-\/-std-c99}
24973
24974 \end_inset 
24975
24976
24977 \series default 
24978  command line options are used.
24979  These may include (depending on the selected processor): 'at', 'banked',
24980  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
24981 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
24982  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
24983  '_naked'.
24984  Compliant equivalents of these keywords are always available in a form
24985  that begin with two underscores
24986 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
24987
24988 \end_inset 
24989
24990 , f.e.
24991  '__data' instead of 'data'.
24992 \layout Section
24993
24994 Cyclomatic Complexity
24995 \begin_inset LatexCommand \index{Cyclomatic complexity}
24996
24997 \end_inset 
24998
24999
25000 \layout Standard
25001
25002 Cyclomatic complexity of a function is defined as the number of independent
25003  paths the program can take during execution of the function.
25004  This is an important number since it defines the number test cases you
25005  have to generate to validate the function.
25006  The accepted industry standard for complexity number is 10, if the cyclomatic
25007  complexity reported by SDCC exceeds 10 you should think about simplification
25008  of the function logic.
25009  Note that the complexity level is not related to the number of lines of
25010  code in a function.
25011  Large functions can have low complexity, and small functions can have large
25012  complexity levels.
25013  
25014 \newline 
25015
25016 \newline 
25017 SDCC uses the following formula to compute the complexity:
25018 \newline 
25019
25020 \layout Standard
25021
25022 complexity = (number of edges in control flow graph) - (number of nodes
25023  in control flow graph) + 2;
25024 \newline 
25025
25026 \newline 
25027 Having said that the industry standard is 10, you should be aware that in
25028  some cases it be may unavoidable to have a complexity level of less than
25029  10.
25030  For example if you have switch statement with more than 10 case labels,
25031  each case label adds one to the complexity level.
25032  The complexity level is by no means an absolute measure of the algorithmic
25033  complexity of the function, it does however provide a good starting point
25034  for which functions you might look at for further optimization.
25035 \layout Section
25036
25037 Retargetting for other Processors
25038 \layout Standard
25039
25040 The issues for retargetting the compiler are far too numerous to be covered
25041  by this document.
25042  What follows is a brief description of each of the seven phases of the
25043  compiler and its MCU dependency.
25044 \layout Itemize
25045
25046 Parsing the source and building the annotated parse tree.
25047  This phase is largely MCU independent (except for the language extensions).
25048  Syntax & semantic checks are also done in this phase, along with some initial
25049  optimizations like back patching labels and the pattern matching optimizations
25050  like bit-rotation etc.
25051 \layout Itemize
25052
25053 The second phase involves generating an intermediate code which can be easy
25054  manipulated during the later phases.
25055  This phase is entirely MCU independent.
25056  The intermediate code generation assumes the target machine has unlimited
25057  number of registers, and designates them with the name iTemp.
25058  The compiler can be made to dump a human readable form of the code generated
25059  by using the -
25060 \begin_inset ERT
25061 status Collapsed
25062
25063 \layout Standard
25064
25065 \backslash 
25066 /
25067 \end_inset 
25068
25069 -dumpraw option.
25070 \layout Itemize
25071
25072 This phase does the bulk of the standard optimizations and is also MCU independe
25073 nt.
25074  This phase can be broken down into several sub-phases:
25075 \newline 
25076
25077 \newline 
25078 Break down intermediate code (iCode) into basic blocks.
25079 \newline 
25080 Do control flow & data flow analysis on the basic blocks.
25081 \newline 
25082 Do local common subexpression elimination, then global subexpression elimination
25083 \newline 
25084 Dead code elimination
25085 \newline 
25086 Loop optimizations
25087 \newline 
25088 If loop optimizations caused any changes then do 'global subexpression eliminati
25089 on' and 'dead code elimination' again.
25090 \layout Itemize
25091
25092 This phase determines the live-ranges; by live range I mean those iTemp
25093  variables defined by the compiler that still survive after all the optimization
25094 s.
25095  Live range analysis
25096 \begin_inset LatexCommand \index{Live range analysis}
25097
25098 \end_inset 
25099
25100  is essential for register allocation, since these computation determines
25101  which of these iTemps will be assigned to registers, and for how long.
25102 \layout Itemize
25103
25104 Phase five is register allocation.
25105  There are two parts to this process.
25106 \newline 
25107
25108 \newline 
25109 The first part I call 'register packing' (for lack of a better term).
25110  In this case several MCU specific expression folding is done to reduce
25111  register pressure.
25112 \newline 
25113
25114 \newline 
25115 The second part is more MCU independent and deals with allocating registers
25116  to the remaining live ranges.
25117  A lot of MCU specific code does creep into this phase because of the limited
25118  number of index registers available in the 8051.
25119 \layout Itemize
25120
25121 The Code generation phase is (unhappily), entirely MCU dependent and very
25122  little (if any at all) of this code can be reused for other MCU.
25123  However the scheme for allocating a homogenized assembler operand for each
25124  iCode operand may be reused.
25125 \layout Itemize
25126
25127 As mentioned in the optimization section the peep-hole optimizer is rule
25128  based system, which can reprogrammed for other MCUs.
25129 \layout Chapter
25130
25131 Compiler internals
25132 \begin_inset LatexCommand \index{Compiler internals}
25133
25134 \end_inset 
25135
25136
25137 \layout Section
25138
25139 The anatomy of the compiler
25140 \begin_inset LatexCommand \label{sub:The-anatomy-of}
25141
25142 \end_inset 
25143
25144
25145 \layout Standard
25146
25147
25148 \shape italic 
25149 This is an excerpt from an article published in Circuit Cellar Magazine
25150  in 
25151 \series bold 
25152 August 2000
25153 \series default 
25154 .
25155  It's a little outdated (the compiler is much more efficient now and user/develo
25156 per friendly), but pretty well exposes the guts of it all.
25157 \shape default 
25158
25159 \newline 
25160
25161 \newline 
25162 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
25163  It is fairly easy to retarget for other 8-bit MCU.
25164  Here we take a look at some of the internals of the compiler.
25165  
25166 \layout Paragraph*
25167
25168 Parsing
25169 \begin_inset LatexCommand \index{Parsing}
25170
25171 \end_inset 
25172
25173  
25174 \layout Standard
25175
25176 Parsing the input source file and creating an AST (Annotated Syntax Tree
25177 \begin_inset LatexCommand \index{Annotated syntax tree}
25178
25179 \end_inset 
25180
25181 ).
25182  This phase also involves propagating types (annotating each node of the
25183  parse tree with type information) and semantic analysis.
25184  There are some MCU specific parsing rules.
25185  For example the storage classes, the extended storage classes are MCU specific
25186  while there may be a xdata storage class for 8051 there is no such storage
25187  class for z80 or Atmel AVR.
25188  SDCC allows MCU specific storage class extensions, i.e.
25189  xdata will be treated as a storage class specifier when parsing 8051 C
25190  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
25191  C code.
25192 \layout Paragraph*
25193
25194 Generating iCode
25195 \begin_inset LatexCommand \index{iCode}
25196
25197 \end_inset 
25198
25199
25200 \layout Standard
25201
25202 Intermediate code generation.
25203  In this phase the AST is broken down into three-operand form (iCode).
25204  These three operand forms are represented as doubly linked lists.
25205  ICode is the term given to the intermediate form generated by the compiler.
25206  ICode example section shows some examples of iCode generated for some simple
25207  C source functions.
25208 \layout Paragraph*
25209
25210 Optimizations
25211 \begin_inset LatexCommand \index{Optimizations}
25212
25213 \end_inset 
25214
25215 .
25216 \layout Standard
25217
25218 Bulk of the target independent optimizations is performed in this phase.
25219  The optimizations include constant propagation, common sub-expression eliminati
25220 on, loop invariant code movement, strength reduction of loop induction variables
25221  and dead-code elimination.
25222 \layout Paragraph*
25223
25224 Live range analysis
25225 \begin_inset LatexCommand \index{Live range analysis}
25226
25227 \end_inset 
25228
25229
25230 \layout Standard
25231
25232 During intermediate code generation phase, the compiler assumes the target
25233  machine has infinite number of registers and generates a lot of temporary
25234  variables.
25235  The live range computation determines the lifetime of each of these compiler-ge
25236 nerated temporaries.
25237  A picture speaks a thousand words.
25238  ICode example sections show the live range annotations for each of the
25239  operand.
25240  It is important to note here, each iCode is assigned a number in the order
25241  of its execution in the function.
25242  The live ranges are computed in terms of these numbers.
25243  The from number is the number of the iCode which first defines the operand
25244  and the to number signifies the iCode which uses this operand last.
25245 \layout Paragraph*
25246
25247 Register Allocation
25248 \begin_inset LatexCommand \index{Register allocation}
25249
25250 \end_inset 
25251
25252
25253 \layout Standard
25254
25255 The register allocation determines the type and number of registers needed
25256  by each operand.
25257  In most MCUs only a few registers can be used for indirect addressing.
25258  In case of 8051 for example the registers R0 & R1 can be used to indirectly
25259  address the internal ram and DPTR to indirectly address the external ram.
25260  The compiler will try to allocate the appropriate register to pointer variables
25261  if it can.
25262  ICode example section shows the operands annotated with the registers assigned
25263  to them.
25264  The compiler will try to keep operands in registers as much as possible;
25265  there are several schemes the compiler uses to do achieve this.
25266  When the compiler runs out of registers the compiler will check to see
25267  if there are any live operands which is not used or defined in the current
25268  basic block being processed, if there are any found then it will push that
25269  operand and use the registers in this block, the operand will then be popped
25270  at the end of the basic block.
25271  
25272 \layout Standard
25273
25274 There are other MCU specific considerations in this phase.
25275  Some MCUs have an accumulator; very short-lived operands could be assigned
25276  to the accumulator instead of a general-purpose register.
25277 \layout Paragraph*
25278
25279 Code generation
25280 \layout Standard
25281
25282 Figure II gives a table of iCode operations supported by the compiler.
25283  The code generation involves translating these operations into corresponding
25284  assembly code for the processor.
25285  This sounds overly simple but that is the essence of code generation.
25286  Some of the iCode operations are generated on a MCU specific manner for
25287  example, the z80 port does not use registers to pass parameters so the
25288  SEND and RECV iCode operations will not be generated, and it also does
25289  not support JUMPTABLES.
25290  
25291 \newline 
25292
25293 \series bold 
25294 \shape italic 
25295 \color red
25296 <Where is Figure II?>
25297 \layout Comment
25298
25299 In the original article Figure II was announced to be downloadable on 
25300 \shape italic 
25301 Circuit Cellar
25302 \shape default 
25303 's web site.
25304  Unfortunately it never seemed to have shown up there, so: where is Figure
25305  II?
25306 \layout Paragraph*
25307
25308 ICode Example
25309 \begin_inset LatexCommand \index{iCode}
25310
25311 \end_inset 
25312
25313
25314 \layout Standard
25315
25316 This section shows some details of iCode.
25317  The example C code does not do anything useful; it is used as an example
25318  to illustrate the intermediate code generated by the compiler.
25319 \layout Verse
25320
25321
25322 \family typewriter 
25323 1.\SpecialChar ~
25324 xdata int * p;
25325 \newline 
25326 2.\SpecialChar ~
25327 int gint;
25328 \newline 
25329 3.\SpecialChar ~
25330 /* This function does nothing useful.
25331  It is used
25332 \newline 
25333 4.\SpecialChar ~
25334 \SpecialChar ~
25335 \SpecialChar ~
25336 \SpecialChar ~
25337 for the purpose of explaining iCode */
25338 \newline 
25339 5.\SpecialChar ~
25340 short function (data int *x)
25341 \newline 
25342 6.\SpecialChar ~
25343 {
25344 \newline 
25345 7.\SpecialChar ~
25346 \SpecialChar ~
25347 \SpecialChar ~
25348 short i=10; \SpecialChar ~
25349 \SpecialChar ~
25350 /* dead initialization eliminated */
25351 \newline 
25352 8.\SpecialChar ~
25353 \SpecialChar ~
25354 \SpecialChar ~
25355 short sum=10; /* dead initialization eliminated */
25356 \newline 
25357 9.\SpecialChar ~
25358 \SpecialChar ~
25359 \SpecialChar ~
25360 short mul;
25361 \newline 
25362 10.\SpecialChar ~
25363 \SpecialChar ~
25364 int j ;
25365 \newline 
25366 11.\SpecialChar ~
25367 \SpecialChar ~
25368 while (*x) *x++ = *p++; 
25369 \newline 
25370 12.\SpecialChar ~
25371 \SpecialChar ~
25372 \SpecialChar ~
25373 \SpecialChar ~
25374 sum = 0 ; 
25375 \newline 
25376 13.\SpecialChar ~
25377 \SpecialChar ~
25378 mul = 0;
25379 \newline 
25380 14.\SpecialChar ~
25381 \SpecialChar ~
25382 /* compiler detects i,j to be induction variables */
25383 \newline 
25384 15.\SpecialChar ~
25385 \SpecialChar ~
25386 for (i = 0, j = 10 ; i < 10 ; i++, j
25387 \family default 
25388 -
25389 \begin_inset ERT
25390 status Collapsed
25391
25392 \layout Standard
25393
25394 \backslash 
25395 /
25396 \end_inset 
25397
25398 -
25399 \family typewriter 
25400 ) {
25401 \newline 
25402 16.\SpecialChar ~
25403 \SpecialChar ~
25404 \SpecialChar ~
25405 \SpecialChar ~
25406 sum += i;
25407 \newline 
25408 17.\SpecialChar ~
25409 \SpecialChar ~
25410 \SpecialChar ~
25411 \SpecialChar ~
25412 mul += i * 3; \SpecialChar ~
25413 \SpecialChar ~
25414 /* this multiplication remains */
25415 \newline 
25416 18.\SpecialChar ~
25417 \SpecialChar ~
25418 \SpecialChar ~
25419 \SpecialChar ~
25420 gint += j * 3;\SpecialChar ~
25421 \SpecialChar ~
25422 /* this multiplication changed to addition */
25423 \newline 
25424 19.\SpecialChar ~
25425 \SpecialChar ~
25426 }
25427 \newline 
25428 20.\SpecialChar ~
25429 \SpecialChar ~
25430 return sum+mul;
25431 \newline 
25432 21.\SpecialChar ~
25433 }
25434 \layout Standard
25435
25436 In addition to the operands each iCode contains information about the filename
25437  and line it corresponds to in the source file.
25438  The first field in the listing should be interpreted as follows:
25439 \newline 
25440
25441 \shape italic 
25442 \size footnotesize 
25443 Filename(linenumber: iCode Execution sequence number : ICode hash table
25444  key : loop depth of the iCode).
25445 \shape default 
25446 \size default 
25447
25448 \newline 
25449 Then follows the human readable form of the ICode operation.
25450  Each operand of this triplet form can be of three basic types a) compiler
25451  generated temporary b) user defined variable c) a constant value.
25452  Note that local variables and parameters are replaced by compiler generated
25453  temporaries.
25454  Live ranges
25455 \begin_inset LatexCommand \index{Live range analysis}
25456
25457 \end_inset 
25458
25459  are computed only for temporaries (i.e.
25460  live ranges are not computed for global variables).
25461  Registers
25462 \begin_inset LatexCommand \index{Register allocation}
25463
25464 \end_inset 
25465
25466  are allocated for temporaries only.
25467  Operands are formatted in the following manner:
25468 \newline 
25469
25470 \shape italic 
25471 \size footnotesize 
25472 Operand Name [lr live-from : live-to ] { type information } [ registers
25473  allocated ].
25474 \shape default 
25475 \size default 
25476
25477 \newline 
25478 As mentioned earlier the live ranges are computed in terms of the execution
25479  sequence number of the iCodes, for example 
25480 \newline 
25481 the iTemp0 is live from (i.e.
25482  first defined in iCode with execution sequence number 3, and is last used
25483  in the iCode with sequence number 5).
25484  For induction variables such as iTemp21 the live range computation extends
25485  the lifetime from the start to the end of the loop.
25486 \newline 
25487 The register allocator used the live range information to allocate registers,
25488  the same registers may be used for different temporaries if their live
25489  ranges do not overlap, for example r0 is allocated to both iTemp6 and to
25490  iTemp17 since their live ranges do not overlap.
25491  In addition the allocator also takes into consideration the type and usage
25492  of a temporary, for example itemp6 is a pointer to near space and is used
25493  as to fetch data from (i.e.
25494  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
25495  Some short lived temporaries are allocated to special registers which have
25496  meaning to the code generator e.g.
25497  iTemp13 is allocated to a pseudo register CC which tells the back end that
25498  the temporary is used only for a conditional jump the code generation makes
25499  use of this information to optimize a compare and jump ICode.
25500 \newline 
25501 There are several loop optimizations
25502 \begin_inset LatexCommand \index{Loop optimization}
25503
25504 \end_inset 
25505
25506  performed by the compiler.
25507  It can detect induction variables iTemp21(i) and iTemp23(j).
25508  Also note the compiler does selective strength reduction
25509 \begin_inset LatexCommand \index{Strength reduction}
25510
25511 \end_inset 
25512
25513 , i.e.
25514  the multiplication of an induction variable in line 18 (gint = j * 3) is
25515  changed to addition, a new temporary iTemp17 is allocated and assigned
25516  a initial value, a constant 3 is then added for each iteration of the loop.
25517  The compiler does not change the multiplication
25518 \begin_inset LatexCommand \index{Multiplication}
25519
25520 \end_inset 
25521
25522  in line 17 however since the processor does support an 8 * 8 bit multiplication.
25523 \newline 
25524 Note the dead code elimination
25525 \begin_inset LatexCommand \index{Dead-code elimination}
25526
25527 \end_inset 
25528
25529  optimization eliminated the dead assignments in line 7 & 8 to I and sum
25530  respectively.
25531 \newline 
25532
25533 \layout Standard
25534
25535
25536 \size footnotesize 
25537 Sample.c (5:1:0:0) _entry($9) :
25538 \layout Standard
25539
25540
25541 \size footnotesize 
25542 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
25543 \layout Standard
25544
25545
25546 \size footnotesize 
25547 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
25548 \layout Standard
25549
25550
25551 \size footnotesize 
25552 Sample.c(11:4:53:0) preHeaderLbl0($11) :
25553 \layout Standard
25554
25555
25556 \size footnotesize 
25557 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
25558  * int}[r2]
25559 \layout Standard
25560
25561
25562 \size footnotesize 
25563 Sample.c(11:6:5:1) _whilecontinue_0($1) :
25564 \layout Standard
25565
25566
25567 \size footnotesize 
25568 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
25569  int}[r0]]
25570 \layout Standard
25571
25572
25573 \size footnotesize 
25574 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
25575 \layout Standard
25576
25577
25578 \size footnotesize 
25579 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
25580  * int}
25581 \layout Standard
25582
25583
25584 \size footnotesize 
25585 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
25586  {short}
25587 \layout Standard
25588
25589
25590 \size footnotesize 
25591 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
25592  * int}[DPTR]]
25593 \layout Standard
25594
25595
25596 \size footnotesize 
25597 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
25598 }[r2 r3]
25599 \layout Standard
25600
25601
25602 \size footnotesize 
25603 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
25604  * int}[r0] + 0x2 {short}
25605 \layout Standard
25606
25607
25608 \size footnotesize 
25609 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
25610 \layout Standard
25611
25612
25613 \size footnotesize 
25614 Sample.c(11:17:21:0)_whilebreak_0($3) :
25615 \layout Standard
25616
25617
25618 \size footnotesize 
25619 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
25620 \layout Standard
25621
25622
25623 \size footnotesize 
25624 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
25625 \layout Standard
25626
25627
25628 \size footnotesize 
25629 Sample.c(15:20:54:0)preHeaderLbl1($13) :
25630 \layout Standard
25631
25632
25633 \size footnotesize 
25634 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
25635 \layout Standard
25636
25637
25638 \size footnotesize 
25639 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
25640 \layout Standard
25641
25642
25643 \size footnotesize 
25644 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
25645 \layout Standard
25646
25647
25648 \size footnotesize 
25649 Sample.c(15:24:26:1)_forcond_0($4) :
25650 \layout Standard
25651
25652
25653 \size footnotesize 
25654 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
25655  < 0xa {short}
25656 \layout Standard
25657
25658
25659 \size footnotesize 
25660 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
25661 \layout Standard
25662
25663
25664 \size footnotesize 
25665 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
25666  + ITemp21 [lr21:38]{short}[r4]
25667 \layout Standard
25668
25669
25670 \size footnotesize 
25671 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
25672  * 0x3 {short}
25673 \layout Standard
25674
25675
25676 \size footnotesize 
25677 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
25678  + iTemp15 [lr29:30]{short}[r1]
25679 \layout Standard
25680
25681
25682 \size footnotesize 
25683 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
25684  r0]- 0x3 {short}
25685 \layout Standard
25686
25687
25688 \size footnotesize 
25689 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
25690 int}[r7 r0]
25691 \layout Standard
25692
25693
25694 \size footnotesize 
25695 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
25696  + 0x1 {short}
25697 \layout Standard
25698
25699
25700 \size footnotesize 
25701 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
25702  r6]- 0x1 {short}
25703 \layout Standard
25704
25705
25706 \size footnotesize 
25707 Sample.c(19:38:47:1) goto _forcond_0($4)
25708 \layout Standard
25709
25710
25711 \size footnotesize 
25712 Sample.c(19:39:48:0)_forbreak_0($7) :
25713 \layout Standard
25714
25715
25716 \size footnotesize 
25717 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
25718  + ITemp11 [lr19:40]{short}[r3]
25719 \layout Standard
25720
25721
25722 \size footnotesize 
25723 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
25724 \layout Standard
25725
25726
25727 \size footnotesize 
25728 Sample.c(20:42:51:0)_return($8) :
25729 \layout Standard
25730
25731
25732 \size footnotesize 
25733 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
25734 \size default 
25735
25736 \newline 
25737
25738 \newline 
25739 Finally the code generated for this function:
25740 \newline 
25741
25742 \layout Standard
25743
25744
25745 \size footnotesize 
25746 .area DSEG (DATA)
25747 \layout Standard
25748
25749
25750 \size footnotesize 
25751 _p::
25752 \layout Standard
25753
25754
25755 \size footnotesize 
25756 \SpecialChar ~
25757 \SpecialChar ~
25758 .ds 2
25759 \layout Standard
25760
25761
25762 \size footnotesize 
25763 _gint::
25764 \layout Standard
25765
25766
25767 \size footnotesize 
25768 \SpecialChar ~
25769 \SpecialChar ~
25770 .ds 2
25771 \layout Standard
25772
25773
25774 \size footnotesize 
25775 ; sample.c 5
25776 \layout Standard
25777
25778
25779 \size footnotesize 
25780 ; ----------------------------------------------
25781 \layout Standard
25782
25783
25784 \size footnotesize 
25785 ; function function
25786 \layout Standard
25787
25788
25789 \size footnotesize 
25790 ; ----------------------------------------------
25791 \layout Standard
25792
25793
25794 \size footnotesize 
25795 _function:
25796 \layout Standard
25797
25798
25799 \size footnotesize 
25800 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
25801 \layout Standard
25802
25803
25804 \size footnotesize 
25805 \SpecialChar ~
25806 \SpecialChar ~
25807 mov r2,dpl
25808 \layout Standard
25809
25810
25811 \size footnotesize 
25812 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
25813 \layout Standard
25814
25815
25816 \size footnotesize 
25817 \SpecialChar ~
25818 \SpecialChar ~
25819 mov ar0,r2
25820 \layout Standard
25821
25822
25823 \size footnotesize 
25824 ;_whilecontinue_0($1) :
25825 \layout Standard
25826
25827
25828 \size footnotesize 
25829 00101$:
25830 \layout Standard
25831
25832
25833 \size footnotesize 
25834 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
25835 \layout Standard
25836
25837
25838 \size footnotesize 
25839 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
25840 \layout Standard
25841
25842
25843 \size footnotesize 
25844 \SpecialChar ~
25845 \SpecialChar ~
25846 mov ar2,@r0
25847 \layout Standard
25848
25849
25850 \size footnotesize 
25851 \SpecialChar ~
25852 \SpecialChar ~
25853 inc r0
25854 \layout Standard
25855
25856
25857 \size footnotesize 
25858 \SpecialChar ~
25859 \SpecialChar ~
25860 mov ar3,@r0
25861 \layout Standard
25862
25863
25864 \size footnotesize 
25865 \SpecialChar ~
25866 \SpecialChar ~
25867 dec r0
25868 \layout Standard
25869
25870
25871 \size footnotesize 
25872 \SpecialChar ~
25873 \SpecialChar ~
25874 mov a,r2
25875 \layout Standard
25876
25877
25878 \size footnotesize 
25879 \SpecialChar ~
25880 \SpecialChar ~
25881 orl a,r3
25882 \layout Standard
25883
25884
25885 \size footnotesize 
25886 \SpecialChar ~
25887 \SpecialChar ~
25888 jz 00103$
25889 \layout Standard
25890
25891
25892 \size footnotesize 
25893 00114$:
25894 \layout Standard
25895
25896
25897 \size footnotesize 
25898 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
25899 \layout Standard
25900
25901
25902 \size footnotesize 
25903 \SpecialChar ~
25904 \SpecialChar ~
25905 mov dpl,_p
25906 \layout Standard
25907
25908
25909 \size footnotesize 
25910 \SpecialChar ~
25911 \SpecialChar ~
25912 mov dph,(_p + 1)
25913 \layout Standard
25914
25915
25916 \size footnotesize 
25917 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
25918 \layout Standard
25919
25920
25921 \size footnotesize 
25922 \SpecialChar ~
25923 \SpecialChar ~
25924 mov a,#0x02
25925 \layout Standard
25926
25927
25928 \size footnotesize 
25929 \SpecialChar ~
25930 \SpecialChar ~
25931 add a,_p
25932 \layout Standard
25933
25934
25935 \size footnotesize 
25936 \SpecialChar ~
25937 \SpecialChar ~
25938 mov _p,a
25939 \layout Standard
25940
25941
25942 \size footnotesize 
25943 \SpecialChar ~
25944 \SpecialChar ~
25945 clr a
25946 \layout Standard
25947
25948
25949 \size footnotesize 
25950 \SpecialChar ~
25951 \SpecialChar ~
25952 addc a,(_p + 1)
25953 \layout Standard
25954
25955
25956 \size footnotesize 
25957 \SpecialChar ~
25958 \SpecialChar ~
25959 mov (_p + 1),a
25960 \layout Standard
25961
25962
25963 \size footnotesize 
25964 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
25965 \layout Standard
25966
25967
25968 \size footnotesize 
25969 \SpecialChar ~
25970 \SpecialChar ~
25971 movx a,@dptr
25972 \layout Standard
25973
25974
25975 \size footnotesize 
25976 \SpecialChar ~
25977 \SpecialChar ~
25978 mov r2,a
25979 \layout Standard
25980
25981
25982 \size footnotesize 
25983 \SpecialChar ~
25984 \SpecialChar ~
25985 inc dptr
25986 \layout Standard
25987
25988
25989 \size footnotesize 
25990 \SpecialChar ~
25991 \SpecialChar ~
25992 movx a,@dptr
25993 \layout Standard
25994
25995
25996 \size footnotesize 
25997 \SpecialChar ~
25998 \SpecialChar ~
25999 mov r3,a
26000 \layout Standard
26001
26002
26003 \size footnotesize 
26004 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
26005 \layout Standard
26006
26007
26008 \size footnotesize 
26009 \SpecialChar ~
26010 \SpecialChar ~
26011 mov @r0,ar2
26012 \layout Standard
26013
26014
26015 \size footnotesize 
26016 \SpecialChar ~
26017 \SpecialChar ~
26018 inc r0
26019 \layout Standard
26020
26021
26022 \size footnotesize 
26023 \SpecialChar ~
26024 \SpecialChar ~
26025 mov @r0,ar3
26026 \layout Standard
26027
26028
26029 \size footnotesize 
26030 ; iTemp6 [lr5:16]{_near * int}[r0] = 
26031 \layout Standard
26032
26033
26034 \size footnotesize 
26035 ; iTemp6 [lr5:16]{_near * int}[r0] + 
26036 \layout Standard
26037
26038
26039 \size footnotesize 
26040 ; 0x2 {short}
26041 \layout Standard
26042
26043
26044 \size footnotesize 
26045 \SpecialChar ~
26046 \SpecialChar ~
26047 inc r0
26048 \layout Standard
26049
26050
26051 \size footnotesize 
26052 ; goto _whilecontinue_0($1)
26053 \layout Standard
26054
26055
26056 \size footnotesize 
26057 \SpecialChar ~
26058 \SpecialChar ~
26059 sjmp 00101$
26060 \layout Standard
26061
26062
26063 \size footnotesize 
26064 ; _whilebreak_0($3) :
26065 \layout Standard
26066
26067
26068 \size footnotesize 
26069 00103$:
26070 \layout Standard
26071
26072
26073 \size footnotesize 
26074 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
26075 \layout Standard
26076
26077
26078 \size footnotesize 
26079 \SpecialChar ~
26080 \SpecialChar ~
26081 mov r2,#0x00
26082 \layout Standard
26083
26084
26085 \size footnotesize 
26086 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
26087 \layout Standard
26088
26089
26090 \size footnotesize 
26091 \SpecialChar ~
26092 \SpecialChar ~
26093 mov r3,#0x00
26094 \layout Standard
26095
26096
26097 \size footnotesize 
26098 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
26099 \layout Standard
26100
26101
26102 \size footnotesize 
26103 \SpecialChar ~
26104 \SpecialChar ~
26105 mov r4,#0x00
26106 \layout Standard
26107
26108
26109 \size footnotesize 
26110 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
26111 \layout Standard
26112
26113
26114 \size footnotesize 
26115 \SpecialChar ~
26116 \SpecialChar ~
26117 mov r5,#0x0A
26118 \layout Standard
26119
26120
26121 \size footnotesize 
26122 \SpecialChar ~
26123 \SpecialChar ~
26124 mov r6,#0x00
26125 \layout Standard
26126
26127
26128 \size footnotesize 
26129 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
26130 \layout Standard
26131
26132
26133 \size footnotesize 
26134 \SpecialChar ~
26135 \SpecialChar ~
26136 mov r7,#0x1E
26137 \layout Standard
26138
26139
26140 \size footnotesize 
26141 \SpecialChar ~
26142 \SpecialChar ~
26143 mov r0,#0x00
26144 \layout Standard
26145
26146
26147 \size footnotesize 
26148 ; _forcond_0($4) :
26149 \layout Standard
26150
26151
26152 \size footnotesize 
26153 00104$:
26154 \layout Standard
26155
26156
26157 \size footnotesize 
26158 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
26159 \layout Standard
26160
26161
26162 \size footnotesize 
26163 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
26164 \layout Standard
26165
26166
26167 \size footnotesize 
26168 \SpecialChar ~
26169 \SpecialChar ~
26170 clr c
26171 \layout Standard
26172
26173
26174 \size footnotesize 
26175 \SpecialChar ~
26176 \SpecialChar ~
26177 mov a,r4
26178 \layout Standard
26179
26180
26181 \size footnotesize 
26182 \SpecialChar ~
26183 \SpecialChar ~
26184 xrl a,#0x80
26185 \layout Standard
26186
26187
26188 \size footnotesize 
26189 \SpecialChar ~
26190 \SpecialChar ~
26191 subb a,#0x8a
26192 \layout Standard
26193
26194
26195 \size footnotesize 
26196 \SpecialChar ~
26197 \SpecialChar ~
26198 jnc 00107$
26199 \layout Standard
26200
26201
26202 \size footnotesize 
26203 00115$:
26204 \layout Standard
26205
26206
26207 \size footnotesize 
26208 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
26209 \layout Standard
26210
26211
26212 \size footnotesize 
26213 ; iTemp21 [lr21:38]{short}[r4]
26214 \layout Standard
26215
26216
26217 \size footnotesize 
26218 \SpecialChar ~
26219 \SpecialChar ~
26220 mov a,r4
26221 \layout Standard
26222
26223
26224 \size footnotesize 
26225 \SpecialChar ~
26226 \SpecialChar ~
26227 add a,r2
26228 \layout Standard
26229
26230
26231 \size footnotesize 
26232 \SpecialChar ~
26233 \SpecialChar ~
26234 mov r2,a
26235 \layout Standard
26236
26237
26238 \size footnotesize 
26239 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
26240 \layout Standard
26241
26242
26243 \size footnotesize 
26244 \SpecialChar ~
26245 \SpecialChar ~
26246 mov b,#0x03
26247 \layout Standard
26248
26249
26250 \size footnotesize 
26251 \SpecialChar ~
26252 \SpecialChar ~
26253 mov a,r4
26254 \layout Standard
26255
26256
26257 \size footnotesize 
26258 \SpecialChar ~
26259 \SpecialChar ~
26260 mul ab
26261 \layout Standard
26262
26263
26264 \size footnotesize 
26265 \SpecialChar ~
26266 \SpecialChar ~
26267 mov r1,a
26268 \layout Standard
26269
26270
26271 \size footnotesize 
26272 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
26273 \layout Standard
26274
26275
26276 \size footnotesize 
26277 ; iTemp15 [lr29:30]{short}[r1]
26278 \layout Standard
26279
26280
26281 \size footnotesize 
26282 \SpecialChar ~
26283 \SpecialChar ~
26284 add a,r3
26285 \layout Standard
26286
26287
26288 \size footnotesize 
26289 \SpecialChar ~
26290 \SpecialChar ~
26291 mov r3,a
26292 \layout Standard
26293
26294
26295 \size footnotesize 
26296 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
26297 \layout Standard
26298
26299
26300 \size footnotesize 
26301 \SpecialChar ~
26302 \SpecialChar ~
26303 mov a,r7
26304 \layout Standard
26305
26306
26307 \size footnotesize 
26308 \SpecialChar ~
26309 \SpecialChar ~
26310 add a,#0xfd
26311 \layout Standard
26312
26313
26314 \size footnotesize 
26315 \SpecialChar ~
26316 \SpecialChar ~
26317 mov r7,a
26318 \layout Standard
26319
26320
26321 \size footnotesize 
26322 \SpecialChar ~
26323 \SpecialChar ~
26324 mov a,r0
26325 \layout Standard
26326
26327
26328 \size footnotesize 
26329 \SpecialChar ~
26330 \SpecialChar ~
26331 addc a,#0xff
26332 \layout Standard
26333
26334
26335 \size footnotesize 
26336 \SpecialChar ~
26337 \SpecialChar ~
26338 mov r0,a
26339 \layout Standard
26340
26341
26342 \size footnotesize 
26343 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
26344 \layout Standard
26345
26346
26347 \size footnotesize 
26348 \SpecialChar ~
26349 \SpecialChar ~
26350 mov a,r7
26351 \layout Standard
26352
26353
26354 \size footnotesize 
26355 \SpecialChar ~
26356 \SpecialChar ~
26357 add a,_gint
26358 \layout Standard
26359
26360
26361 \size footnotesize 
26362 \SpecialChar ~
26363 \SpecialChar ~
26364 mov _gint,a
26365 \layout Standard
26366
26367
26368 \size footnotesize 
26369 \SpecialChar ~
26370 \SpecialChar ~
26371 mov a,r0
26372 \layout Standard
26373
26374
26375 \size footnotesize 
26376 \SpecialChar ~
26377 \SpecialChar ~
26378 addc a,(_gint + 1)
26379 \layout Standard
26380
26381
26382 \size footnotesize 
26383 \SpecialChar ~
26384 \SpecialChar ~
26385 mov (_gint + 1),a
26386 \layout Standard
26387
26388
26389 \size footnotesize 
26390 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
26391 \layout Standard
26392
26393
26394 \size footnotesize 
26395 \SpecialChar ~
26396 \SpecialChar ~
26397 inc r4
26398 \layout Standard
26399
26400
26401 \size footnotesize 
26402 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
26403 \layout Standard
26404
26405
26406 \size footnotesize 
26407 \SpecialChar ~
26408 \SpecialChar ~
26409 dec r5
26410 \layout Standard
26411
26412
26413 \size footnotesize 
26414 \SpecialChar ~
26415 \SpecialChar ~
26416 cjne r5,#0xff,00104$
26417 \layout Standard
26418
26419
26420 \size footnotesize 
26421 \SpecialChar ~
26422 \SpecialChar ~
26423 dec r6
26424 \layout Standard
26425
26426
26427 \size footnotesize 
26428 ; goto _forcond_0($4)
26429 \layout Standard
26430
26431
26432 \size footnotesize 
26433 \SpecialChar ~
26434 \SpecialChar ~
26435 sjmp 00104$
26436 \layout Standard
26437
26438
26439 \size footnotesize 
26440 ; _forbreak_0($7) :
26441 \layout Standard
26442
26443
26444 \size footnotesize 
26445 00107$:
26446 \layout Standard
26447
26448
26449 \size footnotesize 
26450 ; ret iTemp24 [lr40:41]{short}
26451 \layout Standard
26452
26453
26454 \size footnotesize 
26455 \SpecialChar ~
26456 \SpecialChar ~
26457 mov a,r3
26458 \layout Standard
26459
26460
26461 \size footnotesize 
26462 \SpecialChar ~
26463 \SpecialChar ~
26464 add a,r2
26465 \layout Standard
26466
26467
26468 \size footnotesize 
26469 \SpecialChar ~
26470 \SpecialChar ~
26471 mov dpl,a
26472 \layout Standard
26473
26474
26475 \size footnotesize 
26476 ; _return($8) :
26477 \layout Standard
26478
26479
26480 \size footnotesize 
26481 00108$:
26482 \layout Standard
26483
26484
26485 \size footnotesize 
26486 \SpecialChar ~
26487 \SpecialChar ~
26488 ret
26489 \newline 
26490
26491 \layout Section
26492
26493 A few words about basic block successors, predecessors and dominators
26494 \layout Standard
26495
26496 Successors are basic blocks
26497 \begin_inset LatexCommand \index{Basic blocks}
26498
26499 \end_inset 
26500
26501  that might execute after this basic block.
26502 \newline 
26503 Predecessors are basic blocks that might execute before reaching this basic
26504  block.
26505 \newline 
26506 Dominators are basic blocks that WILL execute before reaching this basic
26507  block.
26508 \newline 
26509
26510 \layout Standard
26511
26512 [basic block 1]
26513 \layout Standard
26514
26515 if (something)
26516 \layout Standard
26517
26518 \SpecialChar ~
26519 \SpecialChar ~
26520 \SpecialChar ~
26521 \SpecialChar ~
26522 [basic block 2]
26523 \layout Standard
26524
26525 else
26526 \layout Standard
26527
26528 \SpecialChar ~
26529 \SpecialChar ~
26530 \SpecialChar ~
26531 \SpecialChar ~
26532 [basic block 3]
26533 \layout Standard
26534
26535 [basic block 4]
26536 \newline 
26537
26538 \layout Standard
26539
26540 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
26541 \layout Standard
26542
26543 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
26544 \layout Standard
26545
26546 c) domVect of [BB4] = BB1 ...
26547  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
26548  was executed.
26549 \layout Chapter
26550
26551 Acknowledgments
26552 \layout Standard
26553
26554
26555 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
26556
26557 \end_inset 
26558
26559
26560 \newline 
26561
26562 \newline 
26563
26564 \emph on 
26565 Thanks to all the other volunteer developers who have helped with coding,
26566  testing, web-page creation, distribution sets, etc.
26567  You know who you are :-)
26568 \emph default 
26569
26570 \newline 
26571
26572 \layout Standard
26573
26574 This document was initially written by Sandeep Dutta
26575 \layout Standard
26576
26577 All product names mentioned herein may be trademarks
26578 \begin_inset LatexCommand \index{Trademarks}
26579
26580 \end_inset 
26581
26582  of their respective companies.
26583  
26584 \layout Section*
26585
26586 Alphabetical index
26587 \layout Standard
26588
26589 To avoid confusion, the installation and building options for SDCC itself
26590  (chapter 2) are not part of the index.
26591 \layout Standard
26592
26593
26594 \begin_inset LatexCommand \printindex{}
26595
26596 \end_inset 
26597
26598
26599 \the_end